This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
EH optimization bug in 980308
- To: egcs at cygnus dot com
- Subject: EH optimization bug in 980308
- From: Kriang Lerdsuwanakij <lerdsuwa at scf-fs dot usc dot edu>
- Date: Fri, 13 Mar 1998 13:13:11 -0800
Hi
I discovered problems in loop optimization and jump optimization in the
presence of exception handling. Below are the codes that trigger the
bug. It was tested with the 980308 snapshot. They need to be compiled
with option -O (or higher) for the bug to appear.
For the loop optimization test case (lbug.cc), the exception thrown by
f() is no longer caught by the try block. I found that the function
call to f() is moved outside the exception region right before the
`return ret'.
For the jump optimization test case (jbug.cc), the correct behavior is
that the exception thrown by f() inside the try block should be caught
while the one outside should not. But gcc merge two function calls
together inside the exception region during the second jump optimization
pass. This put the program to infinite loop.
--Kriang
=========== Source file lbug.cc ===============================
// This program should display "ok".
#include <stdio.h>
int f()
{
throw 1;
return 2;
}
void g() {}
int main()
{
int ret = 1;
try {
int i = 5;
while (i) {
if (i == 1) {
ret = f();
return ret;
}
g();
--i;
}
}
catch(...) {
printf("ok\n");
ret = 0;
}
return ret;
}
=========== Source file jbug.cc ===============================
// This program should display "ok" follow by abort message.
#include <stdio.h>
int f()
{
throw 1;
return 2;
}
void g() {}
int main()
{
int ret = 1;
int i = 5;
try {
if (i == 5) {
ret = f();
return ret;
}
g();
}
catch(...) {
printf("ok\n");
ret = 0;
}
ret = f();
return ret;
}
============= Output from `gcc -O -S lbug.cc' ==================
.file "lbug.cc"
.version "01.01"
gcc2_compiled.:
.globl __throw
.text
.align 4
.globl f__Fv
.type f__Fv,@function
f__Fv:
.LFB1:
pushl %ebp
.LCFI0:
movl %esp,%ebp
.LCFI1:
pushl %ebx
.LCFI2:
pushl $4
.LCFI3:
call __eh_alloc
movl %eax,%ebx
movl $1,(%ebx)
addl $4,%esp
pushl $0
.LCFI4:
call __tfi
pushl %eax
pushl %ebx
.LCFI5:
call __cp_push_exception
.LCFI6:
call __throw
.LFE1:
.Lfe1:
.size f__Fv,.Lfe1-f__Fv
.align 4
.globl g__Fv
.type g__Fv,@function
g__Fv:
.LFB2:
pushl %ebp
.LCFI7:
movl %esp,%ebp
.LCFI8:
movl %ebp,%esp
popl %ebp
ret
.LFE2:
.Lfe2:
.size g__Fv,.Lfe2-g__Fv
.section .rodata
.LC0:
.string "ok\n"
.text
.align 4
.globl main
.type main,@function
main:
.LFB3:
pushl %ebp
.LCFI9:
movl %esp,%ebp
.LCFI10:
pushl %esi
.LCFI11:
pushl %ebx
.LCFI12:
movl $1,%esi
.LEHB14:
movl $5,%ebx
.align 4
.L17:
cmpl $1,%ebx
je .L33
call g__Fv
decl %ebx
jnz .L17
.LEHE14:
jmp .L21
.align 4
.L13:
call __throw
.align 4
.L21:
movl %esi,%eax
jmp .L32
.LEHB30:
.align 4
.L14:
.LEHB23:
call __cp_exception_info
movl %eax,%ebx
incl 20(%ebx)
.LEHB26:
movb $1,12(%ebx)
pushl $.LC0
.LCFI13:
call printf
xorl %esi,%esi
.LEHE26:
addl $4,%esp
jmp .L27
.align 4
.L25:
.LCFI14:
call __throw
.align 4
.L27:
pushl %ebx
.LCFI15:
call __cp_pop_exception
jmp .L21
.LEHE23:
.align 4
.L26:
pushl %ebx
call __cp_pop_exception
addl $4,%esp
jmp .L25
.align 4
.L23:
jmp .L13
.LEHE30:
.align 4
.L30:
.LCFI16:
call terminate__Fv
.align 4
.L33:
call f__Fv
movl %eax,%esi
.L32:
leal -8(%ebp),%esp
popl %ebx
popl %esi
movl %ebp,%esp
popl %ebp
ret
.LFE3:
.Lfe3:
.size main,.Lfe3-main
.section .gcc_except_table,"aw",@progbits
.align 4
__EXCEPTION_TABLE__:
.long .LEHB14
.long .LEHE14
.long .L14
.long .LEHB30
.long .LEHE30
.long .L30
.long .LEHB23
.long .LEHE23
.long .L23
.long .LEHB26
.long .LEHE26
.long .L26
.long -1
.long -1
.long -1
.section .eh_frame,"aw",@progbits
__FRAME_BEGIN__:
.4byte .LLCIE1
.LSCIE1:
.4byte 0x0
.byte 0x1
.string "eh"
.4byte __EXCEPTION_TABLE__
.byte 0x1
.byte 0x7c
.byte 0x8
.byte 0xc
.byte 0x4
.byte 0x4
.byte 0x88
.byte 0x1
.align 4
.LECIE1:
.set .LLCIE1,.LECIE1-.LSCIE1
.4byte .LLFDE1
.LSFDE1:
.4byte .LSFDE1-__FRAME_BEGIN__
.4byte .LFB1
.4byte .LFE1-.LFB1
.byte 0x4
.4byte .LCFI0-.LFB1
.byte 0xe
.byte 0x8
.byte 0x85
.byte 0x2
.byte 0x4
.4byte .LCFI1-.LCFI0
.byte 0xd
.byte 0x5
.byte 0x4
.4byte .LCFI2-.LCFI1
.byte 0x83
.byte 0x3
.byte 0x4
.4byte .LCFI3-.LCFI2
.byte 0x2e
.byte 0x4
.byte 0x4
.4byte .LCFI4-.LCFI3
.byte 0x2e
.byte 0x0
.byte 0x4
.4byte .LCFI5-.LCFI4
.byte 0x2e
.byte 0xc
.byte 0x4
.4byte .LCFI6-.LCFI5
.byte 0x2e
.byte 0x0
.align 4
.LEFDE1:
.set .LLFDE1,.LEFDE1-.LSFDE1
.4byte .LLFDE3
.LSFDE3:
.4byte .LSFDE3-__FRAME_BEGIN__
.4byte .LFB2
.4byte .LFE2-.LFB2
.byte 0x4
.4byte .LCFI7-.LFB2
.byte 0xe
.byte 0x8
.byte 0x85
.byte 0x2
.byte 0x4
.4byte .LCFI8-.LCFI7
.byte 0xd
.byte 0x5
.align 4
.LEFDE3:
.set .LLFDE3,.LEFDE3-.LSFDE3
.4byte .LLFDE5
.LSFDE5:
.4byte .LSFDE5-__FRAME_BEGIN__
.4byte .LFB3
.4byte .LFE3-.LFB3
.byte 0x4
.4byte .LCFI9-.LFB3
.byte 0xe
.byte 0x8
.byte 0x85
.byte 0x2
.byte 0x4
.4byte .LCFI10-.LCFI9
.byte 0xd
.byte 0x5
.byte 0x4
.4byte .LCFI11-.LCFI10
.byte 0x86
.byte 0x3
.byte 0x4
.4byte .LCFI12-.LCFI11
.byte 0x83
.byte 0x4
.byte 0x4
.4byte .LCFI13-.LCFI12
.byte 0x2e
.byte 0x4
.byte 0x4
.4byte .LCFI14-.LCFI13
.byte 0x2e
.byte 0x0
.byte 0x4
.4byte .LCFI15-.LCFI14
.byte 0x2e
.byte 0x4
.byte 0x4
.4byte .LCFI16-.LCFI15
.byte 0x2e
.byte 0x0
.align 4
.LEFDE5:
.set .LLFDE5,.LEFDE5-.LSFDE5
.ident "GCC: (GNU) egcs-2.91.13 980308 (gcc-2.8.0 release)"
============= Output from `gcc -O -S jbug.cc' ==================
.file "jbug.cc"
.version "01.01"
gcc2_compiled.:
.globl __throw
.text
.align 4
.globl f__Fv
.type f__Fv,@function
f__Fv:
.LFB1:
pushl %ebp
.LCFI0:
movl %esp,%ebp
.LCFI1:
pushl %ebx
.LCFI2:
pushl $4
.LCFI3:
call __eh_alloc
movl %eax,%ebx
movl $1,(%ebx)
addl $4,%esp
pushl $0
.LCFI4:
call __tfi
pushl %eax
pushl %ebx
.LCFI5:
call __cp_push_exception
.LCFI6:
call __throw
.LFE1:
.Lfe1:
.size f__Fv,.Lfe1-f__Fv
.align 4
.globl g__Fv
.type g__Fv,@function
g__Fv:
.LFB2:
pushl %ebp
.LCFI7:
movl %esp,%ebp
.LCFI8:
movl %ebp,%esp
popl %ebp
ret
.LFE2:
.Lfe2:
.size g__Fv,.Lfe2-g__Fv
.section .rodata
.LC0:
.string "ok\n"
.text
.align 4
.globl main
.type main,@function
main:
.LFB3:
pushl %ebp
.LCFI9:
movl %esp,%ebp
.LCFI10:
pushl %ebx
.LCFI11:
.LEHB14:
.L29:
call f__Fv
jmp .L28
.LEHE14:
.align 4
.L13:
call __throw
.LEHB26:
.align 4
.L14:
.LEHB19:
call __cp_exception_info
movl %eax,%ebx
incl 20(%ebx)
.LEHB22:
movb $1,12(%ebx)
pushl $.LC0
.LCFI12:
call printf
.LEHE22:
addl $4,%esp
jmp .L23
.align 4
.L21:
.LCFI13:
call __throw
.align 4
.L23:
pushl %ebx
.LCFI14:
call __cp_pop_exception
addl $4,%esp
jmp .L29
.LEHE19:
.align 4
.L22:
pushl %ebx
call __cp_pop_exception
addl $4,%esp
jmp .L21
.align 4
.L19:
jmp .L13
.LEHE26:
.align 4
.L26:
.LCFI15:
call terminate__Fv
.align 4
.L28:
movl -4(%ebp),%ebx
movl %ebp,%esp
popl %ebp
ret
.LFE3:
.Lfe3:
.size main,.Lfe3-main
.section .gcc_except_table,"aw",@progbits
.align 4
__EXCEPTION_TABLE__:
.long .LEHB14
.long .LEHE14
.long .L14
.long .LEHB26
.long .LEHE26
.long .L26
.long .LEHB19
.long .LEHE19
.long .L19
.long .LEHB22
.long .LEHE22
.long .L22
.long -1
.long -1
.long -1
.section .eh_frame,"aw",@progbits
__FRAME_BEGIN__:
.4byte .LLCIE1
.LSCIE1:
.4byte 0x0
.byte 0x1
.string "eh"
.4byte __EXCEPTION_TABLE__
.byte 0x1
.byte 0x7c
.byte 0x8
.byte 0xc
.byte 0x4
.byte 0x4
.byte 0x88
.byte 0x1
.align 4
.LECIE1:
.set .LLCIE1,.LECIE1-.LSCIE1
.4byte .LLFDE1
.LSFDE1:
.4byte .LSFDE1-__FRAME_BEGIN__
.4byte .LFB1
.4byte .LFE1-.LFB1
.byte 0x4
.4byte .LCFI0-.LFB1
.byte 0xe
.byte 0x8
.byte 0x85
.byte 0x2
.byte 0x4
.4byte .LCFI1-.LCFI0
.byte 0xd
.byte 0x5
.byte 0x4
.4byte .LCFI2-.LCFI1
.byte 0x83
.byte 0x3
.byte 0x4
.4byte .LCFI3-.LCFI2
.byte 0x2e
.byte 0x4
.byte 0x4
.4byte .LCFI4-.LCFI3
.byte 0x2e
.byte 0x0
.byte 0x4
.4byte .LCFI5-.LCFI4
.byte 0x2e
.byte 0xc
.byte 0x4
.4byte .LCFI6-.LCFI5
.byte 0x2e
.byte 0x0
.align 4
.LEFDE1:
.set .LLFDE1,.LEFDE1-.LSFDE1
.4byte .LLFDE3
.LSFDE3:
.4byte .LSFDE3-__FRAME_BEGIN__
.4byte .LFB2
.4byte .LFE2-.LFB2
.byte 0x4
.4byte .LCFI7-.LFB2
.byte 0xe
.byte 0x8
.byte 0x85
.byte 0x2
.byte 0x4
.4byte .LCFI8-.LCFI7
.byte 0xd
.byte 0x5
.align 4
.LEFDE3:
.set .LLFDE3,.LEFDE3-.LSFDE3
.4byte .LLFDE5
.LSFDE5:
.4byte .LSFDE5-__FRAME_BEGIN__
.4byte .LFB3
.4byte .LFE3-.LFB3
.byte 0x4
.4byte .LCFI9-.LFB3
.byte 0xe
.byte 0x8
.byte 0x85
.byte 0x2
.byte 0x4
.4byte .LCFI10-.LCFI9
.byte 0xd
.byte 0x5
.byte 0x4
.4byte .LCFI11-.LCFI10
.byte 0x83
.byte 0x3
.byte 0x4
.4byte .LCFI12-.LCFI11
.byte 0x2e
.byte 0x4
.byte 0x4
.4byte .LCFI13-.LCFI12
.byte 0x2e
.byte 0x0
.byte 0x4
.4byte .LCFI14-.LCFI13
.byte 0x2e
.byte 0x4
.byte 0x4
.4byte .LCFI15-.LCFI14
.byte 0x2e
.byte 0x0
.align 4
.LEFDE5:
.set .LLFDE5,.LEFDE5-.LSFDE5
.ident "GCC: (GNU) egcs-2.91.13 980308 (gcc-2.8.0 release)"