From 42f681b83378de1541919c7f72e7555e35158867 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 20 Apr 2011 23:14:50 +0000 Subject: [PATCH] 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 --- lib/CodeGen/CGBuiltin.cpp | 6 +++--- test/CodeGen/builtin-memfns.c | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp index 51d9eebaba..e553eb6c27 100644 --- a/lib/CodeGen/CGBuiltin.cpp +++ b/lib/CodeGen/CGBuiltin.cpp @@ -556,7 +556,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, 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 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, 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 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, 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 2ea6793654..fb4d720075 100644 --- a/test/CodeGen/builtin-memfns.c +++ b/test/CodeGen/builtin-memfns.c @@ -42,3 +42,9 @@ void test4(char *P, char *Q) { 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; +} -- 2.40.0