[clang][bytecode] Compile the definition, not the most recent decl (#158093)

This commit is contained in:
Timm Baeder 2025-09-12 07:12:09 +02:00 committed by GitHub
parent aef2f41f3f
commit fefe670be0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 9 deletions

View File

@ -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);
}

View File

@ -236,9 +236,10 @@ private:
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);

View File

@ -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,

View File

@ -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 {}