public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/44924]  New: Broken htons, invalid conversion warning
@ 2010-07-12 20:03 ralgith at gmail dot com
  2010-07-12 20:04 ` [Bug c++/44924] " ralgith at gmail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: ralgith at gmail dot com @ 2010-07-12 20:03 UTC (permalink / raw)
  To: gcc-bugs

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

I believe this needs to be relooked at. It is still an issue, and the bug seems
to come from the gcc/g++ compilers themselves.

To wit (quoting myself from a board where I was discussing this issue):
~~~Start Self Quote~~~
Outline of the problem:
C++ Software written by someone else for server-to-server communication with
MUD softwares, uses htons()
g++ is spitting out the following error:
error: conversion to ‘short unsigned int’ from ‘int’ may alter its value

That line of code:
sa.sin_port        = htons( siteinfo->port );

Other relevant code:
struct sockaddr_in sa;
unsigned short int port;            /* Port the server listens on */

Using --save-temps compiiler flag and grepping the resulting .ii file for
htons:
extern uint16_t htons (uint16_t __hostshort)

Checking typedef for unit16_t also using grep on the .ii file:
typedef unsigned short int __uint16_t;

All proper header files for htons() & network sockets (<sys/socket.h>,
<arpa/inet.h> and <netinet/in.h>) included.

So, am I missing something here... or is this a bad warning from the compiler?

g++ flags in use:
[code]W_FLAGS = -Wall -Werror -Wformat-security -Wshadow -Wpointer-arith
-Wcast-align -Wredundant-decls -Wconversion -pedantic

CFLAGS = -g2 -Os $(W_FLAGS)
LFLAGS = -g2 -lz[/code]

make/g++/ln version infos:
$ make --version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

$ g++ --version
g++ (GCC) 4.4.1
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ ln --version
ln (GNU coreutils) 7.5
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Parker and David MacKenzie.
~~~End Self Quote~~~

Now, as the original reporter of this bug mentioned, it ONLY happens with
higher levels of optimization. Take it or leave it, but this is NOT "invalid".

g++ -v compilation command output:
$ g++ -v -g2 -Os -Wall -Werror -Wformat-security -Wshadow -Wpointer-arith
-Wcast-align -Wredundant-decls -Wconversion -pedantic --save-temps  -c -o imc.o
imc.c
Using built-in specs.
Target: i586-manbo-linux-gnu
Configured with: ../configure --prefix=/usr --libexecdir=/usr/lib
--with-slibdir=/lib --with-bugurl=https://qa.mandriva.com/
--mandir=/usr/share/man --infodir=/usr/share/info --enable-checking=release
--enable-languages=c,c++,ada,fortran,objc,obj-c++,java
--build=i586-manbo-linux-gnu --host=i586-manbo-linux-gnu --with-cpu=generic
--with-system-zlib --enable-threads=posix --enable-shared --enable-objc-gc
--enable-long-long --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-clocale=gnu --enable-java-awt=gtk
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-gtk-cairo
--disable-libjava-multilib --enable-ssp --disable-libssp --disable-werror
--with-ppl --with-cloog --with-python-dir=/lib/python2.6/site-packages
Thread model: posix
gcc version 4.4.1 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-g2' '-Os' '-Wall' '-Werror' '-Wformat-security'
'-Wshadow' '-Wpointer-arith' '-Wcast-align' '-Wredundant-decls' '-Wconversion'
'-pedantic' '-save-temps' '-c' '-o' 'imc.o' '-shared-libgcc' '-mtune=generic'
 /usr/lib/gcc/i586-manbo-linux-gnu/4.4.1/cc1plus -E -quiet -v -D_GNU_SOURCE
imc.c -mtune=generic -Wall -Werror -Wformat-security -Wshadow -Wpointer-arith
-Wcast-align -Wredundant-decls -Wconversion -pedantic -g2 -fworking-directory
-Os -fpch-preprocess -o imc.ii
ignoring nonexistent directory
"/usr/lib/gcc/i586-manbo-linux-gnu/4.4.1/include-fixed"
ignoring nonexistent directory
"/usr/lib/gcc/i586-manbo-linux-gnu/4.4.1/../../../../i586-manbo-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/i586-manbo-linux-gnu/4.4.1/../../../../include/c++/4.4.1

/usr/lib/gcc/i586-manbo-linux-gnu/4.4.1/../../../../include/c++/4.4.1/i586-manbo-linux-gnu
 /usr/lib/gcc/i586-manbo-linux-gnu/4.4.1/../../../../include/c++/4.4.1/backward
 /usr/local/include
 /usr/lib/gcc/i586-manbo-linux-gnu/4.4.1/include
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-g2' '-Os' '-Wall' '-Werror' '-Wformat-security'
'-Wshadow' '-Wpointer-arith' '-Wcast-align' '-Wredundant-decls' '-Wconversion'
'-pedantic' '-save-temps' '-c' '-o' 'imc.o' '-shared-libgcc' '-mtune=generic'
 /usr/lib/gcc/i586-manbo-linux-gnu/4.4.1/cc1plus -fpreprocessed imc.ii -quiet
-dumpbase imc.c -mtune=generic -auxbase-strip imc.o -g2 -Os -Wall -Werror
-Wformat-security -Wshadow -Wpointer-arith -Wcast-align -Wredundant-decls
-Wconversion -pedantic -version -o imc.s
GNU C++ (GCC) version 4.4.1 (i586-manbo-linux-gnu)
        compiled by GNU C version 4.4.1, GMP version 4.3.1, MPFR version 2.4.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: d87da6367e390a0648b100f32b6ee212
cc1plus: warnings being treated as errors
imc.c: In function ‘bool imc_startup_port()’:
imc.c:5895: error: conversion to ‘short unsigned int’ from ‘int’ may alter its
value


-- 
           Summary: Broken htons, invalid conversion warning
           Product: gcc
           Version: 4.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ralgith at gmail dot com


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


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

* [Bug c++/44924] Broken htons, invalid conversion warning
  2010-07-12 20:03 [Bug c++/44924] New: Broken htons, invalid conversion warning ralgith at gmail dot com
@ 2010-07-12 20:04 ` ralgith at gmail dot com
  2010-07-12 20:07 ` ralgith at gmail dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: ralgith at gmail dot com @ 2010-07-12 20:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from ralgith at gmail dot com  2010-07-12 20:04 -------
Created an attachment (id=21187)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=21187&action=view)
Preprocessor output (.ii) file.

This is the output from using --save-temps flag to g++ when trying to compile
the src.


-- 


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


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

* [Bug c++/44924] Broken htons, invalid conversion warning
  2010-07-12 20:03 [Bug c++/44924] New: Broken htons, invalid conversion warning ralgith at gmail dot com
  2010-07-12 20:04 ` [Bug c++/44924] " ralgith at gmail dot com
