public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/67764] New: -Wconversion generates false warnings for bitmask+cast expressions
@ 2015-09-29 13:21 marcin.slusarz at intel dot com
  2015-09-29 19:57 ` [Bug c/67764] " egall at gwmail dot gwu.edu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: marcin.slusarz at intel dot com @ 2015-09-29 13:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67764

            Bug ID: 67764
           Summary: -Wconversion generates false warnings for bitmask+cast
                    expressions
           Product: gcc
           Version: 5.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marcin.slusarz at intel dot com
  Target Milestone: ---

void _setbit(unsigned char *b, unsigned int i)
{
        b[i / 8] |= (unsigned char)(1 << (i % 8));
}
void _setbit_works(unsigned char *b, unsigned int i)
{
        unsigned char ii = (unsigned char)(1 << (i % 8));
        b[i / 8] |= ii;
}

void _mask_stupid(unsigned char *b, unsigned int i)
{
        b[i] |= (unsigned char)i;
}

void _mask_stupid_works(unsigned char *b, unsigned int i)
{
        unsigned char ii = (unsigned char)i;
        b[i] |= ii;
}

$ gcc -c conversion_bug.c -Wconversion -o /dev/null

generates:

conversion_bug.c: In function ‘_setbit’:
conversion_bug.c:3:21: warning: conversion to ‘unsigned char’ from ‘int’ may
alter its value [-Wconversion]
         b[i / 8] |= (unsigned char)(1 << (i % 8));
                     ^
conversion_bug.c: In function ‘_mask_stupid’:
conversion_bug.c:13:17: warning: conversion to ‘unsigned char’ from ‘int’ may
alter its value [-Wconversion]
         b[i] |= (unsigned char)i;
                 ^


gcc-4.9.3 does *not* generate this warning, while gcc-5.2.1 does.


gcc -v:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 5.2.1-17'
--with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs
--enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-5 --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib
--disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64
--with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--enable-objc-gc --enable-multiarch --with-arch-32=i586 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 5.2.1 20150911 (Debian 5.2.1-17)
>From gcc-bugs-return-498305-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Tue Sep 29 13:32:28 2015
Return-Path: <gcc-bugs-return-498305-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 10807 invoked by alias); 29 Sep 2015 13:32:27 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 10782 invoked by uid 55); 29 Sep 2015 13:32:23 -0000
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug testsuite/67583] libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/1.cc:92 erroneous call to sputn
Date: Tue, 29 Sep 2015 13:32:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: testsuite
X-Bugzilla-Version: 6.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: minor
X-Bugzilla-Who: redi at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-67583-4-FKKDlNuKci@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-67583-4@http.gcc.gnu.org/bugzilla/>
References: <bug-67583-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-09/txt/msg02283.txt.bz2
Content-length: 710

https://gcc.gnu.org/bugzilla/show_bug.cgi?idg583

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Author: redi
Date: Tue Sep 29 13:31:51 2015
New Revision: 228245

URL: https://gcc.gnu.org/viewcvs?rev"8245&root=gcc&view=rev
Log:
PR libstdc++/67583 Fix invalid sputn calls in tests

        PR libstdc++/67583
        * testsuite/27_io/basic_stringbuf/seekoff/char/1.cc: Fix sputn call
        with mismatched arguments.
        * testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc: Likewise.

Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/1.cc
    trunk/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc


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

* [Bug c/67764] -Wconversion generates false warnings for bitmask+cast expressions
  2015-09-29 13:21 [Bug c/67764] New: -Wconversion generates false warnings for bitmask+cast expressions marcin.slusarz at intel dot com
@ 2015-09-29 19:57 ` egall at gwmail dot gwu.edu
  2015-09-30  8:41 ` marcin.slusarz at intel dot com
  2015-10-01  4:07 ` egall at gwmail dot gwu.edu
  2 siblings, 0 replies; 4+ messages in thread
From: egall at gwmail dot gwu.edu @ 2015-09-29 19:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67764

Eric Gallager <egall at gwmail dot gwu.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |egall at gwmail dot gwu.edu

--- Comment #1 from Eric Gallager <egall at gwmail dot gwu.edu> ---
Remember, x |= y is the same as x = (x | y). So if we rewrite the problematic
conversions like that, it becomes clearer where the warning is really pointing:

$ /usr/local/bin/gcc -c conversion_bug.c -Wconversion
conversion_bug.c: In function ‘_setbit’:
conversion_bug.c:4:13: warning: conversion to ‘unsigned char’ from ‘int’ may
alter its value [-Wconversion]
  b[i / 8] = (b[i / 8] | (unsigned char)(1 << (i % 8)));
             ^
conversion_bug.c: In function ‘_mask_stupid’:
conversion_bug.c:15:9: warning: conversion to ‘unsigned char’ from ‘int’ may
alter its value [-Wconversion]
  b[i] = (b[i] | (unsigned char)i);
         ^

If you cast the entire expression after it has been re-written like that, the
warning goes away:

b[i / 8] = (unsigned char)(b[i / 8] | (unsigned char)(1 << (i % 8)));
b[i] = (unsigned char)(b[i] | (unsigned char)i);

(no warnings generated for either of those)
>From gcc-bugs-return-498347-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Tue Sep 29 20:10:26 2015
Return-Path: <gcc-bugs-return-498347-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 70319 invoked by alias); 29 Sep 2015 20:10:26 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 70216 invoked by uid 48); 29 Sep 2015 20:10:23 -0000
From: "felix.von.s at posteo dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/59672] Add -m16 support for x86
Date: Tue, 29 Sep 2015 20:10:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: target
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: enhancement
X-Bugzilla-Who: felix.von.s at posteo dot de
X-Bugzilla-Status: NEW
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: cc
Message-ID: <bug-59672-4-M0FGFsAVuB@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-59672-4@http.gcc.gnu.org/bugzilla/>
References: <bug-59672-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-09/txt/msg02325.txt.bz2
Content-length: 588

https://gcc.gnu.org/bugzilla/show_bug.cgi?idY672

felix <felix.von.s at posteo dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |felix.von.s at posteo dot de

--- Comment #10 from felix <felix.von.s at posteo dot de> ---
Out of curiosity: given that hjl's -m16 patch has been merged, is there a
reason for keeping this open? Is anyone hoping to have a more complete support
for x86-16 target, or at least to drop the .code16gcc kludge?


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

* [Bug c/67764] -Wconversion generates false warnings for bitmask+cast expressions
  2015-09-29 13:21 [Bug c/67764] New: -Wconversion generates false warnings for bitmask+cast expressions marcin.slusarz at intel dot com
  2015-09-29 19:57 ` [Bug c/67764] " egall at gwmail dot gwu.edu
@ 2015-09-30  8:41 ` marcin.slusarz at intel dot com
  2015-10-01  4:07 ` egall at gwmail dot gwu.edu
  2 siblings, 0 replies; 4+ messages in thread
From: marcin.slusarz at intel dot com @ 2015-09-30  8:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67764

--- Comment #2 from Marcin Ślusarz <marcin.slusarz at intel dot com> ---
That's still gcc bug.
>From gcc-bugs-return-498379-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed Sep 30 08:58:07 2015
Return-Path: <gcc-bugs-return-498379-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 103446 invoked by alias); 30 Sep 2015 08:58:07 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 103171 invoked by uid 48); 30 Sep 2015 08:58:03 -0000
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/67777] unsigned wchar_t and signed wchar_t should cause compiler errors but do not.
Date: Wed, 30 Sep 2015 08:58:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 6.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: redi at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-67777-4-ucIIuWNHaL@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-67777-4@http.gcc.gnu.org/bugzilla/>
References: <bug-67777-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-09/txt/msg02357.txt.bz2
Content-length: 366

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67777

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This is a GNU extension, use -Wpedantic or -Werror=pedantic to get a
diagnostic.

The diagnostic is not enormously helpful though:

w.cc:1:17: warning: long, short, signed or unsigned used invalidly for
‘parameter’ [-Wpedantic]
>From gcc-bugs-return-498380-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed Sep 30 09:00:57 2015
Return-Path: <gcc-bugs-return-498380-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 106384 invoked by alias); 30 Sep 2015 09:00:57 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 106134 invoked by uid 48); 30 Sep 2015 09:00:49 -0000
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/67777] unsigned wchar_t and signed wchar_t should cause compiler errors but do not.
Date: Wed, 30 Sep 2015 09:00:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 6.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: redi at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-67777-4-Ydpv4ph8qF@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-67777-4@http.gcc.gnu.org/bugzilla/>
References: <bug-67777-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-09/txt/msg02358.txt.bz2
Content-length: 334

https://gcc.gnu.org/bugzilla/show_bug.cgi?idg777

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Trevor Hickey from comment #0)
> Why can we add signed/unsigned qualifiers to wchar_t?

It produces a type of the same size but with the opposite signedness, like
std::make_signed/std::make_unsigned.


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

* [Bug c/67764] -Wconversion generates false warnings for bitmask+cast expressions
  2015-09-29 13:21 [Bug c/67764] New: -Wconversion generates false warnings for bitmask+cast expressions marcin.slusarz at intel dot com
  2015-09-29 19:57 ` [Bug c/67764] " egall at gwmail dot gwu.edu
  2015-09-30  8:41 ` marcin.slusarz at intel dot com
@ 2015-10-01  4:07 ` egall at gwmail dot gwu.edu
  2 siblings, 0 replies; 4+ messages in thread
From: egall at gwmail dot gwu.edu @ 2015-10-01  4:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67764

--- Comment #3 from Eric Gallager <egall at gwmail dot gwu.edu> ---
Wait actually I think this might be a dup of bug 40752


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

end of thread, other threads:[~2015-10-01  4:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-29 13:21 [Bug c/67764] New: -Wconversion generates false warnings for bitmask+cast expressions marcin.slusarz at intel dot com
2015-09-29 19:57 ` [Bug c/67764] " egall at gwmail dot gwu.edu
2015-09-30  8:41 ` marcin.slusarz at intel dot com
2015-10-01  4:07 ` egall at gwmail dot gwu.edu

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