[clang] [analyzer] Model GCC 'cleanup' attribute function calls (PR #221110)

Arseniy Zaostrovnykh via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 9 06:44:48 PDT 2026


================
@@ -559,9 +559,15 @@ static PathDiagnosticLocation getLocationForCaller(const StackFrame *SF,
     return PathDiagnosticLocation::createEnd(Dtor.getBindTemporaryExpr(), SM,
                                              CallerSF);
   }
+  case CFGElement::CleanupFunction: {
+    const CFGCleanupFunction &Cleanup = Source.castAs<CFGCleanupFunction>();
+    // The implicit call is not written in the source; anchor it at the
+    // function name in the cleanup attribute.
+    const CleanupAttr *A = Cleanup.getVarDecl()->getAttr<CleanupAttr>();
+    return PathDiagnosticLocation(A->getLoc(), SM);
----------------
necto wrote:

is it the function-name location or the attribute construct location?
Either way, a test that puts them on different lines would be helpful to know which one it is
```
    int x
       __attribute__
      ((cleanup(noop_cleanup)));
```

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


More information about the cfe-commits mailing list