public inbox for jit@gcc.gnu.org
 help / color / mirror / Atom feed
* __attribute__((cleanup)) support in libgccjit?
@ 2023-06-08 13:46 Eric Wong
  2023-06-08 14:54 ` David Malcolm
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Wong @ 2023-06-08 13:46 UTC (permalink / raw)
  To: jit

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..

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...


Thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: __attribute__((cleanup)) support in libgccjit?
  2023-06-08 13:46 __attribute__((cleanup)) support in libgccjit? Eric Wong
@ 2023-06-08 14:54 ` David Malcolm
  0 siblings, 0 replies; 2+ messages in thread
From: David Malcolm @ 2023-06-08 14:54 UTC (permalink / raw)
  To: Eric Wong, jit

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-08 14:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-08 13:46 __attribute__((cleanup)) support in libgccjit? Eric Wong
2023-06-08 14:54 ` David Malcolm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).