This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
optimization/7884: code compiled with optimization flag causes segmentation violation on powerpc
- From: aloeff at de dot ibm dot com
- To: gcc-gnats at gcc dot gnu dot org
- Date: 11 Sep 2002 08:27:42 -0000
- Subject: optimization/7884: code compiled with optimization flag causes segmentation violation on powerpc
- Reply-to: aloeff at de dot ibm dot com
>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=