Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2309,29 +2309,36 @@ bool Compiler<Emitter>::VisitAbstractConditionalOperator(
return visitChildExpr(FalseExpr);
}

bool IsBcpCall = false;
if (const auto *CE = dyn_cast<CallExpr>(Condition->IgnoreParenCasts());
CE && CE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) {
IsBcpCall = true;
}

LabelTy LabelEnd = this->getLabel(); // Label after the operator.
LabelTy LabelFalse = this->getLabel(); // Label for the false expr.

if (IsBcpCall) {
if (!this->emitStartSpeculation(E))
return false;
}

if (!this->visitBool(Condition))
return false;

if (!this->jumpFalse(LabelFalse))
return false;

if (!visitChildExpr(TrueExpr))
return false;

if (!this->jump(LabelEnd))
return false;

this->emitLabel(LabelFalse);

if (!visitChildExpr(FalseExpr))
return false;

this->fallthrough(LabelEnd);
this->emitLabel(LabelEnd);

if (IsBcpCall)
return this->emitEndSpeculation(E);
return true;
}

Expand Down
7 changes: 2 additions & 5 deletions clang/test/AST/ByteCode/builtin-constant-p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,10 @@ template<typename T> constexpr bool bcp(T t) {
}

constexpr intptr_t ptr_to_int(const void *p) {
return __builtin_constant_p(1) ? (intptr_t)p : (intptr_t)p; // expected-note {{cast that performs the conversions of a reinterpret_cast}}
return __builtin_constant_p(1) ? (intptr_t)p : (intptr_t)p;
}

/// This is from test/SemaCXX/builtin-constant-p.cpp, but it makes no sense.
/// ptr_to_int is called before bcp(), so it fails. GCC does not accept this either.
static_assert(bcp(ptr_to_int("foo"))); // expected-error {{not an integral constant expression}} \
// expected-note {{in call to}}
static_assert(bcp(ptr_to_int("foo")));

constexpr bool AndFold(const int &a, const int &b) {
return __builtin_constant_p(a && b);
Expand Down