[LLVMdev] nonlocal go to -- how?

Jonathan S. Shapiro shap at eros-os.com
Mon May 5 04:25:04 PDT 2008


Hendrick:

I suspect that exception handling is going to be the way to go here. The
following is partly tangential, but possibly relevant.

Largely for social reasons, we've been looking at doing a C-like surface
syntax for BitC. As part of that, we looked at multi-level break and
gotos to same-or-outer scope. In particular, we started by asking
whether either construct adds any new core semantics to the language,
given that we already have exception handling.

The answer is "no". As long as all gotos proceed to same-or-outer scope,
a program containing gotos can be transformed without loss of meaning
into a program containing only exception catch blocks and raise/throw
statements. The catch block executes a switch statement to determine how
to resume computation at the appropriate label. It isn't pretty, and
it's not the way that I would want to actually implement it, but we did
find that outcome comfortable from a formal semantic specification
standpoint.

The nice thing about it is that it generalizes to nested procedure exits
in all cases where the target label of the goto appears in a lexically
nested scope.

However, Mike Stump is right -- you need to consider what happens when
other languages intervene on the call stack. This may not arise in your
case precisely because you are speaking about inner procedures, but do
think it through.

shap




More information about the llvm-dev mailing list