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

avoid memset & memcpy on non-trivially copyable fc::variant to eliminate a bunch of warnings #1246

Merged
merged 1 commit into from
Mar 10, 2025

Conversation

spoonincode
Copy link
Member

clang20 is firing off a megaton of warnings such as

warning: first argument in call to 'memset' is a pointer to non-trivially copyable type 'fc::variant'

and

warning: first argument in call to 'memcpy' is a pointer to non-trivially copyable type 'fc::variant'

Not sure if anyone has strong opinions on proper way to resolve the warning (besides a larger refactor). I think we could keep the memcpy/memset and explicitly cast the pointers but that seems more hacky than using a std::array like done here.

double _data; ///< Alligned according to double requirements
char _type[sizeof(void*)]; ///< pad to void* size
//enough room to store pointers, doubles, uint64s. doubled to allow 1 extra byte to store type at the end
alignas(double) std::array<char, std::max(sizeof(uintmax_t ), sizeof(double)) * 2> _data = {};
Copy link
Member Author

Choose a reason for hiding this comment

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

afaict we just need a +1 but I doubled it so it fits nicely in 16 byte register (and 16 bytes is what it was previously too)

@spoonincode spoonincode merged commit f64b729 into main Mar 10, 2025
71 checks passed
@spoonincode spoonincode deleted the fcvarwarn branch March 10, 2025 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants