From 78d191089182842f6360547c48993e44de9e1437 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Tue, 21 Aug 2018 21:23:07 +0000 Subject: [WebAssembly] Restore __stack_pointer after catch instructions Summary: After the stack is unwound due to a thrown exception, the `__stack_pointer` global can point to an invalid address. This inserts instructions that restore `__stack_pointer` global. Reviewers: jgravelle-google, dschuff Subscribers: mgorny, sbc100, sunfish, llvm-commits Differential Revision: https://reviews.llvm.org/D50980 llvm-svn: 340339 --- llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp') diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp index 7c10f022cbb..1cc688599a9 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp @@ -58,6 +58,7 @@ extern "C" void LLVMInitializeWebAssemblyTarget() { initializeOptimizeReturnedPass(PR); initializeWebAssemblyArgumentMovePass(PR); initializeWebAssemblySetP2AlignOperandsPass(PR); + initializeWebAssemblyEHRestoreStackPointerPass(PR); initializeWebAssemblyReplacePhysRegsPass(PR); initializeWebAssemblyPrepareForLiveIntervalsPass(PR); initializeWebAssemblyOptimizeLiveIntervalsPass(PR); @@ -280,6 +281,9 @@ void WebAssemblyPassConfig::addPostRegAlloc() { void WebAssemblyPassConfig::addPreEmitPass() { TargetPassConfig::addPreEmitPass(); + // Restore __stack_pointer global after an exception is thrown. + addPass(createWebAssemblyEHRestoreStackPointer()); + // Now that we have a prologue and epilogue and all frame indices are // rewritten, eliminate SP and FP. This allows them to be stackified, // colored, and numbered with the rest of the registers. -- cgit v1.2.3