Procházet zdrojové kódy

[linux-port] Fix spirv test warnings (#1337)

clang-spirv-tests uses a lot of external projects that keep
themselves clean with different standards of warnings flags.
This alters the appropriate cmake files to disable flags that
the DXC build enables.
Fixes 72 gcc and 166 clang warnings.

Additionally catch some sign mismatch comparisons in tests
built as part of clang-spirv-tests.
Fixes 2 gcc and 2 clang warnings, but one of them has multiple sources
So it's kind of a lot more.
Greg Roth před 7 roky
rodič
revize
4aa0f706c8

+ 4 - 1
external/CMakeLists.txt

@@ -68,7 +68,10 @@ if (${ENABLE_SPIRV_CODEGEN})
       # This add_compile_options() will only affect the current directory and its subdirectories.
       # This add_compile_options() will only affect the current directory and its subdirectories.
       if (WIN32)
       if (WIN32)
         add_compile_options(/EHs)
         add_compile_options(/EHs)
-      endif()
+      else(WIN32)
+        # Disable all warnings in subproject RE2
+        add_compile_options(-w)
+      endif(WIN32)
       # Don't build/run re2's tests.
       # Don't build/run re2's tests.
       set(RE2_BUILD_TESTING OFF CACHE BOOL "Skip RE2 tests")
       set(RE2_BUILD_TESTING OFF CACHE BOOL "Skip RE2 tests")
       add_subdirectory(${DXC_RE2_DIR} EXCLUDE_FROM_ALL)
       add_subdirectory(${DXC_RE2_DIR} EXCLUDE_FROM_ALL)

+ 4 - 11
external/GTestConfig.cmake

@@ -21,17 +21,10 @@ include_directories(
 
 
 if(WIN32)
 if(WIN32)
   add_definitions(-DGTEST_OS_WINDOWS=1)
   add_definitions(-DGTEST_OS_WINDOWS=1)
-endif()
-
-if(SUPPORTS_VARIADIC_MACROS_FLAG)
-  add_definitions("-Wno-variadic-macros")
-endif()
-if(SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG)
-  add_definitions("-Wno-gnu-zero-variadic-macro-arguments")
-endif()
-if(CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG)
-  add_definitions("-Wno-covered-switch-default")
-endif()
+else(WIN32)
+  # Disable all warnings in subproject googletest
+  add_compile_options(-w)
+endif(WIN32)
 
 
 set(LLVM_REQUIRES_RTTI 1)
 set(LLVM_REQUIRES_RTTI 1)
 add_definitions( -DGTEST_HAS_RTTI=0 )
 add_definitions( -DGTEST_HAS_RTTI=0 )

+ 20 - 20
tools/clang/unittests/SPIRV/DecorationTest.cpp

@@ -88,7 +88,7 @@ TEST(Decoration, RowMajor) {
   SPIRVContext ctx;
   SPIRVContext ctx;
   const Decoration *rowMajor = Decoration::getRowMajor(ctx, 2);
   const Decoration *rowMajor = Decoration::getRowMajor(ctx, 2);
   EXPECT_EQ(rowMajor->getValue(), spv::Decoration::RowMajor);
   EXPECT_EQ(rowMajor->getValue(), spv::Decoration::RowMajor);
-  EXPECT_EQ(rowMajor->getMemberIndex().getValue(), 2);
+  EXPECT_EQ(rowMajor->getMemberIndex().getValue(), 2U);
   EXPECT_TRUE(rowMajor->getArgs().empty());
   EXPECT_TRUE(rowMajor->getArgs().empty());
 }
 }
 
 
@@ -96,7 +96,7 @@ TEST(Decoration, ColMajor) {
   SPIRVContext ctx;
   SPIRVContext ctx;
   const Decoration *colMajor = Decoration::getColMajor(ctx, 2);
   const Decoration *colMajor = Decoration::getColMajor(ctx, 2);
   EXPECT_EQ(colMajor->getValue(), spv::Decoration::ColMajor);
   EXPECT_EQ(colMajor->getValue(), spv::Decoration::ColMajor);
-  EXPECT_EQ(colMajor->getMemberIndex().getValue(), 2);
+  EXPECT_EQ(colMajor->getMemberIndex().getValue(), 2U);
   EXPECT_TRUE(colMajor->getArgs().empty());
   EXPECT_TRUE(colMajor->getArgs().empty());
 }
 }
 
 
@@ -112,7 +112,7 @@ TEST(Decoration, MatrixStride) {
   SPIRVContext ctx;
   SPIRVContext ctx;
   const Decoration *matStride = Decoration::getMatrixStride(ctx, 4, 7);
   const Decoration *matStride = Decoration::getMatrixStride(ctx, 4, 7);
   EXPECT_EQ(matStride->getValue(), spv::Decoration::MatrixStride);
   EXPECT_EQ(matStride->getValue(), spv::Decoration::MatrixStride);
-  EXPECT_EQ(matStride->getMemberIndex().getValue(), 7);
+  EXPECT_EQ(matStride->getMemberIndex().getValue(), 7U);
   EXPECT_THAT(matStride->getArgs(), ElementsAre(4));
   EXPECT_THAT(matStride->getArgs(), ElementsAre(4));
 }
 }
 
 
@@ -155,7 +155,7 @@ TEST(Decoration, BuiltInAppliedToMember) {
   const Decoration *dec =
   const Decoration *dec =
       Decoration::getBuiltIn(ctx, spv::BuiltIn::Position, 3);
       Decoration::getBuiltIn(ctx, spv::BuiltIn::Position, 3);
   EXPECT_EQ(dec->getValue(), spv::Decoration::BuiltIn);
   EXPECT_EQ(dec->getValue(), spv::Decoration::BuiltIn);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3);
+  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
   EXPECT_THAT(dec->getArgs(),
   EXPECT_THAT(dec->getArgs(),
               ElementsAre(static_cast<uint32_t>(spv::BuiltIn::Position)));
               ElementsAre(static_cast<uint32_t>(spv::BuiltIn::Position)));
 }
 }
@@ -172,7 +172,7 @@ TEST(Decoration, NoPerspectiveAppliedToMember) {
   SPIRVContext ctx;
   SPIRVContext ctx;
   const Decoration *dec = Decoration::getNoPerspective(ctx, 3);
   const Decoration *dec = Decoration::getNoPerspective(ctx, 3);
   EXPECT_EQ(dec->getValue(), spv::Decoration::NoPerspective);
   EXPECT_EQ(dec->getValue(), spv::Decoration::NoPerspective);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3);
+  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
   EXPECT_TRUE(dec->getArgs().empty());
   EXPECT_TRUE(dec->getArgs().empty());
 }
 }
 TEST(Decoration, Flat) {
 TEST(Decoration, Flat) {
@@ -187,7 +187,7 @@ TEST(Decoration, FlatAppliedToMember) {
   SPIRVContext ctx;
   SPIRVContext ctx;
   const Decoration *dec = Decoration::getFlat(ctx, 3);
   const Decoration *dec = Decoration::getFlat(ctx, 3);
   EXPECT_EQ(dec->getValue(), spv::Decoration::Flat);
   EXPECT_EQ(dec->getValue(), spv::Decoration::Flat);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3);
+  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
   EXPECT_TRUE(dec->getArgs().empty());
   EXPECT_TRUE(dec->getArgs().empty());
 }
 }
 
 
@@ -203,7 +203,7 @@ TEST(Decoration, PatchAppliedToMember) {
   SPIRVContext ctx;
   SPIRVContext ctx;
   const Decoration *dec = Decoration::getPatch(ctx, 3);
   const Decoration *dec = Decoration::getPatch(ctx, 3);
   EXPECT_EQ(dec->getValue(), spv::Decoration::Patch);
   EXPECT_EQ(dec->getValue(), spv::Decoration::Patch);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3);
+  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
   EXPECT_TRUE(dec->getArgs().empty());
   EXPECT_TRUE(dec->getArgs().empty());
 }
 }
 TEST(Decoration, Centroid) {
 TEST(Decoration, Centroid) {
@@ -218,7 +218,7 @@ TEST(Decoration, CentroidAppliedToMember) {
   SPIRVContext ctx;
   SPIRVContext ctx;
   const Decoration *dec = Decoration::getCentroid(ctx, 3);
   const Decoration *dec = Decoration::getCentroid(ctx, 3);
   EXPECT_EQ(dec->getValue(), spv::Decoration::Centroid);
   EXPECT_EQ(dec->getValue(), spv::Decoration::Centroid);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3);
+  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
   EXPECT_TRUE(dec->getArgs().empty());
   EXPECT_TRUE(dec->getArgs().empty());
 }
 }
 
 
@@ -234,7 +234,7 @@ TEST(Decoration, SampleAppliedToMember) {
   SPIRVContext ctx;
   SPIRVContext ctx;
   const Decoration *dec = Decoration::getSample(ctx, 3);
   const Decoration *dec = Decoration::getSample(ctx, 3);
   EXPECT_EQ(dec->getValue(), spv::Decoration::Sample);
   EXPECT_EQ(dec->getValue(), spv::Decoration::Sample);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3);
+  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
   EXPECT_TRUE(dec->getArgs().empty());
   EXPECT_TRUE(dec->getArgs().empty());
 }
 }
 
 
@@ -274,7 +274,7 @@ TEST(Decoration, VolatileAppliedToMember) {
   SPIRVContext ctx;
   SPIRVContext ctx;
   const Decoration *dec = Decoration::getVolatile(ctx, 3);
   const Decoration *dec = Decoration::getVolatile(ctx, 3);
   EXPECT_EQ(dec->getValue(), spv::Decoration::Volatile);
   EXPECT_EQ(dec->getValue(), spv::Decoration::Volatile);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3);
+  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
   EXPECT_TRUE(dec->getArgs().empty());
   EXPECT_TRUE(dec->getArgs().empty());
 }
 }
 
 
@@ -298,7 +298,7 @@ TEST(Decoration, CoherentAppliedToMember) {
   SPIRVContext ctx;
   SPIRVContext ctx;
   const Decoration *dec = Decoration::getCoherent(ctx, 3);
   const Decoration *dec = Decoration::getCoherent(ctx, 3);
   EXPECT_EQ(dec->getValue(), spv::Decoration::Coherent);
   EXPECT_EQ(dec->getValue(), spv::Decoration::Coherent);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3);
+  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
   EXPECT_TRUE(dec->getArgs().empty());
   EXPECT_TRUE(dec->getArgs().empty());
 }
 }
 TEST(Decoration, NonWritable) {
 TEST(Decoration, NonWritable) {
@@ -313,7 +313,7 @@ TEST(Decoration, NonWritableAppliedToMember) {
   SPIRVContext ctx;
   SPIRVContext ctx;
   const Decoration *dec = Decoration::getNonWritable(ctx, 3);
   const Decoration *dec = Decoration::getNonWritable(ctx, 3);
   EXPECT_EQ(dec->getValue(), spv::Decoration::NonWritable);
   EXPECT_EQ(dec->getValue(), spv::Decoration::NonWritable);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3);
+  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
   EXPECT_TRUE(dec->getArgs().empty());
   EXPECT_TRUE(dec->getArgs().empty());
 }
 }
 
 
@@ -329,7 +329,7 @@ TEST(Decoration, NonReadableAppliedToMember) {
   SPIRVContext ctx;
   SPIRVContext ctx;
   const Decoration *dec = Decoration::getNonReadable(ctx, 3);
   const Decoration *dec = Decoration::getNonReadable(ctx, 3);
   EXPECT_EQ(dec->getValue(), spv::Decoration::NonReadable);
   EXPECT_EQ(dec->getValue(), spv::Decoration::NonReadable);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3);
+  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
   EXPECT_TRUE(dec->getArgs().empty());
   EXPECT_TRUE(dec->getArgs().empty());
 }
 }
 
 
@@ -345,7 +345,7 @@ TEST(Decoration, UniformAppliedToMember) {
   SPIRVContext ctx;
   SPIRVContext ctx;
   const Decoration *dec = Decoration::getUniform(ctx, 3);
   const Decoration *dec = Decoration::getUniform(ctx, 3);
   EXPECT_EQ(dec->getValue(), spv::Decoration::Uniform);
   EXPECT_EQ(dec->getValue(), spv::Decoration::Uniform);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3);
+  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
   EXPECT_TRUE(dec->getArgs().empty());
   EXPECT_TRUE(dec->getArgs().empty());
 }
 }
 
 
@@ -369,7 +369,7 @@ TEST(Decoration, StreamAppliedToMember) {
   SPIRVContext ctx;
   SPIRVContext ctx;
   const Decoration *dec = Decoration::getStream(ctx, 7, 3);
   const Decoration *dec = Decoration::getStream(ctx, 7, 3);
   EXPECT_EQ(dec->getValue(), spv::Decoration::Stream);
   EXPECT_EQ(dec->getValue(), spv::Decoration::Stream);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3);
