Fix all the conversion warnings

This commit is contained in:
Sameer Rahmani 2023-02-06 17:11:20 +00:00
parent dc746f7a8c
commit 87d227ac6f
Signed by: lxsameer
GPG Key ID: B0A4AF28AB9FD90B
6 changed files with 29 additions and 40 deletions

View File

@ -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

View File

@ -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

View File

@ -19,6 +19,7 @@
#ifndef SERENE_TYPES_TYPE_H
#define SERENE_TYPES_TYPE_H
#include <cstddef>
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){};

View File

@ -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<types::InternalString *>(
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<void *>(str), static_cast<const void *>(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<types::Namespace *>(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<void *>(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<void *>(&fptr));
return fptr;
};

View File

@ -38,6 +38,7 @@
#include <llvm/IR/Value.h> // for Value
#include <llvm/Support/Casting.h> // for cast
#include <stdint.h> // 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<llvm::Value *, COMMON_ARGS_COUNT> args;
args.reserve(llvm::size(func.args()));
args.reserve(static_cast<unsigned long>(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<uint64_t>(llvm::size(func.args()))));
llvm::Value *retPtrPtr =
builder.CreateGEP(builder.getInt8PtrTy(), argList, retIndex);
llvm::Value *retPtr =

View File

@ -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<unsigned int>(indexList->size());
i++) {
llvm::Record *defRec = indexList->getElementAsRecord(i);
if (!defRec->isSubClassOf("Error")) {
continue;
}
createErrorClass(i, *defRec, os);
createErrorClass(static_cast<int>(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<unsigned int>(i));
auto recName = defRec->getName();
if (!defRec->isSubClassOf("Error")) {
continue;