public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c/7696: Spurious shift warning
@ 2003-04-06 12:26 Christian Ehrhardt
0 siblings, 0 replies; 4+ messages in thread
From: Christian Ehrhardt @ 2003-04-06 12:26 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR c/7696; it has been noted by GNATS.
From: "Christian Ehrhardt" <ehrhardt@mathematik.uni-ulm.de>
To: gcc-gnats@gcc.gnu.org, schwab@suse.de, gcc-bugs@gcc.gnu.org,
nobody@gcc.gnu.org, gcc-prs@gcc.gnu.org
Cc:
Subject: Re: c/7696: Spurious shift warning
Date: Sun, 6 Apr 2003 14:17:56 +0200
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7696
PR 7696 started out as a spurious warning on ia64 but it turns out that
this is probably a wrong code generation bug on any 64bit arch. The
source code in question is this:
$ cat 7696.c
struct ia64_psr {
unsigned long cpl : 2;
} x = {1};
main ()
{
unsigned long y = ((unsigned long) x.cpl) << 40;
printf ("%lx %d\n", y, sizeof (y));
return 0;
}
$ gcc -m64 7696.c
7696.c: In function `main':
7696.c:7: warning: left shift count >= width of type
This program will print
$ a.out
100 8
According to gdb the cast is thrown away early (build_binary_op doesn't see
it at all), probably because the bitfield is of type unsigned long. But
later on default_conversion sees that the precision is only two and converts
x.cpl to an integer (instead of a long). This oviouly hurts on arches where
int has 32 bit but long has 64.
Two different work arounds can be used to cure the problem: either
declare the bitfield as int or cast x.cpl to long long instead of long.
Obviously none of these is a fix. I'll see if I can come up with a
patch.
regards Christian
--
THAT'S ALL FOLKS!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: c/7696: Spurious shift warning
@ 2003-04-06 15:26 Falk Hueffner
0 siblings, 0 replies; 4+ messages in thread
From: Falk Hueffner @ 2003-04-06 15:26 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR c/7696; it has been noted by GNATS.
From: Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
To: "Christian Ehrhardt" <ehrhardt@mathematik.uni-ulm.de>
Cc: gcc-gnats@gcc.gnu.org, schwab@suse.de, gcc-bugs@gcc.gnu.org,
nobody@gcc.gnu.org, gcc-prs@gcc.gnu.org
Subject: Re: c/7696: Spurious shift warning
Date: 06 Apr 2003 16:50:37 +0200
"Christian Ehrhardt" <ehrhardt@mathematik.uni-ulm.de> writes:
> struct ia64_psr {
> unsigned long cpl : 2;
> } x = {1};
>
> unsigned long y = ((unsigned long) x.cpl) << 40;
>
> According to gdb the cast is thrown away early (build_binary_op
> doesn't see it at all), probably because the bitfield is of type
> unsigned long.
All casts of bit-fields to the same type get discarded. This is a very
long standing bug and has already been reported as c/3325, c/3326,
c/6346, c/6515 and target/9620. We also have xfailing
gcc.c-torture/execute/bitfld-1.c for it.
--
Falk
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: c/7696: Spurious shift warning
@ 2003-01-08 2:15 bangerth
0 siblings, 0 replies; 4+ messages in thread
From: bangerth @ 2003-01-08 2:15 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, nobody, schwab
Synopsis: Spurious shift warning
State-Changed-From-To: open->analyzed
State-Changed-By: bangerth
State-Changed-When: Tue Jan 7 18:15:39 2003
State-Changed-Why:
Confirmed. Still exists in present 3.3 and 3.4
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7696
^ permalink raw reply [flat|nested] 4+ messages in thread
* c/7696: Spurious shift warning
@ 2002-08-23 5:06 Andreas Schwab
0 siblings, 0 replies; 4+ messages in thread
From: Andreas Schwab @ 2002-08-23 5:06 UTC (permalink / raw)
To: gcc-gnats
>Number: 7696
>Category: c
>Synopsis: Spurious shift warning
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Aug 23 04:56:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:
>Release: 3.2
>Organization:
>Environment:
System: Linux sykes 2.4.18-SMP #1 SMP Thu May 16 09:03:14 UTC 2002 ia64 unknown unknown GNU/Linux
Architecture: ia64
host: ia64-suse-linux-gnu
build: ia64-suse-linux-gnu
target: ia64-suse-linux-gnu
configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib --enable-languages=c,c++,f77,objc,java,ada --enable-libgcj --with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib --with-system-zlib --enable-shared --enable-__cxa_atexit ia64-suse-linux
>Description:
There is a spurious warning about shift count too big, although the
operand ist cast to the proper type.
>How-To-Repeat:
$ cat shift.c
struct ia64_psr {
unsigned long cpl : 2;
};
unsigned long foo (struct ia64_psr *c)
{
return (unsigned long) c->cpl << 62;
}
$ gcc -O2 -g -Wall -c -o shift.o shift.c
shift.c: In function `foo':
shift.c:7: warning: left shift count >= width of type
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-04-06 15:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-06 12:26 c/7696: Spurious shift warning Christian Ehrhardt
-- strict thread matches above, loose matches on Subject: below --
2003-04-06 15:26 Falk Hueffner
2003-01-08 2:15 bangerth
2002-08-23 5:06 Andreas Schwab
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).