Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 14 Jun 2000 02:40:05 -0700 (PDT)
From:      Bruce Evans <bde@zeta.org.au>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: i386/19245: -fexpensive-optimizations buggy (even with -O)
Message-ID:  <200006140940.CAA76259@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR i386/19245; it has been noted by GNATS.

From: Bruce Evans <bde@zeta.org.au>
To: mi@aldan.algebra.com
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: i386/19245: -fexpensive-optimizations buggy (even with -O)
Date: Wed, 14 Jun 2000 19:37:28 +1000 (EST)

 On Tue, 13 Jun 2000, Mikhail Teterin wrote:
 
 > >Description:
 > 
 > 	The attached piece of code, when compiled with
 > 	``-O -fexpensive-optimizations'', produces incorrect
 > 	binary on FreeBSD-4.0 .
 > 
 > 	I tested the same compiler line on Mandrake Linux (an
 > 	identical machine hardware-wise) and it compiles correctly.
 
 This is hard to explain, since the bug shown by your example is in gcc
 (2.95.2), not in the assembler or linker.
 
 > static off_t
 > rfc1035QuestionPack(char *buf,
 >     size_t sz,
 >     const char *hostname,
 >     unsigned short class
 >     )
 > {
 >     off_t off = 0;
 >     unsigned short s;
 >     printf("In rfc1035QuestionPack: hostname is %p (%s)\n",
 > 	hostname, hostname);
 >     s = htons(class);
 >     memcpy(buf + off, &s, sizeof(s));
 >     off += sizeof(s);
 >     assert(off <= sz);
 >     return off;
 > }
 
 gcc -O -fexpensive-optimizations reuses the stack space for `hostname' and
 `class', and zeros this space to initialize `off' before loading `hostname'
 or `class'.
 
 > 	Yet, with the -fexpensive-optimizations flag, the hostname
 > 	argument is passed in the register, which, apparently, is
 > 	sometimes not loaded with the value and remains zero, resulting
 > 	in:
 
 No, -fexpensive-optimizations doesn't affect the function call protocol.
 Args are still passed on the stack.
 
 > >Fix:
 > 	Get the new assembler/binutils and add -fno-expensive-optimizations
 > 	to all CFLAGS in the meantime. Anything else?
 
 Don't use -O2 (which enables -fexpensive-optimizations) unless you want to
 find bugs like this :-).
 
 Bruce
 
 


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200006140940.CAA76259>