Skip to content

Commit 572add0

Browse files
authored
[clang][bytecode] Diagnose failed constexpr assertions differently (llvm#140000)
Adjust to the new way the ast walker is doing it.
1 parent d0ee358 commit 572add0

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,21 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
851851
if (F->isLambdaStaticInvoker())
852852
return true;
853853

854+
// Diagnose failed assertions specially.
855+
if (S.Current->getLocation(OpPC).isMacroID() &&
856+
F->getDecl()->getIdentifier()) {
857+
// FIXME: Instead of checking for an implementation-defined function,
858+
// check and evaluate the assert() macro.
859+
StringRef Name = F->getDecl()->getName();
860+
bool AssertFailed =
861+
Name == "__assert_rtn" || Name == "__assert_fail" || Name == "_wassert";
862+
if (AssertFailed) {
863+
S.FFDiag(S.Current->getLocation(OpPC),
864+
diag::note_constexpr_assert_failed);
865+
return false;
866+
}
867+
}
868+
854869
if (S.getLangOpts().CPlusPlus11) {
855870
const FunctionDecl *DiagDecl = F->getDecl();
856871

clang/test/SemaCXX/consteval-assert.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
// RUN: %clang_cc1 -std=c++23 -verify=expected,cxx20_plus -DTEST_LINUX %s
2-
// RUN: %clang_cc1 -std=c++23 -verify=expected,cxx20_plus -DTEST_WINDOWS %s
3-
// RUN: %clang_cc1 -std=c++23 -verify=expected,cxx20_plus -DTEST_DARWIN %s
1+
// RUN: %clang_cc1 -std=c++23 -verify -DTEST_LINUX %s
2+
// RUN: %clang_cc1 -std=c++23 -verify -DTEST_WINDOWS %s
3+
// RUN: %clang_cc1 -std=c++23 -verify -DTEST_DARWIN %s
4+
5+
// RUN: %clang_cc1 -std=c++23 -verify -DTEST_LINUX %s -fexperimental-new-constant-interpreter
6+
// RUN: %clang_cc1 -std=c++23 -verify -DTEST_WINDOWS %s -fexperimental-new-constant-interpreter
7+
// RUN: %clang_cc1 -std=c++23 -verify -DTEST_DARWIN %s -fexperimental-new-constant-interpreter
48

59
#ifdef __ASSERT_FUNCTION
610
#undef __ASSERT_FUNCTION

0 commit comments

Comments
 (0)