Menu

preprocessor includes wrong header files

vilox
2021-01-29
2021-01-29
  • vilox

    vilox - 2021-01-29

    Suppose foo system library has headers:

    $ ls -go /path/to/foo/headers/
    -rw-r--r-- 1 138 Jan 28 17:53 foo.h
    -rw-r--r-- 1   49 Jan 28 17:33 config.h

    and headers are this simple:

    $ cat config.h

    #ifndef FOO_CONFIG_H
    #define FOO_CONFIG_H
    #endif
    

    $ cat foo.h

    #ifndef FOO_PUBLIC_H
    #define FOO_PUBLIC_H
    #include "config.h"
    #  ifndef FOO_CONFIG_H
    #    error Foo was not configured
    #  endif
    #endif
    

    Assume bar application chose to keep it's configuration in it's ownconfig.h.

    $ ls -go bar/*/*
    -rw-r--r-- 1 0 Jan 28 22:53 bar/part_1/config.h
    -rw-r--r-- 1 47 Jan 29 00:54 bar/part_2/bar.c

    where

    $ cat bar/part_2/bar.c

    #include <foo.h>
    #include "../part_1/config.h"
    

    and bar/part_1/config.h is intentionally blank.

    Nothing wrong with this, completely legit setup. To be more specific, let /path/to/foo/headers := /tmp/R/include, and bar := /tmp/R/bar . Then gcc keeps calm:

    host:/$ gcc -m64 -nostdinc -I /tmp/R/include -I /tmp/R/bar/part_1 -c -o /tmp/R/bar/tmp.o /tmp/R/bar/part_2/bar.c
    host:/$

    However, the equivalent cppcheck invocation fails:

    host:/$ cppcheck -DANY -I /tmp/R/include -I /tmp/R/bar/part_1 /tmp/R/bar/part_2/bar.c
    Checking /tmp/R/bar/part_2/bar.c ...
    /tmp/R/include/foo.h:7:0: error: #error Foo was not configured [preprocessorErrorDirective]
    # error Foo was not configured
    ^

    cppcheck reads bar's config.h and includes it into foo.h instead of foo's config.h, I am not kidding.

    Do you think this case is purely speculative and has not been from real life? Think foo := perl and bar := openldap, that's where this case came from.

    The archive with test case attached. Verified for current release (2.3) and current git (2021-01-28 a9b7f0e27).

     
  • Daniel Marjamäki

    thanks. I have the feeling this is a simplecpp issue.
    https://github.com/danmar/simplecpp

    I wonder if you volounteer to download simplecpp source code, build it, then run:

    simplecpp -DANY -I /tmp/R/include -I /tmp/R/bar/part_1 /tmp/R/bar/part_2/bar.c
    

    If you can reproduce some problem then.. then a issue should be created in the simplecpp issue tracker.

     
    • vilox

      vilox - 2021-01-29

      I wonder if you volounteer to download simplecpp source code, build it, then run:
      $ simplecpp -DANY -I /tmp/R/include -I ...

      Hi, Daniel. I have attached the archive of /tmp/R/ (in r_testcase.tar.gz) to top-level post.

      If you have simplecpp already built, then you can just unpack archive into /tmp/ to be able to run the test case on your side. It might be more simple and straightforward then if I would build simplecpp on my side.

       
  • Daniel Marjamäki

    I feel overwhelmed by trouble reports and reviews right now. it's good that problems are reported but when we spend most time reporting more bugs and have no time to fix bugs it's not productive.. :-(

     
  • Daniel Marjamäki

    If anybody can help out a bit .. please do it..

     
  • vilox

    vilox - 2021-01-29

    Understood. I'll try to make a test, but it's not guaranteed :-(

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.