[PATCH] D149160: [clang][analyzer] Handle special value AT_FDCWD in affected standard functions

Balázs Benics via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 26 05:32:15 PDT 2023


steakhal added inline comments.


================
Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:1530-1541
+  // Get platform dependent values of some macros.
+  // Try our best to parse this from the Preprocessor, otherwise fallback to a
+  // default value (what is found in a library header).
+  auto GetMacroValue = [&C](const char *Name, int Default) -> RangeInt {
     if (const std::optional<int> OptInt =
-            tryExpandAsInteger("EOF", C.getPreprocessor()))
+            tryExpandAsInteger(Name, C.getPreprocessor()))
       return *OptInt;
----------------



================
Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:2137-2138
             .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant)
+            .ArgConstraint(ArgumentCondition(
+                0, WithinRange, Range({AT_FDCWDv, AT_FDCWDv}, {0, IntMax})))
             .ArgConstraint(NotNull(ArgNo(1))));
----------------
I think I would recommend hoisting this common subexpression. This would save repetition on subsequent occurrences.

```lang=C++
const auto ValidDescriptorOrAtCWDRange = Range({AT_FDCWDv, AT_FDCWDv}, {0, IntMax});
```

You can explore if hoisting the whole `ArgumentCondition` would make it even more readable.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149160/new/

https://reviews.llvm.org/D149160



More information about the cfe-commits mailing list