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 A7201C16582; Mon, 3 Jun 2024 17:39:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A7201C16582 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1717425561; bh=sy4Bzt4UrLOUgaCSdr27pBggdrLeSJ9xVo6Cs7NBvcs=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=p6+ANdXvFLQWM5pp/emvs0gs+c9Ydww8KZRP9R9nd565NyKJ1MlswXEvAczNDbkZg pFy224iJD4XFcO5n2DIJgwyMol4G0TuOKfL91Epg6rXbFZqTG0SV27wJS5oLSBV+I5 VbssuUMBLH5NXMw1+gMSZA4l7Il8rn+xxFKrF9CM= Received: from smtp44.i.mail.ru (smtp44.i.mail.ru [95.163.41.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 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 606DEC16582 for ; Mon, 3 Jun 2024 17:38:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 606DEC16582 Received: by smtp44.i.mail.ru with esmtpa (envelope-from ) id 1sE8pI-0000000F2Sb-0n5h; Mon, 03 Jun 2024 17:38:20 +0300 To: Maxim Kokryashkin , Sergey Bronnikov Date: Mon, 3 Jun 2024 17:34:00 +0300 Message-ID: X-Mailer: git-send-email 2.45.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD9F634E6C4921FF12DAB6A1088BE559A42FD732337405BAA0600894C459B0CD1B913A6C98E7EDF3D246C36CA141FC789AE452B0CE5AF89CF50B1117BCBF30E9EA1785316FF18B29525 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7CEC4F91A22C5F5FEEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006371111040D1ED495018638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D860702D239AE4665E262E5AE63C0E75AC3E23EB5CE15B1B02CC7F00164DA146DAFE8445B8C89999728AA50765F7900637BA939FD1B3BAB99B389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8989FD0BDF65E50FBF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947CE6BDB36F057AC83C040F9FF01DFDA4A84AD6D5ED66289B523666184CF4C3C14F6136E347CC761E07725E5C173C3A84C3C36FA3AD04261E41BA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CFED8438A78DFE0A9E1DD303D21008E298D5E8D9A59859A8B6957A4DEDD2346B4275ECD9A6C639B01B78DA827A17800CE70012B0FBE38D23AE731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A52152F62B202049835002B1117B3ED696D8839CD7690EC1188B25839F35DFE037823CB91A9FED034534781492E4B8EEAD220496FFA5CD4785C79554A2A72441328621D336A7BC284946AD531847A6065A535571D14F44ED41 X-C8649E89: 1C3962B70DF3F0ADBF74143AD284FC7177DD89D51EBB7742424CF958EAFF5D571004E42C50DC4CA955A7F0CF078B5EC49A30900B95165D349F4E6BC39AAD02BB33E5AB89092AE1839D2574B8A4AF7D3B44CED585F156C1BB755A44FD833F50C41D7E09C32AA3244CAC226F955C5E36E57215182CA7F2886079BDCAC352B70240EA455F16B58544A21C197AAF4D2E4732A5AE236DF995FB59829709634694AABAED6A17656DB59BCAD427812AF56FC65B X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojxO1G5pUKYoEtJYJVjyIjiw== X-Mailru-Sender: 520A125C2F17F0B1A9638AD358559B59CB83DEB9D8EC3F6B411046492FDDF80625D52D8D0B3E3E4EB7CBEF92542CD7C88B0A2698F12F5C9EC77752E0C033A69E86920BD37369036789A8C6A0E60D2BB63A5DB60FBEB33A8A0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 2/4] FFI: Fix sizeof expression in C parser for reference types. 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: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Mike Pall (cherry picked from commit 899093a9e0fa5b16f27016381ef4b15529dadff2) According to C++ Standard, the `alignof()` (5.3.6.3) [1] and `sizeof()` (5.3.3.2) [2] for the reference should be the same as for the referenced type. This patch fixes the behaviour by following the reference to get a child id for `alignof()` and `sizeof()` while parsing C definitions via `ffi.cdef()`. Sergey Kaplun: * added the description and the test for the problem Part of tarantool/tarantool#9924 [1]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4594.pdf#subsection.5.3.6 [2]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4594.pdf#subsection.5.3.3 --- src/lj_cparse.c | 2 +- .../lj-861-ctype-attributes.test.lua | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/lj_cparse.c b/src/lj_cparse.c index 01deb3bf..8506d719 100644 --- a/src/lj_cparse.c +++ b/src/lj_cparse.c @@ -468,7 +468,7 @@ static void cp_expr_sizeof(CPState *cp, CPValue *k, int wantsz) } else { cp_expr_unary(cp, k); } - info = lj_ctype_info(cp->cts, k->id, &sz); + info = lj_ctype_info_raw(cp->cts, k->id, &sz); if (wantsz) { if (sz != CTSIZE_INVALID) k->u32 = sz; diff --git a/test/tarantool-tests/lj-861-ctype-attributes.test.lua b/test/tarantool-tests/lj-861-ctype-attributes.test.lua index d88045a5..e8b29d67 100644 --- a/test/tarantool-tests/lj-861-ctype-attributes.test.lua +++ b/test/tarantool-tests/lj-861-ctype-attributes.test.lua @@ -7,7 +7,7 @@ local tap = require('tap') local test = tap.test('lj-861-ctype-attributes') local ffi = require('ffi') -test:plan(2) +test:plan(4) local EXPECTED_ALIGN = 4 @@ -15,6 +15,15 @@ ffi.cdef([[ struct __attribute__((aligned($))) s_aligned { uint8_t a; }; + +struct test_parsing_sizeof { + char a[sizeof(struct s_aligned &)]; +}; + +struct test_parsing_alignof { + char a[__alignof__(struct s_aligned &)]; +}; + ]], EXPECTED_ALIGN) local ref_align = ffi.alignof(ffi.typeof('struct s_aligned &')) @@ -23,4 +32,9 @@ test:is(ref_align, EXPECTED_ALIGN, 'the reference alignment is correct') test:is(ref_align, ffi.alignof(ffi.typeof('struct s_aligned')), 'the alignment of a reference is the same as for the referenced type') +test:is(ffi.sizeof('struct test_parsing_sizeof'), EXPECTED_ALIGN, + 'correct sizeof during C parsing') +test:is(ffi.sizeof('struct test_parsing_alignof'), EXPECTED_ALIGN, + 'correct alignof during C parsing') + test:done(true) -- 2.45.1