Index: include/clang/AST/ASTContext.h
===================================================================
--- include/clang/AST/ASTContext.h	(revision 170542)
+++ include/clang/AST/ASTContext.h	(working copy)
@@ -719,6 +719,7 @@
   CanQualType OCLImage1dTy, OCLImage1dArrayTy, OCLImage1dBufferTy;
   CanQualType OCLImage2dTy, OCLImage2dArrayTy;
   CanQualType OCLImage3dTy;
+  CanQualType OCLEventTy;
 
   // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand.
   mutable QualType AutoDeductTy;     // Deduction against 'auto'.
Index: include/clang/AST/BuiltinTypes.def
===================================================================
--- include/clang/AST/BuiltinTypes.def	(revision 170542)
+++ include/clang/AST/BuiltinTypes.def	(working copy)
@@ -162,6 +162,9 @@
 BUILTIN_TYPE(OCLImage2dArray, OCLImage2dArrayTy)
 BUILTIN_TYPE(OCLImage3d, OCLImage3dTy)
 
+// OpenCL event_t.
+BUILTIN_TYPE(OCLEvent, OCLEventTy)
+
 // This represents the type of an expression whose type is
 // totally unknown, e.g. 'T::foo'.  It is permitted for this to
 // appear in situations where the structure of the type is
Index: include/clang/AST/OperationKinds.h
===================================================================
--- include/clang/AST/OperationKinds.h	(revision 170542)
+++ include/clang/AST/OperationKinds.h	(working copy)
@@ -292,7 +292,10 @@
 
   // Convert a builtin function to a function pointer; only allowed in the
   // callee of a call expression.
-  CK_BuiltinFnToFnPtr
+  CK_BuiltinFnToFnPtr,
+
+  // Convert a NULL value for OpenCL event_t initialization
+  CK_NullToOCLEvent
 };
 
 static const CastKind CK_Invalid = static_cast<CastKind>(-1);
Index: include/clang/AST/Type.h
===================================================================
--- include/clang/AST/Type.h	(revision 170542)
+++ include/clang/AST/Type.h	(working copy)
@@ -1589,6 +1589,8 @@
 
   bool isImageType() const;                     // Any OpenCL image type
 
+  bool isEventT() const;                        // OpenCL event_t
+
   bool isOpenCLSpecificType() const;            // Any OpenCL specific type
 
   /// Determines if this type, which must satisfy
@@ -4918,6 +4920,10 @@
 inline bool Type::isImage3dT() const {
   return isSpecificBuiltinType(BuiltinType::OCLImage3d);
 }
+inline bool Type::isEventT() const {
+  return isSpecificBuiltinType(BuiltinType::OCLEvent);
+}
+
 inline bool Type::isImageType() const {
   return isImage3dT() ||
          isImage2dT() || isImage2dArrayT() ||
@@ -4925,7 +4931,7 @@
 }
 
 inline bool Type::isOpenCLSpecificType() const {
-  return isImageType();
+  return isImageType() || isEventT();
 }
 
 inline bool Type::isTemplateTypeParmType() const {
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td	(revision 170542)
+++ include/clang/Basic/DiagnosticSemaKinds.td	(working copy)
@@ -6025,6 +6025,11 @@
   "kernel functions cannot be declared static">;
 def err_static_function_scope : Error<
   "variables in function scope cannot be declared static">;
+def err_event_initialization : Error<
+  "initialization of event_t variables is not allowed">;
+def err_event_argument_not_null : Error<
+  "passing %0 as event_t function argument is not allowed; use an event_t "
+  "variable or NULL">;
 
 } // end of sema category
 
Index: include/clang/Basic/Specifiers.h
===================================================================
--- include/clang/Basic/Specifiers.h	(revision 170542)
+++ include/clang/Basic/Specifiers.h	(working copy)
@@ -68,6 +68,7 @@
     TST_image2d_t,        // OpenCL image2d_t
     TST_image2d_array_t,  // OpenCL image2d_array_t
     TST_image3d_t,        // OpenCL image3d_t
+    TST_event_t,          // OpenCL event_t
     TST_error         // erroneous type
   };
   
Index: include/clang/Basic/TokenKinds.def
===================================================================
--- include/clang/Basic/TokenKinds.def	(revision 170542)
+++ include/clang/Basic/TokenKinds.def	(working copy)
@@ -454,6 +454,7 @@
 KEYWORD(image2d_t                   , KEYOPENCL)
 KEYWORD(image2d_array_t             , KEYOPENCL)
 KEYWORD(image3d_t                   , KEYOPENCL)
+KEYWORD(event_t                     , KEYOPENCL)
 
 // Borland Extensions.
 KEYWORD(__pascal                    , KEYALL)
Index: include/clang/Sema/DeclSpec.h
===================================================================
--- include/clang/Sema/DeclSpec.h	(revision 170542)
+++ include/clang/Sema/DeclSpec.h	(working copy)
@@ -282,6 +282,7 @@
   static const TST TST_image2d_t = clang::TST_image2d_t;
   static const TST TST_image2d_array_t = clang::TST_image2d_array_t;
   static const TST TST_image3d_t = clang::TST_image3d_t;
+  static const TST TST_event_t = clang::TST_event_t;
   static const TST TST_error = clang::TST_error;
 
   // type-qualifiers
Index: include/clang/Sema/Initialization.h
===================================================================
--- include/clang/Sema/Initialization.h	(revision 170542)
+++ include/clang/Sema/Initialization.h	(working copy)
@@ -624,7 +624,9 @@
     /// \brief Produce an Objective-C object pointer.
     SK_ProduceObjCObject,
     /// \brief Construct a std::initializer_list from an initializer list.
-    SK_StdInitializerList
+    SK_StdInitializerList,
+    /// \brief Passing NULL to a function where OpenCL event_t is expected.
+    SK_OCLNULLEvent
   };
   
   /// \brief A single step in the initialization sequence.
@@ -953,6 +955,10 @@
   /// initializer list.
   void AddStdInitializerListConstructionStep(QualType T);
 
+  /// \brief Add a step to initialize an OpenCL event_t from a NULL
+  /// constant.
+  void AddOCLNullEventStep(QualType T);
+
   /// \brief Add steps to unwrap a initializer list for a reference around a
   /// single element and rewrap it at the end.
   void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic);
Index: include/clang/Serialization/ASTBitCodes.h
===================================================================
--- include/clang/Serialization/ASTBitCodes.h	(revision 170542)
+++ include/clang/Serialization/ASTBitCodes.h	(working copy)
@@ -713,7 +713,8 @@
       /// \brief OpenCL 2d image array type.
       PREDEF_TYPE_IMAGE2D_ARR_ID = 42,
       /// \brief OpenCL 3d image type.
-      PREDEF_TYPE_IMAGE3D_ID    = 43
+      PREDEF_TYPE_IMAGE3D_ID    = 43,
+      PREDEF_TYPE_EVENT_ID      = 45
     };
 
     /// \brief The number of predefined type IDs that are reserved for
Index: lib/AST/ASTContext.cpp
===================================================================
--- lib/AST/ASTContext.cpp	(revision 170542)
+++ lib/AST/ASTContext.cpp	(working copy)
@@ -882,6 +882,8 @@
     InitBuiltinType(OCLImage2dTy, BuiltinType::OCLImage2d);
     InitBuiltinType(OCLImage2dArrayTy, BuiltinType::OCLImage2dArray);
     InitBuiltinType(OCLImage3dTy, BuiltinType::OCLImage3d);
+
+    InitBuiltinType(OCLEventTy, BuiltinType::OCLEvent);
   }
   
   // Builtin type for __objc_yes and __objc_no
@@ -1421,6 +1423,7 @@
       Width = Target->getPointerWidth(0); 
       Align = Target->getPointerAlign(0);
       break;
+    case BuiltinType::OCLEvent:
     case BuiltinType::OCLImage1d:
     case BuiltinType::OCLImage1dArray:
     case BuiltinType::OCLImage1dBuffer:
Index: lib/AST/Expr.cpp
===================================================================
--- lib/AST/Expr.cpp	(revision 170542)
+++ lib/AST/Expr.cpp	(working copy)
@@ -1417,6 +1417,7 @@
   case CK_ARCConsumeObject:
   case CK_ARCReclaimReturnedObject:
   case CK_ARCExtendBlockObject:
