Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce new SDL compile flags on Windows and fix warnings. #1035

Merged
merged 13 commits into from Mar 30, 2023
Merged
9 changes: 8 additions & 1 deletion cmake/compilers/MSVC.cmake
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2021 Intel Corporation
# Copyright (c) 2020-2023 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,6 +35,13 @@ endif()
set(TBB_LIB_COMPILE_FLAGS -D_CRT_SECURE_NO_WARNINGS /GS)
set(TBB_COMMON_COMPILE_FLAGS /volatile:iso /FS /EHsc)

set(TBB_LIB_LINK_FLAGS ${TBB_LIB_LINK_FLAGS} /DYNAMICBASE /GUARD:CF /NXCOMPAT)
sarathnandu marked this conversation as resolved.
Show resolved Hide resolved

if(CMAKE_SIZEOF_VOID_P EQUAL 4)
sarathnandu marked this conversation as resolved.
Show resolved Hide resolved
# 32 bits
set(TBB_LIB_LINK_FLAGS ${TBB_LIB_LINK_FLAGS} /SAFESEH )
endif()
sarathnandu marked this conversation as resolved.
Show resolved Hide resolved

# Ignore /WX set through add_compile_options() or added to CMAKE_CXX_FLAGS if TBB_STRICT is disabled.
if (NOT TBB_STRICT AND COMMAND tbb_remove_compile_flag)
tbb_remove_compile_flag(/WX)
Expand Down
4 changes: 2 additions & 2 deletions src/tbbmalloc/CMakeLists.txt
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2022 Intel Corporation
# Copyright (c) 2020-2023 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,12 +53,12 @@ if (MSVC)
set(TBB_WARNING_SUPPRESS ${TBB_WARNING_SUPPRESS} /wd4267 /wd4244 /wd4245 /wd4018 /wd4458)
sarathnandu marked this conversation as resolved.
Show resolved Hide resolved
endif()

# TODO: add ${TBB_WARNING_LEVEL} and fix problems
target_compile_options(tbbmalloc
PRIVATE
${TBB_CXX_STD_FLAG} # TODO: consider making it PUBLIC.
${TBB_MMD_FLAG}
${TBB_DSE_FLAG}
${TBB_WARNING_LEVEL}
${TBB_WARNING_SUPPRESS}
${TBB_LIB_COMPILE_FLAGS}
${TBBMALLOC_LIB_COMPILE_FLAGS}
Expand Down
4 changes: 2 additions & 2 deletions src/tbbmalloc/Customize.h
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2022 Intel Corporation
Copyright (c) 2005-2023 Intel Corporation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,7 +48,7 @@
#endif

inline intptr_t BitScanRev(uintptr_t x) {
return !x? -1 : tbb::detail::log2(x);
return !x? -1 : static_cast<intptr_t>(tbb::detail::log2(x));
sarathnandu marked this conversation as resolved.
Show resolved Hide resolved
}

template<typename T>
Expand Down
7 changes: 4 additions & 3 deletions src/tbbmalloc/backend.cpp
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2022 Intel Corporation
Copyright (c) 2005-2023 Intel Corporation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -363,6 +363,7 @@ inline void CoalRequestQ::blockWasProcessed()
{
bkndSync->binsModified();
int prev = inFlyBlocks.fetch_sub(1);
tbb::detail::suppress_unused_warning(prev);
MALLOC_ASSERT(prev > 0, ASSERT_TEXT);
}

Expand Down Expand Up @@ -748,7 +749,7 @@ int Backend::IndexedBins::getMinNonemptyBin(unsigned startBin) const
FreeBlock *Backend::IndexedBins::findBlock(int nativeBin, BackendSync *sync, size_t size,
bool needAlignedBlock, bool alignedBin, int *numOfLockedBins)
{
for (int i=getMinNonemptyBin(nativeBin); i<freeBinsNum; i=getMinNonemptyBin(i+1))
for (int i=getMinNonemptyBin(nativeBin); i<(int)freeBinsNum; i=getMinNonemptyBin(i+1))
if (FreeBlock *block = getFromBin(i, sync, size, needAlignedBlock, alignedBin, /*wait=*/false, numOfLockedBins))
return block;

Expand Down Expand Up @@ -1410,7 +1411,7 @@ bool Backend::clean()
void Backend::IndexedBins::verify()
{
#if MALLOC_DEBUG
for (int i=0; i<freeBinsNum; i++) {
for (int i=0; i<(int)freeBinsNum; i++) {
for (FreeBlock *fb = freeBins[i].head.load(std::memory_order_relaxed); fb; fb=fb->next) {
uintptr_t mySz = fb->myL.value;
MALLOC_ASSERT(mySz>GuardedSize::MAX_SPEC_VAL, ASSERT_TEXT);
Expand Down
8 changes: 4 additions & 4 deletions src/tbbmalloc/backref.cpp
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2022 Intel Corporation
Copyright (c) 2005-2023 Intel Corporation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,13 +42,13 @@ struct BackRefBlock : public BlockI {
nextForUse(nullptr), bumpPtr((FreeObject*)((uintptr_t)blockToUse + slabSize - sizeof(void*))),
freeList(nullptr), nextRawMemBlock(nullptr), allocatedCount(0), myNum(num),
addedToForUse(false) {
memset(&blockMutex, 0, sizeof(MallocMutex));
memset(static_cast<void *>(&blockMutex), 0, sizeof(MallocMutex));
sarathnandu marked this conversation as resolved.
Show resolved Hide resolved

MALLOC_ASSERT(!(num >> CHAR_BIT*sizeof(BackRefIdx::main_t)),
"index in BackRefMain must fit to BackRefIdx::main");
}
// clean all but header
void zeroSet() { memset(this+1, 0, BackRefBlock::bytes-sizeof(BackRefBlock)); }
void zeroSet() { memset(static_cast<void *>(this+1), 0, BackRefBlock::bytes-sizeof(BackRefBlock)); }
sarathnandu marked this conversation as resolved.
Show resolved Hide resolved
static const int bytes = slabSize;
};

Expand Down Expand Up @@ -106,7 +106,7 @@ bool initBackRefMain(Backend *backend)
main->allRawMemBlocks = nullptr;
main->rawMemUsed = rawMemUsed;
main->lastUsed = -1;
memset(&main->requestNewSpaceMutex, 0, sizeof(MallocMutex));
memset(static_cast<void *>(&main->requestNewSpaceMutex), 0, sizeof(MallocMutex));
sarathnandu marked this conversation as resolved.
Show resolved Hide resolved
for (int i=0; i<BackRefMain::leaves; i++) {
BackRefBlock *bl = (BackRefBlock*)((uintptr_t)main + BackRefMain::bytes + i*BackRefBlock::bytes);
bl->zeroSet();
Expand Down
10 changes: 5 additions & 5 deletions src/tbbmalloc/frontend.cpp
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2022 Intel Corporation
Copyright (c) 2005-2023 Intel Corporation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -802,7 +802,8 @@ static inline unsigned int highestBitPos(unsigned int n)
unsigned int getSmallObjectIndex(unsigned int size)
{
unsigned int result = (size-1)>>3;
if (sizeof(void*)==8) {
constexpr bool is_64bit = (8 == sizeof(void*));
if (is_64bit) {
// For 64-bit malloc, 16 byte alignment is needed except for bin 0.
if (result) result |= 1; // 0,1,3,5,7; bins 2,4,6 are not aligned to 16 bytes
}
Expand Down Expand Up @@ -927,7 +928,7 @@ static MallocMutex publicFreeListLock; // lock for changes of publicFreeList
LifoList::LifoList( ) : top(nullptr)
{
// MallocMutex assumes zero initialization
memset(&lock, 0, sizeof(MallocMutex));
memset(static_cast<void *>(&lock), 0, sizeof(MallocMutex));
sarathnandu marked this conversation as resolved.
Show resolved Hide resolved
}

void LifoList::push(Block *block)
Expand Down Expand Up @@ -1863,7 +1864,6 @@ FreeObject *StartupBlock::allocate(size_t size)
{
FreeObject *result;
StartupBlock *newBlock = nullptr;
bool newBlockUnused = false;

/* Objects must be aligned on their natural bounds,
and objects bigger than word on word's bound. */
Expand Down Expand Up @@ -2718,7 +2718,7 @@ rml::MemPoolError pool_create_v1(intptr_t pool_id, const MemPoolPolicy *policy,
*pool = nullptr;
return NO_MEMORY;
}
memset(memPool, 0, sizeof(rml::internal::MemoryPool));
memset(static_cast<void *>(memPool), 0, sizeof(rml::internal::MemoryPool));
sarathnandu marked this conversation as resolved.
Show resolved Hide resolved
if (!memPool->init(pool_id, policy)) {
internalFree(memPool);
*pool = nullptr;
Expand Down
8 changes: 4 additions & 4 deletions src/tbbmalloc/large_objects.cpp
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2022 Intel Corporation
Copyright (c) 2005-2023 Intel Corporation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -462,7 +462,7 @@ template<typename Props> LargeMemoryBlock *LargeObjectCacheImpl<Props>::
CacheBin::get(ExtMemoryPool *extMemPool, size_t size, BinBitMask *bitMask, int idx)
{
LargeMemoryBlock *lmb=nullptr;
OpGet data = {&lmb, size};
OpGet data = {&lmb, size, static_cast<intptr_t>(NULL)};
sarathnandu marked this conversation as resolved.
Show resolved Hide resolved
CacheBinOperation op(data);
ExecuteOperation( &op, extMemPool, bitMask, idx );
return lmb;
Expand Down Expand Up @@ -611,9 +611,9 @@ template<typename Props> void LargeObjectCacheImpl<Props>::

intptr_t threshold = ageThreshold.load(std::memory_order_relaxed);
if (threshold)
doCleanup = sinceLastGet > Props::LongWaitFactor * threshold;
doCleanup = sinceLastGet > static_cast<uintptr_t>(Props::LongWaitFactor * threshold);
else if (lastCleanedAge)
doCleanup = sinceLastGet > Props::LongWaitFactor * (lastCleanedAge - lastGet);
doCleanup = sinceLastGet > static_cast<uintptr_t>(Props::LongWaitFactor * (lastCleanedAge - lastGet));

if (doCleanup) {
lastCleanedAge = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/tbbmalloc/large_objects.h
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2021 Intel Corporation
Copyright (c) 2005-2023 Intel Corporation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -174,7 +174,7 @@ class LargeObjectCacheImpl {

public:
void init() {
memset(this, 0, sizeof(CacheBin));
memset(static_cast<void *>(this), 0, sizeof(CacheBin));
sarathnandu marked this conversation as resolved.
Show resolved Hide resolved
}

/* ---------- Cache accessors ---------- */
Expand Down
3 changes: 2 additions & 1 deletion src/tbbmalloc/tbbmalloc.cpp
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2022 Intel Corporation
Copyright (c) 2005-2023 Intel Corporation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -67,6 +67,7 @@ void init_tbbmalloc() {
|GET_MODULE_HANDLE_EX_FLAG_PIN,
(LPCTSTR)&scalable_malloc, &lib);
MALLOC_ASSERT(lib && ret, "Allocator can't find itself.");
tbb::detail::suppress_unused_warning(ret);
SetErrorMode (prev_mode);
#endif /* USE_PTHREAD && !__TBB_SOURCE_DIRECTLY_INCLUDED */
}
Expand Down