Author: Timm Bäder
Date: 2024-08-18T08:55:22+02:00
New Revision: 07bd3bb9b7eb34426a81de2b988f53f08611ab35

URL: 
https://github.com/llvm/llvm-project/commit/07bd3bb9b7eb34426a81de2b988f53f08611ab35
DIFF: 
https://github.com/llvm/llvm-project/commit/07bd3bb9b7eb34426a81de2b988f53f08611ab35.diff

LOG: [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.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Pointer.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Pointer.cpp 
b/clang/lib/AST/ByteCode/Pointer.cpp
index 466e61666c76e9..e39459578a5f52 100644
--- a/clang/lib/AST/ByteCode/Pointer.cpp
+++ b/clang/lib/AST/ByteCode/Pointer.cpp
@@ -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 << "), ";
@@ -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 {


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to