if (!visit(LHS) || !visit(RHS))
return false;
+ // For languages such as C, cast the result of one
+ // of our comparision opcodes to T (which is usually int).
+ auto MaybeCastToBool = [this, T, BO](bool Result) {
+ if (!Result)
+ return false;
+ if (DiscardResult)
+ return this->emitPop(*T, BO);
+ if (T != PT_Bool)
+ return this->emitCast(PT_Bool, *T, BO);
+ return true;
+ };
+
switch (BO->getOpcode()) {
case BO_EQ:
- return Discard(this->emitEQ(*LT, BO));
+ return MaybeCastToBool(this->emitEQ(*LT, BO));
case BO_NE:
- return Discard(this->emitNE(*LT, BO));
+ return MaybeCastToBool(this->emitNE(*LT, BO));
case BO_LT:
- return Discard(this->emitLT(*LT, BO));
+ return MaybeCastToBool(this->emitLT(*LT, BO));
case BO_LE:
- return Discard(this->emitLE(*LT, BO));
+ return MaybeCastToBool(this->emitLE(*LT, BO));
case BO_GT:
- return Discard(this->emitGT(*LT, BO));
+ return MaybeCastToBool(this->emitGT(*LT, BO));
case BO_GE:
- return Discard(this->emitGE(*LT, BO));
+ return MaybeCastToBool(this->emitGE(*LT, BO));
case BO_Sub:
if (BO->getType()->isFloatingType())
return Discard(this->emitSubf(getRoundingMode(BO), BO));
--- /dev/null
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+/// expected-no-diagnostics
+/// ref-no-diagnostics
+
+_Static_assert(1, "");
+_Static_assert(0 != 1, "");
+_Static_assert(1.0 == 1.0, "");
+_Static_assert( (5 > 4) + (3 > 2) == 2, "");