Author: Benedek Kaibas Date: 2026-10-14T12:38:09+02:00 New Revision: dacc1a59a767e8cc5b513c9c3a7d2327cde59f60
URL: https://github.com/llvm/llvm-project/commit/dacc1a59a767e8cc5b513c9c3a7d2327cde59f60 DIFF: https://github.com/llvm/llvm-project/commit/dacc1a59a767e8cc5b513c9c3a7d2327cde59f60.diff LOG: [NFC][analyzer] Remove guaranteedNotToCloseFile from SimpleStreamChecker (#230288) `SimpleStreamChecker` is a "demo checker", a simplified variant of `StreamChecker` which can be used to demonstrate the architecture of a checker without getting bogged down in the technical details. Despite this, the `checkPointerEscape()` callback was more complex in `SimpleStreamChecker` than in `StreamChecker`. (The complex callback in `SimpleStreamChecker` was present since 2012, the simpler callback in `StreamChecker` was only added in 2020.) This commit rectifies this by replacing the logic in `SimpleStreamChecker` with the simpler logic taken from `StreamChecker`. As `SimpleStreamChecker` is just an educational tool and not used in production, the impact of this change is very limited. The motivation for this simplification is that it removes a reference to `CallEvent::argumentsMayEscape()`, which prepares the ground for #225489 to inline that method into `MallocChecker` (the only place where its logic is really useful). Added: Modified: clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp Removed: ################################################################################ diff --git a/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp index 5152624d00f46..c28ed7b1b04a1 100644 --- a/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp @@ -67,8 +67,6 @@ class SimpleStreamChecker : public Checker<check::PostCall, void reportLeaks(ArrayRef<SymbolRef> LeakedStreams, CheckerContext &C, ExplodedNode *ErrNode) const; - bool guaranteedNotToCloseFile(const CallEvent &Call) const; - public: /// Process fopen. void checkPostCall(const CallEvent &Call, CheckerContext &C) const; @@ -195,21 +193,6 @@ void SimpleStreamChecker::reportLeaks(ArrayRef<SymbolRef> LeakedStreams, } } -bool SimpleStreamChecker::guaranteedNotToCloseFile(const CallEvent &Call) const{ - // If it's not in a system header, assume it might close a file. - if (!Call.isInSystemHeader()) - return false; - - // Handle cases where we know a buffer's /address/ can escape. - if (Call.argumentsMayEscape()) - return false; - - // Note, even though fclose closes the file, we do not list it here - // since the checker is modeling the call. - - return true; -} - // If the pointer we are tracking escaped, do not track the symbol as // we cannot reason about it anymore. ProgramStateRef @@ -218,7 +201,7 @@ SimpleStreamChecker::checkPointerEscape(ProgramStateRef State, const CallEvent *Call, PointerEscapeKind Kind) const { // If we know that the call cannot close a file, there is nothing to do. - if (Kind == PSK_DirectEscapeOnCall && guaranteedNotToCloseFile(*Call)) { + if (Kind == PSK_DirectEscapeOnCall && Call->isInSystemHeader()) { return State; } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
