diff --git a/lib/Target/AMDGPU/AMDGPUConvertAtomicLibCalls.cpp b/lib/Target/AMDGPU/AMDGPUConvertAtomicLibCalls.cpp index d18dab5a27c30..611b0feffcbb5 100644 --- a/lib/Target/AMDGPU/AMDGPUConvertAtomicLibCalls.cpp +++ b/lib/Target/AMDGPU/AMDGPUConvertAtomicLibCalls.cpp @@ -176,7 +176,8 @@ static AtomicOrdering MemoryOrderSpir2LLVM(Value *SpirMemOrd) { memory_order_acq_rel, memory_order_seq_cst }; - unsigned MemOrd = dyn_cast(SpirMemOrd)->getZExtValue(); + auto *MO = dyn_cast(SpirMemOrd); + unsigned MemOrd = MO ? MO->getZExtValue() : -1; switch (MemOrd) { case memory_order_relaxed: return AtomicOrdering::Monotonic; @@ -202,7 +203,8 @@ MemoryScopeOpenCL2LLVM(Value *OpenclMemScope) { memory_scope_all_svm_devices, memory_scope_sub_group }; - unsigned MemScope = dyn_cast(OpenclMemScope)->getZExtValue(); + auto *MS = dyn_cast(OpenclMemScope); + unsigned MemScope = MS ? MS->getZExtValue() : -1; switch (MemScope) { case memory_scope_work_item: llvm_unreachable("memory_scope_work_item not Valid for atomic builtins");