[clang] 904f58e - [clang][bytecode] Use field descriptor in IntPointer::atOffset (#109238)

via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 19 00:12:21 PDT 2024


Author: Timm Baeder
Date: 2024-09-19T09:12:17+02:00
New Revision: 904f58e6b9418dab53719c7817e9216b95981a49

URL: https://github.com/llvm/llvm-project/commit/904f58e6b9418dab53719c7817e9216b95981a49
DIFF: https://github.com/llvm/llvm-project/commit/904f58e6b9418dab53719c7817e9216b95981a49.diff

LOG: [clang][bytecode] Use field descriptor in IntPointer::atOffset (#109238)

We're otherwise still pointing to the old type, but with the new offset.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Pointer.cpp
    clang/test/AST/ByteCode/codegen.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Pointer.cpp b/clang/lib/AST/ByteCode/Pointer.cpp
index 282953eb991a6b..387cad9b137c02 100644
--- a/clang/lib/AST/ByteCode/Pointer.cpp
+++ b/clang/lib/AST/ByteCode/Pointer.cpp
@@ -665,7 +665,7 @@ IntPointer IntPointer::atOffset(const ASTContext &ASTCtx,
   uint64_t FieldOffset =
       ASTCtx.toCharUnitsFromBits(Layout.getFieldOffset(FieldIndex))
           .getQuantity();
-  return IntPointer{this->Desc, this->Value + FieldOffset};
+  return IntPointer{F->Desc, this->Value + FieldOffset};
 }
 
 IntPointer IntPointer::baseCast(const ASTContext &ASTCtx,

diff  --git a/clang/test/AST/ByteCode/codegen.c b/clang/test/AST/ByteCode/codegen.c
index 8434992823010e..3c6f17e2b87264 100644
--- a/clang/test/AST/ByteCode/codegen.c
+++ b/clang/test/AST/ByteCode/codegen.c
@@ -17,3 +17,10 @@ struct B {
 };
 const int A = (char *)(&( (struct B *)(16) )->b[0]) - (char *)(16);
 // CHECK: @A = constant i32 1
+
+struct X { int a[2]; };
+int test(void) {
+  static int i23 = (int) &(((struct X *)0)->a[1]);
+  return i23;
+}
+// CHECK: @test.i23 = internal global i32 4, align 4


        


More information about the cfe-commits mailing list