[Bug c/35701] New: Quieten -Wconversion warnings
christian dot iseli at licr dot org
gcc-bugzilla@gcc.gnu.org
Tue Mar 25 23:23:00 GMT 2008
Given the attached test case, I get warnings from -Wconversion.
I cannot find a way to quieten those warnings.
I believe the bit-and operations should quieten the warnings.
Here is the command line I used:
gcc -v -save-temps -O2 -std=gnu99 -W -Wall -Wconversion -pedantic -c test.c
Here is the output:
====
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla
--enable-bootstrap --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
--disable-dssi --enable-plugin
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
--enable-libgcj-multifile --enable-java-maintainer-mode
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib
--with-cpu=generic --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.3.0 20080229 (Red Hat 4.3.0-0.13) (GCC)
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O2' '-std=gnu99' '-W' '-Wall'
'-Wconversion' '-pedantic' '-c' '-mtune=generic'
/usr/libexec/gcc/x86_64-redhat-linux/4.3.0/cc1 -E -quiet -v test.c
-mtune=generic -std=gnu99 -W -Wall -Wconversion -pedantic -O2 -fpch-preprocess
-o test.i
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-redhat-linux/4.3.0/include-fixed"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-redhat-linux/4.3.0/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc/x86_64-redhat-linux/4.3.0/include
/usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O2' '-std=gnu99' '-W' '-Wall'
'-Wconversion' '-pedantic' '-c' '-mtune=generic'
/usr/libexec/gcc/x86_64-redhat-linux/4.3.0/cc1 -fpreprocessed test.i -quiet
-dumpbase test.c -mtune=generic -auxbase test -O2 -W -Wall -Wconversion
-pedantic -std=gnu99 -version -o test.s
GNU C (GCC) version 4.3.0 20080229 (Red Hat 4.3.0-0.13) (x86_64-redhat-linux)
compiled by GNU C version 4.3.0 20080229 (Red Hat 4.3.0-0.13), GMP
version 4.2.2, MPFR version 2.3.0-p2.
GGC heuristics: --param ggc-min-expand=63 --param ggc-min-heapsize=61903
Compiler executable checksum: fdfb1d6ccb856fd413903980b80f9fc0
test.c: In function âÂÂmy_func1âÂÂ:
test.c:9: warning: conversion to âÂÂunsigned char:1â from âÂÂunsigned intâÂÂ
may alter its value
test.c:10: warning: conversion to âÂÂunsigned int:31â from âÂÂunsigned intâÂÂ
may alter its value
test.c: In function âÂÂmy_func2âÂÂ:
test.c:16: warning: conversion to âÂÂunsigned char:1â from âÂÂunsigned intâÂÂ
may alter its value
test.c:17: warning: conversion to âÂÂunsigned int:31â from âÂÂunsigned intâÂÂ
may alter its value
test.c: In function âÂÂmy_func3âÂÂ:
test.c:24: warning: conversion to âÂÂshort unsigned intâ from âÂÂunsigned
intâ may alter its value
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O2' '-std=gnu99' '-W' '-Wall'
'-Wconversion' '-pedantic' '-c' '-mtune=generic'
as -V -Qy -o test.o test.s
GNU assembler version 2.18.50.0.3 (x86_64-redhat-linux) using BFD version
version 2.18.50.0.3-2 20071102
COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/4.3.0/:/usr/libexec/gcc/x86_64-redhat-linux/4.3.0/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.3.0/:/usr/lib/gcc/x86_64-redhat-linux/:/usr/libexec/gcc/x86_64-redhat-linux/4.3.0/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.3.0/:/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/4.3.0/:/usr/lib/gcc/x86_64-redhat-linux/4.3.0/:/usr/lib/gcc/x86_64-redhat-linux/4.3.0/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/4.3.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O2' '-std=gnu99' '-W' '-Wall'
'-Wconversion' '-pedantic' '-c' '-mtune=generic'
====
Here is the test.c file:
====
typedef struct _my_struct_t {
unsigned int small:1;
unsigned int big:31;
} my_struct_t, *my_struct_p_t;
void
my_func1(unsigned int sm, unsigned int bi, my_struct_p_t msp)
{
msp->small = sm;
msp->big = bi;
}
void
my_func2(unsigned int sm, unsigned int bi, my_struct_p_t msp)
{
msp->small = sm & 1U;
msp->big = bi & 0x7fffffffU;
}
unsigned short
my_func3(unsigned int sm)
{
unsigned short res;
res = sm & 0xffffU;
return res;
}
====
Here is the test.i preprocessed file:
====
# 1 "test.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "test.c"
typedef struct _my_struct_t {
unsigned int small:1;
unsigned int big:31;
} my_struct_t, *my_struct_p_t;
void
my_func1(unsigned int sm, unsigned int bi, my_struct_p_t msp)
{
msp->small = sm;
msp->big = bi;
}
void
my_func2(unsigned int sm, unsigned int bi, my_struct_p_t msp)
{
msp->small = sm & 1U;
msp->big = bi & 0x7fffffffU;
}
unsigned short
my_func3(unsigned int sm)
{
unsigned short res;
res = sm & 0xffffU;
return res;
}
====
Kind regards,
Christian
--
Summary: Quieten -Wconversion warnings
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: christian dot iseli at licr dot org
GCC build triplet: x86_64-redhat-linux
GCC host triplet: x86_64-redhat-linux
GCC target triplet: x86_64-redhat-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35701
More information about the Gcc-bugs
mailing list