public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/37881]  New: -Wunreachable-code warns for system headers macros
@ 2008-10-21 10:20 flameeyes at gentoo dot org
  2008-10-21 21:05 ` [Bug c/37881] " manu at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: flameeyes at gentoo dot org @ 2008-10-21 10:20 UTC (permalink / raw)
  To: gcc-bugs

When turning -Wunreachable-code to get warning about code that might never be
executed, I noticed that gcc throws warnings on all the calls to htons.

This seems to be because htons is expanded as a macro, and indeed a function
written as

uint16_t my_htons(uint16_t val) {
  return htons(val);
}

is expanded by the preprocessor to

uint16_t my_htons(uint16_t val) {
  return (__extension__ ({ register unsigned short int __v, __x = (val); if
(__builtin_constant_p (__x)) __v = ((((__x) >> 8) & 0xff) | (((__x) & 0xff) <<
8)); else __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x) : "cc"); __v; }));
}

I guess the problem here is with the __builtin_constant_p() branch of the macro
since of course val is no constant.

I admit I'm not sure if this is fixable, but it certainly adds a lot of false
positive to -Wunreachable-code (which would otherwise be very useful at least
for C code).


-- 
           Summary: -Wunreachable-code warns for system headers macros
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: flameeyes at gentoo dot org
 GCC build triplet: x86_64-pc-linux-gnu
  GCC host triplet: x86_64-pc-linux-gnu
GCC target triplet: x86_64-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37881


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c/37881] -Wunreachable-code warns for system headers macros
  2008-10-21 10:20 [Bug c/37881] New: -Wunreachable-code warns for system headers macros flameeyes at gentoo dot org
@ 2008-10-21 21:05 ` manu at gcc dot gnu dot org
  2008-10-21 22:57 ` flameeyes at gentoo dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-10-21 21:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from manu at gcc dot gnu dot org  2008-10-21 21:03 -------
We need a complete testcase. See http://gcc.gnu.org/bugs.html

In this case, we would need the unpreprocessed testcase but we still need a
complete one that we can compile ourselves. Thanks.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org
             Status|UNCONFIRMED                 |WAITING


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37881


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c/37881] -Wunreachable-code warns for system headers macros
  2008-10-21 10:20 [Bug c/37881] New: -Wunreachable-code warns for system headers macros flameeyes at gentoo dot org
  2008-10-21 21:05 ` [Bug c/37881] " manu at gcc dot gnu dot org
@ 2008-10-21 22:57 ` flameeyes at gentoo dot org
  2008-10-21 23:13 ` manu at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: flameeyes at gentoo dot org @ 2008-10-21 22:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from flameeyes at gentoo dot org  2008-10-21 22:56 -------
Created an attachment (id=16523)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16523&action=view)
tc-htons-unreachable.c

Sure here it is, there isn't much of a testcase I admit ;)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37881


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c/37881] -Wunreachable-code warns for system headers macros
  2008-10-21 10:20 [Bug c/37881] New: -Wunreachable-code warns for system headers macros flameeyes at gentoo dot org
  2008-10-21 21:05 ` [Bug c/37881] " manu at gcc dot gnu dot org
  2008-10-21 22:57 ` flameeyes at gentoo dot org
@ 2008-10-21 23:13 ` manu at gcc dot gnu dot org
  2008-10-21 23:20 ` flameeyes at gentoo dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-10-21 23:13 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from manu at gcc dot gnu dot org  2008-10-21 23:12 -------
I cannot reproduce this because it seems that in my system
x86_64-unknown-linux-gnu, htons is not expanded as a macro.

Could you also add a preprocessed testcase and the exact output from the
compiler? Please, also use -fshow-column, -fdiagnostics-show-option and -v.

Thanks.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2008-10-21 23:12:02
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37881


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c/37881] -Wunreachable-code warns for system headers macros
  2008-10-21 10:20 [Bug c/37881] New: -Wunreachable-code warns for system headers macros flameeyes at gentoo dot org
                   ` (2 preceding siblings ...)
  2008-10-21 23:13 ` manu at gcc dot gnu dot org
@ 2008-10-21 23:20 ` flameeyes at gentoo dot org
  2008-10-21 23:38 ` manu at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: flameeyes at gentoo dot org @ 2008-10-21 23:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from flameeyes at gentoo dot org  2008-10-21 23:19 -------
