[clang] [clang][bytecode] Compile most recent function decl (PR #131730)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 17 22:00:14 PDT 2025


https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/131730

>From 44b5dcaf35e3a0d4ea6ebdc8eacd530658b799d4 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/Interp.cpp   |  3 ++-
 clang/test/AST/ByteCode/records.cpp | 12 ++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

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