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]

gcc miscompiles gcj @ -O2


Alex wrote:

> > This happens because (we think) gcj is miscompiled by the current
> > cvs gcc.  I believe Alex was planning to look at this.
>
> Yes. I did a bit a while back. The generated assembly language seem to
> be equivalent for both cases.
>

Actually, it is not equivalent. The first call to exit_block() is
delayed in the "broken" version of the method. I think we should check
in the "fix", even though its stupid, and file this problem as a gcc
bug. This thing is annoying a lot of people.

For gcc hackers, here's an analysis of this problem:

Code (from gcc/java/parse.y):

static void
end_artificial_method_body (mdecl)
     tree mdecl;
{
  BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (mdecl)) = exit_block ();
  exit_block ();
}

Symptom: Return value of exit_block() does not actually get assigned
to BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (mdecl)) when compiled with -O2
on an ia32.

If the method is changed to look like:

static void
end_artificial_method_body (mdecl)
     tree mdecl;
{
  tree b = exit_block ();
  BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (mdecl)) = b;
  exit_block ();
}

Then all is well. It also works fine if compiled with an older
compiler, such as Red Hat's 2.96 or anything earlier. The diff between
the asm output is as follows. Note how the exit_block call is made
later in the "broken" method.

--- meth.broken Fri Dec 15 13:00:11 2000
+++ meth.works Fri Dec 15 12:59:54 2000
@@ -3,16 +3,17 @@
  movl %esp, %ebp
  pushl %ebx
  subl $4, %esp
- movl 8(%ebp), %edx
- movzbl 8(%edx), %eax
+ movl 8(%ebp), %ebx
+ call exit_block
+ movl %eax, %edx
+ movzbl 8(%ebx), %eax
  cmpb $100, tree_code_type(%eax)
  jne .L5205
- movl 100(%edx), %eax
- movl 36(%eax), %ebx
- cmpb $5, 8(%ebx)
+ movl 100(%ebx), %eax
+ movl 36(%eax), %eax
+ cmpb $5, 8(%eax)
  jne .L5206
- call exit_block
- movl %eax, 20(%ebx)
+ movl %edx, 20(%eax)
  movl -4(%ebp), %ebx
  movl %ebp, %esp
  popl %ebp
@@ -21,19 +22,19 @@
 .L5205:
  subl $12, %esp
  pushl $.LC632
- pushl $7203
+ pushl $7204
  pushl $.LC375
  pushl $100
- pushl %edx
+ pushl %ebx
  call tree_class_check_failed
  .p2align 4,,7
 .L5206:
  subl $12, %esp
  pushl $.LC632
- pushl $7203
+ pushl $7204
  pushl $.LC375
  pushl $5
- pushl %ebx
+ pushl %eax
  call tree_check_failed
 .Lfe137:
  .size end_artificial_method_body,.Lfe137-end_artificial_method_body



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