Skip to content

Commit

Permalink
[clang][bytecode] Allow checking builtin functions... (#119328)
Browse files Browse the repository at this point in the history
... in checkingPotentialConstantExpression mode. This is what the
current interpreter does, yet it doesn't do so for
`__builtin_operator_new`.
  • Loading branch information
tbaederr authored Dec 10, 2024
1 parent 4cea3c3 commit ce15873
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion clang/lib/AST/ByteCode/Interp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,10 @@ bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func,

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

Expand Down
4 changes: 2 additions & 2 deletions clang/test/AST/ByteCode/builtin-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1198,11 +1198,11 @@ namespace BuiltinMemcpy {
}
static_assert(simpleMove() == 12);

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

0 comments on commit ce15873

Please sign in to comment.