Skip to content

Commit 66c0b77

Browse files
committed
fix logic error
calling evalBind was not consistent: The original issue was that the performTrivialCopy function in ExprEngineCXX.cpp was always calling evalBind with AtDeclInit = true, regardless of whether it was handling: Copy constructors (which should use AtDeclInit = true for initialization) Assignment operators (which should use AtDeclInit = false for assignment)
1 parent 16501fe commit 66c0b77

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void ExprEngine::performTrivialCopy(NodeBuilder &Bldr, ExplodedNode *Pred,
8585
evalLocation(Tmp, CallExpr, VExpr, Pred, Pred->getState(), V,
8686
/*isLoad=*/true);
8787
for (ExplodedNode *N : Tmp)
88-
evalBind(Dst, CallExpr, N, ThisVal, V, true);
88+
evalBind(Dst, CallExpr, N, ThisVal, V, !AlwaysReturnsLValue);
8989

9090
PostStmt PS(CallExpr, LCtx);
9191
for (ExplodedNode *N : Dst) {

clang/unittests/StaticAnalyzer/ExprEngineVisitTest.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,23 @@ TEST(ExprEngineVisitTest, checkLocationAndBind) {
152152
EXPECT_TRUE(LocPos > BindPos);
153153
}
154154

155+
TEST(ExprEngineVisitTest, checkLocationAndBindInitialization) {
156+
std::string Diags;
157+
EXPECT_TRUE(runCheckerOnCode<addMemAccessChecker>(R"(
158+
class MyClass{
159+
public:
160+
int Value;
161+
};
162+
extern MyClass MyClassRead;
163+
void top() {
164+
MyClass MyClassWrite = MyClassRead;
165+
}
166+
)",
167+
Diags));
168+
169+
// Look for any occurrence of AtDeclInit = true
170+
std::size_t BindPos = Diags.find("AtDeclInit = true");
171+
EXPECT_NE(BindPos, std::string::npos);
172+
}
173+
155174
} // namespace

0 commit comments

Comments
 (0)