return DiscardResult ? this->emitPop(T, E) : true;
});
case UO_Not: // ~x
+ if (!this->Visit(SubExpr))
+ return false;
+ if (Optional<PrimType> T = classify(E->getType()))
+ return this->emitComp(*T, E);
+ return false;
case UO_Real: // __real x
case UO_Imag: // __imag x
case UO_Extension:
return false;
}
+ static bool comp(Integral A, Integral *R) {
+ *R = Integral(~A.V);
+ return false;
+ }
+
private:
template <typename T> static bool CheckAddUB(T A, T B, T &R) {
if constexpr (std::is_signed_v<T>) {
return true;
}
+/// 1) Pops the value from the stack.
+/// 2) Pushes the bitwise complemented value on the stack (~V).
+template <PrimType Name, class T = typename PrimConv<Name>::T>
+bool Comp(InterpState &S, CodePtr OpPC) {
+ const T &Val = S.Stk.pop<T>();
+ T Result;
+ if (!T::comp(Val, &Result)) {
+ S.Stk.push<T>(Result);
+ return true;
+ }
+
+ return false;
+}
+
//===----------------------------------------------------------------------===//
// EQ, NE, GT, GE, LT, LE
//===----------------------------------------------------------------------===//
let HasGroup = 1;
}
+// [Real] -> [Real]
+def Comp: Opcode {
+ let Types = [NumberTypeClass];
+ let HasGroup = 1;
+}
+
//===----------------------------------------------------------------------===//
// Cast.
//===----------------------------------------------------------------------===//
// RUN: %clang_cc1 -std=c++11 -verify=ref %s
// RUN: %clang_cc1 -std=c++20 -verify=ref %s
+#define INT_MIN (~__INT_MAX__)
+#define INT_MAX __INT_MAX__
+
+
static_assert(true, "");
static_assert(false, ""); // expected-error{{failed}} ref-error{{failed}}
static_assert(nullptr == nullptr, "");
static_assert(-true, "");
static_assert(-false, ""); //expected-error{{failed}} ref-error{{failed}}
+static_assert(~0 == -1, "");
+static_assert(~1 == -2, "");
+static_assert(~-1 == 0, "");
+static_assert(~255 == -256, "");
+static_assert(~INT_MIN == INT_MAX, "");
+static_assert(~INT_MAX == INT_MIN, "");
+
+enum E {};
+constexpr E e = static_cast<E>(0);
+static_assert(~e == -1, "");
+
+
constexpr int m = 10;
constexpr const int *p = &m;
static_assert(p != nullptr, "");