[comp.sys.sgi] Bug on IRIX 4d 3.1 when -02 level optimizer used.

moss@BRL.MIL ("Gary S. Moss", VLD/VMB) (05/27/89)

Hi,
	Would someone look into this and at least see if it is present
on later releases of the IRIX for the 4D?

	I have finally boiled this one down to a nice little test case,
thanks to Doug Gwyn for his assistance in examining the assembly code.
We spent many hours trying to find something wrong with the generated
code, and although we saw some wasteful steps that were puzzling, no
errors were found.  This seems to point to a microcode or hardware-related
problem.  The code fails the same way on the 2 4Ds that I have tried it
on, one a 4D/60T, and the other with the GT option.  If compiled with
default optimization, it will successfully parse the string "1 2 3" into
3 args, but when compiled with -O2, it only gets the first 2 arguments.
For some reason 'strtok' is found to return NULL when it should have
returned "3".

	If sending to this list is not sufficient, would someone at SGI
please let me know?

Thanks much,
-moss

---------------------------------- cut me ---------------------------------
#include <stdio.h>
#include <string.h>

static void
user_Input( args )
char	*args[];
	{	register int	i;
	if( (args[0] = strtok( "1 2 3", " \t" )) == NULL )
		return;
	for( i = 1; args[i-1] != NULL ; ++i )
		args[i] = strtok( (char *) NULL, " \t" );

	write(2,"args:\n",6);
	for(i = 0;i<3;++i)
		{
		if(args[i])
			write(2,args[i],strlen(args[i]));
		else
			write(2,"(NULL)",6);
		write(2,"\n",1);
		}
	return;
	}

main()
	{	char *args[5];
	user_Input( args );
	}

gwyn@BRL.MIL (Doug Gwyn, VLD/VMB) (05/27/89)

Actually, it is just after args[1] received a pointer to "2" that
the first for-loop terminates prematurely.  strtok() definitely
returned "2" and that was definitely stored into args[1], but the
first for-loop failed to keep looping for what should have been
another two calls to strtok().

len@synthesis.Synthesis.COM (Len Lattanzi) (06/01/89)

In article <8905261424.aa06578@VGR.BRL.MIL> gwyn@BRL.MIL (Doug Gwyn, VLD/VMB) writes:
:Actually, it is just after args[1] received a pointer to "2" that
:the first for-loop terminates prematurely.  strtok() definitely
:returned "2" and that was definitely stored into args[1], but the
:first for-loop failed to keep looping for what should have been
:another two calls to strtok().

This seems to be a bug in the 1.31 as1 (instruction reorganizer). Version
2.0 works the same as the '-g' version. What seems to happening is that
i++ of the for-loop is moved before args[i] = strtok() without
changing the reference to args[i-1].

-Len
 Len Lattanzi (len@Synthesis.com) <{ames,pyramid,decwrl}!mips!synthesis!len>
 Synthesis Software Solutions, Inc. 		The RISC Software Company
I would have put a disclaimer here but I already posted the article.