From: Artem Belevich Date: Mon, 27 Apr 2015 18:52:00 +0000 (+0000) Subject: [cuda] treat file scope __asm as __host__ and ignore it during device-side compilation. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8fe7051c268314081be47127f9b131e0f8925a3c;p=clang [cuda] treat file scope __asm as __host__ and ignore it during device-side compilation. Currently clang emits file-scope asm during *both* host and device compilation modes which is usually a wrong thing to do. There's no way to attach any attribute to an __asm statement, so there's no way to differentiate between host-side and device-side file-scope asm. This patch makes clang to match nvcc behavior and emit file-scope-asm only during host-side compilation. Differential Revision: http://reviews.llvm.org/D9270 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235905 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index b30885d4cd..c517d17666 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/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/test/CodeGenCUDA/filter-decl.cu b/test/CodeGenCUDA/filter-decl.cu index faaeb69fe1..e69473f3e8 100644 --- a/test/CodeGenCUDA/filter-decl.cu +++ b/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];