GCC 4.0 code generation bug
GCC 4.0 code generation bug
- Subject: GCC 4.0 code generation bug
- From: Matthew Litwin <email@hidden>
- Date: Thu, 19 Aug 2010 17:02:34 -0700
Hi,
I believe I've run into a code generation bug in GCC 4.0 / Xcode 3.2.2, which occurs under optimization. GCC 4.2 doesn't show the problem, but we're using 4.0 in order to deploy on Tiger. The code below is a boiled down version of the problem. With that code, the problem occurs at -O2, rather than the -Os we are in fact using in our non-boiled down project, but this is the construct that is giving us problems.
Questions:
1) Am I hallucinating, or is this in fact a code-gen bug, rather than programmer error?
2) If it is a code-gen bug, what's the recommended workaround (judicious use of "volatile" seems to work, for example, but there are other twiddles).
3) If it is a code-gen bug, what's the pattern to when the bug shows up? If I know that, I can try and see if there are other places in the code vulnerable to the same bug.
I've logged this with Apple: Radar 8332481.
Thanks for information / suggestions,
Matthew Litwin
KCP Technologies
==== test.c ====
/*
Expected result: "Good"
$ gcc-4.0 -O0 test.c; ./a.out
Good
$ gcc-4.0 -O2 test.c; ./a.out
Bad
$ gcc-4.0 -v
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /var/tmp/gcc_40/gcc_40-5493~371/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib --build=i686-apple-darwin10 --with-arch=apple --with-tune=generic --host=i686-apple-darwin10 --target=i686-apple-darwin10
Thread model: posix
gcc version 4.0.1 (Apple Inc. build 5493)
Perhaps related bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29605
*/
#include <stdio.h>
static const int f[10]; /* const is necessary for the bug */
static int g = 0;
static int Get_g(void)
{
return g;
}
extern void Set_g(int new_g); /* extern is necessary for the bug */
void Set_g(int new_g)
{
g = new_g;
}
int main(void)
{
if (0 == f[Get_g()]) {
Set_g(1);
if (1 == Get_g())
printf("Good\n");
else
printf("Bad\n");
}
return 0;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden