From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20932 invoked by alias); 24 Sep 2002 16:46:03 -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 20903 invoked by uid 71); 24 Sep 2002 16:46:02 -0000 Resent-Date: 24 Sep 2002 16:46:02 -0000 Resent-Message-ID: <20020924164602.20902.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, dave@hiauly1.hia.nrc.ca Received: (qmail 19236 invoked by uid 61); 24 Sep 2002 16:39:55 -0000 Message-Id: <20020924163955.19233.qmail@sources.redhat.com> Date: Tue, 24 Sep 2002 09:46:00 -0000 From: dave@hiauly1.hia.nrc.ca Reply-To: dave@hiauly1.hia.nrc.ca To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: c/8023: Miscompilation of function grokdeclarator in c-decl.c at -O1 and above X-SW-Source: 2002-09/txt/msg00653.txt.bz2 List-Id: >Number: 8023 >Category: c >Synopsis: Miscompilation of function grokdeclarator in c-decl.c at -O1 and above >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: wrong-code >Submitter-Id: net >Arrival-Date: Tue Sep 24 09:46:00 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Dave Anglin >Release: gcc 3.2 and 3.3 (experimental) >Organization: >Environment: hppa64-hp-hpux11.00 >Description: The following test program char short *x23; should warn that a "long or short" was "specified with char". In trying to determine why the compiler doesn't warn, I found that the variable specbits is treated in inconsistently. The type of specbits is int (32 bits) but it appears that the compiler decides to treat it as a long (64 bits). However, there is a mixup in the subreg access. In some cases, it is accessed at offset 4 (correct) and in other cases it is accessed at offset 0 (incorrect). We have the following code and corresponding rtl at -O1 for the initialization of specbits at 387 of c-decl.c: specbits |= 1 << (int) i; (note 511 510 512 ("grokdeclarator.c") 387) (insn 512 511 513 0000000000000000 (set (reg:SI 215) (minus:SI (const_int 31 [0x1f]) (subreg:SI (reg/v:DI 182) 4))) -1 (nil) (nil)) (insn 513 512 514 0000000000000000 (set (reg:SI 214) (ashift:SI (const_int 1 [0x1]) (minus:SI (const_int 31 [0x1f]) (reg:SI 215)))) -1 (nil) (expr_list:REG_EQUAL (ashift:SI (const_int 1 [0x1]) (subreg:SI (reg/v:DI 182) 4)) (nil))) (insn 514 513 515 0000000000000000 (set (reg:SI 216) (ior:SI (reg:SI 214) (subreg/s:SI (reg/v:DI 74) 4))) -1 (nil) (nil)) (insn 515 514 516 0000000000000000 (set (reg/v:DI 74) (sign_extend:DI (reg:SI 216))) -1 (nil) (nil)) Then, up to line 478, specbits is accessed at offset 4 in DI 74, but a line 478 if ((specbits & 1 << (int) RID_LONG) && (specbits & 1 << (int) RID_SHORT)) error ("both long and short specified for `%s'", name); the following rtl is generated (note 882 881 883 ("grokdeclarator.c") 478) (insn 883 882 884 0000000000000000 (set (reg:SI 328) (const_int 132 [0x84])) -1 (nil) (nil)) (insn 884 883 885 0000000000000000 (set (reg:SI 327) (and:SI (subreg:SI (reg/v:DI 74) 0) (reg:SI 328))) -1 (nil) (nil)) So, the generated assembly code ands SI 327 with the high-order 32 bits instead of the low-order 32 bits of DI 74. This is why the proper warnings are not being generated. This doesn't appear to be a regression as 3.2 has the same behavior as 3.3. The code generated at -O0 is ok. >How-To-Repeat: >Fix: >Release-Note: >Audit-Trail: >Unformatted: