diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp --- a/llvm/lib/IR/DebugInfoMetadata.cpp +++ b/llvm/lib/IR/DebugInfoMetadata.cpp @@ -1076,33 +1076,33 @@ Optional DIExpression::createFragmentExpression( const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits) { + if (!Expr) + return None; SmallVector Ops; // Copy over the expression, but leave off any trailing DW_OP_LLVM_fragment. - if (Expr) { - for (auto Op : Expr->expr_ops()) { - switch (Op.getOp()) { - default: break; - case dwarf::DW_OP_plus: - case dwarf::DW_OP_minus: - // We can't safely split arithmetic into multiple fragments because we - // can't express carry-over between fragments. - // - // FIXME: We *could* preserve the lowest fragment of a constant offset - // operation if the offset fits into SizeInBits. - return None; - case dwarf::DW_OP_LLVM_fragment: { - // Make the new offset point into the existing fragment. - uint64_t FragmentOffsetInBits = Op.getArg(0); - uint64_t FragmentSizeInBits = Op.getArg(1); - (void)FragmentSizeInBits; - assert((OffsetInBits + SizeInBits <= FragmentSizeInBits) && - "new fragment outside of original fragment"); - OffsetInBits += FragmentOffsetInBits; - continue; - } - } - Op.appendToVector(Ops); + for (auto Op : Expr->expr_ops()) { + switch (Op.getOp()) { + default: break; + case dwarf::DW_OP_plus: + case dwarf::DW_OP_minus: + // We can't safely split arithmetic into multiple fragments because we + // can't express carry-over between fragments. + // + // FIXME: We *could* preserve the lowest fragment of a constant offset + // operation if the offset fits into SizeInBits. + return None; + case dwarf::DW_OP_LLVM_fragment: { + // Make the new offset point into the existing fragment. + uint64_t FragmentOffsetInBits = Op.getArg(0); + uint64_t FragmentSizeInBits = Op.getArg(1); + (void)FragmentSizeInBits; + assert((OffsetInBits + SizeInBits <= FragmentSizeInBits) && + "new fragment outside of original fragment"); + OffsetInBits += FragmentOffsetInBits; + continue; } + } + Op.appendToVector(Ops); } Ops.push_back(dwarf::DW_OP_LLVM_fragment); Ops.push_back(OffsetInBits);