[clang] [clang][bytecode] Ignore function calls with depth > 0... (PR #129887)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 5 06:22:13 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
... when checking for a potential constant expression. This is also what the current interpreter does.
---
Full diff: https://github.com/llvm/llvm-project/pull/129887.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Interp.cpp (+3)
- (modified) clang/test/AST/ByteCode/functions.cpp (+13)
``````````diff
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;
+ }
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/129887
More information about the cfe-commits
mailing list