Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td	(revision 175159)
+++ include/clang/Basic/DiagnosticSemaKinds.td	(working copy)
@@ -6130,8 +6130,8 @@
   "the event_t type cannot be used to declare a kernel function argument">;
 def err_event_t_global_var : Error<
   "the event_t type cannot be used to declare a program scope variable">;
-def err_event_t_struct_field : Error<
-  "the event_t type cannot be used to declare a structure or union field">;
+def err_opencl_invalid_field_type : Error<"cannot declare a "
+  "%select{structure|union}1 field of type %0">;
 def err_event_t_addr_space_qual : Error<
   "the event_t type can only be used with __private address space qualifier">;
 def err_expected_kernel_void_return_type : Error<
@@ -6139,7 +6139,14 @@
 def err_sampler_argument_required : Error<
   "sampler_t variable required - got %0">;
 def err_wrong_sampler_addressspace: Error<
-  "sampler type cannot be used with the __local and __global address space qualifiers">;
+  "sampler type cannot be used with the __local and __global address space "
+  "qualifiers">;
+def err_image_variable : Error<"cannot declare a variable of image type %0">;
+def err_opencl_invalid_array_type : Error<"cannot form an array of type %0">;
+def err_opencl_invalid_pointer_type : Error<"cannot declare a pointer to "
+  "type %0">;
+def err_opencl_invalid_return_type : Error<"type %0 cannot be used as the "
+  "return type of a function">;
 
 } // end of sema category
 
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp	(revision 175159)
+++ lib/Sema/SemaDecl.cpp	(working copy)
@@ -4499,13 +4499,17 @@
       SCAsWritten = SC_OpenCLWorkGroupLocal;
     }
 
+    // OpenCL v1.2 s6.9.b p2:
+    //   An image type cannot be used to declare a variable.
+    if (R->isImageType())
+      Diag(D.getIdentifierLoc(), diag::err_image_variable) << R;
+
     // OpenCL v1.2 s6.9.b p4:
-    // The sampler type cannot be used with the __local and __global address
-    // space qualifiers.
+    //   The sampler type cannot be used with the __local and __global address
+    //   space qualifiers.
     if (R->isSamplerT() && (R.getAddressSpace() == LangAS::opencl_local ||
-      R.getAddressSpace() == LangAS::opencl_global)) {
+      R.getAddressSpace() == LangAS::opencl_global))
       Diag(D.getIdentifierLoc(), diag::err_wrong_sampler_addressspace);
-    }
 
     // OpenCL 1.2 spec, p6.9 r:
     // The event type cannot be used to declare a program scope variable.
@@ -6303,6 +6307,14 @@
     }
   }
 
+  // OpenCL v1.2 s6.9.b p2/p4:
+  //   An image/sampler type cannot be used to declare [...]
+  //   the return type of a function.
+  if (LangOpts.OpenCL && (NewFD->getResultType()->isImageType() ||
+      NewFD->getResultType()->isSamplerT()))
+    Diag(D.getIdentifierLoc(), diag::err_opencl_invalid_return_type)
+      << NewFD->getResultType();
+
   MarkUnusedFileScopedDecl(NewFD);
 
   if (getLangOpts().CUDA)
@@ -9989,14 +10001,14 @@
     }
   }
 
-  // OpenCL 1.2 spec, s6.9 r:
-  // The event type cannot be used to declare a structure or union field.
-  if (LangOpts.OpenCL && T->isEventT()) {
-    Diag(Loc, diag::err_event_t_struct_field);
-    D.setInvalidType();
-  }
+  // OpenCL v1.2 s6.9.b p2/p4 and s6.9.r:
+  //   An image/sampler/event type cannot be used to declare a structure or
+  //   union field.
+  if (LangOpts.OpenCL && (T->isImageType() || T->isSamplerT() ||
+      T->isEventT()))
+    Diag(Loc, diag::err_opencl_invalid_field_type)
+      << T << (Record->isStruct() ? 0 : 1);
 
-
   DiagnoseFunctionSpecifiers(D);
 
   if (D.getDeclSpec().isThreadSpecified())
Index: lib/Sema/SemaType.cpp
===================================================================
--- lib/Sema/SemaType.cpp	(revision 175159)
+++ lib/Sema/SemaType.cpp	(working copy)
@@ -1211,6 +1211,14 @@
     return QualType();
   }
 
+  // OpenCL v1.2 s6.9.b p2/p4:
+  //   An image/sampler type cannot be used to declare [...]
+  //   a pointer to an image/sampler.
+  if (LangOpts.OpenCL && (T->isImageType() || T->isSamplerT())) {
+    Diag(Loc, diag::err_opencl_invalid_pointer_type) << T;
+    return QualType();
+  }
+
   assert(!T->isObjCObjectType() && "Should build ObjCObjectPointerType");
 
   // In ARC, it is forbidden to build pointers to unqualified pointers.
@@ -1369,6 +1377,14 @@
     return QualType();
   }
 
+  // OpenCL v1.2 s6.9.b p2/p4:
+  //   An image/sampler type cannot be used to declare [...]
+  //   an array of images/samplers.
+  if (LangOpts.OpenCL && (T->isImageType() || T->isSamplerT())) {
+    Diag(Loc, diag::err_opencl_invalid_array_type) << T;
+    return QualType();
+  }
+
   if (const RecordType *EltTy = T->getAs<RecordType>()) {
     // If the element type is a struct or union that contains a variadic
     // array, accept it as a GNU extension: C99 6.7.2.1p2.
Index: test/SemaOpenCL/event_t.cl
===================================================================
--- test/SemaOpenCL/event_t.cl	(revision 175159)
+++ test/SemaOpenCL/event_t.cl	(working copy)
@@ -3,9 +3,13 @@
 event_t glb_evt; // expected-error {{the event_t type cannot be used to declare a program scope variable}}
 
 struct evt_s {
-  event_t evt;  // expected-error {{the event_t type cannot be used to declare a structure or union field}}
+  event_t evt;  // expected-error {{cannot declare a structure field of type 'event_t'}}
 } evt_str;
 
+union evt_u {
+  event_t evt;  // expected-error {{cannot declare a union field of type 'event_t'}}
+} evt_uni;
+
 void foo(event_t evt); // expected-note {{passing argument to parameter 'evt' here}}
 
 void kernel ker(event_t argevt) { // expected-error {{the event_t type cannot be used to declare a kernel function argument}}
Index: test/SemaOpenCL/images.cl
===================================================================
--- test/SemaOpenCL/images.cl	(revision 0)
+++ test/SemaOpenCL/images.cl	(revision 0)
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+
+constant image1d_t glb_img; // expected-error {{cannot declare a variable of image type '__constant image1d_t}}
+
+struct {
+  image1d_array_t img1; // expected-error {{cannot declare a structure field of type 'image1d_array_t'}}
+  image2d_array_t img2; // expected-error {{cannot declare a structure field of type 'image2d_array_t'}}
+} img_s;
+
+union {
+  image1d_array_t img1; // expected-error {{cannot declare a union field of type 'image1d_array_t'}}
+  image2d_array_t img2; // expected-error {{cannot declare a union field of type 'image2d_array_t'}}
+} img_u;
+
+constant image2d_t glb_img_arr[10]; // expected-error {{cannot form an array of type '__constant image2d_t'}}
+
+constant image3d_t *glb_img_ptr; // expected-error {{cannot declare a pointer to type '__constant image3d_t'}}
+
+image1d_buffer_t foo(image2d_t img); // expected-error {{type 'image1d_buffer_t' cannot be used as the return type of a function}}
+
+void kernel ker(image3d_t img) {
+  image1d_t img_var; // expected-error {{cannot declare a variable of image type 'image1d_t'}}
+  image2d_t img_arr[10]; // expected-error {{cannot form an array of type 'image2d_t'}}
+  image3d_t *img_ptr; // expected-error {{cannot declare a pointer to type 'image3d_t'}}
+}
Index: test/SemaOpenCL/sampler_t.cl
===================================================================
--- test/SemaOpenCL/sampler_t.cl	(revision 175159)
+++ test/SemaOpenCL/sampler_t.cl	(working copy)
@@ -2,11 +2,29 @@
 
 constant sampler_t glb_smp = 5;
 
+struct {
+  sampler_t smp1; // expected-error {{cannot declare a structure field of type 'sampler_t'}}
+  sampler_t smp2; // expected-error {{cannot declare a structure field of type 'sampler_t'}}
+} smp_s;
+
+union {
+  sampler_t smp1; // expected-error {{cannot declare a union field of type 'sampler_t'}}
+  int i;
+} smp_u;
+
+constant sampler_t glb_smp_arr[10]; // expected-error {{cannot form an array of type '__constant sampler_t}}
+
+constant sampler_t *glb_smp_ptr; // expected-error {{cannot declare a pointer to type '__constant sampler_t'}}
+
 void foo(sampler_t); 
 
+sampler_t foo2(void); // expected-error {{type 'sampler_t' cannot be used as the return type of a function}}
+
 void kernel ker(sampler_t argsmp) {
   local sampler_t smp; // expected-error {{sampler type cannot be used with the __local and __global address space qualifiers}}
   const sampler_t const_smp = 7;
+  sampler_t smp_arr[10]; // expected-error {{cannot form an array of type 'sampler_t'}}
+  sampler_t *smp_ptr; // expected-error {{cannot declare a pointer to type 'sampler_t'}}
   foo(glb_smp);
   foo(const_smp);
   foo(5); // expected-error {{sampler_t variable required - got 'int'}}
