RValue RV = EmitCall(CGM.getTypes().getFunctionInfo(ResultType, CallArgs),
Callee, CallArgs, MD);
if (nv_r || v_r) {
+ bool CanBeZero = !(ResultType->isReferenceType()
+ // FIXME: attr nonnull can't be zero either
+ /* || ResultType->hasAttr<NonNullAttr>() */ );
// Do the return result adjustment.
- llvm::BasicBlock *NonZeroBlock = createBasicBlock();
- llvm::BasicBlock *ZeroBlock = createBasicBlock();
- llvm::BasicBlock *ContBlock = createBasicBlock();
-
- const llvm::Type *Ty = RV.getScalarVal()->getType();
- llvm::Value *Zero = llvm::Constant::getNullValue(Ty);
- Builder.CreateCondBr(Builder.CreateICmpNE(RV.getScalarVal(), Zero),
- NonZeroBlock, ZeroBlock);
- EmitBlock(NonZeroBlock);
- llvm::Value *NZ = DynamicTypeAdjust(RV.getScalarVal(), nv_r, v_r);
- EmitBranch(ContBlock);
- EmitBlock(ZeroBlock);
- llvm::Value *Z = RV.getScalarVal();
- EmitBlock(ContBlock);
- llvm::PHINode *RVOrZero = Builder.CreatePHI(Ty);
- RVOrZero->reserveOperandSpace(2);
- RVOrZero->addIncoming(NZ, NonZeroBlock);
- RVOrZero->addIncoming(Z, ZeroBlock);
- RV = RValue::get(RVOrZero);
+ if (CanBeZero) {
+ llvm::BasicBlock *NonZeroBlock = createBasicBlock();
+ llvm::BasicBlock *ZeroBlock = createBasicBlock();
+ llvm::BasicBlock *ContBlock = createBasicBlock();
+
+ const llvm::Type *Ty = RV.getScalarVal()->getType();
+ llvm::Value *Zero = llvm::Constant::getNullValue(Ty);
+ Builder.CreateCondBr(Builder.CreateICmpNE(RV.getScalarVal(), Zero),
+ NonZeroBlock, ZeroBlock);
+ EmitBlock(NonZeroBlock);
+ llvm::Value *NZ = DynamicTypeAdjust(RV.getScalarVal(), nv_r, v_r);
+ EmitBranch(ContBlock);
+ EmitBlock(ZeroBlock);
+ llvm::Value *Z = RV.getScalarVal();
+ EmitBlock(ContBlock);
+ llvm::PHINode *RVOrZero = Builder.CreatePHI(Ty);
+ RVOrZero->reserveOperandSpace(2);
+ RVOrZero->addIncoming(NZ, NonZeroBlock);
+ RVOrZero->addIncoming(Z, ZeroBlock);
+ RV = RValue::get(RVOrZero);
+ } else
+ RV = RValue::get(DynamicTypeAdjust(RV.getScalarVal(), nv_r, v_r));
}
if (!ResultType->isVoidType())