瀏覽代碼

Code Cleanup. (#475)

Add default for switch to avoid warnings.
Xiang Li 8 年之前
父節點
當前提交
c1973d761c

+ 16 - 0
include/dxc/HLSL/DxilSigPoint.inl

@@ -145,6 +145,8 @@ DXIL::SigPointKind SigPoint::GetKind(DXIL::ShaderKind shaderKind, DXIL::Signatur
     case DXIL::ShaderKind::Geometry:
       if (sigKind == DXIL::SignatureKind::Input)
         return DXIL::SigPointKind::GSIn;
+    default:
+      break;
     }
   }
 
@@ -153,6 +155,8 @@ DXIL::SigPointKind SigPoint::GetKind(DXIL::ShaderKind shaderKind, DXIL::Signatur
     switch (sigKind) {
     case DXIL::SignatureKind::Input: return DXIL::SigPointKind::VSIn;
     case DXIL::SignatureKind::Output: return DXIL::SigPointKind::VSOut;
+    default:
+      break;
     }
     break;
   case DXIL::ShaderKind::Hull:
@@ -160,6 +164,8 @@ DXIL::SigPointKind SigPoint::GetKind(DXIL::ShaderKind shaderKind, DXIL::Signatur
     case DXIL::SignatureKind::Input: return DXIL::SigPointKind::HSCPIn;
     case DXIL::SignatureKind::Output: return DXIL::SigPointKind::HSCPOut;
     case DXIL::SignatureKind::PatchConstant: return DXIL::SigPointKind::PCOut;
+    default:
+      break;
     }
     break;
   case DXIL::ShaderKind::Domain:
@@ -167,25 +173,35 @@ DXIL::SigPointKind SigPoint::GetKind(DXIL::ShaderKind shaderKind, DXIL::Signatur
     case DXIL::SignatureKind::Input: return DXIL::SigPointKind::DSCPIn;
     case DXIL::SignatureKind::Output: return DXIL::SigPointKind::DSOut;
     case DXIL::SignatureKind::PatchConstant: return DXIL::SigPointKind::DSIn;
+    default:
+      break;
     }
     break;
   case DXIL::ShaderKind::Geometry:
     switch (sigKind) {
     case DXIL::SignatureKind::Input: return DXIL::SigPointKind::GSVIn;
     case DXIL::SignatureKind::Output: return DXIL::SigPointKind::GSOut;
+    default:
+      break;
     }
     break;
   case DXIL::ShaderKind::Pixel:
     switch (sigKind) {
     case DXIL::SignatureKind::Input: return DXIL::SigPointKind::PSIn;
     case DXIL::SignatureKind::Output: return DXIL::SigPointKind::PSOut;
+    default:
+      break;
     }
     break;
   case DXIL::ShaderKind::Compute:
     switch (sigKind) {
     case DXIL::SignatureKind::Input: return DXIL::SigPointKind::CSIn;
+    default:
+      break;
     }
     break;
+  default:
+    break;
   }
 
   return DXIL::SigPointKind::Invalid;

+ 6 - 3
lib/HLSL/DxilCompType.cpp

@@ -173,8 +173,9 @@ CompType CompType::GetBaseCompType() const {
   case Kind::SNormF64:  __fallthrough;
   case Kind::UNormF64:  __fallthrough;
   case Kind::F64:       return CompType(Kind::F64);
+  default:
+    DXASSERT(false, "invalid type kind");
   }
-  DXASSERT(false, "invalid type kind");
   return CompType();
 }
 
@@ -222,8 +223,9 @@ Type *CompType::GetLLVMType(LLVMContext &Ctx) const {
   case Kind::SNormF64:
   case Kind::UNormF64:
   case Kind::F64:       return Type::getDoubleTy(Ctx);
+  default:
+    DXASSERT(false, "invalid type kind");
   }
-  DXASSERT(false, "invalid type kind");
   return nullptr;
 }
 
@@ -245,8 +247,9 @@ PointerType *CompType::GetLLVMPtrType(LLVMContext &Ctx, const unsigned AddrSpace
   case Kind::SNormF64:
   case Kind::UNormF64:
   case Kind::F64:       return Type::getDoublePtrTy(Ctx, AddrSpace);
+  default:
+    DXASSERT(false, "invalid type kind");
   }
-  DXASSERT(false, "invalid type kind");
   return nullptr;
 }
 

+ 4 - 0
lib/HLSL/DxilMetadataHelper.cpp

@@ -998,6 +998,8 @@ Function *DxilMDHelper::LoadDxilFunctionProps(MDTuple *pProps,
     props->ShaderProps.PS.EarlyDepthStencil =
         ConstMDToUint32(pProps->getOperand(idx++));
     break;
+  default:
+    break;
   }
   return F;
 }
