Split out -Wconversion warnings about constant precision into their
own subcategory, -Wconstant-conversion, which is on by default.
Tweak the constant folder to give better results in the invalid
case of a negative shift amount.
Implements rdar://problem/6792488
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118636 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index ced3839..451aa2a 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -1458,12 +1458,25 @@
return Error(E->getOperatorLoc(), diag::note_expr_divide_by_zero, E);
return Success(Result.getInt() % RHS, E);
case BO_Shl: {
- // FIXME: Warn about out of range shift amounts!
- unsigned SA =
- (unsigned) RHS.getLimitedValue(Result.getInt().getBitWidth()-1);
+ // During constant-folding, a negative shift is an opposite shift.
+ if (RHS.isSigned() && RHS.isNegative()) {
+ RHS = -RHS;
+ goto shift_right;
+ }
+
+ shift_left:
+ unsigned SA
+ = (unsigned) RHS.getLimitedValue(Result.getInt().getBitWidth()-1);
return Success(Result.getInt() << SA, E);
}
case BO_Shr: {
+ // During constant-folding, a negative shift is an opposite shift.
+ if (RHS.isSigned() && RHS.isNegative()) {
+ RHS = -RHS;
+ goto shift_left;
+ }
+
+ shift_right:
unsigned SA =
(unsigned) RHS.getLimitedValue(Result.getInt().getBitWidth()-1);
return Success(Result.getInt() >> SA, E);