Changeset 64302 in webkit


Ignore:
Timestamp:
Jul 29, 2010 12:52:22 PM (14 years ago)
Author:
Csaba Osztrogonác
Message:

2010-07-29 Gabor Loki <loki@webkit.org>

Reviewed by Gavin Barraclough.

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

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.

  • assembler/ARMAssembler.cpp: (JSC::ARMAssembler::executableCopy):
  • assembler/AssemblerBuffer.h: (JSC::AssemblerBuffer::putShortUnchecked): (JSC::AssemblerBuffer::putIntUnchecked): (JSC::AssemblerBuffer::putInt64Unchecked):
  • jit/JITStubs.cpp:
  • pcre/pcre_compile.cpp: (jsRegExpCompile):
  • wtf/FastMalloc.cpp: (WTF::PageHeapAllocator::New): (WTF::TCMalloc_Central_FreeList::Populate):
  • wtf/MD5.cpp: (WTF::reverseBytes): (WTF::MD5::addBytes): (WTF::MD5::checksum):
  • wtf/StdLibExtras.h: (reinterpret_cast_ptr):
  • wtf/Vector.h: (WTF::VectorBuffer::inlineBuffer):
  • wtf/qt/StringQt.cpp: (WebCore::String::String):
Location:
trunk/JavaScriptCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r64281 r64302  
     12010-07-29  Gabor Loki  <loki@webkit.org>
     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        * jit/JITStubs.cpp:
     21        * pcre/pcre_compile.cpp:
     22        (jsRegExpCompile):
     23        * wtf/FastMalloc.cpp:
     24        (WTF::PageHeapAllocator::New):
     25        (WTF::TCMalloc_Central_FreeList::Populate):
     26        * wtf/MD5.cpp:
     27        (WTF::reverseBytes):
     28        (WTF::MD5::addBytes):
     29        (WTF::MD5::checksum):
     30        * wtf/StdLibExtras.h:
     31        (reinterpret_cast_ptr):
     32        * wtf/Vector.h:
     33        (WTF::VectorBuffer::inlineBuffer):
     34        * wtf/qt/StringQt.cpp:
     35        (WebCore::String::String):
     36
    1372010-07-29  Martin Robinson  <mrobinson@igalia.com>
    238
  • trunk/JavaScriptCore/assembler/ARMAssembler.cpp

    r63228 r64302  
    356356        // The last bit is set if the constant must be placed on constant pool.
    357357        int pos = (*iter) & (~0x1);
    358         ARMWord* ldrAddr = reinterpret_cast<ARMWord*>(data + pos);
     358        ARMWord* ldrAddr = reinterpret_cast_ptr<ARMWord*>(data + pos);
    359359        ARMWord* addr = getLdrImmAddress(ldrAddr);
    360360        if (*addr != InvalidBranchTarget) {
    361361            if (!(*iter & 1)) {
    362                 int diff = reinterpret_cast<ARMWord*>(data + *addr) - (ldrAddr + DefaultPrefetching);
     362                int diff = reinterpret_cast_ptr<ARMWord*>(data + *addr) - (ldrAddr + DefaultPrefetching);
    363363
    364364                if ((diff <= BOFFSET_MAX && diff >= BOFFSET_MIN)) {
  • trunk/JavaScriptCore/assembler/AssemblerBuffer.h

    r61851 r64302  
    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/jit/JITStubs.cpp

    r63954 r64302  
    987987};
    988988
    989 #define STUB_INIT_STACK_FRAME(stackFrame) JITStackFrame& stackFrame = *reinterpret_cast<JITStackFrame*>(STUB_ARGS); StackHack stackHack(stackFrame)
     989#define STUB_INIT_STACK_FRAME(stackFrame) JITStackFrame& stackFrame = *reinterpret_cast_ptr<JITStackFrame*>(STUB_ARGS); StackHack stackHack(stackFrame)
    990990#define STUB_SET_RETURN_ADDRESS(returnAddress) stackHack.savedReturnAddress = ReturnAddressPtr(returnAddress)
    991991#define STUB_RETURN_ADDRESS stackHack.savedReturnAddress
     
    993993#else
    994994
    995 #define STUB_INIT_STACK_FRAME(stackFrame) JITStackFrame& stackFrame = *reinterpret_cast<JITStackFrame*>(STUB_ARGS)
     995#define STUB_INIT_STACK_FRAME(stackFrame) JITStackFrame& stackFrame = *reinterpret_cast_ptr<JITStackFrame*>(STUB_ARGS)
    996996#define STUB_SET_RETURN_ADDRESS(returnAddress) *stackFrame.returnAddressSlot() = ReturnAddressPtr(returnAddress)
    997997#define STUB_RETURN_ADDRESS *stackFrame.returnAddressSlot()
  • trunk/JavaScriptCore/pcre/pcre_compile.cpp

    r62367 r64302  
    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/wtf/FastMalloc.cpp

    r62768 r64302  
    8383#include <pthread.h>
    8484#endif
     85#include <wtf/StdLibExtras.h>
    8586
    8687#ifndef NO_TCMALLOC_SAMPLES
     
    10161017          CRASH();
    10171018
    1018         *(void**)new_allocation = allocated_regions_;
     1019        *reinterpret_cast_ptr<void**>(new_allocation) = allocated_regions_;
    10191020        allocated_regions_ = new_allocation;
    10201021        free_area_ = new_allocation + kAlignedSize;
     
    27112712  while ((nptr = ptr + size) <= limit) {
    27122713    *tail = ptr;
    2713     tail = reinterpret_cast<void**>(ptr);
     2714    tail = reinterpret_cast_ptr<void**>(ptr);
    27142715    ptr = nptr;
    27152716    num++;
  • trunk/JavaScriptCore/wtf/MD5.cpp

    r59067 r64302  
    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

    r56085 r64302  
    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 T>
     66T reinterpret_cast_ptr(void* ptr)
     67{
     68    ASSERT(!(reinterpret_cast<unsigned int>(ptr) % __alignof__(T)));
     69    return reinterpret_cast<T>(ptr);
     70}
     71template<typename T>
     72T reinterpret_cast_ptr(const void* ptr)
     73{
     74    ASSERT(!(reinterpret_cast<unsigned int>(ptr) % __alignof__(T)));
     75    return reinterpret_cast<T>(ptr);
     76}
     77#else
     78#define reinterpret_cast_ptr reinterpret_cast
     79#endif
     80
    5481namespace WTF {
    5582
  • trunk/JavaScriptCore/wtf/Vector.h

    r62697 r64302  
    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

    r58006 r64302  
    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.