[clang] [LifetimeSafety] Support C Language in LifetimeSafety (PR #203270)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 15 07:06:51 PDT 2026
================
@@ -27,6 +27,11 @@ namespace clang::lifetimes {
inline bool IsLifetimeSafetyEnabled(Sema &S, const Decl *D) {
if (S.getLangOpts().DebugRunLifetimeSafety)
return true;
+ // TODO: Enable ObjectiveC later when we know it's stable enough.
+ if (S.getLangOpts().ObjC)
+ return false;
----------------
usx95 wrote:
TU mode and non-TU mode should be exclusive. E.g. currently `DebugRunLifetimeSafety` would run both the modes. I think we can further absorb the remaining `EnableLifetimeSafetyTUAnalysis` check:
```cpp
inline bool IsLifetimeSafetyEnabled(Sema &S, const Decl *D) {
// TODO: Enable ObjectiveC later when we know it's stable enough.
if (S.getLangOpts().ObjC)
return false;
// Translation-unit mode: whole-program analysis runs once on TU.
// Individual function analysis is disabled when TU mode is enabled.
if (S.getLangOpts().EnableLifetimeSafetyTUAnalysis)
return isa<TranslationUnitDecl>(D);
// Per-function mode: analysis runs on each function/method individually.
// Skip TU-level calls when per-function mode is enabled.
if (isa<TranslationUnitDecl>(D))
return false;
// Enable per-function mode via debug flag or specific diagnostics
if (S.getLangOpts().DebugRunLifetimeSafety)
return true;
// ... rest of diagnostic checks
}
```
This is complicated :) but atleast these keeps the complicated bits in one place.
You can then remove the TU check in non-TU mode.
`bool EnableLifetimeSafetyAnalysis = lifetimes::IsLifetimeSafetyEnabled(S, D);`
https://github.com/llvm/llvm-project/pull/203270
More information about the cfe-commits
mailing list