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

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).