From: Zhongxing Xu Date: Mon, 10 Jan 2011 03:54:19 +0000 (+0000) Subject: In C++, assignment and compound assignment operators return an lvalue. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f9d3cbbe07afa05c2414c7120d7141409e5a3663;p=clang In C++, assignment and compound assignment operators return an lvalue. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123158 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Checkers/ExprEngine.cpp b/lib/StaticAnalyzer/Checkers/ExprEngine.cpp index 7c1d313453..ca960142ee 100644 --- a/lib/StaticAnalyzer/Checkers/ExprEngine.cpp +++ b/lib/StaticAnalyzer/Checkers/ExprEngine.cpp @@ -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 index 0000000000..f19c59d9d2 --- /dev/null +++ b/test/Analysis/lvalue.cpp @@ -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. +}