Changeset 237063 in webkit


Ignore:
Timestamp:
Oct 11, 2018 7:51:45 PM (6 years ago)
Author:
guijemont@igalia.com
Message:

[JSC] Remove gcc warnings on mips and armv7
https://bugs.webkit.org/show_bug.cgi?id=188598

Reviewed by Mark Lam.

Source/bmalloc:

Add bitwise_cast (from WTF) and use it instead of reinterpret_cast in
a couple places where reinterpret_cast triggers a warning about
alignment even though we know that alignment is correct.

  • bmalloc/Algorithm.h:

(bmalloc::bitwise_cast): Copied from WTF/wtf/StdLibextras.h

  • bmalloc/IsoDirectoryPageInlines.h:

(bmalloc::IsoDirectoryPage<Config>::pageFor):

  • bmalloc/IsoPageInlines.h:

(bmalloc::IsoPage<Config>::startAllocating):

Source/JavaScriptCore:

Fix many gcc/clang warnings that are false positives, mostly alignment
issues.

  • assembler/MacroAssemblerPrinter.cpp:

(JSC::Printer::printMemory):
Use bitwise_cast instead of reinterpret_cast.

  • assembler/testmasm.cpp:

(JSC::floatOperands):
marked as potentially unused as it is not used on all platforms.
(JSC::testProbeModifiesStackValues):
modifiedFlags is not used on mips, so don't declare it.

  • bytecode/CodeBlock.h:

Make ScriptExecutable::prepareForExecution() return an
std::optional<Exception*> instead of a JSObject*.

  • interpreter/Interpreter.cpp:

(JSC::Interpreter::executeProgram):
(JSC::Interpreter::executeCall):
(JSC::Interpreter::executeConstruct):
(JSC::Interpreter::prepareForRepeatCall):
(JSC::Interpreter::execute):
(JSC::Interpreter::executeModuleProgram):
Update calling code for the prototype change of
ScriptExecutable::prepareForExecution().

  • jit/JITOperations.cpp: Same as for Interpreter.cpp.
  • llint/LLIntSlowPaths.cpp:

(JSC::LLInt::setUpCall): Same as for Interpreter.cpp.

  • runtime/JSBigInt.cpp:

(JSC::JSBigInt::dataStorage):
Use bitwise_cast instead of reinterpret_cast.

  • runtime/ScriptExecutable.cpp:
  • runtime/ScriptExecutable.h:

Make ScriptExecutable::prepareForExecution() return an
std::optional<Exception*> instead of a JSObject*.

  • tools/JSDollarVM.cpp:

(JSC::codeBlockFromArg): Use bitwise_cast instead of reinterpret_cast.

