This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] [proposal] Fix for PR20653
Needs ReviewPublic

Authored by a.sidorin on Aug 28 2014, 8:45 AM.

Details

Summary

Do not assume SymbolRegionValues live after their regions have direct bindings
http://llvm.org/bugs/show_bug.cgi?id=20563

Diff Detail

Event Timeline

a.sidorin updated this revision to Diff 13040.Aug 28 2014, 8:45 AM
a.sidorin retitled this revision from to [analyzer] [proposal] Fix for PR20653.
a.sidorin updated this object.
a.sidorin edited the test plan for this revision. (Show Details)
a.sidorin added a subscriber: Unknown Object (MLST).
jordan_rose edited edge metadata.Sep 3 2014, 7:13 PM

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.

a.sidorin updated this revision to Diff 13375.Sep 7 2014, 11:57 AM
a.sidorin updated this object.
a.sidorin edited edge metadata.

Check if a region changes instead of look up if a region has bindings.

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:

  1. It doesn't care about bindings to parent regions.
  2. 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.

NoQ added a subscriber: NoQ.Oct 13 2015, 9:59 AM

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