Changeset 65311 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Aug 13, 2010, 3:14:36 AM (15 years ago)
Author:
[email protected]
Message:

Avoid increasing required alignment of target type warning on ARM
https://bugs.webkit.org/show_bug.cgi?id=38045

Reviewed by Gavin Barraclough.

The reinterpret_cast<Type1*>([pointer to Type2]) expressions - where
sizeof(Type1) > sizeof(Type2) - cause the following warning on ARM:
increases required alignment of target type warnings.
Casting the type of [pointer to Type2] object to void* bypasses the
warning.

(JSC::ARMAssembler::executableCopy):

(JSC::AssemblerBuffer::putShortUnchecked):
(JSC::AssemblerBuffer::putIntUnchecked):
(JSC::AssemblerBuffer::putInt64Unchecked):

(JSC::RegisterFile::RegisterFile):
(JSC::RegisterFile::grow):

(jsRegExpCompile):

(JSC::JSArray::putSlowCase):
(JSC::JSArray::increaseVectorLength):
(JSC::JSArray::increaseVectorPrefixLength):
(JSC::JSArray::shiftCount):
(JSC::JSArray::unshiftCount):

(WTF::PageHeapAllocator::New):
(WTF::TCMalloc_Central_FreeList::Populate):

  • wtf/MD5.cpp:

(WTF::reverseBytes):
(WTF::MD5::addBytes):
(WTF::MD5::checksum):

(isPointerTypeAlignmentOkay):
(reinterpret_cast_ptr):

(WTF::VectorBuffer::inlineBuffer):

(WTF::String::String):

