Hi!

Ye that should work since the lvalue:s are always created first. 

I haven't tried it, but I should add it to the testcase, together with 
some circular linked list thing, to see that nothing gets stuck
running in a circle.

Maybe I should verify this does not blow up the lib, too:

extern const int bar;
const int foo = bar;
const int bar = foo;

Hopefully my patch will complain about "not constant", and not try
to go all in C++ on it.

Regards, Petter


Från: Marc Nieper-Wißkirchen <marc.nieper+...@gmail.com>
Skickat: den 10 december 2021 19:49
Till: Petter Tomner
Kopia: gcc-patches@gcc.gnu.org; j...@gcc.gnu.org
Ämne: Re: [PATCH] jit: Add support for global rvalue initialization and ctors
  

Hi,

I would favor adding support for this kind of initialization to libgccjit.

Does it also support the libgccjit equivalent of the following C module, which 
contains forward references in the struct initializers?

struct bar bar;
struct foo foo;

struct foo
{
  struct bar *b; 
};

struct bar
{
  struct foo *f;
};

struct bar bar = {.f = &foo};
struct foo foo = {.b = &bar}; 


Thanks,


Marc
  

Am Mo., 29. Nov. 2021 um 21:04 Uhr schrieb Petter Tomner via Jit 
<j...@gcc.gnu.org>:
  Hi!

I have wrapped up the patch than adds support for initialization of global 
variables
with rvalues aswell as rvalue constructors for structs, arrays and unions.

New entrypoints are:

gcc_jit_global_set_initializer_rvalue

Which sets the initial value of a global to a rvalue.

And:

gcc_jit_context_new_array_constructor
gcc_jit_context_new_struct_constructor
gcc_jit_context_new_union_constructor

Those three makes a constructor with a rvalue that e.g. can be assigned to a 
local or returned
from a function, or most importantly used to set the initial value of global 
variables
with gcc_jit_global_set_initializer_rvalue.

If no fields are specified for a struct or union to the constructors, 
definition order is assumed.

There can be gaps in the fields specified to the struct constructor, but they 
need to be in order.

For pointer arithmetic to work with setting DECL_INITIAL, alot of folding is 
added.

make check-jit runs fine on gnu-linux-x64 Debian.

Regards,     

Reply via email to