Skip to content

Commit ce2b59c

Browse files
author
Erich Keane
authored
[SYCL] Move deferred emit check to after "Can be emitted" checks. (#2102)
The previous implementation caused function declarations to be attempted to be emitted if they were required to be emitted (such as in the case of -femit-all-decls), which caused a crash. This patch moves the check until after the 'can be emitted' checks for function/var decls, and limits it to only functions that are sycl-devices (or, in the case of implicit attributes, called from a sycl-device function).
1 parent f5de5f5 commit ce2b59c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2642,11 +2642,6 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
26422642
}
26432643
}
26442644

2645-
if (LangOpts.SYCLIsDevice && MustBeEmitted(Global)) {
2646-
addDeferredDeclToEmit(GD);
2647-
return;
2648-
}
2649-
26502645
// Ignore declarations, they will be emitted on their first use.
26512646
if (const auto *FD = dyn_cast<FunctionDecl>(Global)) {
26522647
// Forward declarations are emitted lazily on first use.
@@ -2698,6 +2693,13 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
26982693
}
26992694
}
27002695

2696+
// clang::ParseAST ensures that we emit the SYCL devices at the end, so
2697+
// anything that is a device (or indirectly called) will be handled later.
2698+
if (LangOpts.SYCLIsDevice && MustBeEmitted(Global)) {
2699+
addDeferredDeclToEmit(GD);
2700+
return;
2701+
}
2702+
27012703
// Defer code generation to first use when possible, e.g. if this is an inline
27022704
// function. If the global must always be emitted, do it eagerly if possible
27032705
// to benefit from cache locality.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -disable-llvm-passes -emit-llvm %s -femit-all-decls -o - | FileCheck %s
2+
3+
// This should not crash and we should not emit this declaration, even though
4+
// we have 'emit-all-decls'.
5+
// CHECK-NOT: define
6+
void foo(void);

0 commit comments

Comments
 (0)