Bug 59495 - -ftrack-macro-expansion=2 ignores warnings originated from /usr/include headers
Summary: -ftrack-macro-expansion=2 ignores warnings originated from /usr/include headers
Status: RESOLVED DUPLICATE of bug 55252
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.8.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-12-13 13:49 UTC by Doron Tsur
Modified: 2013-12-15 12:27 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Doron Tsur 2013-12-13 13:49:18 UTC
$ gcc -Wall -Wextra -Werror  include-uapi-linux-netlink.h.test.c -ftrack-macro-expansion=0
include-uapi-linux-netlink.h.test.c: In function 'main':
include-uapi-linux-netlink.h.test.c:26:5: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
     NLMSG_OK(&auxiliary_netlink_header, active_len));
     ^
cc1: all warnings being treated as errors
$ gcc -Wall -Wextra -Werror  include-uapi-linux-netlink.h.test.c -ftrack-macro-expansion=2
$

$ gcc -Wall -Wextra -Werror -I/builds/kernel_tests_pre_patch_user_headers/include/ include-uapi-linux-netlink.h.test.c -ftrack-macro-expansion=2
In file included from include-uapi-linux-netlink.h.test.c:2:0:
include-uapi-linux-netlink.h.test.c: In function 'main':
/builds/kernel_tests_pre_patch_user_headers/include/linux/netlink.h:89:24: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
       (nlh)->nlmsg_len <= (len))
                        ^
include-uapi-linux-netlink.h.test.c:26:5: note: in expansion of macro 'NLMSG_OK'
     NLMSG_OK(&auxiliary_netlink_header, active_len));
     ^
cc1: all warnings being treated as errors
$
Comment 1 Marek Polacek 2013-12-13 14:23:01 UTC
I'd say it's because in maybe_unwind_expanded_macro_loc we've got

  /* Walk LOC_VEC and print the macro expansion trace, unless the
     first macro which expansion triggered this trace was expanded
     inside a system header.  */
  int saved_location_line =
    expand_location_to_spelling_point (diagnostic->location).line;

  if (!LINEMAP_SYSP (map))
    FOR_EACH_VEC_ELT (loc_vec, ix, iter)
      {   
        ...
      }
Comment 2 Manuel López-Ibáñez 2013-12-13 16:50:49 UTC
See the discussion in PR55252, specially comments #3 and #9.

*** This bug has been marked as a duplicate of bug 55252 ***
Comment 3 Doron Tsur 2013-12-15 12:27:06 UTC
It is probably a false positive bug - warning is undetected.

Consider the following code:

$ cat define_compare_test.c
#include "define_compare_test.h"
#include <stdio.h>

int main(int argc __attribute__((unused)), char** argv __attribute__((unused))) {
        const int number_int = -1;
        const unsigned int number_unsigned_int = 0xFFFFFFFF;

        printf("%d and %u are %s\n", number_int, number_unsigned_int,
               DEFINE_COMPARE(number_int, number_unsigned_int) );
        return 0;
}

$ cat define_compare_test/define_compare_test.h

#define DEFINE_COMPARE(X,Y) \
                ((X)==(Y)) ? "equal" : "different"

$ ... cp -v define_compare_test/define_compare_test.h /usr/include
'define_compare_test/define_compare_test.h' -> '/usr/include/define_compare_test.h'

$ gcc -Wall -Wextra -Werror  define_compare_test.c -I define_compare_test -H
. define_compare_test/define_compare_test.h                                       
...
In file included from define_compare_test.c:1:0:
define_compare_test.c: In function 'main':
define_compare_test/define_compare_test.h:3:7: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
   ((X)==(Y)) ? "equal" : "different"
       ^
define_compare_test.c:9:9: note: in expansion of macro 'DEFINE_COMPARE'
         DEFINE_COMPARE(number_int, number_unsigned_int) );
         ^
Multiple include guards may be useful for:
/usr/include/wchar.h
...
/usr/include/x86_64-linux-gnu/gnu/stubs.h
define_compare_test/define_compare_test.h
cc1: all warnings being treated as errors

$ gcc -Wall -Wextra -Werror  define_compare_test.c -H
. /usr/include/define_compare_test.h
. /usr/include/stdio.h
...
Multiple include guards may be useful for:
/usr/include/define_compare_test.h
/usr/include/wchar.h
...
$ ./a.out
-1 and 4294967295 are equal