[clang] [clang][analyzer] Add C standard streams to the internal memory space (PR #147766)

DonĂ¡t Nagy via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 10 07:50:25 PDT 2025


NagyDonat wrote:

> BTW wouldn't this patch break the semantics of `freopen`? That one should invalidate the file ptr, right? Could you demonstrate this?

No, `freopen` should _not_ invalidate the file _ptr_, because it modifies the stream object (associating it with a different file) _without_ changing the pointer identity of the stream object. In fact, if you consider the signature, you can see that in
```c
FILE *freopen(const char *pathname, const char *mode, FILE *stream);
```
the third parameter takes an _rvalue_ of type `FILE *`, so if you call e.g. `freopen("somefile.txt", "r", stdin)` then this cannot invalidate the `FILE *` pointer stored in the global variable `stdin`.

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


More information about the cfe-commits mailing list