Fix for PR5454: make sure to use the right block as the predecessor in the
generated PHI node for the null check of a new operator.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86738 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGCXXExpr.cpp b/lib/CodeGen/CGCXXExpr.cpp
index 2d62df6..8b0490f 100644
--- a/lib/CodeGen/CGCXXExpr.cpp
+++ b/lib/CodeGen/CGCXXExpr.cpp
@@ -218,6 +218,7 @@
 
   if (NullCheckResult) {
     Builder.CreateBr(NewEnd);
+    NewNotNull = Builder.GetInsertBlock();
     EmitBlock(NewNull);
     Builder.CreateBr(NewEnd);
     EmitBlock(NewEnd);
diff --git a/test/CodeGenCXX/new-operator-phi.cpp b/test/CodeGenCXX/new-operator-phi.cpp
new file mode 100644
index 0000000..d4c698d
--- /dev/null
+++ b/test/CodeGenCXX/new-operator-phi.cpp
@@ -0,0 +1,10 @@
+// RUN: clang-cc -emit-llvm-only -verify %s
+// PR5454
+
+class X {static void * operator new(unsigned size) throw(); X(int); };
+int a(), b();
+void b(int x)
+{
+  new X(x ? a() : b());
+}
+