]> granicus.if.org Git - clang/commitdiff
References can't be zero; omit zero check for return value adjustments
authorMike Stump <mrs@apple.com>
Thu, 5 Nov 2009 06:32:02 +0000 (06:32 +0000)
committerMike Stump <mrs@apple.com>
Thu, 5 Nov 2009 06:32:02 +0000 (06:32 +0000)
in covariant thunks that return references.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86121 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCXX.cpp

index fd90dc06d505c73d365361f05e9fd7fe7e19d96d..cf172b1a1cb6ec5bd53c10d109c8458abeb593ca 100644 (file)
@@ -810,26 +810,32 @@ llvm::Constant *CodeGenFunction::GenerateCovariantThunk(llvm::Function *Fn,
   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())