Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

checker-276 does not find C++ include files in Qt projects with C++11 support enabled. #20386

Open Quuxplusone opened 10 years ago

Quuxplusone commented 10 years ago
Bugzilla Link PR20387
Status NEW
Importance P normal
Reported by Jeremy Friesner (jaf@meyersound.com)
Reported on 2014-07-21 12:58:28 -0700
Last modified on 2015-09-30 10:48:43 -0700
Version unspecified
Hardware Macintosh MacOS X
CC jake.cobb@gmail.com, llvm-bugs@lists.llvm.org, quarksoft@live.cn
Fixed by commit(s)
Attachments static_checker_bug.zip (4454 bytes, application/zip)
Blocks
Blocked by
See also
Created attachment 12804
Trivial source code and .pro file that reproduce the problem

To reproduce (note that I've only tested this under MacOS/X 10.8.5, using Xcode
5.1.1, LLVM 4.2, clang++ 425.0.27):

1) Download and install checker-276 static analysis tool ( e.g. from
http://clang-analyzer.llvm.org/downloads/checker-276.tar.bz2 )

2) Make sure you have Qt 5.2.0 or later installed

3) Unzip the attached .zip file

4) In the created directory, run:

     qmake
     scan-build make

5) Observe that you get the following build error:

     main.cpp:1:10: fatal error: 'string' file not found
     #include <string>

6) Observe that if you just run 'make' (rather than 'scan-build make') the
errors do not occur.

7) Observe that if you use checker-275 rather than checker-276, the errors do
not occur

8) Observe that if you disable C++11 support (by commenting out the second line
in the static_checker_bug.pro file), the errors do not occur.
Quuxplusone commented 10 years ago

Attached static_checker_bug.zip (4454 bytes, application/zip): Trivial source code and .pro file that reproduce the problem

Quuxplusone commented 10 years ago
Actually this bug is easier to reproduce than I thought; in particular it does
not require Qt.

Simplified steps to reproduce:

1) Create a file "Makefile" with these contents:

CXXFLAGS +=  -std=c++11 -stdlib=libc++

test: test.o
        $(CXX) $(LFLAGS) -o $@ $^ $(LIBS)

clean:
        rm *.o

2) Create a file "test.cpp" with these contents:

#include <string>

int main(int, char **)
{
   return 0;
}

3) Run "scan-build make" using checker-276.

4) Note these erroneous results:

jeremy-friesners-mac-pro-3:crap jaf$ scan-build make
scan-build: Using '/Users/jaf/checker-276/bin/clang' for static analysis
/Users/jaf/checker-276/libexec/c++-analyzer -std=c++11 -stdlib=libc++   -c -o
test.o test.cpp
test.cpp:1:10: fatal error: 'string' file not found
#include <string>
         ^
1 error generated.
test.cpp:1:10: fatal error: 'string' file not found
#include <string>
         ^
1 error generated.
/Users/jaf/checker-276/libexec/c++-analyzer  -o test test.o
scan-build: 0 bugs found.
scan-build: The analyzer encountered problems on some source files.
scan-build: Preprocessed versions of these sources were deposited in
'/var/folders/xb/6c5bw1tx4qx8qkhd8rk98yc00000gn/T/scan-build-2014-07-21-112651-9974-1/failures'.
scan-build: Please consider submitting a bug report using these files:
scan-build:   http://clang-analyzer.llvm.org/filing_bugs.html
jeremy-friesners-mac-pro-3:crap jaf$
Quuxplusone commented 9 years ago

This seems like a problem with the clang version bundled with the checker. I encounter the same problem with XCode 6.1.1 using xcodebuild as the build tool. That is, everything builds fine with just xcodebuild but fails to find even standard library includes when run with scan-build from checker-276.

However, using a different clang with this checker works, i.e. by passing: --use-analyzer Xcode

Quuxplusone commented 9 years ago
Hi Jake,

I tried the flags you suggested, but still got errors, albeit different ones
(using the same Makefile and test.cpp as above):

Jeremys-Mac-mini:crap lcsuser1$ scan-build --use-analyzer Xcode make
scan-build: Using
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang'
for static analysis
/Users/lcsuser1/checker-276/libexec/c++-analyzer    -c -o test.o test.cpp
In file included from test.cpp:1:
In file included from
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:435:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iosfwd:90:10:
fatal error: 'wchar.h' file not found
#include <wchar.h>  // for mbstate_t
         ^
1 error generated.
In file included from test.cpp:1:
In file included from
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:435:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iosfwd:90:10:
fatal error: 'wchar.h' file not found
#include <wchar.h>  // for mbstate_t
         ^
1 error generated.
/Users/lcsuser1/checker-276/libexec/c++-analyzer  -o test test.o
scan-build: 0 bugs found.
scan-build: The analyzer encountered problems on some source files.
scan-build: Preprocessed versions of these sources were deposited in
'/var/folders/v7/4z87j4sx21d00s8cptxsc0xr0000gp/T/scan-build-2015-07-28-084408-15047-1/failures'.
scan-build: Please consider submitting a bug report using these files:
scan-build:   http://clang-analyzer.llvm.org/filing_bugs.html
Jeremys-Mac-mini:crap lcsuser1$

I did find a work-around that works for me, though... if I add this line to my
Makefile:

CXXFLAGS += -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/
-I/Users/lcsuser1/checker-276/lib/c++/v1

... then I don't get any errors:

Jeremys-Mac-mini:crap lcsuser1$ scan-build make
scan-build: Using '/Users/lcsuser1/checker-276/bin/clang' for static analysis
/Users/lcsuser1/checker-276/libexec/c++-analyzer -std=c++11 -stdlib=libc++ -
isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/
-I/Users/lcsuser1/checker-276/lib/c++/v1   -c -o test.o test.cpp
/Users/lcsuser1/checker-276/libexec/c++-analyzer  -o test test.o
scan-build: Removing directory
'/var/folders/v7/4z87j4sx21d00s8cptxsc0xr0000gp/T/scan-build-2015-07-28-084954-
15274-1' because it contains no reports.
scan-build: No bugs found.
Quuxplusone commented 8 years ago

Come accros same problem with you. Pls try --use-analyser /usr/bin/g++.

Quuxplusone commented 8 years ago

Hi Quark,

I tried your suggestion and I can confirm that running the command line "scan-build --use-analyzer /usr/bin/g++ make" avoids the problem. Thank you for the suggestion! :)

Jeremy