[PATCH] D140387: [clang][analyzer] Add stream related functions to StdLibraryFunctionsChecker.

Balázs Kéri via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 4 07:21:43 PST 2023


balazske added inline comments.


================
Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:838
+  Result += getArgDesc(ArgN);
+  Result += DK == Violation ? " should not be zero" : " is not zero";
+  return Result.c_str();
----------------
Szelethus wrote:
> balazske wrote:
> > Szelethus wrote:
> > > I don't mean to make you test every single `Case` or `ArgumentConstraint` you added, but `NotZeroConstraint` is brand new, and is not tested anywhere.
> > This new class is probably not needed at all. It is always possible to use `ReturnValueCondition(WithinRange, SingleValue(0))` or similar for nonzero cases.
> Convenience is a good enough reason. Please test this before commiting.
There was no exact test for the return value condition. A following test function can be added:
```
    addToFunctionSummaryMap(
        "__test_return_note",
        Signature(ArgTypes{}, RetType{IntTy}),
        Summary(EvalCallAsPure)
            .Case({ReturnValueCondition(WithinRange, SingleValue(0))}, ErrnoIrrelevant, "Test return 0")
            .Case({ReturnValueCondition(WithinRange, SingleValue(1))}, ErrnoIrrelevant, "Test return 1")
            );
```
And add this to std-c-library-functions-arg-constraints-note-tags.cpp:
```
int __test_return_note();
int test_return_constraint_note(int y) {
  int x = __test_return_note(); // expected-note{{Test return 0}} \
                                // expected-note{{'x' initialized here}}
  return y / x;       // expected-warning{{Division by zero}} \
                      // expected-note{{Division by zero}}
}
```



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140387



More information about the cfe-commits mailing list