]> granicus.if.org Git - llvm/commitdiff
[WebAssembly] Fix crash when @llvm.global_dtors is external
authorThomas Lively <tlively@google.com>
Fri, 1 Mar 2019 00:12:13 +0000 (00:12 +0000)
committerThomas Lively <tlively@google.com>
Fri, 1 Mar 2019 00:12:13 +0000 (00:12 +0000)
Reviewers: aheejin

Subscribers: dschuff, sbc100, jgravelle-google, hiraditya, sunfish, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D58799

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355157 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/WebAssembly/WebAssemblyLowerGlobalDtors.cpp
test/CodeGen/WebAssembly/global_dtors.ll [new file with mode: 0644]

index 72e0c33e1e0267e09009f11e5464a02d63605959..494d3fadbc8c82f1d823024a5441502971161a32 100644 (file)
@@ -61,7 +61,7 @@ bool LowerGlobalDtors::runOnModule(Module &M) {
   LLVM_DEBUG(dbgs() << "********** Lower Global Destructors **********\n");
 
   GlobalVariable *GV = M.getGlobalVariable("llvm.global_dtors");
-  if (!GV)
+  if (!GV || !GV->hasInitializer())
     return false;
 
   const ConstantArray *InitList = dyn_cast<ConstantArray>(GV->getInitializer());
diff --git a/test/CodeGen/WebAssembly/global_dtors.ll b/test/CodeGen/WebAssembly/global_dtors.ll
new file mode 100644 (file)
index 0000000..9321dc5
--- /dev/null
@@ -0,0 +1,9 @@
+; RUN: llc < %s
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+; Check that we do not crash when attempting to lower away
+; global_dtors without a definition.
+
+@llvm.global_dtors = external global [2 x { i32, void ()*, i8* }]