llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Zhijie Wang (aeft)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/240176.diff


3 Files Affected:

- (modified) clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp (+2-2) 
- (modified) clang/test/Sema/LifetimeSafety/invalidations.cpp (+4-4) 
- (modified) clang/test/Sema/LifetimeSafety/safety.cpp (+8) 


``````````diff
diff --git a/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp 
b/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp
index 589082a0dcd9d..7254413151c2b 100644
--- a/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp
+++ b/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp
@@ -1024,7 +1024,7 @@ void FactsGenerator::handleInvalidatingCall(const Expr 
*Call,
   // Heuristics to turn-down false positives. Skip member field expressions for
   // now. This is not a perfect filter and will still surface some false
   // positives (e.g. `auto& r = s.v`). Static data members are not fields.
-  const Expr *Obj = Args[0]->IgnoreImpCasts();
+  const Expr *Obj = ignoreParensAndImpCasts(Args[0]);
   if (const auto *ME = dyn_cast<MemberExpr>(Obj);
       !isa<DeclRefExpr>(Obj) && !(ME && isa<VarDecl>(ME->getMemberDecl())))
     return;
@@ -1053,7 +1053,7 @@ void FactsGenerator::handleImplicitObjectFieldUses(const 
Expr *Call,
     return;
 
   if (!isa_and_present<CXXThisExpr>(
-          MemberCall->getImplicitObjectArgument()->IgnoreImpCasts()))
+          ignoreParensAndImpCasts(MemberCall->getImplicitObjectArgument())))
     return;
 
   const auto *MD = dyn_cast<CXXMethodDecl>(FD);
diff --git a/clang/test/Sema/LifetimeSafety/invalidations.cpp 
b/clang/test/Sema/LifetimeSafety/invalidations.cpp
index bdeb309d89973..20a59355e24da 100644
--- a/clang/test/Sema/LifetimeSafety/invalidations.cpp
+++ b/clang/test/Sema/LifetimeSafety/invalidations.cpp
@@ -367,11 +367,11 @@ void 
IteratorInvalidatedThroughPointerParameter(std::vector<int> *v) { // expect
 }
 
 void ParenthesizedContainerInvalidatesIterator() {
-  // FIXME: Support invalidation through non-DRE lvalue expressions.
   std::vector<int> v;
-  auto it = v.begin();
-  (v).push_back(42);
-  use(it);
+  auto it = v.begin(); // expected-warning {{local variable 'v' is later 
invalidated}} \
+                       // expected-note {{result of call to 'begin' aliases 
the storage of local variable 'v'}}
+  (v).push_back(42);   // expected-note {{local variable 'v' is invalidated 
here}}
+  use(it);             // expected-note {{later used here}}
 }
 
 } // namespace InvalidatingThroughContainerAliases
diff --git a/clang/test/Sema/LifetimeSafety/safety.cpp 
b/clang/test/Sema/LifetimeSafety/safety.cpp
index e3e228233f798..42ad9101c13da 100644
--- a/clang/test/Sema/LifetimeSafety/safety.cpp
+++ b/clang/test/Sema/LifetimeSafety/safety.cpp
@@ -4139,6 +4139,14 @@ struct S {
     this->p_ = &GLOBAL_INT;
     bar();
   }
+  void parenthesized_this_call() {
+    {
+      int num;
+      this->p_ = &num; // expected-warning {{local variable 'num' does not 
live long enough}}
+    }                  // expected-note {{local variable 'num' is destroyed 
here}}
+    (this)->bar();     // expected-note {{later used here}}
+    this->p_ = &GLOBAL_INT;
+  }
 };
 
 struct T {

``````````

</details>


https://github.com/llvm/llvm-project/pull/240176
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to