From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24663 invoked by alias); 11 Jun 2002 00:56: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 24626 invoked by uid 71); 11 Jun 2002 00:56:00 -0000 Resent-Date: 11 Jun 2002 00:56:00 -0000 Resent-Message-ID: <20020611005600.24625.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, lucho@haemimont.bg Received: (qmail 20559 invoked by uid 61); 11 Jun 2002 00:48:15 -0000 Message-Id: <20020611004815.20558.qmail@sources.redhat.com> Date: Mon, 10 Jun 2002 17:56:00 -0000 From: lucho@haemimont.bg Reply-To: lucho@haemimont.bg To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: optimization/6985: GCC-3.x incorrectly initializes local arrays X-SW-Source: 2002-06/txt/msg00229.txt.bz2 List-Id: >Number: 6985 >Category: optimization >Synopsis: GCC-3.x incorrectly initializes local arrays >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: wrong-code >Submitter-Id: net >Arrival-Date: Mon Jun 10 17:56:00 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Luchezar Belev >Release: GCC-3.1 >Organization: >Environment: linux-2.4.18 pc-i686 glibc-2.1 gcc-3.1 >Description: It seems that the compiler reorders the initialization-to-zero with the following assignment operation so that the initialization comes last. >How-To-Repeat: /* * GCC-3.1 bug * compile with -O2 to let the bug to appear. * * The test should output (and does so when compiled with -O1 or less): * * aaaaa * a=13 * * but when compiled with -O2 or higher, instead it outputs: * * aaaaa * a=0 * * * I've tested this on 2.95.2, 3.0, 3.0.4 and 3.1. * 2.95.2 doesn't have this bug and all 3.x have it. */ unsigned a = 13, b = 17; int main() { unsigned char buf[18] = {0}; *(unsigned short *)(buf + 12) = a; *(unsigned short *)(buf + 14) = b; printf("aaaaa\n"); printf("a=%i\n", *(unsigned short *)(buf + 12)); return 0; } >Fix: To work around: make little changes to the source and the compiler won't confuse anymore. >Release-Note: >Audit-Trail: >Unformatted: