| Issue |
204307
|
| Summary |
Clang 22 Static Analyzer misreports case of undefined errno
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
jengelh
|
Version: clang version 22.1.6 with GNU libstdc++ 15.3.0 / openSUSE Tumbleweed x86_64 20260615
Input:
```c++
#include <dirent.h>
#include <cerrno>
#include <string>
#include <memory>
struct del {
void operator()(DIR *d) const { closedir(d); }
};
struct D {
std::string foo;
std::unique_ptr<DIR, del> bar;
};
void test()
{
D d;
d.foo = "foo";
errno = 0;
d.bar.reset(opendir("."));
if (d.bar != nullptr)
return;
if (errno != ENOENT)
;
}
```
Observed output:
```
>clang++ 1.cpp -Wall --analyze -c
clang++: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument]
warning: Path diagnostic report is not generated. Current output format does not support diagnostics that cross file boundaries. Refer to --analyzer-output for valid output formats
1.cpp:22:6: warning: An undefined value may be read from 'errno' [unix.Errno]
22 | if (errno != ENOENT)
| ^~~~~
/usr/include/errno.h:38:16: note: expanded from macro 'errno'
38 | # define errno (*__errno_location ())
| ^~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
```
Expected output:
Stay silent. I do not see how errno could be undefined at that point.
Additional information:
Removing the line `d.foo = "foo";` line also makes clang go silent despite being unrelated to the opendir call.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs