Skip to content

Commit

Permalink
Fix clang warning diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
jgavris committed Apr 3, 2022
1 parent d53cec1 commit 928fb49
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 2 additions & 9 deletions lib/ArgKind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)) {
Expand Down Expand Up @@ -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
Expand Down
17 changes: 13 additions & 4 deletions lib/SPIRVProducerPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char *>(&version), sizeof(version));
Expand Down Expand Up @@ -1216,6 +1218,7 @@ void SPIRVProducerPass::FindTypesForResourceVars() {
for (auto *elem_ty : cast<StructType>(type)->elements()) {
work_list.push_back(elem_ty);
}
break;
default:
// This type and its contained types don't get layout.
break;
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 928fb49

Please sign in to comment.