[clang] [clang][bytecode] Return Invalid() on non-constexpr builtins (PR #133700)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 31 04:17:41 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
So the diagnostic output matches with the current interpreter
---
Full diff: https://github.com/llvm/llvm-project/pull/133700.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+1-1)
- (modified) clang/test/AST/ByteCode/builtin-functions.cpp (+9)
``````````diff
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index d7de4c09e2614..e838528b8a16c 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -2102,7 +2102,7 @@ static bool interp__builtin_memchr(InterpState &S, CodePtr OpPC,
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
const CallExpr *Call, uint32_t BuiltinID) {
if (!S.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID))
- return false;
+ return Invalid(S, OpPC);
const InterpFrame *Frame = S.Current;
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp
index 828822375e95e..ea09eede4ff12 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1545,3 +1545,12 @@ namespace WMemChr {
constexpr bool c = !wcschr(L"hello", L'h'); // both-error {{constant expression}} \
// both-note {{non-constexpr function 'wcschr' cannot be used in a constant expression}}
}
+
+namespace Invalid {
+ constexpr int test() { // both-error {{never produces a constant expression}}
+ __builtin_abort(); // both-note 2{{subexpression not valid in a constant expression}}
+ return 0;
+ }
+ static_assert(test() == 0); // both-error {{not an integral constant expression}} \
+ // both-note {{in call to}}
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/133700
More information about the cfe-commits
mailing list