]> granicus.if.org Git - clang/commitdiff
[cuda] treat file scope __asm as __host__ and ignore it during device-side compilation.
authorArtem Belevich <tra@google.com>
Mon, 27 Apr 2015 18:52:00 +0000 (18:52 +0000)
committerArtem Belevich <tra@google.com>
Mon, 27 Apr 2015 18:52:00 +0000 (18:52 +0000)
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

lib/CodeGen/CodeGenModule.cpp
test/CodeGenCUDA/filter-decl.cu

index b30885d4cdb215280b94e7d1acd89154e8a2b3a2..c517d17666d3b472c96096d6facc1060c1e0e33e 100644 (file)
@@ -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<FileScopeAsmDecl>(D);
     getModule().appendModuleInlineAsm(AD->getAsmString()->getString());
     break;
index faaeb69fe1c72ea2c6ee43062c0d2f1b5a47f4bf..e69473f3e84b70bca5259e4b6abf8e020008c99d 100644 (file)
@@ -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];