[comp.sys.sgi] C compiler bug on SGIs, maybe MIPS in general ...

cameron@vast.eecs.unsw.oz.au (Cameron Simpson) (11/26/90)

Here's a bug in the C compiler on an IRIX 3.3.1 machine. It may
apply to all MIPS machines.

Consider the following (reduced from code using <sys/wait.h> etc):

	#define WTERMSIG(x)     (((union u *)&(x))->z)

	union u 	{ short z;
			};

	int
	v(x)
	int x;
	{
		return (x != 0)|WTERMSIG(x);
	}

When compiled it causes the C compiler to say
    ugen: internal  : line 10 : translate.p, line 1828
		    offset/length mismatch between vreg and reference

Line 10 is the return statement.

If I change the `short' in the union definition `int' everything is fine.
If I remove the `(x != 0)|' from the return expression everything is fine.

My current workaround is to declare a static function, so:
	#ifdef	sgi /* may be generic MIPS, but don't know yet */
	static int
	wtermsig(x)
	int x;
	{
		return WTERMSIG(x);
	}
	#else
	# define wtermsig(x) WTERMSIG(x)
	#endif
and then to return
	return (x != 0)|wtermsig(x);

cc -V says:
	cc  (cc)
		Mips Computer Systems 2.0
	/usr/lib/cpp:
	/usr/lib/ujoin:
	/usr/bin/uld:
	/usr/lib/usplit:
	/usr/lib/umerge:
	/usr/lib/uopt:
	/usr/lib/ugen:
	/usr/lib/as0:
	/usr/lib/as1:
	/usr/bin/ld:
	/usr/lib/ftoc:
	/usr/lib/cord:
		 ldclose.c: 1.3 2/16/83
		 ldopen.c: 1.3 2/16/83
		 ldohseek.c: 1.1 1/7/82
		 ldshread.c: 1.1 1/7/82
		 ldsseek.c: 1.1 1/7/82
		 ldnsseek.c: 1.1 1/7/82
		 ldgetname.c: 1.2 2/16/83
		 ldgetname.c: 1.2 2/16/83
		 ldtbread.c: 1.1 1/7/82
		 ldrseek.c: 1.1 1/7/82
		 ldnrseek.c: 1.1 1/7/82
		 vldldptr.c: 1.1 1/8/82
		 allocldptr.c: 1.2 2/16/83
		 freeldptr.c: 1.1 1/7/82
		 ldnshread.c: 1.1 1/7/82
	/usr/lib/crt1.o:
	/usr/lib/crtn.o:

Has anyone else seen this? Is there a version of the compiler with a fix?
	- Cameron Simpson
	  cameron@spectrum.cs.unsw.oz.au

rogerk@mips.COM (Roger B.A. Klorese) (11/28/90)

In article <965@usage.csd.unsw.oz.au> cameron@spectrum.cs.unsw.oz.au (Cameron Simpson) writes:
>Here's a bug in the C compiler on an IRIX 3.3.1 machine. It may
>apply to all MIPS machines.
>cc -V says:
>	cc  (cc)
>		Mips Computer Systems 2.0

...and it is fixed in release 2.10 and later.
-- 
ROGER B.A. KLORESE                                  MIPS Computer Systems, Inc.
MS 6-05    930 DeGuigne Dr.   Sunnyvale, CA  94086              +1 408 524-7421
rogerk@mips.COM         {ames,decwrl,pyramid}!mips!rogerk         "I'm the NLA"
"The problem with the rat race is even if you win you're still a rat." - Tomlin