@@ -1047,6 +1049,8 @@ DxilMDHelper::EmitDxilFunctionProps(const hlsl::DxilFunctionProps *props,
   case DXIL::ShaderKind::Pixel:
     MDVals[valIdx++] = BoolToConstMD(props->ShaderProps.PS.EarlyDepthStencil);
     break;
+  default:
+    break;
   }
   return MDTuple::get(m_Ctx, ArrayRef<llvm::Metadata *>(MDVals, valIdx));
 }

+ 2 - 0
lib/HLSL/DxilOperations.cpp

@@ -286,6 +286,8 @@ unsigned OP::GetTypeSlot(Type *pType) {
     case 64:              return 8;
     }
   }
+  default:
+    break;
   }
   return UINT_MAX;
 }

+ 4 - 0
lib/HLSL/DxilRootSignature.cpp

@@ -597,6 +597,8 @@ static DxilDescriptorRangeType GetRangeType(DxilRootParameterType RPT) {
   case DxilRootParameterType::CBV: return DxilDescriptorRangeType::CBV;
   case DxilRootParameterType::SRV: return DxilDescriptorRangeType::SRV;
   case DxilRootParameterType::UAV: return DxilDescriptorRangeType::UAV;
+  default:
+    break;
   }
 
   DXASSERT_NOMSG(false);
@@ -797,6 +799,8 @@ void RootSignatureVerifier::VerifyShader(DxilShaderVisibility VisType,
       bShaderDeniedByRootSig = true;
     }
     break;
+  default:
+    break;
   }
 
   bool bShaderHasRootBindings = false;

+ 2 - 0
lib/HLSL/DxilSignature.cpp

@@ -89,6 +89,8 @@ static bool ShouldBeAllocated(const DxilSignatureElement *SE) {
   case DXIL::SemanticInterpretationKind::NotPacked:
   case DXIL::SemanticInterpretationKind::Shadow:
     return false;
+  default:
+    break;
   }
   return true;
 }

+ 14 - 0
lib/HLSL/DxilTypeSystem.cpp

@@ -334,6 +334,8 @@ DXIL::SigPointKind SigPointFromInputQual(DxilParamInputQual Q, DXIL::ShaderKind
       return DXIL::SigPointKind::VSIn;
     case DxilParamInputQual::Out:
       return DXIL::SigPointKind::VSOut;
+    default:
+      break;
     }
     break;
   case DXIL::ShaderKind::Hull:
@@ -352,6 +354,8 @@ DXIL::SigPointKind SigPointFromInputQual(DxilParamInputQual Q, DXIL::ShaderKind
       return DXIL::SigPointKind::HSCPIn;
     case DxilParamInputQual::OutputPatch:
       return DXIL::SigPointKind::HSCPOut;
+    default:
+      break;
     }
     break;
   case DXIL::ShaderKind::Domain:
@@ -363,6 +367,8 @@ DXIL::SigPointKind SigPointFromInputQual(DxilParamInputQual Q, DXIL::ShaderKind
     case DxilParamInputQual::InputPatch:
     case DxilParamInputQual::OutputPatch:
       return DXIL::SigPointKind::DSCPIn;
+    default:
+      break;
     }
     break;
   case DXIL::ShaderKind::Geometry:
@@ -376,6 +382,8 @@ DXIL::SigPointKind SigPointFromInputQual(DxilParamInputQual Q, DXIL::ShaderKind
     case DxilParamInputQual::OutStream2:
     case DxilParamInputQual::OutStream3:
       return DXIL::SigPointKind::GSOut;
+    default:
+      break;
     }
     break;
   case DXIL::ShaderKind::Pixel:
@@ -384,14 +392,20 @@ DXIL::SigPointKind SigPointFromInputQual(DxilParamInputQual Q, DXIL::ShaderKind
       return DXIL::SigPointKind::PSIn;
     case DxilParamInputQual::Out:
       return DXIL::SigPointKind::PSOut;
+    default:
+      break;
     }
     break;
   case DXIL::ShaderKind::Compute:
     switch (Q) {
     case DxilParamInputQual::In:
       return DXIL::SigPointKind::CSIn;
+    default:
+      break;
     }
     break;
+  default:
+    break;
   }
   return DXIL::SigPointKind::Invalid;
 }

+ 23 - 4
lib/HLSL/DxilValidation.cpp

@@ -316,6 +316,8 @@ void PrintDiagnosticContext::Handle(const DiagnosticInfo &DI) {
   case llvm::DiagnosticSeverity::DS_Warning:
     m_warningsFound = true;
     break;
+  default:
+    break;
   }
   m_Printer << "\n";
 }
