To add support for a new function attribute in libgccjit, you need to do the following steps:
- Copy the corresponding function from
c-family/c-attribs.cc
intojit/dummy-frontend.cc
. For example if you add thetarget
attribute, the function name will behandle_target_attribute
. - Copy the corresponding entry from the
c_common_attribute_table
variable in thec-family/c-attribs.cc
file into thejit_attribute_table
variable injit/dummy-frontend.cc
. - Add a new variant in the
gcc_jit_fn_attribute
enum in thejit/libgccjit.h
file. - Add a test to ensure the attribute is correctly applied in
gcc/testsuite/jit.dg/
. Take a look atgcc/testsuite/jit.dg/test-nonnull.c
if you want an example. - Run the example like this (in your
gcc-build
folder):make check-jit RUNTESTFLAGS="-v -v -v jit.exp=jit.dg/test-nonnull.c"
Once done, you need to update the gccjit.rs crate to add the new enum variant in the corresponding enum (FnAttribute
).
Finally, you need to update this repository by calling the relevant API you added in gccjit.rs.
To test it, build gcc
, run cargo update -p gccjit
and then you can test the generated output for a given Rust crate.