David Malcolm writes: > On Fri, 2020-07-24 at 18:05 -0400, David Malcolm via Gcc-patches wrote: > > [...] > >> I haven't thought this through in detail, and I'm not sure exactly >> how >> it would work for arbitrary types, but I thought it worth sharing. >> (For example I can think of nasty issues if we ever want to support >> cross-compilation, e.g. where sizeof types or endianness differs >> between host and target). > > ...which is an argument in favor of retaining the name "blob", perhaps > as the name of the argument in the header file e.g.: > > extern void > gcc_jit_global_set_initializer (gcc_jit_lvalue *global, > const void *blob, > size_t num_bytes); > > > as a subtle hint to the user that they need to be wary about binary > layouts ("here be dragons"). > > [...] Hi Dave & all, following up this is my take on the implementation of: gcc_jit_global_set_initializer (gcc_jit_lvalue *global, const void *blob, size_t num_bytes); 'global' must be an array but in the seek of generality it now supports all the various integral types and is not limited to char[]. As you anticipated the implementation I came up is currently not safe for cross-compilation, not sure is requirement tho. make check-jit is clean Feedback very welcome Thanks! Andrea gcc/jit/ChangeLog 2020-08-01 Andrea Corallo * docs/topics/compatibility.rst (LIBGCCJIT_ABI_14): New ABI tag. * docs/topics/expressions.rst (gcc_jit_global_set_initializer): Document new entry point in section 'Global variables'. * jit-playback.c (global_new_decl, global_finalize_lvalue): New method. (playback::context::new_global): Make use of global_new_decl, global_finalize_lvalue. (load_blob_in_ctor): New template function in use by the following. (playback::context::new_global_initialized): New method. * jit-playback.h (class context): Decl 'new_global_initialized', 'global_new_decl', 'global_finalize_lvalue'. (lvalue::set_initializer): Add implementation. * jit-recording.c (recording::memento_of_get_pointer::get_size) (recording::memento_of_get_type::get_size): Add implementation. (recording::global::write_initializer_reproducer): New function in use by 'recording::global::write_reproducer'. (recording::global::replay_into) (recording::global::write_to_dump) (recording::global::write_reproducer): Handle initialized case. * jit-recording.h (class type): Decl 'get_size' and 'num_elements'. * libgccjit++.h (class lvalue): Declare new 'set_initializer' method. (class lvalue): Decl 'is_global' and 'set_initializer'. (class class global) Decl 'write_initializer_reproducer'. Add 'm_initializer', 'm_initializer_num_bytes' fields. Implement 'set_initializer'. * libgccjit.c (gcc_jit_global_set_initializer): New function. * libgccjit.h (gcc_jit_global_set_initializer): New function declaration. * libgccjit.map (LIBGCCJIT_ABI_14): New ABI tag. gcc/testsuite/ChangeLog 2020-08-01 Andrea Corallo * jit.dg/all-non-failing-tests.h: Add test-blob.c. * jit.dg/test-global-set-initializer.c: New testcase.