Index: clang/lib/CodeGen/CGCall.cpp =================================================================== --- clang/lib/CodeGen/CGCall.cpp +++ clang/lib/CodeGen/CGCall.cpp @@ -1969,11 +1969,11 @@ FuncAttrs.addAttribute(llvm::Attribute::Convergent); } - // TODO: NoUnwind attribute should be added for other GPU modes OpenCL, HIP, + // TODO: NoUnwind attribute should be added for other GPU modes HIP, // SYCL, OpenMP offload. AFAIK, none of them support exceptions in device // code. - if (getLangOpts().CUDA && getLangOpts().CUDAIsDevice) { - // Exceptions aren't supported in CUDA device code. + if ((getLangOpts().CUDA && getLangOpts().CUDAIsDevice) || + getLangOpts().OpenCL) { FuncAttrs.addAttribute(llvm::Attribute::NoUnwind); } Index: clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl =================================================================== --- clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl +++ clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl @@ -298,7 +298,7 @@ // CHECK: attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) } // CHECK: attributes #3 = { convergent noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx900" "target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64" } // CHECK: attributes #4 = { nounwind "enqueued-block" } -// CHECK: attributes #5 = { convergent } +// CHECK: attributes #5 = { convergent nounwind } //. // CHECK: !0 = !{i32 1, !"amdgpu_code_object_version", i32 400} // CHECK: !1 = !{i32 1, !"wchar_size", i32 4} Index: clang/test/CodeGenOpenCL/convergent.cl =================================================================== --- clang/test/CodeGenOpenCL/convergent.cl +++ clang/test/CodeGenOpenCL/convergent.cl @@ -139,4 +139,5 @@ // CHECK: attributes #3 = { {{[^}]*}}convergent noduplicate{{[^}]*}} } // CHECK: attributes #4 = { {{[^}]*}}convergent{{[^}]*}} } // CHECK: attributes #5 = { {{[^}]*}}convergent{{[^}]*}} } -// CHECK: attributes #6 = { {{[^}]*}}convergent noduplicate{{[^}]*}} } +// CHECK: attributes #6 = { {{[^}]*}}nounwind{{[^}]*}} } +// CHECK: attributes #7 = { {{[^}]*}}convergent noduplicate nounwind{{[^}]*}} }