Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang][bytecode] Compile most recent function decl #131730

Merged
merged 1 commit into from
Mar 18, 2025

Conversation

tbaederr
Copy link
Contributor

We used to always do this because all calls went through the code path that calls getMostRecentDecl(). Do it now, too.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Mar 18, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 18, 2025

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

We used to always do this because all calls went through the code path that calls getMostRecentDecl(). Do it now, too.


Full diff: https://github.com/llvm/llvm-project/pull/131730.diff

4 Files Affected:

  • (modified) clang/lib/AST/ByteCode/Compiler.cpp (+2)
  • (modified) clang/lib/AST/ByteCode/Context.cpp (+1)
  • (modified) clang/lib/AST/ByteCode/Interp.cpp (+2-1)
  • (modified) clang/test/AST/ByteCode/records.cpp (+12)
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];
+}

We used to always do this because all calls went through the code path
that calls getMostRecentDecl(). Do it now, too.
@tbaederr tbaederr merged commit 2f808dd into llvm:main Mar 18, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants