<!DOCTYPE html>
<html data-lt-installed="true">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body style="padding-bottom: 1px;">
<p>Hi, Sergey</p>
<p>thanks for the patch! LGTM<br>
</p>
<div class="moz-cite-prefix">On 03.06.2024 17:34, Sergey Kaplun
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:f5bbc531e23670edbbed987f7f754ade0ae3c23f.1717424008.git.skaplun@tarantool.org">
<pre class="moz-quote-pre" wrap="">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]: <a class="moz-txt-link-freetext" href="https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4594.pdf#subsection.5.3.6">https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4594.pdf#subsection.5.3.6</a>
[2]: <a class="moz-txt-link-freetext" href="https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4594.pdf#subsection.5.3.3">https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4594.pdf#subsection.5.3.3</a>
---
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)
</pre>
</blockquote>
</body>
<lt-container></lt-container>
</html>