[PATCH] Fix failure to invoke exception handler on Win64.

Vadim Chugunov vadimcn at gmail.com
Fri Aug 1 11:39:41 PDT 2014


================
Comment at: lib/Target/X86/X86FrameLowering.cpp:844
@@ +843,3 @@
+      --MFI;
+      MBBI = MFI->end();
+    }
----------------
Reid Kleckner wrote:
> Does this not return one-past-the-end?
> 
> That aside, I don't think this will work in general, because basic block placement runs *after* prologue-epilogue insertion.
> 
> For now I think we should always insert a nop if the epilogue is at the beginning of a basic block, just to be safe. The actual solution is probably to insert some kind of target-specific pseudo that we lower out after block placement to either a nop or nothing.
> Does this not return one-past-the-end?
Hmm, yes it probably does.

> That aside, I don't think this will work in general, because basic block placement runs *after* prologue-epilogue insertion.

I can make it do what you suggest, though I think that 'ret' starts out in a MBB of its' own quite often.

> The actual solution is probably to insert some kind of target-specific pseudo that we lower out after block placement to either a nop or nothing.
I was considering creating 'SEH_Epilogue' pseudo, then checking for preceding CALLs when lowering it in X86AsmPrinter.   Unfortunately, some pseudos, like EH_LABEL, are not lowered till the last moment, so it'd still have to have logic to skip those.
How does that sound?

================
Comment at: test/CodeGen/X86/win64_call_epi.ll:1
@@ +1,2 @@
+; RUN: llc < %s -O0 -mcpu=corei7 -mtriple=x86_64-pc-mingw32 | FileCheck %s -check-prefix=WIN64
+
----------------
Reid Kleckner wrote:
> Does this fail without -O0?  Just curious.
No, it still works.   Just something I copied from another test...

================
Comment at: test/CodeGen/X86/win64_call_epi.ll:3
@@ +2,3 @@
+
+define void @foo() {
+
----------------
Reid Kleckner wrote:
> Can you come up with a test case that fails when block placement runs?  Something like this maybe:
> 
>   define void @bar(i1 zeroext %cond ) {
>     br i1 %cond, label %a, label %b  ; <- Add metadata to indicate that %a is *highly* likely over %b.
>   a:
>     call void @foo()
>     br label %done
>   b:
>     call void @baz()
>     store i32 0, i32* @something
>     br label %done
>   done:
>     ret void
>   }
Yeah, this breaks it. :(
Okay, that probably means I am gonna have to go with the SEH_Epilogue approach...

http://reviews.llvm.org/D4751






More information about the llvm-commits mailing list