From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-relay-2.sys.kth.se (smtp-relay-2.sys.kth.se [130.237.32.40]) by sourceware.org (Postfix) with ESMTPS id 4723E3858D39; Sat, 11 Dec 2021 15:35:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4723E3858D39 Received: from exdb4.ug.kth.se (exdb4.ug.kth.se [192.168.32.59]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp-relay-2.sys.kth.se (Postfix) with ESMTPS id 4JBBgX72kyzPNQD; Sat, 11 Dec 2021 16:35:52 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp-relay-2.sys.kth.se 4JBBgX72kyzPNQD Received: from exdb6.ug.kth.se (192.168.32.61) by exdb4.ug.kth.se (192.168.32.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Sat, 11 Dec 2021 16:35:52 +0100 Received: from exdb6.ug.kth.se ([192.168.32.61]) by exdb6.ug.kth.se ([192.168.32.61]) with mapi id 15.02.0986.014; Sat, 11 Dec 2021 16:35:52 +0100 From: Petter Tomner To: David Malcolm , "gcc-patches@gcc.gnu.org" , "jit@gcc.gnu.org" , "Antoni Boucher" Subject: SV: [PATCH v2] jit: Add support for global rvalue initialization and ctors Thread-Topic: [PATCH v2] jit: Add support for global rvalue initialization and ctors Thread-Index: AQHX6kRSdlggilZaSkOUVbKhDXhGHawqg7iAgALqaik= Date: Sat, 11 Dec 2021 15:35:52 +0000 Message-ID: References: <47b54ae597a44706aba180a05f1e5fe7@kth.se>, In-Reply-To: Accept-Language: sv-SE, en-US Content-Language: sv-SE X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [192.168.32.250] Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: jit@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Jit mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Dec 2021 15:36:00 -0000 Hi! > s/an union/a union/ > s/a rvalue/an rvalue/ Heh no way ... and I though I knew English grammar :) Had to look that up to see what the deal was but it makes sense.=20 yunion, arevalue. > s/wrong-field-name/wrong-field-obj/ > > to match the struct example (given that the issue being tested for is > that it's the wrong object, rather than the wrong name). Initially, before submitting to the list, I made the code such that the fie= ld=20 objects did not have to be the ones that were used when creating the=20 struct or union, and forgot changing the test names.=20 I figured it required too much string compares for the field names and=20 pointer compares for the field object were more appropriate. To create dummy field objects were also kinda heavy. I'll address the points. Regards, Petter Fr=E5n: David Malcolm Skickat: den 9 december 2021 20:39 Till: Petter Tomner; gcc-patches@gcc.gnu.org; jit@gcc.gnu.org; Antoni Bouch= er =C4mne: Re: [PATCH v2] jit: Add support for global rvalue initialization an= d ctors =A0 =20 On Mon, 2021-12-06 at 10:47 +0000, Petter Tomner via Gcc-patches wrote: > Hi! >=20 > Attached is a patch with changes in line with the review of the prior > patch. > The patch adds support for initialization of global variables with > rvalues as well > as rvalue constructors for structs, arrays and unions. Thanks for the updated patch. Antoni: does this patch work for you for your rustc plugin? >=20 > Review: https://gcc.gnu.org/pipermail/jit/2021q4/001400.html >=20 > The points have been addressed, except: >=20 > > Can the type be made const? >=20 > I started to make types_kinda_same_internal () taking const args, but I > felt the > patch was ballooning because some spread out methods needed a const=20 > signature too. I could submit that in a separate patch. Fair enough; fixing that isn't a blocker; it's already a big patch. >=20 > I also addressed a problem Antoni found:=20 > https://gcc.gnu.org/pipermail/jit/2021q4/001399.html >=20 > , where you could not initialize global pointer variables to point to > uninitialized variables. I did that by=20 > removing a redundant check with validate_var_has_init (), since that > walking function would > have to be quite complex to allow pointers to uninitialized variables. >=20 > Any: > const int foo; > int bar =3D foo; >=20 > will instead be reported as "not compile time constant" instead of a > nice error message with names. >=20 > make check-jit runs fine on gnu-linux-x64 Debian. Various review comments inline below, which are mostly just nits: > From a4fef1308eaa72ce4ec51dbe5efcfbbf032e9870 Mon Sep 17 00:00:00 2001 > From: Petter Tomner > Date: Mon, 29 Nov 2021 20:44:07 +0100 > Subject: [PATCH] Add support for global rvalue initialization and constru= ctors >=20 > This patch adds support for initialization of global variables > with rvalues and creating constructors for array, struct and > union types which can be used as rvalues. >=20 > Signed-off-by: > 2021-12-06=A0=A0=A0 Petter Tomner=A0=A0 [...snip...] > diff --git a/gcc/jit/docs/topics/expressions.rst b/gcc/jit/docs/topics/ex= pressions.rst > index 396259ef07e..5f64ca68595 100644 > --- a/gcc/jit/docs/topics/expressions.rst > +++ b/gcc/jit/docs/topics/expressions.rst > @@ -126,6 +126,147 @@ Simple expressions >=A0=A0=A0=A0 underlying string, so it is valid to pass in a pointer to an = on-stack >=A0=A0=A0=A0 buffer. >=A0=20 > +Constructor expressions > +*********************** > + > +=A0=A0 The following functions make constructors for array, struct and u= nion > +=A0=A0 types. > + > +=A0=A0 The constructor rvalue can be used for assignment to locals. > +=A0=A0 It can be used to initialize global variables with > +=A0=A0 :func:`gcc_jit_global_set_initializer_rvalue`. It can also be use= d as a > +=A0=A0 temporary value for function calls and return values, but its add= ress > +=A0=A0 can't be taken. > + > +=A0=A0 Note that arrays in libgccjit does not collapse to pointers like = in s/does not/do not/ > +=A0=A0 C. I.e. if an array constructor is used as e.g. a return value, t= he whole > +=A0=A0 array would be returned by value - array constructors can be assi= gned to > +=A0=A0 array variables. > + > +=A0=A0 The constructor can contain nested constructors. > + > +=A0=A0 Note that a string literal rvalue can't be used to construct a ch= ar array. > +=A0=A0 It need one rvalue for each char. s/char array.=A0 It need one rvalue/char array; the latter needs one rvalue= / > + > +=A0=A0 These entrypoints were added in :ref:`LIBGCCJIT_ABI_16`; you can = test for its s/16/17/=A0 I believe. s/its/their/ > +=A0=A0 presense using: s/presense/presence/ (and in various other places below) > +=A0=A0 .. code-block:: c > +=A0=A0=A0=A0 #ifdef LIBGCCJIT_HAVE_CTORS > + > +.. function:: gcc_jit_rvalue *\ > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 gcc_jit_context_new_array_constructor (gc= c_jit_context *ctxt,\ > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= gcc_jit_location *loc,\ > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= gcc_jit_type *type,\ > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= size_t arr_length,\ > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= gcc_jit_rvalue **values) > + > +=A0=A0 Create a constructor for an array as a rvalue. > + > +=A0=A0 Returns NULL on error. ``values`` are copied and > +=A0=A0 do not have to outlive the context. > + > +=A0=A0 ``type`` specifies what the constructor will build and has to be > +=A0=A0 an array. > + > +=A0=A0 ``arr_length`` specifies the number of elements in ``values`` and > +=A0=A0 it can't have more elements than the array type. Let's rename this to ``num_values`` (both in the docs, and in libgccjit.c and .h, in all of the various places), since this will make it clearer that we're talking about the size of "values", rather than that of the type. > + > +=A0=A0 Each value in ``values`` sets the corresponding value in the arra= y. > +=A0=A0 If the array type itself has more elements than ``values``, the > +=A0=A0 left-over elements will be zeroed. > + > +=A0=A0 Each value in ``values`` need to be the same unqualified type as = the > +=A0=A0 array type's element type. > + > +=A0=A0 If ``arr_length`` is 0, the ``values`` parameter will be > +=A0=A0 ignored and zero initialization will be used. > + > +=A0=A0 This entrypoint was added in :ref:`LIBGCCJIT_ABI_17`; you can tes= t for its > +=A0=A0 presense using: > + > +=A0=A0 .. code-block:: c > +=A0=A0=A0=A0 #ifdef LIBGCCJIT_HAVE_CTORS > + > +.. function:: gcc_jit_rvalue *\ > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 gcc_jit_context_new_struct_constructor (g= cc_jit_context *ctxt,\ > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 gcc_jit_location *loc,\ > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 gcc_jit_type *type,\ > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 size_t arr_length,\ > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 gcc_jit_field **fields,\ > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 gcc_jit_rvalue **value) > + > + > +=A0=A0 Create a constructor for an struct as a rvalue. > + > +=A0=A0 Returns NULL on error. The two parameter arrays are copied and > +=A0=A0 do not have to outlive the context. > + > +=A0=A0 ``type`` specifies what the constructor will build and has to be > +=A0=A0 a struct. > + > +=A0=A0 ``arr_length`` specifies the number of elements in ``values``. Again, let's make this "num_values" here and in the .c/.h, for clarity. [...snip...] > @@ -603,6 +744,38 @@ Global variables >=A0=20 >=A0=A0=A0=A0=A0=A0=A0 #ifdef LIBGCCJIT_HAVE_gcc_jit_global_set_initializer >=A0=20 > +.. function:: gcc_jit_lvalue *\ > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 gcc_jit_global_set_initializer_rvalue (gc= c_jit_lvalue *global, > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= gcc_jit_rvalue *init_value) > + > +=A0=A0 Set the initial value of a global with an rvalue. > + > +=A0=A0 The rvalue need to be a constant expression, e.g. no function cal= ls. s/need/needs/ [...snip...] > +void > +playback::context:: > +global_set_init_rvalue (lvalue* variable, > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 rvalue* ini= t) > +{ > +=A0 tree inner =3D variable->as_tree (); > + > +=A0 /* We need to fold all expressions as much as possible.=A0 The code > +=A0=A0=A0=A0 for a DECL_INITIAL only handles some operations, > +=A0=A0=A0=A0 etc addition, minus, 'address of'.=A0 See output_addressed_= constants () > +=A0=A0=A0=A0 in varasm.c.=A0 */ > +=A0 tree init_tree =3D init->as_tree (); > +=A0 tree folded =3D fold_const_var (init_tree); > + > +=A0 if (!TREE_CONSTANT (folded)) > +=A0=A0=A0 { > +=A0=A0=A0=A0=A0 tree name =3D DECL_NAME (inner); > + > +=A0=A0=A0=A0=A0 add_error (NULL, > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "unable to convert initial value= for the global variable %s" > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 " to a compile-time constant", > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 name !=3D NULL_TREE ? IDENTIFIER= _POINTER (name) : NULL); It's not safe in general to use NULL with %s, so this needs to be split into something like: =A0=A0=A0=A0=A0 if (name) =A0=A0=A0=A0=A0=A0=A0 add_error (NULL, =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "unable to convert i= nitial value for the global variable %s" =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 " to a compile-time = constant", =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 IDENTIFIER_POINTER); =A0=A0=A0=A0=A0 else =A0=A0=A0=A0=A0=A0=A0 add_error (NULL, =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "unable to convert i= nitial value for global variable" =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 " to a compile-time = constant"); [...snip...] > diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h > index a1c9436c545..967d8843a98 100644 > --- a/gcc/jit/libgccjit.h > +++ b/gcc/jit/libgccjit.h > @@ -812,6 +812,159 @@ gcc_jit_context_new_global (gcc_jit_context *ctxt, >=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0 gcc_jit_type *type, >=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0 const char *name); >=A0=20 > +#define LIBGCCJIT_HAVE_CTORS > + > +/* Create a constructor for an struct as a rvalue. s/an struct/a struct/ s/a rvalue/an rvalue/ [...snip...] > +extern gcc_jit_rvalue * > +gcc_jit_context_new_struct_constructor (gcc_jit_context *ctxt, > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 gcc_jit_location *loc, > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 gcc_jit_type *type, > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 size_t arr_length, > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 gcc_jit_field **fields, > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 gcc_jit_rvalue **values); > + > +/* Create a constructor for an union as a rvalue. s/an union/a union/ s/a rvalue/an rvalue/ [...snip...] > +/* Create a constructor for an array as a rvalue. s/a rvalue/an rvalue/ [...snip...] > diff --git a/gcc/testsuite/jit.dg/test-error-ctor-array-wrong-type.c b/gc= c/testsuite/jit.dg/test-error-ctor-array-wrong-type.c > new file mode 100644 > index 00000000000..1ce83b2ed6c > --- /dev/null > +++ b/gcc/testsuite/jit.dg/test-error-ctor-array-wrong-type.c > @@ -0,0 +1,54 @@ > +/* > + > +=A0 Test that the proper error is triggered when we build a ctor > +=A0 for an array type, but has the type wrong on an element. > + > +*/ > + > +#include > +#include > + > +#include "libgccjit.h" > +#include "harness.h" > + > +void > +create_code (gcc_jit_context *ctxt, void *user_data) > +{ > +=A0 gcc_jit_type *int_type =3D gcc_jit_context_get_type (ctxt, > +=A0=A0=A0 GCC_JIT_TYPE_INT); > +=A0 gcc_jit_type *float_type =3D gcc_jit_context_get_type (ctxt, > +=A0=A0=A0 GCC_JIT_TYPE_FLOAT); > + > +=A0 gcc_jit_type *arr_type =3D > +=A0=A0=A0 gcc_jit_context_new_array_type (ctxt, 0, int_type, 10); > + > +=A0 gcc_jit_rvalue *frv =3D gcc_jit_context_new_rvalue_from_double (ctxt= , > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 float_type, > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 12); > + > +=A0 gcc_jit_rvalue *ctor =3D gcc_jit_context_new_array_constructor > +=A0=A0=A0 (ctxt, 0, > +=A0=A0=A0=A0 arr_type, > +=A0=A0=A0=A0 1, > +=A0=A0=A0=A0 &frv); > + > +=A0 CHECK_VALUE (ctor, NULL); > +} > + > +void > +verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) > +{ > +=A0 /* Ensure that the bad API usage prevents the API giving a bogus > +=A0=A0=A0=A0 result back.=A0 */ > +=A0 CHECK_VALUE (result, NULL); > + > +=A0 /* Verify that the correct error message was emitted. */ > +=A0 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt), > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "gcc_jit_context_= new_array_constructor: array element " > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "value types diff= er from types in 'values' (element " > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "type: int)('valu= es' type: float)"); > +=A0 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt), Looks like a copy&paste error: the second CHECK_STRING_VALUE is presumably meant to check get_last_error here, rather than checking get_first_error again, right? Might be good to introduce a macro, say, EXPECTED_ERROR_MESSAGE, to avoid repeating the string literal, which would make such copy&paste errors more obvious (and avoid repetition), for all of these various error cases. > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "gcc_jit_context_= new_array_constructor: array element " > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "value types diff= er from types in 'values' (element " > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "type: int)('valu= es' type: float)"); > +} [...snip...] > diff --git a/gcc/testsuite/jit.dg/test-error-ctor-union-wrong-field-name.= c b/gcc/testsuite/jit.dg/test-error-ctor-union-wrong-field-name.c > new file mode 100644 > index 00000000000..2bf8ee4023e > --- /dev/null > +++ b/gcc/testsuite/jit.dg/test-error-ctor-union-wrong-field-name.c s/wrong-field-name/wrong-field-obj/ to match the struct example (given that the issue being tested for is that it's the wrong object, rather than the wrong name). [...snip...] > diff --git a/gcc/testsuite/jit.dg/test-error-global-init-too-small-array.= c b/gcc/testsuite/jit.dg/test-error-global-init-too-small-array.c > new file mode 100644 > index 00000000000..996d9583860 > --- /dev/null > +++ b/gcc/testsuite/jit.dg/test-error-global-init-too-small-array.c > @@ -0,0 +1,65 @@ > +/* > + > +=A0 Test that the proper error is triggered when we initialize > +=A0 a global with another non-const global's rvalue. I think this comment is wrong; the filename and code suggest this is testing something else.=A0 Looks like a copy&paste error from the comment in test-error-global-lvalue-init.c > + > +=A0 Using gcc_jit_global_set_initializer_rvalue() > + > +*/ > + > +#include > +#include > + > +#include "libgccjit.h" > +#include "harness.h" > + > +void > +create_code (gcc_jit_context *ctxt, void *user_data) > +{ /* float foo[1] =3D {1,2}; */ > + > +=A0 gcc_jit_type *float_type =3D gcc_jit_context_get_type (ctxt, > +=A0=A0=A0 GCC_JIT_TYPE_FLOAT); > +=A0 gcc_jit_type *arr_type =3D gcc_jit_context_new_array_type (ctxt, > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0 0, > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0 float_type, > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0 1); > +=A0 gcc_jit_rvalue *rval_1 =3D gcc_jit_context_new_rvalue_from_int ( > +=A0=A0=A0 ctxt, float_type, 1); > +=A0 gcc_jit_rvalue *rval_2 =3D gcc_jit_context_new_rvalue_from_int ( > +=A0=A0=A0 ctxt, float_type, 2); > + > +=A0 gcc_jit_rvalue *values[] =3D {rval_1, rval_2}; > + > +=A0 gcc_jit_rvalue *ctor =3D gcc_jit_context_new_array_constructor (ctxt= , > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 0, > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 arr_type, > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 2, > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 values); > +=A0 if (!ctor) > +=A0=A0=A0 return; > + > +=A0 gcc_jit_lvalue *foo =3D=A0 gcc_jit_context_new_global ( > +=A0=A0=A0 ctxt, NULL, > +=A0=A0=A0 GCC_JIT_GLOBAL_EXPORTED, > +=A0=A0=A0 arr_type, > +=A0=A0=A0 "global_floatarr_12"); > +=A0 gcc_jit_global_set_initializer_rvalue (foo, ctor); > +} > + > +void > +verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) > +{ > +=A0 /* Ensure that the bad API usage prevents the API giving a bogus > +=A0=A0=A0=A0 result back.=A0 */ > +=A0 CHECK_VALUE (result, NULL); > + > +=A0 /* Verify that the correct error message was emitted. */ > +=A0 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt), > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "gcc_jit_context_= new_array_constructor: array " > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "constructor has = more values than the array type's " > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "length (array ty= pe length: 1, constructor length: 2)"); > +=A0 CHECK_STRING_VALUE (gcc_jit_context_get_last_error (ctxt), > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "gcc_jit_context_= new_array_constructor: array " > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "constructor has = more values than the array type's " > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "length (array ty= pe length: 1, constructor length: 2)"); > +} [...snip...] > diff --git a/gcc/testsuite/jit.dg/test-global-init-rvalue.c b/gcc/testsui= te/jit.dg/test-global-init-rvalue.c > new file mode 100644 > index 00000000000..21675ac9acf > --- /dev/null > +++ b/gcc/testsuite/jit.dg/test-global-init-rvalue.c > @@ -0,0 +1,1563 @@ > +/* This testcase checks that gcc_jit_global_set_initializer_rvalue() wor= ks > +=A0=A0 with rvalues, especially with gcc_jit_context_new_*_constructor()= for > +=A0=A0 struct, unions and arrays. */ [...snip...] The order in which you create things in create_code isn't quite the same as the order in which you check things in verify_code.=A0 Is it possible to reorder things so that these are consistent?=A0 That would make it easier to compare the libgccjit calls with the expected behavior. Thanks for all the test coverage, BTW - both of valid usage and error- handling - it makes me much happier about the patch. [...snip...] I would say "OK for trunk, with those nits fixed", but I want to hear Antoni's opinion on whether this works for him for the rustc plugin, or if he needs further changes.=A0 Antoni - does this patch work for you? Thanks again for the patch; this is looking close to ready; hope the above makes sense. Dave =