Author: Timm Baeder
Date: 2025-03-31T18:53:12+02:00
New Revision: a0e1e680d28c4ef5f87be948d1d223fbfda2950c

URL: 
https://github.com/llvm/llvm-project/commit/a0e1e680d28c4ef5f87be948d1d223fbfda2950c
DIFF: 
https://github.com/llvm/llvm-project/commit/a0e1e680d28c4ef5f87be948d1d223fbfda2950c.diff

LOG: [clang][bytecode] Return Invalid() on non-constexpr builtins (#133700)

So the diagnostic output matches with the current interpreter

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/InterpBuiltin.cpp
    clang/test/AST/ByteCode/builtin-functions.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 4d125e4c202d2..3029314ddbad8 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -2125,7 +2125,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 8408286314bb8..40f7a18119751 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1591,3 +1591,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

Reply via email to