- if (warn_sign_compare && !skip_evaluation)
- {
- warn_for_sign_compare (orig_op0, orig_op1, op0, op1,
- result_type, resultcode);
+ if (!skip_evaluation)
+ {
+ bool op0_maybe_const = true;
+ bool op1_maybe_const = true;
+ tree orig_op0_folded, orig_op1_folded;
+
+ if (in_late_binary_op)
+ {
+ orig_op0_folded = orig_op0;
+ orig_op1_folded = orig_op1;
+ }
+ else
+ {
+ /* Fold for the sake of possible warnings, as in
+ build_conditional_expr. This requires the
+ "original" values to be folded, not just op0 and
+ op1. */
+ op0 = c_fully_fold (op0, require_constant_value,
+ &op0_maybe_const);
+ op1 = c_fully_fold (op1, require_constant_value,
+ &op1_maybe_const);
+ orig_op0_folded = c_fully_fold (orig_op0,
+ require_constant_value,
+ NULL);
+ orig_op1_folded = c_fully_fold (orig_op1,
+ require_constant_value,
+ NULL);
+ }
+
+ if (warn_sign_compare)
+ warn_for_sign_compare (location, orig_op0_folded,
+ orig_op1_folded, op0, op1,
+ result_type, resultcode);
+ if (!in_late_binary_op)
+ {
+ if (!op0_maybe_const || TREE_CODE (op0) != INTEGER_CST)
+ {
+ op0 = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (op0),
+ NULL, op0);
+ C_MAYBE_CONST_EXPR_NON_CONST (op0) = !op0_maybe_const;
+ }
+ if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST)
+ {
+ op1 = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (op1),
+ NULL, op1);
+ C_MAYBE_CONST_EXPR_NON_CONST (op1) = !op1_maybe_const;
+ }
+ }