segfault due to wrong data alignment in studio12
Hello all,
I just downloaded the realease version of Sun Studio 12.
After compiling our application with the CC compiler version
CC: Sun C++ 5.9 SunOS_i386 2007/05/03
Our applications segfaults due to a data alignment/sse2 error,
which is caused by a compiler bug.
This situation arises like this:
Two variables (in a class) are defined as:
int a[64];
double b[64];
...
and some time later initalized like this:
for(i=0;i<64;i++){ a=0; b=0.0; }
Using an optimization like
CC -fast -xtarget=opteron -xarch=sse2 -m64 -xdepend -xprefetch=auto -xprefetch_level=3
-xprefetch_auto_type=indirect_array_access -xvector=simd -g0 -xpagesize=2M
The application segfaults.
This is due to an illegal access on a non-16byte aligned address via MOVAPD:
The pointers to these array are calculated like this:
leaq0x33e8(%r12,%r9,4),%r8
leaq0x34e8(%r12,%r9,8),%r9
In this case, %r9 = 2 , %r12=0xfffffd7fffdf38a0
The access to memory in the loop is like:
movdqa %xmm0, (%r8)
->movapd %xmm1, (%r9)
with %xmm0 = 0, %xmm1 = 0
The applications fails with the movapd instruction, when
%r9 = 0xfffffd7fffdf6d98
This causes a general protection exception, according to
the AMD reference manual.
Did anybody encounter something like this?
This error did not occur with Studio11/C++.
# 2
> Please file a bug with more info and a small test
> case that actually fails. The simple
> case stated in your question does not produce the
> failure. Thanks!
Yes, I also checked if it would be reproducable
with a small test case, but usually it is not.
It only appears in our fairly large application.
While using the pre-release express edition of
studio12 there were many more errors like this one,
but I didn't track them down then. I just had the impression that
they were somehow connected to statically declared arrays.
With this one it was the first time I actually tracked down the error, but luckily
it remained the only one (until now) with studio12 release, which I got
rid of by lowering the optimization level.
I just wanted people to be aware that there might lurk something
with regard to high optimization levels and static array declarations.
Regards,
# 3
Hello,
despite my former impression that this error was rare it nevertheless occured at several places in our code now. Finally I managed to extract a small portion of the code which reproduces the problem:
[code]
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
class TESTCLASS{
public:
int PrintLevel;
bool AllSingles;
int MaxDIIS;
bool RelaxRefs;
double LevelShift;
int ATensorNuc[256];
double ATensorP[256];
bool AddVCOSMO;
TESTCLASS(){
int i;
for (i=0;i<256;i++){
ATensorNuc[i]=-1;
ATensorP[i] = 0.0;
}
}
};
int main(){
TESTCLASS a, b;
TESTCLASS c[5];
int i,j;
for(i=0;i<256; i++) {
a.ATensorNuc[i]=i+random();
b.ATensorNuc[i]=i+random();
}
}
[/code]
Compiled with:
CC -o test -fast -xtarget=opteron -xarch=sse2 -m64 -xdepend -xprefetch=auto -xprefetch_level=3 -xprefetch_auto_type=indirect_array_access -xvector=simd -g0 -xpagesize=2M -features=tmplife test.cpp
using
CC: Sun C++ 5.9 SunOS_i386 2007/05/03
it reproduces the error described above.
Regards,