Author: Timm Baeder
Date: 2025-05-19T13:29:09+02:00
New Revision: 572add06012036366e02ff5fe6be8e0bd803b157

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

LOG: [clang][bytecode] Diagnose failed constexpr assertions differently 
(#140000)

Adjust to the new way the ast walker is doing it.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Interp.cpp
    clang/test/SemaCXX/consteval-assert.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index 74efc3c914504..fc61de9f92701 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -851,6 +851,21 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const 
Function *F) {
   if (F->isLambdaStaticInvoker())
     return true;
 
+  // Diagnose failed assertions specially.
+  if (S.Current->getLocation(OpPC).isMacroID() &&
+      F->getDecl()->getIdentifier()) {
+    // FIXME: Instead of checking for an implementation-defined function,
+    // check and evaluate the assert() macro.
+    StringRef Name = F->getDecl()->getName();
+    bool AssertFailed =
+        Name == "__assert_rtn" || Name == "__assert_fail" || Name == 
"_wassert";
+    if (AssertFailed) {
+      S.FFDiag(S.Current->getLocation(OpPC),
+               diag::note_constexpr_assert_failed);
+      return false;
+    }
+  }
+
   if (S.getLangOpts().CPlusPlus11) {
     const FunctionDecl *DiagDecl = F->getDecl();
 

diff  --git a/clang/test/SemaCXX/consteval-assert.cpp 
b/clang/test/SemaCXX/consteval-assert.cpp
index b54a38ff26105..8f0b9046518ee 100644
--- a/clang/test/SemaCXX/consteval-assert.cpp
+++ b/clang/test/SemaCXX/consteval-assert.cpp
@@ -1,6 +1,10 @@
-// RUN: %clang_cc1 -std=c++23 -verify=expected,cxx20_plus -DTEST_LINUX %s
-// RUN: %clang_cc1 -std=c++23 -verify=expected,cxx20_plus -DTEST_WINDOWS %s
-// RUN: %clang_cc1 -std=c++23 -verify=expected,cxx20_plus -DTEST_DARWIN %s
+// RUN: %clang_cc1 -std=c++23 -verify -DTEST_LINUX %s
+// RUN: %clang_cc1 -std=c++23 -verify -DTEST_WINDOWS %s
+// RUN: %clang_cc1 -std=c++23 -verify -DTEST_DARWIN %s
+
+// RUN: %clang_cc1 -std=c++23 -verify -DTEST_LINUX %s   
-fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -std=c++23 -verify -DTEST_WINDOWS %s 
-fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -std=c++23 -verify -DTEST_DARWIN %s  
-fexperimental-new-constant-interpreter
 
 #ifdef __ASSERT_FUNCTION
 #undef __ASSERT_FUNCTION


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to