https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/179309
>From fa3fafccc24189259cd0f7d0d78873905e21797b Mon Sep 17 00:00:00 2001 From: Utkarsh Saxena <[email protected]> Date: Mon, 2 Feb 2026 19:16:30 +0000 Subject: [PATCH] Reorganise permissive and strict diagnostic groups --- clang/include/clang/Basic/DiagnosticGroups.td | 69 ++++++++++++++++--- .../clang/Basic/DiagnosticSemaKinds.td | 17 ++--- 2 files changed, 65 insertions(+), 21 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 2d89b71d52d96..c0f559a8ee5c4 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -533,36 +533,65 @@ def Dangling : DiagGroup<"dangling", [DanglingAssignment, DanglingGsl, ReturnStackAddress]>; -def LifetimeSafetyDanglingField : DiagGroup<"lifetime-safety-dangling-field"> { +// Use-After-Scope +def LifetimeSafetyUseAfterScope : DiagGroup<"lifetime-safety-use-after-scope"> { + code Documentation = [{ +Warning to detect dangling referenecs introduced by use-after-scope. + }]; +} +def LifetimeSafetyUseAfterScopeMoved : DiagGroup<"lifetime-safety-use-after-scope-moved"> { code Documentation = [{ - Warning to detect dangling field references. +Warning to detect dangling referenecs introduced by use-after-scope. +This may contain false-positives, e.g. when the borrowed storage is potentially moved and is not destroyed at scope exit. }]; } -def LifetimeSafetyDanglingFieldStrict : DiagGroup<"lifetime-safety-dangling-field-strict"> { +// Return-Stack-Address (aka Use-After-Return) +def LifetimeSafetyReturnStackAddr : DiagGroup<"lifetime-safety-return-stack-addr"> { + code Documentation = [{ +Warning to detect use-after-return introduced by returning stack address. + }]; +} +def LifetimeSafetyReturnStackAddrMoved : DiagGroup<"lifetime-safety-return-stack-addr-moved"> { code Documentation = [{ - Warning to detect dangling field references. - This may contain false-positives, e.g. when the borrowed storage is potentially moved and is not destroyed at function exit. +Warning to detect use-after-return introduced by returning stack address. +This may contain false-positives, e.g. when the borrowed storage is potentially moved and is not destroyed at function exit. }]; } +// Dangling-Field (aka Escape-To-Field) +def LifetimeSafetyDanglingField : DiagGroup<"lifetime-safety-dangling-field"> { + code Documentation = [{ +Warning to detect dangling field references. + }]; +} +def LifetimeSafetyDanglingFieldMoved : DiagGroup<"lifetime-safety-dangling-field-moved"> { + code Documentation = [{ +Warning to detect dangling field references. +This may contain false-positives, e.g. when the borrowed storage is potentially moved and is not destroyed at function exit. + }]; +} def LifetimeSafetyInvalidation : DiagGroup<"lifetime-safety-invalidation"> { code Documentation = [{ - Warning to detect invalidation of references. +Warning to detect invalidation of references. }]; } def LifetimeSafetyPermissive : DiagGroup<"lifetime-safety-permissive", - [LifetimeSafetyDanglingField]>; + [LifetimeSafetyUseAfterScope, + LifetimeSafetyReturnStackAddr, + LifetimeSafetyDanglingField]>; def LifetimeSafetyStrict : DiagGroup<"lifetime-safety-strict", - [LifetimeSafetyDanglingFieldStrict, + [LifetimeSafetyUseAfterScopeMoved, + LifetimeSafetyReturnStackAddrMoved, + LifetimeSafetyDanglingFieldMoved, LifetimeSafetyInvalidation]>; def LifetimeSafety : DiagGroup<"lifetime-safety", [LifetimeSafetyPermissive, LifetimeSafetyStrict]> { code Documentation = [{ - Warnings to detect use-after-free and related temporal safety bugs based on lifetime safety analysis. +Warnings to detect use-after-free and related temporal safety bugs based on lifetime safety analysis. }]; } @@ -575,13 +604,31 @@ def LifetimeSafetySuggestions [LifetimeSafetyCrossTUSuggestions, LifetimeSafetyIntraTUSuggestions]> { code Documentation = [{ - Lifetime annotation suggestions for function parameters that should be marked [[clang::lifetimebound]] based on lifetime analysis. +Lifetime annotation suggestions for function parameters that should be marked [[clang::lifetimebound]] based on lifetime analysis. }]; } + def LifetimeSafetyNoescape : DiagGroup<"lifetime-safety-noescape"> { code Documentation = [{ - Detects misuse of [[clang::noescape]] annotation where the parameter escapes (for example, through return). +Detects misuse of [[clang::noescape]] annotation where the parameter escapes (for example, through return). + }]; +} + +def LifetimeSafetyValidations : DiagGroup<"lifetime-safety-validations", + [LifetimeSafetyNoescape]> { + code Documentation = [{ +Verify function implementations adhere to the annotated lifetime contracts through lifetime safety +like verifying [[clang::noescape]] and [[clang::lifetimebound]] (upcoming). + }]; +} + +def LifetimeSafetyAll : DiagGroup<"lifetime-safety-all", + [LifetimeSafety, + LifetimeSafetySuggestions, + LifetimeSafetyValidations]> { + code Documentation = [{ +Turns on all the warnings in the lifetime-safety umbrella. }]; } diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index b72bdfb175b12..643cef29ab6f4 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10812,24 +10812,21 @@ def warn_dangling_reference_captured_by_unknown : Warning< // Diagnostics based on the Lifetime safety analysis. def warn_lifetime_safety_loan_expires_permissive : Warning< "object whose reference is captured does not live long enough">, - InGroup<LifetimeSafetyPermissive>, DefaultIgnore; -def warn_lifetime_safety_loan_expires_strict : Warning< - "object whose reference is captured may not live long enough">, - InGroup<LifetimeSafetyStrict>, DefaultIgnore; -def warn_lifetime_safety_loan_expires_moved_strict : Warning< + InGroup<LifetimeSafetyUseAfterScope>, DefaultIgnore; +def warn_lifetime_safety_loan_expires_moved : Warning< "object whose reference is captured may not live long enough. " "This could be false positive as the storage may have been moved later">, - InGroup<LifetimeSafetyStrict>, DefaultIgnore; + InGroup<LifetimeSafetyUseAfterScopeMoved>, DefaultIgnore; def warn_lifetime_safety_return_stack_addr_permissive : Warning<"address of stack memory is returned later">, - InGroup<LifetimeSafetyPermissive>, + InGroup<LifetimeSafetyReturnStackAddr>, DefaultIgnore; -def warn_lifetime_safety_return_stack_addr_moved_strict +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<LifetimeSafetyStrict>, + InGroup<LifetimeSafetyReturnStackAddrMoved>, DefaultIgnore; def warn_lifetime_safety_invalidation @@ -10845,7 +10842,7 @@ def warn_lifetime_safety_dangling_field_moved : Warning<"address of stack memory escapes to a field. " "This could be a false positive as the storage may have been moved. " "Consider moving first and then aliasing later to resolve the issue">, - InGroup<LifetimeSafetyDanglingFieldStrict>, + InGroup<LifetimeSafetyDanglingFieldMoved>, DefaultIgnore; def note_lifetime_safety_used_here : Note<"later used here">; _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
