llvm.org GIT mirror llvm / da9c587
[WinEH] Emit the LSDA even if no lpads remain but outlining occurred The outlined funclets call intrinsics which reference labels from the LSDA. This situation can easily arise in small functions with a single cleanup at -O0, where Clang marks a definition as nounwind, and then WinEHPrepare "discovers" that the landingpad is dead by accident and deletes it. We now need to ask the LLVM IR Function for it's personality directly, rather than going through MachineModuleInfo. Fixes PR23892. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242063 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 5 years ago
2 changed file(s) with 49 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
6969
7070 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
7171 unsigned PerEncoding = TLOF.getPersonalityEncoding();
72 const Function *Per = MMI->getPersonality();
72 const Function *Per = nullptr;
73 if (F->hasPersonalityFn())
74 Per = dyn_cast(F->getPersonalityFn()->stripPointerCasts());
7375
7476 shouldEmitPersonality = hasLandingPads &&
7577 PerEncoding != dwarf::DW_EH_PE_omit && Per;
7880 shouldEmitLSDA = shouldEmitPersonality &&
7981 LSDAEncoding != dwarf::DW_EH_PE_omit;
8082
81 // If we're not using CFI, we don't want the CFI or the personality. Emit the
82 // LSDA if this is the parent function.
83 // If we're not using CFI, we don't want the CFI or the personality. If
84 // WinEHPrepare outlined something, we should emit the LSDA.
8385 if (!Asm->MAI->usesWindowsCFI()) {
84 shouldEmitLSDA = (hasLandingPads && F == ParentF);
86 bool HasOutlinedChildren =
87 F->hasFnAttribute("wineh-parent") && F == ParentF;
88 shouldEmitLSDA = HasOutlinedChildren;
8589 shouldEmitPersonality = false;
8690 return;
8791 }
120124 if (!shouldEmitPersonality && !shouldEmitMoves && !shouldEmitLSDA)
121125 return;
122126
123 EHPersonality Per = MMI->getPersonalityType();
127 const Function *F = MF->getFunction();
128 EHPersonality Per = EHPersonality::Unknown;
129 if (F->hasPersonalityFn())
130 Per = classifyEHPersonality(F->getPersonalityFn());
124131
125132 // Get rid of any dead landing pads if we're not using a Windows EH scheme. In
126133 // Windows EH schemes, the landing pad is not actually reachable. It only
581588 OS.EmitValueToAlignment(4);
582589 OS.EmitLabel(LSDALabel);
583590
584 const Function *Per = MMI->getPersonality();
591 const Function *Per =
592 dyn_cast(F->getPersonalityFn()->stripPointerCasts());
585593 StringRef PerName = Per->getName();
586594 int BaseState = -1;
587595 if (PerName == "_except_handler4") {
0 ; RUN: llc -mtriple=i686-pc-windows-msvc < %s | FileCheck %s
1
2 ; Sometimes invokes of nounwind functions make it through to CodeGen, especially
3 ; at -O0, where Clang sometimes optimistically annotates functions as nounwind.
4 ; WinEHPrepare ends up outlining functions, and emitting references to LSDA
5 ; labels. Make sure we emit the LSDA in that case.
6
7 declare i32 @__CxxFrameHandler3(...)
8 declare void @nounwind_func() nounwind
9 declare void @cleanup()
10
11 define void @should_emit_tables() personality i32 (...)* @__CxxFrameHandler3 {
12 entry:
13 invoke void @nounwind_func()
14 to label %done unwind label %lpad
15
16 done:
17 ret void
18
19 lpad:
20 %vals = landingpad { i8*, i32 }
21 cleanup
22 call void @cleanup()
23 resume { i8*, i32 } %vals
24 }
25
26 ; CHECK: _should_emit_tables:
27 ; CHECK: calll _nounwind_func
28 ; CHECK: retl
29
30 ; CHECK: L__ehtable$should_emit_tables:
31
32 ; CHECK: ___ehhandler$should_emit_tables:
33 ; CHECK: movl $L__ehtable$should_emit_tables, %eax
34 ; CHECK: jmp ___CxxFrameHandler3 # TAILCALL