[clang] [clang][analyzer] Fix argument invalidations in StreamChecker. (PR #79470)

Balázs Kéri via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 26 06:20:37 PST 2024


================
@@ -0,0 +1,133 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN: -analyzer-checker=core \
+// RUN: -analyzer-checker=alpha.unix.Stream \
+// RUN: -analyzer-checker=debug.StreamTester \
+// RUN: -analyzer-checker=debug.ExprInspection
+
+#include "Inputs/system-header-simulator.h"
+
+void clang_analyzer_eval(int);
+void clang_analyzer_dump(int);
+void clang_analyzer_warnIfReached(void);
+void StreamTesterChecker_make_feof_stream(FILE *);
+void StreamTesterChecker_make_ferror_stream(FILE *);
+
+void test_fread(void) {
+  FILE *F = fopen("file", "r+");
+  if (!F)
+    return;
+
+  char Buf[3] = {10, 10, 10};
+  fread(Buf, 1, 3, F);
+  // this check applies to succes and failure
+  clang_analyzer_dump(Buf[0]); // expected-warning {{conj_$}} Should not preserve the previous value, thus should not be 10.
+  clang_analyzer_dump(Buf[2]); // expected-warning {{conj_$}}
+  if (feof(F)) {
----------------
balazske wrote:

At `ferror(F)` the next stream call should produce a "file position indeterminate" warning (this is tested in another file) that stops the analysis, buffer invalidation is not needed to be tested.

https://github.com/llvm/llvm-project/pull/79470


More information about the cfe-commits mailing list