+  case CK_NullToOCLEvent:
     assert(!getType()->isBooleanType() && "unheralded conversion to bool");
     goto CheckNoBasePath;
 
@@ -1548,6 +1549,8 @@
     return "CopyAndAutoreleaseBlockObject";
   case CK_BuiltinFnToFnPtr:
     return "BuiltinFnToFnPtr";
+  case CK_NullToOCLEvent:
+    return "NullToOCLEvent";
   }
 
   llvm_unreachable("Unhandled cast kind!");
Index: lib/AST/ExprConstant.cpp
===================================================================
--- lib/AST/ExprConstant.cpp	(revision 170542)
+++ lib/AST/ExprConstant.cpp	(working copy)
@@ -5363,6 +5363,7 @@
   case CK_IntegralComplexCast:
   case CK_IntegralComplexToFloatingComplex:
   case CK_BuiltinFnToFnPtr:
+  case CK_NullToOCLEvent:
     llvm_unreachable("invalid cast kind for integral value");
 
   case CK_BitCast:
@@ -5850,6 +5851,7 @@
   case CK_ARCExtendBlockObject:
   case CK_CopyAndAutoreleaseBlockObject:
   case CK_BuiltinFnToFnPtr:
+  case CK_NullToOCLEvent:
     llvm_unreachable("invalid cast kind for complex value");
 
   case CK_LValueToRValue:
Index: lib/AST/ItaniumMangle.cpp
===================================================================
--- lib/AST/ItaniumMangle.cpp	(revision 170542)
+++ lib/AST/ItaniumMangle.cpp	(working copy)
@@ -1886,6 +1886,7 @@
   case BuiltinType::OCLImage2d: Out << "11ocl_image2d"; break;
   case BuiltinType::OCLImage2dArray: Out << "16ocl_image2darray"; break;
   case BuiltinType::OCLImage3d: Out << "11ocl_image3d"; break;
+  case BuiltinType::OCLEvent: Out << "9ocl_event"; break;
   }
 }
 
Index: lib/AST/MicrosoftMangle.cpp
===================================================================
--- lib/AST/MicrosoftMangle.cpp	(revision 170542)
+++ lib/AST/MicrosoftMangle.cpp	(working copy)
@@ -1060,6 +1060,7 @@
   case BuiltinType::OCLImage2d: Out << "PAUocl_image2d@@"; break;
   case BuiltinType::OCLImage2dArray: Out << "PAUocl_image2darray@@"; break;
   case BuiltinType::OCLImage3d: Out << "PAUocl_image3d@@"; break;
+  case BuiltinType::OCLEvent: Out << "PAUocl_event@@"; break;
  
   case BuiltinType::NullPtr: Out << "$$T"; break;
 
Index: lib/AST/NSAPI.cpp
===================================================================
--- lib/AST/NSAPI.cpp	(revision 170542)
+++ lib/AST/NSAPI.cpp	(working copy)
@@ -343,6 +343,7 @@
   case BuiltinType::OCLImage2d:
   case BuiltinType::OCLImage2dArray:
   case BuiltinType::OCLImage3d:
+  case BuiltinType::OCLEvent:
   case BuiltinType::BoundMember:
   case BuiltinType::Dependent:
   case BuiltinType::Overload:
Index: lib/AST/Type.cpp
===================================================================
--- lib/AST/Type.cpp	(revision 170542)
+++ lib/AST/Type.cpp	(working copy)
@@ -1518,6 +1518,7 @@
   case OCLImage2d:        return "image2d_t";
   case OCLImage2dArray:   return "image2d_array_t";
   case OCLImage3d:        return "image3d_t";
+  case OCLEvent:          return "event_t";
   }
   
   llvm_unreachable("Invalid builtin type.");
Index: lib/AST/TypeLoc.cpp
===================================================================
--- lib/AST/TypeLoc.cpp	(revision 170542)
+++ lib/AST/TypeLoc.cpp	(working copy)
@@ -268,6 +268,7 @@
   case BuiltinType::OCLImage2d:
   case BuiltinType::OCLImage2dArray:
   case BuiltinType::OCLImage3d:
+  case BuiltinType::OCLEvent:
   case BuiltinType::BuiltinFn:
     return TST_unspecified;
   }
