+ top--;
+ if (top->value.overflow && !pfile->state.skip_eval)
+ cpp_error (pfile, CPP_DL_PEDWARN,
+ "integer overflow in preprocessor expression");
+ }
+
+ if (op == CPP_CLOSE_PAREN)
+ {
+ cpp_error (pfile, CPP_DL_ERROR, "missing '(' in expression");
+ return 0;
+ }
+
+ return top;
+}
+
+/* Returns the position of the old top of stack after expansion. */
+struct op *
+_cpp_expand_op_stack (cpp_reader *pfile)
+{
+ size_t old_size = (size_t) (pfile->op_limit - pfile->op_stack);
+ size_t new_size = old_size * 2 + 20;
+
+ pfile->op_stack = xrealloc (pfile->op_stack, new_size * sizeof (struct op));
+ pfile->op_limit = pfile->op_stack + new_size;
+
+ return pfile->op_stack + old_size;
+}
+
+/* Emits a warning if the effective sign of either operand of OP
+ changes because of integer promotions. */
+static void
+check_promotion (cpp_reader *pfile, const struct op *op)
+{
+ if (op->value.unsignedp == op[-1].value.unsignedp)
+ return;
+
+ if (op->value.unsignedp)
+ {
+ if (!num_positive (op[-1].value, CPP_OPTION (pfile, precision)))
+ cpp_error (pfile, CPP_DL_WARNING,
+ "the left operand of \"%s\" changes sign when promoted",
+ cpp_token_as_text (pfile, op->token));
+ }
+ else if (!num_positive (op->value, CPP_OPTION (pfile, precision)))
+ cpp_error (pfile, CPP_DL_WARNING,
+ "the right operand of \"%s\" changes sign when promoted",
+ cpp_token_as_text (pfile, op->token));
+}
+
+/* Clears the unused high order bits of the number pointed to by PNUM. */
+static cpp_num
+num_trim (cpp_num num, size_t precision)
+{
+ if (precision > PART_PRECISION)
+ {
+ precision -= PART_PRECISION;
+ if (precision < PART_PRECISION)
+ num.high &= ((cpp_num_part) 1 << precision) - 1;
+ }
+ else
+ {
+ if (precision < PART_PRECISION)
+ num.low &= ((cpp_num_part) 1 << precision) - 1;
+ num.high = 0;
+ }
+
+ return num;
+}
+
+/* True iff A (presumed signed) >= 0. */
+static bool
+num_positive (cpp_num num, size_t precision)
+{
+ if (precision > PART_PRECISION)
+ {
+ precision -= PART_PRECISION;
+ return (num.high & (cpp_num_part) 1 << (precision - 1)) == 0;
+ }
+
+ return (num.low & (cpp_num_part) 1 << (precision - 1)) == 0;
+}
+
+/* Sign extend a number, with PRECISION significant bits and all
+ others assumed clear, to fill out a cpp_num structure. */
+cpp_num
+cpp_num_sign_extend (cpp_num num, size_t precision)
+{
+ if (!num.unsignedp)
+ {
+ if (precision > PART_PRECISION)
+ {
+ precision -= PART_PRECISION;
+ if (precision < PART_PRECISION
+ && (num.high & (cpp_num_part) 1 << (precision - 1)))
+ num.high |= ~(~(cpp_num_part) 0 >> (PART_PRECISION - precision));
+ }
+ else if (num.low & (cpp_num_part) 1 << (precision - 1))
+ {
+ if (precision < PART_PRECISION)
+ num.low |= ~(~(cpp_num_part) 0 >> (PART_PRECISION - precision));
+ num.high = ~(cpp_num_part) 0;
+ }
+ }
+
+ return num;
+}
+
+/* Returns the negative of NUM. */
+static cpp_num
+num_negate (cpp_num num, size_t precision)
+{
+ cpp_num copy;
+
+ copy = num;
+ num.high = ~num.high;
+ num.low = ~num.low;
+ if (++num.low == 0)
+ num.high++;
+ num = num_trim (num, precision);
+ num.overflow = (!num.unsignedp && num_eq (num, copy) && !num_zerop (num));
+
+ return num;
+}
+
+/* Returns true if A >= B. */
+static bool
+num_greater_eq (cpp_num pa, cpp_num pb, size_t precision)
+{
+ bool unsignedp;
+
+ unsignedp = pa.unsignedp || pb.unsignedp;
+
+ if (!unsignedp)
+ {
+ /* Both numbers have signed type. If they are of different
+ sign, the answer is the sign of A. */
+ unsignedp = num_positive (pa, precision);
+
+ if (unsignedp != num_positive (pb, precision))
+ return unsignedp;
+
+ /* Otherwise we can do an unsigned comparison. */
+ }
+
+ return (pa.high > pb.high) || (pa.high == pb.high && pa.low >= pb.low);
+}
+
+/* Returns LHS OP RHS, where OP is a bit-wise operation. */
+static cpp_num
+num_bitwise_op (cpp_reader *pfile ATTRIBUTE_UNUSED,
+ cpp_num lhs, cpp_num rhs, enum cpp_ttype op)
+{
+ lhs.overflow = false;
+ lhs.unsignedp = lhs.unsignedp || rhs.unsignedp;
+
+ /* As excess precision is zeroed, there is no need to num_trim () as
+ these operations cannot introduce a set bit there. */
+ if (op == CPP_AND)
+ {
+ lhs.low &= rhs.low;
+ lhs.high &= rhs.high;
+ }
+ else if (op == CPP_OR)
+ {
+ lhs.low |= rhs.low;
+ lhs.high |= rhs.high;
+ }
+ else
+ {
+ lhs.low ^= rhs.low;
+ lhs.high ^= rhs.high;
+ }
+
+ return lhs;
+}
+
+/* Returns LHS OP RHS, where OP is an inequality. */
+static cpp_num
+num_inequality_op (cpp_reader *pfile, cpp_num lhs, cpp_num rhs,
+ enum cpp_ttype op)
+{
+ bool gte = num_greater_eq (lhs, rhs, CPP_OPTION (pfile, precision));
+
+ if (op == CPP_GREATER_EQ)
+ lhs.low = gte;
+ else if (op == CPP_LESS)
+ lhs.low = !gte;
+ else if (op == CPP_GREATER)
+ lhs.low = gte && !num_eq (lhs, rhs);
+ else /* CPP_LESS_EQ. */
+ lhs.low = !gte || num_eq (lhs, rhs);
+
+ lhs.high = 0;
+ lhs.overflow = false;
+ lhs.unsignedp = false;
+ return lhs;
+}
+
+/* Returns LHS OP RHS, where OP is == or !=. */
+static cpp_num
+num_equality_op (cpp_reader *pfile ATTRIBUTE_UNUSED,
+ cpp_num lhs, cpp_num rhs, enum cpp_ttype op)
+{
+ /* Work around a 3.0.4 bug; see PR 6950. */
+ bool eq = num_eq (lhs, rhs);
+ if (op == CPP_NOT_EQ)
+ eq = !eq;
+ lhs.low = eq;
+ lhs.high = 0;
+ lhs.overflow = false;
+ lhs.unsignedp = false;
+ return lhs;
+}