https://github.com/benshi001 updated https://github.com/llvm/llvm-project/pull/76557
>From 2eebb462b8a7865684d3baaffbad7560eed10e57 Mon Sep 17 00:00:00 2001 From: Ben Shi <benn...@tencent.com> Date: Fri, 29 Dec 2023 16:44:47 +0800 Subject: [PATCH 1/3] [clang][analyzer] Support 'fflush' in the StdLibraryFunctionsChecker --- .../Checkers/StdLibraryFunctionsChecker.cpp | 8 ++++++ clang/test/Analysis/stream-errno.c | 26 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp index fffcaf7ed18fb7..4ca49b9c0546d9 100644 --- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp @@ -2244,6 +2244,14 @@ void StdLibraryFunctionsChecker::initFunctionSummaries( .ArgConstraint(NotNull(ArgNo(0))) .ArgConstraint(NotNull(ArgNo(1)))); + // int fflush(FILE *stream); + addToFunctionSummaryMap( + "fflush", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}), + Summary(NoEvalCall) + .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg) + .Case({ReturnValueCondition(WithinRange, SingleValue(EOFv))}, + ErrnoNEZeroIrrelevant, GenericFailureMsg)); + // long ftell(FILE *stream); // From 'The Open Group Base Specifications Issue 7, 2018 edition': // "The ftell() function shall not change the setting of errno if diff --git a/clang/test/Analysis/stream-errno.c b/clang/test/Analysis/stream-errno.c index bf0a61db2424f9..d52480741d4cd1 100644 --- a/clang/test/Analysis/stream-errno.c +++ b/clang/test/Analysis/stream-errno.c @@ -222,3 +222,29 @@ void check_fileno(void) { } if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}} } + +void check_fflush_0(void) { + FILE *F = tmpfile(); + if (!F) + return; + int N = fflush(F); + if (N == EOF) { + clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}} + if (errno) {} // no-warning + } else { + clang_analyzer_eval(N == 0); // expected-warning{{TRUE}} + if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}} + } + fclose(F); +} + +void check_fflush_1(void) { + int N = fflush(NULL); + if (N == 0) { + if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}} + } else { + clang_analyzer_eval(N == EOF); // expected-warning{{TRUE}} + clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}} + if (errno) {} // no-warning + } +} >From 3c0f61c3d317e2c4bcff77532677b68c9bc0e01a Mon Sep 17 00:00:00 2001 From: Balazs Benics <benicsbal...@gmail.com> Date: Fri, 29 Dec 2023 11:01:01 +0100 Subject: [PATCH 2/3] Update the release notes --- clang/docs/ReleaseNotes.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 3c08d1808b0e7f..2d5391702385a7 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -1126,9 +1126,11 @@ Improvements ^^^^^^^^^^^^ - Improved the ``unix.StdCLibraryFunctions`` checker by modeling more - functions like ``send``, ``recv``, ``readlink`` and ``errno`` behavior. + functions like ``send``, ``recv``, ``readlink``, ``fflush`` and + ``errno`` behavior. (`52ac71f92d38 <https://github.com/llvm/llvm-project/commit/52ac71f92d38f75df5cb88e9c090ac5fd5a71548>`_, `#71373 <https://github.com/llvm/llvm-project/pull/71373>`_, + `#76557 <https://github.com/llvm/llvm-project/pull/76557>`_, `#71392 <https://github.com/llvm/llvm-project/pull/71392>`_) - Fixed a false negative for when accessing a nonnull property (ObjC). >From f294a949aa5f95e4731fe1bb9d6f51865bc35357 Mon Sep 17 00:00:00 2001 From: Ben Shi <benn...@tencent.com> Date: Fri, 29 Dec 2023 18:21:10 +0800 Subject: [PATCH 3/3] Rename the test function names --- clang/test/Analysis/stream-errno.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/test/Analysis/stream-errno.c b/clang/test/Analysis/stream-errno.c index d52480741d4cd1..f44ee6070708b2 100644 --- a/clang/test/Analysis/stream-errno.c +++ b/clang/test/Analysis/stream-errno.c @@ -223,7 +223,7 @@ void check_fileno(void) { if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}} } -void check_fflush_0(void) { +void check_fflush_opened_file(void) { FILE *F = tmpfile(); if (!F) return; @@ -238,7 +238,7 @@ void check_fflush_0(void) { fclose(F); } -void check_fflush_1(void) { +void check_fflush_all(void) { int N = fflush(NULL); if (N == 0) { if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits