Fix a bug with the use of __builtin_bzero in a conditional expression.
authorJohn McCall <rjmccall@apple.com>
Thu, 9 Nov 2017 09:32:32 +0000 (09:32 +0000)
committerJohn McCall <rjmccall@apple.com>
Thu, 9 Nov 2017 09:32:32 +0000 (09:32 +0000)
Patch by Bharathi Seshadri!

llvm-svn: 317776

clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtins.c

index 369240f..2d1b4f4 100644 (file)
@@ -1431,7 +1431,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
     EmitNonNullArgCheck(RValue::get(Dest.getPointer()), E->getArg(0)->getType(),
                         E->getArg(0)->getExprLoc(), FD, 0);
     Builder.CreateMemSet(Dest, Builder.getInt8(0), SizeVal, false);
-    return RValue::get(Dest.getPointer());
+    return RValue::get(nullptr);
   }
   case Builtin::BImemcpy:
   case Builtin::BI__builtin_memcpy: {
index 86bee45..0207bb6 100644 (file)
@@ -176,6 +176,19 @@ void bar() {
 }
 // CHECK: }
 
+// CHECK-LABEL: define void @test_conditional_bzero
+void test_conditional_bzero() {
+  char dst[20];
+  int _sz = 20, len = 20;
+  return (_sz
+          ? ((_sz >= len)
+              ? __builtin_bzero(dst, len)
+              : foo())
+          : __builtin_bzero(dst, len));
+  // CHECK: call void @llvm.memset
+  // CHECK: call void @llvm.memset
+  // CHECK-NOT: phi
+}
 
 // CHECK-LABEL: define void @test_float_builtins
 void test_float_builtins(float F, double D, long double LD) {