Location:
trunk/JavaScriptCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r65305 r65311  
     12010-08-13  Gabor Loki  <[email protected]>
     2
     3        Reviewed by Gavin Barraclough.
     4
     5        Avoid increasing required alignment of target type warning on ARM
     6        https://bugs.webkit.org/show_bug.cgi?id=38045
     7
     8        The reinterpret_cast<Type1*>([pointer to Type2]) expressions - where
     9        sizeof(Type1) > sizeof(Type2) - cause the following warning on ARM:
     10        increases required alignment of target type warnings.
     11        Casting the type of [pointer to Type2] object to void* bypasses the
     12        warning.
     13
     14        * assembler/ARMAssembler.cpp:
     15        (JSC::ARMAssembler::executableCopy):
     16        * assembler/AssemblerBuffer.h:
     17        (JSC::AssemblerBuffer::putShortUnchecked):
     18        (JSC::AssemblerBuffer::putIntUnchecked):
     19        (JSC::AssemblerBuffer::putInt64Unchecked):
     20        * interpreter/RegisterFile.h:
     21        (JSC::RegisterFile::RegisterFile):
     22        (JSC::RegisterFile::grow):
     23        * jit/JITStubs.cpp:
     24        * pcre/pcre_compile.cpp:
     25        (jsRegExpCompile):
     26        * runtime/JSArray.cpp:
     27        (JSC::JSArray::putSlowCase):
     28        (JSC::JSArray::increaseVectorLength):
     29        (JSC::JSArray::increaseVectorPrefixLength):
     30        (JSC::JSArray::shiftCount):
     31        (JSC::JSArray::unshiftCount):
     32        * wtf/FastMalloc.cpp:
     33        (WTF::PageHeapAllocator::New):
     34        (WTF::TCMalloc_Central_FreeList::Populate):
     35        * wtf/MD5.cpp:
     36        (WTF::reverseBytes):
     37        (WTF::MD5::addBytes):
     38        (WTF::MD5::checksum):
     39        * wtf/StdLibExtras.h:
     40        (isPointerTypeAlignmentOkay):
     41        (reinterpret_cast_ptr):
     42        * wtf/Vector.h:
     43        (WTF::VectorBuffer::inlineBuffer):
     44        * wtf/qt/StringQt.cpp:
     45        (WTF::String::String):
     46
    1472010-08-13  Gavin Barraclough  <[email protected]>
    248
  • trunk/JavaScriptCore/assembler/ARMAssembler.cpp

    r64608 r65311  
    358358        // The last bit is set if the constant must be placed on constant pool.
    359359        int pos = (*iter) & (~0x1);
    360         ARMWord* ldrAddr = reinterpret_cast<ARMWord*>(data + pos);
     360        ARMWord* ldrAddr = reinterpret_cast_ptr<ARMWord*>(data + pos);
    361361        ARMWord* addr = getLdrImmAddress(ldrAddr);
    362362        if (*addr != InvalidBranchTarget) {
    363363            if (!(*iter & 1)) {
    364                 int diff = reinterpret_cast<ARMWord*>(data + *addr) - (ldrAddr + DefaultPrefetching);
     364                int diff = reinterpret_cast_ptr<ARMWord*>(data + *addr) - (ldrAddr + DefaultPrefetching);
    365365
    366366                if ((diff <= BOFFSET_MAX && diff >= BOFFSET_MIN)) {
  • trunk/JavaScriptCore/assembler/AssemblerBuffer.h

    r64327 r65311  
    3434#include <wtf/Assertions.h>
    3535#include <wtf/FastMalloc.h>
     36#include <wtf/StdLibExtras.h>
    3637
    3738namespace JSC {
     
    8283        {
    8384            ASSERT(!(m_size > m_capacity - 4));
    84             *reinterpret_cast<short*>(&m_buffer[m_size]) = value;
     85            *reinterpret_cast_ptr<short*>(&m_buffer[m_size]) = value;
    8586            m_size += 2;
    8687        }
     
    9697        {
    9798            ASSERT(!(m_size > m_capacity - 4));
    98             *reinterpret_cast<int*>(&m_buffer[m_size]) = value;
     99            *reinterpret_cast_ptr<int*>(&m_buffer[m_size]) = value;
    99100            m_size += 4;
    100101        }
     
    103104        {
    104105            ASSERT(!(m_size > m_capacity - 8));
    105             *reinterpret_cast<int64_t*>(&m_buffer[m_size]) = value;
     106            *reinterpret_cast_ptr<int64_t*>(&m_buffer[m_size]) = value;
    106107            m_size += 8;
    107108        }
  • trunk/JavaScriptCore/interpreter/RegisterFile.h

    r64782 r65311  
    167167        size_t committedSize = roundUpAllocationSize(maxGlobals * sizeof(Register), commitSize);
    168168        checkAllocatedOkay(m_reservation.commit(base, committedSize));
    169         m_commitEnd = reinterpret_cast<Register*>(reinterpret_cast<char*>(base) + committedSize);
     169        m_commitEnd = reinterpret_cast_ptr<Register*>(reinterpret_cast<char*>(base) + committedSize);
    170170        m_start = static_cast<Register*>(base) + maxGlobals;
    171171        m_end = m_start;
     
    194194            size_t size = roundUpAllocationSize(reinterpret_cast<char*>(newEnd) - reinterpret_cast<char*>(m_commitEnd), commitSize);
    195195            checkAllocatedOkay(m_reservation.commit(m_commitEnd, size));
    196             m_commitEnd = reinterpret_cast<Register*>(reinterpret_cast<char*>(m_commitEnd) + size);
     196            m_commitEnd = reinterpret_cast_ptr<Register*>(reinterpret_cast<char*>(m_commitEnd) + size);
    197197        }
    198198
  • trunk/JavaScriptCore/jit/JITStubs.cpp

    r65104 r65311  
    968968};
    969969
    970 #define STUB_INIT_STACK_FRAME(stackFrame) JITStackFrame& stackFrame = *reinterpret_cast<JITStackFrame*>(STUB_ARGS); StackHack stackHack(stackFrame)
     970#define STUB_INIT_STACK_FRAME(stackFrame) JITStackFrame& stackFrame = *reinterpret_cast_ptr<JITStackFrame*>(STUB_ARGS); StackHack stackHack(stackFrame)
    971971#define STUB_SET_RETURN_ADDRESS(returnAddress) stackHack.savedReturnAddress = ReturnAddressPtr(returnAddress)
    972972#define STUB_RETURN_ADDRESS stackHack.savedReturnAddress
     
    974974#else
    975975
    976 #define STUB_INIT_STACK_FRAME(stackFrame) JITStackFrame& stackFrame = *reinterpret_cast<JITStackFrame*>(STUB_ARGS)
     976#define STUB_INIT_STACK_FRAME(stackFrame) JITStackFrame& stackFrame = *reinterpret_cast_ptr<JITStackFrame*>(STUB_ARGS)
    977977#define STUB_SET_RETURN_ADDRESS(returnAddress) *stackFrame.returnAddressSlot() = ReturnAddressPtr(returnAddress)
    978978#define STUB_RETURN_ADDRESS *stackFrame.returnAddressSlot()
  • trunk/JavaScriptCore/pcre/pcre_compile.cpp

    r64327 r65311  
    5050#include <wtf/FastMalloc.h>
    5151#include <wtf/FixedArray.h>
     52#include <wtf/StdLibExtras.h>
    5253
    5354using namespace WTF;
     
    25912592    size = stringOffset + patternLength * sizeof(UChar);
    25922593#endif
    2593     JSRegExp* re = reinterpret_cast<JSRegExp*>(new char[size]);
     2594    JSRegExp* re = reinterpret_cast_ptr<JSRegExp*>(new char[size]);
    25942595   
    25952596    if (!re)
  • trunk/JavaScriptCore/runtime/JSArray.cpp

    r65305 r65311  
    442442    }
    443443
    444     m_storage = reinterpret_cast<ArrayStorage*>(static_cast<char*>(baseStorage) + m_indexBias * sizeof(JSValue));
     444    m_storage = reinterpret_cast_ptr<ArrayStorage*>(static_cast<char*>(baseStorage) + m_indexBias * sizeof(JSValue));
    445445    m_storage->m_allocBase = baseStorage;
    446446    storage = m_storage;
     
    592592        return false;
    593593
    594     storage = m_storage = reinterpret_cast<ArrayStorage*>(static_cast<char*>(baseStorage) + m_indexBias * sizeof(JSValue));
     594    storage = m_storage = reinterpret_cast_ptr<ArrayStorage*>(static_cast<char*>(baseStorage) + m_indexBias * sizeof(JSValue));
    595595    m_storage->m_allocBase = baseStorage;
    596596
     
    624624    m_indexBias += newVectorLength - newLength;
    625625   
    626     m_storage = reinterpret_cast<ArrayStorage*>(static_cast<char*>(newBaseStorage) + m_indexBias * sizeof(JSValue));
     626    m_storage = reinterpret_cast_ptr<ArrayStorage*>(static_cast<char*>(newBaseStorage) + m_indexBias * sizeof(JSValue));
    627627
    628628    memcpy(m_storage, storage, storageSize(0));
     
    803803            char* newBaseStorage = reinterpret_cast<char*>(storage) + count * sizeof(JSValue);
    804804            memmove(newBaseStorage, storage, storageSize(0));
    805             m_storage = reinterpret_cast<ArrayStorage*>(newBaseStorage);
     805            m_storage = reinterpret_cast_ptr<ArrayStorage*>(newBaseStorage);
    806806
    807807            m_indexBias += count;
     
    840840        char* newBaseStorage = reinterpret_cast<char*>(storage) - count * sizeof(JSValue);
    841841        memmove(newBaseStorage, storage, storageSize(0));
    842         m_storage = reinterpret_cast<ArrayStorage*>(newBaseStorage);
     842        m_storage = reinterpret_cast_ptr<ArrayStorage*>(newBaseStorage);
    843843        m_vectorLength += count;
    844844    } else if (!increaseVectorPrefixLength(m_vectorLength + count)) {
  • trunk/JavaScriptCore/wtf/FastMalloc.cpp

    r65091 r65311  
    8383#include <pthread.h>
    8484#endif
     85#include <wtf/StdLibExtras.h>
    8586
    8687#ifndef NO_TCMALLOC_SAMPLES
     
    10181019          CRASH();
    10191020
    1020         *(void**)new_allocation = allocated_regions_;
     1021        *reinterpret_cast_ptr<void**>(new_allocation) = allocated_regions_;
    10211022        allocated_regions_ = new_allocation;
    10221023        free_area_ = new_allocation + kAlignedSize;
     
    27192720  while ((nptr = ptr + size) <= limit) {
    27202721    *tail = ptr;
    2721     tail = reinterpret_cast<void**>(ptr);
     2722    tail = reinterpret_cast_ptr<void**>(ptr);
    27222723    ptr = nptr;
    27232724    num++;
  • trunk/JavaScriptCore/wtf/MD5.cpp

    r64327 r65311  
    5555#include "text/CString.h"
    5656#endif
     57#include <wtf/StdLibExtras.h>
    5758
    5859namespace WTF {
     
    104105        uint32_t t = static_cast<uint32_t>(buf[3] << 8 | buf[2]) << 16 | buf[1] << 8 | buf[0];
    105106        ASSERT_WITH_MESSAGE(!(reinterpret_cast<uintptr_t>(buf) % sizeof(t)), "alignment error of buf");
    106         *reinterpret_cast<uint32_t *>(buf) = t;
     107        *reinterpret_cast_ptr<uint32_t *>(buf) = t;
    107108        buf += 4;
    108109    } while (--longs);
     
    239240        memcpy(p, buf, t);
    240241        reverseBytes(m_in, 16);
    241         MD5Transform(m_buf, reinterpret_cast<uint32_t*>(m_in)); // m_in is 4-byte aligned.
     242        MD5Transform(m_buf, reinterpret_cast_ptr<uint32_t*>(m_in)); // m_in is 4-byte aligned.
    242243        buf += t;
    243244        length -= t;
     
    249250        memcpy(m_in, buf, 64);
    250251        reverseBytes(m_in, 16);
    251         MD5Transform(m_buf, reinterpret_cast<uint32_t*>(m_in)); // m_in is 4-byte aligned.
     252        MD5Transform(m_buf, reinterpret_cast_ptr<uint32_t*>(m_in)); // m_in is 4-byte aligned.
    252253        buf += 64;
    253254        length -= 64;
     
    276277        memset(p, 0, count);
    277278        reverseBytes(m_in, 16);
    278         MD5Transform(m_buf, reinterpret_cast<uint32_t *>(m_in)); // m_in is 4-byte aligned.
     279        MD5Transform(m_buf, reinterpret_cast_ptr<uint32_t *>(m_in)); // m_in is 4-byte aligned.
    279280
    280281        // Now fill the next block with 56 bytes
     
    288289    // Append length in bits and transform
    289290    // m_in is 4-byte aligned.
    290     (reinterpret_cast<uint32_t*>(m_in))[14] = m_bits[0];
    291     (reinterpret_cast<uint32_t*>(m_in))[15] = m_bits[1];
    292 
    293     MD5Transform(m_buf, reinterpret_cast<uint32_t*>(m_in));
     291    (reinterpret_cast_ptr<uint32_t*>(m_in))[14] = m_bits[0];
     292    (reinterpret_cast_ptr<uint32_t*>(m_in))[15] = m_bits[1];
     293
     294    MD5Transform(m_buf, reinterpret_cast_ptr<uint32_t*>(m_in));
    294295    reverseBytes(reinterpret_cast<uint8_t*>(m_buf), 4);
    295296
  • trunk/JavaScriptCore/wtf/StdLibExtras.h

    r64327 r65311  
    5252#define STRINGIZE_VALUE_OF(exp) STRINGIZE(exp)
    5353
     54/*
     55 * The reinterpret_cast<Type1*>([pointer to Type2]) expressions - where
     56 * sizeof(Type1) > sizeof(Type2) - cause the following warning on ARM with GCC:
     57 * increases required alignment of target type.
     58 *
     59 * An implicit or an extra static_cast<void*> bypasses the warning.
     60 * For more info see the following bugzilla entries:
     61 * - https://bugs.webkit.org/show_bug.cgi?id=38045
     62 * - http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43976
     63 */
     64#if CPU(ARM) && COMPILER(GCC)
     65template<typename Type>
     66bool isPointerTypeAlignmentOkay(Type* ptr)
     67{
     68    return !(reinterpret_cast<intptr_t>(ptr) % __alignof__(Type));
     69}
     70
     71template<typename TypePtr>
     72TypePtr reinterpret_cast_ptr(void* ptr)
     73{
     74    ASSERT(isPointerTypeAlignmentOkay(reinterpret_cast<TypePtr>(ptr)));
     75    return reinterpret_cast<TypePtr>(ptr);
     76}
     77
     78template<typename TypePtr>
     79TypePtr reinterpret_cast_ptr(const void* ptr)
     80{
     81    ASSERT(isPointerTypeAlignmentOkay(reinterpret_cast<TypePtr>(ptr)));
     82    return reinterpret_cast<TypePtr>(ptr);
     83}
     84#else
     85#define reinterpret_cast_ptr reinterpret_cast
     86#endif
     87
    5488namespace WTF {
    5589
  • trunk/JavaScriptCore/wtf/Vector.h

    r64327 r65311  
    2525#include "Noncopyable.h"
    2626#include "NotFound.h"
     27#include "StdLibExtras.h"
    2728#include "ValueCheck.h"
    2829#include "VectorTraits.h"
     
    482483
    483484        static const size_t m_inlineBufferSize = inlineCapacity * sizeof(T);
    484         T* inlineBuffer() { return reinterpret_cast<T*>(m_inlineBuffer.buffer); }
     485        T* inlineBuffer() { return reinterpret_cast_ptr<T*>(m_inlineBuffer.buffer); }
    485486
    486487        AlignedBuffer<m_inlineBufferSize, WTF_ALIGN_OF(T)> m_inlineBuffer;
  • trunk/JavaScriptCore/wtf/qt/StringQt.cpp

    r65022 r65311  
    2626#include "config.h"
    2727
     28#include <wtf/StdLibExtras.h>
    2829#include <wtf/text/WTFString.h>
    2930
     
    3738    if (qstr.isNull())
    3839        return;
    39     m_impl = StringImpl::create(reinterpret_cast<const UChar*>(qstr.constData()), qstr.length());
     40    m_impl = StringImpl::create(reinterpret_cast_ptr<const UChar*>(qstr.constData()), qstr.length());
    4041}
    4142
     
    4445    if (!ref.string())
    4546        return;
    46     m_impl = StringImpl::create(reinterpret_cast<const UChar*>(ref.unicode()), ref.length());
     47    m_impl = StringImpl::create(reinterpret_cast_ptr<const UChar*>(ref.unicode()), ref.length());
    4748}
    4849
Note: See TracChangeset for help on using the changeset viewer.