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 3D9D0BC5501; Tue, 11 Jun 2024 18:42:08 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3D9D0BC5501 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1718120528; bh=GPerOCtpyf1NYkmmU/jaE2PUAgpJZUOTuBFeN4TrNa8=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=dKyGtp6BruogHM3+DSdud4eOBiRTDx7+Cgt5HDhCrFJhWKbSYBxTQoSEwGerNexjd upYbihM0b6ZpV72X9f0Wbmhta7q8mE+8m1z1t/NCnyuPx6T+dM13rk10vQw0CcCyDR GuRHdPznGIy4QlAxzG43bk4ELP2n7KkNgdSqYt00= Received: from smtp35.i.mail.ru (smtp35.i.mail.ru [95.163.41.76]) (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 83569BC5501 for ; Tue, 11 Jun 2024 18:42:06 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 83569BC5501 Received: by smtp35.i.mail.ru with esmtpa (envelope-from ) id 1sH3dN-0000000Ekjj-2eC6; Tue, 11 Jun 2024 18:42:06 +0300 Content-Type: multipart/alternative; boundary="------------jDWush47RD8oQ0feSWwSh77F" Message-ID: <3baf52d2-79ee-4438-b33e-2f85013bd4d2@tarantool.org> Date: Tue, 11 Jun 2024 18:42:05 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Sergey Kaplun , Maxim Kokryashkin Cc: tarantool-patches@dev.tarantool.org References: In-Reply-To: X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9AC8CA0B4439200FAC9ED020CEABC603EBFE2E3CBD10956AC00894C459B0CD1B986EE2820409283614F0509D9B8515F63309CD33E7D00C9D0139E2EB4DF0EFAADF8D9167951636918 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE74E2C4641A2CB07F2EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637B6B039AA0E19584A8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8436568FC7BAB9E5E4CF797125499C4A891A82CEFAB3EBD22CC7F00164DA146DAFE8445B8C89999728AA50765F7900637D0FEED2715E18529389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8D2DCF9CF1F528DBCF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947C65B78C30F681404D9735652A29929C6C4AD6D5ED66289B523666184CF4C3C14F6136E347CC761E07725E5C173C3A84C3A34FB461F64EA2D5BA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE79E6B27D82EEA174F731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A58E0A9064CCF1C44F5002B1117B3ED6963CC1971B24269EE57E0012C66AE17B00823CB91A9FED034534781492E4B8EEAD47A3109F1ACFD409BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADBF74143AD284FC7177DD89D51EBB7742424CF958EAFF5D571004E42C50DC4CA955A7F0CF078B5EC49A30900B95165D34C1E32F4AD4B2486B04216E53BD5896580382E8E4C04EA9A8014B25EECB8A03F3CD06AA25677DC7421D7E09C32AA3244C8124953D9D0CE6F2B58A6D757C7509E247B5C2771C4EA4B6EA455F16B58544A2557BDE0DD54B3590A5AE236DF995FB59978A700BF655EAEEED6A17656DB59BCAD427812AF56FC65B X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj7p5wIdCuWKNiwu/oomivFw== X-Mailru-Sender: C4F68CFF4024C8867DFDF7C7F258845879927470432E5B95965EDF11CFD47EC7E67F02AB0CE2E3A9C41A96CE181C003A645D15D82EE4B272BD6E4642A116CA93524AA66B5ACBE6721EF430B9A63E2A504198E0F3ECE9B5443453F38A29522196 X-Mras: Ok Subject: Re: [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 Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This is a multi-part message in MIME format. --------------jDWush47RD8oQ0feSWwSh77F Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi, Sergey thanks for the patch! LGTM On 03.06.2024 17:34, Sergey Kaplun wrote: > 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) --------------jDWush47RD8oQ0feSWwSh77F Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

Hi, Sergey

thanks for the patch! LGTM

On 03.06.2024 17:34, Sergey Kaplun wrote:
From: Mike Pall <mike>

(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)
--------------jDWush47RD8oQ0feSWwSh77F--