Unverified Commit 5e42f09a authored by Timm Baeder's avatar Timm Baeder Committed by GitHub
Browse files

[clang][bytecode] Reject non-number values in Rem op (#194309)

parent 295a7a9f
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -196,6 +196,12 @@ bool CheckShift(InterpState &S, CodePtr OpPC, const LT &LHS, const RT &RHS,
/// Checks if Div/Rem operation on LHS and RHS is valid.
template <typename T>
bool CheckDivRem(InterpState &S, CodePtr OpPC, const T &LHS, const T &RHS) {

  if constexpr (isIntegralOrPointer<T>()) {
    if (!LHS.isNumber() || !RHS.isNumber())
      return false;
  }

  if (RHS.isZero()) {
    const auto *Op = cast<BinaryOperator>(S.Current->getExpr(OpPC));
    if constexpr (std::is_same_v<T, Floating>) {
+3 −0
Original line number Diff line number Diff line
@@ -455,3 +455,6 @@ float r = (float) (intptr_t) &r; // all-error {{initializer element is not a co
void labelAndNull(void) { int bar = &*(void *)0 - &&baz; } // all-error {{use of undeclared label 'baz'}} \\
                                                           // pedantic-warning {{use of GNU address-of-label extension}} \
                                                           // pedantic-warning {{arithmetic on pointers to void is a GNU extension}}

void nonNumberRem(void) { *((int *)0) = (long)foo % 42; } // all-warning {{indirection of non-volatile null pointer will be deleted, not trap}} \
                                                          // all-note {{consider using __builtin_trap() or qualifying pointer with 'volatile'}}