[clang] [clang][analyzer] fix false positive of BlockInCriticalSectionChecker (PR #127049)

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 13 07:57:10 PST 2025


================
@@ -315,16 +342,54 @@ bool BlockInCriticalSectionChecker::isBlockingInCritSection(
 void BlockInCriticalSectionChecker::checkPostCall(const CallEvent &Call,
                                                   CheckerContext &C) const {
   if (isBlockingInCritSection(Call, C)) {
+    // for 'read' and 'recv' call, check whether it's file descriptor(first
+    // argument) is
+    // created by 'open' API with O_NONBLOCK flag or is equal to -1, they will
+    // not cause block in these situations, don't report
+    StringRef FuncName = Call.getCalleeIdentifier()->getName();
+    if (FuncName == "read" || FuncName == "recv") {
----------------
steakhal wrote:

Why don't we use CallDescriptions here?
For example, we could split the BlockingFunctions into 3 parts: read call, recv call, and the rest of the blocking calls.

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


More information about the cfe-commits mailing list