Compile cpp code with -Wall (#4310)
-Wunused-function is temporarily disabled because it conflicts with interesting but unused functions. When we will have C++ tests on runtime, these interesting functions will get tested and so stop being unused.
This commit is contained in:
committed by
GitHub
parent
c272ab5e05
commit
7fc66d316d
@@ -67,6 +67,8 @@ open class CompileToBitcode @Inject constructor(@InputDirectory val srcRoot: Fil
|
|||||||
"-Werror", "-ftls-model=initial-exec", "-Wno-unused-function")
|
"-Werror", "-ftls-model=initial-exec", "-Wno-unused-function")
|
||||||
Language.CPP ->
|
Language.CPP ->
|
||||||
listOfNotNull("-std=c++14", "-Werror", "-O2",
|
listOfNotNull("-std=c++14", "-Werror", "-O2",
|
||||||
|
"-Wall",
|
||||||
|
"-Wno-unused-function", // TODO: Enable this warning when we have C++ runtime tests.
|
||||||
"-fPIC".takeIf { !HostManager().targetByName(target).isMINGW })
|
"-fPIC".takeIf { !HostManager().targetByName(target).isMINGW })
|
||||||
}
|
}
|
||||||
return commonFlags + languageFlags + compilerArgs
|
return commonFlags + languageFlags + compilerArgs
|
||||||
|
|||||||
@@ -136,7 +136,11 @@ int DecodeBase64(
|
|||||||
size_t buf = 0, len = 0;
|
size_t buf = 0, len = 0;
|
||||||
|
|
||||||
while (in < end) {
|
while (in < end) {
|
||||||
unsigned char c = kDecode[*in++];
|
// char may be a signed type. Explicitly convert it to an unsigned byte,
|
||||||
|
// so that indexing into kDecode array is safe. The latter has exactly
|
||||||
|
// 256 elements, so any unsigned byte value is valid.
|
||||||
|
uint8_t index = *in++;
|
||||||
|
unsigned char c = kDecode[index];
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case WHITESPACE: continue; /* skip whitespace */
|
case WHITESPACE: continue; /* skip whitespace */
|
||||||
|
|||||||
@@ -26,10 +26,6 @@ static const uint64_t k0 = 0xc3a5c85c97cb3127ULL;
|
|||||||
static const uint64_t k1 = 0xb492b66fbe98f273ULL;
|
static const uint64_t k1 = 0xb492b66fbe98f273ULL;
|
||||||
static const uint64_t k2 = 0x9ae16a3b2f90404fULL;
|
static const uint64_t k2 = 0x9ae16a3b2f90404fULL;
|
||||||
|
|
||||||
// Magic numbers for 32-bit hashing. Copied from Murmur3.
|
|
||||||
static const uint32_t c1 = 0xcc9e2d51;
|
|
||||||
static const uint32_t c2 = 0x1b873593;
|
|
||||||
|
|
||||||
uint64_t UNALIGNED_LOAD64(const char *p) {
|
uint64_t UNALIGNED_LOAD64(const char *p) {
|
||||||
uint64_t result;
|
uint64_t result;
|
||||||
memcpy(&result, p, sizeof(result));
|
memcpy(&result, p, sizeof(result));
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ constexpr uint32_t PrintableHexSize(uint32_t input_length) {
|
|||||||
|
|
||||||
void PrintableHex(const uint8_t* data, uint32_t data_length, char* hex) {
|
void PrintableHex(const uint8_t* data, uint32_t data_length, char* hex) {
|
||||||
static const char* hex_digits = "0123456789ABCDEF";
|
static const char* hex_digits = "0123456789ABCDEF";
|
||||||
int i = 0;
|
|
||||||
for(int i = 0; i < data_length; ++i) {
|
for(int i = 0; i < data_length; ++i) {
|
||||||
*hex++ = hex_digits[(*data >> 4) & 0xf];
|
*hex++ = hex_digits[(*data >> 4) & 0xf];
|
||||||
*hex++ = hex_digits[(*data++) & 0xf];
|
*hex++ = hex_digits[(*data++) & 0xf];
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ OBJ_GETTER(utf8ToUtf16Impl, const char* rawString, const char* end, uint32_t cha
|
|||||||
if (rawString == nullptr) RETURN_OBJ(nullptr);
|
if (rawString == nullptr) RETURN_OBJ(nullptr);
|
||||||
ArrayHeader* result = AllocArrayInstance(theStringTypeInfo, charCount, OBJ_RESULT)->array();
|
ArrayHeader* result = AllocArrayInstance(theStringTypeInfo, charCount, OBJ_RESULT)->array();
|
||||||
KChar* rawResult = CharArrayAddressOfElementAt(result, 0);
|
KChar* rawResult = CharArrayAddressOfElementAt(result, 0);
|
||||||
auto convertResult = conversion(rawString, end, rawResult);
|
conversion(rawString, end, rawResult);
|
||||||
RETURN_OBJ(result->obj());
|
RETURN_OBJ(result->obj());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1091,7 +1091,6 @@ KInt Kotlin_String_lastIndexOfChar(KString thiz, KChar ch, KInt fromIndex) {
|
|||||||
if (fromIndex >= thiz->count_) {
|
if (fromIndex >= thiz->count_) {
|
||||||
fromIndex = thiz->count_ - 1;
|
fromIndex = thiz->count_ - 1;
|
||||||
}
|
}
|
||||||
KInt count = thiz->count_;
|
|
||||||
KInt index = fromIndex;
|
KInt index = fromIndex;
|
||||||
const KChar* thizRaw = CharArrayAddressOfElementAt(thiz, index);
|
const KChar* thizRaw = CharArrayAddressOfElementAt(thiz, index);
|
||||||
while (index >= 0) {
|
while (index >= 0) {
|
||||||
@@ -1116,7 +1115,6 @@ KInt Kotlin_String_indexOfString(KString thiz, KString other, KInt fromIndex) {
|
|||||||
if (other->count_ == 0) {
|
if (other->count_ == 0) {
|
||||||
return fromIndex;
|
return fromIndex;
|
||||||
}
|
}
|
||||||
KInt count = thiz->count_;
|
|
||||||
const KChar* thizRaw = CharArrayAddressOfElementAt(thiz, fromIndex);
|
const KChar* thizRaw = CharArrayAddressOfElementAt(thiz, fromIndex);
|
||||||
const KChar* otherRaw = CharArrayAddressOfElementAt(other, 0);
|
const KChar* otherRaw = CharArrayAddressOfElementAt(other, 0);
|
||||||
void* result = konan::memmem(thizRaw, (thiz->count_ - fromIndex) * sizeof(KChar),
|
void* result = konan::memmem(thizRaw, (thiz->count_ - fromIndex) * sizeof(KChar),
|
||||||
|
|||||||
@@ -119,13 +119,18 @@ typedef KStdUnorderedMap<void**, std::pair<KRef*,int>> KThreadLocalStorageMap;
|
|||||||
// Prevents clang from replacing FrameOverlay struct
|
// Prevents clang from replacing FrameOverlay struct
|
||||||
// with single pointer.
|
// with single pointer.
|
||||||
// Can be removed when FrameOverlay will become more complex.
|
// Can be removed when FrameOverlay will become more complex.
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||||
FrameOverlay exportFrameOverlay;
|
FrameOverlay exportFrameOverlay;
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
|
||||||
// Current number of allocated containers.
|
// Current number of allocated containers.
|
||||||
volatile int allocCount = 0;
|
volatile int allocCount = 0;
|
||||||
volatile int aliveMemoryStatesCount = 0;
|
volatile int aliveMemoryStatesCount = 0;
|
||||||
|
|
||||||
|
#if USE_CYCLIC_GC
|
||||||
KBoolean g_hasCyclicCollector = true;
|
KBoolean g_hasCyclicCollector = true;
|
||||||
|
#endif // USE_CYCLIC_GC
|
||||||
|
|
||||||
// TODO: can we pass this variable as an explicit argument?
|
// TODO: can we pass this variable as an explicit argument?
|
||||||
THREAD_LOCAL_VARIABLE MemoryState* memoryState = nullptr;
|
THREAD_LOCAL_VARIABLE MemoryState* memoryState = nullptr;
|
||||||
@@ -980,7 +985,7 @@ void freeContainer(ContainerHeader* container) {
|
|||||||
runDeallocationHooks(container);
|
runDeallocationHooks(container);
|
||||||
|
|
||||||
// Now let's clean all object's fields in this container.
|
// Now let's clean all object's fields in this container.
|
||||||
traverseContainerObjectFields(container, [container](ObjHeader** location) {
|
traverseContainerObjectFields(container, [](ObjHeader** location) {
|
||||||
ZeroHeapRef(location);
|
ZeroHeapRef(location);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1017,7 +1022,7 @@ void depthFirstTraversal(ContainerHeader* start, bool* hasCycles,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
toVisit.push_front(markAsRemoved(container));
|
toVisit.push_front(markAsRemoved(container));
|
||||||
traverseContainerReferredObjects(container, [container, hasCycles, firstBlocker, &order, &toVisit](ObjHeader* obj) {
|
traverseContainerReferredObjects(container, [container, hasCycles, firstBlocker, &toVisit](ObjHeader* obj) {
|
||||||
if (*firstBlocker != nullptr)
|
if (*firstBlocker != nullptr)
|
||||||
return;
|
return;
|
||||||
if (obj->has_meta_object() && ((obj->meta_object()->flags_ & MF_NEVER_FROZEN) != 0)) {
|
if (obj->has_meta_object() && ((obj->meta_object()->flags_ & MF_NEVER_FROZEN) != 0)) {
|
||||||
@@ -1426,7 +1431,7 @@ void collectWhite(MemoryState* state, ContainerHeader* start) {
|
|||||||
toVisit.pop_front();
|
toVisit.pop_front();
|
||||||
if (container->color() != CONTAINER_TAG_GC_WHITE || container->buffered()) continue;
|
if (container->color() != CONTAINER_TAG_GC_WHITE || container->buffered()) continue;
|
||||||
container->setColorAssertIfGreen(CONTAINER_TAG_GC_BLACK);
|
container->setColorAssertIfGreen(CONTAINER_TAG_GC_BLACK);
|
||||||
traverseContainerObjectFields(container, [state, &toVisit](ObjHeader** location) {
|
traverseContainerObjectFields(container, [&toVisit](ObjHeader** location) {
|
||||||
auto* ref = *location;
|
auto* ref = *location;
|
||||||
if (ref == nullptr) return;
|
if (ref == nullptr) return;
|
||||||
auto* childContainer = ref->container();
|
auto* childContainer = ref->container();
|
||||||
@@ -1610,7 +1615,9 @@ void decrementStack(MemoryState* state) {
|
|||||||
void garbageCollect(MemoryState* state, bool force) {
|
void garbageCollect(MemoryState* state, bool force) {
|
||||||
RuntimeAssert(!state->gcInProgress, "Recursive GC is disallowed");
|
RuntimeAssert(!state->gcInProgress, "Recursive GC is disallowed");
|
||||||
|
|
||||||
|
#if TRACE_GC
|
||||||
uint64_t allocSinceLastGc = state->allocSinceLastGc;
|
uint64_t allocSinceLastGc = state->allocSinceLastGc;
|
||||||
|
#endif // TRACE_GC
|
||||||
state->allocSinceLastGc = 0;
|
state->allocSinceLastGc = 0;
|
||||||
|
|
||||||
if (!IsStrictMemoryModel) {
|
if (!IsStrictMemoryModel) {
|
||||||
@@ -2493,7 +2500,7 @@ void freezeAcyclic(ContainerHeader* rootContainer, ContainerHeaderSet* newlyFroz
|
|||||||
newlyFrozen->insert(current);
|
newlyFrozen->insert(current);
|
||||||
MEMORY_LOG("freezing %p\n", current)
|
MEMORY_LOG("freezing %p\n", current)
|
||||||
current->freeze();
|
current->freeze();
|
||||||
traverseContainerReferredObjects(current, [current, &queue](ObjHeader* obj) {
|
traverseContainerReferredObjects(current, [&queue](ObjHeader* obj) {
|
||||||
ContainerHeader* objContainer = obj->container();
|
ContainerHeader* objContainer = obj->container();
|
||||||
if (canFreeze(objContainer)) {
|
if (canFreeze(objContainer)) {
|
||||||
if (objContainer->marked())
|
if (objContainer->marked())
|
||||||
|
|||||||
@@ -799,8 +799,6 @@ static void throwIfCantBeOverridden(Class clazz, const KotlinToObjCMethodAdapter
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const TypeInfo* createTypeInfo(Class clazz, const TypeInfo* superType, const TypeInfo* fieldsInfo) {
|
static const TypeInfo* createTypeInfo(Class clazz, const TypeInfo* superType, const TypeInfo* fieldsInfo) {
|
||||||
Class superClass = class_getSuperclass(clazz);
|
|
||||||
|
|
||||||
KStdUnorderedSet<SEL> definedSelectors;
|
KStdUnorderedSet<SEL> definedSelectors;
|
||||||
addDefinedSelectors(clazz, definedSelectors);
|
addDefinedSelectors(clazz, definedSelectors);
|
||||||
|
|
||||||
@@ -913,7 +911,7 @@ static const TypeInfo* createTypeInfo(Class clazz, const TypeInfo* superType, co
|
|||||||
auto interfaceVTablesIt = interfaceVTables.find(interfaceId);
|
auto interfaceVTablesIt = interfaceVTables.find(interfaceId);
|
||||||
if (interfaceVTablesIt == interfaceVTables.end()) {
|
if (interfaceVTablesIt == interfaceVTables.end()) {
|
||||||
itableEqualsSuper = false;
|
itableEqualsSuper = false;
|
||||||
interfaceVTables.emplace(interfaceId, std::move(KStdVector<VTableElement>(interfaceVTableSize)));
|
interfaceVTables.emplace(interfaceId, KStdVector<VTableElement>(interfaceVTableSize));
|
||||||
} else {
|
} else {
|
||||||
auto const& interfaceVTable = interfaceVTablesIt->second;
|
auto const& interfaceVTable = interfaceVTablesIt->second;
|
||||||
RuntimeAssert(interfaceVTable.size() == interfaceVTableSize, "");
|
RuntimeAssert(interfaceVTable.size() == interfaceVTableSize, "");
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ int getLastErrorMessage(char* message, uint32_t size) {
|
|||||||
auto errMsgBufSize = size / 4;
|
auto errMsgBufSize = size / 4;
|
||||||
wchar_t errMsgBuffer[errMsgBufSize];
|
wchar_t errMsgBuffer[errMsgBufSize];
|
||||||
::FormatMessageW(flags, NULL, errCode, 0, errMsgBuffer, errMsgBufSize, NULL);
|
::FormatMessageW(flags, NULL, errCode, 0, errMsgBuffer, errMsgBufSize, NULL);
|
||||||
auto errMsgLength = ::WideCharToMultiByte(CP_UTF8, 0, errMsgBuffer, -1, message, size, NULL, NULL);
|
::WideCharToMultiByte(CP_UTF8, 0, errMsgBuffer, -1, message, size, NULL, NULL);
|
||||||
}
|
}
|
||||||
return errCode;
|
return errCode;
|
||||||
}
|
}
|
||||||
@@ -108,7 +108,6 @@ int32_t consoleReadUtf8(void* utf8, uint32_t maxSizeBytes) {
|
|||||||
if (!length && KonanNeedDebugInfo) {
|
if (!length && KonanNeedDebugInfo) {
|
||||||
char msg[512];
|
char msg[512];
|
||||||
auto errCode = getLastErrorMessage(msg, sizeof(msg));
|
auto errCode = getLastErrorMessage(msg, sizeof(msg));
|
||||||
char buffer[1024];
|
|
||||||
consoleErrorf("UTF-16 to UTF-8 conversion error %d: %s", errCode, msg);
|
consoleErrorf("UTF-16 to UTF-8 conversion error %d: %s", errCode, msg);
|
||||||
}
|
}
|
||||||
((char*) utf8)[length] = 0;
|
((char*) utf8)[length] = 0;
|
||||||
|
|||||||
@@ -165,11 +165,6 @@ class Worker {
|
|||||||
pthread_t thread_ = 0;
|
pthread_t thread_ = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#else // WITH_WORKERS
|
|
||||||
class Worker {
|
|
||||||
KInt id;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // WITH_WORKERS
|
#endif // WITH_WORKERS
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -407,7 +402,6 @@ class State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
OBJ_GETTER(getWorkerNameUnlocked, KInt id) {
|
OBJ_GETTER(getWorkerNameUnlocked, KInt id) {
|
||||||
Worker* worker = nullptr;
|
|
||||||
ObjHolder nameHolder;
|
ObjHolder nameHolder;
|
||||||
{
|
{
|
||||||
Locker locker(&lock_);
|
Locker locker(&lock_);
|
||||||
@@ -566,7 +560,6 @@ KInt currentWorker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
KInt execute(KInt id, KInt transferMode, KRef producer, KNativePtr jobFunction) {
|
KInt execute(KInt id, KInt transferMode, KRef producer, KNativePtr jobFunction) {
|
||||||
Job job;
|
|
||||||
ObjHolder holder;
|
ObjHolder holder;
|
||||||
WorkerLaunchpad(producer, holder.slot());
|
WorkerLaunchpad(producer, holder.slot());
|
||||||
KNativePtr jobArgument = transfer(&holder, transferMode);
|
KNativePtr jobArgument = transfer(&holder, transferMode);
|
||||||
|
|||||||
Reference in New Issue
Block a user