diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index b30885d4cdb2..c517d17666d3 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -3356,6 +3356,9 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) { break; case Decl::FileScopeAsm: { + // File-scope asm is ignored during device-side CUDA compilation. + if (LangOpts.CUDA && LangOpts.CUDAIsDevice) + break; auto *AD = cast(D); getModule().appendModuleInlineAsm(AD->getAsmString()->getString()); break; diff --git a/clang/test/CodeGenCUDA/filter-decl.cu b/clang/test/CodeGenCUDA/filter-decl.cu index faaeb69fe1c7..e69473f3e84b 100644 --- a/clang/test/CodeGenCUDA/filter-decl.cu +++ b/clang/test/CodeGenCUDA/filter-decl.cu @@ -3,6 +3,12 @@ #include "Inputs/cuda.h" +// This has to be at the top of the file as that's where file-scope +// asm ends up. +// CHECK-HOST: module asm "file scope asm is host only" +// CHECK-DEVICE-NOT: module asm "file scope asm is host only" +__asm__("file scope asm is host only"); + // CHECK-HOST-NOT: constantdata = global // CHECK-DEVICE: constantdata = global __constant__ char constantdata[256];