[clang] [clang][analyzer] Support `fgetc` in StreamChecker (PR #72627)

Balázs Kéri via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 23 01:46:18 PST 2023


================
@@ -101,6 +101,30 @@ void error_fwrite(void) {
   Ret = fwrite(0, 1, 10, F); // expected-warning {{Stream might be already closed}}
 }
 
+void error_fgetc(void) {
+  FILE *F = tmpfile();
+  if (!F)
+    return;
+  int Ret = fgetc(F);
+  if (0 <= Ret && Ret <= 255) {
+    clang_analyzer_eval(feof(F) || ferror(F)); // expected-warning {{FALSE}}
+  } else {
+    clang_analyzer_eval(Ret == EOF);  // expected-warning {{TRUE}}
----------------
balazske wrote:

A line `clang_analyzer_eval(feof(F) || ferror(F)); // expected-warning {{FALSE}}` can be added to check that no state is produced when none of the state flags are set.

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


More information about the cfe-commits mailing list