⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 293265 in webkit


Ignore:
Timestamp:
Apr 22, 2022, 4:21:38 PM (4 years ago)
Author:
dbezhetskov
Message:

[Refactoring] Reduce number of const and reinterpret casts
https://bugs.webkit.org/show_bug.cgi?id=239648

Reviewed by Yusuke Suzuki.

The statement
"reinterpret_cast<TypeDefinition*>(const_cast<char*>(functionType.m_payload)

  • sizeof(TypeDefinition))"

is dangerous and it produces warning on some platfroms.
There is way to avoid it and this patch is doint that.

  • wasm/WasmSlowPaths.cpp:

(JSC::LLInt::doWasmCallIndirect):
(JSC::LLInt::doWasmCallRef):

  • wasm/WasmTypeDefinition.h:

(JSC::Wasm::FunctionSignature::operator== const):

  • wasm/WasmTypeDefinitionInlines.h:
Location:
trunk/Source/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r293252 r293265  
     12022-04-22  Dmitry Bezhetskov  <dbezhetskov@igalia.com>
     2
     3        [Refactoring] Reduce number of const and reinterpret casts
     4        https://bugs.webkit.org/show_bug.cgi?id=239648
     5
     6        Reviewed by Yusuke Suzuki.
     7       
     8        The statement
     9        "reinterpret_cast<TypeDefinition*>(const_cast<char*>(functionType.m_payload)
     10        - sizeof(TypeDefinition))"
     11        is dangerous and it produces warning on some platfroms.
     12        There is way to avoid it and this patch is doint that.
     13
     14        * wasm/WasmSlowPaths.cpp:
     15        (JSC::LLInt::doWasmCallIndirect):
     16        (JSC::LLInt::doWasmCallRef):
     17        * wasm/WasmTypeDefinition.h:
     18        (JSC::Wasm::FunctionSignature::operator== const):
     19        * wasm/WasmTypeDefinitionInlines.h:
     20
    1212022-04-22  Geza Lore  <glore@igalia.com>
    222
  • trunk/Source/JavaScriptCore/wasm/WasmSlowPaths.cpp

    r292929 r293265  
    501501
    502502    const auto& callSignature = CALLEE()->signature(typeIndex);
    503     if (function.typeIndex != Wasm::TypeInformation::get(callSignature))
     503    if (callSignature != Wasm::TypeInformation::getFunctionSignature(function.typeIndex))
    504504        WASM_THROW(Wasm::ExceptionType::BadSignature);
    505505
     
    542542        calleeInstance->setCachedStackLimit(callerInstance->cachedStackLimit());
    543543
    544     ASSERT(function.typeIndex == Wasm::TypeInformation::get(CALLEE()->signature(typeIndex)));
     544    ASSERT(Wasm::TypeInformation::getFunctionSignature(function.typeIndex) == CALLEE()->signature(typeIndex));
    545545    UNUSED_PARAM(typeIndex);
    546546    WASM_CALL_RETURN(calleeInstance, function.entrypointLoadLocation->executableAddress(), WasmEntryPtrTag);
  • trunk/Source/JavaScriptCore/wasm/WasmTypeDefinition.h

    r292773 r293265  
    6161    Type argumentType(FunctionArgCount i) const { return const_cast<FunctionSignature*>(this)->getArgumentType(i); }
    6262
     63    bool operator==(const FunctionSignature& other) const
     64    {
     65        // Function signatures are unique because it is just an view class over TypeDefinition and
     66        // so, we can compare two signatures with just payload pointers comparision.
     67        // Other checks probably aren't necessary but it's good to be paranoid.
     68        return m_payload == other.m_payload && m_argCount == other.m_argCount && m_retCount == other.m_retCount;
     69    }
     70
    6371    WTF::String toString() const;
    6472    void dump(WTF::PrintStream& out) const;
     
    218226    static TypeIndex get(const TypeDefinition&);
    219227
    220     static TypeIndex get(const FunctionSignature&);
    221228    static const FunctionSignature& getFunctionSignature(TypeIndex);
    222229
  • trunk/Source/JavaScriptCore/wasm/WasmTypeDefinitionInlines.h

    r292773 r293265  
    6565}
    6666
    67 inline TypeIndex TypeInformation::get(const FunctionSignature& functionType)
    68 {
    69     return get(*reinterpret_cast<TypeDefinition*>(const_cast<char*>(functionType.m_payload) - sizeof(TypeDefinition)));
    70 }
    71 
    7267} } // namespace JSC::Wasm
    7368
Note: See TracChangeset for help on using the changeset viewer.