🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #329

bug in gcc 2.2.2 for Sparc/SunOS 4.1.1

#329
From: Sean E. Trowbridge
Date: Mon, 10 Aug 1992 16:23
161 lines
4103 bytes
Version/platform:
-----------------
vanilla (no modifications) gcc 2.2.2 
Sun Sparc IPC
SunOS 4.1.1

Bug:
----
When optimizing, gcc rearranges a call to memcpy with assignments to the
structure being copied to, thus writing over the assignments with the misplaced
memcpy call.

Command line:

gcc -g -O2 -S class.i

generates assembly file class.s with incorrect code.


Files:
------
class.i is the preprocessor output which compiles to cause the bug
(suitably modified to eliminate irrelevant stuff).

------class.i--------
# 1 "/home/vde/src/vclass/class.c"

typedef struct vclassRoot {
    void                    *super; 
    const char              *name; 
    int                     size; 
    int                     objectSize; 
    void                    *pool; 
    void                    *dict; 
    short                   flags;
} vclassRoot;


void *vclassSpawn(
    	void                    *clas, 
    	int                     size
    	);

void *malloc(
   	int                     size
    	);

void *memcpy(
    	void			*dest,
	const void		*src,
	int			size
	);
	
void *vclassSpawn(void *clas, int size)


{
    vclassRoot 		*child;

    child = 		(vclassRoot *) malloc(size);

    memcpy(child,clas, ( ((vclassRoot*)clas)->size) );

    child->super = clas;
    child->name  = ((void*)0);
    child->size  = size;
    child->pool  = ((void*)0);
    child->dict  = ((void*)0);

    return child;
}

------------------------

class.s is the incorrect assembler output of the compiler.  Note that the 
call to memcpy is moved after some of the assignments to the child structure.

------class.s----------

gcc2_compiled.:
.stabs "/home/vde/src/vclass/",100,0,0,Ltext0
.stabs "/home/vde/src/vclass/class.c",100,0,0,Ltext0
.text
Ltext0:
.stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0
.stabs "char:t2=r2;0;127;",128,0,0,0
.stabs "long int:t3=r1;-2147483648;2147483647;",128,0,0,0
.stabs "unsigned int:t4=r1;0;-1;",128,0,0,0
.stabs "long unsigned int:t5=r1;0;-1;",128,0,0,0
.stabs "short int:t6=r1;-32768;32767;",128,0,0,0
.stabs "long long int:t7=r1;0;-1;",128,0,0,0
.stabs "short unsigned int:t8=r1;0;65535;",128,0,0,0
.stabs "long long unsigned int:t9=r1;0;-1;",128,0,0,0
.stabs "signed char:t10=r1;-128;127;",128,0,0,0
.stabs "unsigned char:t11=r1;0;255;",128,0,0,0
.stabs "float:t12=r1;4;0;",128,0,0,0
.stabs "double:t13=r1;8;0;",128,0,0,0
.stabs "long double:t14=r1;8;0;",128,0,0,0
.stabs "void:t15=15",128,0,0,0
.stabs "vclassRoot:T16=s28super:17=*15,0,32;name:18=*2,32,32;size:1,64,32;objectSize:1,96,32;pool:17,128,32;dict:17,160,32;flags:6,192,16;;",128,0,0,0
.stabs "vclassRoot:t16",128,0,0,0
	.align 4
	.global _vclassSpawn
	.proc	0120
_vclassSpawn:
.stabn 68,0,31,LM1
LM1:
	!#PROLOGUE# 0
	save %sp,-136,%sp
	!#PROLOGUE# 1
.stabn 68,0,32,LM2
LM2:
LBB2:
.stabn 68,0,34,LM3
LM3:
	call _malloc,0
	mov %i1,%o0
	mov %o0,%l0
.stabn 68,0,36,LM4
LM4:
	ld [%i0+8],%o2
	mov %i0,%o1
.stabn 68,0,38,LM5
LM5:
	st %o1,[%l0]
.stabn 68,0,39,LM6
LM6:
	st %g0,[%l0+4]
.stabn 68,0,40,LM7
LM7:
	st %i1,[%l0+8]
.stabn 68,0,41,LM8
LM8:
	st %g0,[%l0+16]
.stabn 68,0,42,LM9
LM9:
.stabn 68,0,36,LM10
LM10:
	call _memcpy,0
	st %g0,[%l0+20]
.stabn 68,0,44,LM11
LM11:
.stabn 68,0,45,LM12
LM12:
LBE2:
	ret
	restore %g0,%l0,%o0
.stabs "vclassSpawn:F17",36,0,0,_vclassSpawn
.stabs "clas:P17",64,0,0,24
.stabs "size:P1",64,0,0,25
.stabs "child:r19=*16",64,0,0,16
.stabn 192,0,0,LBB2
.stabn 224,0,0,LBE2

----------------------------------


Thanks for your time, and keep up the good work!

Sean
sean@visix.com
Technical Details
Message-ID: <9208101623.AA27877@jetta.visix.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!porsche.visix.com!sean

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!porsche.visix.com!sean
From: sean@porsche.visix.com (Sean E. Trowbridge)
Subject: bug in gcc 2.2.2 for Sparc/SunOS 4.1.1
Message-ID: <9208101623.AA27877@jetta.visix.com>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Mon, 10 Aug 1992 16:23:35 GMT
Approved: bug-gcc@prep.ai.mit.edu
Lines: 162