Skip to content

Commit aeec9da

Browse files
author
Andrew Savonichev
committed
[SYCL] Remove noreturn function attribute
This is a follow-up to: 74aa9a0 [SYCL] Remove "unreachable" instruction from LLVM IR for SYCL devices (#1789) Noreturn function attribute gives LLVM optimization passes an opportunity to re-structure code and insert an unreachable instruction. This happens when optimizations are turned on by -fsycl-enable-optimizations, so noreturn function attribute must be removed. Signed-off-by: Andrew Savonichev <[email protected]>
1 parent 630a6de commit aeec9da

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

clang/lib/CodeGen/CGCall.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -4971,10 +4971,21 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
49714971

49724972
// 4. Finish the call.
49734973

4974+
// SYCL does not support C++ exceptions or termination in device code, so all
4975+
// functions have to return.
4976+
bool SyclSkipNoReturn = false;
4977+
if (getLangOpts().SYCLIsDevice && CI->doesNotReturn()) {
4978+
if (auto *F = CI->getCalledFunction())
4979+
F->removeFnAttr(llvm::Attribute::NoReturn);
4980+
CI->removeAttribute(llvm::AttributeList::FunctionIndex,
4981+
llvm::Attribute::NoReturn);
4982+
SyclSkipNoReturn = true;
4983+
}
4984+
49744985
// If the call doesn't return for non-sycl devices, finish the basic block and
49754986
// clear the insertion point; this allows the rest of IRGen to discard
49764987
// unreachable code.
4977-
if (CI->doesNotReturn() && !getLangOpts().SYCLIsDevice) {
4988+
if (!SyclSkipNoReturn && CI->doesNotReturn()) {
49784989
if (UnusedReturnSizePtr)
49794990
PopCleanupBlock();
49804991

clang/test/CodeGenSYCL/remove-ur-inst.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -emit-llvm %s -o - | FileCheck %s
2+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsycl-enable-optimizations -triple spir64-unknown-unknown-sycldevice -emit-llvm %s -o - | FileCheck %s
23

34
SYCL_EXTERNAL void doesNotReturn() throw() __attribute__((__noreturn__));
45

@@ -11,6 +12,7 @@ int main() {
1112
kernel<class test>([]() {
1213
doesNotReturn();
1314
// CHECK-NOT: unreachable
15+
// CHECK-NOT: noreturn
1416
});
1517
return 0;
16-
}
18+
}

0 commit comments

Comments
 (0)