Skip to content

Commit fefe670

Browse files
authored
[clang][bytecode] Compile the definition, not the most recent decl (#158093)
1 parent aef2f41 commit fefe670

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

clang/lib/AST/ByteCode/ByteCodeEmitter.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@ void ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl,
2424
Function *Func) {
2525
assert(FuncDecl);
2626
assert(Func);
27+
assert(FuncDecl->isThisDeclarationADefinition());
2728

2829
// Manually created functions that haven't been assigned proper
2930
// parameters yet.
3031
if (!FuncDecl->param_empty() && !FuncDecl->param_begin())
3132
return;
3233

33-
if (!FuncDecl->isDefined())
34-
return;
35-
3634
// Set up lambda captures.
3735
if (const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl);
3836
MD && isLambdaCallOperator(MD)) {
@@ -87,7 +85,7 @@ void ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl,
8785
}
8886

8987
// Set the function's code.
90-
Func->setCode(NextLocalOffset, std::move(Code), std::move(SrcMap),
88+
Func->setCode(FuncDecl, NextLocalOffset, std::move(Code), std::move(SrcMap),
9189
std::move(Scopes), FuncDecl->hasBody());
9290
Func->setIsFullyCompiled(true);
9391
}

clang/lib/AST/ByteCode/Function.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,10 @@ class Function final {
236236
bool HasRVO, bool IsLambdaStaticInvoker);
237237

238238
/// Sets the code of a function.
239-
void setCode(unsigned NewFrameSize, llvm::SmallVector<std::byte> &&NewCode,
240-
SourceMap &&NewSrcMap, llvm::SmallVector<Scope, 2> &&NewScopes,
241-
bool NewHasBody) {
239+
void setCode(FunctionDeclTy Source, unsigned NewFrameSize,
240+
llvm::SmallVector<std::byte> &&NewCode, SourceMap &&NewSrcMap,
241+
llvm::SmallVector<Scope, 2> &&NewScopes, bool NewHasBody) {
242+
this->Source = Source;
242243
FrameSize = NewFrameSize;
243244
Code = std::move(NewCode);
244245
SrcMap = std::move(NewSrcMap);

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,9 +1493,12 @@ bool CheckDestructor(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
14931493
}
14941494

14951495
static void compileFunction(InterpState &S, const Function *Func) {
1496+
const FunctionDecl *Definition = Func->getDecl()->getDefinition();
1497+
if (!Definition)
1498+
return;
1499+
14961500
Compiler<ByteCodeEmitter>(S.getContext(), S.P)
1497-
.compileFunc(Func->getDecl()->getMostRecentDecl(),
1498-
const_cast<Function *>(Func));
1501+
.compileFunc(Definition, const_cast<Function *>(Func));
14991502
}
15001503

15011504
bool CallVar(InterpState &S, CodePtr OpPC, const Function *Func,

clang/test/Modules/lambda-merge.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -fmodules -std=c++17 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s
2+
// RUN: %clang_cc1 -fmodules -std=c++17 -emit-llvm %s -o - -triple x86_64-linux-gnu -fexperimental-new-constant-interpreter | FileCheck %s
23

34
#pragma clang module build A
45
module A {}

0 commit comments

Comments
 (0)