[comp.sys.sequent] C optmizer bug in DYNIX 3.0.12

rich@hacgate.scg.hac.com (Rich Loo) (10/13/88)

A member of our staff discovered a serious bug in the C optimizer 
under DYNIX 3.0.12.  I thought I'd post it here for the benefit of 
other 3.0.12 sites.  Sequent sent us a new /lib/c2 as an official
fix.  If you're running 3.0.12, you can try running the following
program to see if you have the bug.  If you do, call Sequent for the
fix.

Attached is copy of the mailbug.

Richard Loo 			UUCP:     ..!{elroy,gryphon}!hacgate!rich
(213) 648-0239			Internet: rich@hacgate.scg.hac.com

Hughes Aircraft Company
PO Box 92919 S65/J305
Los Angeles, Ca 90009

------------------------------------------------------------------------
From rlz Mon Aug 15 10:01:11 1988
Received: by hacgate.SCG.HAC.COM (4.12/smail2.5)
	id AA07914; Mon, 15 Aug 88 10:01:09 pdt
Date: Mon, 15 Aug 88 10:01:09 pdt
From: rlz (R. G. Curley)
Message-Id: <8808151701.AA07914@hacgate.SCG.HAC.COM>
To: pts
Subject: mailbug: C optimizer produces bad code rlz
Status: RO

	[... System configuration info deleted from here ... ]

Summary: C optimizer produces bad code
Severity: Serious
Category: Software
Id: unknown ()
Description:
Given the following program:
#define BS     1<<9		/* backspace */

#include <stdio.h>

int  var, *ip;

main()   {

   ip = &var;
   var = 0;
   *ip = *ip | BS ;
   printf("var = %O  %O\n",var,*ip);
   var = 01777777;
   *ip = *ip & BS;
   printf("var = %O  %O\n",var,*ip);
}

When compiled with -O, the first printf produces 2 2 instead of 1000 1000
The assembler code shows the problem
	.file	"orbar.c"
	.data
	.comm	_var,4
	.comm	_ip,4
	.text
	.align	2
	.globl	_main
_main:
	pushl	%ebp
	movl	%esp,%ebp
	movl	$_var,_ip
	movl	$0,_var
	movl	_ip,%eax
	orb     $2,(%eax)       <== SHOULD BE orl $512,(%eax)
	pushl	(%eax)
	pushl	_var
	pushl	$.L26
	call	_printf
	addl	$12,%esp
	movl	$524287,_var
	movl	_ip,%eax
	andl	$512,(%eax)
	pushl	(%eax)
	pushl	_var
	pushl	$.L27
	call	_printf
	addl	$12,%esp
	leave	
	ret	
/DEF	_main;

	.data
.L26:
	.byte	0x76,0x61,0x72,0x20,0x3d,0x20,0x25,0x4f,0x20,0x20
	.byte	0x25,0x4f,0x0a,0x00
.L27:
	.byte	0x76,0x61,0x72,0x20,0x3d,0x20,0x25,0x4f,0x20,0x20
	.byte	0x25,0x4f,0x0a,0x00
	.text
[End Description]