]> granicus.if.org Git - clang/commitdiff
In C++, assignment and compound assignment operators return an lvalue.
authorZhongxing Xu <xuzhongxing@gmail.com>
Mon, 10 Jan 2011 03:54:19 +0000 (03:54 +0000)
committerZhongxing Xu <xuzhongxing@gmail.com>
Mon, 10 Jan 2011 03:54:19 +0000 (03:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123158 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/ExprEngine.cpp
test/Analysis/lvalue.cpp [new file with mode: 0644]

index 7c1d3134538cf1383b7e299d8a5a8da201972931..ca960142ee35a5c1ff9a249dc4022961a8eff990 100644 (file)
@@ -3241,8 +3241,14 @@ void ExprEngine::VisitBinaryOperator(const BinaryOperator* B,
           LHSVal = svalBuilder.evalCast(Result, LTy, CTy);
         }
 
-        evalStore(Tmp3, B, LHS, *I4, state->BindExpr(B, Result),
-                  location, LHSVal);
+        // In C++, assignment and compound assignment operators return an 
+        // lvalue.
+        if (B->isLValue())
+          state = state->BindExpr(B, location);
+        else
+          state = state->BindExpr(B, Result);
+
+        evalStore(Tmp3, B, LHS, *I4, state, location, LHSVal);
       }
     }
   }
diff --git a/test/Analysis/lvalue.cpp b/test/Analysis/lvalue.cpp
new file mode 100644 (file)
index 0000000..f19c59d
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=region -verify %s
+
+int f1() {
+  int x = 0, y = 1;
+  return x += y; // Should bind a location to 'x += y'. No crash.
+}