@ 2010-07-12 20:07 ` ralgith at gmail dot com
  2010-07-12 20:11 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: ralgith at gmail dot com @ 2010-07-12 20:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from ralgith at gmail dot com  2010-07-12 20:07 -------
This was originally reported and ignored here:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39623

Since this ONLY happens with optimization, I'm curious why someone would think
it has multiple defines in the arpa headers?


-- 


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


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

* [Bug c++/44924] Broken htons, invalid conversion warning
  2010-07-12 20:03 [Bug c++/44924] New: Broken htons, invalid conversion warning ralgith at gmail dot com
  2010-07-12 20:04 ` [Bug c++/44924] " ralgith at gmail dot com
  2010-07-12 20:07 ` ralgith at gmail dot com
@ 2010-07-12 20:11 ` pinskia at gcc dot gnu dot org
  2010-07-12 20:18 ` ralgith at gmail dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-07-12 20:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2010-07-12 20:10 -------
>-Wconversion
Will cause this warning.


   sa.sin_port = (__extension__ ({ register unsigned short int __v, __x =
(siteinfo->port); if (__builtin_constant_p (__x)) __v = ((((__x) >> 8) & 0xff)
| (((__x) & 0xff) << 8)); else __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x)
: "cc"); __v; }));


__v = ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8));
is the part which is causing the warning.  The issue is the (__x) >> 8 is
implictly casted into int.


-- 


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


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

* [Bug c++/44924] Broken htons, invalid conversion warning
  2010-07-12 20:03 [Bug c++/44924] New: Broken htons, invalid conversion warning ralgith at gmail dot com
                   ` (2 preceding siblings ...)
  2010-07-12 20:11 ` pinskia at gcc dot gnu dot org
@ 2010-07-12 20:18 ` ralgith at gmail dot com
  2010-07-24 18:48 ` pinskia at gcc dot gnu dot org
  2010-07-24 20:02 ` ralgith at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: ralgith at gmail dot com @ 2010-07-12 20:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from ralgith at gmail dot com  2010-07-12 20:17 -------
