Clean up CMake configuration and address compiler warnings.

- Removed dead configuration in CMakeLists.txt.
- Used target_compile_options() instead of CMAKE_{C|CXX}_FLAGS.
- Turned on warnings on tests.
- Fixed various warnings for comparing signed with unsigned values.
- Removed dead code exposed by compiler warnings.
This commit is contained in:
Lei Zhang 2015-11-18 09:22:10 -05:00
parent 64a9be97ca
commit 8bd75d650e
20 changed files with 161 additions and 186 deletions

View File

@ -26,6 +26,7 @@
cmake_minimum_required(VERSION 2.8)
project(spirv-tools)
set(SPIRV_TOOLS "SPIRV-Tools")
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
add_definitions(-DSPIRV_LINUX)
@ -37,36 +38,26 @@ else()
message(FATAL_ERROR "Your platform '${CMAKE_SYSTEM_NAME}' is not supported!")
endif()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
if (UNIX)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
elseif(WIN32)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
message(STATUS "No build type selected, default to Debug")
set(CMAKE_BUILD_TYPE "Debug")
endif()
if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-exceptions -fno-rtti")
set(SPIRV_WARNINGS -Wall -Wextra -Wno-missing-field-initializers)
# For good call stacks in profiles, keep the frame pointers.
if(NOT SPIRV_PERF STREQUAL "")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
option(SPIRV_WARN_EVERYTHING "Enable -Weverything" OFF)
if(${SPIRV_WARN_EVERYTHING})
set(SPIRV_WARNINGS ${SPIRV_WARNINGS}
-Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded)
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics")
set(SPIRV_USE_SANITIZER "" CACHE STRING
"Use the clang sanitizer [address|memory|thread|...]")
if(NOT "${SPIRV_USE_SANITIZER}" STREQUAL "")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=${SPIRV_USE_SANITIZER}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${SPIRV_USE_SANITIZER}")
endif()
option(SPIRV_WERROR "Enable error on warning" OFF)
if(${SPIRV_WERROR})
set(SPIRV_WARNINGS ${SPIRV_WARNINGS} -Werror)
endif()
elseif(WIN32)
set(SPIRV_WARNINGS -D_CRT_SECURE_NO_WARNINGS /wd4800)
endif()
option(SPIRV_COLOR_TERMINAL "Enable color terminal output" ON)
@ -74,34 +65,32 @@ if(${SPIRV_COLOR_TERMINAL})
add_definitions(-DSPIRV_COLOR_TERMINAL)
endif()
if(UNIX)
set(SPIRV_WARNINGS "-Wall -Wextra -Wno-missing-field-initializers")
option(SPIRV_WARN_EVERYTHING "Enable -Weverything for SPIRV library" OFF)
if(${SPIRV_WARN_EVERYTHING})
set(SPIRV_WARNINGS
"${SPIRV_WARNINGS} -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded")
function(default_compile_options TARGET)
target_compile_options(${TARGET} PRIVATE ${SPIRV_WARNINGS})
if (UNIX)
target_compile_options(${TARGET} PRIVATE
-std=c++11 -fno-exceptions -fno-rtti)
# For good call stacks in profiles, keep the frame pointers.
if(NOT "${SPIRV_PERF}" STREQUAL "")
target_compile_options(${TARGET} PRIVATE -fno-omit-frame-pointer)
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
target_compile_options(${TARGET} PRIVATE -fcolor-diagnostics)
set(SPIRV_USE_SANITIZER "" CACHE STRING
"Use the clang sanitizer [address|memory|thread|...]")
if(NOT "${SPIRV_USE_SANITIZER}" STREQUAL "")
target_compile_options(${TARGET} PRIVATE
-fsanitize=${SPIRV_USE_SANITIZER})
endif()
endif()
endif()
elseif(WIN32)
set(SPIRV_WARNINGS "-D_CRT_SECURE_NO_WARNINGS /wd4800")
endif()
if(UNIX)
option(SPIRV_WERROR "Enable error on warning" OFF)
if(${SPIRV_WERROR})
set(SPIRV_WARNINGS "${SPIRV_WARNINGS} -Werror")
endif()
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/include)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include)
endfunction()
set(SPIRV_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/include/libspirv/libspirv.h
${CMAKE_CURRENT_SOURCE_DIR}/include/util/bitutils.h
${CMAKE_CURRENT_SOURCE_DIR}/source/assembly_grammar.h
${CMAKE_CURRENT_SOURCE_DIR}/include/util/hex_float.h
${CMAKE_CURRENT_SOURCE_DIR}/source/assembly_grammar.h
${CMAKE_CURRENT_SOURCE_DIR}/source/binary.h
${CMAKE_CURRENT_SOURCE_DIR}/source/diagnostic.h
${CMAKE_CURRENT_SOURCE_DIR}/source/endian.h
@ -131,33 +120,29 @@ set(SPIRV_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/source/validate.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/validate_id.cpp)
set(SPIRV_TOOLS "SPIRV-Tools")
add_library(${SPIRV_TOOLS} ${SPIRV_SOURCES})
target_link_libraries(${SPIRV_TOOLS} ${SPIRV_LIBS})
set_target_properties(${SPIRV_TOOLS} PROPERTIES COMPILE_FLAGS ${SPIRV_WARNINGS})
default_compile_options(${SPIRV_TOOLS})
target_include_directories(${SPIRV_TOOLS} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/external/include)
option(SPIRV_SKIP_EXECUTABLES "Skip building the executables and tests along with the library" ${SPIRV_SKIP_EXECUTABLES})
set(SPIRV_BUILT_TARGETS ${SPIRV_TOOLS})
option(SPIRV_SKIP_EXECUTABLES
"Skip building the executables and tests along with the library" OFF)
set(SPIRV_INSTALL_TARGETS ${SPIRV_TOOLS})
if (NOT ${SPIRV_SKIP_EXECUTABLES})
list(APPEND SPIRV_BUILT_TARGETS spirv-as spirv-dis spirv-val)
add_executable(spirv-as
${CMAKE_CURRENT_SOURCE_DIR}/include/libspirv/libspirv.h
${CMAKE_CURRENT_SOURCE_DIR}/tools/as/as.cpp)
set_target_properties(spirv-as PROPERTIES COMPILE_FLAGS ${SPIRV_WARNINGS})
target_link_libraries(spirv-as ${SPIRV_TOOLS})
list(APPEND SPIRV_INSTALL_TARGETS spirv-as spirv-dis spirv-val)
add_executable(spirv-dis
${CMAKE_CURRENT_SOURCE_DIR}/include/libspirv/libspirv.h
${CMAKE_CURRENT_SOURCE_DIR}/tools/dis/dis.cpp)
set_target_properties(spirv-dis PROPERTIES COMPILE_FLAGS ${SPIRV_WARNINGS})
target_link_libraries(spirv-dis ${SPIRV_TOOLS})
add_executable(spirv-as ${CMAKE_CURRENT_SOURCE_DIR}/tools/as/as.cpp)
default_compile_options(spirv-as)
target_link_libraries(spirv-as PRIVATE ${SPIRV_TOOLS})
add_executable(spirv-val
${CMAKE_CURRENT_SOURCE_DIR}/include/libspirv/libspirv.h
${CMAKE_CURRENT_SOURCE_DIR}/tools/val/val.cpp)
set_target_properties(spirv-val PROPERTIES COMPILE_FLAGS ${SPIRV_WARNINGS})
target_link_libraries(spirv-val ${SPIRV_TOOLS})
add_executable(spirv-dis ${CMAKE_CURRENT_SOURCE_DIR}/tools/dis/dis.cpp)
default_compile_options(spirv-dis)
target_link_libraries(spirv-dis PRIVATE ${SPIRV_TOOLS})
add_executable(spirv-val ${CMAKE_CURRENT_SOURCE_DIR}/tools/val/val.cpp)
default_compile_options(spirv-val)
target_link_libraries(spirv-val PRIVATE ${SPIRV_TOOLS})
set(GMOCK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/googletest/googlemock)
if(EXISTS ${GMOCK_DIR})
@ -172,11 +157,7 @@ if (NOT ${SPIRV_SKIP_EXECUTABLES})
if (TARGET gmock)
message(STATUS "Found Google Mock, building tests.")
include_directories(SYSTEM
${gmock_SOURCE_DIR}/include
${gtest_SOURCE_DIR}/include)
add_executable(UnitSPIRV
set(TEST_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/test/TestFixture.h
${CMAKE_CURRENT_SOURCE_DIR}/test/UnitSPIRV.h
@ -232,14 +213,18 @@ if (NOT ${SPIRV_SKIP_EXECUTABLES})
${CMAKE_CURRENT_SOURCE_DIR}/test/ValidateID.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/main.cpp)
target_link_libraries(UnitSPIRV ${SPIRV_TOOLS} gmock)
add_executable(UnitSPIRV ${TEST_SOURCES})
default_compile_options(UnitSPIRV)
target_include_directories(UnitSPIRV PRIVATE
${gmock_SOURCE_DIR}/include ${gtest_SOURCE_DIR}/include)
target_link_libraries(UnitSPIRV PRIVATE ${SPIRV_TOOLS} gmock)
else()
message(STATUS "Did not find googletest, tests will not be built."
"To enable tests place googletest in '<spirv-dir>/external/googletest'.")
endif()
endif()
install(TARGETS ${SPIRV_BUILT_TARGETS}
install(TARGETS ${SPIRV_INSTALL_TARGETS}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)

View File

@ -488,7 +488,7 @@ std::istream& operator>>(std::istream& is, HexFloat<T, Traits>& value) {
fraction = (fraction >> HF::fraction_right_shift) & HF::fraction_encode_mask;
const uint_type max_exponent =
const int_type max_exponent =
SetBits<uint_type, 0, HF::num_exponent_bits>::get;
// Handle actual denorm numbers

View File

@ -51,9 +51,8 @@ class Disassembler {
public:
Disassembler(const libspirv::AssemblyGrammar& grammar, uint32_t const* words,
size_t num_words, uint32_t options)
uint32_t options)
: words_(words),
num_words_(num_words),
grammar_(grammar),
print_(spvIsInBitfield(SPV_BINARY_TO_TEXT_OPTION_PRINT, options)),
color_(print_ &&
@ -115,7 +114,6 @@ class Disassembler {
// The SPIR-V binary. The endianness is not necessarily converted
// to native endianness.
const uint32_t* const words_;
const size_t num_words_;
const libspirv::AssemblyGrammar& grammar_;
const bool print_; // Should we also print to the standard output stream?
const bool color_; // Should we print in colour?
@ -391,7 +389,7 @@ spv_result_t spvBinaryToText(const spv_const_context context,
const libspirv::AssemblyGrammar grammar(context);
if (!grammar.isValid()) return SPV_ERROR_INVALID_TABLE;
Disassembler disassembler(grammar, code, wordCount, options);
Disassembler disassembler(grammar, code, options);
if (auto error = spvBinaryParse(context, &disassembler, code, wordCount,
DisassembleHeader, DisassembleInstruction,
pDiagnostic)) {

View File

@ -501,8 +501,9 @@ spv_result_t AssemblyContext::checkRangeAndIfHexThenSignExtend(
// should be zero.
failed = (value & overflow_mask);
} else {
const uint64_t value_as_u64 = static_cast<uint64_t>(value);
// Check overflow in the ordinary case.
failed = (value & magnitude_mask) != value;
failed = (value_as_u64 & magnitude_mask) != value_as_u64;
}
}

View File

@ -40,7 +40,7 @@ TEST_F(TextToBinaryTest, NotPlacingResultIDAtTheBeginning) {
"Expected <result-id> at the beginning of an instruction, found "
"'OpTypeMatrix'.",
diagnostic->error);
EXPECT_EQ(0, diagnostic->position.line);
EXPECT_EQ(0u, diagnostic->position.line);
}
} // anonymous namespace

View File

@ -62,7 +62,7 @@ TEST_F(BinaryHeaderGet, Default) {
ASSERT_EQ(SPV_SUCCESS, spvBinaryHeaderGet(&const_bin, endian, &header));
ASSERT_EQ(static_cast<uint32_t>(SpvMagicNumber), header.magic);
ASSERT_EQ(0x10000, header.version);
ASSERT_EQ(0x10000u, header.version);
ASSERT_EQ(static_cast<uint32_t>(SPV_GENERATOR_CODEPLAY), header.generator);
ASSERT_EQ(1u, header.bound);
ASSERT_EQ(0u, header.schema);
@ -83,7 +83,7 @@ TEST_F(BinaryHeaderGet, InvalidPointerHeader) {
}
TEST_F(BinaryHeaderGet, TruncatedHeader) {
for (int i = 1; i < SPV_INDEX_INSTRUCTION; i++) {
for (uint8_t i = 1; i < SPV_INDEX_INSTRUCTION; i++) {
binary.wordCount = i;
spv_const_binary_t const_bin = get_const_binary();
ASSERT_EQ(SPV_ERROR_INVALID_BINARY,

View File

@ -120,7 +120,7 @@ TEST_F(BinaryToText, TruncatedModule) {
CompileSuccessfully("");
EXPECT_EQ(SPV_INDEX_INSTRUCTION, binary->wordCount);
for (int length = 0; length < SPV_INDEX_INSTRUCTION; length++) {
for (size_t length = 0; length < SPV_INDEX_INSTRUCTION; length++) {
spv_text text = nullptr;
spv_diagnostic diagnostic = nullptr;
EXPECT_EQ(
@ -230,9 +230,6 @@ TEST_F(TextToBinaryTest, OneInstruction) {
// This could detect problems in updating the expected-set-of-operands
// list.
TEST_F(TextToBinaryTest, OperandWithOperands) {
spv_binary binary;
spv_diagnostic diagnostic = nullptr;
const std::string input = R"(OpEntryPoint Kernel %1 "foo"
OpExecutionMode %1 LocalSizeHint 100 200 300
%2 = OpTypeVoid
@ -428,7 +425,7 @@ using GeneratorStringTest = spvtest::TextToBinaryTestBase<
TEST_P(GeneratorStringTest, Sample) {
auto words = CompileSuccessfully("");
EXPECT_EQ(SPV_INDEX_GENERATOR_NUMBER, 2);
EXPECT_EQ(2u, SPV_INDEX_GENERATOR_NUMBER);
words[SPV_INDEX_GENERATOR_NUMBER] =
SPV_GENERATOR_WORD(GetParam().generator, GetParam().misc);

View File

@ -113,12 +113,6 @@ OpFunctionEnd
spvContextDestroy(context);
}
static const char* kF32Type = R"(%4 = OpTypeFloat 32)";
static const char* kF32Const = R"(%5 = OpConstant %4 1)";
static const char* kU32Type = R"(%4 = OpTypeInt 32 0)";
static const char* kS32Type = R"(%4 = OpTypeInt 32 1)";
static const char* kI32Const = R"(%5 = OpConstant %4 1)";
INSTANTIATE_TEST_CASE_P(
ExtInstParameters, ExtInstGLSLstd450RoundTripTest,
::testing::ValuesIn(std::vector<ExtInstContext>({

View File

@ -349,18 +349,18 @@ TEST(FloatProxy, ValidConversion) {
EXPECT_TRUE(std::isnan(FloatProxy<float>(uint32_t(0x7F80F000)).getAsFloat()));
EXPECT_TRUE(std::isnan(FloatProxy<float>(uint32_t(0x7FFFFFFF)).getAsFloat()));
EXPECT_THAT(FloatProxy<float>(uint32_t(0xFF800000)).data(), Eq(0xFF800000));
EXPECT_THAT(FloatProxy<float>(uint32_t(0x7F800000)).data(), Eq(0x7F800000));
EXPECT_THAT(FloatProxy<float>(uint32_t(0xFFC00000)).data(), Eq(0xFFC00000));
EXPECT_THAT(FloatProxy<float>(uint32_t(0xFF800100)).data(), Eq(0xFF800100));
EXPECT_THAT(FloatProxy<float>(uint32_t(0xFF800c00)).data(), Eq(0xFF800c00));
EXPECT_THAT(FloatProxy<float>(uint32_t(0xFF80F000)).data(), Eq(0xFF80F000));
EXPECT_THAT(FloatProxy<float>(uint32_t(0xFFFFFFFF)).data(), Eq(0xFFFFFFFF));
EXPECT_THAT(FloatProxy<float>(uint32_t(0x7FC00000)).data(), Eq(0x7FC00000));
EXPECT_THAT(FloatProxy<float>(uint32_t(0x7F800100)).data(), Eq(0x7F800100));
EXPECT_THAT(FloatProxy<float>(uint32_t(0x7f800c00)).data(), Eq(0x7f800c00));
EXPECT_THAT(FloatProxy<float>(uint32_t(0x7F80F000)).data(), Eq(0x7F80F000));
EXPECT_THAT(FloatProxy<float>(uint32_t(0x7FFFFFFF)).data(), Eq(0x7FFFFFFF));
EXPECT_THAT(FloatProxy<float>(uint32_t(0xFF800000)).data(), Eq(0xFF800000u));
EXPECT_THAT(FloatProxy<float>(uint32_t(0x7F800000)).data(), Eq(0x7F800000u));
EXPECT_THAT(FloatProxy<float>(uint32_t(0xFFC00000)).data(), Eq(0xFFC00000u));
EXPECT_THAT(FloatProxy<float>(uint32_t(0xFF800100)).data(), Eq(0xFF800100u));
EXPECT_THAT(FloatProxy<float>(uint32_t(0xFF800c00)).data(), Eq(0xFF800c00u));
EXPECT_THAT(FloatProxy<float>(uint32_t(0xFF80F000)).data(), Eq(0xFF80F000u));
EXPECT_THAT(FloatProxy<float>(uint32_t(0xFFFFFFFF)).data(), Eq(0xFFFFFFFFu));
EXPECT_THAT(FloatProxy<float>(uint32_t(0x7FC00000)).data(), Eq(0x7FC00000u));
EXPECT_THAT(FloatProxy<float>(uint32_t(0x7F800100)).data(), Eq(0x7F800100u));
EXPECT_THAT(FloatProxy<float>(uint32_t(0x7f800c00)).data(), Eq(0x7f800c00u));
EXPECT_THAT(FloatProxy<float>(uint32_t(0x7F80F000)).data(), Eq(0x7F80F000u));
EXPECT_THAT(FloatProxy<float>(uint32_t(0x7FFFFFFF)).data(), Eq(0x7FFFFFFFu));
}
TEST(FloatProxy, Nan) {
@ -425,7 +425,7 @@ std::string EncodeViaFloatProxy(const T& value) {
std::string NormalizeExponentInFloatString(std::string in) {
std::string result;
// Reserve one spot for the terminating null, even when the sscanf fails.
std::vector<char> prefix(in.size()+1);
std::vector<char> prefix(in.size() + 1);
char e;
char plus_or_minus;
int exponent; // in base 10

View File

@ -48,7 +48,7 @@ TEST_F(TextToBinaryTest, ImmediateIntOpCode) {
SetText("!0x00FF00FF");
ASSERT_EQ(SPV_SUCCESS, spvTextToBinary(context, text.str, text.length,
&binary, &diagnostic));
EXPECT_EQ(0x00FF00FF, binary->code[5]);
EXPECT_EQ(0x00FF00FFu, binary->code[5]);
if (diagnostic) {
spvDiagnosticPrint(diagnostic);
}
@ -58,7 +58,7 @@ TEST_F(TextToBinaryTest, ImmediateIntOperand) {
SetText("OpCapability !0x00FF00FF");
EXPECT_EQ(SPV_SUCCESS, spvTextToBinary(context, text.str, text.length,
&binary, &diagnostic));
EXPECT_EQ(0x00FF00FF, binary->code[6]);
EXPECT_EQ(0x00FF00FFu, binary->code[6]);
if (diagnostic) {
spvDiagnosticPrint(diagnostic);
}
@ -241,7 +241,7 @@ OpCopyMemorySized %3 %4 %1
!0x0002003D %10 %1 %2 !1
OpCopyMemorySized %3 %4 %1
)");
EXPECT_EQ(0x0002003D, alternate[kFirstInstruction]);
EXPECT_EQ(0x0002003Du, alternate[kFirstInstruction]);
EXPECT_EQ(Subvector(original, kFirstInstruction + 1),
Subvector(alternate, kFirstInstruction + 1));
}

View File

@ -31,7 +31,7 @@ namespace {
TEST(OpcodeTableGet, Default) {
spv_opcode_table table;
ASSERT_EQ(SPV_SUCCESS, spvOpcodeTableGet(&table));
ASSERT_NE(0, table->count);
ASSERT_NE(0u, table->count);
ASSERT_NE(nullptr, table->entries);
}

View File

@ -31,7 +31,7 @@ namespace {
TEST(OperandTableGet, Default) {
spv_operand_table table;
ASSERT_EQ(SPV_SUCCESS, spvOperandTableGet(&table));
ASSERT_NE(0, table->count);
ASSERT_NE(0u, table->count);
ASSERT_NE(nullptr, table->types);
}
@ -40,7 +40,8 @@ TEST(OperandTableGet, InvalidPointerTable) {
}
TEST(OperandString, AllAreDefinedExceptVariable) {
EXPECT_EQ(0, SPV_OPERAND_TYPE_NONE); // None has no string, so don't test it.
// None has no string, so don't test it.
EXPECT_EQ(0u, SPV_OPERAND_TYPE_NONE);
// Start testing at enum with value 1, skipping None.
for (int i = 1; i < int(SPV_OPERAND_TYPE_FIRST_VARIABLE_TYPE); i++) {
EXPECT_NE(nullptr, spvOperandTypeStr(static_cast<spv_operand_type_t>(i)))

View File

@ -139,7 +139,7 @@ TEST_P(MatchableOperandExpansionTest, MatchableOperandsDontExpand) {
if (!spvOperandIsVariable(type)) {
spv_operand_pattern_t pattern;
const bool did_expand = spvExpandOperandSequenceOnce(type, &pattern);
EXPECT_EQ(false, did_expand);
EXPECT_FALSE(did_expand);
EXPECT_THAT(pattern, Eq(spv_operand_pattern_t{}));
}
}
@ -156,7 +156,7 @@ TEST_P(VariableOperandExpansionTest, NonMatchableOperandsExpand) {
if (spvOperandIsVariable(type)) {
spv_operand_pattern_t pattern;
const bool did_expand = spvExpandOperandSequenceOnce(type, &pattern);
EXPECT_EQ(true, did_expand);
EXPECT_TRUE(did_expand);
EXPECT_FALSE(pattern.empty());
// For the existing rules, the first expansion of a zero-or-more operand
// type yields a matchable operand type. This isn't strictly necessary.

View File

@ -35,45 +35,45 @@ TEST(TextAdvance, LeadingNewLines) {
AutoText input("\n\nWord");
AssemblyContext data(input, nullptr);
ASSERT_EQ(SPV_SUCCESS, data.advance());
ASSERT_EQ(0, data.position().column);
ASSERT_EQ(2, data.position().line);
ASSERT_EQ(2, data.position().index);
ASSERT_EQ(0u, data.position().column);
ASSERT_EQ(2u, data.position().line);
ASSERT_EQ(2u, data.position().index);
}
TEST(TextAdvance, LeadingSpaces) {
AutoText input(" Word");
AssemblyContext data(input, nullptr);
ASSERT_EQ(SPV_SUCCESS, data.advance());
ASSERT_EQ(4, data.position().column);
ASSERT_EQ(0, data.position().line);
ASSERT_EQ(4, data.position().index);
ASSERT_EQ(4u, data.position().column);
ASSERT_EQ(0u, data.position().line);
ASSERT_EQ(4u, data.position().index);
}
TEST(TextAdvance, LeadingTabs) {
AutoText input("\t\t\tWord");
AssemblyContext data(input, nullptr);
ASSERT_EQ(SPV_SUCCESS, data.advance());
ASSERT_EQ(3, data.position().column);
ASSERT_EQ(0, data.position().line);
ASSERT_EQ(3, data.position().index);
ASSERT_EQ(3u, data.position().column);
ASSERT_EQ(0u, data.position().line);
ASSERT_EQ(3u, data.position().index);
}
TEST(TextAdvance, LeadingNewLinesSpacesAndTabs) {
AutoText input("\n\n\t Word");
AssemblyContext data(input, nullptr);
ASSERT_EQ(SPV_SUCCESS, data.advance());
ASSERT_EQ(3, data.position().column);
ASSERT_EQ(2, data.position().line);
ASSERT_EQ(5, data.position().index);
ASSERT_EQ(3u, data.position().column);
ASSERT_EQ(2u, data.position().line);
ASSERT_EQ(5u, data.position().index);
}
TEST(TextAdvance, LeadingWhitespaceAfterCommentLine) {
AutoText input("; comment\n \t \tWord");
AssemblyContext data(input, nullptr);
ASSERT_EQ(SPV_SUCCESS, data.advance());
ASSERT_EQ(4, data.position().column);
ASSERT_EQ(1, data.position().line);
ASSERT_EQ(14, data.position().index);
ASSERT_EQ(4u, data.position().column);
ASSERT_EQ(1u, data.position().line);
ASSERT_EQ(14u, data.position().index);
}
TEST(TextAdvance, EOFAfterCommentLine) {
@ -91,7 +91,7 @@ TEST(TextAdvance, NullTerminator) {
TEST(TextAdvance, NoNullTerminator) {
spv_text_t text = {"OpNop\nSomething else in memory", 6};
AssemblyContext data(&text, nullptr);
const spv_position_t line_break = {1, 5, 5};
const spv_position_t line_break = {1u, 5u, 5u};
data.setPosition(line_break);
ASSERT_EQ(SPV_END_OF_STREAM, data.advance());
}

View File

@ -60,7 +60,7 @@ TEST(TextDestroy, Default) {
&binary, &diagnostic));
EXPECT_NE(nullptr, binary);
EXPECT_NE(nullptr, binary->code);
EXPECT_NE(0, binary->wordCount);
EXPECT_NE(0u, binary->wordCount);
if (diagnostic) {
spvDiagnosticPrint(diagnostic);
ASSERT_TRUE(false);
@ -77,7 +77,7 @@ TEST(TextDestroy, Default) {
ASSERT_TRUE(false);
}
EXPECT_NE(nullptr, resultText->str);
EXPECT_NE(0, resultText->length);
EXPECT_NE(0u, resultText->length);
spvTextDestroy(resultText);
spvContextDestroy(context);
}

View File

@ -71,7 +71,7 @@ TEST(TextLiteral, GoodU64) {
ASSERT_EQ(SPV_SUCCESS, spvTextToLiteral("4294967296", &l));
EXPECT_EQ(SPV_LITERAL_TYPE_UINT_64, l.type);
EXPECT_EQ(4294967296, l.value.u64);
EXPECT_EQ(4294967296u, l.value.u64);
}
TEST(TextLiteral, GoodFloat) {

View File

@ -68,7 +68,7 @@ TEST_F(TextToBinaryTest, CombinedMemoryAccessMask) {
const std::string input = "OpStore %ptr %value Volatile|Aligned 16";
const uint32_t expected_mask =
SpvMemoryAccessVolatileMask | SpvMemoryAccessAlignedMask;
EXPECT_THAT(expected_mask, Eq(3));
EXPECT_THAT(expected_mask, Eq(3u));
EXPECT_THAT(CompiledInstructions(input),
Eq(MakeInstruction(SpvOpStore, {1, 2, expected_mask, 16})));
}

View File

@ -187,32 +187,32 @@ TEST_F(TextToBinaryTest, UnknownBeginningOfInstruction) {
"found 'Google'.",
CompileFailure(
"\nOpSource OpenCL_C 12\nOpMemoryModel Physical64 OpenCL\nGoogle\n"));
EXPECT_EQ(4, diagnostic->position.line + 1);
EXPECT_EQ(1, diagnostic->position.column + 1);
EXPECT_EQ(4u, diagnostic->position.line + 1);
EXPECT_EQ(1u, diagnostic->position.column + 1);
}
TEST_F(TextToBinaryTest, NoEqualSign) {
EXPECT_EQ("Expected '=', found end of stream.",
CompileFailure("\nOpSource OpenCL_C 12\n"
"OpMemoryModel Physical64 OpenCL\n%2\n"));
EXPECT_EQ(5, diagnostic->position.line + 1);
EXPECT_EQ(1, diagnostic->position.column + 1);
EXPECT_EQ(5u, diagnostic->position.line + 1);
EXPECT_EQ(1u, diagnostic->position.column + 1);
}
TEST_F(TextToBinaryTest, NoOpCode) {
EXPECT_EQ("Expected opcode, found end of stream.",
CompileFailure("\nOpSource OpenCL_C 12\n"
"OpMemoryModel Physical64 OpenCL\n%2 =\n"));
EXPECT_EQ(5, diagnostic->position.line + 1);
EXPECT_EQ(1, diagnostic->position.column + 1);
EXPECT_EQ(5u, diagnostic->position.line + 1);
EXPECT_EQ(1u, diagnostic->position.column + 1);
}
TEST_F(TextToBinaryTest, WrongOpCode) {
EXPECT_EQ("Invalid Opcode prefix 'Wahahaha'.",
CompileFailure("\nOpSource OpenCL_C 12\n"
"OpMemoryModel Physical64 OpenCL\n%2 = Wahahaha\n"));
EXPECT_EQ(4, diagnostic->position.line + 1);
EXPECT_EQ(6, diagnostic->position.column + 1);
EXPECT_EQ(4u, diagnostic->position.line + 1);
EXPECT_EQ(6u, diagnostic->position.column + 1);
}
using TextToBinaryFloatValueTest = spvtest::TextToBinaryTestBase<
@ -322,12 +322,12 @@ TEST(AssemblyContextParseWideUnsignedIntegers, Sample) {
EXPECT_EQ(SPV_FAILED_MATCH, context.parseNumber("", ec, &u64, ""));
EXPECT_EQ(SPV_FAILED_MATCH, context.parseNumber("0=", ec, &u64, ""));
EXPECT_EQ(SPV_SUCCESS, context.parseNumber("0", ec, &u64, ""));
EXPECT_EQ(0, u64);
EXPECT_EQ(0u, u64);
EXPECT_EQ(SPV_SUCCESS,
context.parseNumber("0xffffffffffffffff", ec, &u64, ""));
EXPECT_EQ(0xffffffffffffffffULL, u64);
EXPECT_EQ(SPV_SUCCESS, context.parseNumber("-0", ec, &u64, ""));
EXPECT_EQ(0, u64);
EXPECT_EQ(0u, u64);
EXPECT_EQ(SPV_FAILED_MATCH, context.parseNumber("-1", ec, &u64, ""));
}

View File

@ -41,9 +41,9 @@ TEST(TextWordGet, NullTerminator) {
spv_position_t endPosition = {};
ASSERT_EQ(SPV_SUCCESS, AssemblyContext(AutoText("Word"), nullptr)
.getWord(word, &endPosition));
ASSERT_EQ(4, endPosition.column);
ASSERT_EQ(0, endPosition.line);
ASSERT_EQ(4, endPosition.index);
ASSERT_EQ(4u, endPosition.column);
ASSERT_EQ(0u, endPosition.line);
ASSERT_EQ(4u, endPosition.index);
ASSERT_STREQ("Word", word.c_str());
}
@ -52,9 +52,9 @@ TEST(TextWordGet, TabTerminator) {
spv_position_t endPosition = {};
ASSERT_EQ(SPV_SUCCESS, AssemblyContext(AutoText("Word\t"), nullptr)
.getWord(word, &endPosition));
ASSERT_EQ(4, endPosition.column);
ASSERT_EQ(0, endPosition.line);
ASSERT_EQ(4, endPosition.index);
ASSERT_EQ(4u, endPosition.column);
ASSERT_EQ(0u, endPosition.line);
ASSERT_EQ(4u, endPosition.index);
ASSERT_STREQ("Word", word.c_str());
}
@ -63,9 +63,9 @@ TEST(TextWordGet, SpaceTerminator) {
spv_position_t endPosition = {};
ASSERT_EQ(SPV_SUCCESS, AssemblyContext(AutoText("Word "), nullptr)
.getWord(word, &endPosition));
ASSERT_EQ(4, endPosition.column);
ASSERT_EQ(0, endPosition.line);
ASSERT_EQ(4, endPosition.index);
ASSERT_EQ(4u, endPosition.column);
ASSERT_EQ(0u, endPosition.line);
ASSERT_EQ(4u, endPosition.index);
ASSERT_STREQ("Word", word.c_str());
}
@ -74,9 +74,9 @@ TEST(TextWordGet, SemicolonTerminator) {
spv_position_t endPosition = {};
ASSERT_EQ(SPV_SUCCESS, AssemblyContext(AutoText("Wo;rd"), nullptr)
.getWord(word, &endPosition));
ASSERT_EQ(2, endPosition.column);
ASSERT_EQ(0, endPosition.line);
ASSERT_EQ(2, endPosition.index);
ASSERT_EQ(2u, endPosition.column);
ASSERT_EQ(0u, endPosition.line);
ASSERT_EQ(2u, endPosition.index);
ASSERT_STREQ("Wo", word.c_str());
}
@ -92,7 +92,7 @@ TEST(TextWordGet, MultipleWords) {
ASSERT_EQ(SPV_SUCCESS, data.getWord(word, &endPosition));
ASSERT_EQ(strlen(words[wordIndex]),
endPosition.column - data.position().column);
ASSERT_EQ(0, endPosition.line);
ASSERT_EQ(0u, endPosition.line);
ASSERT_EQ(strlen(words[wordIndex]),
endPosition.index - data.position().index);
ASSERT_STREQ(words[wordIndex], word.c_str());
@ -114,9 +114,9 @@ TEST(TextWordGet, QuotesAreKept) {
std::string word;
spv_position_t endPosition = {};
ASSERT_EQ(SPV_SUCCESS, data.getWord(word, &endPosition));
EXPECT_EQ(8, endPosition.column);
EXPECT_EQ(0, endPosition.line);
EXPECT_EQ(8, endPosition.index);
EXPECT_EQ(8u, endPosition.column);
EXPECT_EQ(0u, endPosition.line);
EXPECT_EQ(8u, endPosition.index);
EXPECT_STREQ(expected[0], word.c_str());
// Move to the next word.
@ -124,9 +124,9 @@ TEST(TextWordGet, QuotesAreKept) {
data.seekForward(1);
ASSERT_EQ(SPV_SUCCESS, data.getWord(word, &endPosition));
EXPECT_EQ(23, endPosition.column);
EXPECT_EQ(0, endPosition.line);
EXPECT_EQ(23, endPosition.index);
EXPECT_EQ(23u, endPosition.column);
EXPECT_EQ(0u, endPosition.line);
EXPECT_EQ(23u, endPosition.index);
EXPECT_STREQ(expected[1], word.c_str());
}
@ -138,9 +138,9 @@ TEST(TextWordGet, QuotesBetweenWordsActLikeGlue) {
std::string word;
spv_position_t endPosition = {};
ASSERT_EQ(SPV_SUCCESS, data.getWord(word, &endPosition));
EXPECT_EQ(16, endPosition.column);
EXPECT_EQ(0, endPosition.line);
EXPECT_EQ(16, endPosition.index);
EXPECT_EQ(16u, endPosition.column);
EXPECT_EQ(0u, endPosition.line);
EXPECT_EQ(16u, endPosition.index);
EXPECT_STREQ(expected[0], word.c_str());
// Move to the next word.
@ -148,9 +148,9 @@ TEST(TextWordGet, QuotesBetweenWordsActLikeGlue) {
data.seekForward(1);
ASSERT_EQ(SPV_SUCCESS, data.getWord(word, &endPosition));
EXPECT_EQ(22, endPosition.column);
EXPECT_EQ(0, endPosition.line);
EXPECT_EQ(22, endPosition.index);
EXPECT_EQ(22u, endPosition.column);
EXPECT_EQ(0u, endPosition.line);
EXPECT_EQ(22u, endPosition.index);
EXPECT_STREQ(expected[1], word.c_str());
}
@ -158,12 +158,11 @@ TEST(TextWordGet, QuotingWhitespace) {
AutoText input(QUOTE "white " NEWLINE TAB " space" QUOTE);
// Whitespace surrounded by quotes acts like glue.
std::string word;
spv_position_t startPosition = {};
spv_position_t endPosition = {};
ASSERT_EQ(SPV_SUCCESS,
AssemblyContext(input, nullptr).getWord(word, &endPosition));
EXPECT_EQ(input.str.length(), endPosition.column);
EXPECT_EQ(0, endPosition.line);
EXPECT_EQ(0u, endPosition.line);
EXPECT_EQ(input.str.length(), endPosition.index);
EXPECT_EQ(input.str, word);
}
@ -174,9 +173,9 @@ TEST(TextWordGet, QuoteAlone) {
spv_position_t endPosition = {};
ASSERT_EQ(SPV_SUCCESS,
AssemblyContext(input, nullptr).getWord(word, &endPosition));
ASSERT_EQ(1, endPosition.column);
ASSERT_EQ(0, endPosition.line);
ASSERT_EQ(1, endPosition.index);
ASSERT_EQ(1u, endPosition.column);
ASSERT_EQ(0u, endPosition.line);
ASSERT_EQ(1u, endPosition.index);
ASSERT_STREQ(QUOTE, word.c_str());
}
@ -186,9 +185,9 @@ TEST(TextWordGet, EscapeAlone) {
spv_position_t endPosition = {};
ASSERT_EQ(SPV_SUCCESS,
AssemblyContext(input, nullptr).getWord(word, &endPosition));
ASSERT_EQ(1, endPosition.column);
ASSERT_EQ(0, endPosition.line);
ASSERT_EQ(1, endPosition.index);
ASSERT_EQ(1u, endPosition.column);
ASSERT_EQ(0u, endPosition.line);
ASSERT_EQ(1u, endPosition.index);
ASSERT_STREQ(BACKSLASH, word.c_str());
}
@ -198,9 +197,9 @@ TEST(TextWordGet, EscapeAtEndOfInput) {
spv_position_t endPosition = {};
ASSERT_EQ(SPV_SUCCESS,
AssemblyContext(input, nullptr).getWord(word, &endPosition));
ASSERT_EQ(5, endPosition.column);
ASSERT_EQ(0, endPosition.line);
ASSERT_EQ(5, endPosition.index);
ASSERT_EQ(5u, endPosition.column);
ASSERT_EQ(0u, endPosition.line);
ASSERT_EQ(5u, endPosition.index);
ASSERT_STREQ("word" BACKSLASH, word.c_str());
}
@ -210,9 +209,9 @@ TEST(TextWordGet, Escaping) {
spv_position_t endPosition = {};
ASSERT_EQ(SPV_SUCCESS,
AssemblyContext(input, nullptr).getWord(word, &endPosition));
ASSERT_EQ(10, endPosition.column);
ASSERT_EQ(0, endPosition.line);
ASSERT_EQ(10, endPosition.index);
ASSERT_EQ(10u, endPosition.column);
ASSERT_EQ(0u, endPosition.line);
ASSERT_EQ(10u, endPosition.index);
ASSERT_EQ(input.str, word);
}
@ -222,9 +221,9 @@ TEST(TextWordGet, EscapingEscape) {
spv_position_t endPosition = {};
ASSERT_EQ(SPV_SUCCESS,
AssemblyContext(input, nullptr).getWord(word, &endPosition));
ASSERT_EQ(6, endPosition.column);
ASSERT_EQ(0, endPosition.line);
ASSERT_EQ(6, endPosition.index);
ASSERT_EQ(6u, endPosition.column);
ASSERT_EQ(0u, endPosition.line);
ASSERT_EQ(6u, endPosition.index);
ASSERT_STREQ("word" BACKSLASH BACKSLASH, word.c_str());
}

View File

@ -202,7 +202,7 @@ inline std::string MakeLongUTF8String(size_t num_4_byte_chars) {
// characters. Ideally, we would just use a C++11 UTF-8 string literal,
// but we want to support older Microsoft compilers.
const std::basic_string<char> earth_africa("\xF0\x9F\x8C\x8D");
EXPECT_EQ(4, earth_africa.size());
EXPECT_EQ(4u, earth_africa.size());
std::string result;
result.reserve(num_4_byte_chars * 4);