From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27482 invoked by alias); 6 Apr 2003 12:26:01 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 27468 invoked by uid 71); 6 Apr 2003 12:26:01 -0000 Date: Sun, 06 Apr 2003 12:26:00 -0000 Message-ID: <20030406122601.27467.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: "Christian Ehrhardt" Subject: Re: c/7696: Spurious shift warning Reply-To: "Christian Ehrhardt" X-SW-Source: 2003-04/txt/msg00189.txt.bz2 List-Id: The following reply was made to PR c/7696; it has been noted by GNATS. From: "Christian Ehrhardt" 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!