__attribute__((cleanup)) support in libgccjit?

David Malcolm dmalcolm@redhat.com
Thu Jun 8 14:54:22 GMT 2023


On Thu, 2023-06-08 at 13:46 +0000, Eric Wong via Jit wrote:
> Hi, I'm considering libgccjit for use in a new GPL3+ scripting
> language and I am wondering if declaring locals with
> __attribute__((cleanup)) is supported by libgccjit.
> 
> I find gcc_jit_lvalue_set_alignment in libgccjit.h, but not
> many other attributes for locals..

It varies attribute by attribute.

I took a look at this, and unfortunately it would need extra work on
libgccjit to make it support __attribute__((cleanup)).

Specifically, when the C and C++ frontends are building the
"generic/tree" representation of functions and see a local variable
with the attribute they add extra code to handle the cleanup:
C: in gcc/c/c-decl.c: finish_decl
C++: in gcc/cp/decl.c: cxx_maybe_build_cleanup

We'd need to implement something similar to the above in gcc/jit/jit-
playback.cc (and I'm already overtasked with analyzer work, alas).

Note that libgccjit doesn't have fine-grained scopes like C/C++ do;
locals exist at the level of a function frame.

> 
> I'll likely use libgccjit regardless since it seems like it could
> make libffi redundant (or maybe I'm wrong on that bit...).
> 
> I might steal LuaJIT's C parser to deal with parsing headers and
> structs; not sure if gcc exposes a C parser as a stable API...

Yeah, unfortunately we don't export C parsing as an API.  If you need
to parse a header you'll need to either use a different C parser or
write a plugin to the GCC C frontend.

Hope this is helpful
Dave



More information about the Jit mailing list