[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}}
+ if (feof(F)) {
+ clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
----------------
balazske wrote:
These `warnIfReached` calls are not necessary, because the presence of the next warning tells anyway that the code is reachable.
https://github.com/llvm/llvm-project/pull/72627
More information about the cfe-commits
mailing list