Skip to content

Commit 2c934dc

Browse files
authored
[clang][bytecode] Always compile most recent function decl (#124722)
1 parent cdea38f commit 2c934dc

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

clang/lib/AST/ByteCode/Context.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ Context::~Context() {}
2727

2828
bool Context::isPotentialConstantExpr(State &Parent, const FunctionDecl *FD) {
2929
assert(Stk.empty());
30-
Function *Func = P->getFunction(FD);
31-
if (!Func || !Func->hasBody())
32-
Func = Compiler<ByteCodeEmitter>(*this, *P).compileFunc(FD);
33-
30+
const Function *Func = getOrCreateFunction(FD);
3431
if (!Func)
3532
return false;
3633

@@ -271,6 +268,7 @@ Context::getOverridingFunction(const CXXRecordDecl *DynamicDecl,
271268

272269
const Function *Context::getOrCreateFunction(const FunctionDecl *FD) {
273270
assert(FD);
271+
FD = FD->getMostRecentDecl();
274272
const Function *Func = P->getFunction(FD);
275273
bool IsBeingCompiled = Func && Func->isDefined() && !Func->isFullyCompiled();
276274
bool WasNotDefined = Func && !Func->isConstexpr() && !Func->isDefined();

clang/test/AST/ByteCode/cxx2a.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,12 @@ namespace TypeId {
170170
}
171171
static_assert(side_effects());
172172
}
173+
174+
consteval int f(int i);
175+
constexpr bool test(auto i) {
176+
return f(0) == 0;
177+
}
178+
consteval int f(int i) {
179+
return 2 * i;
180+
}
181+
static_assert(test(42));

0 commit comments

Comments
 (0)