Skip to content

Commit ce15873

Browse files
authored
[clang][bytecode] Allow checking builtin functions... (#119328)
... in checkingPotentialConstantExpression mode. This is what the current interpreter does, yet it doesn't do so for `__builtin_operator_new`.
1 parent 4cea3c3 commit ce15873

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,10 @@ bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func,
13601360

13611361
bool CallBI(InterpState &S, CodePtr OpPC, const Function *Func,
13621362
const CallExpr *CE, uint32_t BuiltinID) {
1363-
if (S.checkingPotentialConstantExpression())
1363+
// A little arbitrary, but the current interpreter allows evaluation
1364+
// of builtin functions in this mode, with some exceptions.
1365+
if (BuiltinID == Builtin::BI__builtin_operator_new &&
1366+
S.checkingPotentialConstantExpression())
13641367
return false;
13651368
auto NewFrame = std::make_unique<InterpFrame>(S, Func, OpPC);
13661369

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,11 +1198,11 @@ namespace BuiltinMemcpy {
11981198
}
11991199
static_assert(simpleMove() == 12);
12001200

1201-
constexpr int memcpyTypeRem() { // ref-error {{never produces a constant expression}}
1201+
constexpr int memcpyTypeRem() { // both-error {{never produces a constant expression}}
12021202
int a = 12;
12031203
int b = 0;
12041204
__builtin_memmove(&b, &a, 1); // both-note {{'memmove' not supported: size to copy (1) is not a multiple of size of element type 'int'}} \
1205-
// ref-note {{not supported}}
1205+
// both-note {{not supported}}
12061206
return b;
12071207
}
12081208
static_assert(memcpyTypeRem() == 12); // both-error {{not an integral constant expression}} \

0 commit comments

Comments
 (0)