Index: lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- lib/CodeGen/CGDebugInfo.cpp	(revision 170542)
+++ lib/CodeGen/CGDebugInfo.cpp	(working copy)
@@ -426,6 +426,9 @@
   case BuiltinType::OCLImage3d:
     return getOrCreateStructPtrType("opencl_image3d_t",
                                     OCLImage3dDITy);
+  case BuiltinType::OCLEvent:
+    return getOrCreateStructPtrType("opencl_event_t",
+                                    OCLEventDITy);
 
   case BuiltinType::UChar:
   case BuiltinType::Char_U: Encoding = llvm::dwarf::DW_ATE_unsigned_char; break;
Index: lib/CodeGen/CGDebugInfo.h
===================================================================
--- lib/CodeGen/CGDebugInfo.h	(revision 170542)
+++ lib/CodeGen/CGDebugInfo.h	(working copy)
@@ -55,6 +55,7 @@
   llvm::DIType OCLImage1dDITy, OCLImage1dArrayDITy, OCLImage1dBufferDITy;
   llvm::DIType OCLImage2dDITy, OCLImage2dArrayDITy;
   llvm::DIType OCLImage3dDITy;
+  llvm::DIType OCLEventDITy;
   
   /// TypeCache - Cache of previously constructed Types.
   llvm::DenseMap<void *, llvm::WeakVH> TypeCache;
Index: lib/CodeGen/CGExpr.cpp
===================================================================
--- lib/CodeGen/CGExpr.cpp	(revision 170542)
+++ lib/CodeGen/CGExpr.cpp	(working copy)
@@ -2641,6 +2641,8 @@
                                            ConvertType(ToType));
     return MakeAddrLValue(V, E->getType());
   }
+  case CK_NullToOCLEvent:
+    llvm_unreachable("NULL to OpenCL event lvalue cast is not valid");
   }
   
   llvm_unreachable("Unhandled lvalue cast kind?");
Index: lib/CodeGen/CGExprAgg.cpp
===================================================================
--- lib/CodeGen/CGExprAgg.cpp	(revision 170542)
+++ lib/CodeGen/CGExprAgg.cpp	(working copy)
@@ -648,6 +648,7 @@
   case CK_ARCExtendBlockObject:
   case CK_CopyAndAutoreleaseBlockObject:
   case CK_BuiltinFnToFnPtr:
+  case CK_NullToOCLEvent:
     llvm_unreachable("cast kind invalid for aggregate types");
   }
 }
Index: lib/CodeGen/CGExprComplex.cpp
===================================================================
--- lib/CodeGen/CGExprComplex.cpp	(revision 170542)
+++ lib/CodeGen/CGExprComplex.cpp	(working copy)
@@ -428,6 +428,7 @@
   case CK_ARCExtendBlockObject:
   case CK_CopyAndAutoreleaseBlockObject:
   case CK_BuiltinFnToFnPtr:
+  case CK_NullToOCLEvent:
     llvm_unreachable("invalid cast kind for complex value");
 
   case CK_FloatingRealToComplex:
Index: lib/CodeGen/CGExprConstant.cpp
===================================================================
--- lib/CodeGen/CGExprConstant.cpp	(revision 170542)
+++ lib/CodeGen/CGExprConstant.cpp	(working copy)
@@ -747,6 +747,7 @@
     case CK_FloatingToIntegral:
     case CK_FloatingToBoolean:
     case CK_FloatingCast:
+    case CK_NullToOCLEvent:
       return 0;
     }
     llvm_unreachable("Invalid CastKind");
Index: lib/CodeGen/CGExprScalar.cpp
===================================================================
--- lib/CodeGen/CGExprScalar.cpp	(revision 170542)
+++ lib/CodeGen/CGExprScalar.cpp	(working copy)
@@ -1400,8 +1400,13 @@
     return EmitComplexToScalarConversion(V, E->getType(), DestTy);
   }
 
+  case CK_NullToOCLEvent: {
+    assert(DestTy->isEventT() && "CK_NullToOCLEvent cast on non event type");
+    return llvm::Constant::getNullValue(ConvertType(DestTy));
   }
 
+  }
+
   llvm_unreachable("unknown scalar cast");
 }
 
Index: lib/CodeGen/CGOpenCLRuntime.cpp
===================================================================
--- lib/CodeGen/CGOpenCLRuntime.cpp	(revision 170542)
+++ lib/CodeGen/CGOpenCLRuntime.cpp	(working copy)
@@ -55,5 +55,8 @@
   case BuiltinType::OCLImage3d:
     return llvm::PointerType::get(llvm::StructType::create(
                            CGM.getLLVMContext(), "opencl.image3d_t"), 0);
+  case BuiltinType::OCLEvent:
+    return llvm::PointerType::get(llvm::StructType::create(
+                           CGM.getLLVMContext(), "opencl.event_t"), 0);
   }
 }
Index: lib/CodeGen/CGRTTI.cpp
===================================================================
--- lib/CodeGen/CGRTTI.cpp	(revision 170542)
+++ lib/CodeGen/CGRTTI.cpp	(working copy)
@@ -197,6 +197,7 @@
     case BuiltinType::OCLImage2d:
     case BuiltinType::OCLImage2dArray:
     case BuiltinType::OCLImage3d:
+    case BuiltinType::OCLEvent:
       return true;
       
     case BuiltinType::Dependent:
Index: lib/CodeGen/CodeGenTypes.cpp
===================================================================
--- lib/CodeGen/CodeGenTypes.cpp	(revision 170542)
+++ lib/CodeGen/CodeGenTypes.cpp	(working copy)
@@ -374,6 +374,7 @@
     case BuiltinType::OCLImage2d:
     case BuiltinType::OCLImage2dArray:
     case BuiltinType::OCLImage3d:
+    case BuiltinType::OCLEvent:
       ResultType = CGM.getOpenCLRuntime().convertOpenCLSpecificType(Ty);
       break;
     
Index: lib/Edit/RewriteObjCFoundationAPI.cpp
===================================================================
--- lib/Edit/RewriteObjCFoundationAPI.cpp	(revision 170542)
+++ lib/Edit/RewriteObjCFoundationAPI.cpp	(working copy)
@@ -921,6 +921,7 @@
     case CK_NonAtomicToAtomic:
     case CK_CopyAndAutoreleaseBlockObject:
     case CK_BuiltinFnToFnPtr:
+    case CK_NullToOCLEvent:
       return false;
     }
   }
Index: lib/Parse/ParseDecl.cpp
===================================================================
--- lib/Parse/ParseDecl.cpp	(revision 170542)
+++ lib/Parse/ParseDecl.cpp	(working copy)
@@ -2777,6 +2777,10 @@
       isInvalid = DS.SetTypeSpecType(DeclSpec::TST_image3d_t, Loc,
                                      PrevSpec, DiagID);
       break;
+    case tok::kw_event_t:
+      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_event_t, Loc,
+                                     PrevSpec, DiagID);
+      break;
     case tok::kw___unknown_anytype:
       isInvalid = DS.SetTypeSpecType(TST_unknown_anytype, Loc,
                                      PrevSpec, DiagID);
@@ -3627,6 +3631,7 @@
   case tok::kw_image2d_t:
   case tok::kw_image2d_array_t:
   case tok::kw_image3d_t:
+  case tok::kw_event_t:
 
     // struct-or-union-specifier (C99) or class-specifier (C++)
   case tok::kw_class:
@@ -3707,6 +3712,7 @@
   case tok::kw_image2d_t:
   case tok::kw_image2d_array_t:
   case tok::kw_image3d_t:
+  case tok::kw_event_t:
 
     // struct-or-union-specifier (C99) or class-specifier (C++)
   case tok::kw_class:
@@ -3859,6 +3865,7 @@
   case tok::kw_image2d_t:
   case tok::kw_image2d_array_t:
   case tok::kw_image3d_t:
+  case tok::kw_event_t:
 
     // struct-or-union-specifier (C99) or class-specifier (C++)
   case tok::kw_class:
Index: lib/Parse/ParseExpr.cpp
===================================================================
--- lib/Parse/ParseExpr.cpp	(revision 170542)
+++ lib/Parse/ParseExpr.cpp	(working copy)
@@ -1085,6 +1085,7 @@
   case tok::kw_image2d_t:
   case tok::kw_image2d_array_t:
   case tok::kw_image3d_t: {
+  case tok::kw_event_t:
     if (!getLangOpts().CPlusPlus) {
       Diag(Tok, diag::err_expected_expression);
       return ExprError();
Index: lib/Parse/ParseTentative.cpp
===================================================================
--- lib/Parse/ParseTentative.cpp	(revision 170542)
+++ lib/Parse/ParseTentative.cpp	(working copy)
@@ -843,6 +843,7 @@
   case tok::kw_image2d_t:
   case tok::kw_image2d_array_t:
   case tok::kw_image3d_t:
+  case tok::kw_event_t:
   case tok::kw___unknown_anytype:
     return TPResult::False();
 
Index: lib/Sema/DeclSpec.cpp
===================================================================
--- lib/Sema/DeclSpec.cpp	(revision 170542)
+++ lib/Sema/DeclSpec.cpp	(working copy)
@@ -286,6 +286,7 @@
     case TST_image2d_t:
     case TST_image2d_array_t:
     case TST_image3d_t:
+    case TST_event_t:
       return false;
 
     case TST_decltype:
@@ -426,6 +427,7 @@
   case DeclSpec::TST_image2d_t:   return "image2d_t";
   case DeclSpec::TST_image2d_array_t: return "image2d_array_t";
   case DeclSpec::TST_image3d_t:   return "image3d_t";
+  case DeclSpec::TST_event_t:     return "event_t";
   case DeclSpec::TST_error:       return "(error)";
   }
   llvm_unreachable("Unknown typespec!");
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp	(revision 170542)
+++ lib/Sema/SemaExpr.cpp	(working copy)
@@ -2466,10 +2466,22 @@
         valueKind = VK_RValue;
         break;
       }
+
+      // In OpenCL, event_t is not l-value.
+      if (getLangOpts().OpenCL && type->isEventT()) {
+        valueKind = VK_RValue;
+        break;
+      }
       // fallthrough
 
     case Decl::ImplicitParam:
     case Decl::ParmVar: {
+      // In OpenCL, event_t is not l-value.
+      if (getLangOpts().OpenCL && type->isEventT()) {
+        valueKind = VK_RValue;
+        break;
+      }
+
       // These are always l-values.
       valueKind = VK_LValue;
       type = type.getNonReferenceType();
Index: lib/Sema/SemaInit.cpp
===================================================================
--- lib/Sema/SemaInit.cpp	(revision 170542)
+++ lib/Sema/SemaInit.cpp	(working copy)
@@ -2424,6 +2424,7 @@
   case SK_PassByIndirectRestore:
   case SK_ProduceObjCObject:
   case SK_StdInitializerList:
+  case SK_OCLNULLEvent:
     break;
 
   case SK_ConversionSequence:
@@ -2652,6 +2653,13 @@
   Steps.push_back(S);
 }
 
+void InitializationSequence::AddOCLNullEventStep(QualType T) {
+  Step S;
+  S.Kind = SK_OCLNULLEvent;
+  S.Type = T;
+  Steps.push_back(S);
+}
+
 void InitializationSequence::RewrapReferenceInitList(QualType T,
                                                      InitListExpr *Syntactic) {
   assert(Syntactic->getNumInits() == 1 &&
@@ -4005,6 +4013,18 @@
   return true;
 }
 
+static bool TryOCLNULLEventInitialization(Sema &S,
+                                          InitializationSequence &Sequence,
+                                          QualType DestType,
+                                          Expr *Initializer) {
+  if (!S.getLangOpts().OpenCL || !DestType->isEventT() ||
+    !Initializer->getType()->isIntegralType(S.getASTContext()))
+    return false;
+
+  Sequence.AddOCLNullEventStep(DestType);
+  return true;
+}
+
 InitializationSequence::InitializationSequence(Sema &S,
                                                const InitializedEntity &Entity,
                                                const InitializationKind &Kind,
@@ -4148,6 +4168,11 @@
       return;
     }
     
+
+    if (TryOCLNULLEventInitialization(S, *this, DestType, Initializer)) {
+      return;
+    }
+
     // Handle initialization in C
     AddCAssignmentStep(DestType);
     MaybeProduceObjCObject(S, *this, Entity);
@@ -4935,7 +4960,8 @@
   case SK_PassByIndirectCopyRestore:
   case SK_PassByIndirectRestore:
   case SK_ProduceObjCObject:
-  case SK_StdInitializerList: {
+  case SK_StdInitializerList:
+  case SK_OCLNULLEvent: {
     assert(Args.size() == 1);
     CurInit = Args[0];
     if (!CurInit.get()) return ExprError();
@@ -5448,7 +5474,23 @@
       CurInit = S.Owned(Semantic);
       break;
     }
+    case SK_OCLNULLEvent: {
+      assert(Step->Type->isEventT() && 
+             "Event initialization on non event type.");
+
+      if (Entity.getKind() != InitializedEntity::EK_Parameter)
+        S.Diag(Kind.getLocation(), diag::err_event_initialization);
+      else if (!CurInit.get()->isNullPointerConstant(S.getASTContext(), 
+                                               Expr::NPC_ValueDependentIsNull))
+        S.Diag(Kind.getLocation(), diag::err_event_argument_not_null)
+          << SourceType;
+      else
+        CurInit = S.ImpCastExprToType(CurInit.take(), Step->Type,
+                      CK_NullToOCLEvent,
+                      CurInit.get()->getValueKind());
+      break;
     }
+    }
   }
 
   // Diagnose non-fatal problems with the completed initialization.
@@ -6134,6 +6176,10 @@
     case SK_StdInitializerList:
       OS << "std::initializer_list from initializer list";
       break;
+
+    case SK_OCLNULLEvent:
+      OS << "OpenCL event_t from NULL";
+      break;
     }
   }
 }
Index: lib/Sema/SemaTemplateVariadic.cpp
===================================================================
--- lib/Sema/SemaTemplateVariadic.cpp	(revision 170542)
+++ lib/Sema/SemaTemplateVariadic.cpp	(working copy)
@@ -737,6 +737,7 @@
   case TST_image2d_t:
   case TST_image2d_array_t:
   case TST_image3d_t:
+  case TST_event_t:
   case TST_error:
     break;
   }
Index: lib/Sema/SemaType.cpp
===================================================================
--- lib/Sema/SemaType.cpp	(revision 170542)
+++ lib/Sema/SemaType.cpp	(working copy)
@@ -927,6 +927,10 @@
     Result = Context.OCLImage3dTy;
     break;
 
+  case DeclSpec::TST_event_t:
+    Result = Context.OCLEventTy;
+    break;
+
   case DeclSpec::TST_error:
     Result = Context.IntTy;
     declarator.setInvalidType(true);
Index: lib/Serialization/ASTCommon.cpp
===================================================================
--- lib/Serialization/ASTCommon.cpp	(revision 170542)
+++ lib/Serialization/ASTCommon.cpp	(working copy)
@@ -66,6 +66,7 @@
   case BuiltinType::OCLImage2d:       ID = PREDEF_TYPE_IMAGE2D_ID;      break;
   case BuiltinType::OCLImage2dArray:  ID = PREDEF_TYPE_IMAGE2D_ARR_ID;  break;
   case BuiltinType::OCLImage3d:       ID = PREDEF_TYPE_IMAGE3D_ID;      break;
+  case BuiltinType::OCLEvent:         ID = PREDEF_TYPE_EVENT_ID;        break;
   case BuiltinType::BuiltinFn:
                                 ID = PREDEF_TYPE_BUILTIN_FN; break;
 
Index: lib/Serialization/ASTReader.cpp
===================================================================
--- lib/Serialization/ASTReader.cpp	(revision 170542)
+++ lib/Serialization/ASTReader.cpp	(working copy)
@@ -4889,6 +4889,7 @@
     case PREDEF_TYPE_IMAGE2D_ID:    T = Context.OCLImage2dTy;       break;
     case PREDEF_TYPE_IMAGE2D_ARR_ID: T = Context.OCLImage2dArrayTy; break;
     case PREDEF_TYPE_IMAGE3D_ID:    T = Context.OCLImage3dTy;       break;
+    case PREDEF_TYPE_EVENT_ID:      T = Context.OCLEventTy;         break;
     case PREDEF_TYPE_AUTO_DEDUCT:   T = Context.getAutoDeductType(); break;
         
     case PREDEF_TYPE_AUTO_RREF_DEDUCT: 
Index: lib/StaticAnalyzer/Core/ExprEngineC.cpp
===================================================================
--- lib/StaticAnalyzer/Core/ExprEngineC.cpp	(revision 170542)
+++ lib/StaticAnalyzer/Core/ExprEngineC.cpp	(working copy)
@@ -306,7 +306,8 @@
       case CK_CPointerToObjCPointerCast:
       case CK_BlockPointerToObjCPointerCast:
       case CK_AnyPointerToBlockPointerCast:  
-      case CK_ObjCObjectLValueCast: {
+      case CK_ObjCObjectLValueCast: 
+      case CK_NullToOCLEvent: {
         // Delegate to SValBuilder to process.
         SVal V = state->getSVal(Ex, LCtx);
         V = svalBuilder.evalCast(V, T, ExTy);
Index: test/CodeGenOpenCL/event_t.cl
===================================================================
--- test/CodeGenOpenCL/event_t.cl	(revision 0)
+++ test/CodeGenOpenCL/event_t.cl	(revision 0)
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - -O0 | FileCheck %s
+
+void foo(event_t evt);
+
+void kernel ker() {
+  event_t e;
+// CHECK: alloca %opencl.event_t*,
+  foo(e);
+// CHECK: call void @foo(%opencl.event_t* %
+  foo(0);
+// CHECK: call void @foo(%opencl.event_t* null)
+}
Index: test/CodeGenOpenCL/opencl_types.cl
===================================================================
--- test/CodeGenOpenCL/opencl_types.cl	(revision 170542)
+++ test/CodeGenOpenCL/opencl_types.cl	(working copy)
@@ -19,4 +19,6 @@
 // CHECK: @fnc3(%opencl.image3d_t*
 
 kernel void foo(image1d_t img) {
+	event_t evt;
+// CHECK: alloca %opencl.event_t*
 }
Index: test/PCH/ocl_types.cl
===================================================================
--- test/PCH/ocl_types.cl	(revision 170542)
+++ test/PCH/ocl_types.cl	(working copy)
@@ -16,3 +16,7 @@
 void foo5(img2darr_t img);
 
 void foo6(img3d_t img);
+
+void foo8(evt_t evt) {
+  evt_t loc_evt;
+}
Index: test/PCH/ocl_types.h
===================================================================
--- test/PCH/ocl_types.h	(revision 170542)
+++ test/PCH/ocl_types.h	(working copy)
@@ -17,3 +17,6 @@
 
 // image3d_t
 typedef image3d_t img3d_t;
+
+// event_t
+typedef event_t evt_t;
Index: test/SemaOpenCL/event_t.cl
===================================================================
--- test/SemaOpenCL/event_t.cl	(revision 0)
+++ test/SemaOpenCL/event_t.cl	(revision 0)
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+
+void foo(event_t evt);
+
+void kernel ker() {
+  event_t e = 0; // expected-error {{initialization of event_t variables is not allowed}}
+  foo(0);
+  foo(5); // expected-error {{passing 'int' as event_t function argument is not allowed; use an event_t variable or NULL}}
+}
Index: tools/libclang/CIndex.cpp
===================================================================
--- tools/libclang/CIndex.cpp	(revision 170542)
+++ tools/libclang/CIndex.cpp	(working copy)
@@ -1376,6 +1376,7 @@
   case BuiltinType::OCLImage2d:
   case BuiltinType::OCLImage2dArray:
   case BuiltinType::OCLImage3d:
+  case BuiltinType::OCLEvent:
 #define BUILTIN_TYPE(Id, SingletonId)
 #define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
 #define UNSIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
Index: tools/libclang/CIndexUSRs.cpp
===================================================================
--- tools/libclang/CIndexUSRs.cpp	(revision 170542)
+++ tools/libclang/CIndexUSRs.cpp	(working copy)
@@ -593,6 +593,7 @@
         case BuiltinType::OCLImage2d:
         case BuiltinType::OCLImage2dArray:
         case BuiltinType::OCLImage3d:
+        case BuiltinType::OCLEvent:
           IgnoreResults = true;
           return;
         case BuiltinType::ObjCId:
