https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/158093
None >From 124ff06b036813e3a799ed67cc5edb1a835e0c7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Thu, 11 Sep 2025 16:57:14 +0200 Subject: [PATCH] [clang][bytecode] Compile the definition, not the most recent decl --- clang/lib/AST/ByteCode/ByteCodeEmitter.cpp | 6 ++---- clang/lib/AST/ByteCode/Function.h | 7 ++++--- clang/lib/AST/ByteCode/Interp.cpp | 7 +++++-- clang/test/Modules/lambda-merge.cpp | 1 + 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp index 1d71708799518..274efccac79dc 100644 --- a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp +++ b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp @@ -24,15 +24,13 @@ void ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl, Function *Func) { assert(FuncDecl); assert(Func); + assert(FuncDecl->isThisDeclarationADefinition()); // Manually created functions that haven't been assigned proper // parameters yet. if (!FuncDecl->param_empty() && !FuncDecl->param_begin()) return; - if (!FuncDecl->isDefined()) - return; - // Set up lambda captures. if (const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl); MD && isLambdaCallOperator(MD)) { @@ -87,7 +85,7 @@ void ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl, } // Set the function's code. - Func->setCode(NextLocalOffset, std::move(Code), std::move(SrcMap), + Func->setCode(FuncDecl, NextLocalOffset, std::move(Code), std::move(SrcMap), std::move(Scopes), FuncDecl->hasBody()); Func->setIsFullyCompiled(true); } diff --git a/clang/lib/AST/ByteCode/Function.h b/clang/lib/AST/ByteCode/Function.h index af429b7849e88..95add5809afcc 100644 --- a/clang/lib/AST/ByteCode/Function.h +++ b/clang/lib/AST/ByteCode/Function.h @@ -236,9 +236,10 @@ class Function final { bool HasRVO, bool IsLambdaStaticInvoker); /// Sets the code of a function. - void setCode(unsigned NewFrameSize, llvm::SmallVector<std::byte> &&NewCode, - SourceMap &&NewSrcMap, llvm::SmallVector<Scope, 2> &&NewScopes, - bool NewHasBody) { + void setCode(FunctionDeclTy Source, unsigned NewFrameSize, + llvm::SmallVector<std::byte> &&NewCode, SourceMap &&NewSrcMap, + llvm::SmallVector<Scope, 2> &&NewScopes, bool NewHasBody) { + this->Source = Source; FrameSize = NewFrameSize; Code = std::move(NewCode); SrcMap = std::move(NewSrcMap); diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index b961a413fbe78..d5e75a0c90469 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -1493,9 +1493,12 @@ bool CheckDestructor(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { } static void compileFunction(InterpState &S, const Function *Func) { + const FunctionDecl *Definition = Func->getDecl()->getDefinition(); + if (!Definition) + return; + Compiler<ByteCodeEmitter>(S.getContext(), S.P) - .compileFunc(Func->getDecl()->getMostRecentDecl(), - const_cast<Function *>(Func)); + .compileFunc(Definition, const_cast<Function *>(Func)); } bool CallVar(InterpState &S, CodePtr OpPC, const Function *Func, diff --git a/clang/test/Modules/lambda-merge.cpp b/clang/test/Modules/lambda-merge.cpp index e996c9c0d5d1f..6b61d356ec581 100644 --- a/clang/test/Modules/lambda-merge.cpp +++ b/clang/test/Modules/lambda-merge.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fmodules -std=c++17 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s +// RUN: %clang_cc1 -fmodules -std=c++17 -emit-llvm %s -o - -triple x86_64-linux-gnu -fexperimental-new-constant-interpreter | FileCheck %s #pragma clang module build A module A {} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits