My program segfaults when compiled with gcc-4.6, gcc-4.7 or gcc-4.8, if I use the -O flag (or -O2 or -O3). Without optimization, no crash. (These compilers were gotten from Macports.)
There's no crash when I compile with gcc-4.2, even with -O3.
There's no crash when I compile with Apple's gcc-4.2 (based on llvm) using -O2, but there's a segfault if that same compiler is used with -O3.
Am I correct to assume that my code is OK and I've exposed compiler bugs?
Compiler bugs?
Moderators: hgm, Dann Corbit, Harvey Williamson
-
zullil
- Posts: 6442
- Joined: Tue Jan 09, 2007 12:31 am
- Location: PA USA
- Full name: Louis Zulli
-
rbarreira
- Posts: 900
- Joined: Tue Apr 27, 2010 3:48 pm
Re: Compiler bugs?
No, because your code could be relying on undefined behavior such as reading uninitialized memory etc.
The only sure way to find the problem is get a reproducible error and then narrow it down to see what piece of code is behaving differently between compilers. When you narrow it down enough (possibly down to the assembly code level) you'll know if it's a compiler fault or not.
The only sure way to find the problem is get a reproducible error and then narrow it down to see what piece of code is behaving differently between compilers. When you narrow it down enough (possibly down to the assembly code level) you'll know if it's a compiler fault or not.
-
ZirconiumX
- Posts: 1334
- Joined: Sun Jul 17, 2011 11:14 am
Re: Compiler bugs?
No.zullil wrote:My program segfaults when compiled with gcc-4.6, gcc-4.7 or gcc-4.8, if I use the -O flag (or -O2 or -O3). Without optimization, no crash. (These compilers were gotten from Macports.)
There's no crash when I compile with gcc-4.2, even with -O3.
There's no crash when I compile with Apple's gcc-4.2 (based on llvm) using -O2, but there's a segfault if that same compiler is used with -O3.
Am I correct to assume that my code is OK and I've exposed compiler bugs?
But I have seen bizarre compiler behaviour. On my computer I have to replace the compilers after a while, as they 'wear out' and start either producing suboptimal code or refusing to compile it at all.
Matthew:out
Some believe in the almighty dollar.
I believe in the almighty printf statement.
I believe in the almighty printf statement.
-
Codesquid
- Posts: 138
- Joined: Tue Aug 23, 2011 10:25 pm
- Location: Germany
Re: Compiler bugs?
So many different compiler versions, this makes it rather unlikely for it to be a compiler error in my opinion. My guess would be that you're accessing uninitialized memory, either because it hasn't been initialized yet, because it has already been freed, or because you're pointing to a totally wrong memory location.zullil wrote:My program segfaults when compiled with gcc-4.6, gcc-4.7 or gcc-4.8, if I use the -O flag (or -O2 or -O3). Without optimization, no crash. (These compilers were gotten from Macports.)
There's no crash when I compile with gcc-4.2, even with -O3.
There's no crash when I compile with Apple's gcc-4.2 (based on llvm) using -O2, but there's a segfault if that same compiler is used with -O3.
Am I correct to assume that my code is OK and I've exposed compiler bugs?
Have you yet tried running your program in valgrind, both with and without optimizations? Any error there indicates a potential problem in your code.
nanos gigantium humeris insidentes
-
zullil
- Posts: 6442
- Joined: Tue Jan 09, 2007 12:31 am
- Location: PA USA
- Full name: Louis Zulli
Re: Compiler bugs?
Thanks to all. After some time with gdb, perhaps I've found the problem.Codesquid wrote:So many different compiler versions, this makes it rather unlikely for it to be a compiler error in my opinion. My guess would be that you're accessing uninitialized memory, either because it hasn't been initialized yet, because it has already been freed, or because you're pointing to a totally wrong memory location.zullil wrote:My program segfaults when compiled with gcc-4.6, gcc-4.7 or gcc-4.8, if I use the -O flag (or -O2 or -O3). Without optimization, no crash. (These compilers were gotten from Macports.)
There's no crash when I compile with gcc-4.2, even with -O3.
There's no crash when I compile with Apple's gcc-4.2 (based on llvm) using -O2, but there's a segfault if that same compiler is used with -O3.
Am I correct to assume that my code is OK and I've exposed compiler bugs?
Have you yet tried running your program in valgrind, both with and without optimizations? Any error there indicates a potential problem in your code.
I switched recently from legal to pseudo-legal move generation. I'm storing the list of generated moves in an array of fixed size. That fixed size was adequate for strictly-legal moves, but it seems to have been too small for pseudo-legal moves (ie, I forgot to update my constant MOVELISTSIZE when I modified my move-generation code).
-
zullil
- Posts: 6442
- Joined: Tue Jan 09, 2007 12:31 am
- Location: PA USA
- Full name: Louis Zulli
Re: Compiler bugs?
An assert statement confirmed that my original size was indeed too small. It would have been too small probably even for strictly-legal moves, but I had managed to avoid crashes in my limited testing.zullil wrote:Thanks to all. After some time with gdb, perhaps I've found the problem.Codesquid wrote:So many different compiler versions, this makes it rather unlikely for it to be a compiler error in my opinion. My guess would be that you're accessing uninitialized memory, either because it hasn't been initialized yet, because it has already been freed, or because you're pointing to a totally wrong memory location.zullil wrote:My program segfaults when compiled with gcc-4.6, gcc-4.7 or gcc-4.8, if I use the -O flag (or -O2 or -O3). Without optimization, no crash. (These compilers were gotten from Macports.)
There's no crash when I compile with gcc-4.2, even with -O3.
There's no crash when I compile with Apple's gcc-4.2 (based on llvm) using -O2, but there's a segfault if that same compiler is used with -O3.
Am I correct to assume that my code is OK and I've exposed compiler bugs?
Have you yet tried running your program in valgrind, both with and without optimizations? Any error there indicates a potential problem in your code.
I switched recently from legal to pseudo-legal move generation. I'm storing the list of generated moves in an array of fixed size. That fixed size was adequate for strictly-legal moves, but it seems to have been too small for pseudo-legal moves (ie, I forgot to update my constant MOVELISTSIZE when I modified my move-generation code).
-
stegemma
- Posts: 859
- Joined: Mon Aug 10, 2009 10:05 pm
- Location: Italy
- Full name: Stefano Gemma
Re: Compiler bugs?
I have a strange behavior compiling Satana on Windows, with g++ on mingw32. I use some static library that have a lot of class on it. In Mac it compiles fine but in Windows it give me "unresolved reference" on some classes constructor and other functions. I use the same list of library for both environments and the error disappear just adding this kind of dummy lines in main cpp file:
clsString sDummy;
So i force the compiler to link in my "ligsbase" library, that contains the code for the class clsString. If i don't do that, the compiler doesn't add the library and then it doesn't find the code to link in. I think that the problem is that the clsString class is used indirectly in other static library, in a situation like this one:
ligsbase: code for clsString
components: other classes that uses clsString
Satana: use components classes but not directly ligsbase classes
This is very strange to me. Any compiler i've used can resolve this kind of library linking. Maybe i've missed some configuration for the linker or for the compiler?
g++ is version 4.6.2 on Windows (those that gives the problem) and 4.2 on the MAC
clsString sDummy;
So i force the compiler to link in my "ligsbase" library, that contains the code for the class clsString. If i don't do that, the compiler doesn't add the library and then it doesn't find the code to link in. I think that the problem is that the clsString class is used indirectly in other static library, in a situation like this one:
ligsbase: code for clsString
components: other classes that uses clsString
Satana: use components classes but not directly ligsbase classes
This is very strange to me. Any compiler i've used can resolve this kind of library linking. Maybe i've missed some configuration for the linker or for the compiler?
g++ is version 4.6.2 on Windows (those that gives the problem) and 4.2 on the MAC
-
Sven
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: Compiler bugs?
Does clsString use templates? That would explain it. Enabling implicit template instantiation through a compiler switch would be an alternative solution in that case.stegemma wrote:I have a strange behavior compiling Satana on Windows, with g++ on mingw32. I use some static library that have a lot of class on it. In Mac it compiles fine but in Windows it give me "unresolved reference" on some classes constructor and other functions. I use the same list of library for both environments and the error disappear just adding this kind of dummy lines in main cpp file:
clsString sDummy;
So i force the compiler to link in my "ligsbase" library, that contains the code for the class clsString. If i don't do that, the compiler doesn't add the library and then it doesn't find the code to link in. I think that the problem is that the clsString class is used indirectly in other static library, in a situation like this one:
ligsbase: code for clsString
components: other classes that uses clsString
Satana: use components classes but not directly ligsbase classes
This is very strange to me. Any compiler i've used can resolve this kind of library linking. Maybe i've missed some configuration for the linker or for the compiler?
g++ is version 4.6.2 on Windows (those that gives the problem) and 4.2 on the MAC
Sven
-
stegemma
- Posts: 859
- Joined: Mon Aug 10, 2009 10:05 pm
- Location: Italy
- Full name: Stefano Gemma
Re: Compiler bugs?
clsString use templates indirectly (in other classes) but all the template code is in headers. Maybe i can check if somewhere there are template code defined outside the headers.Sven Schüle wrote:...
Does clsString use templates? That would explain it. Enabling implicit template instantiation through a compiler switch would be an alternative solution in that case.
Sven
-
bob
- Posts: 20943
- Joined: Mon Feb 27, 2006 7:30 pm
- Location: Birmingham, AL
Re: Compiler bugs?
No. It is much more likely that a newer compiler optimization that causes a bug in your program to produce a crash. Things like uninitialized variables, or unsafe pointer usage can cause such to happen. Compiler bugs do happen, but 99% of the time, it is not the compiler that is at fault...zullil wrote:My program segfaults when compiled with gcc-4.6, gcc-4.7 or gcc-4.8, if I use the -O flag (or -O2 or -O3). Without optimization, no crash. (These compilers were gotten from Macports.)
There's no crash when I compile with gcc-4.2, even with -O3.
There's no crash when I compile with Apple's gcc-4.2 (based on llvm) using -O2, but there's a segfault if that same compiler is used with -O3.
Am I correct to assume that my code is OK and I've exposed compiler bugs?