Skip to content

Commit

Permalink
add additional compiler warning and cleanup code (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGrulich authored Sep 14, 2024
1 parent 92c44dc commit ae705b6
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 75 deletions.
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ project(nautilus VERSION 0.1)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Werror=extra -Werror=all -fpermissive -fPIC -fno-omit-frame-pointer")

set(CMAKE_CXX_WARNINGS "-Wall -Wextra -pedantic-errors -Werror=extra-semi -Werror=extra -Werror=all -Werror=delete-non-virtual-dtor -Werror=deprecated -Werror=array-bounds -Werror=ignored-qualifiers -Werror=sign-compare")

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_WARNINGS "${CMAKE_CXX_WARNINGS} -Wpedantic-macros -Werror=integer-overflow -Werror=return-type -Werror=return-stack-address -Werror=writable-strings")
else ()
set(CMAKE_CXX_WARNINGS "${CMAKE_CXX_WARNINGS} -Woverflow -Werror=return-type -Werror=return-local-addr -Werror=write-strings")
endif ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_WARNINGS} -fpermissive -fPIC -fno-omit-frame-pointer")

if (ENABLE_TEST_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcoverage-mapping -fprofile-instr-generate")
Expand Down
6 changes: 3 additions & 3 deletions nautilus/include/nautilus/Executable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class Executable {
public:
using FunctionType = R(Args...);

explicit Invocable(void* fptr) : function(reinterpret_cast<FunctionType*>(fptr)) {};
explicit Invocable(void* fptr) : function(reinterpret_cast<FunctionType*>(fptr)) {}

explicit Invocable(std::unique_ptr<GenericInvocable> generic) : function(std::move(generic)) {};
explicit Invocable(std::unique_ptr<GenericInvocable> generic) : function(std::move(generic)) {}

template <typename T>
requires(std::is_fundamental_v<T> || std::is_fundamental_v<std::remove_cvref_t<T>>)
Expand Down Expand Up @@ -132,7 +132,7 @@ class Executable {
*/
virtual std::unique_ptr<GenericInvocable> getGenericInvocable(const std::string&) {
return nullptr;
};
}
};

} // namespace nautilus::compiler
4 changes: 1 addition & 3 deletions nautilus/include/nautilus/function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,9 @@ class MemberFuncWrapperImpl : public MemberFuncWrapper {
MemberFuncWrapperImpl(T func)
: func(func), callableRuntimeFunction(function(+[](MemberFuncWrapper* ptr, Tp* clazzPtr) -> auto {
auto p = static_cast<MemberFuncWrapperImpl<T, Rp, Tp>*>(ptr);
// return p->func(clazzPtr);
Rp (Tp::*func)() = p->func;
return (*clazzPtr.*func)();
// return std::invoke(p->func, clazzPtr);
})) {};
})) {}

template <typename... FunctionArgumentsRaw>
auto operator()(FunctionArgumentsRaw... args) {
Expand Down
19 changes: 11 additions & 8 deletions nautilus/include/nautilus/static.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class alignas(64) static_val {

static_val() {
tracing::pushStaticVal(&value);
};
}

static_val(T v) : value(v) {
tracing::pushStaticVal((void*) &value);
};
}

static_val(const static_val& other) : static_val((T) other) {
}
Expand Down Expand Up @@ -91,6 +91,10 @@ class alignas(64) static_val {
return value == other;
}

bool operator!=(const T& other) const {
return value != other;
}

bool operator>(const T& other) const {
return value > other;
}
Expand Down Expand Up @@ -139,15 +143,14 @@ class static_iterator {
return tmp;
}

bool operator==(const static_iterator& other) {
val = val + 1;
return m_iterator == other.m_iterator;
// Define comparison operators as friends to control their argument order
friend bool operator==(const static_iterator& lhs, const static_iterator& rhs) {
return lhs.m_iterator == rhs.m_iterator;
}

bool operator!=(const static_iterator& other) const {
return !(*this == other);
friend bool operator!=(const static_iterator& lhs, const static_iterator& rhs) {
return lhs.m_iterator != rhs.m_iterator;
}

private:
static_val<int64_t> val;
Iterator m_iterator;
Expand Down
3 changes: 2 additions & 1 deletion nautilus/include/nautilus/std/ostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ val<std::basic_ostream<_CharT, _Traits>>& flush(val<std::basic_ostream<_CharT, _
template <class CharT, class Traits>
class val<std::basic_ostream<CharT, Traits>> {
public:
explicit val(val<std::basic_ostream<CharT, Traits>*> stream) : stream(stream) {};
explicit val(val<std::basic_ostream<CharT, Traits>*> stream) : stream(stream) {
}
template <class _CharT, class _Traits>
val(val<std::basic_ostream<_CharT, _Traits>>& other) : stream(other.stream) {
}
Expand Down
2 changes: 1 addition & 1 deletion nautilus/include/nautilus/std/sstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class val<std::basic_stringstream<CharT, Traits, Allocator>> : public val<std::b
},
this->stream);
return val<std::basic_string<CharT, Traits>>(str_ptr);
};
}

~val() {
invoke(
Expand Down
7 changes: 6 additions & 1 deletion nautilus/include/nautilus/std/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class val<std::basic_string<CharT, Traits>> {
val(const CharT* s) : val(val<const CharT*>(s)) {
}

val<std::basic_string<CharT, Traits>>& operator=(const val<std::basic_string<CharT, Traits>>& other) {
this->data_ptr = other.data_ptr;
return *this;
}

val<CharT> at(val<size_type> pos) {
return invoke(
+[](base_type* ptr, size_type p) -> CharT { return ptr->at(p); }, data_ptr, pos);
Expand Down Expand Up @@ -259,7 +264,7 @@ class val<std::basic_string<CharT, Traits>> {
auto ptr = std::move(data_ptr);
data_ptr = nullptr;
return ptr;
};
}

private:
val<base_type*> data_ptr;
Expand Down
42 changes: 21 additions & 21 deletions nautilus/include/nautilus/val.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,20 @@ class val<ValueType> {
using basic_type = ValueType;

#ifdef ENABLE_TRACING
val() : state(tracing::traceConstant(0)) {};
val(ValueType value) : state(tracing::traceConstant(value)), value(value) {};
val() : state(tracing::traceConstant(0)) {}
val(ValueType value) : state(tracing::traceConstant(value)), value(value) {}
// copy constructor
val(const val<ValueType>& other) : state(tracing::traceCopy(other.state)), value(other.value) {};
val(const val<ValueType>& other) : state(tracing::traceCopy(other.state)), value(other.value) {}
// move constructor
val(const val<ValueType>&& other) noexcept : state(std::move(other.state)), value(other.value) {};
val(tracing::value_ref& tc) : state(tc), value() {};
val(const val<ValueType>&& other) noexcept : state(std::move(other.state)), value(other.value) {}
val(tracing::value_ref& tc) : state(tc), value() {}
#else
val() {};
val(ValueType value) : value(value) {};
val() {}
val(ValueType value) : value(value) {}
// copy constructor
val(const val<ValueType>& other) : value(other.value) {};
val(const val<ValueType>& other) : value(other.value) {}
// move constructor
val(const val<ValueType>&& other) : value(other.value) {};
val(const val<ValueType>&& other) : value(other.value) {}
#endif

val<ValueType>& operator=(const val<ValueType>& other) {
Expand All @@ -116,7 +116,7 @@ class val<ValueType> {
#endif
this->value = other.value;
return *this;
};
}

template <typename OtherType>
requires std::is_convertible_v<ValueType, OtherType>
Expand Down Expand Up @@ -234,21 +234,21 @@ class val<bool> {

#ifdef ENABLE_TRACING

val() : state(tracing::traceConstant(0)), value(false) {};
val(bool value) : state(tracing::traceConstant(value)), value(value) {};
val() : state(tracing::traceConstant(0)), value(false) {}
val(bool value) : state(tracing::traceConstant(value)), value(value) {}
// copy constructor
val(const val<bool>& other) : state(tracing::traceCopy(other.state)), value(other.value) {};
val(const val<bool>& other) : state(tracing::traceCopy(other.state)), value(other.value) {}
// move constructor
val(const val<bool>&& other) : state(other.state), value(other.value) {};
val(tracing::value_ref& tc) : state(tc) {};
val(const val<bool>&& other) : state(other.state), value(other.value) {}
val(tracing::value_ref& tc) : state(tc) {}

#else
val() {};
val(bool value) : value(value) {};
val() {}
val(bool value) : value(value) {}
// copy constructor
val(const val<bool>& other) : value(other.value) {};
val(const val<bool>& other) : value(other.value) {}
// move constructor
val(const val<bool>&& other) : value(other.value) {};
val(const val<bool>&& other) : value(other.value) {}
#endif

val<bool>& operator=(const val<bool>& other) {
Expand All @@ -261,7 +261,7 @@ class val<bool> {

this->value = other.value;
return *this;
};
}

operator bool() const {
if SHOULD_TRACE () {
Expand All @@ -279,7 +279,7 @@ class val<bool> {
template <is_fundamental_val Type>
auto inline&& make_value(Type&& value) {
return std::forward<Type>(value);
};
}

template <convertible_to_fundamental Type>
auto inline make_value(const Type& value) {
Expand Down
18 changes: 9 additions & 9 deletions nautilus/include/nautilus/val_enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ class val<T> {
using raw_type = underlying_type_t;
using basic_type = raw_type;

val() : value() {};
val() : value() {}

#ifdef ENABLE_TRACING
val(val<underlying_type_t> t) : state(t.state), value((T) details::getRawValue(t)) {};
val(val<T>& t) : state(tracing::traceCopy(t.state)), value(t.value) {};
val(val<T>&& t) : state(t.state), value(t.value) {};
val(T val) : state(tracing::traceConstant((underlying_type_t) val)), value(val) {};
val(val<underlying_type_t> t) : state(t.state), value((T) details::getRawValue(t)) {}
val(val<T>& t) : state(tracing::traceCopy(t.state)), value(t.value) {}
val(val<T>&& t) : state(t.state), value(t.value) {}
val(T val) : state(tracing::traceConstant((underlying_type_t) val)), value(val) {}
#else
val(val<underlying_type_t> t) : value((T) details::getRawValue(t)) {};
val(val<T>& t) : value(t.value) {};
val(T val) : value(val) {};
val(val<underlying_type_t> t) : value((T) details::getRawValue(t)) {}
val(val<T>& t) : value(t.value) {}
val(T val) : value(val) {}
#endif

operator val<underlying_type_t>() const {
Expand All @@ -45,7 +45,7 @@ class val<T> {
#endif
this->value = other.value;
return *this;
};
}

#ifdef ENABLE_TRACING
tracing::TypedValueRefHolder state;
Expand Down
36 changes: 18 additions & 18 deletions nautilus/include/nautilus/val_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class val<ValueType> {
const tracing::TypedValueRefHolder state;
#endif
#ifdef ENABLE_TRACING
val(ValueType ref) : state(tracing::value_ref()), ptr(&ref) {};
val(ValueType ref, tracing::value_ref value_ref) : state(value_ref), ptr(&ref) {};
val(val<ptrType> ptr, tracing::value_ref ref) : state(ref), ptr(ptr) {};
val(ValueType ref) : state(tracing::value_ref()), ptr(&ref) {}
val(ValueType ref, tracing::value_ref value_ref) : state(value_ref), ptr(&ref) {}
val(val<ptrType> ptr, tracing::value_ref ref) : state(ref), ptr(ptr) {}
#else
val(ValueType ref) : ptr(&ref) {};
val(val<ptrType> ptr) : ptr(ptr) {};
val(ValueType ref) : ptr(&ref) {}
val(val<ptrType> ptr) : ptr(ptr) {}
#endif

template <class T>
Expand Down Expand Up @@ -80,16 +80,16 @@ class base_ptr_val {
using basic_type = std::remove_pointer_t<ValuePtrType>;
using pointer_type = ValuePtrType;

base_ptr_val() : value() {};
base_ptr_val() : value() {}
#ifdef ENABLE_TRACING
base_ptr_val(ValuePtrType ptr) : state(tracing::traceConstant((void*) ptr)), value(ptr) {};
base_ptr_val(ValuePtrType ptr, tracing::value_ref tc) : state(tc), value(ptr) {};
base_ptr_val(ValuePtrType ptr, tracing::TypedValueRefHolder tc) : state(std::move(tc)), value(ptr) {};
base_ptr_val(ValuePtrType ptr) : state(tracing::traceConstant((void*) ptr)), value(ptr) {}
base_ptr_val(ValuePtrType ptr, tracing::value_ref tc) : state(tc), value(ptr) {}
base_ptr_val(ValuePtrType ptr, tracing::TypedValueRefHolder tc) : state(std::move(tc)), value(ptr) {}

base_ptr_val(tracing::value_ref ref) : state(ref), value(nullptr) {
}
#else
base_ptr_val(ValuePtrType ptr) : value(ptr) {};
base_ptr_val(ValuePtrType ptr) : value(ptr) {}
#endif

#ifdef ENABLE_TRACING
Expand Down Expand Up @@ -120,7 +120,7 @@ class val<ValuePtrType> : public base_ptr_val<ValuePtrType> {
#endif
this->value = other.value;
return *this;
};
}

val<ValType&> operator*()
requires is_arithmetic<ValType>
Expand All @@ -130,7 +130,7 @@ class val<ValuePtrType> : public base_ptr_val<ValuePtrType> {
#else
return val<ValType&>(*this);
#endif
};
}

template <class T>
val<ValType&> operator[](T&& io)
Expand Down Expand Up @@ -196,7 +196,7 @@ class val<ValuePtrType> : public base_ptr_val<ValuePtrType> {
#endif
this->value = other.value;
return *this;
};
}

template <typename OtherType>
requires std::is_pointer_v<OtherType>
Expand Down Expand Up @@ -346,12 +346,12 @@ class val<bool&> {

#ifdef ENABLE_TRACING
tracing::TypedValueRefHolder state;
val(bool ref) : state(tracing::value_ref()), ptr(&ref) {};
val(bool& ref, tracing::value_ref value_ref) : state(value_ref), ptr(&ref) {};
val(val<ptrType> ptr, tracing::value_ref ref) : state(ref), ptr(ptr) {};
val(bool ref) : state(tracing::value_ref()), ptr(&ref) {}
val(bool& ref, tracing::value_ref value_ref) : state(value_ref), ptr(&ref) {}
val(val<ptrType> ptr, tracing::value_ref ref) : state(ref), ptr(ptr) {}
#else
val(bool ref) : ptr(&ref) {};
val(val<ptrType> ptr) : ptr(ptr) {};
val(bool ref) : ptr(&ref) {}
val(val<ptrType> ptr) : ptr(ptr) {}
#endif

template <class T>
Expand Down
2 changes: 1 addition & 1 deletion nautilus/src/nautilus/compiler/backends/bc/ByteCode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class FunctionCallTarget {
* @brief The general definition of opcode, that contains a bytecode, at max two input registers and a result register.
*/
struct OpCode {
OpCode(ByteCode op, short reg1, short reg2, short output) : op(op), reg1(reg1), reg2(reg2), output(output) {};
OpCode(ByteCode op, short reg1, short reg2, short output) : op(op), reg1(reg1), reg2(reg2), output(output) {}
ByteCode op;
short reg1;
short reg2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ProxyFunctions {
public:
ProxyFunctions() {
functionNameToAddressMap.emplace(std::pair {"printValueFromMLIR", (void*) &printValueFromMLIR});
};
}
~ProxyFunctions() = default;
void* getProxyFunctionAddress(std::string name) {
return functionNameToAddressMap[name];
Expand Down
4 changes: 0 additions & 4 deletions nautilus/src/nautilus/tracing/TraceOperation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,8 @@ class TraceOperation {

TraceOperation(Op op, std::vector<InputVariant>&& input);

TraceOperation(const TraceOperation& other) = default;

friend std::ostream& operator<<(std::ostream& os, const TraceOperation& operation);

~TraceOperation() = default;

Snapshot tag;
Op op;
Type resultType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TraceToIRConversionPhase {
*/
class IRConversionContext {
public:
IRConversionContext(std::shared_ptr<ExecutionTrace> trace, const compiler::CompilationUnitID& id) : trace(trace), ir(std::make_shared<compiler::ir::IRGraph>(id)) {};
IRConversionContext(std::shared_ptr<ExecutionTrace> trace, const compiler::CompilationUnitID& id) : trace(trace), ir(std::make_shared<compiler::ir::IRGraph>(id)) {}

std::shared_ptr<compiler::ir::IRGraph> process();

Expand Down
2 changes: 1 addition & 1 deletion nautilus/src/nautilus/tracing/tag/Trie.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TrieNode {
} else {
return found->get();
}
};
}

private:
T content;
Expand Down
Loading

0 comments on commit ae705b6

Please sign in to comment.