Skip to content

Commit

Permalink
[clang][bytecode][NFC] Improve Pointer::print()
Browse files Browse the repository at this point in the history
Do not access PointeeStorage.BS.Pointee if we have a non-block pointer
and extend printing to handle function pointers as well.
  • Loading branch information
tbaederr committed Aug 18, 2024
1 parent e59c824 commit 07bd3bb
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions clang/lib/AST/ByteCode/Pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
}

void Pointer::print(llvm::raw_ostream &OS) const {
OS << PointeeStorage.BS.Pointee << " (";
if (isBlockPointer()) {
switch (StorageKind) {
case Storage::Block: {
const Block *B = PointeeStorage.BS.Pointee;
OS << "Block) {";
OS << "(Block) " << B << " {";

if (isRoot())
OS << "rootptr(" << PointeeStorage.BS.Base << "), ";
Expand All @@ -284,11 +284,18 @@ void Pointer::print(llvm::raw_ostream &OS) const {
OS << B->getSize();
else
OS << "nullptr";
} else {
OS << "Int) {";
OS << PointeeStorage.Int.Value << ", " << PointeeStorage.Int.Desc;
OS << "}";
} break;
case Storage::Int:
OS << "(Int) {";
OS << PointeeStorage.Int.Value << " + " << Offset << ", "
<< PointeeStorage.Int.Desc;
OS << "}";
break;
case Storage::Fn:
OS << "(Fn) { " << asFunctionPointer().getFunction() << " + " << Offset
<< " }";
}
OS << "}";
}

std::string Pointer::toDiagnosticString(const ASTContext &Ctx) const {
Expand Down

0 comments on commit 07bd3bb

Please sign in to comment.