fix a crash on code that uses the result value of __builtin___memcpy_chk.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129892 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp
index 51d9eeb..e553eb6 100644
--- a/lib/CodeGen/CGBuiltin.cpp
+++ b/lib/CodeGen/CGBuiltin.cpp
@@ -556,7 +556,7 @@
     Value *Src = EmitScalarExpr(E->getArg(1));
     Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size);
     Builder.CreateMemCpy(Dest, Src, SizeVal, 1, false);
-    return RValue::get(0);
+    return RValue::get(Dest);
   }
       
   case Builtin::BI__builtin_objc_memmove_collectable: {
@@ -581,7 +581,7 @@
     Value *Src = EmitScalarExpr(E->getArg(1));
     Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size);
     Builder.CreateMemMove(Dest, Src, SizeVal, 1, false);
-    return RValue::get(0);
+    return RValue::get(Dest);
   }
 
   case Builtin::BImemmove:
@@ -616,7 +616,7 @@
     Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size);
     Builder.CreateMemSet(Address, ByteVal, SizeVal, 1, false);
     
-    return RValue::get(0);
+    return RValue::get(Address);
   }
   case Builtin::BI__builtin_dwarf_cfa: {
     // The offset in bytes from the first argument to the CFA.
diff --git a/test/CodeGen/builtin-memfns.c b/test/CodeGen/builtin-memfns.c
index 2ea6793..fb4d720 100644
--- a/test/CodeGen/builtin-memfns.c
+++ b/test/CodeGen/builtin-memfns.c
@@ -42,3 +42,9 @@
 void test5(char *P, char *Q) {
   __builtin___memmove_chk(P, Q, 128, 128);
 }
+
+// CHECK: @test6
+// CHECK: call void @llvm.memcpy
+int test6(char *X) {
+  return __builtin___memcpy_chk(X, X, 42, 42) != 0;
+}