[gnu.emacs.bug] VMS C compiler bug

GENTZEL@CPWSCB.PSC.EDU (Dave Gentzel) (06/04/89)

I've uncovered a major bug in version 3.0 of DEC's VAX C compiler for VMS.
This bug showed up compiling GNU Emacs.  (Emacs users take note.  You should
compile DISPNEW.C with /OPTIMIZE=NOINLINE so long as this bug exists.  There
may be other files which tickle the bug, but this is the only one I noticed.
The symptom is that redisplays become strangely and decidedly non-optimal!)

Basically, the compiler messes up some references to the arguments of inlined
functions.  Here is a file which tickles the bug along with an annotated
assembler listing showing the problem.  Yet another reason to use GCC, I
suppose...

					David Gentzel
					Pittsburgh Supercomputing Center
					gentzel@cpwsca.psc.edu
					or gentzel@morgul.psc.edu

P.S. I haven't submitted an SPR on this.  Any takers?

------------------------------ bug.c ------------------------------
int count_blanks(char *str)
{
    char *p = str;

    while (*str++ == ' ');
    return str - p - 1;
}

int bug(char *s)
{
    return count_blanks(s);
}
------------------------------ tst.c ------------------------------
#include <stdio.h>

main()
{
    char test[] = "    ";

    printf("right: %d\ncount_blanks: %d\nbug: %d\n",
	   sizeof test - 1, count_blanks(test), bug(test));
}
-------------------------------------------------------------------
int count_blanks(char *str)
{
				count_blanks:
				    .entry	count_blanks,^m<>
				    subl2	#4,sp
    register char *p = str;
				    movl	4(ap),r1

    while (*str++ == ' ');
				    incl	4(ap)
				    cmpb	(r1),#32
				    bneq	sym.2
				    tstl	r0
				    nop	
				sym.1:
				    movl	4(ap),r0
				    incl	4(ap)
				    cmpb	(r0),#32
				    beql	sym.1
				sym.2:
    return str - p - 1;
				    subl3	r1,4(ap),r0
				    decl	r0
				    ret	
}

int bug(register char *s)
{
				bug:
				    .entry	bug,^m<r2>
				    subl2	#4,sp
    return count_blanks(s);
				    movl	4(ap),r1
				    cmpb	(r1)+,#32
				    bneq	sym.4
				    tstl	r0
				sym.3:
				    cmpb	(r1)+,#32
				    beql	sym.3
				sym.4:
				    subl3	r1,r1,r2    <--- BUG HERE
							         should be
							    subl3 r1,4(ap),r2
				    decl	r2
				    movl	r2,r0
				    ret	
}
-------------------------------------------------------------------