]> granicus.if.org Git - clang/commitdiff
Fix -Wshift-count-negative. It didn't work if the right hand side
authorDavide Italiano <davide@freebsd.org>
Thu, 26 Mar 2015 21:37:49 +0000 (21:37 +0000)
committerDavide Italiano <davide@freebsd.org>
Thu, 26 Mar 2015 21:37:49 +0000 (21:37 +0000)
of the shift wasn't a constant integer expression, now it (hopefully)
does.

PR: 22059

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233320 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/Sema/warn-shift-negative.c [new file with mode: 0644]

index c061e0610edd216cb4bd1e6d7ba32b469c4ae400..6eac5b6a93662d1bf057c90768af723ab2dda1d0 100644 (file)
@@ -7769,7 +7769,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult &LHS, ExprResult &RHS,
   llvm::APSInt Right;
   // Check right/shifter operand
   if (RHS.get()->isValueDependent() ||
-      !RHS.get()->isIntegerConstantExpr(Right, S.Context))
+      !RHS.get()->EvaluateAsInt(Right, S.Context))
     return;
 
   if (Right.isNegative()) {
diff --git a/test/Sema/warn-shift-negative.c b/test/Sema/warn-shift-negative.c
new file mode 100644 (file)
index 0000000..c65d66c
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -Wshift-count-negative -fblocks -verify %s
+
+int f(int a) {
+  const int i = -1;
+  return a << i; // expected-warning{{shift count is negative}}
+}