summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/SemaExpr.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 7ef30d36475..51ebd079a49 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -4124,6 +4124,29 @@ QualType Sema::CheckShiftOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
UsualUnaryConversions(rex);
+ // Sanity-check shift operands
+ llvm::APSInt Right;
+ // Check right/shifter operand
+ if (rex->isIntegerConstantExpr(Right, Context)) {
+ // Check left/shiftee operand
+ llvm::APSInt Left;
+ if (lex->isIntegerConstantExpr(Left, Context)) {
+ if (Left == 0 && Right != 0)
+ Diag(Loc, diag::warn_op_no_effect)
+ << lex->getSourceRange() << rex->getSourceRange();
+ }
+ if (isCompAssign && Right == 0)
+ Diag(Loc, diag::warn_op_no_effect) << rex->getSourceRange();
+ else if (Right.isNegative())
+ Diag(Loc, diag::warn_shift_negative) << rex->getSourceRange();
+ else {
+ llvm::APInt LeftBits(Right.getBitWidth(),
+ Context.getTypeSize(lex->getType()));
+ if (Right.uge(LeftBits))
+ Diag(Loc, diag::warn_shift_gt_typewidth) << rex->getSourceRange();
+ }
+ }
+
// "The type of the result is that of the promoted left operand."
return LHSTy;
}
OpenPOWER on IntegriCloud