[clang] [LifetimeSafety] Add report on misuse of clang::noescape (PR #177260)

Baranov Victor via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 25 08:06:00 PST 2026


================
@@ -2927,6 +2927,17 @@ class LifetimeSafetyReporterImpl : public LifetimeSafetyReporter {
         << EscapeExpr->getSourceRange();
   }
 
+  void reportNoescapeViolation(const ParmVarDecl *ParmWithNoescape,
+                               const Expr *EscapeExpr) override {
+    S.Diag(ParmWithNoescape->getBeginLoc(),
----------------
vbvictor wrote:

> Does this work when the attribute is behind a macro?

Currently no, `FIX-IT unable to apply suggested code changes in a macro`

> Also, what about other spellings of the attribute like __attribute__((....))?

It only removes `noescape` part, which makes `__attribute__(())`. It compiles but clearly this isn't good code. So we need to adjust for this spelling too.

If I try to make robust fixes, I think the patch will bloat too much with just fixit logic, maybe its is better to handle in a follow-up patch, WDYT? If that is the case, I will undo all fixits for now.  

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


More information about the cfe-commits mailing list