[clang] 570bc5d - Revert "[clang][analyzer] StreamChecker: Model getc, vfscanf, putc, vfprintf (#82476)"
Balazs Benics via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 28 05:10:58 PST 2024
Author: Balazs Benics
Date: 2024-02-28T14:10:22+01:00
New Revision: 570bc5d291f92e19f6264262b02ddff1a2f2e09b
URL: https://github.com/llvm/llvm-project/commit/570bc5d291f92e19f6264262b02ddff1a2f2e09b
DIFF: https://github.com/llvm/llvm-project/commit/570bc5d291f92e19f6264262b02ddff1a2f2e09b.diff
LOG: Revert "[clang][analyzer] StreamChecker: Model getc, vfscanf, putc, vfprintf (#82476)"
This reverts commit ffe7049b543adb9739261d28a60d4a47a00aa2e0.
This commit breaks on e.g. arm:
Example:
https://lab.llvm.org/buildbot/#/builders/245/builds/21177/steps/5/logs/FAIL__Clang__stream_c
```
******************** TEST 'Clang :: Analysis/stream.c' FAILED ********************
Exit Code: 1
Command Output (stderr):
--
RUN: at line 1: /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/lib/clang/19/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core,alpha.unix.Stream,debug.ExprInspection -verify /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Analysis/stream.c
+ /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/lib/clang/19/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core,alpha.unix.Stream,debug.ExprInspection -verify /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Analysis/stream.c
error: 'expected-warning' diagnostics expected but not seen:
File /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Analysis/stream.c Line 147: Stream pointer might be NULL
File /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Analysis/stream.c Line 153: Stream pointer might be NULL
error: 'expected-warning' diagnostics seen but not expected:
File /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Analysis/stream.c Line 148: Stream pointer might be NULL [alpha.unix.Stream]
File /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Analysis/stream.c Line 154: Stream pointer might be NULL [alpha.unix.Stream]
4 errors generated.
--
********************
```
Added:
Modified:
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
clang/test/Analysis/Inputs/system-header-simulator.h
clang/test/Analysis/stream-invalidate.c
clang/test/Analysis/stream.c
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 29956fed2b3c24..65bdc4cac30940 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -348,30 +348,18 @@ class StreamChecker : public Checker<check::PreCall, eval::Call,
{{{"fgets"}, 3},
{std::bind(&StreamChecker::preReadWrite, _1, _2, _3, _4, true),
std::bind(&StreamChecker::evalFgetx, _1, _2, _3, _4, false), 2}},
- {{{"getc"}, 1},
- {std::bind(&StreamChecker::preReadWrite, _1, _2, _3, _4, true),
- std::bind(&StreamChecker::evalFgetx, _1, _2, _3, _4, true), 0}},
{{{"fputc"}, 2},
{std::bind(&StreamChecker::preReadWrite, _1, _2, _3, _4, false),
std::bind(&StreamChecker::evalFputx, _1, _2, _3, _4, true), 1}},
{{{"fputs"}, 2},
{std::bind(&StreamChecker::preReadWrite, _1, _2, _3, _4, false),
std::bind(&StreamChecker::evalFputx, _1, _2, _3, _4, false), 1}},
- {{{"putc"}, 2},
- {std::bind(&StreamChecker::preReadWrite, _1, _2, _3, _4, false),
- std::bind(&StreamChecker::evalFputx, _1, _2, _3, _4, true), 1}},
{{{"fprintf"}},
{std::bind(&StreamChecker::preReadWrite, _1, _2, _3, _4, false),
std::bind(&StreamChecker::evalFprintf, _1, _2, _3, _4), 0}},
- {{{"vfprintf"}, 3},
- {std::bind(&StreamChecker::preReadWrite, _1, _2, _3, _4, false),
- std::bind(&StreamChecker::evalFprintf, _1, _2, _3, _4), 0}},
{{{"fscanf"}},
{std::bind(&StreamChecker::preReadWrite, _1, _2, _3, _4, true),
std::bind(&StreamChecker::evalFscanf, _1, _2, _3, _4), 0}},
- {{{"vfscanf"}, 3},
- {std::bind(&StreamChecker::preReadWrite, _1, _2, _3, _4, true),
- std::bind(&StreamChecker::evalFscanf, _1, _2, _3, _4), 0}},
{{{"ungetc"}, 2},
{std::bind(&StreamChecker::preReadWrite, _1, _2, _3, _4, false),
std::bind(&StreamChecker::evalUngetc, _1, _2, _3, _4), 1}},
@@ -1050,13 +1038,10 @@ void StreamChecker::evalFscanf(const FnDescription *Desc, const CallEvent &Call,
if (!StateNotFailed)
return;
- if (auto const *Callee = Call.getCalleeIdentifier();
- !Callee || !Callee->getName().equals("vfscanf")) {
- SmallVector<unsigned int> EscArgs;
- for (auto EscArg : llvm::seq(2u, Call.getNumArgs()))
- EscArgs.push_back(EscArg);
- StateNotFailed = escapeArgs(StateNotFailed, C, Call, EscArgs);
- }
+ SmallVector<unsigned int> EscArgs;
+ for (auto EscArg : llvm::seq(2u, Call.getNumArgs()))
+ EscArgs.push_back(EscArg);
+ StateNotFailed = escapeArgs(StateNotFailed, C, Call, EscArgs);
if (StateNotFailed)
C.addTransition(StateNotFailed);
diff --git a/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h b/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
index c26d3582149120..098a2208fecbe9 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
@@ -5,7 +5,7 @@
// suppressed.
#pragma clang system_header
-typedef struct _FILE {
+typedef struct __sFILE {
unsigned char *_p;
} FILE;
FILE *fopen(const char *restrict, const char *restrict) __asm("_" "fopen" );
diff --git a/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h b/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
index 720944abb8ad47..7299b61353d460 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
@@ -10,8 +10,6 @@
#define restrict /*restrict*/
#endif
-typedef struct _FILE FILE;
-
typedef __builtin_va_list va_list;
#define va_start(ap, param) __builtin_va_start(ap, param)
@@ -23,10 +21,6 @@ int vprintf (const char *restrict format, va_list arg);
int vsprintf (char *restrict s, const char *restrict format, va_list arg);
-int vfprintf(FILE *stream, const char *format, va_list ap);
-
-int vfscanf(FILE *stream, const char *format, va_list ap);
-
int some_library_function(int n, va_list arg);
// No warning from system header.
diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h b/clang/test/Analysis/Inputs/system-header-simulator.h
index 8fd51449ecc0a4..15986984802c0e 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator.h
@@ -73,9 +73,6 @@ int ferror(FILE *stream);
int fileno(FILE *stream);
int fflush(FILE *stream);
-
-int getc(FILE *stream);
-
size_t strlen(const char *);
char *strcpy(char *restrict, const char *restrict);
diff --git a/clang/test/Analysis/stream-invalidate.c b/clang/test/Analysis/stream-invalidate.c
index 5046a356d0583d..6745d11a2fe701 100644
--- a/clang/test/Analysis/stream-invalidate.c
+++ b/clang/test/Analysis/stream-invalidate.c
@@ -4,7 +4,6 @@
// RUN: -analyzer-checker=debug.ExprInspection
#include "Inputs/system-header-simulator.h"
-#include "Inputs/system-header-simulator-for-valist.h"
void clang_analyzer_eval(int);
void clang_analyzer_dump(int);
@@ -146,44 +145,3 @@ void test_fgetpos() {
fclose(F);
}
-
-void test_fprintf() {
- FILE *F1 = tmpfile();
- if (!F1)
- return;
-
- unsigned a = 42;
- char *output = "HELLO";
- int r = fprintf(F1, "%s\t%u\n", output, a);
- // fprintf does not invalidate any of its input
- // 69 is ascii for 'E'
- clang_analyzer_dump(a); // expected-warning {{42 S32b}}
- clang_analyzer_dump(output[1]); // expected-warning {{69 S32b}}
- fclose(F1);
-}
-
-int test_vfscanf_inner(const char *fmt, ...) {
- FILE *F1 = tmpfile();
- if (!F1)
- return EOF;
-
- va_list ap;
- va_start(ap, fmt);
-
- int r = vfscanf(F1, fmt, ap);
-
- fclose(F1);
- va_end(ap);
- return r;
-}
-
-void test_vfscanf() {
- int i = 42;
- int j = 43;
- int r = test_vfscanf_inner("%d", &i);
- if (r != EOF) {
- // i gets invalidated by the call to test_vfscanf_inner, not by vfscanf.
- clang_analyzer_dump(i); // expected-warning {{conj_$}}
- clang_analyzer_dump(j); // expected-warning {{43 S32b}}
- }
-}
diff --git a/clang/test/Analysis/stream.c b/clang/test/Analysis/stream.c
index 7c7f68abeecac7..378c9154f8f6a8 100644
--- a/clang/test/Analysis/stream.c
+++ b/clang/test/Analysis/stream.c
@@ -1,7 +1,6 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream,debug.ExprInspection -verify %s
#include "Inputs/system-header-simulator.h"
-#include "Inputs/system-header-simulator-for-valist.h"
void clang_analyzer_eval(int);
@@ -66,24 +65,12 @@ void check_fseek(void) {
fclose(fp);
}
-void check_fseeko(void) {
- FILE *fp = tmpfile();
- fseeko(fp, 0, 0); // expected-warning {{Stream pointer might be NULL}}
- fclose(fp);
-}
-
void check_ftell(void) {
FILE *fp = tmpfile();
ftell(fp); // expected-warning {{Stream pointer might be NULL}}
fclose(fp);
}
-void check_ftello(void) {
- FILE *fp = tmpfile();
- ftello(fp); // expected-warning {{Stream pointer might be NULL}}
- fclose(fp);
-}
-
void check_rewind(void) {
FILE *fp = tmpfile();
rewind(fp); // expected-warning {{Stream pointer might be NULL}}
@@ -142,18 +129,6 @@ void f_dopen(int fd) {
fclose(F);
}
-void f_vfprintf(int fd, va_list args) {
- FILE *F = fdopen(fd, "r");
- vfprintf(F, "%d", args); // expected-warning {{Stream pointer might be NULL}}
- fclose(F);
-}
-
-void f_vfscanf(int fd, va_list args) {
- FILE *F = fdopen(fd, "r");
- vfscanf(F, "%u", args); // expected-warning {{Stream pointer might be NULL}}
- fclose(F);
-}
-
void f_seek(void) {
FILE *p = fopen("foo", "r");
if (!p)
@@ -163,15 +138,6 @@ void f_seek(void) {
fclose(p);
}
-void f_seeko(void) {
- FILE *p = fopen("foo", "r");
- if (!p)
- return;
- fseeko(p, 1, SEEK_SET); // no-warning
- fseeko(p, 1, 3); // expected-warning {{The whence argument to fseek() should be SEEK_SET, SEEK_END, or SEEK_CUR}}
- fclose(p);
-}
-
void f_double_close(void) {
FILE *p = fopen("foo", "r");
if (!p)
More information about the cfe-commits
mailing list