Skip to content

Commit a0e1e68

Browse files
authored
[clang][bytecode] Return Invalid() on non-constexpr builtins (#133700)
So the diagnostic output matches with the current interpreter
1 parent 11dd7d9 commit a0e1e68

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2125,7 +2125,7 @@ static bool interp__builtin_memchr(InterpState &S, CodePtr OpPC,
21252125
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
21262126
const CallExpr *Call, uint32_t BuiltinID) {
21272127
if (!S.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID))
2128-
return false;
2128+
return Invalid(S, OpPC);
21292129

21302130
const InterpFrame *Frame = S.Current;
21312131

clang/test/AST/ByteCode/builtin-functions.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,3 +1591,12 @@ namespace WMemChr {
15911591
constexpr bool c = !wcschr(L"hello", L'h'); // both-error {{constant expression}} \
15921592
// both-note {{non-constexpr function 'wcschr' cannot be used in a constant expression}}
15931593
}
1594+
1595+
namespace Invalid {
1596+
constexpr int test() { // both-error {{never produces a constant expression}}
1597+
__builtin_abort(); // both-note 2{{subexpression not valid in a constant expression}}
1598+
return 0;
1599+
}
1600+
static_assert(test() == 0); // both-error {{not an integral constant expression}} \
1601+
// both-note {{in call to}}
1602+
}

0 commit comments

Comments
 (0)