Created an attachment (id=16524)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16524&action=view)
Preprocessed test case

For what it's worth this is glibc 2.8 on Gentoo, AMD64 multilib system.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37881


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c/37881] -Wunreachable-code warns for system headers macros
  2008-10-21 10:20 [Bug c/37881] New: -Wunreachable-code warns for system headers macros flameeyes at gentoo dot org
                   ` (3 preceding siblings ...)
  2008-10-21 23:20 ` flameeyes at gentoo dot org
@ 2008-10-21 23:38 ` manu at gcc dot gnu dot org
  2008-10-21 23:49 ` flameeyes at gentoo dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-10-21 23:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from manu at gcc dot gnu dot org  2008-10-21 23:36 -------
(In reply to comment #4)
> Created an attachment (id=16524)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16524&action=view) [edit]
> Preprocessed test case
> 

I don't see that htons was expanded as a macro there. Moreover, I am interested
in the output from the compiler when you use -Wunreachable-code together with
the options I mentioned (that is, the output given by gcc when it throws a
warning that you think it should not throw).

Thanks.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37881


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c/37881] -Wunreachable-code warns for system headers macros
  2008-10-21 10:20 [Bug c/37881] New: -Wunreachable-code warns for system headers macros flameeyes at gentoo dot org
                   ` (4 preceding siblings ...)
  2008-10-21 23:38 ` manu at gcc dot gnu dot org
@ 2008-10-21 23:49 ` flameeyes at gentoo dot org
  2008-10-27  1:50 ` pinskia at gcc dot gnu dot org
  2010-01-17 10:23 ` rguenth at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: flameeyes at gentoo dot org @ 2008-10-21 23:49 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 757 bytes --]



------- Comment #6 from flameeyes at gentoo dot org  2008-10-21 23:48 -------
Created an attachment (id=16525)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16525&action=view)
Preprocessed test case

That's because I forgot to turn on -O2 :/

tc-htons-unrechable.c: In function ‘my_htons’:
tc-htons-unrechable.c:5:10: warning: will never be executed
[-Wunreachable-code]

this is the warning that it throws.


-- 

flameeyes at gentoo dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #16524|0                           |1
        is obsolete|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37881


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c/37881] -Wunreachable-code warns for system headers macros
  2008-10-21 10:20 [Bug c/37881] New: -Wunreachable-code warns for system headers macros flameeyes at gentoo dot org
                   ` (5 preceding siblings ...)
  2008-10-21 23:49 ` flameeyes at gentoo dot org
@ 2008-10-27  1:50 ` pinskia at gcc dot gnu dot org
  2010-01-17 10:23 ` rguenth at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-10-27  1:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from pinskia at gcc dot gnu dot org  2008-10-27 01:49 -------
This requires us to record that the macros came from system headers and so did
the expansion.

Also -Wunreachable-code is useless for most cases in general because of
inlining and such.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
  GCC build triplet|x86_64-pc-linux-gnu         |
   GCC host triplet|x86_64-pc-linux-gnu         |
 GCC target triplet|x86_64-pc-linux-gnu         |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37881


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c/37881] -Wunreachable-code warns for system headers macros
  2008-10-21 10:20 [Bug c/37881] New: -Wunreachable-code warns for system headers macros flameeyes at gentoo dot org
                   ` (6 preceding siblings ...)
  2008-10-27  1:50 ` pinskia at gcc dot gnu dot org
@ 2010-01-17 10:23 ` rguenth at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-01-17 10:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from rguenth at gcc dot gnu dot org  2010-01-17 10:23 -------
-Wunreachable-code has been removed.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37881


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-01-17 10:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-21 10:20 [Bug c/37881] New: -Wunreachable-code warns for system headers macros flameeyes at gentoo dot org
2008-10-21 21:05 ` [Bug c/37881] " manu at gcc dot gnu dot org
2008-10-21 22:57 ` flameeyes at gentoo dot org
2008-10-21 23:13 ` manu at gcc dot gnu dot org
2008-10-21 23:20 ` flameeyes at gentoo dot org
2008-10-21 23:38 ` manu at gcc dot gnu dot org
2008-10-21 23:49 ` flameeyes at gentoo dot org
2008-10-27  1:50 ` pinskia at gcc dot gnu dot org
2010-01-17 10:23 ` rguenth at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).