Skip to content

Add DynamicAllocLValue and TypeInfoLValue support to APValue::dump() #134996

@tbaederr

Description

@tbaederr

APValue recently gained support for dump()ing lvalues, however, the code to handle them is missing support for lvalue bases of type TypeInfoLValue and DynamicAllocLValue:

case APValue::LValue: {
(void)Context;
OS << "LValue Base=";
APValue::LValueBase B = Value.getLValueBase();
if (B.isNull())
OS << "null";
else if (const auto *BE = B.dyn_cast<const Expr *>()) {
OS << BE->getStmtClassName() << ' ';
dumpPointer(BE);
} else {
const auto *VDB = B.get<const ValueDecl *>();
OS << VDB->getDeclKindName() << "Decl";
dumpPointer(VDB);
}
OS << ", Null=" << Value.isNullPointer()
<< ", Offset=" << Value.getLValueOffset().getQuantity()
<< ", HasPath=" << Value.hasLValuePath();
if (Value.hasLValuePath()) {
OS << ", PathLength=" << Value.getLValuePath().size();
OS << ", Path=(";
llvm::ListSeparator Sep;
for (const auto &PathEntry : Value.getLValuePath()) {
// We're printing all entries as array indices because don't have the
// type information here to do anything else.
OS << Sep << PathEntry.getAsArrayIndex();
}
OS << ")";
}
return;
}

Before the else { branch that unconditionally assumes the base to be a const ValueDecl*, we need to check whether the base is a dynamic alloc value or a typeid value:

if (B.is<TypeInfoLValue>() || B.is<DynamicAllocLValue>())
return true;

... and print something appropriate, or at least not crash.

Metadata

Metadata

Assignees

Labels

clang:frontendLanguage frontend issues, e.g. anything involving "Sema"good first issuehttps://github.com/llvm/llvm-project/contribute

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions