From: Sergey Bronnikov via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: Maksim Kokryashkin <max.kokryashkin@gmail.com>, tarantool-patches@dev.tarantool.org, skaplun@tarantool.org, m.kokryashkin@tarantool.org Subject: Re: [Tarantool-patches] [PATCH luajit] FFI: Fix recording of union initialization. Date: Thu, 13 Jul 2023 12:26:29 +0300 [thread overview] Message-ID: <e5a8fd16-6633-4286-7ca9-398e9e2245ba@tarantool.org> (raw) In-Reply-To: <20230710155624.70639-1-max.kokryashkin@gmail.com> Hi, Max! thanks for the patch! See my comments inline. Sergey On 7/10/23 18:56, Maksim Kokryashkin wrote: > From: Mike Pall <mike> > > Thanks to Alex Shpilkin. > > (cherry-picked from commit 56c04accf975bff2519c34721dccbbdb7b8e6963) > > As stated here[1], only the first field of a union can be > initialized with a flat initializer. However, before this > patch, on-trace initialization instructions were emitted > for other union members too, overwriting the previous > initialization values. > > This patch fixes the mentioned behavior by preventing > initialization of members other than the first one. > > [1]: https://luajit.org/ext_ffi_semantics.html#init > > Maxim Kokryashkin: > * added the description and the test for the problem > > Part of tarantool/tarantool#8825 > --- > Branch: https://github.com/tarantool/luajit/tree/fckxorg/lj-128-fix-union-init > PR: https://github.com/tarantool/tarantool/pull/8867 > Original LuaJIT PR: https://github.com/LuaJIT/LuaJIT/pull/650 > > src/lj_crecord.c | 5 +++++ > .../lj-128-fix-union-init.test.lua | 18 ++++++++++++++++++ > 2 files changed, 23 insertions(+) > create mode 100644 test/tarantool-tests/lj-128-fix-union-init.test.lua > > diff --git a/src/lj_crecord.c b/src/lj_crecord.c > index 0008a865..ffe995f4 100644 > --- a/src/lj_crecord.c > +++ b/src/lj_crecord.c > @@ -1065,6 +1065,11 @@ static void crec_alloc(jit_State *J, RecordFFData *rd, CTypeID id) > dp = emitir(IRT(IR_ADD, IRT_PTR), trcd, > lj_ir_kintp(J, df->size + sizeof(GCcdata))); > crec_ct_tv(J, dc, dp, sp, sval); > + if ((d->info & CTF_UNION)) { > + if (d->size != dc->size) /* NYI: partial init of union. */ > + lj_trace_err(J, LJ_TRERR_NYICONV); > + break; > + } > } else if (!ctype_isconstval(df->info)) { > /* NYI: init bitfields and sub-structures. */ > lj_trace_err(J, LJ_TRERR_NYICONV); > diff --git a/test/tarantool-tests/lj-128-fix-union-init.test.lua b/test/tarantool-tests/lj-128-fix-union-init.test.lua > new file mode 100644 > index 00000000..6a49cec8 > --- /dev/null > +++ b/test/tarantool-tests/lj-128-fix-union-init.test.lua > @@ -0,0 +1,18 @@ > +local tap = require('tap') > +local test = tap.test('lj-128-fix-union-init'):skipcond({ > + ['Test requires JIT enabled'] = not jit.status(), > +}) > + > +local NITERATIONS = 4 > + > +test:plan(NITERATIONS) > + > +local ffi = require('ffi') > +local union_type = ffi.typeof('union { uint32_t u; float f; }') > + > +jit.opt.start('hotloop=1') > +for i = 1, NITERATIONS do > + test:ok(union_type(i).u == i) testcases description is missed, please add one. > +end > + > +os.exit(test:check() and 0 or 1)
next prev parent reply other threads:[~2023-07-13 9:26 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-07-10 15:56 Maksim Kokryashkin via Tarantool-patches 2023-07-13 9:26 ` Sergey Bronnikov via Tarantool-patches [this message] 2023-07-13 10:30 ` Sergey Kaplun via Tarantool-patches 2023-07-14 14:57 ` Maxim Kokryashkin via Tarantool-patches 2023-07-15 11:27 ` Sergey Kaplun via Tarantool-patches 2023-07-17 11:31 ` Maxim Kokryashkin via Tarantool-patches 2023-07-18 15:11 ` Sergey Bronnikov via Tarantool-patches 2023-07-20 18:37 ` Igor Munkin via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=e5a8fd16-6633-4286-7ca9-398e9e2245ba@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=m.kokryashkin@tarantool.org \ --cc=max.kokryashkin@gmail.com \ --cc=sergeyb@tarantool.org \ --cc=skaplun@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH luajit] FFI: Fix recording of union initialization.' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox