From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11257 invoked by alias); 11 Sep 2002 08:36: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 11234 invoked by uid 71); 11 Sep 2002 08:36:01 -0000 Resent-Date: 11 Sep 2002 08:36:01 -0000 Resent-Message-ID: <20020911083601.11233.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, aloeff@de.ibm.com Received: (qmail 8813 invoked by uid 61); 11 Sep 2002 08:27:42 -0000 Message-Id: <20020911082742.8812.qmail@sources.redhat.com> Date: Wed, 11 Sep 2002 01:36:00 -0000 From: aloeff@de.ibm.com Reply-To: aloeff@de.ibm.com To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: optimization/7884: code compiled with optimization flag causes segmentation violation on powerpc X-SW-Source: 2002-09/txt/msg00182.txt.bz2 List-Id: >Number: 7884 >Category: optimization >Synopsis: code compiled with optimization flag causes segmentation violation on powerpc >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: sw-bug >Submitter-Id: net >Arrival-Date: Wed Sep 11 01:36:01 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Andreas Loeffler >Release: 3.1 and 3.2 >Organization: >Environment: redhat 7.1 [lefty@trinity - 09:34am: ~]$ powerpc-linux-gcc -v Reading specs from /opt/fsp/i586-pc-linux-gnu/local/lib/gcc-lib/powerpc-linux/3.2/specs Configured with: ../configure --host=i586-pc-linux-gnu --target=powerpc-linux --prefix=/opt/fsp/i586-pc-linux-gnu/local --enable-shared --enable-languages=c,c++,f77 --with-headers=/opt/fsp/powerpc-linux/include --with-libs=/opt/fsp/powerpc-linux/lib --with-cpu=403 --without-fp Thread model: posix gcc version 3.2 >Description: We have encountered problems compiling our code with the -Os flag (and -O, -O2, -O3) and attempting to run on the hardware. We've tracked it down to one particular scenario that causes the problem If you have a function defined like this int f(char*& data); and some code that calls it that looks like this rc = f((char*)myData); x = myData->value; The value myData does not get set and we get a segmentation violation. To fix it, it needs to be changed to rc = f((char*&)myData); >How-To-Repeat: powerpc-linux-g++ -o test-opt test-opt.cc without optimization myData gets assigned a value powerpc-linux-g++ -O -o test-opt test-opt.cc powerpc-linux-g++ -Os -o test-opt test-opt.cc powerpc-linux-g++ -O3 -o test-opt test-opt.cc with optimization myData becomes a null pointer which can cause seg faults >Fix: >Release-Note: >Audit-Trail: >Unformatted: ----gnatsweb-attachment---- Content-Type: application/octet-stream; name="test-opt.cc" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="test-opt.cc" I2luY2x1ZGUgPHN0ZGlvLmg+Cgp2b2lkIGYoY2hhciomIGRhdGEpCnsKICAgIGNoYXIqIHRtcCA9 IG5ldyBjaGFyWzI1Nl07CiAgICBkYXRhID0gdG1wOwp9CgoKaW50IG1haW4gKGludCBhcmdjLCBj aGFyICphcmd2W10pCnsKICAgIHZvaWQqIG15RGF0YSA9IDA7CgogICAgLy9mKChjaGFyKiYpbXlE YXRhKTsKICAgIGYoKGNoYXIqKW15RGF0YSk7CgogICAgcHJpbnRmKCJteURhdGEoMSkgPSAleFxu IixteURhdGEpOwoKICAgIHJldHVybiAwOwp9Cgo=