🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.sun
Article #10831

Sun4 C compiler generates bad code under strange conditions

#10831
From: Felix Lee
Date: Thu, 09 Feb 1989 03:38
16 lines
1110 bytes
Compile and run the following (on a Sun4/260, SunOS4.0):

	main() { printf("%d %d\n", x(0), x(1)); }
	x(a) int a; { return (a==0) ? 99 : y() + y(); }
	y() { return 12; }

Curiously enough, it prints 0 and 12, instead of 99 and 24.  Looking at
the assembly code, the compiler is putting the intermediate return value
of x() into %i5, instead of somewhere useful, like %o0.

If you compile with at least -O2 optimization, it works correctly.
--
Felix Lee	flee@shire.cs.psu.edu	*!psuvax1!shire!flee

[[ Send it to Sun (if you haven't already)!  They'll see it someday.
--wnl ]]
Technical Details
Message-ID: <8902021245.AA22000@shire.cs.psu.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!rutgers!mit-eddie!uw-beaver!rice!sun-spots-request

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!rutgers!mit-eddie!uw-beaver!rice!sun-spots-request
From: flee@shire.cs.psu.edu (Felix Lee)
Newsgroups: comp.sys.sun
Subject: Sun4 C compiler generates bad code under strange conditions
Message-ID: <8902021245.AA22000@shire.cs.psu.edu>
Date: 9 Feb 89 03:38:21 GMT
Sender: usenet@rice.edu
Organization: Sun-Spots
Lines: 16
Approved: Sun-Spots@rice.edu
Original-Date: Thu, 02 Feb 89 07:45:00 EST
X-Sun-Spots-Digest: Volume 7, Issue 146, message 2 of 8