Skip to content

[SYCL] Move deferred emit check to after "Can be emitted" checks. #2102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2642,11 +2642,6 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
}
}

if (LangOpts.SYCLIsDevice && MustBeEmitted(Global)) {
addDeferredDeclToEmit(GD);
return;
}

// Ignore declarations, they will be emitted on their first use.
if (const auto *FD = dyn_cast<FunctionDecl>(Global)) {
// Forward declarations are emitted lazily on first use.
Expand Down Expand Up @@ -2698,6 +2693,13 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
}
}

// clang::ParseAST ensures that we emit the SYCL devices at the end, so
// anything that is a device (or indirectly called) will be handled later.
if (LangOpts.SYCLIsDevice && MustBeEmitted(Global)) {
addDeferredDeclToEmit(GD);
return;
}

// Defer code generation to first use when possible, e.g. if this is an inline
// function. If the global must always be emitted, do it eagerly if possible
// to benefit from cache locality.
Expand Down
6 changes: 6 additions & 0 deletions clang/test/CodeGenSYCL/emit-all-decls-crash.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -disable-llvm-passes -emit-llvm %s -femit-all-decls -o - | FileCheck %s

// This should not crash and we should not emit this declaration, even though
// we have 'emit-all-decls'.
// CHECK-NOT: define
void foo(void);