Author: Yuan Suo Date: 2026-06-17T04:54:59+02:00 New Revision: 054c8f4082efa2e050861f998e2fbb881b2ad17e
URL: https://github.com/llvm/llvm-project/commit/054c8f4082efa2e050861f998e2fbb881b2ad17e DIFF: https://github.com/llvm/llvm-project/commit/054c8f4082efa2e050861f998e2fbb881b2ad17e.diff LOG: [LifetimeSafety] Add additional test for buildOriginFlowChain (#204124) These are test case improvements suggested in previous PRs. The `simpleparen` case originates from https://github.com/llvm/llvm-project/pull/199345#discussion_r3343186258. Additional unit test improvements were suggested in https://github.com/llvm/llvm-project/pull/196075#discussion_r3274899024. --------- Signed-off-by: Yuan Suo <[email protected]> Added: Modified: clang/test/Sema/LifetimeSafety/safety.cpp clang/unittests/Analysis/LifetimeSafetyTest.cpp Removed: ################################################################################ diff --git a/clang/test/Sema/LifetimeSafety/safety.cpp b/clang/test/Sema/LifetimeSafety/safety.cpp index 56226f954fee3..3c954cebda820 100644 --- a/clang/test/Sema/LifetimeSafety/safety.cpp +++ b/clang/test/Sema/LifetimeSafety/safety.cpp @@ -1250,6 +1250,18 @@ void conditional_operator_lifetimebound_nested_deep(bool cond) { (void)*p; // expected-note 4 {{later used here}} } +// FIXME: Diagnostic output does not handle ParenExpr correctly, causing alias +// information to be missed (local variable 'p' aliases the storage of local variable 'b'). +void simpleparen() { + MyObj* p; + { + MyObj a; + MyObj* b = &a; // expected-warning {{local variable 'a' does not live long enough}} + p = (((b))); + } // expected-note {{destroyed here}} + (void)*p; // expected-note {{later used here}} +} + void parentheses(bool cond) { MyObj* p; { diff --git a/clang/unittests/Analysis/LifetimeSafetyTest.cpp b/clang/unittests/Analysis/LifetimeSafetyTest.cpp index febecb472455a..78b7449958140 100644 --- a/clang/unittests/Analysis/LifetimeSafetyTest.cpp +++ b/clang/unittests/Analysis/LifetimeSafetyTest.cpp @@ -213,7 +213,7 @@ class LifetimeTestHelper { std::vector<LoanID> EndLoanIDs = getLoansForVar(EndLoanVar); for (LoanID LID : EndLoanIDs) { - const llvm::SmallVector<OriginID> OriginFlowChain = + llvm::SmallVector<OriginID> OriginFlowChain = Runner.getAnalysis().getLoanPropagation().buildOriginFlowChain( getProgramPoint(Annotation), *StartOriginID, LID); if (!OriginFlowChain.empty()) @@ -2025,6 +2025,8 @@ TEST_F(LifetimeAnalysisTest, BuildOriginFlowChainWithMultiAssignInSameStmt) { Helper->buildOriginFlowChainInOneBlock("s", "tgt", "after_use"); EXPECT_THAT(OriginFlowChain, Contains(*Helper->getOriginForDecl("a"))); + EXPECT_THAT(OriginFlowChain, Contains(*Helper->getOriginForDecl("b"))); + EXPECT_THAT(OriginFlowChain, Contains(*Helper->getOriginForDecl("c"))); } TEST_F(LifetimeAnalysisTest, BuildOriginFlowChainWithOverwritingAssignments) { @@ -2044,6 +2046,8 @@ TEST_F(LifetimeAnalysisTest, BuildOriginFlowChainWithOverwritingAssignments) { Helper->buildOriginFlowChainInOneBlock("s", "tgt1", "after_use"); EXPECT_THAT(OriginFlowChain, Contains(*Helper->getOriginForDecl("a"))); + EXPECT_THAT(OriginFlowChain, Contains(*Helper->getOriginForDecl("b"))); + EXPECT_THAT(OriginFlowChain, Contains(*Helper->getOriginForDecl("c"))); } TEST_F(LifetimeAnalysisTest, BuildOriginFlowChainWithLifetimeBound) { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
