]> granicus.if.org Git - clang/commitdiff
Refine covariant return value adjustments for thunks when null
authorMike Stump <mrs@apple.com>
Thu, 5 Nov 2009 06:12:26 +0000 (06:12 +0000)
committerMike Stump <mrs@apple.com>
Thu, 5 Nov 2009 06:12:26 +0000 (06:12 +0000)
pointers are returned.

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

lib/CodeGen/CGCXX.cpp
test/CodeGenCXX/virt.cpp

index d4adbad1e45e240f68484a9832ab84aa11fcb304..fd90dc06d505c73d365361f05e9fd7fe7e19d96d 100644 (file)
@@ -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())
index a85b2dfe477e3443aec2201a27427c4be20a0a83..193a96ddd5897c1609d57c4cf2fc3b70c1bf4363 100644 (file)
@@ -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 {