From 32e3deace1ef737b3ddad5006437cdda2ac2d261 Mon Sep 17 00:00:00 2001 From: Alexander Shabalin Date: Mon, 11 Jan 2021 20:45:02 +0300 Subject: [PATCH] Enable unused-function warning for runtime (#4628) --- .../jetbrains/kotlin/bitcode/CompileToBitcode.kt | 3 +-- kotlin-native/common/src/hash/cpp/City.cpp | 5 ----- kotlin-native/common/src/hash/cpp/Names.cpp | 12 ------------ kotlin-native/runtime/src/legacymm/cpp/Memory.cpp | 14 +++++++++----- kotlin-native/runtime/src/main/cpp/Exceptions.cpp | 2 ++ kotlin-native/runtime/src/main/cpp/ObjCExport.mm | 11 ----------- 6 files changed, 12 insertions(+), 35 deletions(-) diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcode.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcode.kt index 1cc97443109..d06a8614cec 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcode.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcode.kt @@ -71,7 +71,6 @@ open class CompileToBitcode @Inject constructor( listOfNotNull("-std=c++14", "-Werror", "-O2", "-Wall", "-Wextra", "-Wno-unused-parameter", // False positives with polymorphic functions. - "-Wno-unused-function", // TODO: Enable this warning when we have C++ runtime tests. "-fPIC".takeIf { !HostManager().targetByName(target).isMINGW }) } return commonFlags + languageFlags + compilerArgs @@ -151,4 +150,4 @@ open class CompileToBitcode @Inject constructor( } } } -} \ No newline at end of file +} diff --git a/kotlin-native/common/src/hash/cpp/City.cpp b/kotlin-native/common/src/hash/cpp/City.cpp index cb263dc926f..68470aa774f 100644 --- a/kotlin-native/common/src/hash/cpp/City.cpp +++ b/kotlin-native/common/src/hash/cpp/City.cpp @@ -57,11 +57,6 @@ uint32_t Fetch32(const char *p) { return uint32_in_expected_order(UNALIGNED_LOAD32(p)); } -uint32_t Rotate32(uint32_t val, int shift) { - // Avoid shifting by 32: doing so yields an undefined result. - return shift == 0 ? val : ((val >> shift) | (val << (32 - shift))); -} - // Bitwise right rotate. Normally this will compile to a single // instruction, especially if the shift is a manifest constant. uint64_t Rotate(uint64_t val, int shift) { diff --git a/kotlin-native/common/src/hash/cpp/Names.cpp b/kotlin-native/common/src/hash/cpp/Names.cpp index 182eeef3cc7..3c19b37d476 100644 --- a/kotlin-native/common/src/hash/cpp/Names.cpp +++ b/kotlin-native/common/src/hash/cpp/Names.cpp @@ -23,18 +23,6 @@ namespace { -constexpr uint32_t PrintableHexSize(uint32_t input_length) { - return input_length * 2; -} - -void PrintableHex(const uint8_t* data, uint32_t data_length, char* hex) { - static const char* hex_digits = "0123456789ABCDEF"; - for (uint32_t i = 0; i < data_length; ++i) { - *hex++ = hex_digits[(*data >> 4) & 0xf]; - *hex++ = hex_digits[(*data++) & 0xf]; - } -} - constexpr uint32_t PrintableBase64Size(uint32_t input_length) { return ((input_length + 2) / 3 * 4) + 1; } diff --git a/kotlin-native/runtime/src/legacymm/cpp/Memory.cpp b/kotlin-native/runtime/src/legacymm/cpp/Memory.cpp index 5fd2ab38e73..512fbf84dce 100644 --- a/kotlin-native/runtime/src/legacymm/cpp/Memory.cpp +++ b/kotlin-native/runtime/src/legacymm/cpp/Memory.cpp @@ -798,7 +798,6 @@ namespace { void freeContainer(ContainerHeader* header) NO_INLINE; #if USE_GC void garbageCollect(MemoryState* state, bool force) NO_INLINE; -void cyclicGarbageCollect() NO_INLINE; void rememberNewContainer(ContainerHeader* container); #endif // USE_GC @@ -1017,10 +1016,6 @@ inline FrameOverlay* asFrameOverlay(ObjHeader** slot) { return reinterpret_cast(slot); } -inline bool isRefCounted(KConstRef object) { - return isFreeable(containerFor(object)); -} - inline void lock(KInt* spinlock) { while (compareAndSwap(spinlock, 0, 1) != 0) {} } @@ -1698,6 +1693,7 @@ void collectWhite(MemoryState* state, ContainerHeader* start) { } #endif +#if COLLECT_STATISTIC inline bool needAtomicAccess(ContainerHeader* container) { return container->shareable(); } @@ -1707,6 +1703,7 @@ inline bool canBeCyclic(ContainerHeader* container) { if (container->color() == CONTAINER_TAG_GC_GREEN) return false; return true; } +#endif inline void addHeapRef(ContainerHeader* container) { MEMORY_LOG("AddHeapRef %p: rc=%d\n", container, container->refCount()) @@ -1774,6 +1771,11 @@ inline void releaseHeapRef(const ObjHeader* header) { releaseHeapRef(const_cast(container)); } + +// TODO: Consider removing this unused stuff. +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-function" + // We use first slot as place to store frame-local arena container. // TODO: create ArenaContainer object on the stack, so that we don't // do two allocations per frame (ArenaContainer + actual container). @@ -1800,6 +1802,8 @@ inline size_t containerSize(const ContainerHeader* container) { return result; } +#pragma clang diagnostic pop + #if USE_GC void incrementStack(MemoryState* state) { FrameOverlay* frame = currentFrame; diff --git a/kotlin-native/runtime/src/main/cpp/Exceptions.cpp b/kotlin-native/runtime/src/main/cpp/Exceptions.cpp index a4c8625fcb9..8fd6c4088c8 100644 --- a/kotlin-native/runtime/src/main/cpp/Exceptions.cpp +++ b/kotlin-native/runtime/src/main/cpp/Exceptions.cpp @@ -107,11 +107,13 @@ _Unwind_Reason_Code unwindCallback( THREAD_LOCAL_VARIABLE bool disallowSourceInfo = false; +#if !OMIT_BACKTRACE && !USE_GCC_UNWIND SourceInfo getSourceInfo(KConstRef stackTrace, int index) { return disallowSourceInfo ? SourceInfo { .fileName = nullptr, .lineNumber = -1, .column = -1 } : Kotlin_getSourceInfo(*PrimitiveArrayAddressOfElementAt(stackTrace->array(), index)); } +#endif } // namespace diff --git a/kotlin-native/runtime/src/main/cpp/ObjCExport.mm b/kotlin-native/runtime/src/main/cpp/ObjCExport.mm index ae9ead6feee..9988eaf427a 100644 --- a/kotlin-native/runtime/src/main/cpp/ObjCExport.mm +++ b/kotlin-native/runtime/src/main/cpp/ObjCExport.mm @@ -124,7 +124,6 @@ extern "C" OBJ_GETTER(Kotlin_ObjCExport_AllocInstanceWithAssociatedObject, } static Class getOrCreateClass(const TypeInfo* typeInfo); -static void initializeClass(Class clazz); extern "C" id objc_retainAutoreleaseReturnValue(id self); @@ -768,16 +767,6 @@ static KStdVector getProtocolsAsInterfaces(Class clazz) { return result; } -static const TypeInfo* getMostSpecificKotlinClass(const TypeInfo* typeInfo) { - const TypeInfo* result = typeInfo; - while (getTypeAdapter(result) == nullptr) { - result = result->superType_; - RuntimeAssert(result != nullptr, ""); - } - - return result; -} - static int getVtableSize(const TypeInfo* typeInfo) { for (const TypeInfo* current = typeInfo; current != nullptr; current = current->superType_) { auto typeAdapter = getTypeAdapter(current);