diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 6321f745593b..4688f13dae21 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -5672,6 +5672,9 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) { // File-scope asm is ignored during device-side OpenMP compilation. if (LangOpts.OpenMPIsDevice) break; + // File-scope asm is ignored during device-side SYCL compilation. + if (LangOpts.SYCLIsDevice) + break; auto *AD = cast(D); getModule().appendModuleInlineAsm(AD->getAsmString()->getString()); break; diff --git a/clang/test/CodeGenSYCL/filescope_asm.c b/clang/test/CodeGenSYCL/filescope_asm.c new file mode 100644 index 000000000000..5f4f6709a0e1 --- /dev/null +++ b/clang/test/CodeGenSYCL/filescope_asm.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -emit-llvm %s -o - | FileCheck %s +// +// Check that file-scope asm is ignored during device-side SYCL compilation. +// +// CHECK-NOT: module asm "foo" +__asm__("foo");