CMake: fix warnings on msvc builds

Remove /W3 from default flags, and disable a couple of warnings:

C4127: conditional expression is constant
C4458: declaration of 'identifier' hides class member

These match our warning settings of Clang/GCC more closely.
Also fix some valid warnings in some tests.

Change-Id: I46cb30b93ece74039db4aa0d6b52a675ee36859d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44960
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Antonio Maiorano 2021-03-17 13:32:54 +00:00 committed by Commit Bot service account
parent 4f4534df3a
commit d600972e49
3 changed files with 13 additions and 2 deletions

View File

@ -76,6 +76,14 @@ message(STATUS "Tint build checking [chromium-style]: ${TINT_CHECK_CHROMIUM_STYL
message(STATUS "Using python3") message(STATUS "Using python3")
find_package(PythonInterp 3 REQUIRED) find_package(PythonInterp 3 REQUIRED)
# CMake < 3.15 sets /W3 in CMAKE_CXX_FLAGS. Remove it if it's there.
# See https://gitlab.kitware.com/cmake/cmake/-/issues/18317
if (MSVC)
if (CMAKE_CXX_FLAGS MATCHES "/W3")
string(REPLACE "/W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()
endif()
if (${TINT_CHECK_CHROMIUM_STYLE}) if (${TINT_CHECK_CHROMIUM_STYLE})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -add-plugin -Xclang find-bad-constructs") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -add-plugin -Xclang find-bad-constructs")
endif() endif()
@ -186,8 +194,10 @@ function(tint_default_compile_options TARGET)
/W4 /W4
/WX /WX
/wd4068 /wd4068
/wd4127
/wd4244 /wd4244
/wd4267 /wd4267
/wd4458
/wd4514 /wd4514
/wd4571 /wd4571
/wd4625 /wd4625

View File

@ -28,7 +28,7 @@ TEST_F(BuilderTest, Discard) {
spirv::Builder& b = Build(); spirv::Builder& b = Build();
b.push_function(Function{}); b.push_function(Function{});
EXPECT_EQ(b.GenerateStatement(expr), 1u) << b.error(); EXPECT_TRUE(b.GenerateStatement(expr)) << b.error();
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(OpKill EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(OpKill
)"); )");
} }

View File

@ -65,7 +65,8 @@ TEST_P(Decoration_StageTest, Emit) {
EXPECT_EQ(preamble[0].opcode(), spv::Op::OpEntryPoint); EXPECT_EQ(preamble[0].opcode(), spv::Op::OpEntryPoint);
ASSERT_GE(preamble[0].operands().size(), 3u); ASSERT_GE(preamble[0].operands().size(), 3u);
EXPECT_EQ(preamble[0].operands()[0].to_i(), params.model); EXPECT_EQ(preamble[0].operands()[0].to_i(),
static_cast<uint32_t>(params.model));
} }
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
BuilderTest, BuilderTest,