From 87d227ac6fa5696f47c4f8018e91c1d011b1b13b Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Mon, 6 Feb 2023 17:11:20 +0000 Subject: [PATCH] Fix all the conversion warnings --- CMakeLists.txt | 1 - libserene/include/serene/jit/halley.h | 32 +++++-------------------- libserene/include/serene/types/types.h | 3 ++- libserene/lib/jit/halley.cpp | 15 +++++++----- libserene/lib/jit/packer.cpp | 8 +++++-- serene-tblgen/serene/errors-backend.cpp | 10 ++++---- 6 files changed, 29 insertions(+), 40 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d828c5f..03f52ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,7 +99,6 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) -Warray-bounds-pointer-arithmetic -Warray-parameter -Wassign-enum - -Wconversion -Wsign-conversion -Wnon-virtual-dtor -Wold-style-cast diff --git a/libserene/include/serene/jit/halley.h b/libserene/include/serene/jit/halley.h index c2edac0..e437662 100644 --- a/libserene/include/serene/jit/halley.h +++ b/libserene/include/serene/jit/halley.h @@ -71,42 +71,22 @@ namespace llvm { class DataLayout; -} // namespace llvm -namespace llvm { class JITEventListener; -} // namespace llvm -namespace llvm { class Module; -} // namespace llvm -namespace llvm { namespace orc { class JITDylib; -} +} // namespace orc } // namespace llvm + namespace serene { namespace fs { enum class NSFileType; -} -} // namespace serene -namespace serene { -namespace jit { -class Halley; -} -} // namespace serene -namespace serene { -namespace types { -struct InternalString; -} -} // namespace serene -namespace serene { +} // namespace fs namespace types { struct Namespace; -} -} // namespace serene -namespace serene { -namespace types { struct Symbol; -} +struct InternalString; +} // namespace types } // namespace serene #define HALLEY_LOG(...) \ @@ -117,7 +97,7 @@ struct Symbol; namespace serene { namespace jit { - +class Halley; // Why? This is the lazy man's way to make it easier to replace // the class under the hood later on to test different implementaion // with the same interface diff --git a/libserene/include/serene/types/types.h b/libserene/include/serene/types/types.h index e80128c..7b4ecd7 100644 --- a/libserene/include/serene/types/types.h +++ b/libserene/include/serene/types/types.h @@ -19,6 +19,7 @@ #ifndef SERENE_TYPES_TYPE_H #define SERENE_TYPES_TYPE_H +#include namespace serene::types { // ============================================================================ @@ -38,7 +39,7 @@ struct Expression { struct InternalString { // We store the actual string in a "string" data section const char *data; - unsigned int len; + size_t len; InternalString(const char *data, const unsigned int len) : data(data), len(len){}; diff --git a/libserene/lib/jit/halley.cpp b/libserene/lib/jit/halley.cpp index 1802e9c..9062f75 100644 --- a/libserene/lib/jit/halley.cpp +++ b/libserene/lib/jit/halley.cpp @@ -366,11 +366,12 @@ const types::InternalString &Halley::getInternalString(const char *s) { assert(s && "s is nullptr: getInternalString"); auto len = std::strlen(s); - auto *str = (types::InternalString *)GC_MALLOC(sizeof(types::InternalString)); + auto *str = static_cast( + GC_MALLOC(sizeof(types::InternalString))); // str->data = (char *)GC_MALLOC_ATOMIC(len); // memcpy((void *)str->data, (void *)s, len); - memcpy((void *)str, (const void *)s, len); + memcpy(static_cast(str), static_cast(s), len); str->len = len; stringStorage.push_back(str); @@ -384,8 +385,9 @@ types::Namespace &Halley::makeNamespace(const char *name) { // randomly build instances here and there that causes unsafe memory assert(name && "name is nullptr: createNamespace"); const auto &nsName = getInternalString(name); - auto *ns = (types::Namespace *)GC_MALLOC(sizeof(types::Namespace)); - ns->name = &nsName; + auto *ns = + static_cast(GC_MALLOC(sizeof(types::Namespace))); + ns->name = &nsName; nsStorage.push_back(ns); return *ns; @@ -433,7 +435,7 @@ MaybeJitAddress Halley::lookup(const char *nsName, const char *sym) const { return tempError(*ctx, "No dylib " + s); } - HALLEY_LOG("Looking in dylib: " << (void *)dylib); + HALLEY_LOG("Looking in dylib: " << static_cast(dylib)); auto expectedSymbol = engine->lookup(*dylib, fqsym); // JIT lookup may return an Error referring to strings stored internally by @@ -452,7 +454,8 @@ MaybeJitAddress Halley::lookup(const char *nsName, const char *sym) const { return tempError(*ctx, "Lookup function is null!"); } - HALLEY_LOG("Found symbol '" << fqsym << "' at " << (void *)fptr); + HALLEY_LOG("Found symbol '" << fqsym << "' at " + << static_cast(&fptr)); return fptr; }; diff --git a/libserene/lib/jit/packer.cpp b/libserene/lib/jit/packer.cpp index cfd4d4b..2bddac5 100644 --- a/libserene/lib/jit/packer.cpp +++ b/libserene/lib/jit/packer.cpp @@ -38,6 +38,7 @@ #include // for Value #include // for cast +#include // for uint64_t namespace serene::jit { std::string makePackedFunctionName(llvm::StringRef name) { @@ -75,7 +76,8 @@ void packFunctionArguments(llvm::Module *module) { builder.SetInsertPoint(bb); llvm::Value *argList = interfaceFunc->arg_begin(); llvm::SmallVector args; - args.reserve(llvm::size(func.args())); + + args.reserve(static_cast(llvm::size(func.args()))); for (const auto &indexedArg : llvm::enumerate(func.args())) { llvm::Value *argIndex = llvm::Constant::getIntegerValue( builder.getInt64Ty(), llvm::APInt(I64_SIZE, indexedArg.index())); @@ -95,7 +97,9 @@ void packFunctionArguments(llvm::Module *module) { // Assuming the result is one value, potentially of type `void`. if (!result->getType()->isVoidTy()) { llvm::Value *retIndex = llvm::Constant::getIntegerValue( - builder.getInt64Ty(), llvm::APInt(I64_SIZE, llvm::size(func.args()))); + builder.getInt64Ty(), + llvm::APInt(I64_SIZE, + static_cast(llvm::size(func.args())))); llvm::Value *retPtrPtr = builder.CreateGEP(builder.getInt8PtrTy(), argList, retIndex); llvm::Value *retPtr = diff --git a/serene-tblgen/serene/errors-backend.cpp b/serene-tblgen/serene/errors-backend.cpp index 33762b3..54aa7b6 100644 --- a/serene-tblgen/serene/errors-backend.cpp +++ b/serene-tblgen/serene/errors-backend.cpp @@ -103,14 +103,15 @@ void ErrorsBackend::createNSBody(llvm::raw_ostream &os) { os << "#ifdef GET_CLASS_DEFS\n"; inNamespace("serene::errors", os, [&](llvm::raw_ostream &os) { os << "enum ErrorType {\n"; - for (size_t i = 0; i < indexList->size(); i++) { + for (unsigned int i = 0; i < static_cast(indexList->size()); + i++) { llvm::Record *defRec = indexList->getElementAsRecord(i); if (!defRec->isSubClassOf("Error")) { continue; } - createErrorClass(i, *defRec, os); + createErrorClass(static_cast(i), *defRec, os); } os << "};\n\n"; @@ -119,8 +120,9 @@ void ErrorsBackend::createNSBody(llvm::raw_ostream &os) { << "] = {\n"; for (size_t i = 0; i < indexList->size(); i++) { - llvm::Record *defRec = indexList->getElementAsRecord(i); - auto recName = defRec->getName(); + llvm::Record *defRec = + indexList->getElementAsRecord(static_cast(i)); + auto recName = defRec->getName(); if (!defRec->isSubClassOf("Error")) { continue;