🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Jyrki A Niemi Sat, 06 Jan 1996 00:00
A bug in gcc 2.7.2 optimization causing a fatal error
#6281
Author: Jyrki A Niemi
Date: Sat, 06 Jan 1996 00:00
138 lines
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/
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads