mirror of
https://github.com/yuzu-emu/sirit.git
synced 2024-12-22 14:45:31 +00:00
cmake: Always treat warnings as errors
Enable cast warnings in gcc and clang and always treat warnings as errors. GetWordCount now returns std::size_t for simplicity and the word count is asserted and casted in WordCount (now called CalculateTotalWords. Silence warnings.
This commit is contained in:
parent
71b53b855a
commit
22cc6f6c1b
|
@ -54,12 +54,8 @@ if (MSVC)
|
|||
/EHsc
|
||||
/Zc:throwingNew # Assumes new never returns null
|
||||
/Zc:inline # Omits inline functions from object-file output
|
||||
/DNOMINMAX)
|
||||
|
||||
if (SIRIT_WARNINGS_AS_ERRORS)
|
||||
list(APPEND SIRIT_CXX_FLAGS
|
||||
/WX)
|
||||
endif()
|
||||
/DNOMINMAX
|
||||
/WX)
|
||||
|
||||
if (CMAKE_VS_PLATFORM_TOOLSET MATCHES "LLVM-vs[0-9]+")
|
||||
list(APPEND SIRIT_CXX_FLAGS
|
||||
|
@ -74,12 +70,10 @@ else()
|
|||
-pedantic
|
||||
-pedantic-errors
|
||||
-Wfatal-errors
|
||||
-Wno-missing-braces)
|
||||
|
||||
if (SIRIT_WARNINGS_AS_ERRORS)
|
||||
list(APPEND SIRIT_CXX_FLAGS
|
||||
-Werror)
|
||||
endif()
|
||||
-Wno-missing-braces
|
||||
-Wconversion
|
||||
-Wsign-conversion
|
||||
-Werror)
|
||||
endif()
|
||||
|
||||
# Enable unit-testing.
|
||||
|
|
|
@ -22,7 +22,7 @@ void LiteralNumber::Fetch(Stream& stream) const {
|
|||
}
|
||||
}
|
||||
|
||||
u16 LiteralNumber::GetWordCount() const noexcept {
|
||||
std::size_t LiteralNumber::GetWordCount() const noexcept {
|
||||
return is_32 ? 1 : 2;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
#include "operand.h"
|
||||
#include "stream.h"
|
||||
|
||||
|
@ -20,7 +22,7 @@ public:
|
|||
|
||||
void Fetch(Stream& stream) const override;
|
||||
|
||||
u16 GetWordCount() const noexcept override;
|
||||
std::size_t GetWordCount() const noexcept override;
|
||||
|
||||
bool operator==(const Operand& other) const noexcept override;
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ void LiteralString::Fetch(Stream& stream) const {
|
|||
stream.Write(string);
|
||||
}
|
||||
|
||||
u16 LiteralString::GetWordCount() const noexcept {
|
||||
return static_cast<u16>(string.size() / 4 + 1);
|
||||
std::size_t LiteralString::GetWordCount() const noexcept {
|
||||
return string.size() / 4 + 1;
|
||||
}
|
||||
|
||||
bool LiteralString::operator==(const Operand& other) const noexcept {
|
||||
|
|
|
@ -19,7 +19,7 @@ public:
|
|||
|
||||
void Fetch(Stream& stream) const override;
|
||||
|
||||
u16 GetWordCount() const noexcept override;
|
||||
std::size_t GetWordCount() const noexcept override;
|
||||
|
||||
bool operator==(const Operand& other) const noexcept override;
|
||||
|
||||
|
|
22
src/op.cpp
22
src/op.cpp
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <limits>
|
||||
|
||||
#include "common_types.h"
|
||||
#include "literal_number.h"
|
||||
|
@ -25,7 +26,7 @@ void Op::Fetch(Stream& stream) const {
|
|||
stream.Write(id.value());
|
||||
}
|
||||
|
||||
u16 Op::GetWordCount() const noexcept {
|
||||
std::size_t Op::GetWordCount() const noexcept {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -47,7 +48,7 @@ bool Op::operator==(const Operand& other) const noexcept {
|
|||
}
|
||||
|
||||
void Op::Write(Stream& stream) const {
|
||||
stream.Write(static_cast<u16>(opcode), WordCount());
|
||||
stream.Write(static_cast<u16>(opcode), CalculateTotalWords());
|
||||
|
||||
if (result_type) {
|
||||
result_type->Fetch(stream);
|
||||
|
@ -99,7 +100,11 @@ void Op::Add(const Operand* operand) {
|
|||
}
|
||||
|
||||
void Op::Add(u32 integer) {
|
||||
Sink(LiteralNumber::Create<u32>(integer));
|
||||
Sink(LiteralNumber::Create(integer));
|
||||
}
|
||||
|
||||
void Op::Add(s32 integer) {
|
||||
Sink(LiteralNumber::Create(integer));
|
||||
}
|
||||
|
||||
void Op::Add(std::string string) {
|
||||
|
@ -111,18 +116,19 @@ void Op::Add(const std::vector<Id>& ids) {
|
|||
operands.insert(operands.end(), ids.begin(), ids.end());
|
||||
}
|
||||
|
||||
u16 Op::WordCount() const {
|
||||
u16 count = 1;
|
||||
u16 Op::CalculateTotalWords() const noexcept {
|
||||
std::size_t count = 1;
|
||||
if (result_type) {
|
||||
count++;
|
||||
++count;
|
||||
}
|
||||
if (id.has_value()) {
|
||||
count++;
|
||||
++count;
|
||||
}
|
||||
for (const Operand* operand : operands) {
|
||||
count += operand->GetWordCount();
|
||||
}
|
||||
return count;
|
||||
assert(count < std::numeric_limits<u16>::max());
|
||||
return static_cast<u16>(count);
|
||||
}
|
||||
|
||||
} // namespace Sirit
|
||||
|
|
9
src/op.h
9
src/op.h
|
@ -6,7 +6,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "common_types.h"
|
||||
#include "operand.h"
|
||||
#include "sirit/sirit.h"
|
||||
|
@ -21,7 +24,7 @@ public:
|
|||
|
||||
void Fetch(Stream& stream) const override;
|
||||
|
||||
u16 GetWordCount() const noexcept override;
|
||||
std::size_t GetWordCount() const noexcept override;
|
||||
|
||||
bool operator==(const Operand& other) const noexcept override;
|
||||
|
||||
|
@ -37,12 +40,14 @@ public:
|
|||
|
||||
void Add(u32 integer);
|
||||
|
||||
void Add(s32 integer);
|
||||
|
||||
void Add(std::string string);
|
||||
|
||||
void Add(const std::vector<Id>& ids);
|
||||
|
||||
private:
|
||||
u16 WordCount() const;
|
||||
u16 CalculateTotalWords() const noexcept;
|
||||
|
||||
spv::Op opcode;
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "stream.h"
|
||||
|
||||
namespace Sirit {
|
||||
|
@ -19,7 +21,7 @@ public:
|
|||
|
||||
virtual void Fetch(Stream& stream) const = 0;
|
||||
|
||||
virtual u16 GetWordCount() const noexcept = 0;
|
||||
virtual std::size_t GetWordCount() const noexcept = 0;
|
||||
|
||||
virtual bool operator==(const Operand& other) const noexcept = 0;
|
||||
|
||||
|
|
|
@ -15,7 +15,9 @@ Stream::~Stream() = default;
|
|||
void Stream::Write(std::string_view string) {
|
||||
constexpr std::size_t word_size = 4;
|
||||
const auto size = string.size();
|
||||
auto read = [string, size](std::size_t offset) { return offset < size ? string[offset] : 0; };
|
||||
const auto read = [string, size](std::size_t offset) {
|
||||
return offset < size ? static_cast<u8>(string[offset]) : u8(0);
|
||||
};
|
||||
|
||||
words.reserve(words.size() + size / word_size + 1);
|
||||
for (std::size_t i = 0; i < size; i += word_size) {
|
||||
|
|
Loading…
Reference in a new issue