COMP: silence gcc 8.2 memcpy warnings

- we know they have already protected by an is_contiguous check,
  so the class-memaccess warning/error can be suppressed.
This commit is contained in:
Mark Olesen
2019-10-28 16:57:47 +01:00
parent 00552eff17
commit e91dbcf834
6 changed files with 74 additions and 40 deletions

View File

@ -1428,7 +1428,7 @@ bool Foam::ping
} }
// Fill sockaddr_in structure with dest address and port // Fill sockaddr_in structure with dest address and port
memset(reinterpret_cast<char *>(&destAddr), '\0', sizeof(destAddr)); std::memset(reinterpret_cast<char *>(&destAddr), '\0', sizeof(destAddr));
destAddr.sin_family = AF_INET; destAddr.sin_family = AF_INET;
destAddr.sin_port = htons(ushort(destPort)); destAddr.sin_port = htons(ushort(destPort));
destAddr.sin_addr.s_addr = addr; destAddr.sin_addr.s_addr = addr;

View File

@ -59,7 +59,10 @@ void Foam::List<T>::doResize(const label newSize)
#ifdef USEMEMCPY #ifdef USEMEMCPY
if (contiguous<T>()) if (contiguous<T>())
{ {
memcpy(nv, this->v_, overlap*sizeof(T)); std::memcpy
(
static_cast<void*>(nv), this->v_, overlap*sizeof(T)
);
} }
else else
#endif #endif
@ -185,21 +188,26 @@ Foam::List<T>::List(const UList<T>& a)
: :
UList<T>(nullptr, a.size_) UList<T>(nullptr, a.size_)
{ {
if (this->size_) const label len = this->size_;
if (len)
{ {
doAlloc(); doAlloc();
#ifdef USEMEMCPY #ifdef USEMEMCPY
if (contiguous<T>()) if (contiguous<T>())
{ {
memcpy(this->v_, a.v_, this->byteSize()); std::memcpy
(
static_cast<void*>(this->v_), a.v_, this->byteSize()
);
} }
else else
#endif #endif
{ {
List_ACCESS(T, (*this), vp); List_ACCESS(T, (*this), vp);
List_CONST_ACCESS(T, a, ap); List_CONST_ACCESS(T, a, ap);
List_FOR_ALL((*this), i) for (label i = 0; i < len; ++i)
{ {
vp[i] = ap[i]; vp[i] = ap[i];
} }
@ -213,21 +221,26 @@ Foam::List<T>::List(const List<T>& a)
: :
UList<T>(nullptr, a.size_) UList<T>(nullptr, a.size_)
{ {
if (this->size_) const label len = this->size_;
if (len)
{ {
doAlloc(); doAlloc();
#ifdef USEMEMCPY #ifdef USEMEMCPY
if (contiguous<T>()) if (contiguous<T>())
{ {
memcpy(this->v_, a.v_, this->byteSize()); std::memcpy
(
static_cast<void*>(this->v_), a.v_, this->byteSize()
);
} }
else else
#endif #endif
{ {
List_ACCESS(T, (*this), vp); List_ACCESS(T, (*this), vp);
List_CONST_ACCESS(T, a, ap); List_CONST_ACCESS(T, a, ap);
List_FOR_ALL((*this), i) for (label i = 0; i < len; ++i)
{ {
vp[i] = ap[i]; vp[i] = ap[i];
} }
@ -247,22 +260,29 @@ Foam::List<T>::List(List<T>& a, bool reuse)
this->v_ = a.v_; this->v_ = a.v_;
a.v_ = nullptr; a.v_ = nullptr;
a.size_ = 0; a.size_ = 0;
return;
} }
else if (this->size_)
const label len = this->size_;
if (len)
{ {
doAlloc(); doAlloc();
#ifdef USEMEMCPY #ifdef USEMEMCPY
if (contiguous<T>()) if (contiguous<T>())
{ {
memcpy(this->v_, a.v_, this->byteSize()); std::memcpy
(
static_cast<void*>(this->v_), a.v_, this->byteSize()
);
} }
else else
#endif #endif
{ {
List_ACCESS(T, (*this), vp); List_ACCESS(T, (*this), vp);
List_CONST_ACCESS(T, a, ap); List_CONST_ACCESS(T, a, ap);
List_FOR_ALL((*this), i) for (label i = 0; i < len; ++i)
{ {
vp[i] = ap[i]; vp[i] = ap[i];
} }
@ -454,19 +474,24 @@ void Foam::List<T>::operator=(const UList<T>& a)
{ {
reAlloc(a.size_); reAlloc(a.size_);
if (this->size_) const label len = this->size_;
if (len)
{ {
#ifdef USEMEMCPY #ifdef USEMEMCPY
if (contiguous<T>()) if (contiguous<T>())
{ {
memcpy(this->v_, a.v_, this->byteSize()); std::memcpy
(
static_cast<void*>(this->v_), a.v_, this->byteSize()
);
} }
else else
#endif #endif
{ {
List_ACCESS(T, (*this), vp); List_ACCESS(T, (*this), vp);
List_CONST_ACCESS(T, a, ap); List_CONST_ACCESS(T, a, ap);
List_FOR_ALL((*this), i) for (label i = 0; i < len; ++i)
{ {
vp[i] = ap[i]; vp[i] = ap[i];
} }
@ -522,7 +547,7 @@ void Foam::List<T>::operator=(const IndirectListBase<T, Addr>& list)
{ {
List_ACCESS(T, (*this), vp); List_ACCESS(T, (*this), vp);
for (label i=0; i<len; ++i) for (label i=0; i < len; ++i)
{ {
vp[i] = list[i]; vp[i] = list[i];
} }

View File

@ -118,7 +118,10 @@ void Foam::UList<T>::deepCopy(const UList<T>& list)
#ifdef USEMEMCPY #ifdef USEMEMCPY
if (contiguous<T>()) if (contiguous<T>())
{ {
memcpy(this->v_, list.v_, this->byteSize()); std::memcpy
(
static_cast<void*>(this->v_), list.v_, this->byteSize()
);
} }
else else
#endif #endif

View File

@ -50,7 +50,7 @@ void Foam::processorLduInterface::send
( (
commsType, commsType,
neighbProcNo(), neighbProcNo(),
reinterpret_cast<const char*>(f.begin()), reinterpret_cast<const char*>(f.cdata()),
nBytes, nBytes,
tag(), tag(),
comm() comm()
@ -64,20 +64,23 @@ void Foam::processorLduInterface::send
( (
commsType, commsType,
neighbProcNo(), neighbProcNo(),
receiveBuf_.begin(), receiveBuf_.data(),
nBytes, nBytes,
tag(), tag(),
comm() comm()
); );
resizeBuf(sendBuf_, nBytes); resizeBuf(sendBuf_, nBytes);
memcpy(sendBuf_.begin(), f.begin(), nBytes); std::memcpy
(
static_cast<void*>(sendBuf_.data()), f.cdata(), nBytes
);
OPstream::write OPstream::write
( (
commsType, commsType,
neighbProcNo(), neighbProcNo(),
sendBuf_.begin(), sendBuf_.cdata(),
nBytes, nBytes,
tag(), tag(),
comm() comm()
@ -109,7 +112,7 @@ void Foam::processorLduInterface::receive
( (
commsType, commsType,
neighbProcNo(), neighbProcNo(),
reinterpret_cast<char*>(f.begin()), reinterpret_cast<char*>(f.data()),
f.byteSize(), f.byteSize(),
tag(), tag(),
comm() comm()
@ -117,7 +120,10 @@ void Foam::processorLduInterface::receive
} }
else if (commsType == Pstream::commsTypes::nonBlocking) else if (commsType == Pstream::commsTypes::nonBlocking)
{ {
memcpy(f.begin(), receiveBuf_.begin(), f.byteSize()); std::memcpy
(
static_cast<void*>(f.data()), receiveBuf_.cdata(), f.byteSize()
);
} }
else else
{ {
@ -156,10 +162,10 @@ void Foam::processorLduInterface::compressedSend
label nFloats = nm1 + nlast; label nFloats = nm1 + nlast;
label nBytes = nFloats*sizeof(float); label nBytes = nFloats*sizeof(float);
const scalar *sArray = reinterpret_cast<const scalar*>(f.begin()); const scalar *sArray = reinterpret_cast<const scalar*>(f.cdata());
const scalar *slast = &sArray[nm1]; const scalar *slast = &sArray[nm1];
resizeBuf(sendBuf_, nBytes); resizeBuf(sendBuf_, nBytes);
float *fArray = reinterpret_cast<float*>(sendBuf_.begin()); float *fArray = reinterpret_cast<float*>(sendBuf_.data());
for (label i=0; i<nm1; i++) for (label i=0; i<nm1; i++)
{ {
@ -178,7 +184,7 @@ void Foam::processorLduInterface::compressedSend
( (
commsType, commsType,
neighbProcNo(), neighbProcNo(),
sendBuf_.begin(), sendBuf_.cdata(),
nBytes, nBytes,
tag(), tag(),
comm() comm()
@ -192,7 +198,7 @@ void Foam::processorLduInterface::compressedSend
( (
commsType, commsType,
neighbProcNo(), neighbProcNo(),
receiveBuf_.begin(), receiveBuf_.data(),
nBytes, nBytes,
tag(), tag(),
comm() comm()
@ -202,7 +208,7 @@ void Foam::processorLduInterface::compressedSend
( (
commsType, commsType,
neighbProcNo(), neighbProcNo(),
sendBuf_.begin(), sendBuf_.cdata(),
nBytes, nBytes,
tag(), tag(),
comm() comm()
@ -248,7 +254,7 @@ void Foam::processorLduInterface::compressedReceive
( (
commsType, commsType,
neighbProcNo(), neighbProcNo(),
receiveBuf_.begin(), receiveBuf_.data(),
nBytes, nBytes,
tag(), tag(),
comm() comm()
@ -262,9 +268,9 @@ void Foam::processorLduInterface::compressedReceive
} }
const float *fArray = const float *fArray =
reinterpret_cast<const float*>(receiveBuf_.begin()); reinterpret_cast<const float*>(receiveBuf_.cdata());
f.last() = reinterpret_cast<const Type&>(fArray[nm1]); f.last() = reinterpret_cast<const Type&>(fArray[nm1]);
scalar *sArray = reinterpret_cast<scalar*>(f.begin()); scalar *sArray = reinterpret_cast<scalar*>(f.data());
const scalar *slast = &sArray[nm1]; const scalar *slast = &sArray[nm1];
for (label i=0; i<nm1; i++) for (label i=0; i<nm1; i++)

View File

@ -68,7 +68,7 @@ static inline uint32_t swapBytes(uint32_t n)
// *(uint32_t *) cp = val // *(uint32_t *) cp = val
static inline void set_uint32(unsigned char *dst, uint32_t v) static inline void set_uint32(unsigned char *dst, uint32_t v)
{ {
memcpy(dst, &v, sizeof(uint32_t)); std::memcpy(dst, &v, sizeof(uint32_t));
} }
//! \endcond //! \endcond
@ -96,7 +96,7 @@ void Foam::SHA1::processBytes(const void *data, size_t len)
unsigned char* bufp = reinterpret_cast<unsigned char*>(buffer_); unsigned char* bufp = reinterpret_cast<unsigned char*>(buffer_);
memcpy(&bufp[remaining], data, add); std::memcpy(&bufp[remaining], data, add);
bufLen_ += add; bufLen_ += add;
if (bufLen_ > 64) if (bufLen_ > 64)
@ -106,7 +106,7 @@ void Foam::SHA1::processBytes(const void *data, size_t len)
bufLen_ &= 63; bufLen_ &= 63;
// The regions in the following copy operation do not // The regions in the following copy operation do not
// (cannot) overlap // (cannot) overlap
memcpy(buffer_, &bufp[(remaining + add) & ~63], bufLen_); std::memcpy(buffer_, &bufp[(remaining + add) & ~63], bufLen_);
} }
data = reinterpret_cast<const unsigned char*>(data) + add; data = reinterpret_cast<const unsigned char*>(data) + add;
@ -116,7 +116,7 @@ void Foam::SHA1::processBytes(const void *data, size_t len)
// Process available complete blocks // Process available complete blocks
while (len >= 64) while (len >= 64)
{ {
processBlock(memcpy(buffer_, data, 64), 64); processBlock(std::memcpy(buffer_, data, 64), 64);
data = reinterpret_cast<const unsigned char*>(data) + 64; data = reinterpret_cast<const unsigned char*>(data) + 64;
len -= 64; len -= 64;
} }
@ -127,13 +127,13 @@ void Foam::SHA1::processBytes(const void *data, size_t len)
unsigned char* bufp = reinterpret_cast<unsigned char*>(buffer_); unsigned char* bufp = reinterpret_cast<unsigned char*>(buffer_);
size_t remaining = bufLen_; size_t remaining = bufLen_;
memcpy(&bufp[remaining], data, len); std::memcpy(&bufp[remaining], data, len);
remaining += len; remaining += len;
if (remaining >= 64) if (remaining >= 64)
{ {
processBlock(buffer_, 64); processBlock(buffer_, 64);
remaining -= 64; remaining -= 64;
memcpy(buffer_, &buffer_[16], remaining); std::memcpy(buffer_, &buffer_[16], remaining);
} }
bufLen_ = remaining; bufLen_ = remaining;
} }
@ -356,7 +356,7 @@ bool Foam::SHA1::finalize()
unsigned char* bufp = reinterpret_cast<unsigned char *>(buffer_); unsigned char* bufp = reinterpret_cast<unsigned char *>(buffer_);
memcpy(&bufp[bytes], fillbuf, (size-2) * sizeof(uint32_t) - bytes); std::memcpy(&bufp[bytes], fillbuf, (size-2) * sizeof(uint32_t) - bytes);
// Process remaining bytes // Process remaining bytes
processBlock(buffer_, size * sizeof(uint32_t)); processBlock(buffer_, size * sizeof(uint32_t));

View File

@ -574,7 +574,7 @@ void Foam::UPstream::allToAll
<< " does not equal bytes to receive " << recvSizes[0] << " does not equal bytes to receive " << recvSizes[0]
<< Foam::abort(FatalError); << Foam::abort(FatalError);
} }
memmove(recvData, &sendData[sendOffsets[0]], recvSizes[0]); std::memmove(recvData, &sendData[sendOffsets[0]], recvSizes[0]);
} }
else else
{ {
@ -640,7 +640,7 @@ void Foam::UPstream::gather
if (!UPstream::parRun()) if (!UPstream::parRun())
{ {
memmove(recvData, sendData, sendSize); std::memmove(recvData, sendData, sendSize);
} }
else else
{ {
@ -703,7 +703,7 @@ void Foam::UPstream::scatter
if (!UPstream::parRun()) if (!UPstream::parRun())
{ {
memmove(recvData, sendData, recvSize); std::memmove(recvData, sendData, recvSize);
} }
else else
{ {