tree-optimization/108691 - indirect calls to setjmp
authorRichard Biener <rguenther@suse.de>
Mon, 13 Feb 2023 09:41:51 +0000 (10:41 +0100)
committerRichard Biener <rguenther@suse.de>
Mon, 13 Feb 2023 14:57:08 +0000 (15:57 +0100)
commit6436add49ed9ecf74f1f01b4fe18961df4f3e83d
treef8c986b61112ca8a922355d848271084860e64d3
parent452db716d8debb6e09b85e4a0c0e73a047ed5c1d
tree-optimization/108691 - indirect calls to setjmp

DCE now chokes on indirect setjmp calls becoming direct because
that exposes them too late to be subject to abnormal edge creation.
The following patch honors gimple_call_ctrl_altering for those and
_not_ treat formerly indirect calls to setjmp as calls to setjmp
in notice_special_calls.

Unfortunately there's no way to have an indirect call to setjmp
properly annotated (the returns_twice attribute is ignored on types).

RTL expansion late discovers returns-twice for the purpose of
adding REG_SETJMP notes and also sets ->calls_setjmp
(instead of asserting it is set).  There's no good way to
transfer proper knowledge around here so I'm using ->calls_setjmp
as a flag to indicate whether gimple_call_ctrl_altering_p was set.

PR tree-optimization/108691
* tree-cfg.cc (notice_special_calls): When the CFG is built
honor gimple_call_ctrl_altering_p.
* cfgexpand.cc (expand_call_stmt): Clear cfun->calls_setjmp
temporarily if the call is not control-altering.
* calls.cc (emit_call_1): Do not add REG_SETJMP if
cfun->calls_setjmp is not set.  Do not alter cfun->calls_setjmp.

* gcc.dg/pr108691.c: New testcase.
gcc/calls.cc
gcc/cfgexpand.cc
gcc/testsuite/gcc.dg/pr108691.c [new file with mode: 0644]
gcc/tree-cfg.cc