@@ -500,7 +502,7 @@ struct ValidationContext {
       unsigned idx = 0;
       for (auto i = F->getBasicBlockList().begin(),
         e = F->getBasicBlockList().end(); i != e; ++i) {
-        if (BB == i) {
+        if (BB == &(*i)) {
           break;
         }
       }
@@ -1871,7 +1873,7 @@ static void ValidateDxilOperationCallInProfile(CallInst *CI,
 }
 
 static bool IsDxilFunction(llvm::Function *F) {
-  unsigned argSize = F->getArgumentList().size();
+  unsigned argSize = F->arg_size();
   if (argSize < 1) {
     // Cannot be a DXIL operation.
     return false;
@@ -3159,6 +3161,8 @@ static void ValidateSignatureElement(DxilSignatureElement &SE,
     case DXIL::InterpolationMode::LinearNoperspectiveSample: {
       ValCtx.EmitFormatError(ValidationRule::MetaIntegerInterpMode, {SE.GetName()});
     } break;
+    default:
+      break;
     }
   }
 
@@ -3175,6 +3179,8 @@ static void ValidateSignatureElement(DxilSignatureElement &SE,
   case DXIL::SemanticInterpretationKind::Shadow:
     bShouldBeAllocated = false;
     break;
+  default:
+    break;
   }
 
   const char *inputOutput = nullptr;
@@ -3383,6 +3389,8 @@ static void ValidateSignatureOverlap(
   case DXIL::SemanticInterpretationKind::NotPacked:
   case DXIL::SemanticInterpretationKind::Shadow:
     return;
+  default:
+    break;
   }
 
   DxilPackElement PE(&E);
@@ -3623,6 +3631,8 @@ static void ValidateSignatures(ValidationContext &ValCtx) {
       maxOutputScalars = DXIL::kMaxOutputTotalScalars;
       maxPatchConstantScalars = DXIL::kMaxHSOutputPatchConstantTotalScalars;
     break;
+  default:
+    break;
   }
 
   ValidateSignature(ValCtx, ValCtx.DxilMod.GetInputSignature(), maxInputScalars);
@@ -3905,6 +3915,8 @@ static void ValidateShaderState(ValidationContext &ValCtx) {
       case DXIL::TessellatorOutputPrimitive::TriangleCCW:
         ValCtx.EmitError(ValidationRule::SmIsoLineOutputPrimitiveMismatch);
         break;
+      default:
+        break;
       }
       break;
     case DXIL::TessellatorDomain::Tri:
@@ -3912,6 +3924,8 @@ static void ValidateShaderState(ValidationContext &ValCtx) {
       case DXIL::TessellatorOutputPrimitive::Line:
         ValCtx.EmitError(ValidationRule::SmTriOutputPrimitiveMismatch);
         break;
+      default:
+        break;
       }
       break;
     case DXIL::TessellatorDomain::Quad:
@@ -3919,6 +3933,8 @@ static void ValidateShaderState(ValidationContext &ValCtx) {
       case DXIL::TessellatorOutputPrimitive::Line:
         ValCtx.EmitError(ValidationRule::SmTriOutputPrimitiveMismatch);
         break;
+      default:
+        break;
       }
       break;
     default:
@@ -4224,6 +4240,8 @@ static void VerifySignatureMatches(_In_ ValidationContext &ValCtx,
   case hlsl::DXIL::SignatureKind::PatchConstant:
     pName = "Program Patch Constant Signature";
     break;
+  default:
+    break;
   }
 
   unique_ptr<DxilPartWriter> pWriter(NewProgramSignatureWriter(ValCtx.DxilMod, SigKind));
@@ -4468,8 +4486,9 @@ HRESULT ValidateLoadModule(const char *pIL,
   std::unique_ptr<llvm::MemoryBuffer> pBitcodeBuf;
   pBitcodeBuf.reset(llvm::MemoryBuffer::getMemBuffer(
       llvm::StringRef(pIL, ILLength), "", false).release());
-  ErrorOr<std::unique_ptr<llvm::Module>> loadedModuleResult(llvm::parseBitcodeFile(
-    pBitcodeBuf->getMemBufferRef(), Ctx));
+
+  ErrorOr<std::unique_ptr<Module>> loadedModuleResult =
+      llvm::parseBitcodeFile(pBitcodeBuf->getMemBufferRef(), Ctx);
 
   // DXIL disallows some LLVM bitcode constructs, like unaccounted-for sub-blocks.
   // These appear as warnings, which the validator should reject.