This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: gcc miscompiles gcj @ -O2



Richard Henderson writes:

> Reason: exit_block modifies DECL_FUNCTION_BODY (current_function_decl).

Oh yeah that's right. For some reasons DECL_FUNCTION_BODY (mdecl) has
to have it's value set to the current block before we exit it.

> Therefore, if mdecl == current_function_decl, we have undefined 
> behaviour, since there is no sequence point across the = in
> 
>   BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (mdecl)) = exit_block ();

Thanks a bunch. I'm checking this patch in.

./A

2000-12-15  Alexandre Petit-Bianco  <apbianco@cygnus.com>

	* parse.y (end_artificial_method_body): Fixed undefined behavior.
	Credits go to rth for finding it.

Index: parse.y
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/parse.y,v
retrieving revision 1.235
diff -u -p -r1.235 parse.y
--- parse.y     2000/12/14 04:28:50     1.235
+++ parse.y     2000/12/15 08:40:58
@@ -7200,7 +7200,11 @@ static void
 end_artificial_method_body (mdecl)
      tree mdecl;
 {
-  BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (mdecl)) = exit_block ();
+  /* exit_block modifies DECL_FUNCTION_BODY (current_function_decl).
+     It has to be evaluated first. (if mdecl is current_function_decl,
+     we have an undefined behavior if no temporary variable is used.) */
+  tree b = exit_block ();
+  BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (mdecl)) = b;
   exit_block ();
 }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]