[PATCH] D16739: [CUDA] Die if we ask the NVPTX backend to emit a global ctor/dtor.

Justin Lebar via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 29 17:11:39 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL259279: [CUDA] Die if we ask the NVPTX backend to emit a global ctor/dtor. (authored by jlebar).

Changed prior to commit:
  http://reviews.llvm.org/D16739?vs=46442&id=46455#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D16739

Files:
  llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
  llvm/trunk/test/CodeGen/NVPTX/global-ctor-empty.ll
  llvm/trunk/test/CodeGen/NVPTX/global-ctor.ll
  llvm/trunk/test/CodeGen/NVPTX/global-dtor.ll

Index: llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
===================================================================
--- llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
+++ llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
@@ -802,6 +802,13 @@
   }
 }
 
+static bool isEmptyXXStructor(GlobalVariable *GV) {
+  if (!GV) return true;
+  const ConstantArray *InitList = dyn_cast<ConstantArray>(GV->getInitializer());
+  if (!InitList) return true;  // Not an array; we don't know how to parse.
+  return InitList->getNumOperands() == 0;
+}
+
 bool NVPTXAsmPrinter::doInitialization(Module &M) {
   // Construct a default subtarget off of the TargetMachine defaults. The
   // rest of NVPTX isn't friendly to change subtargets per function and
@@ -816,6 +823,16 @@
     report_fatal_error("Module has aliases, which NVPTX does not support.");
     return true; // error
   }
+  if (!isEmptyXXStructor(M.getNamedGlobal("llvm.global_ctors"))) {
+    report_fatal_error(
+        "Module has a nontrivial global ctor, which NVPTX does not support.");
+    return true;  // error
+  }
+  if (!isEmptyXXStructor(M.getNamedGlobal("llvm.global_dtors"))) {
+    report_fatal_error(
+        "Module has a nontrivial global dtor, which NVPTX does not support.");
+    return true;  // error
+  }
 
   SmallString<128> Str1;
   raw_svector_ostream OS1(Str1);
Index: llvm/trunk/test/CodeGen/NVPTX/global-ctor-empty.ll
===================================================================
--- llvm/trunk/test/CodeGen/NVPTX/global-ctor-empty.ll
+++ llvm/trunk/test/CodeGen/NVPTX/global-ctor-empty.ll
@@ -0,0 +1,5 @@
+; RUN: llc < %s -march=nvptx -mcpu=sm_20 2>&1
+
+; Check that llc doesn't die when given an empty global ctor / dtor.
+ at llvm.global_ctors = appending global [0 x { i32, void ()*, i8* }] []
+ at llvm.global_dtors = appending global [0 x { i32, void ()*, i8* }] []
Index: llvm/trunk/test/CodeGen/NVPTX/global-ctor.ll
===================================================================
--- llvm/trunk/test/CodeGen/NVPTX/global-ctor.ll
+++ llvm/trunk/test/CodeGen/NVPTX/global-ctor.ll
@@ -0,0 +1,9 @@
+; RUN: not llc < %s -march=nvptx -mcpu=sm_20 2>&1 | FileCheck %s
+
+; Check that llc dies when given a nonempty global ctor.
+ at llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @foo, i8* null }]
+
+; CHECK: ERROR: Module has a nontrivial global ctor
+define internal void @foo() {
+  ret void
+}
Index: llvm/trunk/test/CodeGen/NVPTX/global-dtor.ll
===================================================================
--- llvm/trunk/test/CodeGen/NVPTX/global-dtor.ll
+++ llvm/trunk/test/CodeGen/NVPTX/global-dtor.ll
@@ -0,0 +1,9 @@
+; RUN: not llc < %s -march=nvptx -mcpu=sm_20 2>&1 | FileCheck %s
+
+; Check that llc dies when given a nonempty global dtor.
+ at llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @foo, i8* null }]
+
+; CHECK: ERROR: Module has a nontrivial global dtor
+define internal void @foo() {
+  ret void
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16739.46455.patch
Type: text/x-patch
Size: 3048 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160130/0b892393/attachment-0001.bin>


More information about the llvm-commits mailing list