Commit 07865679 authored by unknown's avatar unknown

BUG#31761: Code for cluster is not safe for strict-alias optimization in new gcc

Fix problem with AttributeHeader::init() seen with gcc 4.2.1.

Using the same object as both Uint32 and class AttributeHeader violates
strict aliasing rule.


ndb/include/kernel/AttributeHeader.hpp:
  Fix problem with AttributeHeader::init() seen with gcc 4.2.1.
  
  Using the same object as both Uint32 and class AttributeHeader violates
  strict aliasing rule.
ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp:
  Fix problem with AttributeHeader::init() seen with gcc 4.2.1.
  
  Using the same object as both Uint32 and class AttributeHeader violates
  strict aliasing rule.
ndb/src/kernel/blocks/dbtup/DbtupRoutines.cpp:
  Fix problem with AttributeHeader::init() seen with gcc 4.2.1.
  
  Using the same object as both Uint32 and class AttributeHeader violates
  strict aliasing rule.
ndb/src/kernel/blocks/dbutil/DbUtil.cpp:
  Fix problem with AttributeHeader::init() seen with gcc 4.2.1.
  
  Using the same object as both Uint32 and class AttributeHeader violates
  strict aliasing rule.
ndb/src/ndbapi/NdbOperationDefine.cpp:
  Fix problem with AttributeHeader::init() seen with gcc 4.2.1.
  
  Using the same object as both Uint32 and class AttributeHeader violates
  strict aliasing rule.
