🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #775

GCC 1.36 -O (sparc) generates wrong code for float-int union

#775
From: Paul Eggert
Date: Thu, 09 Nov 1989 20:18
79 lines
2136 bytes
The following C program should print 0.  Under GCC 1.36 on a Sparcstation 1
(SunOS 4.0.3) using the -O option, it prints 7.

	#include <stdio.h>

	double d;

	main(argc, argv)
		int argc;
		char **argv;
	{
		if (argc) {
			union { float f; long l;} t;
			t.f = d;
			fprintf(stdout, "%d\n", t.l);
		} else
			fprintf(stdout, "");
		return 0;
	}

Here is a transcript.

	1-rise% gcc -v -O a.c
	gcc version 1.36
	 /local/lib/gcc-cpp -v -undef -D__GNUC__ -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__OPTIMIZE__ a.c /usr/tmp/cca17592.cpp
	GNU CPP version 1.36
	 /local/lib/gcc-cc1 /usr/tmp/cca17592.cpp -quiet -dumpbase a.c -O -version -o /usr/tmp/cca17592.s
	GNU C version 1.36 (sparc) compiled by GNU C version 1.36.
	default target switches: -mfpu -mepilogue
	 as -o a.o /usr/tmp/cca17592.s
	 ld -e start -dc -dp /lib/crt0.o a.o /local/lib/gcc-gnulib -lc
	2-rise% ./a.out
	7

Here is the assembly language output.  I am not a Sparc expert, but the
code marked **** looks like GCC tried to shoehorn two instructions into
one delay slot.

gcc_compiled.:
.text
LC0:
	.ascii "%d\12\0"
LC1:
	.ascii "\0"
	.align 4
.global _main
	.proc 1
_main:
	!#PROLOGUE# 0
	save %sp,-112,%sp
	!#PROLOGUE# 1
	tst %i0
	be L2
	nop
	sethi %hi(_d),%g1
	ldd [%g1+%lo(_d)],%f2
	fdtos %f2,%f2
	sethi %hi(__iob),%o0
	or %lo(__iob),%o0,%o0
	add %o0,20,%o0
	sethi %hi(LC0),%o1
	or %lo(LC0),%o1,%o1
	b L4
	st %f2,[%fp-4]			****
	ld [%fp-4],%o2			****
L2:
	sethi %hi(__iob),%o0
	or %lo(__iob),%o0,%o0
	add %o0,20,%o0
	sethi %hi(LC1),%o1
	or %lo(LC1),%o1,%o1
L4:
	call _fprintf,0
	nop
	mov 0,%i0
	ret
	restore
.global _d
.common _d,8,"bss"
Technical Details
Message-ID: <8911092018.AA17609@rise.twinsun.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!brutus.cs.uiuc.edu!rpi!tut.cis.ohio-state.edu!twinsun.com!eggert

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!brutus.cs.uiuc.edu!rpi!tut.cis.ohio-state.edu!twinsun.com!eggert
From: eggert@twinsun.com (Paul Eggert)
Newsgroups: gnu.gcc.bug
Subject: GCC 1.36 -O (sparc) generates wrong code for float-int union
Message-ID: <8911092018.AA17609@rise.twinsun.com>
Date: 9 Nov 89 20:18:10 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 79