[clang] [clang][bytecode] Compile most recent function decl (PR #131730)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 17 21:56:31 PDT 2025
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/131730
We used to always do this because all calls went through the code path that calls getMostRecentDecl(). Do it now, too.
>From eee0c1cb26452fa0ba96fa842eb7b343751d5baf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Tue, 18 Mar 2025 05:50:57 +0100
Subject: [PATCH] [clang][bytecode] Compile most recent function decl
We used to always do this because all calls went through the code path
that calls getMostRecentDecl(). Do it now, too.
---
clang/lib/AST/ByteCode/Compiler.cpp | 2 ++
clang/lib/AST/ByteCode/Context.cpp | 1 +
clang/lib/AST/ByteCode/Interp.cpp | 3 ++-
clang/test/AST/ByteCode/records.cpp | 12 ++++++++++++
4 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 3524ab5f86de8..4734ae8eaf52c 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -5676,6 +5676,8 @@ bool Compiler<Emitter>::checkLiteralType(const Expr *E) {
template <class Emitter>
bool Compiler<Emitter>::compileConstructor(const CXXConstructorDecl *Ctor) {
+ llvm::errs() << __PRETTY_FUNCTION__ << '\n';
+ Ctor->dump();
assert(!ReturnType);
auto emitFieldInitializer = [&](const Record::Field *F, unsigned FieldOffset,
diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp
index 23f4c5a4fa4b7..be39ed444e30d 100644
--- a/clang/lib/AST/ByteCode/Context.cpp
+++ b/clang/lib/AST/ByteCode/Context.cpp
@@ -104,6 +104,7 @@ bool Context::evaluate(State &Parent, const Expr *E, APValue &Result,
bool Context::evaluateAsInitializer(State &Parent, const VarDecl *VD,
APValue &Result) {
+ VD->dump();
++EvalID;
bool Recursing = !Stk.empty();
size_t StackSizeBefore = Stk.size();
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index ffd2b31147d20..bdbce5f662c6d 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1360,7 +1360,8 @@ static bool checkConstructor(InterpState &S, CodePtr OpPC, const Function *Func,
static void compileFunction(InterpState &S, const Function *Func) {
Compiler<ByteCodeEmitter>(S.getContext(), S.P)
- .compileFunc(Func->getDecl(), const_cast<Function *>(Func));
+ .compileFunc(Func->getDecl()->getMostRecentDecl(),
+ const_cast<Function *>(Func));
}
bool CallVar(InterpState &S, CodePtr OpPC, const Function *Func,
diff --git a/clang/test/AST/ByteCode/records.cpp b/clang/test/AST/ByteCode/records.cpp
index 42b6d82d7190b..5d9f1044f206b 100644
--- a/clang/test/AST/ByteCode/records.cpp
+++ b/clang/test/AST/ByteCode/records.cpp
@@ -1759,3 +1759,15 @@ namespace IncompleteTypes {
}
static_assert(foo(), "");
}
+
+namespace RedeclaredCtor {
+
+ struct __sp_mut {
+ void *__lx_;
+ constexpr __sp_mut(void *) noexcept;
+ };
+ int mut_back[1];
+
+ constexpr __sp_mut::__sp_mut(void *p) noexcept : __lx_(p) {}
+ constexpr __sp_mut muts = &mut_back[0];
+}
More information about the cfe-commits
mailing list