Skip to content
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

[meta] Enable strict cast-align warning #738

Merged
merged 1 commit into from
Dec 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ CFLAGS_COMMON+=" -ansi"
CFLAGS_COMMON+=" -fPIC"
CFLAGS_COMMON+=" -std=c++11"
CFLAGS_COMMON+=" -Wall"
CFLAGS_COMMON+=" -Wcast-align"
CFLAGS_COMMON+=" -Wcast-align=strict"
CFLAGS_COMMON+=" -Wcast-qual"
CFLAGS_COMMON+=" -Wconversion"
CFLAGS_COMMON+=" -Wdisabled-optimization"
Expand Down
11 changes: 8 additions & 3 deletions meta/MetaKeyHasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ static inline std::size_t sai_get_hash(

if (re.destination.addr_family == SAI_IP_ADDR_FAMILY_IPV6)
{
const uint32_t* ip6 = (const uint32_t*)re.destination.addr.ip6;
// cast is not good enough for arm (cast align)
uint32_t ip6[4];
memcpy(ip6, re.destination.addr.ip6, sizeof(ip6));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addr [](start = 35, length = 4)

I see sai_ip_addr_t is already 4 bytes aligned because ip4 is uint32_t. So the memcpy is preventable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

somehow on arm architecture it still gives this warning, also i checked assembly on O2, and memcpy is optimized, and it's not there, just direct ip access


return ip6[0] ^ ip6[1] ^ ip6[2] ^ ip6[3];
}
Expand All @@ -152,7 +154,9 @@ static inline std::size_t sai_get_hash(

if (ne.ip_address.addr_family == SAI_IP_ADDR_FAMILY_IPV6)
{
const uint32_t* ip6 = (const uint32_t*)ne.ip_address.addr.ip6;
// cast is not good enough for arm (cast align)
uint32_t ip6[4];
memcpy(ip6, ne.ip_address.addr.ip6, sizeof(ip6));

return ip6[0] ^ ip6[1] ^ ip6[2] ^ ip6[3];
}
Expand Down Expand Up @@ -195,7 +199,8 @@ std::size_t MetaKeyHasher::operator()(

if (meta && meta->isobjectid)
{
return k.objectkey.key.object_id;
// cast is required in case size_t is 4 bytes (arm)
return (std::size_t)k.objectkey.key.object_id;
}

switch (k.objecttype)
Expand Down