From 1fb293dbccb834faa6e624efff10ad06c492f5ce Mon Sep 17 00:00:00 2001
From: Nikola Smiljanic <popizdeh@gmail.com>
Date: Fri, 30 May 2014 00:15:04 +0000
Subject: [PATCH] PR12214 - Warn on suspicious self-compound-assignments.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209867 91177308-0d34-0410-b5e6-96231b3b80d8
---
 include/clang/Basic/DiagnosticSemaKinds.td | 2 +-
 lib/Sema/SemaExpr.cpp                      | 3 ++-
 test/SemaCXX/warn-self-assign.cpp          | 3 +++
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index d831008b1bb..209f4259b93 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -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<
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 1d4792e9e05..9b4c6382dce 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -9297,8 +9297,9 @@ ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc,
       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())
diff --git a/test/SemaCXX/warn-self-assign.cpp b/test/SemaCXX/warn-self-assign.cpp
index fcdb2ab6bc6..7d558c6a073 100644
--- a/test/SemaCXX/warn-self-assign.cpp
+++ b/test/SemaCXX/warn-self-assign.cpp
@@ -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.
-- 
GitLab