Skip to content

Commit 02b3012

Browse files
authored
[clang][bytecode] Always return false for invalid bcp results (#121467)
1 parent 67c974b commit 02b3012

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1544,9 +1544,10 @@ static bool interp__builtin_constant_p(InterpState &S, CodePtr OpPC,
15441544
if (Res.isInvalid()) {
15451545
C.cleanup();
15461546
Stk.clear();
1547+
return returnInt(false);
15471548
}
15481549

1549-
if (!Res.isInvalid() && !Res.empty()) {
1550+
if (!Res.empty()) {
15501551
const APValue &LV = Res.toAPValue();
15511552
if (LV.isLValue()) {
15521553
APValue::LValueBase Base = LV.getLValueBase();

clang/test/AST/ByteCode/builtin-constant-p.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ static_assert(__builtin_constant_p(I + 10.0), "");
1212
static_assert(__builtin_constant_p(nullptr), "");
1313
static_assert(__builtin_constant_p(&I), ""); // both-error {{failed due to requirement}}
1414
static_assert(__builtin_constant_p((void)I), ""); // both-error {{failed due to requirement}}
15+
16+
extern int z;
17+
constexpr int foo(int &a) {
18+
return __builtin_constant_p(a);
19+
}
20+
static_assert(!foo(z));

0 commit comments

Comments
 (0)