Skip to content

Commit 07bd3bb

Browse files
committed
[clang][bytecode][NFC] Improve Pointer::print()
Do not access PointeeStorage.BS.Pointee if we have a non-block pointer and extend printing to handle function pointers as well.
1 parent e59c824 commit 07bd3bb

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

clang/lib/AST/ByteCode/Pointer.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,10 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
265265
}
266266

267267
void Pointer::print(llvm::raw_ostream &OS) const {
268-
OS << PointeeStorage.BS.Pointee << " (";
269-
if (isBlockPointer()) {
268+
switch (StorageKind) {
269+
case Storage::Block: {
270270
const Block *B = PointeeStorage.BS.Pointee;
271-
OS << "Block) {";
271+
OS << "(Block) " << B << " {";
272272

273273
if (isRoot())
274274
OS << "rootptr(" << PointeeStorage.BS.Base << "), ";
@@ -284,11 +284,18 @@ void Pointer::print(llvm::raw_ostream &OS) const {
284284
OS << B->getSize();
285285
else
286286
OS << "nullptr";
287-
} else {
288-
OS << "Int) {";
289-
OS << PointeeStorage.Int.Value << ", " << PointeeStorage.Int.Desc;
287+
OS << "}";
288+
} break;
289+
case Storage::Int:
290+
OS << "(Int) {";
291+
OS << PointeeStorage.Int.Value << " + " << Offset << ", "
292+
<< PointeeStorage.Int.Desc;
293+
OS << "}";
294+
break;
295+
case Storage::Fn:
296+
OS << "(Fn) { " << asFunctionPointer().getFunction() << " + " << Offset
297+
<< " }";
290298
}
291-
OS << "}";
292299
}
293300

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

0 commit comments

Comments
 (0)