From 928fb49c2ade307c568945e2f6171c44f57fe233 Mon Sep 17 00:00:00 2001 From: Jason Gavris Date: Sun, 3 Apr 2022 11:49:34 -0400 Subject: [PATCH] Fix clang warning diagnostics See https://clang.llvm.org/docs/UsersManual.html#options-to-control-error-and-warning-messages --- CMakeLists.txt | 2 +- lib/ArgKind.cpp | 11 ++--------- lib/SPIRVProducerPass.cpp | 17 +++++++++++++---- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8dcc2bc655..e6794a1b86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -159,7 +159,7 @@ endif() if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=unused-variable -Werror=switch") elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror-unused-variable -Werror-switch") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=unused-variable -Werror=switch") endif() # Bring in our cmake folder diff --git a/lib/ArgKind.cpp b/lib/ArgKind.cpp index 85690df755..7b8fc14216 100644 --- a/lib/ArgKind.cpp +++ b/lib/ArgKind.cpp @@ -35,9 +35,6 @@ using namespace llvm; namespace { -// Maps an LLVM type for a kernel argument to an argument kind. -clspv::ArgKind GetArgKindForType(Type *type); - // Maps an LLVM type for a kernel argument to an argument // kind suitable for embedded reflection. The result is one of: // buffer - storage buffer @@ -48,10 +45,6 @@ clspv::ArgKind GetArgKindForType(Type *type); // ro_image - sampled image // wo_image - storage image // sampler - sampler -inline const char *GetArgKindNameForType(llvm::Type *type) { - return GetArgKindName(GetArgKindForType(type)); -} - clspv::ArgKind GetArgKindForType(Type *type) { if (type->isPointerTy()) { if (clspv::IsSamplerType(type)) { @@ -89,8 +82,8 @@ clspv::ArgKind GetArgKindForType(Type *type) { else return clspv::ArgKind::Pod; } - errs() << "Unhandled case in clspv::GetArgKindNameForType: " << *type << "\n"; - llvm_unreachable("Unhandled case in clspv::GetArgKindNameForType"); + errs() << "Unhandled case in clspv::GetArgKindForType: " << *type << "\n"; + llvm_unreachable("Unhandled case in clspv::GetArgKindForType"); return clspv::ArgKind::Buffer; } } // namespace diff --git a/lib/SPIRVProducerPass.cpp b/lib/SPIRVProducerPass.cpp index 99ac9e503b..d0f8f164ef 100644 --- a/lib/SPIRVProducerPass.cpp +++ b/lib/SPIRVProducerPass.cpp @@ -871,9 +871,11 @@ void SPIRVProducerPass::outputHeader() { case SPIRVVersion::SPIRV_1_6: minor = 6; break; + #if !defined(__clang__) default: llvm_unreachable("unhandled spir-v version"); break; + #endif } uint32_t version = (1 << 16) | (minor << 8); binaryOut->write(reinterpret_cast(&version), sizeof(version)); @@ -1216,6 +1218,7 @@ void SPIRVProducerPass::FindTypesForResourceVars() { for (auto *elem_ty : cast(type)->elements()) { work_list.push_back(elem_ty); } + break; default: // This type and its contained types don't get layout. break; @@ -1330,8 +1333,10 @@ SPIRVProducerPass::GetStorageClassForArgKind(clspv::ArgKind arg_kind) const { case clspv::ArgKind::StorageImage: case clspv::ArgKind::Sampler: return spv::StorageClassUniformConstant; + #if !defined(__clang__) default: llvm_unreachable("Unsupported storage class for argument kind"); + #endif } } @@ -3323,8 +3328,8 @@ SPIRVProducerPass::GenerateImageInstruction(CallInst *Call, const FunctionInfo &FuncInfo) { SPIRVID RID; - auto GetExtendMask = [this](Type *sample_type, - bool is_int_image) -> uint32_t { + auto GetExtendMask = [](Type *sample_type, + bool is_int_image) -> uint32_t { if (SpvVersion() >= SPIRVVersion::SPIRV_1_4 && sample_type->getScalarType()->isIntegerTy()) { if (is_int_image) @@ -4010,7 +4015,7 @@ SPIRVID SPIRVProducerPass::GenerateInstructionFromCall(CallInst *Call) { // Generate one more instruction that uses the result of the extended // instruction. Its result id is one more than the id of the // extended instruction. - auto generate_extra_inst = [this, &Context, &Call, + auto generate_extra_inst = [this, &Call, &RID](spv::Op opcode, Constant *constant) { // // Generate instruction like: @@ -4974,7 +4979,7 @@ void SPIRVProducerPass::HandleDeferredInstruction() { SPIRVInstruction *Placeholder = DeferredInsts[i].second; SPIRVOperandVec Operands; - auto nextDeferred = [&i, &Inst, &DeferredInsts, &Placeholder]() { + auto nextDeferred = [&i, &DeferredInsts, &Placeholder]() { ++i; assert(DeferredInsts.size() > i); assert(Inst == DeferredInsts[i].first); @@ -5456,10 +5461,12 @@ void SPIRVProducerPass::WriteWordCountAndOpcode(const SPIRVInstruction &Inst) { void SPIRVProducerPass::WriteOperand(const SPIRVOperand &Op) { SPIRVOperandType OpTy = Op.getType(); switch (OpTy) { + #if !defined(__clang__) default: { llvm_unreachable("Unsupported SPIRV Operand Type???"); break; } + #endif case SPIRVOperandType::NUMBERID: { WriteOneWord(Op.getNumID()); break; @@ -6501,9 +6508,11 @@ void SPIRVProducerPass::AddArgumentReflection( case clspv::ArgKind::Sampler: ext_inst = reflection::ExtInstArgumentSampler; break; + #if !defined(__clang__) default: llvm_unreachable("Unhandled argument reflection"); break; + #endif } Ops << ext_inst << kernel_decl << getSPIRVInt32Constant(ordinal);