Bug 150235 - SameSizeAs* structs wrongly assume sizeof(ptr)==sizeof(std::unique_ptr)
Summary: SameSizeAs* structs wrongly assume sizeof(ptr)==sizeof(std::unique_ptr)
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-16 09:54 PDT by R. Sharma
Modified: 2015-10-22 15:27 PDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description R. Sharma 2015-10-16 09:54:23 PDT
Hi,

In regard to all the static assertions, to check the sizes of the data-structures using SameSizeAs* structs, it is wrongly assumed, that sizeof (std::unique_ptr) is same as sizeof (pointer) for all compilers. 
Therefore, I would suggest to list them separately while computing the sizes.

To give an example:
In WebCore\dom\ElementRareData.cpp

The structure should look like:
struct SameSizeAsElementRareData : NodeRareData {
    short indices[2];
    unsigned bitfields;
    RegionOversetState regionOversetState;
    LayoutSize sizeForResizing;
    IntSize scrollOffset;

// CHANGE BEGINS HERE . Earlier it was :void* pointers[7];
    void* pointers[4];
    std::unique_ptr<DatasetDOMStringMap> pointer2;
    std::unique_ptr<ClassList> pointer3;
    std::unique_ptr<NamedNodeMap> pointer4;
// CHANGE ENDS HERE
};

Making the above change,  works perfectly for us without throwing any compile-time assert at:
static_assert(sizeof(ElementRareData) == sizeof(SameSizeAsElementRareData), "ElementRareData should stay small");

Thanks,
Rupali
Comment 1 Anders Carlsson 2015-10-19 11:00:19 PDT
On which platform is the size of a unique_ptr not the same as the size as a raw pointer?
Comment 2 R. Sharma 2015-10-22 15:27:16 PDT
Hi Anders,

We have our first party platform which uses its own fork of Clang where the sizes are different.