r368501 - Fix a false positive warning when initializing members with gsl::Owners.

Nico Weber via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 10 11:53:09 PDT 2019


Up to you :)

On Fri, Aug 9, 2019 at 8:54 PM Gábor Horváth <xazax.hun at gmail.com> wrote:

> It does! Do you want me to commit that test as well?
>
> On Fri, 9 Aug 2019 at 17:50, Nico Weber <thakis at chromium.org> wrote:
>
>> This fixes `+  X(std::unique_ptr<int> up) : pointee(up.get()),
>> pointer(std::move(up)) {}` as well, right?
>>
>> On Fri, Aug 9, 2019 at 8:31 PM Gabor Horvath via cfe-commits <
>> cfe-commits at lists.llvm.org> wrote:
>>
>>> Author: xazax
>>> Date: Fri Aug  9 17:32:29 2019
>>> New Revision: 368501
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=368501&view=rev
>>> Log:
>>> Fix a false positive warning when initializing members with gsl::Owners.
>>>
>>> Modified:
>>>     cfe/trunk/lib/Sema/SemaInit.cpp
>>>     cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg.cpp
>>>
>>> Modified: cfe/trunk/lib/Sema/SemaInit.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=368501&r1=368500&r2=368501&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/lib/Sema/SemaInit.cpp (original)
>>> +++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Aug  9 17:32:29 2019
>>> @@ -7217,6 +7217,11 @@ void Sema::checkInitializerLifetime(cons
>>>          if (pathContainsInit(Path))
>>>            return false;
>>>
>>> +        // Suppress false positives for code like the below:
>>> +        //   Ctor(unique_ptr<T> up) : member(*up), member2(move(up)) {}
>>> +        if (IsLocalGslOwner && pathOnlyInitializesGslPointer(Path))
>>> +          return false;
>>> +
>>>          auto *DRE = dyn_cast<DeclRefExpr>(L);
>>>          auto *VD = DRE ? dyn_cast<VarDecl>(DRE->getDecl()) : nullptr;
>>>          if (!VD) {
>>>
>>> Modified: cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg.cpp?rev=368501&r1=368500&r2=368501&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg.cpp (original)
>>> +++ cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg.cpp Fri Aug  9
>>> 17:32:29 2019
>>> @@ -120,6 +120,13 @@ void initLocalGslPtrWithTempOwner() {
>>>  }
>>>
>>>  namespace std {
>>> +template<class T> struct remove_reference       { typedef T type; };
>>> +template<class T> struct remove_reference<T &>  { typedef T type; };
>>> +template<class T> struct remove_reference<T &&> { typedef T type; };
>>> +
>>> +template<class T>
>>> +typename remove_reference<T>::type &&move(T &&t) noexcept;
>>> +
>>>  template <typename T>
>>>  struct basic_iterator {
>>>    basic_iterator operator++();
>>> @@ -153,6 +160,7 @@ struct basic_string {
>>>
>>>  template<typename T>
>>>  struct unique_ptr {
>>> +  T &operator*();
>>>    T *get() const;
>>>  };
>>>
>>> @@ -217,3 +225,10 @@ int &doNotFollowReferencesForLocalOwner(
>>>  const char *trackThroughMultiplePointer() {
>>>    return
>>> std::basic_string_view<char>(std::basic_string<char>()).begin(); //
>>> expected-warning {{returning address of local temporary object}}
>>>  }
>>> +
>>> +struct X {
>>> +  X(std::unique_ptr<int> up) : pointee(*up), pointer(std::move(up)) {}
>>> +
>>> +  int &pointee;
>>> +  std::unique_ptr<int> pointer;
>>> +};
>>>
>>>
>>> _______________________________________________
>>> cfe-commits mailing list
>>> cfe-commits at lists.llvm.org
>>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190810/ad0e5071/attachment-0001.html>


More information about the cfe-commits mailing list