[clang] [clang][bytecode] Ignore function calls with depth > 0... (PR #129887)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 5 06:21:37 PST 2025
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/129887
... when checking for a potential constant expression. This is also what the current interpreter does.
>From 8e4267678319e98b2119233e13b5e73869bc3a21 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Wed, 5 Mar 2025 15:17:30 +0100
Subject: [PATCH] [clang][bytecode] Ignore function calls with depth > 0...
... when checking for a potential constant expression. This is also
what the current interpreter does.
---
clang/lib/AST/ByteCode/Interp.cpp | 3 +++
clang/test/AST/ByteCode/functions.cpp | 13 +++++++++++++
2 files changed, 16 insertions(+)
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index a2090f3e85e08..1107c0c32792f 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -714,6 +714,9 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
return false;
}
+ if (S.checkingPotentialConstantExpression() && S.Current->getDepth() != 0)
+ return false;
+
if (F->isConstexpr() && F->hasBody() &&
(F->getDecl()->isConstexpr() || F->getDecl()->hasAttr<MSConstexprAttr>()))
return true;
diff --git a/clang/test/AST/ByteCode/functions.cpp b/clang/test/AST/ByteCode/functions.cpp
index a7c8836eac6b8..a767d104b3c8a 100644
--- a/clang/test/AST/ByteCode/functions.cpp
+++ b/clang/test/AST/ByteCode/functions.cpp
@@ -681,3 +681,16 @@ namespace StableAddress {
static_assert(sum<str{"$hello $world."}>() == 1234, "");
}
#endif
+
+namespace NoDiags {
+ void huh();
+ template <unsigned>
+ constexpr void hd_fun() {
+ huh();
+ }
+
+ constexpr bool foo() {
+ hd_fun<1>();
+ return true;
+ }
+}
More information about the cfe-commits
mailing list