[clang] [clang][analyzer] Teach the BlockInCriticalSectionChecker about O_NONBLOCK streams (PR #127049)
Gábor Horváth via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 17 04:11:14 PST 2025
================
@@ -337,6 +391,28 @@ void BlockInCriticalSectionChecker::reportBlockInCritSection(
<< "' inside of critical section";
auto R = std::make_unique<PathSensitiveBugReport>(BlockInCritSectionBugType,
os.str(), ErrNode);
+ // 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") {
+ SVal SV = Call.getArgSVal(0);
+ SValBuilder &SVB = C.getSValBuilder();
+ ProgramStateRef state = C.getState();
+ ConditionTruthVal CTV =
+ state->areEqual(SV, SVB.makeIntVal(-1, C.getASTContext().IntTy));
+ if (CTV.isConstrainedTrue())
+ return;
+
+ if (SymbolRef SR = SV.getAsSymbol()) {
+ if (!O_NONBLOCKValue)
+ O_NONBLOCKValue = tryExpandAsInteger(
----------------
Xazax-hun wrote:
Oh, I completely missed that! Sorry! :)
https://github.com/llvm/llvm-project/pull/127049
More information about the cfe-commits
mailing list