[clang] d2c26d8 - [clang][Interp] Use first field decl for Record field lookup (#104412)

via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 15 04:57:41 PDT 2024


Author: Timm Baeder
Date: 2024-08-15T13:57:38+02:00
New Revision: d2c26d82b0395b8b555be384ed778361ec176c14

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

LOG: [clang][Interp] Use first field decl for Record field lookup (#104412)

Added: 
    

Modified: 
    clang/lib/AST/Interp/Program.cpp
    clang/lib/AST/Interp/Record.cpp
    clang/test/Modules/enum-codegen.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/Program.cpp b/clang/lib/AST/Interp/Program.cpp
index 5dd59d969853cc..9109956dc652cb 100644
--- a/clang/lib/AST/Interp/Program.cpp
+++ b/clang/lib/AST/Interp/Program.cpp
@@ -329,6 +329,7 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) {
   // Reserve space for fields.
   Record::FieldList Fields;
   for (const FieldDecl *FD : RD->fields()) {
+    assert(FD == FD->getFirstDecl());
     // Note that we DO create fields and descriptors
     // for unnamed bitfields here, even though we later ignore
     // them everywhere. That's so the FieldDecl's getFieldIndex() matches.

diff  --git a/clang/lib/AST/Interp/Record.cpp b/clang/lib/AST/Interp/Record.cpp
index ac01524e1caf0d..e7b741f2d458c8 100644
--- a/clang/lib/AST/Interp/Record.cpp
+++ b/clang/lib/AST/Interp/Record.cpp
@@ -37,7 +37,7 @@ const std::string Record::getName() const {
 }
 
 const Record::Field *Record::getField(const FieldDecl *FD) const {
-  auto It = FieldMap.find(FD);
+  auto It = FieldMap.find(FD->getFirstDecl());
   assert(It != FieldMap.end() && "Missing field");
   return It->second;
 }

diff  --git a/clang/test/Modules/enum-codegen.cpp b/clang/test/Modules/enum-codegen.cpp
index 4397b457801da4..0028ab00c15290 100644
--- a/clang/test/Modules/enum-codegen.cpp
+++ b/clang/test/Modules/enum-codegen.cpp
@@ -1,5 +1,6 @@
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -triple %itanium_abi_triple -fmodules -fmodules-cache-path=%t %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -fmodules -fmodules-cache-path=%t %s -emit-llvm -o - -fexperimental-new-constant-interpreter | FileCheck %s
 
 // CHECK: @{{.*var.*}} = {{.*}} %union.union_type { i8 1 },
 


        


More information about the cfe-commits mailing list