r209867 - PR12214 - Warn on suspicious self-compound-assignments.

Nikola Smiljanic popizdeh at gmail.com
Thu May 29 17:15:04 PDT 2014


Author: nikola
Date: Thu May 29 19:15:04 2014
New Revision: 209867

URL: http://llvm.org/viewvc/llvm-project?rev=209867&view=rev
Log:
PR12214 - Warn on suspicious self-compound-assignments.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/warn-self-assign.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=209867&r1=209866&r2=209867&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu May 29 19:15:04 2014
@@ -4466,7 +4466,7 @@ def warn_addition_in_bitshift : Warning<
   "'%1' will be evaluated first">, InGroup<ShiftOpParentheses>;
 
 def warn_self_assignment : Warning<
-  "explicitly assigning a variable of type %0 to itself">,
+  "explicitly assigning value of variable of type %0 to itself">,
   InGroup<SelfAssignment>, DefaultIgnore;
 
 def warn_string_plus_int : Warning<

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=209867&r1=209866&r2=209867&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu May 29 19:15:04 2014
@@ -9297,8 +9297,9 @@ ExprResult Sema::CreateBuiltinBinOp(Sour
       ResultTy = CheckAssignmentOperands(LHS.get(), RHS, OpLoc, CompResultTy);
     break;
   case BO_AndAssign:
+  case BO_OrAssign: // fallthrough
+	  DiagnoseSelfAssignment(*this, LHS.get(), RHS.get(), OpLoc);
   case BO_XorAssign:
-  case BO_OrAssign:
     CompResultTy = CheckBitwiseOperands(LHS, RHS, OpLoc, true);
     CompLHSTy = CompResultTy;
     if (!CompResultTy.isNull() && !LHS.isInvalid() && !RHS.isInvalid())

Modified: cfe/trunk/test/SemaCXX/warn-self-assign.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-self-assign.cpp?rev=209867&r1=209866&r2=209867&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-self-assign.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-self-assign.cpp Thu May 29 19:15:04 2014
@@ -8,6 +8,9 @@ void f() {
   b = a = b;
   a = a = a; // expected-warning{{explicitly assigning}}
   a = b = b = a;
+  a &= a; // expected-warning{{explicitly assigning}}
+  a |= a; // expected-warning{{explicitly assigning}}
+  a ^= a;
 }
 
 // Dummy type.





More information about the cfe-commits mailing list