+  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
   EXPECT_THAT(dec->getArgs(), ElementsAre(7));
   EXPECT_THAT(dec->getArgs(), ElementsAre(7));
 }
 }
 
 
@@ -385,7 +385,7 @@ TEST(Decoration, LocationAppliedToMember) {
   SPIRVContext ctx;
   SPIRVContext ctx;
   const Decoration *dec = Decoration::getLocation(ctx, 7, 3);
   const Decoration *dec = Decoration::getLocation(ctx, 7, 3);
   EXPECT_EQ(dec->getValue(), spv::Decoration::Location);
   EXPECT_EQ(dec->getValue(), spv::Decoration::Location);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3);
+  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
   EXPECT_THAT(dec->getArgs(), ElementsAre(7));
   EXPECT_THAT(dec->getArgs(), ElementsAre(7));
 }
 }
 
 
@@ -401,7 +401,7 @@ TEST(Decoration, ComponentAppliedToMember) {
   SPIRVContext ctx;
   SPIRVContext ctx;
   const Decoration *dec = Decoration::getComponent(ctx, 7, 3);
   const Decoration *dec = Decoration::getComponent(ctx, 7, 3);
   EXPECT_EQ(dec->getValue(), spv::Decoration::Component);
   EXPECT_EQ(dec->getValue(), spv::Decoration::Component);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3);
+  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
   EXPECT_THAT(dec->getArgs(), ElementsAre(7));
   EXPECT_THAT(dec->getArgs(), ElementsAre(7));
 }
 }
 
 
@@ -433,7 +433,7 @@ TEST(Decoration, Offset) {
   SPIRVContext ctx;
   SPIRVContext ctx;
   const Decoration *dec = Decoration::getOffset(ctx, 3, 3);
   const Decoration *dec = Decoration::getOffset(ctx, 3, 3);
   EXPECT_EQ(dec->getValue(), spv::Decoration::Offset);
   EXPECT_EQ(dec->getValue(), spv::Decoration::Offset);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3);
+  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
   EXPECT_THAT(dec->getArgs(), ElementsAre(3));
   EXPECT_THAT(dec->getArgs(), ElementsAre(3));
 }
 }
 
 
@@ -449,7 +449,7 @@ TEST(Decoration, XfbBufferAppliedToMember) {
   SPIRVContext ctx;
   SPIRVContext ctx;
   const Decoration *dec = Decoration::getXfbBuffer(ctx, 7, 3);
   const Decoration *dec = Decoration::getXfbBuffer(ctx, 7, 3);
   EXPECT_EQ(dec->getValue(), spv::Decoration::XfbBuffer);
   EXPECT_EQ(dec->getValue(), spv::Decoration::XfbBuffer);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3);
+  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
   EXPECT_THAT(dec->getArgs(), ElementsAre(7));
   EXPECT_THAT(dec->getArgs(), ElementsAre(7));
 }
 }
 
 
@@ -465,7 +465,7 @@ TEST(Decoration, XfbStrideAppliedToMember) {
   SPIRVContext ctx;
   SPIRVContext ctx;
   const Decoration *dec = Decoration::getXfbStride(ctx, 7, 3);
   const Decoration *dec = Decoration::getXfbStride(ctx, 7, 3);
   EXPECT_EQ(dec->getValue(), spv::Decoration::XfbStride);
   EXPECT_EQ(dec->getValue(), spv::Decoration::XfbStride);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3);
+  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
   EXPECT_THAT(dec->getArgs(), ElementsAre(7));
   EXPECT_THAT(dec->getArgs(), ElementsAre(7));
 }
 }
 
 

+ 1 - 1
tools/clang/unittests/SPIRV/ModuleBuilderTest.cpp

@@ -52,7 +52,7 @@ TEST(ModuleBuilder, CreateBasicBlock) {
   const auto rType = context.takeNextId();
   const auto rType = context.takeNextId();
   const auto fType = context.takeNextId();
   const auto fType = context.takeNextId();
   const auto fId = context.getNextId();
   const auto fId = context.getNextId();
-  EXPECT_NE(0, builder.beginFunction(fType, rType));
+  EXPECT_NE(0U, builder.beginFunction(fType, rType));
   const auto labelId = context.getNextId();
   const auto labelId = context.getNextId();
   const auto resultId = builder.createBasicBlock();
   const auto resultId = builder.createBasicBlock();
   EXPECT_EQ(labelId, resultId);
   EXPECT_EQ(labelId, resultId);