[clang] [analyzer] Assume the result of 'fopen' can't alias with 'std{in,out,err}' (PR #100085)
DonĂ¡t Nagy via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 23 03:53:09 PDT 2024
================
@@ -451,6 +462,10 @@ class StreamChecker : public Checker<check::PreCall, eval::Call,
/// The built-in va_list type is platform-specific
mutable QualType VaListType;
+ mutable const VarDecl *StdinDecl = nullptr;
+ mutable const VarDecl *StdoutDecl = nullptr;
+ mutable const VarDecl *StderrDecl = nullptr;
----------------
NagyDonat wrote:
`<bikeshedding>`
In your code the three standard streams have exactly identical roles (as far as I see), and I think it would be good to emphasize this by storing them in a three-element array instead of three separate independently named variables.
For example, I could imagine a solution like
```c++
const char *StdStreamNames[3] = {"stdin", "stdout", "stderr"};
mutable const VarDecl *StdStreamDecls[3] = {};
// ... in checkASTDecl()
for (int i = 0; i < 3; i++) {
// inline getGlobalStreamPointerByName here to initialize
// StdStreamDecls[i] via StdStreamNames[i]
}
// ... in assumeNoAliasingWithStdStreams()
for (const VarDecl *Var : StdStreamDecls) {
// put the definition of the lambda `assumeRetNE` here
}
```
(This is just a rough draft, there might be more idiomatic/elegant solutions for some parts.)
`</bikeshedding>`
https://github.com/llvm/llvm-project/pull/100085
More information about the cfe-commits
mailing list