[clang] [LifetimeSafety] Add details for `-Wlifetime-safety-return-stack-addr` diagnostic (PR #199432)

via cfe-commits cfe-commits at lists.llvm.org
Sun May 24 12:38:17 PDT 2026


================
@@ -10967,16 +10967,27 @@ def warn_lifetime_safety_use_after_free : Warning<
     "%select{allocated object|parameter}0 does not live long enough">,
     InGroup<LifetimeSafetyUseAfterFree>, DefaultIgnore;
 
-def warn_lifetime_safety_return_stack_addr
-    : Warning<"address of stack memory is returned later">,
-      InGroup<LifetimeSafetyReturnStackAddr>,
-      DefaultIgnore;
-def warn_lifetime_safety_return_stack_addr_moved
-    : Warning<"address of stack memory may be returned later. "
-      "This could be false positive as the storage may have been moved. "
-      "Consider moving first and then aliasing later to resolve the issue">,
-      InGroup<LifetimeSafetyReturnStackAddrMoved>,
-      DefaultIgnore;
+def warn_lifetime_safety_return_stack_addr : Warning<
+  "%select{address of|reference to}0 stack memory associated with "
+  "%select{local variable|parameter}2 %1 returned">,
+  InGroup<LifetimeSafetyReturnStackAddr>, DefaultIgnore;
----------------
NeKon69 wrote:

>From my very limited experience, what I don’t really like about doing this is that it’s hard to understand how a message will actually look just from looking at the diagnostic definition.

Maybe we could instead create an enum for each of the parameters where you have to select an option? The thing I don’t like about that approach is that we’d end up with a lot of enums. Or maybe there's a different reason you prefer this direct string approach?

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


More information about the cfe-commits mailing list