llvm.org GIT mirror llvm / 64b2297
Patch by Vadim Chugunov Win64 stack unwinder gets confused when execution flow "falls through" after a call to 'noreturn' function. This fixes the "missing epilogue" problem by emitting a trap instruction for IR 'unreachable' on x86_x64-pc-windows. A secondary use for it would be for anyone wanting to make double-sure that 'noreturn' functions, indeed, do not return. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206684 91177308-0d34-0410-b5e6-96231b3b80d8 Yaron Keren 6 years ago
6 changed file(s) with 37 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
5050 EnableFastISel(false), PositionIndependentExecutable(false),
5151 UseInitArray(false),
5252 DisableIntegratedAS(false), CompressDebugSections(false),
53 TrapUnreachable(false),
5354 TrapFuncName(""), FloatABIType(FloatABI::Default),
5455 AllowFPOpFusion(FPOpFusion::Standard) {}
5556
160161
161162 /// Compress DWARF debug sections.
162163 unsigned CompressDebugSections : 1;
164
165 /// Emit target-specific trap instruction for 'unreachable' IR instructions.
166 unsigned TrapUnreachable : 1;
163167
164168 /// getTrapFunctionName - If this returns a non-empty string, this means
165169 /// isel should lower Intrinsic::trap to a call to the specified function
215219 ARE_EQUAL(EnableFastISel) &&
216220 ARE_EQUAL(PositionIndependentExecutable) &&
217221 ARE_EQUAL(UseInitArray) &&
222 ARE_EQUAL(TrapUnreachable) &&
218223 ARE_EQUAL(TrapFuncName) &&
219224 ARE_EQUAL(FloatABIType) &&
220225 ARE_EQUAL(AllowFPOpFusion);
10401040 }
10411041
10421042 case Instruction::Unreachable:
1043 // Nothing to emit.
1044 return true;
1043 if (TM.Options.TrapUnreachable)
1044 return FastEmit_(MVT::Other, MVT::Other, ISD::TRAP) != 0;
1045 else
1046 return true;
10451047
10461048 case Instruction::Alloca:
10471049 // FunctionLowering has the static-sized case covered.
27622762 DAG.setRoot(DAG.getNode(ISD::BRIND, getCurSDLoc(),
27632763 MVT::Other, getControlRoot(),
27642764 getValue(I.getAddress())));
2765 }
2766
2767 void SelectionDAGBuilder::visitUnreachable(const UnreachableInst &I) {
2768 if (DAG.getTarget().Options.TrapUnreachable)
2769 DAG.setRoot(DAG.getNode(ISD::TRAP, getCurSDLoc(), MVT::Other, DAG.getRoot()));
27652770 }
27662771
27672772 void SelectionDAGBuilder::visitFSub(const User &I) {
641641 void visitBr(const BranchInst &I);
642642 void visitSwitch(const SwitchInst &I);
643643 void visitIndirectBr(const IndirectBrInst &I);
644 void visitUnreachable(const UnreachableInst &I) { /* noop */ }
644 void visitUnreachable(const UnreachableInst &I);
645645
646646 // Helpers for visitSwitch
647647 bool handleSmallSwitchRange(CaseRec& CR,
107107 if (Options.FloatABIType == FloatABI::Default)
108108 this->Options.FloatABIType = FloatABI::Hard;
109109
110 // Windows stack unwinder gets confused when execution flow "falls through"
111 // after a call to 'noreturn' function.
112 // To prevent that, we emit a trap for 'unreachable' IR instructions.
113 // (which on X86, happens to be the 'ud2' instruction)
114 if (Subtarget.isTargetWin64())
115 this->Options.TrapUnreachable = true;
116
110117 initAsmInfo();
111118 }
112119
None ; RUN: llc -march=x86-64 < %s | FileCheck %s
0 ; RUN: llc -mtriple=x86_64-apple-darwin < %s | FileCheck -check-prefix=X64_DARWIN %s
1 ; RUN: llc -mtriple=x86_64-pc-linux < %s | FileCheck -check-prefix=X64_LINUX %s
2 ; RUN: llc -mtriple=x86_64-pc-windows < %s | FileCheck -check-prefix=X64_WINDOWS %s
3 ; RUN: llc -mtriple=x86_64-pc-windows-gnu < %s | FileCheck -check-prefix=X64_WINDOWS_GNU %s
14
2 ; CHECK: orq
3 ; CHECK-NEXT: %bb8.i329
5 ; X64_DARWIN: orq
6 ; X64_DARWIN-NEXT: %bb8.i329
7
8 ; X64_LINUX: orq %rax, %rcx
9 ; X64_LINUX-NEXT: %bb8.i329
10
11 ; X64_WINDOWS: orq %rax, %rcx
12 ; X64_WINDOWS-NEXT: ud2
13
14 ; X64_WINDOWS_GNU: orq %rax, %rcx
15 ; X64_WINDOWS_GNU-NEXT: ud2
416
517 @_ZN11xercesc_2_513SchemaSymbols21fgURI_SCHEMAFORSCHEMAE = external constant [33 x i16], align 32 ; <[33 x i16]*> [#uses=1]
618 @_ZN11xercesc_2_56XMLUni16fgNotationStringE = external constant [9 x i16], align 16 ; <[9 x i16]*> [#uses=1]