https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/133700
So the diagnostic output matches with the current interpreter >From 172f1381f0a342ad89a85c6b3b63e893a961c827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Mon, 31 Mar 2025 13:15:32 +0200 Subject: [PATCH] [clang][bytecode] Return Invalid() on non-constexpr builtins So the diagnostic output matches with the current interpreter --- clang/lib/AST/ByteCode/InterpBuiltin.cpp | 2 +- clang/test/AST/ByteCode/builtin-functions.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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}} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits