Propagating prior merge from 'llvm.org/release_40'.
diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp
index 0092447..b10a549 100644
--- a/lib/CodeGen/CGExprAgg.cpp
+++ b/lib/CodeGen/CGExprAgg.cpp
@@ -505,12 +505,20 @@
     currentElement->addIncoming(element, entryBB);
 
     // Emit the actual filler expression.
-    LValue elementLV =
-      CGF.MakeAddrLValue(Address(currentElement, elementAlign), elementType);
-    if (filler)
-      EmitInitializationToLValue(filler, elementLV);
-    else
-      EmitNullInitializationToLValue(elementLV);
+    {
+      // C++1z [class.temporary]p5:
+      //   when a default constructor is called to initialize an element of
+      //   an array with no corresponding initializer [...] the destruction of
+      //   every temporary created in a default argument is sequenced before
+      //   the construction of the next array element, if any
+      CodeGenFunction::RunCleanupsScope CleanupsScope(CGF);
+      LValue elementLV =
+        CGF.MakeAddrLValue(Address(currentElement, elementAlign), elementType);
+      if (filler)
+        EmitInitializationToLValue(filler, elementLV);
+      else
+        EmitNullInitializationToLValue(elementLV);
+    }
 
     // Move on to the next element.
     llvm::Value *nextElement =
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index a9e0a84..46aee60 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -11644,7 +11644,7 @@
                  Context.getLangOpts().OpenCLVersion < 120) {
         // OpenCL v1.1 6.3.h: The logical operator not (!) does not
         // operate on scalar float types.
-        if (!resultType->isIntegerType())
+        if (!resultType->isIntegerType() && !resultType->isPointerType())
           return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr)
                            << resultType << Input.get()->getSourceRange());
       }
diff --git a/test/CodeGenCXX/array-default-argument.cpp b/test/CodeGenCXX/array-default-argument.cpp
new file mode 100644
index 0000000..a07e390
--- /dev/null
+++ b/test/CodeGenCXX/array-default-argument.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -emit-llvm -o - %s -triple %itanium_abi_triple | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -o - %s -triple %itanium_abi_triple -std=c++98 -fexceptions -fcxx-exceptions | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-EH
+
+struct A {
+  A();
+  ~A();
+};
+
+struct B {
+  B(A = A());
+  ~B();
+};
+
+void f();
+// CHECK-LABEL: define void @_Z1gv()
+void g() {
+  // CHECK: br label %[[LOOP:.*]]
+
+  // [[LOOP]]:
+  // CHECK: {{call|invoke}} {{.*}} @_ZN1AC1Ev([[TEMPORARY:.*]])
+  // CHECK-EH:  unwind label %[[PARTIAL_ARRAY_LPAD:.*]]
+  // CHECK: {{call|invoke}} {{.*}} @_ZN1BC1E1A({{.*}}, [[TEMPORARY]])
+  // CHECK-EH:  unwind label %[[A_AND_PARTIAL_ARRAY_LPAD:.*]]
+  // CHECK: {{call|invoke}} {{.*}} @_ZN1AD1Ev([[TEMPORARY]])
+  // CHECK-EH:  unwind label %[[PARTIAL_ARRAY_LPAD]]
+  // CHECK: getelementptr {{.*}}, i{{[0-9]*}} 1
+  // CHECK: icmp eq
+  // CHECK: br i1 {{.*}} label %[[LOOP]]
+  B b[5];
+
+  // CHECK: {{call|invoke}} void @_Z1fv()
+  f();
+
+  // CHECK-NOT: @_ZN1AD1Ev(
+  // CHECK: {{call|invoke}} {{.*}} @_ZN1BD1Ev(
+}
diff --git a/test/SemaOpenCL/invalid-logical-ops-1.1.cl b/test/SemaOpenCL/invalid-logical-ops-1.1.cl
deleted file mode 100644
index 2269dd3..0000000
--- a/test/SemaOpenCL/invalid-logical-ops-1.1.cl
+++ /dev/null
@@ -1,57 +0,0 @@
-// RUN: %clang_cc1 %s -verify -cl-std=CL1.1 -triple x86_64-unknown-linux-gnu
-
-#pragma OPENCL EXTENSION cl_khr_fp64 : enable
-typedef __attribute__((ext_vector_type(4))) float float4;
-typedef __attribute__((ext_vector_type(4))) double double4;
-typedef __attribute__((ext_vector_type(4))) int int4;
-typedef __attribute__((ext_vector_type(4))) long long4;
-
-kernel void float_ops() {
-  int flaf = 0.0f && 0.0f; // expected-error {{invalid operands}}
-  int flof = 0.0f || 0.0f; // expected-error {{invalid operands}}
-  float fbaf = 0.0f & 0.0f; // expected-error {{invalid operands}}
-  float fbof = 0.0f | 0.0f; // expected-error {{invalid operands}}
-  float fbxf = 0.0f ^ 0.0f; // expected-error {{invalid operands}}
-  int flai = 0.0f && 0; // expected-error {{invalid operands}}
-  int floi = 0.0f || 0; // expected-error {{invalid operands}}
-  float ibaf = 0 & 0.0f; // expected-error {{invalid operands}}
-  float ibof = 0 | 0.0f; // expected-error {{invalid operands}}
-  float bnf = ~0.0f; // expected-error {{invalid argument type}}
-  float lnf = !0.0f; // expected-error {{invalid argument type}}
-}
-
-kernel void vec_float_ops() {
-  float4 f4 = (float4)(0, 0, 0, 0);
-  int4 f4laf = f4 && 0.0f; // expected-error {{invalid operands}}
-  int4 f4lof = f4 || 0.0f; // expected-error {{invalid operands}}
-  float4 f4baf = f4 & 0.0f; // expected-error {{invalid operands}}
-  float4 f4bof = f4 | 0.0f; // expected-error {{invalid operands}}
-  float4 f4bxf = f4 ^ 0.0f; // expected-error {{invalid operands}}
-  float bnf4 = ~f4; // expected-error {{invalid argument type}}
-  int4 lnf4 = !f4; // expected-error {{invalid argument type}}
-}
-
-kernel void double_ops() {
-  int flaf = 0.0 && 0.0; // expected-error {{invalid operands}}
-  int flof = 0.0 || 0.0; // expected-error {{invalid operands}}
-  double fbaf = 0.0 & 0.0; // expected-error {{invalid operands}}
-  double fbof = 0.0 | 0.0; // expected-error {{invalid operands}}
-  double fbxf = 0.0 ^ 0.0; // expected-error {{invalid operands}}
-  int flai = 0.0 && 0; // expected-error {{invalid operands}}
-  int floi = 0.0 || 0; // expected-error {{invalid operands}}
-  double ibaf = 0 & 0.0; // expected-error {{invalid operands}}
-  double ibof = 0 | 0.0; // expected-error {{invalid operands}}
-  double bnf = ~0.0; // expected-error {{invalid argument type}}
-  double lnf = !0.0; // expected-error {{invalid argument type}}
-}
-
-kernel void vec_double_ops() {
-  double4 f4 = (double4)(0, 0, 0, 0);
-  long4 f4laf = f4 && 0.0; // expected-error {{invalid operands}}
-  long4 f4lof = f4 || 0.0; // expected-error {{invalid operands}}
-  double4 f4baf = f4 & 0.0; // expected-error {{invalid operands}}
-  double4 f4bof = f4 | 0.0; // expected-error {{invalid operands}}
-  double4 f4bxf = f4 ^ 0.0; // expected-error {{invalid operands}}
-  double bnf4 = ~f4; // expected-error {{invalid argument type}}
-  long4 lnf4 = !f4; // expected-error {{invalid argument type}}
-}
diff --git a/test/SemaOpenCL/invalid-logical-ops-1.2.cl b/test/SemaOpenCL/invalid-logical-ops-1.2.cl
deleted file mode 100644
index bee5239..0000000
--- a/test/SemaOpenCL/invalid-logical-ops-1.2.cl
+++ /dev/null
@@ -1,58 +0,0 @@
-// RUN: %clang_cc1 %s -verify -cl-std=CL1.2 -triple x86_64-unknown-linux-gnu
-
-#pragma OPENCL EXTENSION cl_khr_fp64 : enable
-
-typedef __attribute__((ext_vector_type(4))) float float4;
-typedef __attribute__((ext_vector_type(4))) double double4;
-typedef __attribute__((ext_vector_type(4))) int int4;
-typedef __attribute__((ext_vector_type(4))) long long4;
-
-kernel void float_ops() {
-  int flaf = 0.0f && 0.0f;
-  int flof = 0.0f || 0.0f;
-  float fbaf = 0.0f & 0.0f; // expected-error {{invalid operands}}
-  float fbof = 0.0f | 0.0f; // expected-error {{invalid operands}}
-  float fbxf = 0.0f ^ 0.0f; // expected-error {{invalid operands}}
-  int flai = 0.0f && 0;
-  int floi = 0.0f || 0;
-  float ibaf = 0 & 0.0f; // expected-error {{invalid operands}}
-  float ibof = 0 | 0.0f; // expected-error {{invalid operands}}
-  float bnf = ~0.0f;// expected-error {{invalid argument type}}
-  float lnf = !0.0f;
-}
-
-kernel void vec_float_ops() {
-  float4 f4 = (float4)(0, 0, 0, 0);
-  int4 f4laf = f4 && 0.0f;
-  int4 f4lof = f4 || 0.0f;
-  float4 f4baf = f4 & 0.0f; // expected-error {{invalid operands}}
-  float4 f4bof = f4 | 0.0f; // expected-error {{invalid operands}}
-  float4 f4bxf = f4 ^ 0.0f; // expected-error {{invalid operands}}
-  float bnf4 = ~f4; // expected-error {{invalid argument type}}
-  int4 lnf4 = !f4;
-}
-
-kernel void double_ops() {
-  int flaf = 0.0 && 0.0;
-  int flof = 0.0 || 0.0;
-  double fbaf = 0.0 & 0.0; // expected-error {{invalid operands}}
-  double fbof = 0.0 | 0.0; // expected-error {{invalid operands}}
-  double fbxf = 0.0 ^ 0.0; // expected-error {{invalid operands}}
-  int flai = 0.0 && 0;
-  int floi = 0.0 || 0;
-  double ibaf = 0 & 0.0; // expected-error {{invalid operands}}
-  double ibof = 0 | 0.0; // expected-error {{invalid operands}}
-  double bnf = ~0.0; // expected-error {{invalid argument type}}
-  double lnf = !0.0;
-}
-
-kernel void vec_double_ops() {
-  double4 f4 = (double4)(0, 0, 0, 0);
-  long4 f4laf = f4 && 0.0;
-  long4 f4lof = f4 || 0.0;
-  double4 f4baf = f4 & 0.0; // expected-error {{invalid operands}}
-  double4 f4bof = f4 | 0.0; // expected-error {{invalid operands}}
-  double4 f4bxf = f4 ^ 0.0; // expected-error {{invalid operands}}
-  double bnf4 = ~f4; // expected-error {{invalid argument type}}
-  long4 lnf4 = !f4;
-}
diff --git a/test/SemaOpenCL/logical-ops.cl b/test/SemaOpenCL/logical-ops.cl
new file mode 100644
index 0000000..42501b1
--- /dev/null
+++ b/test/SemaOpenCL/logical-ops.cl
@@ -0,0 +1,117 @@
+// RUN: %clang_cc1 %s -verify -cl-std=CL1.1 -triple x86_64-unknown-linux-gnu
+// RUN: %clang_cc1 %s -verify -cl-std=CL1.2 -triple x86_64-unknown-linux-gnu
+// RUN: %clang_cc1 %s -verify -cl-std=CL2.0 -triple x86_64-unknown-linux-gnu
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+typedef __attribute__((ext_vector_type(4))) float float4;
+typedef __attribute__((ext_vector_type(4))) double double4;
+typedef __attribute__((ext_vector_type(4))) int int4;
+typedef __attribute__((ext_vector_type(4))) long long4;
+
+kernel void float_ops() {
+  int flaf = 0.0f && 0.0f;
+#if __OPENCL_C_VERSION__ < 120
+// expected-error@-2{{invalid operands}}
+#endif
+  int flof = 0.0f || 0.0f;
+#if __OPENCL_C_VERSION__ < 120
+// expected-error@-2{{invalid operands}}
+#endif
+  float fbaf = 0.0f & 0.0f; // expected-error {{invalid operands}}
+  float fbof = 0.0f | 0.0f; // expected-error {{invalid operands}}
+  float fbxf = 0.0f ^ 0.0f; // expected-error {{invalid operands}}
+  int flai = 0.0f && 0;
+#if __OPENCL_C_VERSION__ < 120
+// expected-error@-2{{invalid operands}}
+#endif
+  int floi = 0.0f || 0;
+#if __OPENCL_C_VERSION__ < 120
+// expected-error@-2{{invalid operands}}
+#endif
+  float ibaf = 0 & 0.0f; // expected-error {{invalid operands}}
+  float ibof = 0 | 0.0f; // expected-error {{invalid operands}}
+  float bnf = ~0.0f;// expected-error {{invalid argument type}}
+  float lnf = !0.0f;
+#if __OPENCL_C_VERSION__ < 120
+// expected-error@-2{{invalid argument type}}
+#endif
+}
+
+kernel void vec_float_ops() {
+  float4 f4 = (float4)(0, 0, 0, 0);
+  int4 f4laf = f4 && 0.0f;
+#if __OPENCL_C_VERSION__ < 120
+// expected-error@-2{{invalid operands}}
+#endif
+  int4 f4lof = f4 || 0.0f;
+#if __OPENCL_C_VERSION__ < 120
+// expected-error@-2{{invalid operands}}
+#endif
+  float4 f4baf = f4 & 0.0f; // expected-error {{invalid operands}}
+  float4 f4bof = f4 | 0.0f; // expected-error {{invalid operands}}
+  float4 f4bxf = f4 ^ 0.0f; // expected-error {{invalid operands}}
+  float bnf4 = ~f4; // expected-error {{invalid argument type}}
+  int4 lnf4 = !f4;
+#if __OPENCL_C_VERSION__ < 120
+// expected-error@-2{{invalid argument type}}
+#endif
+}
+
+kernel void double_ops() {
+  int flaf = 0.0 && 0.0;
+#if __OPENCL_C_VERSION__ < 120
+// expected-error@-2{{invalid operands}}
+#endif
+  int flof = 0.0 || 0.0;
+#if __OPENCL_C_VERSION__ < 120
+// expected-error@-2{{invalid operands}}
+#endif
+  double fbaf = 0.0 & 0.0; // expected-error {{invalid operands}}
+  double fbof = 0.0 | 0.0; // expected-error {{invalid operands}}
+  double fbxf = 0.0 ^ 0.0; // expected-error {{invalid operands}}
+  int flai = 0.0 && 0;
+#if __OPENCL_C_VERSION__ < 120
+// expected-error@-2{{invalid operands}}
+#endif
+  int floi = 0.0 || 0;
+#if __OPENCL_C_VERSION__ < 120
+// expected-error@-2{{invalid operands}}
+#endif
+  double ibaf = 0 & 0.0; // expected-error {{invalid operands}}
+  double ibof = 0 | 0.0; // expected-error {{invalid operands}}
+  double bnf = ~0.0; // expected-error {{invalid argument type}}
+  double lnf = !0.0;
+#if __OPENCL_C_VERSION__ < 120
+// expected-error@-2{{invalid argument type}}
+#endif
+}
+
+kernel void vec_double_ops() {
+  double4 f4 = (double4)(0, 0, 0, 0);
+  long4 f4laf = f4 && 0.0;
+#if __OPENCL_C_VERSION__ < 120
+// expected-error@-2{{invalid operands}}
+#endif
+  long4 f4lof = f4 || 0.0;
+#if __OPENCL_C_VERSION__ < 120
+// expected-error@-2{{invalid operands}}
+#endif
+  double4 f4baf = f4 & 0.0; // expected-error {{invalid operands}}
+  double4 f4bof = f4 | 0.0; // expected-error {{invalid operands}}
+  double4 f4bxf = f4 ^ 0.0; // expected-error {{invalid operands}}
+  double bnf4 = ~f4; // expected-error {{invalid argument type}}
+  long4 lnf4 = !f4;
+#if __OPENCL_C_VERSION__ < 120
+// expected-error@-2{{invalid argument type}}
+#endif
+}
+
+kernel void pointer_ops(){
+  global int* p;
+  bool b = !p;
+  b = p==0;
+  int i;
+  b = !&i;
+  b = &i==(int *)1;
+}