[cfe-dev] Nested functions in Clang?

mats petersson via cfe-dev cfe-dev at lists.llvm.org
Sun Sep 13 03:28:15 PDT 2015

My Pascal compiler (for obvious reasons) supper nested functions.

I originally added hidden extra, hidden, arguments for the variables used
in the outer arguments, but had to add support for function pointers for
functions inside a nested structure, and ended up using the LLVM suport for

For (probably not ideal) reference:


On 13 September 2015 at 10:39, David Chisnall via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> On 13 Sep 2015, at 01:18, Rodney M. Bates via cfe-dev <
> cfe-dev at lists.llvm.org> wrote:
> >
> > Does Clang have an option that allows C nested functions, as in gcc?
> > So far, I can't find it.  I just want to look at generated llvm IR, for
> > ideas on the best way to produce it from another front end.
> Clang doesn’t support it, but llvm-gcc did (and DragonEgg, possibly?), and
> this is what the trampoline intrinsics are for.  The way that GCC
> implements it is very dangerous - it requires having an executable stack,
> which makes various attacks significantly easier.
> The nested function approach is *only* required if you need the ability
> for unmodified C code (or code using a C FFI) to be able to call the
> generated functions.  If you do not have this requirement, then using an
> explicit argument in the LLVM IR to contain the state for the closure (as
> [Objective-]C blocks and C++ lambdas do) is probably a better option.
> David
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150913/a62dd7fe/attachment.html>

More information about the cfe-dev mailing list