Bug 239698

Summary: [WASM] Fix warning: cast from ‘char*’ to ‘JSC::Wasm::Type*’ increases required alignment of target type [-Wcast-align]
Product: WebKit Reporter: Dmitry <dbezhetskov>
Component: WebAssemblyAssignee: Dmitry <dbezhetskov>
Status: RESOLVED FIXED    
Severity: Normal CC: darin, ews-watchlist, keith_miller, mark.lam, msaboff, saam, tzagallo, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch none

Description Dmitry 2022-04-23 22:14:17 PDT
[WASM] Fix warning: cast from ‘char*’ to ‘JSC::Wasm::Type*’ increases required alignment of target type [-Wcast-align]
Comment 1 Dmitry 2022-04-23 22:15:56 PDT
Created attachment 458227 [details]
Patch
Comment 2 Yusuke Suzuki 2022-04-24 23:16:46 PDT
Comment on attachment 458227 [details]
Patch

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

Commented.

> Source/JavaScriptCore/wasm/WasmTypeDefinition.h:83
> +    void* const m_payload;

I wonder if we should just change it to `Type*`.

> Source/JavaScriptCore/wasm/WasmTypeDefinition.h:121
> +    void* const m_payload;

How about changing it to `StructField*`?
Comment 3 Dmitry 2022-04-25 06:45:30 PDT
Created attachment 458266 [details]
Patch
Comment 4 Darin Adler 2022-04-25 09:41:17 PDT
Comment on attachment 458266 [details]
Patch

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

> Source/JavaScriptCore/wasm/WasmTypeDefinition.h:132
> +        : m_typeHeader { FunctionSignature { reinterpret_cast<Type*>(payload()), argCount, retCount } }

Casting from void* can and should be done with static_cast instead of reinterpret_cast.

> Source/JavaScriptCore/wasm/WasmTypeDefinition.h:137
> +        : m_typeHeader { StructType { reinterpret_cast<StructField*>(payload()), fieldCount } }

Ditto.

> Source/JavaScriptCore/wasm/WasmTypeDefinition.h:142
> +    void* payload() { return reinterpret_cast<void*>(this + 1); }

This should not need a type cast. TypeDefinition* can be converted to void* without one
Comment 5 Dmitry 2022-04-25 22:00:41 PDT
Created attachment 458328 [details]
Patch
Comment 6 EWS 2022-04-26 19:01:16 PDT
Committed r293492 (250025@main): <https://commits.webkit.org/250025@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 458328 [details].
Comment 7 Radar WebKit Bug Importer 2022-04-26 19:02:15 PDT
<rdar://problem/92372097>