"clang -cc1 -analyze" can't identify header files?

I try to use "clang -cc1 -analyze -analyzer-checker=alpha.unix.SimpleStream
test.cpp" to anlyze the test.cpp. However fatal error occured "header file
not found!"

And if I could bet it’s one of the standard library includes? That’s because -cc1 invokes the frontend directly and not the driver. Frontend doesn’t know where to find include files, you have to pass -I. A better option is to use -Xanalyze. So something like clang test.cpp -Xanalyze -analyzer-checker=alpha.unix.SimpleStream should work.

Thank you Nikola! It's indeed standard library.
If I use "clang test.cpp -Xanalyze
-analyzer-checker=alpha.unix.SimpleStream", will produce following warnings.
"warning: argument unused during compilation:'-Xanalyze'"
"warning: argument unused during
And I have not found "-Xanalyze" int the clang usage options, instead I
found "-Xanalyzer". But even if I use "-Xanalyzer", it still doesn't work.
Originally I want to use "scan-build" to invoke static analyzer on windows
7, but I have difficulty in this method.

Sorry about that, it should be -Xclang followed by whatever frontend flag you need, in your case -analyze and checker name.

Thanks!The "-Xclang" seemingly cannot invoke the static analyzer, maybe I use
the -Xclang the wrong way. I tried to use "-I" option, but this command
cannot recursively visit the include files.

I found a temporary solution to this problem. We can add some hard-code in
llvm/tools/clang/lib/Frontend/InitHeaderSearch.cpp, these code will tell
clang where to search the c++ standard library. According to the existing
code, we also can put the standard library to the corresponding path. Then
when we use "clang -cc1 -analyze -analyzer-checker=alpha.unix.SimpleStream
test.cpp" we don't even need to use "-I" option, the clang static analyzer
can also execute correctly.

Adding Ted and Anna to get an official answer :slight_smile: