russo@M.CS.UIUC.EDU (Vince Russo) (01/04/89)
The following code fragment is an example of something output from the C++ translator when inlining a function. When compiled on the sun3 with gcc-1.31 it generates the code below it. The three local variables are assigned to in the comma expression, but then immediately go out of scope. My question is, why does it generate any code at all. Shouldnt the assignments be dead coded since the variables immediately go out of scope? Then no space for the variables even needs allocated since they are never used. The next result of the comma expression is just 0. Therefore as long as any parts of it dont have side effect, the whole expression is dead. Is there some subtle reason to leave in the dead assignments or is this just an optimization gcc misses? The only compiler flags I used where "-O -S". Ive tried others but nothing deadcodes the assignments. --Vince Russo russo@cs.uiuc.edu ------------------------------------------------------------------------- union debugArg { long l__8debugArg ; char * p__8debugArg ; }; char main () { { /* in scope */ union debugArg __0_V1 ; union debugArg __0_V2 ; union debugArg __0_V3 ; ( ( ((& __0_V1 )-> l__8debugArg = ((long )0 )), (((& __0_V1 )))) , ( ( ((& __0_V2 )-> l__8debugArg = ((long )1 )), (((& __0_V2 )))) , ( ( ((& __0_V3 )-> p__8debugArg = ((char *)"aa")), (((& __0_V3 )))) , ( ( 0 ) ) ) ) ); } /* out of scope */ } ---------------------------------------------------------------------------- #NO_APP .text LC0: .ascii "aa\0" .even .globl _main _main: link a6,#-12 <<- Stack space is wasted storing them clrl a6@(-4) <<- Why is this here (dead assignment). moveq #1,d0 <<- Why is this here (ditto) movel d0,a6@(-8) <<- Why is this here (ditto) movel #LC0,a6@(-12) <<- Why is this here (ditto) unlk a6 rts ---------------------------------------------------------------------------