Bug 226167

Summary: GCC complains about a memcpy in SmallSet.h
Product: WebKit Reporter: Eleni Maria Stea <estea>
Component: Web Template FrameworkAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: benjamin, cdumez, cmarcelo, darin, estea, ews-watchlist, mcatanzaro, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Local Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch mcatanzaro: review+, mcatanzaro: commit-queue-

Description Eleni Maria Stea 2021-05-24 00:57:16 PDT
GCC complains about a memcpy in SmallSet.h It seems that it contains an object with no trivial copy-assignment. We'd rather eplace the memcpy with assignments of the private members.

Error:

WTF/Headers/wtf/SmallSet.h:70:15: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘class WTF::SmallSet<WTF::UniquedStringImpl*’ with no trivial copy-assignment [-Wclass-memaccess]
   70 |         memcpy(this, &other, sizeof(SmallSet));
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
WTF/Headers/wtf/SmallSet.h:44:7: note: ‘class WTF::SmallSet<WTF::UniquedStringImpl*>’ declared here
   44 | class SmallSet {
Comment 1 Eleni Maria Stea 2021-05-24 01:01:53 PDT
Created attachment 429512 [details]
Patch
Comment 2 Radar WebKit Bug Importer 2021-05-31 00:58:16 PDT
<rdar://problem/78679329>
Comment 3 Michael Catanzaro 2023-11-14 10:58:23 PST
Comment on attachment 429512 [details]
Patch

Found this when searching for -Wclass-memaccess warnings. It will need to be rebased because I added void casts at some point to suppress this warning. Your solution is better.
Comment 4 Darin Adler 2023-11-15 07:43:49 PST
Comment on attachment 429512 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=429512&action=review

> Source/WTF/wtf/SmallSet.h:72
> +        this->m_size = other.m_size;
> +        this->m_capacity = other.m_capacity;
> +        this->m_inline = other.m_inline;

We can also omit the "this->" here.