Do not assume SymbolRegionValues live after their regions have direct bindings
http://llvm.org/bugs/show_bug.cgi?id=20563
Details
- Reviewers
krememek zaks.anna jordan_rose
Diff Detail
Event Timeline
Hm, yes, this would make sense. It's still not complete because things can remove bindings from the Store, which does not make formerly invalid symbols valid again. But it still seems like a strict improvement over the base. Thanks!
Please add some test cases, following the examples in test/Analysis.
lib/StaticAnalyzer/Core/SymbolManager.cpp | ||
---|---|---|
451–452 | Please reformat to be two separate lines. We try not to break before . when we can help it. |
Thank you Jordan. You're right, I have missed something. But it seems to be not so trivial.
I really don't want states tracking liveness information—for one, you never remove this information even after the symbol is marked dead. Moreover, this still wouldn't handle removing a binding, nor would it handle binding to an entire aggregate region (i.e. what happens for struct assignment). I think the most-semantically-correct thing to do would be to ask the Store to refetch the value of the region, but that's not too cheap. Maybe we just need a new API to ask "are there any bindings to this region or any of its super-regions?".
Thank you Jordan. Sorry for delay.
As I understand, a first revision of this patch has two problems:
- It doesn't care about bindings to parent regions.
- It misses a situation where a binding is added and removed before dead symbols removal.
And the second revision is broken completely.
Your idea is good since it solves the first problem but its implementation will take some time. And currently I have no ideas about a nice fix for the second problem.
I'd be okay with committing the original change as a partial measure. Who knows when any of us will get around to implementing something more complete? But I'll let you make that call.
While investigating http://reviews.llvm.org/D12726 , i accidentally came up with a way to test this patch; with the extension of ExprInspectionChecker in the aforementioned review, which allows testing SymbolReaper directly, the following test passes as soon as the old (accepted) version of this diff is applied:
void clang_analyzer_warnOnDeadSymbol(int); void clang_analyzer_warnIfReached(void); // SymbolRegionValue should live as long as its region is live but has no // direct bindings that override its value. void test_region_value_lifetime_after_binding(int x) { clang_analyzer_warnOnDeadSymbol(x); if (x) {} x = 0; (void)0; // expected-warning{{SYMBOL DEAD}} if (x) { clang_analyzer_warnIfReached(); // no-warning } } // no-warning
Please reformat to be two separate lines. We try not to break before . when we can help it.