[clang] [clang][analyzer] Add C standard streams to the internal memory space (PR #147766)
Balázs Kéri via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 11 01:48:12 PDT 2025
================
@@ -519,14 +519,53 @@ void reopen_std_stream(void) {
if (!fp) return;
stdout = fp; // Let's make them alias.
- clang_analyzer_eval(fp == oldStdout); // expected-warning {{UNKNOWN}}
- clang_analyzer_eval(fp == stdout); // expected-warning {{TRUE}} no-FALSE
- clang_analyzer_eval(oldStdout == stdout); // expected-warning {{UNKNOWN}}
+ clang_analyzer_eval(fp == oldStdout); // expected-warning {{FALSE}}
+ clang_analyzer_eval(fp == stdout); // expected-warning {{TRUE}}
+ clang_analyzer_eval(oldStdout == stdout); // expected-warning {{FALSE}}
}
void only_success_path_does_not_alias_with_stdout(void) {
if (stdout) return;
FILE *f = fopen("/tmp/foof", "r"); // no-crash
+ clang_analyzer_eval(f == 0);// expected-warning {{TRUE}} expected-warning {{FALSE}}
if (!f) return;
fclose(f);
}
+
+extern void do_something();
+
+void test_no_invalidate_at_system_call(int use_std) {
+ FILE *fd;
+ char *buf;
+
+ if (use_std) {
+ fd = stdin;
+ } else {
+ if ((fd = fopen("x/y/z", "r")) == NULL)
+ return;
+
+ clang_analyzer_eval(fd == stdin); // expected-warning{{FALSE}}
+ buf = (char *)malloc(100);
+ clang_analyzer_eval(fd == stdin); // expected-warning{{FALSE}}
+ }
+
+ if (fd != stdin)
+ fclose(fd);
+}
----------------
balazske wrote:
The test can be simplified, I added this code because it looks like the real code where the problem was found.
https://github.com/llvm/llvm-project/pull/147766
More information about the cfe-commits
mailing list