[PATCH] D66806: [LifetimeAnalysis] Fix some false positives

Gábor Horváth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 27 08:31:05 PDT 2019


xazax.hun created this revision.
xazax.hun added reviewers: gribozavr, mgehre.
xazax.hun added a project: clang.
Herald added subscribers: Szelethus, Charusso, gamesh411, dkrupp, rnkovacs.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66806

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/Sema/warn-lifetime-analysis-nocfg.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66806.217411.patch
Type: text/x-patch
Size: 7791 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190827/2524bafc/attachment.bin>


More information about the cfe-commits mailing list