Skip to content

Commit 6217dff

Browse files
committed
Fix bug when processing '?' operator: invalidate the old "Uninitialized" value of the block-level expression for ?.
llvm-svn: 47645
1 parent 3007585 commit 6217dff

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

clang/Analysis/GRExprEngine.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ GRExprEngine::SetRVal(StateTy St, Expr* Ex, const RVal& V) {
4040
return St;
4141
}
4242

43-
return StateMgr.SetRVal(St, Ex, isBlkExpr, V);
43+
return StateMgr.SetRVal(St, Ex, V, isBlkExpr, false);
4444
}
4545

4646
const GRExprEngine::StateTy::BufferTy&
@@ -606,7 +606,9 @@ void GRExprEngine::VisitGuardedExpr(Expr* Ex, Expr* L, Expr* R,
606606
assert (SE);
607607

608608
X = GetBlkExprRVal(St, SE);
609-
Nodify(Dst, Ex, Pred, SetBlkExprRVal(St, Ex, X));
609+
610+
// Make sure that we invalidate the previous binding.
611+
Nodify(Dst, Ex, Pred, StateMgr.SetRVal(St, Ex, X, true, true));
610612
}
611613

612614
/// VisitSizeOfAlignOfTypeExpr - Transfer function for sizeof(type).

clang/Analysis/ValueState.cpp

+19-4
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,27 @@ RVal ValueStateManager::GetLVal(ValueState St, Expr* E) {
387387
}
388388

389389
ValueState
390-
ValueStateManager::SetRVal(ValueState St, Expr* E, bool isBlkExpr, RVal V) {
390+
ValueStateManager::SetRVal(ValueState St, Expr* E, RVal V,
391+
bool isBlkExpr, bool Invalidate) {
391392

392393
assert (E);
393394

394-
if (V.isUnknown())
395+
if (V.isUnknown()) {
396+
397+
if (Invalidate) {
398+
399+
ValueStateImpl NewSt = *St;
400+
401+
if (isBlkExpr)
402+
NewSt.BlockExprBindings = EXFactory.Remove(NewSt.BlockExprBindings, E);
403+
else
404+
NewSt.SubExprBindings = EXFactory.Remove(NewSt.SubExprBindings, E);
405+
406+
return getPersistentState(NewSt);
407+
}
408+
395409
return St;
410+
}
396411

397412
ValueStateImpl NewSt = *St;
398413

@@ -406,8 +421,8 @@ ValueStateManager::SetRVal(ValueState St, Expr* E, bool isBlkExpr, RVal V) {
406421
return getPersistentState(NewSt);
407422
}
408423

409-
ValueState
410-
ValueStateManager::SetRVal(ValueState St, LVal LV, RVal V) {
424+
425+
ValueState ValueStateManager::SetRVal(ValueState St, LVal LV, RVal V) {
411426

412427
switch (LV.getSubKind()) {
413428

clang/Analysis/ValueState.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,9 @@ class ValueStateManager {
255255
return getPersistentState(NewSt);
256256
}
257257

258-
ValueState SetRVal(ValueState St, Expr* E, bool isBlkExpr, RVal V);
258+
ValueState SetRVal(ValueState St, Expr* E, RVal V,
259+
bool isBlkExpr, bool Invalidate);
260+
259261
ValueState SetRVal(ValueState St, LVal LV, RVal V);
260262

261263
RVal GetRVal(ValueState St, Expr* E);

clang/include/clang/Analysis/PathSensitive/GRExprEngine.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class GRExprEngine {
243243
}
244244

245245
StateTy SetBlkExprRVal(StateTy St, Expr* Ex, const RVal& V) {
246-
return StateMgr.SetRVal(St, Ex, true, V);
246+
return StateMgr.SetRVal(St, Ex, V, true, false);
247247
}
248248

249249
/// SetRVal - This version of SetRVal is used to batch process a set

0 commit comments

Comments
 (0)