Commit 7534a3fa authored by loki@webkit.org's avatar loki@webkit.org

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.

* JavaScriptCore/assembler/ARMAssembler.cpp:
(JSC::ARMAssembler::executableCopy):
* JavaScriptCore/assembler/AssemblerBuffer.h:
(JSC::AssemblerBuffer::putShortUnchecked):
(JSC::AssemblerBuffer::putIntUnchecked):
(JSC::AssemblerBuffer::putInt64Unchecked):
* JavaScriptCore/interpreter/RegisterFile.h:
(JSC::RegisterFile::RegisterFile):
(JSC::RegisterFile::grow):
* JavaScriptCore/jit/JITStubs.cpp:
* JavaScriptCore/pcre/pcre_compile.cpp:
(jsRegExpCompile):
* JavaScriptCore/runtime/JSArray.cpp:
(JSC::JSArray::putSlowCase):
(JSC::JSArray::increaseVectorLength):
(JSC::JSArray::increaseVectorPrefixLength):
(JSC::JSArray::shiftCount):
(JSC::JSArray::unshiftCount):
* JavaScriptCore/wtf/FastMalloc.cpp:
(WTF::PageHeapAllocator::New):
(WTF::TCMalloc_Central_FreeList::Populate):
* wtf/MD5.cpp:
(WTF::reverseBytes):
(WTF::MD5::addBytes):
(WTF::MD5::checksum):
* JavaScriptCore/wtf/StdLibExtras.h:
(isPointerTypeAlignmentOkay):
(reinterpret_cast_ptr):
* JavaScriptCore/wtf/Vector.h:
(WTF::VectorBuffer::inlineBuffer):
* JavaScriptCore/wtf/qt/StringQt.cpp:
(WTF::String::String):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@65311 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent cff3134e
2010-08-13 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):
* interpreter/RegisterFile.h:
(JSC::RegisterFile::RegisterFile):
(JSC::RegisterFile::grow):
* jit/JITStubs.cpp:
* pcre/pcre_compile.cpp:
(jsRegExpCompile):
* runtime/JSArray.cpp:
(JSC::JSArray::putSlowCase):
(JSC::JSArray::increaseVectorLength):
(JSC::JSArray::increaseVectorPrefixLength):
(JSC::JSArray::shiftCount):
(JSC::JSArray::unshiftCount):
* 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:
(isPointerTypeAlignmentOkay):
(reinterpret_cast_ptr):
* wtf/Vector.h:
(WTF::VectorBuffer::inlineBuffer):
* wtf/qt/StringQt.cpp:
(WTF::String::String):
2010-08-13 Gavin Barraclough <barraclough@apple.com>
Reviewed by Sam Weinig
......
......@@ -357,11 +357,11 @@ void* ARMAssembler::executableCopy(ExecutablePool* allocator)
for (Jumps::Iterator iter = m_jumps.begin(); iter != m_jumps.end(); ++iter) {
// The last bit is set if the constant must be placed on constant pool.
int pos = (*iter) & (~0x1);
ARMWord* ldrAddr = reinterpret_cast<ARMWord*>(data + pos);
ARMWord* ldrAddr = reinterpret_cast_ptr<ARMWord*>(data + pos);
ARMWord* addr = getLdrImmAddress(ldrAddr);
if (*addr != InvalidBranchTarget) {
if (!(*iter & 1)) {
int diff = reinterpret_cast<ARMWord*>(data + *addr) - (ldrAddr + DefaultPrefetching);
int diff = reinterpret_cast_ptr<ARMWord*>(data + *addr) - (ldrAddr + DefaultPrefetching);
if ((diff <= BOFFSET_MAX && diff >= BOFFSET_MIN)) {
*ldrAddr = B | getConditionalField(*ldrAddr) | (diff & BRANCH_MASK);
......
......@@ -33,6 +33,7 @@
#include <jit/ExecutableAllocator.h>
#include <wtf/Assertions.h>
#include <wtf/FastMalloc.h>
#include <wtf/StdLibExtras.h>
namespace JSC {
......@@ -81,7 +82,7 @@ namespace JSC {
void putShortUnchecked(int value)
{
ASSERT(!(m_size > m_capacity - 4));
*reinterpret_cast<short*>(&m_buffer[m_size]) = value;
*reinterpret_cast_ptr<short*>(&m_buffer[m_size]) = value;
m_size += 2;
}
......@@ -95,14 +96,14 @@ namespace JSC {
void putIntUnchecked(int value)
{
ASSERT(!(m_size > m_capacity - 4));
*reinterpret_cast<int*>(&m_buffer[m_size]) = value;
*reinterpret_cast_ptr<int*>(&m_buffer[m_size]) = value;
m_size += 4;
}
void putInt64Unchecked(int64_t value)
{
ASSERT(!(m_size > m_capacity - 8));
*reinterpret_cast<int64_t*>(&m_buffer[m_size]) = value;
*reinterpret_cast_ptr<int64_t*>(&m_buffer[m_size]) = value;
m_size += 8;
}
......
......@@ -166,7 +166,7 @@ namespace JSC {
checkAllocatedOkay(base);
size_t committedSize = roundUpAllocationSize(maxGlobals * sizeof(Register), commitSize);
checkAllocatedOkay(m_reservation.commit(base, committedSize));
m_commitEnd = reinterpret_cast<Register*>(reinterpret_cast<char*>(base) + committedSize);
m_commitEnd = reinterpret_cast_ptr<Register*>(reinterpret_cast<char*>(base) + committedSize);
m_start = static_cast<Register*>(base) + maxGlobals;
m_end = m_start;
m_maxUsed = m_end;
......@@ -193,7 +193,7 @@ namespace JSC {
if (newEnd > m_commitEnd) {
size_t size = roundUpAllocationSize(reinterpret_cast<char*>(newEnd) - reinterpret_cast<char*>(m_commitEnd), commitSize);
checkAllocatedOkay(m_reservation.commit(m_commitEnd, size));
m_commitEnd = reinterpret_cast<Register*>(reinterpret_cast<char*>(m_commitEnd) + size);
m_commitEnd = reinterpret_cast_ptr<Register*>(reinterpret_cast<char*>(m_commitEnd) + size);
}
if (newEnd > m_maxUsed)
......
......@@ -967,13 +967,13 @@ struct StackHack {
ReturnAddressPtr savedReturnAddress;
};
#define STUB_INIT_STACK_FRAME(stackFrame) JITStackFrame& stackFrame = *reinterpret_cast<JITStackFrame*>(STUB_ARGS); StackHack stackHack(stackFrame)
#define STUB_INIT_STACK_FRAME(stackFrame) JITStackFrame& stackFrame = *reinterpret_cast_ptr<JITStackFrame*>(STUB_ARGS); StackHack stackHack(stackFrame)
#define STUB_SET_RETURN_ADDRESS(returnAddress) stackHack.savedReturnAddress = ReturnAddressPtr(returnAddress)
#define STUB_RETURN_ADDRESS stackHack.savedReturnAddress
#else
#define STUB_INIT_STACK_FRAME(stackFrame) JITStackFrame& stackFrame = *reinterpret_cast<JITStackFrame*>(STUB_ARGS)
#define STUB_INIT_STACK_FRAME(stackFrame) JITStackFrame& stackFrame = *reinterpret_cast_ptr<JITStackFrame*>(STUB_ARGS)
#define STUB_SET_RETURN_ADDRESS(returnAddress) *stackFrame.returnAddressSlot() = ReturnAddressPtr(returnAddress)
#define STUB_RETURN_ADDRESS *stackFrame.returnAddressSlot()
......
......@@ -49,6 +49,7 @@ supporting internal functions that are not used by other modules. */
#include <wtf/ASCIICType.h>
#include <wtf/FastMalloc.h>
#include <wtf/FixedArray.h>
#include <wtf/StdLibExtras.h>
using namespace WTF;
......@@ -2590,7 +2591,7 @@ JSRegExp* jsRegExpCompile(const UChar* pattern, int patternLength,
size_t stringOffset = (size + sizeof(UChar) - 1) / sizeof(UChar) * sizeof(UChar);
size = stringOffset + patternLength * sizeof(UChar);
#endif
JSRegExp* re = reinterpret_cast<JSRegExp*>(new char[size]);
JSRegExp* re = reinterpret_cast_ptr<JSRegExp*>(new char[size]);
if (!re)
return returnError(ERR13, errorPtr);
......
......@@ -441,7 +441,7 @@ NEVER_INLINE void JSArray::putSlowCase(ExecState* exec, unsigned i, JSValue valu
return;
}
m_storage = reinterpret_cast<ArrayStorage*>(static_cast<char*>(baseStorage) + m_indexBias * sizeof(JSValue));
m_storage = reinterpret_cast_ptr<ArrayStorage*>(static_cast<char*>(baseStorage) + m_indexBias * sizeof(JSValue));
m_storage->m_allocBase = baseStorage;
storage = m_storage;
......@@ -591,7 +591,7 @@ bool JSArray::increaseVectorLength(unsigned newLength)
if (!tryFastRealloc(baseStorage, storageSize(newVectorLength + m_indexBias)).getValue(baseStorage))
return false;
storage = m_storage = reinterpret_cast<ArrayStorage*>(static_cast<char*>(baseStorage) + m_indexBias * sizeof(JSValue));
storage = m_storage = reinterpret_cast_ptr<ArrayStorage*>(static_cast<char*>(baseStorage) + m_indexBias * sizeof(JSValue));
m_storage->m_allocBase = baseStorage;
JSValue* vector = storage->m_vector;
......@@ -623,7 +623,7 @@ bool JSArray::increaseVectorPrefixLength(unsigned newLength)
m_indexBias += newVectorLength - newLength;
m_storage = reinterpret_cast<ArrayStorage*>(static_cast<char*>(newBaseStorage) + m_indexBias * sizeof(JSValue));
m_storage = reinterpret_cast_ptr<ArrayStorage*>(static_cast<char*>(newBaseStorage) + m_indexBias * sizeof(JSValue));
memcpy(m_storage, storage, storageSize(0));
memcpy(&m_storage->m_vector[newLength - m_vectorLength], &storage->m_vector[0], vectorLength * sizeof(JSValue));
......@@ -802,7 +802,7 @@ void JSArray::shiftCount(ExecState* exec, int count)
if (m_vectorLength) {
char* newBaseStorage = reinterpret_cast<char*>(storage) + count * sizeof(JSValue);
memmove(newBaseStorage, storage, storageSize(0));
m_storage = reinterpret_cast<ArrayStorage*>(newBaseStorage);
m_storage = reinterpret_cast_ptr<ArrayStorage*>(newBaseStorage);
m_indexBias += count;
}
......@@ -839,7 +839,7 @@ void JSArray::unshiftCount(ExecState* exec, int count)
m_indexBias -= count;
char* newBaseStorage = reinterpret_cast<char*>(storage) - count * sizeof(JSValue);
memmove(newBaseStorage, storage, storageSize(0));
m_storage = reinterpret_cast<ArrayStorage*>(newBaseStorage);
m_storage = reinterpret_cast_ptr<ArrayStorage*>(newBaseStorage);
m_vectorLength += count;
} else if (!increaseVectorPrefixLength(m_vectorLength + count)) {
throwOutOfMemoryError(exec);
......
......@@ -82,6 +82,7 @@
#if ENABLE(JSC_MULTIPLE_THREADS)
#include <pthread.h>
#endif
#include <wtf/StdLibExtras.h>
#ifndef NO_TCMALLOC_SAMPLES
#ifdef WTF_CHANGES
......@@ -1017,7 +1018,7 @@ class PageHeapAllocator {
if (!new_allocation)
CRASH();
*(void**)new_allocation = allocated_regions_;
*reinterpret_cast_ptr<void**>(new_allocation) = allocated_regions_;
allocated_regions_ = new_allocation;
free_area_ = new_allocation + kAlignedSize;
free_avail_ = kAllocIncrement - kAlignedSize;
......@@ -2718,7 +2719,7 @@ ALWAYS_INLINE void TCMalloc_Central_FreeList::Populate() {
char* nptr;
while ((nptr = ptr + size) <= limit) {
*tail = ptr;
tail = reinterpret_cast<void**>(ptr);
tail = reinterpret_cast_ptr<void**>(ptr);
ptr = nptr;
num++;
}
......
......@@ -54,6 +54,7 @@
#include "StringExtras.h"
#include "text/CString.h"
#endif
#include <wtf/StdLibExtras.h>
namespace WTF {
......@@ -103,7 +104,7 @@ static void reverseBytes(uint8_t* buf, unsigned longs)
do {
uint32_t t = static_cast<uint32_t>(buf[3] << 8 | buf[2]) << 16 | buf[1] << 8 | buf[0];
ASSERT_WITH_MESSAGE(!(reinterpret_cast<uintptr_t>(buf) % sizeof(t)), "alignment error of buf");
*reinterpret_cast<uint32_t *>(buf) = t;
*reinterpret_cast_ptr<uint32_t *>(buf) = t;
buf += 4;
} while (--longs);
}
......@@ -238,7 +239,7 @@ void MD5::addBytes(const uint8_t* input, size_t length)
}
memcpy(p, buf, t);
reverseBytes(m_in, 16);
MD5Transform(m_buf, reinterpret_cast<uint32_t*>(m_in)); // m_in is 4-byte aligned.
MD5Transform(m_buf, reinterpret_cast_ptr<uint32_t*>(m_in)); // m_in is 4-byte aligned.
buf += t;
length -= t;
}
......@@ -248,7 +249,7 @@ void MD5::addBytes(const uint8_t* input, size_t length)
while (length >= 64) {
memcpy(m_in, buf, 64);
reverseBytes(m_in, 16);
MD5Transform(m_buf, reinterpret_cast<uint32_t*>(m_in)); // m_in is 4-byte aligned.
MD5Transform(m_buf, reinterpret_cast_ptr<uint32_t*>(m_in)); // m_in is 4-byte aligned.
buf += 64;
length -= 64;
}
......@@ -275,7 +276,7 @@ void MD5::checksum(Vector<uint8_t, 16>& digest)
// Two lots of padding: Pad the first block to 64 bytes
memset(p, 0, count);
reverseBytes(m_in, 16);
MD5Transform(m_buf, reinterpret_cast<uint32_t *>(m_in)); // m_in is 4-byte aligned.
MD5Transform(m_buf, reinterpret_cast_ptr<uint32_t *>(m_in)); // m_in is 4-byte aligned.
// Now fill the next block with 56 bytes
memset(m_in, 0, 56);
......@@ -287,10 +288,10 @@ void MD5::checksum(Vector<uint8_t, 16>& digest)
// Append length in bits and transform
// m_in is 4-byte aligned.
(reinterpret_cast<uint32_t*>(m_in))[14] = m_bits[0];
(reinterpret_cast<uint32_t*>(m_in))[15] = m_bits[1];
(reinterpret_cast_ptr<uint32_t*>(m_in))[14] = m_bits[0];
(reinterpret_cast_ptr<uint32_t*>(m_in))[15] = m_bits[1];
MD5Transform(m_buf, reinterpret_cast<uint32_t*>(m_in));
MD5Transform(m_buf, reinterpret_cast_ptr<uint32_t*>(m_in));
reverseBytes(reinterpret_cast<uint8_t*>(m_buf), 4);
// Now, m_buf contains checksum result.
......
......@@ -51,6 +51,40 @@
#define STRINGIZE(exp) #exp
#define STRINGIZE_VALUE_OF(exp) STRINGIZE(exp)
/*
* The reinterpret_cast<Type1*>([pointer to Type2]) expressions - where
* sizeof(Type1) > sizeof(Type2) - cause the following warning on ARM with GCC:
* increases required alignment of target type.
*
* An implicit or an extra static_cast<void*> bypasses the warning.
* For more info see the following bugzilla entries:
* - https://bugs.webkit.org/show_bug.cgi?id=38045
* - http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43976
*/
#if CPU(ARM) && COMPILER(GCC)
template<typename Type>
bool isPointerTypeAlignmentOkay(Type* ptr)
{
return !(reinterpret_cast<intptr_t>(ptr) % __alignof__(Type));
}
template<typename TypePtr>
TypePtr reinterpret_cast_ptr(void* ptr)
{
ASSERT(isPointerTypeAlignmentOkay(reinterpret_cast<TypePtr>(ptr)));
return reinterpret_cast<TypePtr>(ptr);
}
template<typename TypePtr>
TypePtr reinterpret_cast_ptr(const void* ptr)
{
ASSERT(isPointerTypeAlignmentOkay(reinterpret_cast<TypePtr>(ptr)));
return reinterpret_cast<TypePtr>(ptr);
}
#else
#define reinterpret_cast_ptr reinterpret_cast
#endif
namespace WTF {
/*
......
......@@ -24,6 +24,7 @@
#include "FastAllocBase.h"
#include "Noncopyable.h"
#include "NotFound.h"
#include "StdLibExtras.h"
#include "ValueCheck.h"
#include "VectorTraits.h"
#include <limits>
......@@ -481,7 +482,7 @@ namespace WTF {
using Base::m_capacity;
static const size_t m_inlineBufferSize = inlineCapacity * sizeof(T);
T* inlineBuffer() { return reinterpret_cast<T*>(m_inlineBuffer.buffer); }
T* inlineBuffer() { return reinterpret_cast_ptr<T*>(m_inlineBuffer.buffer); }
AlignedBuffer<m_inlineBufferSize, WTF_ALIGN_OF(T)> m_inlineBuffer;
};
......
......@@ -25,6 +25,7 @@
#include "config.h"
#include <wtf/StdLibExtras.h>
#include <wtf/text/WTFString.h>
#include <QString>
......@@ -36,14 +37,14 @@ String::String(const QString& qstr)
{
if (qstr.isNull())
return;
m_impl = StringImpl::create(reinterpret_cast<const UChar*>(qstr.constData()), qstr.length());
m_impl = StringImpl::create(reinterpret_cast_ptr<const UChar*>(qstr.constData()), qstr.length());
}
String::String(const QStringRef& ref)
{
if (!ref.string())
return;
m_impl = StringImpl::create(reinterpret_cast<const UChar*>(ref.unicode()), ref.length());
m_impl = StringImpl::create(reinterpret_cast_ptr<const UChar*>(ref.unicode()), ref.length());
}
String::operator QString() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment