From: Mike Stump Date: Thu, 5 Nov 2009 06:12:26 +0000 (+0000) Subject: Refine covariant return value adjustments for thunks when null X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7c276b84d6881df18c847b036fe3c95d94d9b5b3;p=clang Refine covariant return value adjustments for thunks when null pointers are returned. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86120 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp index d4adbad1e4..fd90dc06d5 100644 --- a/lib/CodeGen/CGCXX.cpp +++ b/lib/CodeGen/CGCXX.cpp @@ -811,7 +811,25 @@ llvm::Constant *CodeGenFunction::GenerateCovariantThunk(llvm::Function *Fn, Callee, CallArgs, MD); if (nv_r || v_r) { // Do the return result adjustment. - RV = RValue::get(DynamicTypeAdjust(RV.getScalarVal(), nv_r, v_r)); + 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 (!ResultType->isVoidType()) diff --git a/test/CodeGenCXX/virt.cpp b/test/CodeGenCXX/virt.cpp index a85b2dfe47..193a96ddd5 100644 --- a/test/CodeGenCXX/virt.cpp +++ b/test/CodeGenCXX/virt.cpp @@ -1076,12 +1076,16 @@ void test16_D::bar() { } // CHECK-LPOPT64-NEXT: subq $8, %rsp // CHECK-LPOPT64-NEXT:Llabel // CHECK-LPOPT64-NEXT: call __ZN8test16_D4foo1Ev -// FIXME: We need a == 0 check here +// CHECK-LPOPT64-NEXT: testq %rax, %rax +// CHECK-LPOPT64-NEXT: je LBB102_2 // CHECK-LPOPT64-NEXT: movq 16(%rax), %rcx // CHECK-LPOPT64-NEXT: movq -32(%rcx), %rcx // CHECK-LPOPT64-NEXT: leaq 16(%rcx,%rax), %rax // CHECK-LPOPT64-NEXT: addq $8, %rsp // CHECK-LPOPT64-NEXT: ret +// CHECK-LPOPT64-NEXT:LBB102_2: +// CHECK-LPOPT64-NEXT: addq $8, %rsp +// CHECK-LPOPT64-NEXT: ret class test17_B1 {