(In reply to comment #3)
> >-Wconversion
> Will cause this warning.
> 
> 
>    sa.sin_port = (__extension__ ({ register unsigned short int __v, __x =
> (siteinfo->port); if (__builtin_constant_p (__x)) __v = ((((__x) >> 8) & 0xff)
> | (((__x) & 0xff) << 8)); else __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x)
> : "cc"); __v; }));
> 
> 
> __v = ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8));
> is the part which is causing the warning.  The issue is the (__x) >> 8 is
> implictly casted into int.
> 

Yet, if I remove the optimization flag -Os and keep the -Wconversion it doesn't
generate the warning. So there's still an issue here, even if the issue is that
-Wconversion is MISSING this when the code isn't optimized. Or perhaps I'm
missing something else here.

Regardless, is there a work around? I really enjoy using all my optimization
and -W flags because I like to have the best code possible. Thanks.


-- 


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


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

* [Bug c++/44924] Broken htons, invalid conversion warning
  2010-07-12 20:03 [Bug c++/44924] New: Broken htons, invalid conversion warning ralgith at gmail dot com
                   ` (3 preceding siblings ...)
  2010-07-12 20:18 ` ralgith at gmail dot com
@ 2010-07-24 18:48 ` pinskia at gcc dot gnu dot org
  2010-07-24 20:02 ` ralgith at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-07-24 18:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pinskia at gcc dot gnu dot org  2010-07-24 18:48 -------
There is nothing in GCC that can be done because the macro is being expanded
and glibc defines the macro.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

* [Bug c++/44924] Broken htons, invalid conversion warning
  2010-07-12 20:03 [Bug c++/44924] New: Broken htons, invalid conversion warning ralgith at gmail dot com
                   ` (4 preceding siblings ...)
  2010-07-24 18:48 ` pinskia at gcc dot gnu dot org
@ 2010-07-24 20:02 ` ralgith at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: ralgith at gmail dot com @ 2010-07-24 20:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from ralgith at gmail dot com  2010-07-24 20:02 -------
Apparently this is fixed in later versions of glibc already. Thanks for the
info.


-- 


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


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

end of thread, other threads:[~2010-07-24 20:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-12 20:03 [Bug c++/44924] New: Broken htons, invalid conversion warning ralgith at gmail dot com
2010-07-12 20:04 ` [Bug c++/44924] " ralgith at gmail dot com
2010-07-12 20:07 ` ralgith at gmail dot com
2010-07-12 20:11 ` pinskia at gcc dot gnu dot org
2010-07-12 20:18 ` ralgith at gmail dot com
2010-07-24 18:48 ` pinskia at gcc dot gnu dot org
2010-07-24 20:02 ` ralgith at gmail dot com

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