[clang] [clang][Interp] Use first field decl for Record field lookup (PR #104412)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 15 00:36:35 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-modules
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/104412.diff
3 Files Affected:
- (modified) clang/lib/AST/Interp/Program.cpp (+1)
- (modified) clang/lib/AST/Interp/Record.cpp (+1-1)
- (modified) clang/test/Modules/enum-codegen.cpp (+1)
``````````diff
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 },
``````````
</details>
https://github.com/llvm/llvm-project/pull/104412
More information about the cfe-commits
mailing list