This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG7fc150309d27: [analyzer] Bifurcate on getenv() calls (authored by steakhal). Herald added a project: clang. Herald added a subscriber: cfe-commits.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D111245/new/ https://reviews.llvm.org/D111245 Files: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp clang/test/Analysis/std-c-library-functions.c Index: clang/test/Analysis/std-c-library-functions.c =================================================================== --- clang/test/Analysis/std-c-library-functions.c +++ clang/test/Analysis/std-c-library-functions.c @@ -254,3 +254,11 @@ f = ispunct; clang_analyzer_eval(f('A')); // expected-warning{{FALSE}} } + +char *getenv(const char *name); +void test_getenv() { + // getenv() bifurcates here. + clang_analyzer_eval(getenv("FOO") == 0); + // expected-warning@-1 {{TRUE}} + // expected-warning@-2 {{FALSE}} +} Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp @@ -1433,6 +1433,14 @@ RetType{Ssize_tTy}), GetLineSummary); + // char *getenv(const char *name); + addToFunctionSummaryMap( + "getenv", Signature(ArgTypes{ConstCharPtrTy}, RetType{CharPtrTy}), + Summary(NoEvalCall) + .Case({NotNull(Ret)}) + .Case({NotNull(Ret)->negate()}) + .ArgConstraint(NotNull(ArgNo(0)))); + if (ModelPOSIX) { // long a64l(const char *str64);
Index: clang/test/Analysis/std-c-library-functions.c =================================================================== --- clang/test/Analysis/std-c-library-functions.c +++ clang/test/Analysis/std-c-library-functions.c @@ -254,3 +254,11 @@ f = ispunct; clang_analyzer_eval(f('A')); // expected-warning{{FALSE}} } + +char *getenv(const char *name); +void test_getenv() { + // getenv() bifurcates here. + clang_analyzer_eval(getenv("FOO") == 0); + // expected-warning@-1 {{TRUE}} + // expected-warning@-2 {{FALSE}} +} Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp @@ -1433,6 +1433,14 @@ RetType{Ssize_tTy}), GetLineSummary); + // char *getenv(const char *name); + addToFunctionSummaryMap( + "getenv", Signature(ArgTypes{ConstCharPtrTy}, RetType{CharPtrTy}), + Summary(NoEvalCall) + .Case({NotNull(Ret)}) + .Case({NotNull(Ret)->negate()}) + .ArgConstraint(NotNull(ArgNo(0)))); + if (ModelPOSIX) { // long a64l(const char *str64);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits