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

Benedek Kaibas via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 1 02:37:48 PST 2026


================
@@ -559,9 +559,15 @@ static PathDiagnosticLocation getLocationForCaller(const StackFrame *SF,
     return PathDiagnosticLocation::createEnd(Dtor.getBindTemporaryExpr(), SM,
                                              CallerSF);
   }
+  case CFGElement::CleanupFunction: {
+    // The cleanup call is implicit and runs when the variable goes out of
+    // scope, so anchor it at the end of the trigger statement.
+    const auto &Cleanup = Source.castAs<CFGCleanupFunction>();
+    return PathDiagnosticLocation::createEnd(Cleanup.getTriggerStmt(), SM,
+                                             CallerSF);
+  }
   case CFGElement::ScopeBegin:
   case CFGElement::ScopeEnd:
-  case CFGElement::CleanupFunction:
     llvm_unreachable("not yet implemented!");
----------------
benedekaibas wrote:

So now the `llvm_unreachable("not yet implemented!");` will be under `ScopeEnd`. Is that correct? I think the "not yet implemented" is not correct for `ScopeBegin` and `ScopeEnd`. These CFG elements cannot be call sites they are just markers for the scope. `LoopExit` already has `llvm_unreachable("CFGElement kind should not be on callsite!");` which is what we should have here as well.

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


More information about the cfe-commits mailing list