From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id B716F51F737; Mon, 10 Jul 2023 18:56:32 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B716F51F737 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1689004592; bh=66muQTAei/PuJrb8UFsSztt95P67JHfz2B0epRoSl9Y=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=eaE/mnw4gtGRVBDlFPxMau6Fpv1mGXAarEN0wDr2FLHMs8SzNjK9GwncBRU8JAQV3 BY7ajEI1GBZE1VQ6irBxthB26X2t/nkcGxJw55YxD8qiJF1SJWHqwpeQeeXZMf4dZf KfI/EfqA9Ph1MPOp4A8CZikCSkw8MbdApwdOIPt8= Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 3C3D751F737 for ; Mon, 10 Jul 2023 18:56:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3C3D751F737 Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-2b703a0453fso71926111fa.3 for ; Mon, 10 Jul 2023 08:56:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689004590; x=1691596590; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZpgJdjQRCciixHGL+v66SgfQCc4wtzZmcKfRXSqgny4=; b=aXD5ryGueA+EAdupuWANpc3p71wmx9u7hrEHQkjxf52MeaXXw6tTd/qh/yGJGNNXTL MgdrJD81U9pEbNvX1w79J6reJ90qMTaVgjkgpyEOwPayCuhxXlLmzzVib/zfy911viuC LAR3hav8idGDEWoTEdHg8gFvuFAwLYNpAErhg+Y796JC8aGKM14egNoHjtv078ncivoQ JqrCtVWdDZtvc/ZaB1Q3da7SBYzCsfXFN3dhBHLeOe1RwIUQw7UAKRtuCfS8E426F/PF TCUo+4e7TeQi36js79wafNadmTzeJ/Ma+idWuIi4FwRuaxmxwMNaAeF/zFqINB/i06ZH qnkw== X-Gm-Message-State: ABy/qLabZnzfXod1ofSUx/+7TDlhjnxpq9tsF5a+skjN79+W0OE/dxLL jWU+IZNlm/1ADS/ZYcotV8AgBMLQo3QIpQ== X-Google-Smtp-Source: APBJJlFAWlsZT5LRGs0ddLaQqcn63P5Gdl7CwdP8flI78/tbTKDQPxUbyCZqPedH8eAauSau0rUPGQ== X-Received: by 2002:a2e:9d99:0:b0:2b6:d57a:cf2e with SMTP id c25-20020a2e9d99000000b002b6d57acf2emr11744051ljj.42.1689004589872; Mon, 10 Jul 2023 08:56:29 -0700 (PDT) Received: from localhost.localdomain ([185.205.79.32]) by smtp.gmail.com with ESMTPSA id n10-20020a2e720a000000b002b70a8478ddsm30357ljc.44.2023.07.10.08.56.28 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 10 Jul 2023 08:56:29 -0700 (PDT) To: tarantool-patches@dev.tarantool.org, sergeyb@tarantool.org, skaplun@tarantool.org, m.kokryashkin@tarantool.org Date: Mon, 10 Jul 2023 18:56:22 +0300 Message-Id: <20230710155624.70639-1-max.kokryashkin@gmail.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH luajit] FFI: Fix recording of union initialization. X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Maksim Kokryashkin via Tarantool-patches Reply-To: Maksim Kokryashkin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Mike Pall 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) +end + +os.exit(test:check() and 0 or 1) -- 2.39.2 (Apple Git-143)