Index: test/SemaOpenCL/address-spaces.cl
===================================================================
--- test/SemaOpenCL/address-spaces.cl	(revision 158365)
+++ test/SemaOpenCL/address-spaces.cl	(working copy)
@@ -2,6 +2,11 @@
 
 __constant int ci = 1;
 
+struct my_struct {
+__local int a;
+__global int b; // expected-error {{elements of a struct or union must belong to the same address space}}
+};
+
 __kernel void foo(__global int *gip) {
   __local int li;
   __local int lj = 2; // expected-error {{'__local' variable cannot have an initializer}}
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td	(revision 158365)
+++ include/clang/Basic/DiagnosticSemaKinds.td	(working copy)
@@ -5587,6 +5587,8 @@
 // OpenCL warnings and errors.
 def err_invalid_astype_of_different_size : Error<
   "invalid reinterpretation: sizes of %0 and %1 must match">;
+def err_different_address_spaces_in_struct : Error<
+  "elements of a struct or union must belong to the same address space">;
 
 } // end of sema category
 
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp	(revision 158365)
+++ lib/Sema/SemaDecl.cpp	(working copy)
@@ -9814,6 +9814,24 @@
       ++NumNamedMembers;
   }
 
+  // Elements of a struct or union must belong to the same address
+  // space (OpenCL: (Sec 6.9.o). Declaring a struct or union whose
+  // elements are in different address spaces is illegal.
+  unsigned AddressSpace;
+  for (llvm::ArrayRef<Decl *>::iterator first = Fields.begin(),
+         i = first,
+         end = Fields.end();
+       i != end; ++i) {
+    FieldDecl *FD = cast<FieldDecl>(*i);
+    const QualType FieldTy = FD->getType();
+    if (i == first)
+      AddressSpace = FieldTy.getAddressSpace();
+    else if (FieldTy.getAddressSpace() != AddressSpace) {
+      Diag(FD->getLocation(), diag::err_different_address_spaces_in_struct);
+      break;
+    }
+  }
+
   // Okay, we successfully defined 'Record'.
   if (Record) {
     bool Completed = false;
