bug report for GCC 2.95.2
Taras Ivanenko
ivanenko@ctpa03.mit.edu
Mon Nov 15 06:47:00 GMT 1999
Here is the simple version of the bug i run into.
System description: SUN Ultra-1, Solaris 2.5.1
Compiler: 2.95.2 configured with Solaris bintools (as & ld) as recommended
The code below compiles and runs fine with
gcc -g
gcc -g -O2 -mcpu=supersparc
gcc -g -mcpu=ultrasparc
but fails with
gcc -O2 -mcpu=ultrasparc
Symptoms: The call to fail() function below generates "Bus error"
The reson seems to be that the compiler loads the double from the stack
by a single ldd operation but does not make sure that the stack
(frame pointer) is properly aligned. Adding the option -munaligned-doubles
does not help either. The only solution to my problem was to re-arrange
arguments for fail() so that it looks like succeed(). The number of ints
before the double argument seems to be important, the code works fine
with only 2 int arguments.
The stack pointer %sp *is* aligned on 8 bytes in main() and other functions,
fail() and succeed() so the problem is that the compiler does not pad
the arguments to 8 bytes but assumes anyway that the data are aligned.
I am not good in GCC internals to offer the fix.
Taras Ivanenko <ivanenko@ctpa03.mit.edu>
------------------------------------------------------------------------------
// #include <stdio.h>
double succeed(int, int, int, double d1, double d2, int i);
double fail(int, int, int, double d1, int i, double d2);
int main(int argc, char *argv[])
{
int x0=9;
int x1=2;
int x2=5;
double d1 = 1.3;
double d2 = 3.1;
int i = 5;
double retval = 0;
// fprintf(stderr, "Calling succeed()... ");
retval = succeed(x0, x1, x2, d1, d2, i);
// fprintf(stderr, "OK, returned from succeed()\n");
// fprintf(stderr, "Calling fail()... ");
retval = fail(x0, x1, x2, d1, i, d2);
// fprintf(stderr, "OK, returned from fail()\n");
return 0;
}
double succeed(int x0,
int x1, int x2, double d1, double d2, int i) {
return d2;
}
double fail(int x0,
int x1, int x2, double d1, int i, double d2) {
return d2;
}
----------------------------------------------------------------------
The assembler output, produced by: gcc -g -O2 -mcpu=ultrasparc -S bs.c
.file "bs.c"
.stabs "/a/home/ivanenko/tmp/",100,0,0,.LLtext0
.stabs "bs.c",100,0,0,.LLtext0
.section ".text"
.LLtext0:
.stabs "gcc2_compiled.", 0x3c, 0, 0, 0
.stabs "int:t(0,1)=r(0,1);0020000000000;0017777777777;",128,0,0,0
.stabs "char:t(0,2)=r(0,2);0;127;",128,0,0,0
.stabs "long int:t(0,3)=r(0,1);0020000000000;0017777777777;",128,0,0,0
.stabs "unsigned int:t(0,4)=r(0,1);0000000000000;0037777777777;",128,0,0,0
.stabs "long unsigned int:t(0,5)=r(0,1);0000000000000;0037777777777;",128,0,0,0
.stabs "long long int:t(0,6)=r(0,1);01000000000000000000000;0777777777777777777777;",128,0,0,0
.stabs "long long unsigned int:t(0,7)=r(0,1);0000000000000;01777777777777777777777;",128,0,0,0
.stabs "short int:t(0,8)=r(0,8);-32768;32767;",128,0,0,0
.stabs "short unsigned int:t(0,9)=r(0,9);0;65535;",128,0,0,0
.stabs "signed char:t(0,10)=r(0,10);-128;127;",128,0,0,0
.stabs "unsigned char:t(0,11)=r(0,11);0;255;",128,0,0,0
.stabs "float:t(0,12)=r(0,1);4;0;",128,0,0,0
.stabs "double:t(0,13)=r(0,1);8;0;",128,0,0,0
.stabs "long double:t(0,14)=r(0,1);16;0;",128,0,0,0
.stabs "complex int:t(0,15)=s8real:(0,1),0,32;imag:(0,1),32,32;;",128,0,0,0
.stabs "complex float:t(0,16)=r(0,16);4;0;",128,0,0,0
.stabs "complex double:t(0,17)=r(0,17);8;0;",128,0,0,0
.stabs "complex long double:t(0,18)=r(0,18);16;0;",128,0,0,0
.stabs "void:t(0,19)=(0,19)",128,0,0,0
.align 32
.stabs "main:F(0,1)",36,0,7,main
.stabs "argc:P(0,1)",64,0,6,24
.stabs "argv:P(0,20)=*(0,21)=*(0,2)",64,0,6,25
.global main
.type main,#function
.proc 04
main:
.stabn 68,0,7,.LLM1-main
.LLM1:
!#PROLOGUE# 0
save %sp, -120, %sp
!#PROLOGUE# 1
.stabn 68,0,8,.LLM2-main
.LLM2:
.LLBB2:
.stabn 68,0,12,.LLM3-main
.LLM3:
sethi %hi(1074318336), %l0
sethi %hi(-858993664), %l1
.stabn 68,0,11,.LLM4-main
.LLM4:
sethi %hi(1073007616), %l2
sethi %hi(-858993664), %l3
.stabn 68,0,10,.LLM5-main
.LLM5:
mov 5, %o2
.stabn 68,0,12,.LLM6-main
.LLM6:
or %l0, 204, %l0
or %l1, 205, %l1
.stabn 68,0,11,.LLM7-main
.LLM7:
or %l2, 204, %l2
.stabn 68,0,17,.LLM8-main
.LLM8:
st %o2, [%sp+96]
.stabn 68,0,11,.LLM9-main
.LLM9:
or %l3, 205, %l3
.stabn 68,0,17,.LLM10-main
.LLM10:
mov %l0, %o5
st %l1, [%sp+92]
mov 9, %o0
mov 2, %o1
mov %l2, %o3
call succeed, 0
mov %l3, %o4
.stabn 68,0,24,.LLM11-main
.LLM11:
mov 0, %i0
.stabn 68,0,21,.LLM12-main
.LLM12:
mov 9, %o0
mov 2, %o1
st %l0, [%sp+92]
mov 5, %o2
mov 5, %o5
st %l1, [%sp+96]
mov %l2, %o3
call fail, 0
mov %l3, %o4
.stabn 68,0,25,.LLM13-main
.LLM13:
.LLBE2:
return %i7+8
nop
.LLfe1:
.size main,.LLfe1-main
.stabs "x2:r(0,1)",64,0,10,10
.stabs "d1:r(0,13)",64,0,11,18
.stabs "d2:r(0,13)",64,0,12,16
.stabn 192,0,0,.LLBB2-main
.stabn 224,0,0,.LLBE2-main
.LLscope0:
.stabs "",36,0,0,.LLscope0-main
.align 32
.stabs "succeed:F(0,13)",36,0,28,succeed
.stabs "x0:P(0,1)",64,0,27,8
.stabs "x1:P(0,1)",64,0,28,9
.stabs "x2:P(0,1)",64,0,28,10
.stabs "d1:P(0,13)",64,0,28,11
.stabs "d2:p(0,13)",160,0,28,88
.stabs "i:p(0,1)",160,0,28,96
.global succeed
.type succeed,#function
.proc 07
succeed:
.stabn 68,0,28,.LLM14-succeed
.LLM14:
!#PROLOGUE# 0
!#PROLOGUE# 1
st %o5, [%sp+88]
.stabn 68,0,29,.LLM15-succeed
.LLM15:
retl
ldd [%sp+88], %f0
.LLfe2:
.size succeed,.LLfe2-succeed
.LLscope1:
.stabs "",36,0,0,.LLscope1-succeed
.align 32
.stabs "fail:F(0,13)",36,0,32,fail
.stabs "x0:P(0,1)",64,0,31,8
.stabs "x1:P(0,1)",64,0,32,9
.stabs "x2:P(0,1)",64,0,32,10
.stabs "d1:P(0,13)",64,0,32,11
.stabs "i:P(0,1)",64,0,32,13
.stabs "d2:p(0,13)",160,0,32,92
.global fail
.type fail,#function
.proc 07
fail:
.stabn 68,0,32,.LLM16-fail
.LLM16:
!#PROLOGUE# 0
!#PROLOGUE# 1
.stabn 68,0,33,.LLM17-fail
.LLM17:
retl
ldd [%sp+92], %f0 ! <----------- THIS STATEMENT FAILS
.LLfe3:
.size fail,.LLfe3-fail
.LLscope2:
.stabs "",36,0,0,.LLscope2-fail
.text
.stabs "",100,0,0,Letext
Letext:
.ident "GCC: (GNU) 2.95.2 19991024 (release)"
More information about the Gcc-bugs
mailing list