public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/35701]  New: Quieten -Wconversion warnings
@ 2008-03-25 23:23 christian dot iseli at licr dot org
  2008-06-08 17:25 ` [Bug c/35701] " manu at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: christian dot iseli at licr dot org @ 2008-03-25 23:23 UTC (permalink / raw)
  To: gcc-bugs

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

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


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

* [Bug c/35701] Quieten -Wconversion warnings
  2008-03-25 23:23 [Bug c/35701] New: Quieten -Wconversion warnings christian dot iseli at licr dot org
@ 2008-06-08 17:25 ` manu at gcc dot gnu dot org
  2008-06-08 17:33 ` manu at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-06-08 17:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from manu at gcc dot gnu dot org  2008-06-08 17:25 -------
Ideally, one could just do:

  msp->small = (unsigned int:1) sm;

Meanwhile, we will need to check that when converting to p bits that the mask
is less than 2^p - 1. I wonder if we already have a function to do that.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2008-06-08 17:25:11
               date|                            |


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


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

* [Bug c/35701] Quieten -Wconversion warnings
  2008-03-25 23:23 [Bug c/35701] New: Quieten -Wconversion warnings christian dot iseli at licr dot org
  2008-06-08 17:25 ` [Bug c/35701] " manu at gcc dot gnu dot org
@ 2008-06-08 17:33 ` manu at gcc dot gnu dot org
  2008-08-20 16:12 ` manu at gcc dot gnu dot org
  2008-08-20 16:15 ` manu at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-06-08 17:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from manu at gcc dot gnu dot org  2008-06-08 17:32 -------
Anyway, this won't work at all until bug 34389 is fixed because fold with
convert each operand to the target type before considering the bit_and_expr. 


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  BugsThisDependsOn|                            |34389


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


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

* [Bug c/35701] Quieten -Wconversion warnings
  2008-03-25 23:23 [Bug c/35701] New: Quieten -Wconversion warnings christian dot iseli at licr dot org
  2008-06-08 17:25 ` [Bug c/35701] " manu at gcc dot gnu dot org
  2008-06-08 17:33 ` manu at gcc dot gnu dot org
@ 2008-08-20 16:12 ` manu at gcc dot gnu dot org
  2008-08-20 16:15 ` manu at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-08-20 16:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from manu at gcc dot gnu dot org  2008-08-20 16:11 -------
Subject: Bug 35701

Author: manu
Date: Wed Aug 20 16:09:45 2008
New Revision: 139329

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=139329
Log:
2008-08-20  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

        PR 35701
        * c-common.c (conversion_warning): Do not warn if applying bit-and
        operator to unsigned constant that fits in the target type.

testsuite/
        * gcc.dg/pr35701.c: New.
        * gcc.dg/Wconversion-real-integer.c: Add more tests.
        * gcc.dg/Wconversion-pr34389.c: Update.
        * g++.dg/warn/Wconversion-pr34389.C: Update.

Added:
    trunk/gcc/testsuite/gcc.dg/pr35701.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-common.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/warn/Wconversion-pr34389.C
    trunk/gcc/testsuite/g++.dg/warn/Wconversion-real-integer.C
    trunk/gcc/testsuite/gcc.dg/Wconversion-pr34389.c
    trunk/gcc/testsuite/gcc.dg/Wconversion-real-integer.c


-- 


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


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

* [Bug c/35701] Quieten -Wconversion warnings
  2008-03-25 23:23 [Bug c/35701] New: Quieten -Wconversion warnings christian dot iseli at licr dot org
                   ` (2 preceding siblings ...)
  2008-08-20 16:12 ` manu at gcc dot gnu dot org
@ 2008-08-20 16:15 ` manu at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-08-20 16:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from manu at gcc dot gnu dot org  2008-08-20 16:13 -------
Fixed in GCC 4.4


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.4.0


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


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

end of thread, other threads:[~2008-08-20 16:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-25 23:23 [Bug c/35701] New: Quieten -Wconversion warnings christian dot iseli at licr dot org
2008-06-08 17:25 ` [Bug c/35701] " manu at gcc dot gnu dot org
2008-06-08 17:33 ` manu at gcc dot gnu dot org
2008-08-20 16:12 ` manu at gcc dot gnu dot org
2008-08-20 16:15 ` manu 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).