https://github.com/aeft created https://github.com/llvm/llvm-project/pull/240176
None >From 91df46c1ab362ce21324ade7729c3e60e47a7165 Mon Sep 17 00:00:00 2001 From: Zhijie Wang <[email protected]> Date: Sun, 8 Nov 2026 09:48:35 -0800 Subject: [PATCH] [LifetimeSafety] Look through parentheses on the object of a member call --- clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp | 4 ++-- clang/test/Sema/LifetimeSafety/invalidations.cpp | 8 ++++---- clang/test/Sema/LifetimeSafety/safety.cpp | 8 ++++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp b/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp index 589082a0dcd9d1..7254413151c2bd 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 bdeb309d89973e..20a59355e24dad 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 e3e228233f7988..42ad9101c13da6 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_ = # // 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 { _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
