-
Notifications
You must be signed in to change notification settings - Fork 403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
iox-#1614 Move uninitialized array #1774
iox-#1614 Move uninitialized array #1774
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1774 +/- ##
==========================================
- Coverage 77.39% 77.35% -0.04%
==========================================
Files 367 367
Lines 14245 14243 -2
Branches 1992 1992
==========================================
- Hits 11025 11018 -7
- Misses 2591 2592 +1
- Partials 629 633 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine. Just one question related to the location and it seems bazel is not happy
Oh, the clang-tidy warning will disappear once you rebase to master :) |
4c157ea
to
9d905aa
Compare
…amespace iox Signed-off-by: Marika Lehmann <marika.lehmann@apex.ai>
9d905aa
to
edd3f99
Compare
Move header file to iox folder, remove 's' from buffer and container modules Signed-off-by: Marika Lehmann <marika.lehmann@apex.ai>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the clang-tidy-diff file could be simplified
Replace UninitializedArrays with ElementType char with char array Signed-off-by: Marika Lehmann <marika.lehmann@apex.ai>
e988034
042878c
to
6cb1a0f
Compare
Refactoring in UninitializedArray, variant and optional. Change gcc version to 8 for ubuntu build. Signed-off-by: Marika Lehmann <marika.lehmann@apex.ai>
6cb1a0f
to
c31b000
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The brace zero initialization question is the only relevant comment. Everything else is only a style question or potential future refactoring in a different issue.
{ | ||
// AXIVION Next Construct AutosarC++19_03-A18.1.1 : required by low level UninitializedArray building block and encapsulated in abstraction | ||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays) | ||
cxx::byte_t data[sizeof(ElementType)]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding any other fields to the struct will break things. Maybe worth a comment.
I am also wondering whether the zero-initialization braces { }
are required here (instead of array of element_t
).
alignas(ElementType) element_t value[Capacity]{}; | ||
// NOLINTEND(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays) | ||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays) | ||
element_t value[Capacity]{}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we move the braces to element_t
, they should not be required here. I am generally not sure how it works with padding without trying it out.
There can be trailing padding in element_t
(to make size a multiple of alignment). Depends on our requirements of the padding initialization. Padding initialization which would not happen if we move it I think, but would it as it is now?
@elBoberido FYI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the UninitialiizedArray
is typed and element_t
uses the size and alignment of that type, there are no issues with additional padding bytes
@@ -229,7 +230,14 @@ class optional final : public FunctionalInterface<optional<T>, T, void> | |||
// initHandle(&handle); | |||
// } | |||
bool m_hasValue{false}; | |||
typename std::aligned_storage<sizeof(T), alignof(T)>::type m_data; | |||
struct alignas(T) element_t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not be necessary to use our own struct. Do we want to remove the dependency on std::aligned_storage
or is there another reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replaced std::aligned_storage
since it is deprecated in C++23 (I know, not a problem now but maybe later) and already added similar constructs in variant
and UninitializedArray
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just a few minor remarks
@@ -31,7 +31,7 @@ inline constexpr variant<Types...>::variant(const variant& rhs) noexcept | |||
{ | |||
if (m_type_index != INVALID_VARIANT_INDEX) | |||
{ | |||
internal::call_at_index<0, Types...>::copyConstructor(m_type_index, rhs.m_storage, m_storage); | |||
internal::call_at_index<0, Types...>::copyConstructor(m_type_index, &rhs.m_storage.data[0], &m_storage.data[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this leads to warnings with -Wcast-align=strict
. Unfortunately this is baked into the call_at_index
struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FerdinandSpitzschnueffler after some thinking, the call_at_index
should use void*
instead of byte_t*
. Could you please change that?
With that change there is only two offender when using -Wcast_aling=strict
One is in types.h
in the C binding. Changing
/// @brief handle of the chunk header
typedef struct
{
// could be empty but then we get `struct has no members` warning
uint8_t do_not_touch_me[1];
} iox_chunk_header_t;
to
/// @brief handle of the chunk header
typedef struct iox_chunk_header_opaque_t iox_chunk_header_t;
fixes the problem there.
And the others in the UDS and MQ iceperf code ... which is just by coincidence not broken 😅
I think types.h
and the iceperf example could be fixed in another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also in another issue, in types.h we may consider defining iox::byte
to be char
and not uint8_t
. This is mainly to prevent some issues with strict aliasing with compilers that do not define uint8_t
to be unsigned char
(I do not know of such a compiler).
It is mandated by the standard that no type can be smaller than char
(and unsigned char
I guess), and sizeof(char) = 1
. So we do not lose guarantees but prevent some strict aliasing problems on exotic compilers.
To my knowledge, there is no reason to define a byte not to be char instead of uint8_t
. Note that C++17 offers std::byte
but we cannot use that here, see https://stackoverflow.com/questions/46150738/how-to-use-new-stdbyte-type-in-places-where-old-style-unsigned-char-is-needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed call_at_index
to take a void*
and created #1778 for the warnings in the C binding and the iceperf example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MatthiasKillat I like the idea of a iox::byte
similar to std::byte
. Would be something for a separate issue.
…ve .data Signed-off-by: Marika Lehmann <marika.lehmann@apex.ai>
200616c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My last remark can also be done in a separate PR since it is not really related to the uninitialized array
iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/variant_internal.hpp
Outdated
Show resolved
Hide resolved
Signed-off-by: Marika Lehmann <marika.lehmann@apex.ai>
Pre-Review Checklist for the PR Author
iox-123-this-is-a-branch
)iox-#123 commit text
)task-list-completed
)iceoryx_hoofs
are added to./clang-tidy-diff-scans.txt
Notes for Reviewer
This PR moves the UninitializedArray to
iceoryx_hoofs/containers/include/iox/detail/
and removes the namespacecontainers
.Checklist for the PR Reviewer
iceoryx_hoofs
have been added to./clang-tidy-diff-scans.txt
Post-review Checklist for the PR Author
References