[clang] [LifetimeSafety] Handle escape through assignment to global storage (PR #181646)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 3 02:36:37 PST 2026


================
@@ -469,11 +470,19 @@ void FactsGenerator::handleFullExprCleanup(
 }
 
 void FactsGenerator::handleExitBlock() {
----------------
usx95 wrote:

> Any assignment of stack memory to a global variable is treated as a potential dangle. This was my initial approach, but @usx95 and I decided that this was too strict.

The thing that Gábor mentions is different from the initial approach. It is less related to assignments themselves than how we model escapes associated with function calls. The call `save_global();` is key here and is responsible for the escape. 

The way we can do this is to associate a global escape to all function calls. This also generalises well for field escapes happening through member function calls (all member calls escape the pointer fields). In this model, EscapeFacts can be associated with some severity (strict and permissive) and we can diagnose accordingly.

That said, I think this belongs to a separate PR. 

https://github.com/llvm/llvm-project/pull/181646


More information about the cfe-commits mailing list