Bug 1114755

Summary: sparse seems unable to locate header files
Product: [Fedora] Fedora Reporter: Vishal Verma <stellarhopper>
Component: sparseAssignee: Jeff Layton <jlayton>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 20CC: jlayton, stellarhopper
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-07-09 01:08:59 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Vishal Verma 2014-06-30 21:35:29 UTC
Description of problem: Running sparse on a simple test.c containing just "#include <stdio.h>" gives:

$ sparse test.c 
/usr/include/stdio.h:33:12: error: unable to open 'stddef.h'

and sparse exits with '1'

Trying this allows it to succeed for this test file:

$ gcc_install="$(gcc --print-search | grep "install:" | cut -d' ' -f2)/include"; sparse -I$gcc_install test.c

But seems to have spurious warnings if I add "#include <stdint.h>" to the test.

/usr/lib/gcc/x86_64-redhat-linux/4.8.3//include/stdint-gcc.h:60:29: error: Expected ; at end of declaration
/usr/lib/gcc/x86_64-redhat-linux/4.8.3//include/stdint-gcc.h:60:29: error: got int_least8_t
/usr/lib/gcc/x86_64-redhat-linux/4.8.3//include/stdint-gcc.h:61:30: error: Expected ; at end of declaration
/usr/lib/gcc/x86_64-redhat-linux/4.8.3//include/stdint-gcc.h:61:30: error: got int_least16_t
...


Version-Release number of selected component (if applicable): 0.5.0-2.fc20


How reproducible: 100%


Steps to Reproduce:
1. Create test.c containing:
#include <stdio.h>
#include <stdint.h>

2.Run: sparse test.c


Actual results: Sparse fails


Expected results: Saprse should pass


Additional info:

Comment 1 Vishal Verma 2014-06-30 21:38:03 UTC
I should note that this only started after gcc recently got updated to 4.8.3-1.fc20

Comment 2 Vishal Verma 2014-07-08 21:27:36 UTC
Upstream sparse appears to work ok.

Comment 3 Jeff Layton 2014-07-09 01:08:59 UTC
I'm afraid that this is just a fundamental limitation in the way sparse currently works. It defaults to looking for gcc headers in the location given by -DGCC_BASE. Once gcc is upgraded, then that no longer works by default since the headers will have moved. The reason "upstream sparse" works for you is because you built it with gcc that's currently installed. If you changed your gcc version after building it, you'd hit the same problem.

It would be nice to have a proper fix for that sometime, but in the meantime you can use a command like this to work around it:

    $ sparse -gcc-base-dir `gcc --print-file-name=` /tmp/test.c

...with that, your testcase doesn't throw that warning. It would be nice if sparse were able to determine that automatically, but for now it doesn't. Feel free to complain on the upstream sparse list however (and send patches if you're able to do so).