Author: Gábor Horváth Date: 2026-11-27T09:23:39Z New Revision: 27e531715ac6d3a1e8e8a6444ed5d511c881ef93
URL: https://github.com/llvm/llvm-project/commit/27e531715ac6d3a1e8e8a6444ed5d511c881ef93 DIFF: https://github.com/llvm/llvm-project/commit/27e531715ac6d3a1e8e8a6444ed5d511c881ef93.diff LOG: [LifetimeSafety] Skip unreachable predecessors when building origin flow chains (#246581) Added: Modified: clang/lib/Analysis/LifetimeSafety/LoanPropagation.cpp clang/test/Sema/LifetimeSafety/dangling-global.cpp Removed: ################################################################################ diff --git a/clang/lib/Analysis/LifetimeSafety/LoanPropagation.cpp b/clang/lib/Analysis/LifetimeSafety/LoanPropagation.cpp index 58979bbcfd5cee..732274d2e1f730 100644 --- a/clang/lib/Analysis/LifetimeSafety/LoanPropagation.cpp +++ b/clang/lib/Analysis/LifetimeSafety/LoanPropagation.cpp @@ -220,6 +220,8 @@ class AnalysisImpl // Only explore predecessor blocks where the target loan is present in the // current origin. for (const CFGBlock *PredBlock : CurrBlock->preds()) { + if (!PredBlock) + continue; SearchState NextState = {PredBlock, CurrOID}; if (getLoans(getOutState(PredBlock), CurrOID).contains(TargetLoan) && VistedStates.insert(NextState).second) diff --git a/clang/test/Sema/LifetimeSafety/dangling-global.cpp b/clang/test/Sema/LifetimeSafety/dangling-global.cpp index 0b4f79a562d031..2d3bf2638c8aee 100644 --- a/clang/test/Sema/LifetimeSafety/dangling-global.cpp +++ b/clang/test/Sema/LifetimeSafety/dangling-global.cpp @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -Wlifetime-safety -Wno-dangling -verify %s #include "Inputs/lifetime-analysis.h" -int *global; // expected-note 11 {{this global dangles}} +int *global; // expected-note 12 {{this global dangles}} int *global_backup; // expected-note {{this global dangles}} std::string_view global_view; // expected-note 2 {{this global dangles}} @@ -194,6 +194,14 @@ void store_local_in_global_but_moved(std::string s){ takeString(std::move(s)); //expected-note {{potentially moved here}} } +// The constant condition prunes the false edge, leaving a null predecessor. +void store_local_in_global_under_constant_condition() { + if (6) { + int local; + global = &local; // expected-warning {{stack memory associated with local variable 'local' escapes to the global variable 'global' which will dangle}} + } +} + int main() { int local = 0; global = &local; // expected-warning {{stack memory associated with local variable 'local' escapes to the global variable 'global' which will dangle after main returns}} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
