This is an archive of the discontinued LLVM Phabricator instance.

[LifetimeAnalysis] Fix some false positives
ClosedPublic

Authored by xazax.hun on Aug 27 2019, 8:27 AM.

Details

Summary

We should never track if a gsl::Pointer is created from an unannotated type.

For example the code below is definitely buggy:

reference_wrapper<int> f() {
  int i;
  return i; // Invalid!
}

While the code below can be safe:

some_iterator f() {
  MyUnannotatedSpan local = ...;
  return std::begin(local); // this is fine
}

Note that, this problem will be solved once we have function annotations, as each constructor can be annotated what it actually does.

This patch also fixes a false positive from the use of address of operator.

All in all this patch reduces the number of warnings emitted but all it fixes all the false positives we know so far. The added tests with the TODO will be useful once we start to add function annotations and great for documenting the currently known false negatives.

Diff Detail

Event Timeline

xazax.hun created this revision.Aug 27 2019, 8:27 AM

Nice! Having no false-positives is most important because this is enabled by default.

gribozavr accepted this revision.Sep 2 2019, 5:09 AM

Looks like a reasonable way to suppress some false positives. It will suppress some true positives (e.g., imagine an "identity" function that returns the same pointer as was provided to it), but I guess you're aware of that.

This revision is now accepted and ready to land.Sep 2 2019, 5:09 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 3 2019, 9:18 AM