Bug 78989 - Missing -Waddress warning due to -Wno-system-headers
Summary: Missing -Waddress warning due to -Wno-system-headers
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on: 77513
Blocks: Waddress
  Show dependency treegraph
 
Reported: 2017-01-04 17:27 UTC by Martin Liška
Modified: 2024-03-11 12:31 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 6.4.0, 7.3.0, 8.2.0, 9.0
Last reconfirmed: 2024-03-11 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Liška 2017-01-04 17:27:04 UTC
Following test-case does not report warning:

$ cat /tmp/gimplify.ii 
int 
asan_poison_variables ()
{
 return (asan_poison_variables &&  
# 6 "gimplify.cpp" 3 4
                              __null
                                  );
}

./xgcc -B. /tmp/gimplify.ii -Wall -c
[nothing]

While:

cat /tmp/gimplify.ii 
int 
asan_poison_variables ()
{
 return (asan_poison_variables &&  
                              __null
                                  );
}
$ ./xgcc -B. /tmp/gimplify.ii -Wall -c
/tmp/gimplify.ii: In function ‘int asan_poison_variables()’:
/tmp/gimplify.ii:5:31: warning: the address of ‘int asan_poison_variables()’ will never be NULL [-Waddress]
                               __null
                               ^~~~~~

It's somehow related to the location if *.ii file, but I don't know how.
Thanks
Comment 1 Jakub Jelinek 2017-01-04 18:12:57 UTC
Looks like -Wsystem-headers in action again.  NULL is a macro defined in a system header...
Comment 2 Jakub Jelinek 2017-01-04 18:16:11 UTC
Dunno if we don't want to special case macros in system headers that expand to a single token or what other heuristics to use.
Comment 3 David Malcolm 2017-01-04 19:54:59 UTC
Looking at the PRs you filed about the locations (PR78987 and PR78988), perhaps the best approach here is for the location of the warning to be either this:

return (asan_poison_variables &&  
        ~~~~~~~~~~~~~~~~~~~~~~^~
# 6 "gimplify.cpp" 3 4
                              __null
                              ~~~~~~
                                  );

or this:

return (asan_poison_variables &&  
        ~~~~~~~~~~~~~~~~~~~~~~~~
# 6 "gimplify.cpp" 3 4
                              __null
                              ^~~~~~
                                  );

i.e. for the location to be a range starting at the LHS start, finishing at the RHS finish, with the caret at either the && or the RHS...

...and then for in_system_header_at to only reject the warning if *all* of the range of the location is fully within a system header, rather than just partially within a header?
Comment 4 David Malcolm 2017-01-04 19:57:40 UTC
...or to use a rich location to send two locations for the warning, giving:

return (asan_poison_variables &&  
                              ^~
# 6 "gimplify.cpp" 3 4
                              __null
                              ~~~~~~
                                  );

and for the logic that uses diagnostic_report_warnings_p to check all locations in the rich location, requiring all to be within a system header for the warning to be rejected.
Comment 5 Andrew Pinski 2017-01-04 23:13:09 UTC
Isn't there a dup somewhere?  I Know this was filed before.
Comment 6 Andrew Pinski 2017-01-04 23:15:19 UTC
I suspect PR 77513 can be considered the dup.
Comment 7 Eric Gallager 2018-07-30 02:12:20 UTC
(In reply to Andrew Pinski from comment #6)
> I suspect PR 77513 can be considered the dup.

As in, that's the dup of this, or this is the dup of that?
Comment 8 Martin Sebor 2019-02-03 23:25:54 UTC
Confirmed there's no change in GCC 9.0.
Comment 9 Martin Sebor 2021-11-22 15:57:31 UTC
GCC 12 (and prior, down to 10) warns for the test case:

$ cat pr78989.ii && gcc -S -Wall pr78989.ii 
int 
asan_poison_variables ()
{
 return (asan_poison_variables &&  
# 6 "gimplify.cpp" 3 4
                              __null
                                  );
}
pr78989.ii: In function ‘int asan_poison_variables()’:
pr78989.ii:4:10: warning: the address of ‘int asan_poison_variables()’ will never be NULL [-Waddress]
    4 |  return (asan_poison_variables &&
      |          ^~~~~~~~~~~~~~~~~~~~~
pr78989.ii:2:1: note: ‘int asan_poison_variables()’ declared here
    2 | asan_poison_variables ()
      | ^~~~~~~~~~~~~~~~~~~~~