phate / jlm

GNU Lesser General Public License v2.1
51 stars 13 forks source link

jlc segfaults #52

Closed sjalander closed 3 years ago

sjalander commented 3 years ago

jlc -DNDEBUG -O0 -w -Werror=date-time 2004-03-15-IndirectGoto.c

2004-03-15-IndirectGoto.zip

phate commented 3 years ago

This program contains a GCC extension that allows code to take the addresses of labels and then later jump to them. Please see here for more information: https://blog.llvm.org/2010/01/address-of-label-and-indirect-branches.html. This involves the blockaddress and indirectbr instructions in LLVM. Basically, these instructions enable to take the "address" of a basic block and later jump to this basic block. This is a feature that is inherently tied to a CFG or at least I do not see how we can (ever) support this.

alexrp commented 4 months ago

I was just about to post a whole discussion thread on representing computed gotos in the RVSDG, but then came across this issue, so I guess I'll post here.

@phate any chance you can elaborate on your thinking here? It's not immediately obvious to me why these constructs should be more problematic than regular irreducible control flow. Notably, blockaddress constants are defined opaquely enough that you have quite a lot of implementation flexibility (e.g. worst case, you can lower to a jump table as mentioned in that LLVM blog post; LLVM still has a pass to do this today), and the indirectbr instruction must explicitly list all possible branch targets. Is this not sufficient information to be able to translate from CFG to RVSDG?

It does occur to me that, assuming you can translate it to an RVSDG, you would still need new node types to represent and lower these concepts faithfully (i.e. without a jump table). Probably a new structural node with a mix of lambda/gamma characteristics to represent the regions that have address-exposed labels, a new apply-like node to use it, and maybe a generalized phi node to break cycles that can occur in this scheme. Or something like that. :thinking:

phate commented 4 months ago

@alexrp Would you be so kind and start a discussion thread about it, please? A closed issue is not really the right place to discuss such concepts. Obviously, you can reference the issue in the discussion. I also need some time to remind myself of the concrete issues with it.