Browse Source

[linux-port] Misc HLSL test warnings (#1471)

Compiling HLSL tests on Unix produces a long list of warnings that
obfuscate the results of the build and ambiguates the intent.

This includes reordering the constructor initialization lists to
match the actual initialization order, removing unused variables,
changing pointer parameters to const to avoid casts that remove
the const qualifier when the value pointed to is not altered anyway,
removes deprecated and unused header, changes type to match
comparison, casts a few pointers to const when passed in, removes
unused functions.
Greg Roth 7 years ago
parent
commit
611fe4068f

+ 2 - 4
tools/clang/unittests/HLSL/CompilationResult.h

@@ -149,8 +149,8 @@ public:
     IsenseSupport(support),
     IsenseSupport(support),
     Intellisense(isense),
     Intellisense(isense),
     Index(index),
     Index(index),
-    TU(tu),
-    NumErrorDiagnostics(0)
+    NumErrorDiagnostics(0),
+    TU(tu)
   {
   {
     if (tu) {
     if (tu) {
       IFE(tu->GetNumDiagnostics(&NumDiagnostics));
       IFE(tu->GetNumDiagnostics(&NumDiagnostics));
@@ -224,7 +224,6 @@ public:
     CComPtr<IDxcIndex> tuIndex;
     CComPtr<IDxcIndex> tuIndex;
     CComPtr<IDxcTranslationUnit> tu;
     CComPtr<IDxcTranslationUnit> tu;
     const char *fileName = getDefaultFileName();
     const char *fileName = getDefaultFileName();
-    const int DisplayDiagnosticsToStdErrFalse = 0;
     if (textLen == 0) textLen = strlen(text);
     if (textLen == 0) textLen = strlen(text);
 
 
     IFE(isense->CreateIndex(&tuIndex));
     IFE(isense->CreateIndex(&tuIndex));
@@ -267,7 +266,6 @@ public:
     IFE(support->CreateIntellisense(&isense));
     IFE(support->CreateIntellisense(&isense));
     CComPtr<IDxcIndex> tuIndex;
     CComPtr<IDxcIndex> tuIndex;
     CComPtr<IDxcTranslationUnit> tu;
     CComPtr<IDxcTranslationUnit> tu;
-    const int DisplayDiagnosticsToStdErrFalse = 0;
     const char* commandLineArgs[32];
     const char* commandLineArgs[32];
     unsigned commandLineArgsCount = 0;
     unsigned commandLineArgsCount = 0;
     char* nextArg = arguments;
     char* nextArg = arguments;

+ 2 - 2
tools/clang/unittests/HLSL/CompilerTest.cpp

@@ -1417,11 +1417,11 @@ public:
     }
     }
   }
   }
 
 
-  std::string VerifyCompileFailed(LPCSTR pText, LPWSTR pTargetProfile, LPCSTR pErrorMsg) {
+  std::string VerifyCompileFailed(LPCSTR pText, LPCWSTR pTargetProfile, LPCSTR pErrorMsg) {
     return VerifyCompileFailed(pText, pTargetProfile, pErrorMsg, L"main");
     return VerifyCompileFailed(pText, pTargetProfile, pErrorMsg, L"main");
   }
   }
 
 
-  std::string VerifyCompileFailed(LPCSTR pText, LPWSTR pTargetProfile, LPCSTR pErrorMsg, LPCWSTR pEntryPoint) {
+  std::string VerifyCompileFailed(LPCSTR pText, LPCWSTR pTargetProfile, LPCSTR pErrorMsg, LPCWSTR pEntryPoint) {
     CComPtr<IDxcCompiler> pCompiler;
     CComPtr<IDxcCompiler> pCompiler;
     CComPtr<IDxcOperationResult> pResult;
     CComPtr<IDxcOperationResult> pResult;
     CComPtr<IDxcBlobEncoding> pSource;
     CComPtr<IDxcBlobEncoding> pSource;

+ 1 - 1
tools/clang/unittests/HLSL/FileCheckerTest.cpp

@@ -66,8 +66,8 @@ static string trim(string value) {
       Command(command), Arguments(arguments), CommandFileName(commandFileName) { }
       Command(command), Arguments(arguments), CommandFileName(commandFileName) { }
     FileRunCommandPart::FileRunCommandPart(FileRunCommandPart && other) :
     FileRunCommandPart::FileRunCommandPart(FileRunCommandPart && other) :
       Command(std::move(other.Command)),
       Command(std::move(other.Command)),
-      CommandFileName(other.CommandFileName),
       Arguments(std::move(other.Arguments)),
       Arguments(std::move(other.Arguments)),
+      CommandFileName(other.CommandFileName),
       RunResult(other.RunResult),
       RunResult(other.RunResult),
       StdOut(std::move(other.StdOut)),
       StdOut(std::move(other.StdOut)),
       StdErr(std::move(other.StdErr)) { }
       StdErr(std::move(other.StdErr)) { }

+ 1 - 2
tools/clang/unittests/HLSL/FunctionTest.cpp

@@ -13,7 +13,6 @@
 #include <memory>
 #include <memory>
 #include <vector>
 #include <vector>
 #include <string>
 #include <string>
-#include <strstream>
 #include "CompilationResult.h"
 #include "CompilationResult.h"
 #include "HLSLTestData.h"
 #include "HLSLTestData.h"
 
 
@@ -143,7 +142,7 @@ TEST_F(FunctionTest, AllowedStorageClass) {
 TEST_F(FunctionTest, AllowedInParamUsesClass) {
 TEST_F(FunctionTest, AllowedInParamUsesClass) {
   const char* fragments[] =  { "f", "1.0f" };
   const char* fragments[] =  { "f", "1.0f" };
   for (const auto &iop : InOutParameterModifierData) {
   for (const auto &iop : InOutParameterModifierData) {
-    for (int i = 0; i < _countof(fragments); i++) {
+    for (unsigned i = 0; i < _countof(fragments); i++) {
       char program[256];
       char program[256];
       sprintf_s(program, _countof(program),
       sprintf_s(program, _countof(program),
               "float ps(%s float o) { return o; }\n"
               "float ps(%s float o) { return o; }\n"

+ 3 - 6
tools/clang/unittests/HLSL/HlslTestUtils.h

@@ -275,9 +275,6 @@ inline uint16_t ConvertFloat32ToFloat16(float val) {
 
 
   static const uint32_t SignMask = 0x8000;
   static const uint32_t SignMask = 0x8000;
 
 
-  // Maximum f32 value representable in f16 format
-  static const uint32_t Max16in32 = 0x477fe000;
-
   // Minimum f32 value representable in f16 format without denormalizing
   // Minimum f32 value representable in f16 format without denormalizing
   static const uint32_t Min16in32 = 0x38800000;
   static const uint32_t Min16in32 = 0x38800000;
 
 
@@ -298,12 +295,12 @@ inline uint16_t ConvertFloat32ToFloat16(float val) {
   Bits Abs;
   Bits Abs;
   Abs.u_bits = bits.u_bits ^ sign;
   Abs.u_bits = bits.u_bits ^ sign;
 
 
-  bool isLessThanNormal = Abs.f_bits < *(float*)&Min16in32;
+  bool isLessThanNormal = Abs.f_bits < *(const float*)&Min16in32;
   bool isInfOrNaN = Abs.u_bits > Max32;
   bool isInfOrNaN = Abs.u_bits > Max32;
 
 
   if (isLessThanNormal) {
   if (isLessThanNormal) {
     // Compute Denormal result
     // Compute Denormal result
-    return (uint16_t)(Abs.f_bits * *(float*)(&DenormalRatio)) | (sign >> 16);
+    return (uint16_t)(Abs.f_bits * *(const float*)(&DenormalRatio)) | (sign >> 16);
   }
   }
   else if (isInfOrNaN) {
   else if (isInfOrNaN) {
     // Compute Inf or Nan result
     // Compute Inf or Nan result
@@ -372,7 +369,7 @@ inline bool CompareFloatULP(const float &fsrc, const float &fref,
   }
   }
   // For FTZ or Preserve mode, we should get the expected number within
   // For FTZ or Preserve mode, we should get the expected number within
   // ULPTolerance for any operations.
   // ULPTolerance for any operations.
-  int diff = *((DWORD *)&fsrc) - *((DWORD *)&fref);
+  int diff = *((const DWORD *)&fsrc) - *((const DWORD *)&fref);
   unsigned int uDiff = diff < 0 ? -diff : diff;
   unsigned int uDiff = diff < 0 ? -diff : diff;
   return uDiff <= (unsigned int)ULPTolerance;
   return uDiff <= (unsigned int)ULPTolerance;
 }
 }

+ 18 - 72
tools/clang/unittests/HLSL/Objects.cpp

@@ -130,20 +130,6 @@ enum ShaderType
   ST_All = ST_Vertex | ST_Hull | ST_Domain | ST_Geometry | ST_Pixel | ST_Compute
   ST_All = ST_Vertex | ST_Hull | ST_Domain | ST_Geometry | ST_Pixel | ST_Compute
 };
 };
 
 
-static
-const char* GetShaderTypeName(ShaderType value)
-{
-  switch (value) {
-  case ST_Vertex: return "Vertex shader";
-  case ST_Hull: return "Hull shader";
-  case ST_Domain: return "Domain shader";
-  case ST_Geometry: return "Geometry shader";
-  case ST_Pixel: return "Pixel shader";
-  case ST_Compute: return "Compute shader";
-  default: return "(unknown)";
-  }
-}
-
 typedef EnumFlagsIterator<ShaderType> ShaderTypeIterator;
 typedef EnumFlagsIterator<ShaderType> ShaderTypeIterator;
 ShaderTypeIterator begin(ShaderType value) { return ShaderTypeIterator(value); }
 ShaderTypeIterator begin(ShaderType value) { return ShaderTypeIterator(value); }
 ShaderTypeIterator end(ShaderType value) { return ShaderTypeIterator((ShaderType)0); }
 ShaderTypeIterator end(ShaderType value) { return ShaderTypeIterator((ShaderType)0); }
@@ -232,14 +218,6 @@ enum ShaderObjectKind
   SOK_TextureCubeArray
   SOK_TextureCubeArray
 };
 };
 
 
-static
-bool IsStreamOutputObject(ShaderObjectKind value)
-{
-  return (value == SOK_StreamOutputPoint) || 
-    (value == SOK_StreamOutputLine) || 
-    (value == SOK_StreamOutputTriangle);
-}
-
 struct ShaderObjectDataItem
 struct ShaderObjectDataItem
 {
 {
   ShaderObjectKind Kind;
   ShaderObjectKind Kind;
@@ -360,14 +338,6 @@ const ShaderObjectTemplateDataItem& GetTemplateData(const ShaderObjectDataItem&
   return *iter;
   return *iter;
 }
 }
 
 
-static
-bool HasOptionalTemplateArguments(const ShaderObjectDataItem& sod)
-{
-  const ShaderObjectTemplateDataItem& templateData = GetTemplateData(sod);
-  return templateData.TemplateKind != SOTK_NoParams &&
-    templateData.TemplateParamsOptional;
-}
-
 static
 static
 int CountOptionalTemplateArguments(const ShaderObjectTemplateDataItem& templateData)
 int CountOptionalTemplateArguments(const ShaderObjectTemplateDataItem& templateData)
 {
 {
@@ -385,38 +355,6 @@ int CountOptionalTemplateArguments(const ShaderObjectTemplateDataItem& templateD
  }
  }
 }
 }
 
 
-struct ShaderObjectMethodDataItem
-{
-  ShaderObjectKind ObjectKind;
-  const char* MethodName;
-};
-
-static const
-ShaderObjectDataItem ShaderObjectMethodData[] =
-{
-  { SOK_AppendStructuredBuffer, "Append" },
-  { SOK_AppendStructuredBuffer, "GetDimensions" },
-  { SOK_Buffer, "GetDimensions" },
-  { SOK_Buffer, "Load" }, // overloaded!
-  { SOK_Buffer, "operator[]" },
-  { SOK_ByteAddressBuffer, "GetDimensions" },
-  { SOK_ByteAddressBuffer, "Load" },  // overloaded
-  { SOK_ByteAddressBuffer, "Load2" }, // overloaded
-  { SOK_ByteAddressBuffer, "Load3" }, // overloaded
-  { SOK_ByteAddressBuffer, "Load4" }, // overloaded
-  { SOK_ConsumeStructuredBuffer, "Consume" },
-  { SOK_ConsumeStructuredBuffer, "GetDimensions" },
-  { SOK_InputPatch, "operator[]" },
-  { SOK_InputPatch, "Length" }, // actually a property
-  { SOK_OutputPatch, "operator[]" },
-  { SOK_OutputPatch, "Length" }, // actually a property
-  { SOK_RWBuffer, "GetDimensions" },
-  { SOK_RWBuffer, "Load" }, // overloaded!
-  { SOK_RWBuffer, "operator[]" }
-// TODO: add RWByteAddressBuffer members
-// TODO: add RWStructuredBuffer members
-};
-
 // - a RWBuffer supports globallycoherent storage class to generate memory barriers
 // - a RWBuffer supports globallycoherent storage class to generate memory barriers
 // TODO: ByteAddressBuffer is supported on SM4 on compute shaders
 // TODO: ByteAddressBuffer is supported on SM4 on compute shaders
 // TODO: RWByteAddressBuffer is supported on SM4 on compute shaders
 // TODO: RWByteAddressBuffer is supported on SM4 on compute shaders
@@ -438,6 +376,9 @@ struct ShaderObjectIntrinsicDataItem
   size_t IntrinsicCount;
   size_t IntrinsicCount;
 };
 };
 
 
+// The test that requires this is pending complete
+// support for primitive types
+#if 0
 const ShaderObjectIntrinsicDataItem ShaderObjectIntrinsicData[] = {
 const ShaderObjectIntrinsicDataItem ShaderObjectIntrinsicData[] = {
   { SOK_AppendStructuredBuffer, g_AppendStructuredBufferMethods, _countof(g_AppendStructuredBufferMethods) },
   { SOK_AppendStructuredBuffer, g_AppendStructuredBufferMethods, _countof(g_AppendStructuredBufferMethods) },
   { SOK_Buffer, g_BufferMethods, _countof(g_BufferMethods) },
   { SOK_Buffer, g_BufferMethods, _countof(g_BufferMethods) },
@@ -471,7 +412,7 @@ const ShaderObjectIntrinsicDataItem ShaderObjectIntrinsicData[] = {
 static
 static
 const ShaderObjectIntrinsicDataItem& GetIntrinsicData(const ShaderObjectDataItem& sod)
 const ShaderObjectIntrinsicDataItem& GetIntrinsicData(const ShaderObjectDataItem& sod)
 {
 {
-  for (int i = 0; i < _countof(ShaderObjectIntrinsicData); i++)
+  for (unsigned i = 0; i < _countof(ShaderObjectIntrinsicData); i++)
   {
   {
     if (sod.Kind == ShaderObjectIntrinsicData[i].Kind)
     if (sod.Kind == ShaderObjectIntrinsicData[i].Kind)
     {
     {
@@ -481,6 +422,7 @@ const ShaderObjectIntrinsicDataItem& GetIntrinsicData(const ShaderObjectDataItem
 
 
   throw std::runtime_error("cannot find shader object kind");
   throw std::runtime_error("cannot find shader object kind");
 }
 }
+#endif
 
 
 // The test fixture.
 // The test fixture.
 #ifdef _WIN32
 #ifdef _WIN32
@@ -700,7 +642,7 @@ TEST_F(ObjectTest, DeclareLocalObject) {
   for (const auto &sod : ShaderObjectData) {
   for (const auto &sod : ShaderObjectData) {
     // When shader models are validated, run through all of them.
     // When shader models are validated, run through all of them.
     // for (const auto &st : sod.ValidShaderTypes)
     // for (const auto &st : sod.ValidShaderTypes)
-    const auto st = std::first(sod.ValidShaderTypes);
+    // const auto st = std::first(sod.ValidShaderTypes);
     CheckCompiles(BuildDeclarationFunction(sod), true);
     CheckCompiles(BuildDeclarationFunction(sod), true);
   }
   }
 }
 }
@@ -709,7 +651,7 @@ TEST_F(ObjectTest, OptionalTemplateArgs) {
   for (const auto &sod : ShaderObjectData) {
   for (const auto &sod : ShaderObjectData) {
     // When shader models are validated, run through all of them.
     // When shader models are validated, run through all of them.
     // for (const auto &st : sod.ValidShaderTypes)
     // for (const auto &st : sod.ValidShaderTypes)
-    const auto st = std::first(sod.ValidShaderTypes);
+    //const auto st = std::first(sod.ValidShaderTypes);
 
 
     const ShaderObjectTemplateDataItem& templateData = GetTemplateData(sod);
     const ShaderObjectTemplateDataItem& templateData = GetTemplateData(sod);
     int argCount = CountOptionalTemplateArguments(templateData);
     int argCount = CountOptionalTemplateArguments(templateData);
@@ -727,7 +669,7 @@ TEST_F(ObjectTest, MissingTemplateArgs) {
   for (const auto &sod : ShaderObjectData) {
   for (const auto &sod : ShaderObjectData) {
     // When shader models are validated, run through all of them.
     // When shader models are validated, run through all of them.
     // for (const auto &st : sod.ValidShaderTypes)
     // for (const auto &st : sod.ValidShaderTypes)
-    const auto st = std::first(sod.ValidShaderTypes);
+    // const auto st = std::first(sod.ValidShaderTypes);
 
 
     const ShaderObjectTemplateDataItem& templateData = GetTemplateData(sod);
     const ShaderObjectTemplateDataItem& templateData = GetTemplateData(sod);
     int argCount = CountOptionalTemplateArguments(templateData);
     int argCount = CountOptionalTemplateArguments(templateData);
@@ -743,7 +685,7 @@ TEST_F(ObjectTest, TooManyTemplateArgs) {
   for (const auto &sod : ShaderObjectData) {
   for (const auto &sod : ShaderObjectData) {
     // When shader models are validated, run through all of them.
     // When shader models are validated, run through all of them.
     // for (const auto &st : sod.ValidShaderTypes)
     // for (const auto &st : sod.ValidShaderTypes)
-    const auto st = std::first(sod.ValidShaderTypes);
+    // const auto st = std::first(sod.ValidShaderTypes);
 
 
     CheckCompiles(BuildDeclarationFunctionTooManyArgs(sod), false);
     CheckCompiles(BuildDeclarationFunctionTooManyArgs(sod), false);
   }
   }
@@ -753,7 +695,7 @@ TEST_F(ObjectTest, PassAsParameter) {
   for (const auto &sod : ShaderObjectData) {
   for (const auto &sod : ShaderObjectData) {
     // When shader models are validated, run through all of them.
     // When shader models are validated, run through all of them.
     // for (const auto &st : sod.ValidShaderTypes)
     // for (const auto &st : sod.ValidShaderTypes)
-    const auto st = std::first(sod.ValidShaderTypes);
+    // const auto st = std::first(sod.ValidShaderTypes);
 
 
     CheckCompiles(BuildPassAsParameter(sod), true);
     CheckCompiles(BuildPassAsParameter(sod), true);
   }
   }
@@ -763,7 +705,7 @@ TEST_F(ObjectTest, AssignVariables) {
   for (const auto &sod : ShaderObjectData) {
   for (const auto &sod : ShaderObjectData) {
     // When shader models are validated, run through all of them.
     // When shader models are validated, run through all of them.
     // for (const auto &st : sod.ValidShaderTypes)
     // for (const auto &st : sod.ValidShaderTypes)
-    const auto st = std::first(sod.ValidShaderTypes);
+    // const auto st = std::first(sod.ValidShaderTypes);
 
 
     CheckCompiles(BuildAssignment(sod), true);
     CheckCompiles(BuildAssignment(sod), true);
   }
   }
@@ -773,7 +715,7 @@ TEST_F(ObjectTest, AssignReturnResult) {
   for (const auto &sod : ShaderObjectData) {
   for (const auto &sod : ShaderObjectData) {
     // When shader models are validated, run through all of them.
     // When shader models are validated, run through all of them.
     // for (const auto &st : sod.ValidShaderTypes)
     // for (const auto &st : sod.ValidShaderTypes)
-    const auto st = std::first(sod.ValidShaderTypes);
+    // const auto st = std::first(sod.ValidShaderTypes);
 
 
     CheckCompiles(BuildAssignmentFromResult(sod), true);
     CheckCompiles(BuildAssignmentFromResult(sod), true);
   }
   }
@@ -803,7 +745,7 @@ TEST_F(ObjectTest, PassToInoutArgs) {
 
 
       // When shader models are validated, run through all of them.
       // When shader models are validated, run through all of them.
       // for (const auto &st : sod.ValidShaderTypes)
       // for (const auto &st : sod.ValidShaderTypes)
-      const auto st = std::first(sod.ValidShaderTypes);
+      // const auto st = std::first(sod.ValidShaderTypes);
 
 
       FormatTypeNameAndPreamble(sod, typeName, &preambleDecl);
       FormatTypeNameAndPreamble(sod, typeName, &preambleDecl);
       if (uniqueId == 0) { // do this only once
       if (uniqueId == 0) { // do this only once
@@ -894,7 +836,7 @@ TEST_F(ObjectTest, TemplateArgConstraints) {
   for (const auto &sod : ShaderObjectData) {
   for (const auto &sod : ShaderObjectData) {
     // When shader models are validated, run through all of them.
     // When shader models are validated, run through all of them.
     // for (const auto &st : sod.ValidShaderTypes)
     // for (const auto &st : sod.ValidShaderTypes)
-    const auto st = std::first(sod.ValidShaderTypes);
+    // const auto st = std::first(sod.ValidShaderTypes);
 
 
     const ShaderObjectTemplateDataItem& templateData = GetTemplateData(sod);
     const ShaderObjectTemplateDataItem& templateData = GetTemplateData(sod);
     int argCount = CountOptionalTemplateArguments(templateData);
     int argCount = CountOptionalTemplateArguments(templateData);
@@ -919,6 +861,9 @@ TEST_F(ObjectTest, TemplateArgConstraints) {
   }
   }
 }
 }
 
 
+// The test that requires this function is pending complete
+// support for primitive types
+#if 0
 static
 static
 std::string SelectComponentType(BYTE legalTypes)
 std::string SelectComponentType(BYTE legalTypes)
 {
 {
@@ -951,6 +896,7 @@ std::string SelectComponentType(BYTE legalTypes)
       //LICOMPTYPE_STRING,
       //LICOMPTYPE_STRING,
   }
   }
 }
 }
+#endif
 
 
 TEST_F(ObjectTest, FunctionInvoke) {
 TEST_F(ObjectTest, FunctionInvoke) {
   // This is pending complete support for primitive types - there are many
   // This is pending complete support for primitive types - there are many