Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site vaxine.UUCP Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!wanginst!vaxine!jwf From: jwf@vaxine.UUCP (Jim Franklin) Newsgroups: net.lang.c,net.bugs.4bsd Subject: VAX 4.2BSD cc compiler bug Message-ID: <22@vaxine.UUCP> Date: Fri, 31-Jan-86 14:02:31 EST Article-I.D.: vaxine.22 Posted: Fri Jan 31 14:02:31 1986 Date-Received: Sun, 2-Feb-86 06:02:00 EST Organization: Automatix, Inc., Billerica, MA Lines: 104 Xref: watmath net.lang.c:7729 net.bugs.4bsd:1948 ---- There is a bug in the VAX 4.2BSD cc compiler related to expressions involving "register short *" operands and the bitwise-& operator. The problem does not occur if you remove the "register" declaration or if you compile without optimizing. Program good.c below will correctly print: 6 6 1 However, if you autoincrement t in the printf statement, i.e., *t++ & SYM_TYPE, the optimizer generates bogus code and you get the following output from program bad.c: 6 1664 6 The problem is that the optimizer generates an extzv with autoincrement for bad.c, and the implied length is 4 bytes (so t gets incremented by 4 bytes rather than 2). -------------------------- good.c -------------------------------------- #define SYM_READONLY 0x8000 #define SYM_TYPE 0x7ff short t_values[] = { 6 | SYM_READONLY, 6 | SYM_READONLY, 1 | SYM_READONLY }; main() { register short * t; int i; t = t_values; for ( i = 0; i < 3; i++ ) { printf ("%d\n", *t & SYM_TYPE); t++; } } -------------------------- bad.c -------------------------------------- #define SYM_READONLY 0x8000 #define SYM_TYPE 0x7ff short t_values[] = { 6 | SYM_READONLY, 6 | SYM_READONLY, 1 | SYM_READONLY }; main() { register short * t; int i; t = t_values; for ( i = 0; i < 3; i++ ) printf ("%d\n", *t++ & SYM_TYPE); } -------------------------- good.s ------------------------------------- .data .data .align 1 .globl _t_values _t_values:.long 0x80068006 .long 0x8001 .text LL0:.align 1 .globl _main .data 1 L21:.ascii "%d\12\0" .text .set L13,0x800 .data .text _main:.word L13 subl2 $4,sp moval _t_values,r11 clrl -4(fp) L2000001:extzv $0,$11,(r11),-(sp) pushal L21 calls $2,_printf addl2 $2,r11 aoblss $3,-4(fp),L2000001 ret -------------------------- bad.s -------------------------------------- .data .data .align 1 .globl _t_values _t_values:.long 0x80068006 .long 0x8001 .text LL0:.align 1 .globl _main .data 1 L21:.ascii "%d\12\0" .text .set L13,0x800 .data .text _main:.word L13 subl2 $4,sp moval _t_values,r11 clrl -4(fp) L2000001:extzv $0,$11,(r11)+,-(sp) <-- wrong !!! pushal L21 calls $2,_printf aoblss $3,-4(fp),L2000001 ret -----------------------------------------------------------------------