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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Help needed with SEH exception handler (not really Win32 specific)


>  >   printf( "Normal Execution!\n");
>  > 
>  >   /* Without this redundant check, GCC considers the following code
>  >    * unreachable and eliminates it! 
>  >    */
>  >   if (er.hlr_addr != 0)
>  >     goto rm_hlr;
>  > 
>  > ex_hlr:
> 
> There's a potential problem here.  gcc doesn't know that the printf()
> above has not happened.  For example, it is possible that gcc will
> generate this:
> 
>       move    #printf, r1
>       move    #string1, r0
>       call    r1
>       cmp     er.hlr_addr, #0
>       bne     rm_hlr
> 
> ex_hlr:
>       move    #string2, r0
>       call    r1
> 
> Bad -- the address of printf isn't in r1.  The compiler needs to know
> that there is an abnormal edge to ex_hlr in the control flow graph.
> 
> I don't know the right way to tell gcc that this might happen.  There
> may be a way that uses __builtin_setjmp.

As in something like the following?
----------------------------- 8< -----------------------------
    /* Set up exception handler... */
    ...
    if (__builtin_setjmp (jmpbuf) == 0)
    {
        retVal = inner_foo( x);
        printf( "Normal Execution!\n");
    }
    else
    {
ex_hlr:
        printf( "*** Abnormal Execution! ***\n");
        retVal = x*10;
    }
    ...

    /* Tear down exception handler... */
----------------------------- 8< -----------------------------

However, I'm a bit uneasy about using this function because of this
comment in gcc/builtins.c (expand_builtin_setjmp):
----------------------------- 8< -----------------------------
   NOTE: This is intended for use by GNAT and the exception handling
   scheme in the compiler and will only work in the method used by
   them.  */
----------------------------- 8< -----------------------------

It's not immediately clear to me what the "proper" way is supposed
to be.

Also worth noting is the fact that this obviously will not work if 
"-fomit-frame-pointer" is specified while compiling the program.

Ranjit.


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