Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblyLowerGlobalDtors.cpp =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssemblyLowerGlobalDtors.cpp +++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyLowerGlobalDtors.cpp @@ -61,7 +61,7 @@ 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(GV->getInitializer()); Index: llvm/trunk/test/CodeGen/WebAssembly/global_dtors.ll =================================================================== --- llvm/trunk/test/CodeGen/WebAssembly/global_dtors.ll +++ llvm/trunk/test/CodeGen/WebAssembly/global_dtors.ll @@ -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* }]