https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21161

--- Comment #11 from Jeffrey A. Law <law at redhat dot com> ---
Just to record some thoughts.

The implementation of the "clobbered by longjmp" warning essentially looks at
the objects that are live at the setjmp point.  In theory we can do better when
we're dealing with setjmp/sigsetjmp (but not getcontext for example).

In theory we can look at the code after the setjmp for this kind of pattern:

(insn 15 14 21 2 (set (reg:SI 91 [ <retval> ])
        (reg:SI 0 ax)) "j.c":18 86 {*movsi_internal}
     (expr_list:REG_DEAD (reg:SI 0 ax)
        (nil)))
(insn 21 15 22 2 (set (reg:CCZ 17 flags)
        (compare:CCZ (reg:SI 91 [ <retval> ])
            (const_int 0 [0]))) "j.c":18 7 {*cmpsi_ccno_1}
     (nil))
(jump_insn 22 21 23 2 (set (pc)
        (if_then_else (eq (reg:CCZ 17 flags)
                (const_int 0 [0]))
            (label_ref 28)
            (pc))) "j.c":18 672 {*jcc}
     (expr_list:REG_DEAD (reg:CCZ 17 flags)
        (int_list:REG_BR_PROB 719407028 (nil)))
 -> 28)

Since in the longjmp case, we know this will fallthru, we look at the what's
live-in in the fallthru successor.  If the test were inverted we'd (of course)
look at the live in of the target of the branch.  THat live-in set is what we
want to use to compute setjmp_crosses rather than what's actually live at the
setjmp (which is overly-conservative as it is the union of what's live on both
paths after the setjmp, only one of which we care about).

The implementation would be somewhat gross.  It'd have to account for the
differences between setjmp/sigsetjmp and things like savectx, vfork, and
getcontext.  It might be somewhat fragile since we'd be matching a series of
insns which could look radically different on some targets.  *But* a proof of
concept does seem to work.  I'm going to try to polish that up.

I haven't check if that addresses any of Florian's concerns from 61118. 
There's a reasonable chance it will.

Alternately this could be done on gimple, but I suspect factoring of the
abnormal dispatcher as well as the inaccurate CFG will kill us.

Reply via email to