Index: lib/Target/NVPTX/NVPTXISelLowering.cpp =================================================================== --- lib/Target/NVPTX/NVPTXISelLowering.cpp +++ lib/Target/NVPTX/NVPTXISelLowering.cpp @@ -987,43 +987,46 @@ Type *Ty, unsigned Idx) const { const DataLayout *TD = getDataLayout(); - unsigned Align = 0; - const Value *DirectCallee = CS->getCalledFunction(); - if (!DirectCallee) { - // We don't have a direct function symbol, but that may be because of - // constant cast instructions in the call. - const Instruction *CalleeI = CS->getInstruction(); - assert(CalleeI && "Call target is not a function or derived value?"); - - // With bitcast'd call targets, the instruction will be the call - if (isa(CalleeI)) { - // Check if we have call alignment metadata - if (llvm::getAlign(*cast(CalleeI), Idx, Align)) - return Align; - - const Value *CalleeV = cast(CalleeI)->getCalledValue(); - // Ignore any bitcast instructions - while(isa(CalleeV)) { - const ConstantExpr *CE = cast(CalleeV); - if (!CE->isCast()) - break; - // Look through the bitcast - CalleeV = cast(CalleeV)->getOperand(0); + if (CS) { + unsigned Align = 0; + const Value *DirectCallee = CS->getCalledFunction(); + + if (!DirectCallee) { + // We don't have a direct function symbol, but that may be because of + // constant cast instructions in the call. + const Instruction *CalleeI = CS->getInstruction(); + assert(CalleeI && "Call target is not a function or derived value?"); + + // With bitcast'd call targets, the instruction will be the call + if (isa(CalleeI)) { + // Check if we have call alignment metadata + if (llvm::getAlign(*cast(CalleeI), Idx, Align)) + return Align; + + const Value *CalleeV = cast(CalleeI)->getCalledValue(); + // Ignore any bitcast instructions + while(isa(CalleeV)) { + const ConstantExpr *CE = cast(CalleeV); + if (!CE->isCast()) + break; + // Look through the bitcast + CalleeV = cast(CalleeV)->getOperand(0); + } + + // We have now looked past all of the bitcasts. Do we finally have a + // Function? + if (isa(CalleeV)) + DirectCallee = CalleeV; } - - // We have now looked past all of the bitcasts. Do we finally have a - // Function? - if (isa(CalleeV)) - DirectCallee = CalleeV; } - } - // Check for function alignment information if we found that the - // ultimate target is a Function - if (DirectCallee) - if (llvm::getAlign(*cast(DirectCallee), Idx, Align)) - return Align; + // Check for function alignment information if we found that the + // ultimate target is a Function + if (DirectCallee) + if (llvm::getAlign(*cast(DirectCallee), Idx, Align)) + return Align; + } // Call is indirect or alignment information is not available, fall back to // the ABI type alignment