Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3714,8 +3714,7 @@ ExprEngine::notifyCheckersOfPointerEscape(ProgramStateRef State,
/// evalBind - Handle the semantics of binding a value to a specific location.
/// This method is used by evalStore and (soon) VisitDeclStmt, and others.
void ExprEngine::evalBind(ExplodedNodeSet &Dst, const Stmt *StoreE,
ExplodedNode *Pred,
SVal location, SVal Val,
ExplodedNode *Pred, SVal location, SVal Val,
bool AtDeclInit, const ProgramPoint *PP) {
const LocationContext *LC = Pred->getLocationContext();
PostStmt PS(StoreE, LC);
Expand Down Expand Up @@ -3748,8 +3747,8 @@ void ExprEngine::evalBind(ExplodedNodeSet &Dst, const Stmt *StoreE,
// When binding the value, pass on the hint that this is a initialization.
// For initializations, we do not need to inform clients of region
// changes.
state = state->bindLoc(location.castAs<Loc>(),
Val, LC, /* notifyChanges = */ !AtDeclInit);
state = state->bindLoc(location.castAs<Loc>(), Val, LC,
/* notifyChanges = */ !AtDeclInit);

const MemRegion *LocReg = nullptr;
if (std::optional<loc::MemRegionVal> LocRegVal =
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void ExprEngine::performTrivialCopy(NodeBuilder &Bldr, ExplodedNode *Pred,
evalLocation(Tmp, CallExpr, VExpr, Pred, Pred->getState(), V,
/*isLoad=*/true);
for (ExplodedNode *N : Tmp)
evalBind(Dst, CallExpr, N, ThisVal, V, true);
evalBind(Dst, CallExpr, N, ThisVal, V, !AlwaysReturnsLValue);

PostStmt PS(CallExpr, LCtx);
for (ExplodedNode *N : Dst) {
Expand Down
19 changes: 19 additions & 0 deletions clang/unittests/StaticAnalyzer/ExprEngineVisitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,23 @@ TEST(ExprEngineVisitTest, checkLocationAndBind) {
EXPECT_TRUE(LocPos > BindPos);
}

TEST(ExprEngineVisitTest, checkLocationAndBindInitialization) {
std::string Diags;
EXPECT_TRUE(runCheckerOnCode<addMemAccessChecker>(R"(
class MyClass{
public:
int Value;
};
extern MyClass MyClassRead;
void top() {
MyClass MyClassWrite = MyClassRead;
}
)",
Diags));

// Look for any occurrence of AtDeclInit = true
std::size_t BindPos = Diags.find("AtDeclInit = true");
EXPECT_NE(BindPos, std::string::npos);
}

} // namespace