[clang] 1495210 - [OpenCL] Always add nounwind attribute for OpenCL
Sven van Haastregt via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 20 04:05:57 PST 2023
Author: Sven van Haastregt
Date: 2023-01-20T12:01:22Z
New Revision: 1495210914997bcd0ca6937be0ae3cd6809b5ef5
URL: https://github.com/llvm/llvm-project/commit/1495210914997bcd0ca6937be0ae3cd6809b5ef5
DIFF: https://github.com/llvm/llvm-project/commit/1495210914997bcd0ca6937be0ae3cd6809b5ef5.diff
LOG: [OpenCL] Always add nounwind attribute for OpenCL
Neither OpenCL nor C++ for OpenCL support exceptions, so add the
`nounwind` attribute unconditionally for those languages.
Differential Revision: https://reviews.llvm.org/D142033
Added:
Modified:
clang/lib/CodeGen/CGCall.cpp
clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
clang/test/CodeGenOpenCL/convergent.cl
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 276d91fa2758d..dfa552161d7ca 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1969,11 +1969,11 @@ void CodeGenModule::getDefaultFunctionAttributes(StringRef Name,
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);
}
diff --git a/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl b/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
index 210014d14c086..4277dbbc20530 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
@@ -298,7 +298,7 @@ kernel void test(global char *a, char b, global long *c, long d) {
// 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}
diff --git a/clang/test/CodeGenOpenCL/convergent.cl b/clang/test/CodeGenOpenCL/convergent.cl
index f764cf0fc782d..123adba7b40d2 100644
--- a/clang/test/CodeGenOpenCL/convergent.cl
+++ b/clang/test/CodeGenOpenCL/convergent.cl
@@ -139,4 +139,5 @@ kernel void assume_convergent_asm()
// 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{{[^}]*}} }
More information about the cfe-commits
mailing list