🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #2343

gcc-1.33 (sun4-os4) bug without -O (n=1 ==> n*n=-134219372)

#2343
From: Jim Meyering
Date: Tue, 21 Feb 1989 20:46
49 lines
1709 bytes
In these 3 cases, if -O is used, we get the right answer.
Similarly, if statements like "foo = n*n;" or "printf("%d\n",n);"
are placed between the definition and the use of n, the
problem does not arise.

% gcc -DARGV gcc-bug.c; a.out 1
n=1, n*n=-134219372
% gcc -DLITERAL gcc-bug.c; a.out 1
n=1, n*n=124
% gcc -DCONSTANT gcc-bug.c; a.out 1
n=1, n*n=1

% gcc -v -DARGV gcc-bug.c
gcc version 1.33
 /p/lib/gcc-1.33/gcc-cpp -v -DARGV -undef -D__GNUC__ -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ gcc-bug.c /tmp/cca25288.cpp
GNU CPP version 1.33
 /p/lib/gcc-1.33/gcc-cc1 /tmp/cca25288.cpp -quiet -dumpbase gcc-bug.c -version -o /tmp/cca25288.s
GNU C version 1.33 (sparc) compiled by GNU C version 1.33.
 as /tmp/cca25288.s -o gcc-bug.o
 ld -e start -dc -dp /lib/crt0.o gcc-bug.o /p/lib/gcc-1.33/gcc-gnulib -lc
0.2u 1.0s 0:06 17% 0+272k 86+32io 157pf+0w
% 
------------------------------------
	void
main(argc,argv)
	int argc;
	char **argv;
{
	int n, atoi();

#if defined(ARGV)
	if (argc < 2) {
		printf("usage: %s n\n",argv[0]);
		exit(1);
	}
	n = atoi(argv[1]);
#elif defined(LITERAL)
	n = atoi("1");
#elif defined(CONSTANT)
	n = 1;
#else
# error "must use -D(ARGV|LITERAL|CONSTANT)"
#endif
	printf("n=%d, n*n=%d\n", n, n*n);
	exit(0);
}
-- 
---
Jim Meyering      meyering@cs.utexas.edu
Technical Details
Message-ID: <189@ai.cs.utexas.edu>
Path: arc1-ca.pugleaf.net!utzoo!telly!attcan!uunet!tut.cis.ohio-state.edu!cs.utexas.edu!meyering

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!attcan!uunet!tut.cis.ohio-state.edu!cs.utexas.edu!meyering
From: meyering@cs.utexas.edu (Jim Meyering)
Newsgroups: gnu.gcc.bug
Subject: gcc-1.33 (sun4-os4) bug without -O (n=1  ==>  n*n=-134219372)
Message-ID: <189@ai.cs.utexas.edu>
Date: 21 Feb 89 20:46:23 GMT
Distribution: gnu
Organization: U. Texas CS Dept., Austin, Texas
Lines: 49