Index: lib/CodeGen/LocalStackSlotAllocation.cpp =================================================================== --- lib/CodeGen/LocalStackSlotAllocation.cpp +++ lib/CodeGen/LocalStackSlotAllocation.cpp @@ -99,7 +99,7 @@ void getAnalysisUsage(AnalysisUsage &AU) const override { AU.setPreservesCFG(); - AU.addRequired(); + AU.addUsedIfAvailable(); MachineFunctionPass::getAnalysisUsage(AU); } }; @@ -202,7 +202,7 @@ TFI.getStackGrowthDirection() == TargetFrameLowering::StackGrowsDown; int64_t Offset = 0; unsigned MaxAlign = 0; - StackProtector *SP = &getAnalysis(); + StackProtector *SP = getAnalysisIfAvailable(); // Make sure that the stack protector comes before the local variables on the // stack. @@ -222,18 +222,20 @@ if (MFI.getStackProtectorIndex() == (int)i) continue; - switch (SP->getSSPLayout(MFI.getObjectAllocation(i))) { - case StackProtector::SSPLK_None: - continue; - case StackProtector::SSPLK_SmallArray: - SmallArrayObjs.insert(i); - continue; - case StackProtector::SSPLK_AddrOf: - AddrOfObjs.insert(i); - continue; - case StackProtector::SSPLK_LargeArray: - LargeArrayObjs.insert(i); - continue; + if (SP) { + switch (SP->getSSPLayout(MFI.getObjectAllocation(i))) { + case StackProtector::SSPLK_None: + continue; + case StackProtector::SSPLK_SmallArray: + SmallArrayObjs.insert(i); + continue; + case StackProtector::SSPLK_AddrOf: + AddrOfObjs.insert(i); + continue; + case StackProtector::SSPLK_LargeArray: + LargeArrayObjs.insert(i); + continue; + } } llvm_unreachable("Unexpected SSPLayoutKind."); } Index: lib/CodeGen/PrologEpilogInserter.cpp =================================================================== --- lib/CodeGen/PrologEpilogInserter.cpp +++ lib/CodeGen/PrologEpilogInserter.cpp @@ -160,7 +160,7 @@ AU.setPreservesCFG(); AU.addPreserved(); AU.addPreserved(); - AU.addRequired(); + AU.addUsedIfAvailable(); AU.addRequired(); MachineFunctionPass::getAnalysisUsage(AU); } @@ -695,7 +695,7 @@ /// abstract stack objects. void PEI::calculateFrameObjectOffsets(MachineFunction &MF) { const TargetFrameLowering &TFI = *MF.getSubtarget().getFrameLowering(); - StackProtector *SP = &getAnalysis(); + StackProtector *SP = getAnalysisIfAvailable(); bool StackGrowsDown = TFI.getStackGrowthDirection() == TargetFrameLowering::StackGrowsDown; @@ -844,18 +844,20 @@ EHRegNodeFrameIndex == (int)i) continue; - switch (SP->getSSPLayout(MFI.getObjectAllocation(i))) { - case StackProtector::SSPLK_None: - continue; - case StackProtector::SSPLK_SmallArray: - SmallArrayObjs.insert(i); - continue; - case StackProtector::SSPLK_AddrOf: - AddrOfObjs.insert(i); - continue; - case StackProtector::SSPLK_LargeArray: - LargeArrayObjs.insert(i); - continue; + if (SP) { + switch (SP->getSSPLayout(MFI.getObjectAllocation(i))) { + case StackProtector::SSPLK_None: + continue; + case StackProtector::SSPLK_SmallArray: + SmallArrayObjs.insert(i); + continue; + case StackProtector::SSPLK_AddrOf: + AddrOfObjs.insert(i); + continue; + case StackProtector::SSPLK_LargeArray: + LargeArrayObjs.insert(i); + continue; + } } llvm_unreachable("Unexpected SSPLayoutKind."); } Index: lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -327,7 +327,7 @@ if (OptLevel != CodeGenOpt::None) AU.addRequired(); AU.addRequired(); - AU.addRequired(); + AU.addUsedIfAvailable(); AU.addPreserved(); AU.addPreserved(); AU.addRequired(); @@ -1713,7 +1713,8 @@ FastIS->recomputeInsertPt(); } - if (getAnalysis().shouldEmitSDCheck(*LLVMBB)) { + StackProtector *SP = getAnalysisIfAvailable(); + if (SP && SP->shouldEmitSDCheck(*LLVMBB)) { bool FunctionBasedInstrumentation = TLI->getSSPStackGuardCheck(*Fn.getParent()); SDB->SPDescriptor.initialize(LLVMBB, FuncInfo->MBBMap[LLVMBB], Index: lib/CodeGen/StackColoring.cpp =================================================================== --- lib/CodeGen/StackColoring.cpp +++ lib/CodeGen/StackColoring.cpp @@ -530,7 +530,8 @@ void StackColoring::getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired(); - AU.addRequired(); + AU.addUsedIfAvailable(); + AU.addPreserved(); MachineFunctionPass::getAnalysisUsage(AU); } @@ -938,7 +939,8 @@ // Allow the stack protector to adjust its value map to account for the // upcoming replacement. - SP->adjustForColoring(From, To); + if (SP) + SP->adjustForColoring(From, To); // The new alloca might not be valid in a llvm.dbg.declare for this // variable, so undef out the use to make the verifier happy. @@ -1139,7 +1141,7 @@ MF = &Func; MFI = &MF->getFrameInfo(); Indexes = &getAnalysis(); - SP = &getAnalysis(); + SP = getAnalysisIfAvailable(); BlockLiveness.clear(); BasicBlocks.clear(); BasicBlockNumbering.clear(); Index: test/CodeGen/X86/PR37310.mir =================================================================== --- test/CodeGen/X86/PR37310.mir +++ test/CodeGen/X86/PR37310.mir @@ -1,4 +1,4 @@ -# RUN: llc -mtriple=x86_64-unknown-linux-gnu -mcpu=corei7 -start-before dwarfehprepare -no-stack-coloring=false -stop-after stack-coloring -o - %s +# RUN: llc -mtriple=x86_64-unknown-linux-gnu -mcpu=corei7 -no-stack-coloring=false -run-pass stack-coloring -o - %s # Test to insure that the liveness analysis in the StackColoring # pass gracefully handles statically unreachable blocks. See PR 37310.