Re: egcs-1.1.2 ping bug also causes miscompilation of pcbit isdn driver

R. Kelley Cook (KCook@IBM.net)
Wed, 16 Jun 1999 19:04:10 -0400 (EDT)


On 13 Jun 1999 16:47:26 +0200, Lars Heete wrote:

>Hello,
>
>the bug in egcs-1.1.2 that causes miscompilations of in_cksum also is
>responsible for the pcbit-isdn driver failure (See thread "Still no ISDN
>connection"). I suspect there are some other places in kernel
>which suffer from this bug.
>
>--------------------- test case ----------------------
>#include <stdio.h>
>int main(int argc, char **argv) {
> struct {char c1, c2, c2, 4;} t;
> t.c4 = 0x78; t.c3 = 0x56; t.c2 = 0x34; t.c1 = 0x12;
> printf("0x%x\n", *((unsigned long*) &t));
> return 0;
>}
>
>gives 0x12 with egcs-1.1.2 on i386, instead of 0x78563412.
>

>From egcs mailing list:

==================BEGIN FORWARDED MESSAGE==================
>From: law@cygnus.com (Jeffrey A Law)
>Subject: Re: Strange bug in egcs-1.1.2 suspected
>Date: 16 Jun 1999 07:08:12 +0200
>Message-ID: <4573.929509316@upchuck.cygnus.com>
>References: <37665FF4.F7203D26@darmstadt.gmd.de>
>Reply-To: law@cygnus.com
>Mailing-List: contact egcs-help@egcs.cygnus.com; run by ezmlm

In message <37665FF4.F7203D26@darmstadt.gmd.de>you write:
> -------------------------------------------------------------
> #include <stdio.h>
>
> int
> main(int argc, char **argv)
> {
> struct {char c1, c2, c3, c4;} t;
> t.c4 = 0x78; t.c3 = 0x56; t.c2 = 0x34; t.c1 = 0x12;
> printf("0x%x\n", *((unsigned long*) &t));
> return 0;
> }
> -------------------------------------------------------------
> Remember, the following is compiled with egcs-1.1.2 where Mark's
> aliasing framework is disabled by default:
>
> pommnitz ~/alias>gcc aliasorig.c -o aliasorig
> pommnitz ~/alias>./aliasorig
> 0x78563412
> pommnitz ~/alias>gcc -O2 aliasorig.c -o aliasorig
> pommnitz ~/alias>./aliasorig
> 0x12
> pommnitz ~/alias>gcc -O2 -fno-strict-aliasing aliasorig.c -o aliasorig
> pommnitz ~/alias>./aliasorig
> 0x12
This is a known bug in egcs-1.1.2 -- it is not related to strict aliasing.
Though the code is not valid according to the aliasing rules of ISO/ANSI.

> #include <stdio.h>
>
> #define noalias(type, ptr) (((union { type __x__; __typeof__(*(ptr)) __y__;
> } *)(ptr))->__x__)
>
> int
> main(int argc, char **argv)
> {
> struct {char c1, c2, c3, c4;} t;
> t.c4 = 0x78; t.c3 = 0x56; t.c2 = 0x34; t.c1 = 0x12;
> printf("0x%x\n", noalias (unsigned long, &t));
> return 0;
> }
> -------------------------------------------------------------
>
> The result:
> pommnitz ~/alias>gcc -O2 alias2.c -o alias2
> pommnitz ~/alias>./alias2
> 0x12
>
> Still not what we want. OK, next try:
No surprise since the bug in egcs-1.1.2 isn't related to type based aliasing.

> Can somebody comment on this?
Yea, there was a code gen bug in egcs-1.1.2 independent of strict aliasing
that caused this code to blow up. That bug has been fixed. All three
versions produce the correct answers with gcc-2.95, even though correctness
for the first one can not be guaranteed due to strict aliasing violations.

jeff

===================END FORWARDED MESSAGE===================

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/