r178412 - Sema: Don't crash when trying to emit a precedence warning on postinc/decrement.

Benjamin Kramer benny.kra at googlemail.com
Sat Mar 30 04:56:01 PDT 2013


Author: d0k
Date: Sat Mar 30 06:56:00 2013
New Revision: 178412

URL: http://llvm.org/viewvc/llvm-project?rev=178412&view=rev
Log:
Sema: Don't crash when trying to emit a precedence warning on postinc/decrement.

Post-Inc can occur as a binary call (the infamous dummy int argument), but it's
not really a binary operator.

Fixes PR15628.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/Sema/parentheses.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=178412&r1=178411&r2=178412&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Mar 30 06:56:00 2013
@@ -5412,7 +5412,8 @@ static bool IsArithmeticBinaryExpr(Expr
     // Make sure this is really a binary operator that is safe to pass into
     // BinaryOperator::getOverloadedOpcode(), e.g. it's not a subscript op.
     OverloadedOperatorKind OO = Call->getOperator();
-    if (OO < OO_Plus || OO > OO_Arrow)
+    if (OO < OO_Plus || OO > OO_Arrow ||
+        OO == OO_PlusPlus || OO == OO_MinusMinus)
       return false;
 
     BinaryOperatorKind OpKind = BinaryOperator::getOverloadedOpcode(OO);

Modified: cfe/trunk/test/Sema/parentheses.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/parentheses.cpp?rev=178412&r1=178411&r2=178412&view=diff
==============================================================================
--- cfe/trunk/test/Sema/parentheses.cpp (original)
+++ cfe/trunk/test/Sema/parentheses.cpp Sat Mar 30 06:56:00 2013
@@ -57,3 +57,15 @@ void test(int a, int b, int c) {
   Stream() >> b + c; // expected-warning {{operator '>>' has lower precedence than '+'; '+' will be evaluated first}} \
                         expected-note {{place parentheses around the '+' expression to silence this warning}}
 }
+
+namespace PR15628 {
+  struct BlockInputIter {
+    void* operator++(int);
+    void* operator--(int);
+  };
+
+  void test(BlockInputIter i) {
+    (void)(i++ ? true : false); // no-warning
+    (void)(i-- ? true : false); // no-warning
+  }
+}





More information about the cfe-commits mailing list