================
@@ -1393,6 +1395,46 @@ void ExprEngine::ProcessAutomaticObjDtor(const 
CFGAutomaticObjDtor Dtor,
                      /*IsBase=*/false, Pred, Dst, CallOpts);
 }
 
+void ExprEngine::ProcessCleanupFunction(const CFGCleanupFunction Cleanup,
+                                        ExplodedNode *Pred) {
+  const VarDecl *VD = Cleanup.getVarDecl();
+  const FunctionDecl *FD = Cleanup.getFunctionDecl();
+
+  ProgramStateRef State = Pred->getState();
+  const StackFrame *SF = Pred->getStackFrame();
+
+  // The implicit f(&var) call is not written in the source; anchor it at the
+  // function name in the cleanup attribute.
+  static SimpleProgramPointTag PT("ExprEngine",
+                                  "Prepare for cleanup function call");
+  PreImplicitCall PP(FD, VD->getAttr<CleanupAttr>()->getLoc(), SF,
+                     getCFGElementRef(), &PT);
+  Pred = Engine.makeNode(PP, State, Pred);
+
+  if (!Pred)
+    return;
+
+  CallEventManager &CEMgr = getStateManager().getCallEventManager();
+  CallEventRef<CleanupFunctionCall> Call = CEMgr.getCleanupFunctionCall(
+      FD, VD, Pred->getState(), SF, getCFGElementRef());
+
+  PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),
+                                Call->getSourceRange().getBegin(),
+                                "Error evaluating cleanup function");
+
+  ExplodedNodeSet Dst;
+  ExplodedNodeSet DstPreCall;
+  getCheckerManager().runCheckersForPreCall(DstPreCall, Pred, *Call, *this);
+
+  ExplodedNodeSet DstInvalidated;
+  for (ExplodedNode *N : DstPreCall)
+    defaultEvalCall(DstInvalidated, N, *Call);
----------------
PengZheng wrote:

The cleanup function receives the address of the variable. The functions 
modeled by EvalCall checkers don't fit that signature directly. All real-world 
usages I have in mind are covered with `defaultEvalCall`:

https://github.com/apache/celix/blob/master/libs/utils/include/celix_cleanup.h
https://github.com/apache/celix/blob/master/libs/utils/include/celix_stdio_cleanup.h
https://github.com/apache/celix/blob/master/libs/utils/include/celix_stdlib_cleanup.h
https://github.com/apache/celix/blob/master/libs/utils/include/celix_unistd_cleanup.h

https://github.com/llvm/llvm-project/pull/221110
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to