parent 7ebebf5e
...@@ -42,8 +42,7 @@ public: ...@@ -42,8 +42,7 @@ public:
STATIC_CONST( FRAGMENT_MEMORY= 0xFFF9 ); STATIC_CONST( FRAGMENT_MEMORY= 0xFFF9 );
/** Initialize AttributeHeader at location aHeaderPtr */ /** Initialize AttributeHeader at location aHeaderPtr */
static AttributeHeader& init(void* aHeaderPtr, Uint32 anAttributeId, static void init(Uint32* aHeaderPtr, Uint32 anAttributeId, Uint32 aDataSize);
Uint32 aDataSize);
/** Returns size of AttributeHeader (usually one or two words) */ /** Returns size of AttributeHeader (usually one or two words) */
Uint32 getHeaderSize() const; // In 32-bit words Uint32 getHeaderSize() const; // In 32-bit words
...@@ -101,10 +100,11 @@ public: ...@@ -101,10 +100,11 @@ public:
*/ */
inline inline
AttributeHeader& AttributeHeader::init(void* aHeaderPtr, Uint32 anAttributeId, void AttributeHeader::init(Uint32* aHeaderPtr, Uint32 anAttributeId,
Uint32 aDataSize) Uint32 aDataSize)
{ {
return * new (aHeaderPtr) AttributeHeader(anAttributeId, aDataSize); AttributeHeader ah(anAttributeId, aDataSize);
*aHeaderPtr = ah.m_value;
} }
inline inline
......
...@@ -1578,8 +1578,8 @@ int Dbtup::interpreterNextLab(Signal* signal, ...@@ -1578,8 +1578,8 @@ int Dbtup::interpreterNextLab(Signal* signal,
Uint32 TdataForUpdate[3]; Uint32 TdataForUpdate[3];
Uint32 Tlen; Uint32 Tlen;
AttributeHeader& ah = AttributeHeader::init(&TdataForUpdate[0], AttributeHeader ah(TattrId, TattrNoOfWords);
TattrId, TattrNoOfWords); TdataForUpdate[0] = ah.m_value;
TdataForUpdate[1] = TregMemBuffer[theRegister + 2]; TdataForUpdate[1] = TregMemBuffer[theRegister + 2];
TdataForUpdate[2] = TregMemBuffer[theRegister + 3]; TdataForUpdate[2] = TregMemBuffer[theRegister + 3];
Tlen = TattrNoOfWords + 1; Tlen = TattrNoOfWords + 1;
...@@ -1595,6 +1595,7 @@ int Dbtup::interpreterNextLab(Signal* signal, ...@@ -1595,6 +1595,7 @@ int Dbtup::interpreterNextLab(Signal* signal,
// Write a NULL value into the attribute // Write a NULL value into the attribute
/* --------------------------------------------------------- */ /* --------------------------------------------------------- */
ah.setNULL(); ah.setNULL();
TdataForUpdate[0] = ah.m_value;
Tlen = 1; Tlen = 1;
}//if }//if
int TnoDataRW= updateAttributes(pagePtr, int TnoDataRW= updateAttributes(pagePtr,
......
...@@ -677,8 +677,6 @@ bool ...@@ -677,8 +677,6 @@ bool
Dbtup::checkUpdateOfPrimaryKey(Uint32* updateBuffer, Tablerec* const regTabPtr) Dbtup::checkUpdateOfPrimaryKey(Uint32* updateBuffer, Tablerec* const regTabPtr)
{ {
Uint32 keyReadBuffer[MAX_KEY_SIZE_IN_WORDS]; Uint32 keyReadBuffer[MAX_KEY_SIZE_IN_WORDS];
Uint32 attributeHeader;
AttributeHeader* ahOut = (AttributeHeader*)&attributeHeader;
AttributeHeader ahIn(*updateBuffer); AttributeHeader ahIn(*updateBuffer);
Uint32 attributeId = ahIn.getAttributeId(); Uint32 attributeId = ahIn.getAttributeId();
Uint32 attrDescriptorIndex = regTabPtr->tabDescriptor + (attributeId << ZAD_LOG_SIZE); Uint32 attrDescriptorIndex = regTabPtr->tabDescriptor + (attributeId << ZAD_LOG_SIZE);
...@@ -701,16 +699,17 @@ Dbtup::checkUpdateOfPrimaryKey(Uint32* updateBuffer, Tablerec* const regTabPtr) ...@@ -701,16 +699,17 @@ Dbtup::checkUpdateOfPrimaryKey(Uint32* updateBuffer, Tablerec* const regTabPtr)
ReadFunction f = regTabPtr->readFunctionArray[attributeId]; ReadFunction f = regTabPtr->readFunctionArray[attributeId];
AttributeHeader::init(&attributeHeader, attributeId, 0); AttributeHeader attributeHeader(attributeId, 0);
tOutBufIndex = 0; tOutBufIndex = 0;
tMaxRead = MAX_KEY_SIZE_IN_WORDS; tMaxRead = MAX_KEY_SIZE_IN_WORDS;
bool tmp = tXfrmFlag; bool tmp = tXfrmFlag;
tXfrmFlag = true; tXfrmFlag = true;
ndbrequire((this->*f)(&keyReadBuffer[0], ahOut, attrDescriptor, attributeOffset)); ndbrequire((this->*f)(&keyReadBuffer[0], &attributeHeader, attrDescriptor,
attributeOffset));
tXfrmFlag = tmp; tXfrmFlag = tmp;
ndbrequire(tOutBufIndex == ahOut->getDataSize()); ndbrequire(tOutBufIndex == attributeHeader.getDataSize());
if (ahIn.getDataSize() != ahOut->getDataSize()) { if (ahIn.getDataSize() != attributeHeader.getDataSize()) {
ljam(); ljam();
return true; return true;
}//if }//if
......
...@@ -1169,9 +1169,7 @@ DbUtil::prepareOperation(Signal* signal, PreparePtr prepPtr) ...@@ -1169,9 +1169,7 @@ DbUtil::prepareOperation(Signal* signal, PreparePtr prepPtr)
/************************************************************** /**************************************************************
* Attribute found - store in mapping (AttributeId, Position) * Attribute found - store in mapping (AttributeId, Position)
**************************************************************/ **************************************************************/
AttributeHeader & attrMap = AttributeHeader attrMap(attrDesc.AttributeId, // 1. Store AttrId
AttributeHeader::init(attrMappingIt.data,
attrDesc.AttributeId, // 1. Store AttrId
0); 0);
if (attrDesc.AttributeKeyFlag) { if (attrDesc.AttributeKeyFlag) {
...@@ -1200,6 +1198,7 @@ DbUtil::prepareOperation(Signal* signal, PreparePtr prepPtr) ...@@ -1200,6 +1198,7 @@ DbUtil::prepareOperation(Signal* signal, PreparePtr prepPtr)
return; return;
} }
} }
*(attrMappingIt.data) = attrMap.m_value;
#if 0 #if 0
ndbout << "BEFORE: attrLength: " << attrLength << endl; ndbout << "BEFORE: attrLength: " << attrLength << endl;
#endif #endif
......
...@@ -363,9 +363,8 @@ NdbOperation::getValue_impl(const NdbColumnImpl* tAttrInfo, char* aValue) ...@@ -363,9 +363,8 @@ NdbOperation::getValue_impl(const NdbColumnImpl* tAttrInfo, char* aValue)
return NULL; return NULL;
}//if }//if
}//if }//if
Uint32 ah; AttributeHeader ah(tAttrInfo->m_attrId, 0);
AttributeHeader::init(&ah, tAttrInfo->m_attrId, 0); if (insertATTRINFO(ah.m_value) != -1) {
if (insertATTRINFO(ah) != -1) {
// Insert Attribute Id into ATTRINFO part. // Insert Attribute Id into ATTRINFO part.
/************************************************************************ /************************************************************************
...@@ -496,12 +495,11 @@ NdbOperation::setValue( const NdbColumnImpl* tAttrInfo, ...@@ -496,12 +495,11 @@ NdbOperation::setValue( const NdbColumnImpl* tAttrInfo,
tAttrId = tAttrInfo->m_attrId; tAttrId = tAttrInfo->m_attrId;
const char *aValue = aValuePassed; const char *aValue = aValuePassed;
Uint32 ahValue;
if (aValue == NULL) { if (aValue == NULL) {
if (tAttrInfo->m_nullable) { if (tAttrInfo->m_nullable) {
AttributeHeader& ah = AttributeHeader::init(&ahValue, tAttrId, 0); AttributeHeader ah(tAttrId, 0);
ah.setNULL(); ah.setNULL();
insertATTRINFO(ahValue); insertATTRINFO(ah.m_value);
// Insert Attribute Id with the value // Insert Attribute Id with the value
// NULL into ATTRINFO part. // NULL into ATTRINFO part.
DBUG_RETURN(0); DBUG_RETURN(0);
...@@ -534,9 +532,8 @@ NdbOperation::setValue( const NdbColumnImpl* tAttrInfo, ...@@ -534,9 +532,8 @@ NdbOperation::setValue( const NdbColumnImpl* tAttrInfo,
}//if }//if
const Uint32 totalSizeInWords = (sizeInBytes + 3)/4; // Including bits in last word const Uint32 totalSizeInWords = (sizeInBytes + 3)/4; // Including bits in last word
const Uint32 sizeInWords = sizeInBytes / 4; // Excluding bits in last word const Uint32 sizeInWords = sizeInBytes / 4; // Excluding bits in last word
AttributeHeader& ah = AttributeHeader::init(&ahValue, tAttrId, AttributeHeader ah(tAttrId, totalSizeInWords);
totalSizeInWords); insertATTRINFO( ah.m_value );
insertATTRINFO( ahValue );
/*********************************************************************** /***********************************************************************
* Check if the pointer of the value passed is aligned on a 4 byte boundary. * Check if the pointer of the value passed is aligned on a 4 byte boundary.
......
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