This is an archive of the discontinued LLVM Phabricator instance.

Fix crash when resolving branch conditions for temporary destructor condition blocks.
ClosedPublic

Authored by klimek on Apr 29 2014, 1:13 PM.

Details

Summary

Document and simplify ResolveCondition.

  1. Introduce a temporary special case for temporary desctructors when resolving

the branch condition - in an upcoming patch, alexmc will change temporary
destructor conditions to not run through this logic, in which case we can remove
this (marked as FIXME); this currently fixes a crash.

  1. Simplify ResolveCondition; while documenting the function, I noticed that it

always returns the last statement - either that statement is the condition
itself (in which case the condition was returned anyway), or the rightmost
leaf is returned; for correctness, the rightmost leaf must be evaluated anyway
(which the CFG does in the last statement), thus we can just return the last
statement in that case, too. Added an assert to verify the invariant; no tests
break - please let me know if I'm missing obvious test cases here, or this
doesn't make sense for some other reason.

Diff Detail

Event Timeline

klimek updated this revision to Diff 8940.Apr 29 2014, 1:13 PM
klimek retitled this revision from to Fix crash when resolving branch conditions for temporary destructor condition blocks..
klimek updated this object.
klimek edited the test plan for this revision. (Show Details)
klimek added reviewers: jordan_rose, krememek.
klimek added subscribers: alexmc, Unknown Object (MLST).

Awesome, thanks for this fix, Manuel!

lib/StaticAnalyzer/Core/ExprEngine.cpp
1389
1392

funcion -> function

1413

What happens if we actually hit an llvm_unreachable? Does it die like an assert?

If not, maybe assert before this?

test/Analysis/temporaries.cpp
192

Out of curiosity, why the change to this test case?

jordan_rose accepted this revision.Apr 29 2014, 8:34 PM
jordan_rose edited edge metadata.

What this is basically saying is that we will never be in a situation where the condition (or the rightmost branch in the condition) was not evaluated in the current CFG block. That seems a bit questionable in general but reasonable given the way the CFG is currently constructed. (Especially if/when this whole block of code can go away!)

I'm concerned about the test change Alex noted but otherwise this looks good.

lib/StaticAnalyzer/Core/ExprEngine.cpp
1355

Please follow the new LLVM style with lowercase function names. This can also be static. (And the asterisks go on the right of the space.)

1389

No, we try not to put links or PR numbers in the source code itself. Commit messages, sure.

1409–1411

Style nitpicks: no "clang::", asterisk next to the variable name.

1413

It's like an assert when assertions are enabled, but acts as an optimization hint in NDEBUG builds. So it's slightly better than an assert.

test/Analysis/temporaries.cpp
192

Seconded; all the existing tests are designed to tickle past bugs, and I'd rather not change any of the conditions.

This revision is now accepted and ready to land.Apr 29 2014, 8:34 PM
klimek updated this revision to Diff 8963.Apr 30 2014, 1:31 AM
klimek edited edge metadata.

Review comment changes.

lib/StaticAnalyzer/Core/ExprEngine.cpp
1355

Done.

1392

Done.

1409–1411

Done.

test/Analysis/temporaries.cpp
192

Good catch - that was a leftover from debugging, I didn't intend to change it.
Changed the test back (it still breaks, so I added the wrong expectation and a FIXME).

klimek closed this revision.May 23 2014, 11:47 PM