[clang] [clang][Interp] Use first field decl for Record field lookup (PR #104412)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 15 00:36:06 PDT 2024
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/104412
None
>From cbc62389a992fddfbf9ef7362367b816e2810f40 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Thu, 15 Aug 2024 09:32:16 +0200
Subject: [PATCH] [clang][Interp] Use first field decl for Record field lookup
---
clang/lib/AST/Interp/Program.cpp | 1 +
clang/lib/AST/Interp/Record.cpp | 2 +-
clang/test/Modules/enum-codegen.cpp | 1 +
3 files changed, 3 insertions(+), 1 deletion(-)
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