Article View: gnu.gcc.bug
Article #6281A bug in gcc 2.7.2 optimization causing a fatal error
From: Jyrki A Niemi
Date: Sat, 06 Jan 1996 00:00
Date: Sat, 06 Jan 1996 00:00
138 lines
4614 bytes
4614 bytes
Hello!
I think I've discovered in gcc 2.7.[12] a bug which causes a "fatal
signal 11" (segmentation fault) in cc1 when optimization is turned on
(regardless of optimization level). The bug would seem to relate to
the optimization of expressions with an operator && whose operands
contain bitwise &'s. (However, the expression which triggered the bug
appeared to contain a bug in itself.)
The bug occurred with gcc 2.7.1 and 2.7.2 on a Sun SPARCstation 10/40
running SunOS 4.1.3, but neither with gcc 2.4.5 on the same machine
nor with gcc 2.6.3 on a Sun SPARCserver 10/30 running Solaris 2.4.
I experimented a bit with the code causing the bug to occur, and found
that the program shown below was the simplest one with which I could
get the same compiler error. More specifically, the expression
((a & 1) && ! (a & 2 & 4)) seemed to cause the error. (Considering
what the program does, this expression is unnecessarily complicated,
since it is the same as (a & 1).)
I hope the captured session below illustrates the bug clearly enough.
I have also included several slightly modified versions of the program
(expression) which didn't cause the bug to appear.
------------------------------------------------------------------------------
[29] polva$ cat gcctest.c
/* With optimization, this produces a "fatal signal 11" in cc1.
Because 2 & 4 == 0, ! (a & 2 & 4) == 1 always, and therefore
the expression below could be optimized to (a & 1). */
int main (void)
{
unsigned a;
return ((a & 1) && ! (a & 2 & 4));
}
[30] polva$ gcc gcctest.c
[31] polva$ gcc -O -v gcctest.c
Reading specs from /usr/local/lib/gcc-lib/sparc-sun-sunos4.1.3/2.7.2/specs
gcc version 2.7.2
/usr/local/lib/gcc-lib/sparc-sun-sunos4.1.3/2.7.2/cpp -lang-c -v -undef -D__GNUC__=2 -D__GNUC_MINOR__=7 -Dsparc -Dsun -Dunix -D__GCC_NEW_VARARGS__ -D__sparc__ -D__sun__ -D__unix__ -D__GCC_NEW_VARARGS__ -D__sparc -D__sun -D__unix -Asystem(unix) -Asystem(bsd) -Acpu(sparc) -Amachine(sparc) -D__OPTIMIZE__ gcctest.c /usr/tmp/cca06815.i
GNU CPP version 2.7.2 (sparc)
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/local/sparc-sun-sunos4.1.3/include
/usr/local/lib/gcc-lib/sparc-sun-sunos4.1.3/2.7.2/include
/usr/include
End of search list.
/usr/local/lib/gcc-lib/sparc-sun-sunos4.1.3/2.7.2/cc1 /usr/tmp/cca06815.i -quiet -dumpbase gcctest.c -O -version -o /usr/tmp/cca06815.s
GNU C version 2.7.2 (sparc) compiled by GNU C version 2.7.2.
gcc: Internal compiler error: program cc1 got fatal signal 11
[32] polva$ cat gcctest1.c
/* This compiles OK ((2 & 4) grouped with parentheses) */
int main (void)
{
unsigned a;
return ((a & 1) && ! (a & (2 & 4)));
}
[33] polva$ gcc -O gcctest1.c
[34] polva$ cat gcctest2.c
/* This compiles OK (2 & 6 != 0) */
int main (void)
{
unsigned a;
return ((a & 1) && ! (a & 2 & 6));
}
[35] polva$ gcc -O gcctest2.c
[36] polva$ cat gcctest3.c
/* This compiles OK (the second operand to && not negated) */
int main (void)
{
unsigned a;
return ((a & 1) && (a & 2 & 4));
}
[37] polva$ gcc -O gcctest3.c
[38] polva$ cat gcctest4.c
/* This compiles OK */
int main (void)
{
unsigned a;
return (! (a & 2 & 4));
}
[39] polva$ gcc -O gcctest4.c
[40] polva$ cat gcctest5.c
/* This compiles OK (two different variables, a and b) */
int main (void)
{
unsigned a, b;
return ((a & 1) && ! (b & 2 & 4));
}
[41] polva$ gcc -O gcctest5.c
[42] polva$ cat gcctest6.c
/* This compiles OK (the first operand to && is a variable) */
int main (void)
{
unsigned a;
return (a && ! (a & 2 & 4));
}
[43] polva$ gcc -O gcctest6.c
[44] polva$
------------------------------------------------------------------------------
Thanks for an excellent compiler! (In this case the bug in gcc helped
me to spot a bug in my own program.)
Jyrki Niemi
--
-----------------------------------------------------------------
jyrki.niemi@helsinki.fi http://www.ling.helsinki.fi/~janiemi/
Technical Details
Message-ID:
<199601061626.SAA00427@myntti.helsinki.fi>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 113d02,a749fd3d3dc16e18,start X-Google-Attributes: gid113d02,public From: janiemi@cc.helsinki.FI (Jyrki A Niemi) Subject: A bug in gcc 2.7.2 optimization causing a fatal error Date: 1996/01/06 Message-ID: <199601061626.SAA00427@myntti.helsinki.fi> X-Deja-AN: 134325077 distribution: gnu sender: daemon@cis.ohio-state.edu organization: GNUs Not Usenet newsgroups: gnu.gcc.bug