Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9310 from leoetlino/compile-time-errors-format
Turn format string issues into compile-time errors
  • Loading branch information
leoetlino committed Dec 5, 2020
2 parents d8b9a04 + 585899d commit c8cb330
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Source/CMakeLists.txt
Expand Up @@ -93,6 +93,12 @@ else()
if (HAS_STRINGOP_TRUNCATION_WARNING)
check_and_add_flag(NO_STRINGOP_TRUNCATION -Wno-stringop-truncation)
endif()

# Format string issues that the compiler can detect should be compile time errors.
check_cxx_compiler_flag(-Wformat HAS_FORMAT_WARNING)
if (HAS_FORMAT_WARNING)
check_and_add_flag(FORMAT_WARNING_TO_ERROR -Werror=format)
endif()
endif()

# These aren't actually needed for C11/C++11
Expand Down
Expand Up @@ -14,6 +14,7 @@
#include "Core/PowerPC/Jit64Common/Jit64AsmCommon.h"
#include "Core/PowerPC/Jit64Common/Jit64PowerPCState.h"

#include <fmt/format.h>
#include <gtest/gtest.h>

namespace
Expand Down Expand Up @@ -109,7 +110,7 @@ TEST(Jit64, ConvertDoubleToSingle)
const u32 expected = ConvertToSingle(input);
const u32 actual = routines.wrapped_cdts(input);

printf("%016llx -> %08x == %08x\n", input, actual, expected);
fmt::print("{:016x} -> {:08x} == {:08x}\n", input, actual, expected);

EXPECT_EQ(expected, actual);
}
Expand Down
3 changes: 2 additions & 1 deletion Source/UnitTests/Core/PowerPC/Jit64Common/Frsqrte.cpp
Expand Up @@ -14,6 +14,7 @@
#include "Core/PowerPC/Jit64Common/Jit64AsmCommon.h"
#include "Core/PowerPC/Jit64Common/Jit64PowerPCState.h"

#include <fmt/format.h>
#include <gtest/gtest.h>

namespace
Expand Down Expand Up @@ -98,7 +99,7 @@ TEST(Jit64, Frsqrte)

u64 actual = routines.wrapped_frsqrte(ivalue, fpscr);

printf("%016llx -> %016llx == %016llx\n", ivalue, actual, expected);
fmt::print("{:016x} -> {:016x} == {:016x}\n", ivalue, actual, expected);

EXPECT_EQ(expected, actual);
}
Expand Down

0 comments on commit c8cb330

Please sign in to comment.