Location:
trunk/Source
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r237059 r237063  
     12018-10-11  Guillaume Emont  <guijemont@igalia.com>
     2
     3        [JSC] Remove gcc warnings on mips and armv7
     4        https://bugs.webkit.org/show_bug.cgi?id=188598
     5
     6        Reviewed by Mark Lam.
     7
     8        Fix many gcc/clang warnings that are false positives, mostly alignment
     9        issues.
     10
     11        * assembler/MacroAssemblerPrinter.cpp:
     12        (JSC::Printer::printMemory):
     13        Use bitwise_cast instead of reinterpret_cast.
     14        * assembler/testmasm.cpp:
     15        (JSC::floatOperands):
     16        marked as potentially unused as it is not used on all platforms.
     17        (JSC::testProbeModifiesStackValues):
     18        modifiedFlags is not used on mips, so don't declare it.
     19        * bytecode/CodeBlock.h:
     20        Make ScriptExecutable::prepareForExecution() return an
     21        std::optional<Exception*> instead of a JSObject*.
     22        * interpreter/Interpreter.cpp:
     23        (JSC::Interpreter::executeProgram):
     24        (JSC::Interpreter::executeCall):
     25        (JSC::Interpreter::executeConstruct):
     26        (JSC::Interpreter::prepareForRepeatCall):
     27        (JSC::Interpreter::execute):
     28        (JSC::Interpreter::executeModuleProgram):
     29        Update calling code for the prototype change of
     30        ScriptExecutable::prepareForExecution().
     31        * jit/JITOperations.cpp: Same as for Interpreter.cpp.
     32        * llint/LLIntSlowPaths.cpp:
     33        (JSC::LLInt::setUpCall): Same as for Interpreter.cpp.
     34        * runtime/JSBigInt.cpp:
     35        (JSC::JSBigInt::dataStorage):
     36        Use bitwise_cast instead of reinterpret_cast.
     37        * runtime/ScriptExecutable.cpp:
     38        * runtime/ScriptExecutable.h:
     39        Make ScriptExecutable::prepareForExecution() return an
     40        std::optional<Exception*> instead of a JSObject*.
     41        * tools/JSDollarVM.cpp:
     42        (JSC::codeBlockFromArg): Use bitwise_cast instead of reinterpret_cast.
     43
    1442018-10-11  Yusuke Suzuki  <yusukesuzuki@slowstart.org>
    245
  • trunk/Source/JavaScriptCore/assembler/MacroAssemblerPrinter.cpp

    r236805 r237063  
    132132    }
    133133
     134    // assuming memory is not malformed, it originally pointed to a value
     135    // of the size with which we use it below, so the bitwise_casts should
     136    // be safe, including regarding alignment.
    134137    if (memory.dumpStyle == Memory::SingleWordDump) {
    135138        if (memory.numBytes == sizeof(int8_t)) {
     
    139142        }
    140143        if (memory.numBytes == sizeof(int16_t)) {
    141             auto p = reinterpret_cast<int16_t*>(ptr);
     144            auto p = bitwise_cast<int16_t*>(ptr);
    142145            out.printf("%p:<0x%04x %d>", p, *p, *p);
    143146            return;
    144147        }
    145148        if (memory.numBytes == sizeof(int32_t)) {
    146             auto p = reinterpret_cast<int32_t*>(ptr);
     149            auto p = bitwise_cast<int32_t*>(ptr);
    147150            out.printf("%p:<0x%08x %d>", p, *p, *p);
    148151            return;
    149152        }
    150153        if (memory.numBytes == sizeof(int64_t)) {
    151             auto p = reinterpret_cast<int64_t*>(ptr);
     154            auto p = bitwise_cast<int64_t*>(ptr);
    152155            out.printf("%p:<0x%016" PRIx64 " %" PRId64 ">", p, *p, *p);
    153156            return;
  • trunk/Source/JavaScriptCore/assembler/testmasm.cpp

    r235106 r237063  
    247247
    248248
    249 static Vector<float> floatOperands()
     249static Vector<float> UNUSED_FUNCTION floatOperands()
    250250{
    251251    return Vector<float> {
     
    748748    void* originalSP { nullptr };
    749749    void* newSP { nullptr };
     750#if !(CPU(MIPS))
    750751    uintptr_t modifiedFlags { 0 };
     752#endif
    751753    size_t numberOfExtraEntriesToWrite { 10 }; // ARM64 requires that this be 2 word aligned.
    752754
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.h

    r236430 r237063  
    10491049
    10501050template <typename ExecutableType>
    1051 JSObject* ScriptExecutable::prepareForExecution(VM& vm, JSFunction* function, JSScope* scope, CodeSpecializationKind kind, CodeBlock*& resultCodeBlock)
     1051std::optional<Exception*> ScriptExecutable::prepareForExecution(VM& vm, JSFunction* function, JSScope* scope, CodeSpecializationKind kind, CodeBlock*& resultCodeBlock)
    10521052{
    10531053    if (hasJITCodeFor(kind)) {
     
    10621062        else
    10631063            RELEASE_ASSERT_NOT_REACHED();
    1064         return nullptr;
     1064        return std::nullopt;
    10651065    }
    10661066    return prepareForExecutionImpl(vm, function, scope, kind, resultCodeBlock);
  • trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp

    r236697 r237063  
    807807    {
    808808        CodeBlock* tempCodeBlock;
    809         JSObject* error = program->prepareForExecution<ProgramExecutable>(vm, nullptr, scope, CodeForCall, tempCodeBlock);
    810         EXCEPTION_ASSERT(throwScope.exception() == reinterpret_cast<Exception*>(error));
     809        std::optional<Exception*> error = program->prepareForExecution<ProgramExecutable>(vm, nullptr, scope, CodeForCall, tempCodeBlock);
     810        EXCEPTION_ASSERT(throwScope.exception() == error.value_or(nullptr));
     811
    811812        if (UNLIKELY(error))
    812             return checkedReturn(error);
     813            return checkedReturn(*error);
    813814        codeBlock = jsCast<ProgramCodeBlock*>(tempCodeBlock);
    814815    }
     
    865866    if (isJSCall) {
    866867        // Compile the callee:
    867         JSObject* compileError = callData.js.functionExecutable->prepareForExecution<FunctionExecutable>(vm, jsCast<JSFunction*>(function), scope, CodeForCall, newCodeBlock);
    868         EXCEPTION_ASSERT(throwScope.exception() == reinterpret_cast<Exception*>(compileError));
     868        std::optional<Exception*> compileError = callData.js.functionExecutable->prepareForExecution<FunctionExecutable>(vm, jsCast<JSFunction*>(function), scope, CodeForCall, newCodeBlock);
     869        EXCEPTION_ASSERT(throwScope.exception() == compileError.value_or(nullptr));
    869870        if (UNLIKELY(!!compileError))
    870             return checkedReturn(compileError);
     871            return checkedReturn(*compileError);
    871872
    872873        ASSERT(!!newCodeBlock);
     
    932933    if (isJSConstruct) {
    933934        // Compile the callee:
    934         JSObject* compileError = constructData.js.functionExecutable->prepareForExecution<FunctionExecutable>(vm, jsCast<JSFunction*>(constructor), scope, CodeForConstruct, newCodeBlock);
    935         EXCEPTION_ASSERT(throwScope.exception() == reinterpret_cast<Exception*>(compileError));
     935        std::optional<Exception*> compileError = constructData.js.functionExecutable->prepareForExecution<FunctionExecutable>(vm, jsCast<JSFunction*>(constructor), scope, CodeForConstruct, newCodeBlock);
     936        EXCEPTION_ASSERT(throwScope.exception() == compileError.value_or(nullptr));
    936937        if (UNLIKELY(!!compileError))
    937             return checkedReturn(compileError);
     938            return checkedReturn(*compileError);
    938939
    939940        ASSERT(!!newCodeBlock);
     
    980981    // Compile the callee:
    981982    CodeBlock* newCodeBlock;
    982     JSObject* error = functionExecutable->prepareForExecution<FunctionExecutable>(vm, function, scope, CodeForCall, newCodeBlock);
    983     EXCEPTION_ASSERT(throwScope.exception() == reinterpret_cast<Exception*>(error));
     983    std::optional<Exception*> error = functionExecutable->prepareForExecution<FunctionExecutable>(vm, function, scope, CodeForCall, newCodeBlock);
     984    EXCEPTION_ASSERT(throwScope.exception() == error.value_or(nullptr));
    984985    if (UNLIKELY(error))
    985986        return CallFrameClosure();
     
    10381039    {
    10391040        CodeBlock* tempCodeBlock;
    1040         JSObject* compileError = eval->prepareForExecution<EvalExecutable>(vm, nullptr, scope, CodeForCall, tempCodeBlock);
    1041         EXCEPTION_ASSERT(throwScope.exception() == reinterpret_cast<Exception*>(compileError));
     1041        std::optional<Exception*> compileError = eval->prepareForExecution<EvalExecutable>(vm, nullptr, scope, CodeForCall, tempCodeBlock);
     1042        EXCEPTION_ASSERT(throwScope.exception() == compileError.value_or(nullptr));
    10421043        if (UNLIKELY(!!compileError))
    1043             return checkedReturn(compileError);
     1044            return checkedReturn(*compileError);
    10441045        codeBlock = jsCast<EvalCodeBlock*>(tempCodeBlock);
    10451046    }
     
    11611162    {
    11621163        CodeBlock* tempCodeBlock;
    1163         JSObject* compileError = executable->prepareForExecution<ModuleProgramExecutable>(vm, nullptr, scope, CodeForCall, tempCodeBlock);
    1164         EXCEPTION_ASSERT(throwScope.exception() == reinterpret_cast<Exception*>(compileError));
     1164        std::optional<Exception*> compileError = executable->prepareForExecution<ModuleProgramExecutable>(vm, nullptr, scope, CodeForCall, tempCodeBlock);
     1165        EXCEPTION_ASSERT(throwScope.exception() == compileError.value_or(nullptr));
    11651166        if (UNLIKELY(!!compileError))
    1166             return checkedReturn(compileError);
     1167            return checkedReturn(*compileError);
    11671168        codeBlock = jsCast<ModuleProgramCodeBlock*>(tempCodeBlock);
    11681169    }
  • trunk/Source/JavaScriptCore/jit/JITOperations.cpp

    r236697 r237063  
    10411041
    10421042        CodeBlock** codeBlockSlot = execCallee->addressOfCodeBlock();
    1043         JSObject* error = functionExecutable->prepareForExecution<FunctionExecutable>(*vm, callee, scope, kind, *codeBlockSlot);
    1044         EXCEPTION_ASSERT(throwScope.exception() == reinterpret_cast<Exception*>(error));
     1043        std::optional<Exception*> error = functionExecutable->prepareForExecution<FunctionExecutable>(*vm, callee, scope, kind, *codeBlockSlot);
     1044        EXCEPTION_ASSERT(throwScope.exception() == error.value_or(nullptr));
    10451045        if (error)
    10461046            return handleThrowException();
     
    10971097        RELEASE_ASSERT(isCall(kind) || functionExecutable->constructAbility() != ConstructAbility::CannotConstruct);
    10981098       
    1099         JSObject* error = functionExecutable->prepareForExecution<FunctionExecutable>(*vm, callee, scope, kind, codeBlock);
    1100         EXCEPTION_ASSERT_UNUSED(throwScope, throwScope.exception() == reinterpret_cast<Exception*>(error));
     1099        std::optional<Exception*> error = functionExecutable->prepareForExecution<FunctionExecutable>(*vm, callee, scope, kind, codeBlock);
     1100        EXCEPTION_ASSERT_UNUSED(throwScope, throwScope.exception() == error.value_or(nullptr));
    11011101        if (error)
    11021102            return;
     
    11461146
    11471147        CodeBlock** codeBlockSlot = execCallee->addressOfCodeBlock();
    1148         JSObject* error = functionExecutable->prepareForExecution<FunctionExecutable>(*vm, function, scope, kind, *codeBlockSlot);
    1149         EXCEPTION_ASSERT(throwScope.exception() == reinterpret_cast<Exception*>(error));
     1148        std::optional<Exception*> error = functionExecutable->prepareForExecution<FunctionExecutable>(*vm, function, scope, kind, *codeBlockSlot);
     1149        EXCEPTION_ASSERT(throwScope.exception() == error.value_or(nullptr));
    11501150        if (error) {
    11511151            return encodeResult(
  • trunk/Source/JavaScriptCore/llint/LLIntSlowPaths.cpp

    r236697 r237063  
    14851485
    14861486        CodeBlock** codeBlockSlot = execCallee->addressOfCodeBlock();
    1487         JSObject* error = functionExecutable->prepareForExecution<FunctionExecutable>(vm, callee, scope, kind, *codeBlockSlot);
    1488         EXCEPTION_ASSERT(throwScope.exception() == error);
     1487        std::optional<Exception*> error = functionExecutable->prepareForExecution<FunctionExecutable>(vm, callee, scope, kind, *codeBlockSlot);
     1488        EXCEPTION_ASSERT(throwScope.exception() == error.value_or(nullptr));
    14891489        if (UNLIKELY(error))
    1490             LLINT_CALL_THROW(exec, error);
     1490            LLINT_CALL_THROW(exec, *error);
    14911491        codeBlock = *codeBlockSlot;
    14921492        ASSERT(codeBlock);
  • trunk/Source/JavaScriptCore/runtime/JSBigInt.cpp

    r236901 r237063  
    15511551inline JSBigInt::Digit* JSBigInt::dataStorage()
    15521552{
    1553     return reinterpret_cast<Digit*>(reinterpret_cast<char*>(this) + offsetOfData());
     1553    // offsetOfData() makes sure that its return value is aligned to the size
     1554    // of Digit, so even though we cast to char* for pointer arithmetics, the
     1555    // bitwise_cast to Digit* is correct and properly aligned.
     1556    return bitwise_cast<Digit*>(reinterpret_cast<char*>(this) + offsetOfData());
    15541557}
    15551558
  • trunk/Source/JavaScriptCore/runtime/ScriptExecutable.cpp

    r236697 r237063  
    3030#include "Debugger.h"
    3131#include "EvalCodeBlock.h"
     32#include "Exception.h"
    3233#include "FunctionCodeBlock.h"
    3334#include "IsoCellSetInlines.h"
     
    338339}
    339340
    340 JSObject* ScriptExecutable::prepareForExecutionImpl(
     341std::optional<Exception*> ScriptExecutable::prepareForExecutionImpl(
    341342    VM& vm, JSFunction* function, JSScope* scope, CodeSpecializationKind kind, CodeBlock*& resultCodeBlock)
    342343{
     
    346347    if (vm.getAndClearFailNextNewCodeBlock()) {
    347348        auto& state = *scope->globalObject(vm)->globalExec();
    348         return throwException(&state, throwScope, createError(&state, "Forced Failure"_s));
     349        return static_cast<Exception*>(throwException(&state, throwScope, createError(&state, "Forced Failure"_s)));
    349350    }
    350351
     
    354355    EXCEPTION_ASSERT(!!throwScope.exception() == !codeBlock);
    355356    if (UNLIKELY(!codeBlock))
    356         return exception;
     357        return static_cast<Exception*>(exception);
    357358   
    358359    if (Options::validateBytecode())
     
    365366   
    366367    installCode(vm, codeBlock, codeBlock->codeType(), codeBlock->specializationKind());
    367     return nullptr;
     368    return std::nullopt;
    368369}
    369370
  • trunk/Source/JavaScriptCore/runtime/ScriptExecutable.h

    r233039 r237063  
    106106    // by conservative GC if a GC happens after we create the CodeBlock.
    107107    template <typename ExecutableType>
    108     JSObject* prepareForExecution(VM&, JSFunction*, JSScope*, CodeSpecializationKind, CodeBlock*& resultCodeBlock);
     108    std::optional<Exception*> prepareForExecution(VM&, JSFunction*, JSScope*, CodeSpecializationKind, CodeBlock*& resultCodeBlock);
    109109
    110110private:
    111111    friend class ExecutableBase;
    112     JSObject* prepareForExecutionImpl(VM&, JSFunction*, JSScope*, CodeSpecializationKind, CodeBlock*&);
     112    std::optional<Exception*> prepareForExecutionImpl(VM&, JSFunction*, JSScope*, CodeSpecializationKind, CodeBlock*&);
    113113
    114114protected:
  • trunk/Source/JavaScriptCore/tools/JSDollarVM.cpp

    r236697 r237063  
    14631463                candidateCodeBlock = func->jsExecutable()->eitherCodeBlock();
    14641464        } else
    1465             candidateCodeBlock = reinterpret_cast<CodeBlock*>(value.asCell());
     1465            candidateCodeBlock = static_cast<CodeBlock*>(value.asCell());
    14661466    }
    14671467
  • trunk/Source/bmalloc/ChangeLog

    r236805 r237063  
     12018-10-11  Guillaume Emont  <guijemont@igalia.com>
     2
     3        [JSC] Remove gcc warnings on mips and armv7
     4        https://bugs.webkit.org/show_bug.cgi?id=188598
     5
     6        Reviewed by Mark Lam.
     7
     8        Add bitwise_cast (from WTF) and use it instead of reinterpret_cast in
     9        a couple places where reinterpret_cast triggers a warning about
     10        alignment even though we know that alignment is correct.
     11
     12        * bmalloc/Algorithm.h:
     13        (bmalloc::bitwise_cast): Copied from WTF/wtf/StdLibextras.h
     14        * bmalloc/IsoDirectoryPageInlines.h:
     15        (bmalloc::IsoDirectoryPage<Config>::pageFor):
     16        * bmalloc/IsoPageInlines.h:
     17        (bmalloc::IsoPage<Config>::startAllocating):
     18
    1192018-10-03  Dan Bernstein  <mitz@apple.com>
    220
  • trunk/Source/bmalloc/bmalloc/Algorithm.h

    r229504 r237063  
    3131#include <cstdint>
    3232#include <cstddef>
     33#include <cstring>
    3334#include <limits>
    3435#include <string.h>
     
    182183}
    183184
     185// Copied from WTF/wtf/StdLibExtras.h
     186template<typename ToType, typename FromType>
     187inline ToType bitwise_cast(FromType from)
     188{
     189    static_assert(sizeof(FromType) == sizeof(ToType), "bitwise_cast size of FromType and ToType must be equal!");
     190#if defined(__has_feature)
     191#if __has_feature(is_trivially_copyable)
     192    // Not all recent STL implementations support the std::is_trivially_copyable type trait. Work around this by only checking on toolchains which have the equivalent compiler intrinsic.
     193    static_assert(__is_trivially_copyable(ToType), "bitwise_cast of non-trivially-copyable type!");
     194    static_assert(__is_trivially_copyable(FromType), "bitwise_cast of non-trivially-copyable type!");
     195#endif
     196#endif
     197    typename std::remove_const<ToType>::type to { };
     198    std::memcpy(static_cast<void*>(&to), static_cast<void*>(&from), sizeof(to));
     199    return to;
     200}
     201
    184202} // namespace bmalloc
    185203
  • trunk/Source/bmalloc/bmalloc/IsoDirectoryPageInlines.h

    r224537 r237063  
    4040IsoDirectoryPage<Config>* IsoDirectoryPage<Config>::pageFor(IsoDirectory<Config, numPages>* payload)
    4141{
    42     return reinterpret_cast<IsoDirectoryPage<Config>*>(
     42    // the char* cast is only used to do a pointer calculation, and said
     43    // calculation results in a pointer to an existing, correctly aligned
     44    // IsoDirectoryPage.
     45    return bitwise_cast<IsoDirectoryPage<Config>*>(
    4346        reinterpret_cast<char*>(payload) - BOFFSETOF(IsoDirectoryPage, payload));
    4447}
  • trunk/Source/bmalloc/bmalloc/IsoPageInlines.h

    r228576 r237063  
    189189        if (verbose)
    190190            fprintf(stderr, "%p: putting %p on free list.\n", this, cellByte);
    191         FreeCell* cell = reinterpret_cast<FreeCell*>(cellByte);
     191
     192        static_assert(!(Config::objectSize % alignof(FreeCell)), "Config::objectSize should respect alignment of FreeCell");
     193        static_assert(!(alignof(IsoPage<Config>) % alignof(FreeCell)), "Alignment of IsoPage<Config> should match that of FreeCell");
     194        FreeCell* cell = bitwise_cast<FreeCell*>(cellByte);
    192195        cell->setNext(head, secret);
    193196        head = cell;
Note: See TracChangeset for help on using the changeset viewer.