Subject: gcc optimizer bug in netbsd-1-6 on alpha (gcc 2.95.3 20010315 (release) (NetBSD nb3))
To: NetBSD/alpha Discussion List <port-alpha@NetBSD.ORG>
From: Greg A. Woods <woods@weird.com>
List: tech-toolchain
Date: 08/14/2003 14:40:22
It seems I've encountered a bug with the optimizer in GCC on alpha on
the netbsd-1-6 branch:

	13:45 [29] $ cc -pipe -c addr.c
	13:45 [30] $ cc -O -pipe -c addr.c  
	addr.c: In function `check_target_and_remainder':
	addr.c:718: Internal compiler error in `fixup_var_refs_1', at function.c:2081
	Please submit a full bug report.
	See <URL:http://www.gnu.org/software/gcc/bugs.html> for instructions.
	cpp0: output pipe has been closed
	13:45 [31] $ cc --version
	2.95.3
	13:46 [32] $ cc -v 
	Using builtin specs.
	gcc version 2.95.3 20010315 (release) (NetBSD nb3)
	13:46 [33] $ uname -mrs
	NetBSD 1.6.1_STABLE alpha

The source in question is from smail.  It doesn't seem very complicated
to my eyes and as far as I know hasn't caused any problems with other
GCC variants, including on sparc64, though this may be the first time
this function has been compiled on NetBSD/alpha in recent times.

Removing all but the function in question, and paring it down to just
the following little bit of code derived from the original, still
triggers the problem:

	14:24 [81] $ cat addrgcc.c 
	#include <sys/types.h>
	#include <netinet/in.h>
	#include <arpa/inet.h>
	#include <stdio.h>
	
	static int make_gcc_barf_on_alpha __P((void));
	
	static int
	make_gcc_barf_on_alpha()
	{
		unsigned long inet = 0;		/* an IPv4 address */
	
		printf("parse_address(): inet addr given: [%s]\n",
		       inet_ntoa(*((struct in_addr *) &inet)));
	}
	14:24 [82] $ cc -O -pipe -c addrgcc.c 
	addrgcc.c: In function `make_gcc_barf_on_alpha':
	addrgcc.c:15: Internal compiler error in `fixup_var_refs_1', at function.c:2081
	Please submit a full bug report.
	See <URL:http://www.gnu.org/software/gcc/bugs.html> for instructions.

Now I know I can work around this by making that inet_ntoa() call into
what I believe to be the more correct/portable form:

	inet_ntoa(inet_makeaddr(inet, (unsigned long) 0))

Regardless the compiler shouldn't barf with an internal error.

Is this perhaps a known bug?

Should I do as it says and go via GNU.ORG, or should I send-pr, or both?

-- 
						Greg A. Woods

+1 416 218-0098                  VE3TCP            RoboHack <woods@robohack.ca>
Planix, Inc. <woods@planix.com>          Secrets of the Weird <woods@weird.com>