[clang] 2c934dc - [clang][bytecode] Always compile most recent function decl (#124722)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 28 02:43:06 PST 2025
Author: Timm Baeder
Date: 2025-01-28T11:43:02+01:00
New Revision: 2c934dc5e1a3ef7b717400f27d6b9ea21f4e20a0
URL: https://github.com/llvm/llvm-project/commit/2c934dc5e1a3ef7b717400f27d6b9ea21f4e20a0
DIFF: https://github.com/llvm/llvm-project/commit/2c934dc5e1a3ef7b717400f27d6b9ea21f4e20a0.diff
LOG: [clang][bytecode] Always compile most recent function decl (#124722)
Added:
Modified:
clang/lib/AST/ByteCode/Context.cpp
clang/test/AST/ByteCode/cxx2a.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp
index b52892cf69bfb6..a322700fc0d229 100644
--- a/clang/lib/AST/ByteCode/Context.cpp
+++ b/clang/lib/AST/ByteCode/Context.cpp
@@ -27,10 +27,7 @@ Context::~Context() {}
bool Context::isPotentialConstantExpr(State &Parent, const FunctionDecl *FD) {
assert(Stk.empty());
- Function *Func = P->getFunction(FD);
- if (!Func || !Func->hasBody())
- Func = Compiler<ByteCodeEmitter>(*this, *P).compileFunc(FD);
-
+ const Function *Func = getOrCreateFunction(FD);
if (!Func)
return false;
@@ -271,6 +268,7 @@ Context::getOverridingFunction(const CXXRecordDecl *DynamicDecl,
const Function *Context::getOrCreateFunction(const FunctionDecl *FD) {
assert(FD);
+ FD = FD->getMostRecentDecl();
const Function *Func = P->getFunction(FD);
bool IsBeingCompiled = Func && Func->isDefined() && !Func->isFullyCompiled();
bool WasNotDefined = Func && !Func->isConstexpr() && !Func->isDefined();
diff --git a/clang/test/AST/ByteCode/cxx2a.cpp b/clang/test/AST/ByteCode/cxx2a.cpp
index e478a0ddc4c146..b9327716d7b92d 100644
--- a/clang/test/AST/ByteCode/cxx2a.cpp
+++ b/clang/test/AST/ByteCode/cxx2a.cpp
@@ -170,3 +170,12 @@ namespace TypeId {
}
static_assert(side_effects());
}
+
+consteval int f(int i);
+constexpr bool test(auto i) {
+ return f(0) == 0;
+}
+consteval int f(int i) {
+ return 2 * i;
+}
+static_assert(test(42));
More information about the cfe-commits
mailing list