Include llvm::Optional in clang/Basic/LLVM.h

Post-commit CR feedback from Jordan Rose regarding r175594.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175679 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp b/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
index 27692fe..5e4b824 100644
--- a/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
+++ b/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
@@ -110,12 +110,12 @@
 
   SVal extentBegin = computeExtentBegin(svalBuilder, rawOffset.getRegion());
   
-  if (llvm::Optional<NonLoc> NV = extentBegin.getAs<NonLoc>()) {
+  if (Optional<NonLoc> NV = extentBegin.getAs<NonLoc>()) {
     SVal lowerBound =
         svalBuilder.evalBinOpNN(state, BO_LT, rawOffset.getByteOffset(), *NV,
                                 svalBuilder.getConditionType());
 
-    llvm::Optional<NonLoc> lowerBoundToCheck = lowerBound.getAs<NonLoc>();
+    Optional<NonLoc> lowerBoundToCheck = lowerBound.getAs<NonLoc>();
     if (!lowerBoundToCheck)
       return;
     
@@ -147,7 +147,7 @@
                                 extentVal.castAs<NonLoc>(),
                                 svalBuilder.getConditionType());
   
-    llvm::Optional<NonLoc> upperboundToCheck = upperbound.getAs<NonLoc>();
+    Optional<NonLoc> upperboundToCheck = upperbound.getAs<NonLoc>();
     if (!upperboundToCheck)
       break;
   
diff --git a/lib/StaticAnalyzer/Checkers/AttrNonNullChecker.cpp b/lib/StaticAnalyzer/Checkers/AttrNonNullChecker.cpp
index 6185a8e..de5e6dc 100644
--- a/lib/StaticAnalyzer/Checkers/AttrNonNullChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/AttrNonNullChecker.cpp
@@ -51,7 +51,7 @@
       continue;
 
     SVal V = Call.getArgSVal(idx);
-    llvm::Optional<DefinedSVal> DV = V.getAs<DefinedSVal>();
+    Optional<DefinedSVal> DV = V.getAs<DefinedSVal>();
 
     // If the value is unknown or undefined, we can't perform this check.
     if (!DV)
@@ -69,7 +69,7 @@
       if (!UT || !UT->getDecl()->hasAttr<TransparentUnionAttr>())
         continue;
 
-      if (llvm::Optional<nonloc::CompoundVal> CSV =
+      if (Optional<nonloc::CompoundVal> CSV =
               DV->getAs<nonloc::CompoundVal>()) {
         nonloc::CompoundVal::iterator CSV_I = CSV->begin();
         assert(CSV_I != CSV->end());
diff --git a/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp b/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
index 7603f8f..ae33a8a 100644
--- a/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
+++ b/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
@@ -268,13 +268,12 @@
 
   // FIXME: We really should allow ranges of valid theType values, and
   //   bifurcate the state appropriately.
-  llvm::Optional<nonloc::ConcreteInt> V =
-      TheTypeVal.getAs<nonloc::ConcreteInt>();
+  Optional<nonloc::ConcreteInt> V = TheTypeVal.getAs<nonloc::ConcreteInt>();
   if (!V)
     return;
 
   uint64_t NumberKind = V->getValue().getLimitedValue();
-  llvm::Optional<uint64_t> OptTargetSize = GetCFNumberSize(Ctx, NumberKind);
+  Optional<uint64_t> OptTargetSize = GetCFNumberSize(Ctx, NumberKind);
 
   // FIXME: In some cases we can emit an error.
   if (!OptTargetSize)
@@ -289,8 +288,7 @@
 
   // FIXME: Eventually we should handle arbitrary locations.  We can do this
   //  by having an enhanced memory model that does low-level typing.
-  llvm::Optional<loc::MemRegionVal> LV =
-      TheValueExpr.getAs<loc::MemRegionVal>();
+  Optional<loc::MemRegionVal> LV = TheValueExpr.getAs<loc::MemRegionVal>();
   if (!LV)
     return;
 
@@ -391,7 +389,7 @@
   // Get the argument's value.
   const Expr *Arg = CE->getArg(0);
   SVal ArgVal = state->getSVal(Arg, C.getLocationContext());
-  llvm::Optional<DefinedSVal> DefArgVal = ArgVal.getAs<DefinedSVal>();
+  Optional<DefinedSVal> DefArgVal = ArgVal.getAs<DefinedSVal>();
   if (!DefArgVal)
     return;
 
@@ -589,7 +587,7 @@
     return;
 
   // Verify that all arguments have Objective-C types.
-  llvm::Optional<ExplodedNode*> errorNode;
+  Optional<ExplodedNode*> errorNode;
   ProgramStateRef state = C.getState();
   
   for (unsigned I = variadicArgsBegin; I != variadicArgsEnd; ++I) {
@@ -728,8 +726,7 @@
                                            ProgramStateRef State,
                                            CheckerContext &C) {
   SVal Val = State->getSVal(NonNullExpr, C.getLocationContext());
-  if (llvm::Optional<DefinedOrUnknownSVal> DV =
-          Val.getAs<DefinedOrUnknownSVal>())
+  if (Optional<DefinedOrUnknownSVal> DV = Val.getAs<DefinedOrUnknownSVal>())
     return State->assume(*DV, true);
   return State;
 }
diff --git a/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp b/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp
index 3ceb8c4..5169244 100644
--- a/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp
@@ -69,7 +69,7 @@
   // Get the value of the right-hand side.  We only care about values
   // that are defined (UnknownVals and UndefinedVals are handled by other
   // checkers).
-  llvm::Optional<DefinedSVal> DV = val.getAs<DefinedSVal>();
+  Optional<DefinedSVal> DV = val.getAs<DefinedSVal>();
   if (!DV)
     return;
     
@@ -86,7 +86,7 @@
     svalBuilder.evalBinOp(state, BO_GE, *DV, zeroVal,
                           svalBuilder.getConditionType());
 
-  llvm::Optional<DefinedSVal> greaterThanEqualToZero =
+  Optional<DefinedSVal> greaterThanEqualToZero =
       greaterThanOrEqualToZeroVal.getAs<DefinedSVal>();
 
   if (!greaterThanEqualToZero) {
@@ -122,7 +122,7 @@
     svalBuilder.evalBinOp(state, BO_LE, *DV, OneVal,
                           svalBuilder.getConditionType());
 
-  llvm::Optional<DefinedSVal> lessThanEqToOne =
+  Optional<DefinedSVal> lessThanEqToOne =
       lessThanEqToOneVal.getAs<DefinedSVal>();
 
   if (!lessThanEqToOne) {
diff --git a/lib/StaticAnalyzer/Checkers/CStringChecker.cpp b/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index 1c99567..d0c4322 100644
--- a/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -201,7 +201,7 @@
 std::pair<ProgramStateRef , ProgramStateRef >
 CStringChecker::assumeZero(CheckerContext &C, ProgramStateRef state, SVal V,
                            QualType Ty) {
-  llvm::Optional<DefinedSVal> val = V.getAs<DefinedSVal>();
+  Optional<DefinedSVal> val = V.getAs<DefinedSVal>();
   if (!val)
     return std::pair<ProgramStateRef , ProgramStateRef >(state, state);
 
@@ -359,7 +359,7 @@
   // FIXME: This assumes the caller has already checked that the access length
   // is positive. And that it's unsigned.
   SVal LengthVal = state->getSVal(Size, LCtx);
-  llvm::Optional<NonLoc> Length = LengthVal.getAs<NonLoc>();
+  Optional<NonLoc> Length = LengthVal.getAs<NonLoc>();
   if (!Length)
     return state;
 
@@ -370,7 +370,7 @@
 
   // Check that the first buffer is sufficiently long.
   SVal BufStart = svalBuilder.evalCast(BufVal, PtrTy, FirstBuf->getType());
-  if (llvm::Optional<Loc> BufLoc = BufStart.getAs<Loc>()) {
+  if (Optional<Loc> BufLoc = BufStart.getAs<Loc>()) {
     const Expr *warningExpr = (WarnAboutSize ? Size : FirstBuf);
 
     SVal BufEnd = svalBuilder.evalBinOpLN(state, BO_Add, *BufLoc,
@@ -390,7 +390,7 @@
       return NULL;
 
     BufStart = svalBuilder.evalCast(BufVal, PtrTy, SecondBuf->getType());
-    if (llvm::Optional<Loc> BufLoc = BufStart.getAs<Loc>()) {
+    if (Optional<Loc> BufLoc = BufStart.getAs<Loc>()) {
       const Expr *warningExpr = (WarnAboutSize ? Size : SecondBuf);
 
       SVal BufEnd = svalBuilder.evalBinOpLN(state, BO_Add, *BufLoc,
@@ -426,11 +426,11 @@
   SVal firstVal = state->getSVal(First, LCtx);
   SVal secondVal = state->getSVal(Second, LCtx);
 
-  llvm::Optional<Loc> firstLoc = firstVal.getAs<Loc>();
+  Optional<Loc> firstLoc = firstVal.getAs<Loc>();
   if (!firstLoc)
     return state;
 
-  llvm::Optional<Loc> secondLoc = secondVal.getAs<Loc>();
+  Optional<Loc> secondLoc = secondVal.getAs<Loc>();
   if (!secondLoc)
     return state;
 
@@ -453,7 +453,7 @@
   QualType cmpTy = svalBuilder.getConditionType();
   SVal reverse = svalBuilder.evalBinOpLL(state, BO_GT,
                                          *firstLoc, *secondLoc, cmpTy);
-  llvm::Optional<DefinedOrUnknownSVal> reverseTest =
+  Optional<DefinedOrUnknownSVal> reverseTest =
       reverse.getAs<DefinedOrUnknownSVal>();
   if (!reverseTest)
     return state;
@@ -474,7 +474,7 @@
 
   // Get the length, and make sure it too is known.
   SVal LengthVal = state->getSVal(Size, LCtx);
-  llvm::Optional<NonLoc> Length = LengthVal.getAs<NonLoc>();
+  Optional<NonLoc> Length = LengthVal.getAs<NonLoc>();
   if (!Length)
     return state;
 
@@ -484,21 +484,21 @@
   QualType CharPtrTy = Ctx.getPointerType(Ctx.CharTy);
   SVal FirstStart = svalBuilder.evalCast(*firstLoc, CharPtrTy, 
                                          First->getType());
-  llvm::Optional<Loc> FirstStartLoc = FirstStart.getAs<Loc>();
+  Optional<Loc> FirstStartLoc = FirstStart.getAs<Loc>();
   if (!FirstStartLoc)
     return state;
 
   // Compute the end of the first buffer. Bail out if THAT fails.
   SVal FirstEnd = svalBuilder.evalBinOpLN(state, BO_Add,
                                  *FirstStartLoc, *Length, CharPtrTy);
-  llvm::Optional<Loc> FirstEndLoc = FirstEnd.getAs<Loc>();
+  Optional<Loc> FirstEndLoc = FirstEnd.getAs<Loc>();
   if (!FirstEndLoc)
     return state;
 
   // Is the end of the first buffer past the start of the second buffer?
   SVal Overlap = svalBuilder.evalBinOpLL(state, BO_GT,
                                 *FirstEndLoc, *secondLoc, cmpTy);
-  llvm::Optional<DefinedOrUnknownSVal> OverlapTest =
+  Optional<DefinedOrUnknownSVal> OverlapTest =
       Overlap.getAs<DefinedOrUnknownSVal>();
   if (!OverlapTest)
     return state;
@@ -566,7 +566,7 @@
     left = right;
   }
 
-  if (llvm::Optional<NonLoc> maxMinusRightNL = maxMinusRight.getAs<NonLoc>()) {
+  if (Optional<NonLoc> maxMinusRightNL = maxMinusRight.getAs<NonLoc>()) {
     QualType cmpTy = svalBuilder.getConditionType();
     // If left > max - right, we have an overflow.
     SVal willOverflow = svalBuilder.evalBinOpNN(state, BO_GT, left,
@@ -681,7 +681,7 @@
     // If we can't get a region, see if it's something we /know/ isn't a
     // C string. In the context of locations, the only time we can issue such
     // a warning is for labels.
-    if (llvm::Optional<loc::GotoLabel> Label = Buf.getAs<loc::GotoLabel>()) {
+    if (Optional<loc::GotoLabel> Label = Buf.getAs<loc::GotoLabel>()) {
       if (!Filter.CheckCStringNotNullTerm)
         return UndefinedVal();
 
@@ -796,14 +796,14 @@
 ProgramStateRef CStringChecker::InvalidateBuffer(CheckerContext &C,
                                                 ProgramStateRef state,
                                                 const Expr *E, SVal V) {
-  llvm::Optional<Loc> L = V.getAs<Loc>();
+  Optional<Loc> L = V.getAs<Loc>();
   if (!L)
     return state;
 
   // FIXME: This is a simplified version of what's in CFRefCount.cpp -- it makes
   // some assumptions about the value that CFRefCount can't. Even so, it should
   // probably be refactored.
-  if (llvm::Optional<loc::MemRegionVal> MR = L->getAs<loc::MemRegionVal>()) {
+  if (Optional<loc::MemRegionVal> MR = L->getAs<loc::MemRegionVal>()) {
     const MemRegion *R = MR->getRegion()->StripCasts();
 
     // Are we dealing with an ElementRegion?  If so, we should be invalidating
@@ -930,7 +930,7 @@
       loc::MemRegionVal destRegVal = destVal.castAs<loc::MemRegionVal>();
       
       // Get the length to copy.
-      if (llvm::Optional<NonLoc> lenValNonLoc = sizeVal.getAs<NonLoc>()) {
+      if (Optional<NonLoc> lenValNonLoc = sizeVal.getAs<NonLoc>()) {
         // Get the byte after the last byte copied.
         SVal lastElement = C.getSValBuilder().evalBinOpLN(state, BO_Add, 
                                                           destRegVal,
@@ -1161,8 +1161,8 @@
     const Expr *maxlenExpr = CE->getArg(1);
     SVal maxlenVal = state->getSVal(maxlenExpr, LCtx);
 
-    llvm::Optional<NonLoc> strLengthNL = strLength.getAs<NonLoc>();
-    llvm::Optional<NonLoc> maxlenValNL = maxlenVal.getAs<NonLoc>();
+    Optional<NonLoc> strLengthNL = strLength.getAs<NonLoc>();
+    Optional<NonLoc> maxlenValNL = maxlenVal.getAs<NonLoc>();
 
     if (strLengthNL && maxlenValNL) {
       ProgramStateRef stateStringTooLong, stateStringNotTooLong;
@@ -1324,8 +1324,8 @@
     // Protect against misdeclared strncpy().
     lenVal = svalBuilder.evalCast(lenVal, sizeTy, lenExpr->getType());
 
-    llvm::Optional<NonLoc> strLengthNL = strLength.getAs<NonLoc>();
-    llvm::Optional<NonLoc> lenValNL = lenVal.getAs<NonLoc>();
+    Optional<NonLoc> strLengthNL = strLength.getAs<NonLoc>();
+    Optional<NonLoc> lenValNL = lenVal.getAs<NonLoc>();
 
     // If we know both values, we might be able to figure out how much
     // we're copying.
@@ -1364,8 +1364,7 @@
         if (dstStrLength.isUndef())
           return;
 
-        if (llvm::Optional<NonLoc> dstStrLengthNL =
-                dstStrLength.getAs<NonLoc>()) {
+        if (Optional<NonLoc> dstStrLengthNL = dstStrLength.getAs<NonLoc>()) {
           maxLastElementIndex = svalBuilder.evalBinOpNN(state, BO_Add,
                                                         *lenValNL,
                                                         *dstStrLengthNL,
@@ -1414,8 +1413,7 @@
       amountCopied = getCStringLength(C, state, lenExpr, srcVal, true);
       assert(!amountCopied.isUndef());
 
-      if (llvm::Optional<NonLoc> amountCopiedNL =
-              amountCopied.getAs<NonLoc>()) {
+      if (Optional<NonLoc> amountCopiedNL = amountCopied.getAs<NonLoc>()) {
         if (lenValNL) {
           // amountCopied <= lenVal
           SVal copiedLessThanBound = svalBuilder.evalBinOpNN(state, BO_LE,
@@ -1465,8 +1463,8 @@
     if (dstStrLength.isUndef())
       return;
 
-    llvm::Optional<NonLoc> srcStrLengthNL = amountCopied.getAs<NonLoc>();
-    llvm::Optional<NonLoc> dstStrLengthNL = dstStrLength.getAs<NonLoc>();
+    Optional<NonLoc> srcStrLengthNL = amountCopied.getAs<NonLoc>();
+    Optional<NonLoc> dstStrLengthNL = dstStrLength.getAs<NonLoc>();
     
     // If we know both string lengths, we might know the final string length.
     if (srcStrLengthNL && dstStrLengthNL) {
@@ -1487,8 +1485,7 @@
       finalStrLength = getCStringLength(C, state, CE, DstVal, true);
       assert(!finalStrLength.isUndef());
 
-      if (llvm::Optional<NonLoc> finalStrLengthNL =
-              finalStrLength.getAs<NonLoc>()) {
+      if (Optional<NonLoc> finalStrLengthNL = finalStrLength.getAs<NonLoc>()) {
         if (srcStrLengthNL) {
           // finalStrLength >= srcStrLength
           SVal sourceInResult = svalBuilder.evalBinOpNN(state, BO_GE,
@@ -1529,15 +1526,14 @@
 
   // If the destination is a MemRegion, try to check for a buffer overflow and
   // record the new string length.
-  if (llvm::Optional<loc::MemRegionVal> dstRegVal =
+  if (Optional<loc::MemRegionVal> dstRegVal =
           DstVal.getAs<loc::MemRegionVal>()) {
     QualType ptrTy = Dst->getType();
 
     // If we have an exact value on a bounded copy, use that to check for
     // overflows, rather than our estimate about how much is actually copied.
     if (boundWarning) {
-      if (llvm::Optional<NonLoc> maxLastNL =
-              maxLastElementIndex.getAs<NonLoc>()) {
+      if (Optional<NonLoc> maxLastNL = maxLastElementIndex.getAs<NonLoc>()) {
         SVal maxLastElement = svalBuilder.evalBinOpLN(state, BO_Add, *dstRegVal,
                                                       *maxLastNL, ptrTy);
         state = CheckLocation(C, state, CE->getArg(2), maxLastElement, 
@@ -1548,8 +1544,7 @@
     }
 
     // Then, if the final length is known...
-    if (llvm::Optional<NonLoc> knownStrLength =
-            finalStrLength.getAs<NonLoc>()) {
+    if (Optional<NonLoc> knownStrLength = finalStrLength.getAs<NonLoc>()) {
       SVal lastElement = svalBuilder.evalBinOpLN(state, BO_Add, *dstRegVal,
                                                  *knownStrLength, ptrTy);
 
diff --git a/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp b/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
index d5203a8..37e203d 100644
--- a/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
@@ -134,7 +134,7 @@
   if (!checkUninitFields)
     return false;
 
-  if (llvm::Optional<nonloc::LazyCompoundVal> LV =
+  if (Optional<nonloc::LazyCompoundVal> LV =
           V.getAs<nonloc::LazyCompoundVal>()) {
 
     class FindUninitializedField {
diff --git a/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp b/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp
index 3c14e7e..93daf94 100644
--- a/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp
@@ -58,7 +58,7 @@
     return;
 
   SVal Denom = C.getState()->getSVal(B->getRHS(), C.getLocationContext());
-  llvm::Optional<DefinedSVal> DV = Denom.getAs<DefinedSVal>();
+  Optional<DefinedSVal> DV = Denom.getAs<DefinedSVal>();
 
   // Divide-by-undefined handled in the generic checking for uses of
   // undefined values.
diff --git a/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp b/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
index 00ef1f6..c67c597 100644
--- a/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
@@ -431,7 +431,7 @@
   if (AddrVal.isUnknownOrUndef())
     return 0;
 
-  llvm::Optional<Loc> AddrLoc = AddrVal.getAs<Loc>();
+  Optional<Loc> AddrLoc = AddrVal.getAs<Loc>();
   if (!AddrLoc)
     return 0;
 
diff --git a/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp b/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
index 50114e9..84cad82 100644
--- a/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
@@ -217,7 +217,7 @@
   ProgramStateRef State = C.getState();
   SVal ArgV = State->getSVal(Expr, C.getLocationContext());
 
-  if (llvm::Optional<loc::MemRegionVal> X = ArgV.getAs<loc::MemRegionVal>()) {
+  if (Optional<loc::MemRegionVal> X = ArgV.getAs<loc::MemRegionVal>()) {
     StoreManager& SM = C.getStoreManager();
     SymbolRef sym = SM.getBinding(State->getStore(), *X).getAsLocSymbol();
     if (sym)
diff --git a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index aaaafeb..38722a2 100644
--- a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -571,7 +571,7 @@
       dyn_cast_or_null<SymbolicRegion>(RetVal.getAsRegion());
   if (!R)
     return 0;
-  if (llvm::Optional<DefinedOrUnknownSVal> DefinedSize =
+  if (Optional<DefinedOrUnknownSVal> DefinedSize =
           Size.getAs<DefinedOrUnknownSVal>()) {
     SValBuilder &svalBuilder = C.getSValBuilder();
     DefinedOrUnknownSVal Extent = R->getExtent(svalBuilder);
@@ -782,13 +782,11 @@
 }
 
 bool MallocChecker::SummarizeValue(raw_ostream &os, SVal V) {
-  if (llvm::Optional<nonloc::ConcreteInt> IntVal =
-          V.getAs<nonloc::ConcreteInt>())
+  if (Optional<nonloc::ConcreteInt> IntVal = V.getAs<nonloc::ConcreteInt>())
     os << "an integer (" << IntVal->getValue() << ")";
-  else if (llvm::Optional<loc::ConcreteInt> ConstAddr =
-               V.getAs<loc::ConcreteInt>())
+  else if (Optional<loc::ConcreteInt> ConstAddr = V.getAs<loc::ConcreteInt>())
     os << "a constant address (" << ConstAddr->getValue() << ")";
-  else if (llvm::Optional<loc::GotoLabel> Label = V.getAs<loc::GotoLabel>())
+  else if (Optional<loc::GotoLabel> Label = V.getAs<loc::GotoLabel>())
     os << "the address of the label '" << Label->getLabel()->getName() << "'";
   else
     return false;
diff --git a/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp b/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
index 9e2202b..9f01522 100644
--- a/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
@@ -186,7 +186,7 @@
 static QualType parameterTypeFromSVal(SVal val, CheckerContext &C) {
   const StackFrameContext *
     SFC = C.getLocationContext()->getCurrentStackFrame();
-  if (llvm::Optional<loc::MemRegionVal> X = val.getAs<loc::MemRegionVal>()) {
+  if (Optional<loc::MemRegionVal> X = val.getAs<loc::MemRegionVal>()) {
     const MemRegion* R = X->getRegion();
     if (const VarRegion *VR = R->getAs<VarRegion>())
       if (const StackArgumentsSpaceRegion *
diff --git a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
index cb731fc..69191de 100644
--- a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -3361,8 +3361,7 @@
   //     does not understand.
   ProgramStateRef state = C.getState();
 
-  if (llvm::Optional<loc::MemRegionVal> regionLoc =
-          loc.getAs<loc::MemRegionVal>()) {
+  if (Optional<loc::MemRegionVal> regionLoc = loc.getAs<loc::MemRegionVal>()) {
     escapes = !regionLoc->getRegion()->hasStackStorage();
 
     if (!escapes) {
diff --git a/lib/StaticAnalyzer/Checkers/StreamChecker.cpp b/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 2a6c217..1c38ab0 100644
--- a/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -259,7 +259,7 @@
     return;
   // Check the legality of the 'whence' argument of 'fseek'.
   SVal Whence = state->getSVal(CE->getArg(2), C.getLocationContext());
-  llvm::Optional<nonloc::ConcreteInt> CI = Whence.getAs<nonloc::ConcreteInt>();
+  Optional<nonloc::ConcreteInt> CI = Whence.getAs<nonloc::ConcreteInt>();
 
   if (!CI)
     return;
@@ -337,7 +337,7 @@
 
 ProgramStateRef StreamChecker::CheckNullStream(SVal SV, ProgramStateRef state,
                                     CheckerContext &C) const {
-  llvm::Optional<DefinedSVal> DV = SV.getAs<DefinedSVal>();
+  Optional<DefinedSVal> DV = SV.getAs<DefinedSVal>();
   if (!DV)
     return 0;
 
diff --git a/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp b/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
index 3e11fd8..4ea07e2 100644
--- a/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
@@ -27,7 +27,6 @@
 
 using namespace clang;
 using namespace ento;
-using llvm::Optional;
 
 namespace {
 class UnixAPIChecker : public Checker< check::PreStmt<CallExpr> > {
diff --git a/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp b/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
index cb02e94..2d6246e 100644
--- a/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ b/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -109,8 +109,7 @@
       .Default(DefaultVal);
 }
 
-bool AnalyzerOptions::getBooleanOption(llvm::Optional<bool> &V,
-                                       StringRef Name,
+bool AnalyzerOptions::getBooleanOption(Optional<bool> &V, StringRef Name,
                                        bool DefaultVal) {
   if (!V.hasValue())
     V = getBooleanOption(Name, DefaultVal);
diff --git a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index 8afd488..05d187e 100644
--- a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -475,7 +475,7 @@
 
         if (!b)
           os << action << "a null pointer value";
-      } else if (llvm::Optional<nonloc::ConcreteInt> CVal =
+      } else if (Optional<nonloc::ConcreteInt> CVal =
                      V.getAs<nonloc::ConcreteInt>()) {
         os << action << CVal->getValue();
       }
@@ -506,7 +506,7 @@
         os << "null pointer value";
     } else if (V.isUndef()) {
       os << "uninitialized value";
-    } else if (llvm::Optional<nonloc::ConcreteInt> CI =
+    } else if (Optional<nonloc::ConcreteInt> CI =
                    V.getAs<nonloc::ConcreteInt>()) {
       os << "the value " << CI->getValue();
     } else {
@@ -538,7 +538,7 @@
     }
     else if (V.isUndef()) {
       os << "Uninitialized value stored to ";
-    } else if (llvm::Optional<nonloc::ConcreteInt> CV =
+    } else if (Optional<nonloc::ConcreteInt> CV =
                    V.getAs<nonloc::ConcreteInt>()) {
       os << "The value " << CV->getValue() << " is assigned to ";
     }
@@ -713,7 +713,7 @@
   // assert(!V.isUnknownOrUndef());
 
   // Is it a symbolic value?
-  if (llvm::Optional<loc::MemRegionVal> L = V.getAs<loc::MemRegionVal>()) {
+  if (Optional<loc::MemRegionVal> L = V.getAs<loc::MemRegionVal>()) {
     // At this point we are dealing with the region's LValue.
     // However, if the rvalue is a symbolic region, we should track it as well.
     SVal RVal = state->getSVal(L->getRegion());
@@ -766,7 +766,7 @@
     return 0;
   ProgramStateRef state = N->getState();
   const SVal &V = state->getSVal(Receiver, N->getLocationContext());
-  llvm::Optional<DefinedOrUnknownSVal> DV = V.getAs<DefinedOrUnknownSVal>();
+  Optional<DefinedOrUnknownSVal> DV = V.getAs<DefinedOrUnknownSVal>();
   if (!DV)
     return 0;
   state = state->assume(*DV, true);
@@ -951,7 +951,7 @@
                                       BugReporterContext &BRC,
                                       BugReport &report,
                                       const ExplodedNode *N,
-                                      llvm::Optional<bool> &prunable) {
+                                      Optional<bool> &prunable) {
   const Expr *OriginalExpr = Ex;
   Ex = Ex->IgnoreParenCasts();
 
@@ -1010,7 +1010,7 @@
                                   const ExplodedNode *N) {
   
   bool shouldInvert = false;
-  llvm::Optional<bool> shouldPrune;
+  Optional<bool> shouldPrune;
   
   SmallString<128> LhsString, RhsString;
   {
diff --git a/lib/StaticAnalyzer/Core/CallEvent.cpp b/lib/StaticAnalyzer/Core/CallEvent.cpp
index a09d483..c5e3c05 100644
--- a/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ b/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -156,7 +156,7 @@
 
     // If we are passing a location wrapped as an integer, unwrap it and
     // invalidate the values referred by the location.
-    if (llvm::Optional<nonloc::LocAsInteger> Wrapped =
+    if (Optional<nonloc::LocAsInteger> Wrapped =
             V.getAs<nonloc::LocAsInteger>())
       V = Wrapped->getLoc();
     else if (!V.getAs<Loc>())
@@ -854,12 +854,11 @@
         typedef std::pair<const ObjCInterfaceDecl*, Selector>
                 PrivateMethodKey;
         typedef llvm::DenseMap<PrivateMethodKey,
-                               llvm::Optional<const ObjCMethodDecl *> >
+                               Optional<const ObjCMethodDecl *> >
                 PrivateMethodCache;
 
         static PrivateMethodCache PMC;
-        llvm::Optional<const ObjCMethodDecl *> &Val =
-          PMC[std::make_pair(IDecl, Sel)];
+        Optional<const ObjCMethodDecl *> &Val = PMC[std::make_pair(IDecl, Sel)];
 
         // Query lookupPrivateMethod() if the cache does not hit.
         if (!Val.hasValue())
diff --git a/lib/StaticAnalyzer/Core/Environment.cpp b/lib/StaticAnalyzer/Core/Environment.cpp
index 481e1bf..fe352aa 100644
--- a/lib/StaticAnalyzer/Core/Environment.cpp
+++ b/lib/StaticAnalyzer/Core/Environment.cpp
@@ -198,7 +198,7 @@
       EBMapRef = EBMapRef.add(BlkExpr, X);
 
       // If the block expr's value is a memory region, then mark that region.
-      if (llvm::Optional<loc::MemRegionVal> R = X.getAs<loc::MemRegionVal>())
+      if (Optional<loc::MemRegionVal> R = X.getAs<loc::MemRegionVal>())
         SymReaper.markLive(R->getRegion());
 
       // Mark all symbols in the block expr's value live.
diff --git a/lib/StaticAnalyzer/Core/ExprEngine.cpp b/lib/StaticAnalyzer/Core/ExprEngine.cpp
index a077056..89df40f 100644
--- a/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -118,8 +118,8 @@
                                            svalBuilder.makeZeroVal(T),
                                            getContext().IntTy);
 
-      llvm::Optional<DefinedOrUnknownSVal> Constraint =
-        Constraint_untested.getAs<DefinedOrUnknownSVal>();
+      Optional<DefinedOrUnknownSVal> Constraint =
+          Constraint_untested.getAs<DefinedOrUnknownSVal>();
 
       if (!Constraint)
         break;
@@ -138,7 +138,7 @@
     const MemRegion *R = state->getRegion(SelfD, InitLoc);
     SVal V = state->getSVal(loc::MemRegionVal(R));
 
-    if (llvm::Optional<Loc> LV = V.getAs<Loc>()) {
+    if (Optional<Loc> LV = V.getAs<Loc>()) {
       // Assume that the pointer value in 'self' is non-null.
       state = state->assume(*LV, true);
       assert(state && "'self' cannot be null");
@@ -154,7 +154,7 @@
       if (SFC->getParent() == 0) {
         loc::MemRegionVal L = svalBuilder.getCXXThis(MD, SFC);
         SVal V = state->getSVal(L);
-        if (llvm::Optional<Loc> LV = V.getAs<Loc>()) {
+        if (Optional<Loc> LV = V.getAs<Loc>()) {
           state = state->assume(*LV, true);
           assert(state && "'this' cannot be null");
         }
@@ -1328,7 +1328,7 @@
 
   typedef IndirectGotoNodeBuilder::iterator iterator;
 
-  if (llvm::Optional<loc::GotoLabel> LV = V.getAs<loc::GotoLabel>()) {
+  if (Optional<loc::GotoLabel> LV = V.getAs<loc::GotoLabel>()) {
     const LabelDecl *L = LV->getLabel();
 
     for (iterator I = builder.begin(), E = builder.end(); I != E; ++I) {
@@ -1647,8 +1647,7 @@
   bool escapes = true;
 
   // TODO: Move to StoreManager.
-  if (llvm::Optional<loc::MemRegionVal> regionLoc =
-          Loc.getAs<loc::MemRegionVal>()) {
+  if (Optional<loc::MemRegionVal> regionLoc = Loc.getAs<loc::MemRegionVal>()) {
     escapes = !regionLoc->getRegion()->hasStackStorage();
 
     if (!escapes) {
@@ -1779,7 +1778,7 @@
                            Val, /* notifyChanges = */ !atDeclInit);
 
     const MemRegion *LocReg = 0;
-    if (llvm::Optional<loc::MemRegionVal> LocRegVal =
+    if (Optional<loc::MemRegionVal> LocRegVal =
             location.getAs<loc::MemRegionVal>()) {
       LocReg = LocRegVal->getRegion();
     }
@@ -1958,7 +1957,7 @@
 
     ProgramStateRef state = Pred->getState();
     SVal V = state->getSVal(Ex, Pred->getLocationContext());
-    llvm::Optional<nonloc::SymbolVal> SEV = V.getAs<nonloc::SymbolVal>();
+    Optional<nonloc::SymbolVal> SEV = V.getAs<nonloc::SymbolVal>();
     if (SEV && SEV->isExpression()) {
       const std::pair<const ProgramPointTag *, const ProgramPointTag*> &tags =
         geteagerlyAssumeBinOpBifurcationTags();
@@ -2000,7 +1999,7 @@
     SVal X = state->getSVal(*OI, Pred->getLocationContext());
     assert (!X.getAs<NonLoc>());  // Should be an Lval, or unknown, undef.
 
-    if (llvm::Optional<Loc> LV = X.getAs<Loc>())
+    if (Optional<Loc> LV = X.getAs<Loc>())
       state = state->bindLoc(*LV, UnknownVal());
   }
 
diff --git a/lib/StaticAnalyzer/Core/ExprEngineC.cpp b/lib/StaticAnalyzer/Core/ExprEngineC.cpp
index fe132df..b93dfe1 100644
--- a/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ b/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -482,7 +482,7 @@
         // the lazy compound value when the variable is not a reference.
         if (AMgr.getLangOpts().CPlusPlus && VD->getType()->isRecordType() &&
             !VD->getType()->isReferenceType()) {
-          if (llvm::Optional<loc::MemRegionVal> M =
+          if (Optional<loc::MemRegionVal> M =
                   InitVal.getAs<loc::MemRegionVal>()) {
             InitVal = state->getSVal(M->getRegion());
             assert(InitVal.getAs<nonloc::LazyCompoundVal>());
@@ -825,7 +825,7 @@
           //  Note: technically we do "E == 0", but this is the same in the
           //    transfer functions as "0 == E".
           SVal Result;          
-          if (llvm::Optional<Loc> LV = V.getAs<Loc>()) {
+          if (Optional<Loc> LV = V.getAs<Loc>()) {
             Loc X = svalBuilder.makeNull();
             Result = evalBinOp(state, BO_EQ, *LV, X, U->getType());
           }
diff --git a/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp b/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
index 7e86a56..cb3339d 100644
--- a/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ b/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -64,7 +64,7 @@
   SVal V = Call.getArgSVal(0);
 
   // Make sure the value being copied is not unknown.
-  if (llvm::Optional<Loc> L = V.getAs<Loc>())
+  if (Optional<Loc> L = V.getAs<Loc>())
     V = Pred->getState()->getSVal(*L);
 
   evalBind(Dst, CtorExpr, Pred, ThisVal, V, true);
@@ -319,7 +319,7 @@
       (void)ObjTy;
       assert(!ObjTy->isRecordType());
       SVal Location = State->getSVal(CNE, LCtx);
-      if (llvm::Optional<Loc> LV = Location.getAs<Loc>())
+      if (Optional<Loc> LV = Location.getAs<Loc>())
         State = State->bindLoc(*LV, State->getSVal(Init, LCtx));
     }
   }
diff --git a/lib/StaticAnalyzer/Core/ExprEngineObjC.cpp b/lib/StaticAnalyzer/Core/ExprEngineObjC.cpp
index 69a5052..d276d92 100644
--- a/lib/StaticAnalyzer/Core/ExprEngineObjC.cpp
+++ b/lib/StaticAnalyzer/Core/ExprEngineObjC.cpp
@@ -104,8 +104,7 @@
     SVal FalseV = svalBuilder.makeTruthVal(0);
     ProgramStateRef noElems = state->BindExpr(S, LCtx, FalseV);
 
-    if (llvm::Optional<loc::MemRegionVal> MV =
-            elementV.getAs<loc::MemRegionVal>())
+    if (Optional<loc::MemRegionVal> MV = elementV.getAs<loc::MemRegionVal>())
       if (const TypedValueRegion *R = 
           dyn_cast<TypedValueRegion>(MV->getRegion())) {
         // FIXME: The proper thing to do is to really iterate over the
diff --git a/lib/StaticAnalyzer/Core/MemRegion.cpp b/lib/StaticAnalyzer/Core/MemRegion.cpp
index c48343a..922a984 100644
--- a/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ b/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -1044,8 +1044,7 @@
 
     // FIXME: generalize to symbolic offsets.
     SVal index = ER->getIndex();
-    if (llvm::Optional<nonloc::ConcreteInt> CI =
-            index.getAs<nonloc::ConcreteInt>()) {
+    if (Optional<nonloc::ConcreteInt> CI = index.getAs<nonloc::ConcreteInt>()) {
       // Update the offset.
       int64_t i = CI->getValue().getSExtValue();
 
@@ -1172,7 +1171,7 @@
       }
 
       SVal Index = ER->getIndex();
-      if (llvm::Optional<nonloc::ConcreteInt> CI =
+      if (Optional<nonloc::ConcreteInt> CI =
               Index.getAs<nonloc::ConcreteInt>()) {
         // Don't bother calculating precise offsets if we already have a
         // symbolic offset somewhere in the chain. 
diff --git a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
index c723bc8..bbf2db3 100644
--- a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
+++ b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
@@ -213,9 +213,8 @@
   Diags.InsertNode(OwningD.take());
 }
 
-static llvm::Optional<bool> comparePath(const PathPieces &X,
-                                        const PathPieces &Y);
-static llvm::Optional<bool>
+static Optional<bool> comparePath(const PathPieces &X, const PathPieces &Y);
+static Optional<bool>
 compareControlFlow(const PathDiagnosticControlFlowPiece &X,
                    const PathDiagnosticControlFlowPiece &Y) {
   FullSourceLoc XSL = X.getStartLocation().asLocation();
@@ -226,18 +225,16 @@
   FullSourceLoc YEL = Y.getEndLocation().asLocation();
   if (XEL != YEL)
     return XEL.isBeforeInTranslationUnitThan(YEL);
-  return llvm::Optional<bool>();
+  return Optional<bool>();
 }
 
-static llvm::Optional<bool>
-compareMacro(const PathDiagnosticMacroPiece &X,
-             const PathDiagnosticMacroPiece &Y) {
+static Optional<bool> compareMacro(const PathDiagnosticMacroPiece &X,
+                                   const PathDiagnosticMacroPiece &Y) {
   return comparePath(X.subPieces, Y.subPieces);
 }
 
-static llvm::Optional<bool>
-compareCall(const PathDiagnosticCallPiece &X,
-            const PathDiagnosticCallPiece &Y) {
+static Optional<bool> compareCall(const PathDiagnosticCallPiece &X,
+                                  const PathDiagnosticCallPiece &Y) {
   FullSourceLoc X_CEL = X.callEnter.asLocation();
   FullSourceLoc Y_CEL = Y.callEnter.asLocation();
   if (X_CEL != Y_CEL)
@@ -253,8 +250,8 @@
   return comparePath(X.path, Y.path);
 }
 
-static llvm::Optional<bool> comparePiece(const PathDiagnosticPiece &X,
-                                         const PathDiagnosticPiece &Y) {
+static Optional<bool> comparePiece(const PathDiagnosticPiece &X,
+                                   const PathDiagnosticPiece &Y) {
   if (X.getKind() != Y.getKind())
     return X.getKind() < Y.getKind();
   
@@ -286,7 +283,7 @@
       return compareControlFlow(cast<PathDiagnosticControlFlowPiece>(X),
                                 cast<PathDiagnosticControlFlowPiece>(Y));
     case clang::ento::PathDiagnosticPiece::Event:
-      return llvm::Optional<bool>();
+      return Optional<bool>();
     case clang::ento::PathDiagnosticPiece::Macro:
       return compareMacro(cast<PathDiagnosticMacroPiece>(X),
                           cast<PathDiagnosticMacroPiece>(Y));
@@ -297,16 +294,15 @@
   llvm_unreachable("all cases handled");
 }
 
-static llvm::Optional<bool> comparePath(const PathPieces &X,
-                                        const PathPieces &Y) {
+static Optional<bool> comparePath(const PathPieces &X, const PathPieces &Y) {
   if (X.size() != Y.size())
     return X.size() < Y.size();
   for (unsigned i = 0, n = X.size(); i != n; ++i) {
-    llvm::Optional<bool> b = comparePiece(*X[i], *Y[i]);
+    Optional<bool> b = comparePiece(*X[i], *Y[i]);
     if (b.hasValue())
       return b.getValue();
   }
-  return llvm::Optional<bool>();
+  return Optional<bool>();
 }
 
 static bool compare(const PathDiagnostic &X, const PathDiagnostic &Y) {
@@ -344,7 +340,7 @@
     if (*XI != *YI)
       return (*XI) < (*YI);
   }
-  llvm::Optional<bool> b = comparePath(X.path, Y.path);
+  Optional<bool> b = comparePath(X.path, Y.path);
   assert(b.hasValue());
   return b.getValue();
 }
@@ -1029,7 +1025,7 @@
     }
 
     // Check if the parameter is a pointer to the symbol.
-    if (llvm::Optional<loc::MemRegionVal> Reg = SV.getAs<loc::MemRegionVal>()) {
+    if (Optional<loc::MemRegionVal> Reg = SV.getAs<loc::MemRegionVal>()) {
       SVal PSV = State->getSVal(Reg->getRegion());
       SymbolRef AS = PSV.getAsLocSymbol();
       if (AS == Sym) {
diff --git a/lib/StaticAnalyzer/Core/ProgramState.cpp b/lib/StaticAnalyzer/Core/ProgramState.cpp
index 6c76ebf..400569e 100644
--- a/lib/StaticAnalyzer/Core/ProgramState.cpp
+++ b/lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -508,10 +508,10 @@
 }
 
 bool ScanReachableSymbols::scan(SVal val) {
-  if (llvm::Optional<loc::MemRegionVal> X = val.getAs<loc::MemRegionVal>())
+  if (Optional<loc::MemRegionVal> X = val.getAs<loc::MemRegionVal>())
     return scan(X->getRegion());
 
-  if (llvm::Optional<nonloc::LazyCompoundVal> X =
+  if (Optional<nonloc::LazyCompoundVal> X =
           val.getAs<nonloc::LazyCompoundVal>()) {
     StoreManager &StoreMgr = state->getStateManager().getStoreManager();
     // FIXME: We don't really want to use getBaseRegion() here because pointer
@@ -523,8 +523,7 @@
       return false;
   }
 
-  if (llvm::Optional<nonloc::LocAsInteger> X =
-          val.getAs<nonloc::LocAsInteger>())
+  if (Optional<nonloc::LocAsInteger> X = val.getAs<nonloc::LocAsInteger>())
     return scan(X->getLoc());
 
   if (SymbolRef Sym = val.getAsSymbol())
@@ -533,7 +532,7 @@
   if (const SymExpr *Sym = val.getAsSymbolicExpression())
     return scan(Sym);
 
-  if (llvm::Optional<nonloc::CompoundVal> X = val.getAs<nonloc::CompoundVal>())
+  if (Optional<nonloc::CompoundVal> X = val.getAs<nonloc::CompoundVal>())
     return scan(*X);
 
   return true;
diff --git a/lib/StaticAnalyzer/Core/RegionStore.cpp b/lib/StaticAnalyzer/Core/RegionStore.cpp
index b5e31d2..799022e 100644
--- a/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ b/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -30,7 +30,6 @@
 
 using namespace clang;
 using namespace ento;
-using llvm::Optional;
 
 //===----------------------------------------------------------------------===//
 // Representation of binding keys.
@@ -753,7 +752,7 @@
   // be using this function anyway.
   uint64_t Length = UINT64_MAX;
   SVal Extent = Top->getExtent(SVB);
-  if (llvm::Optional<nonloc::ConcreteInt> ExtentCI =
+  if (Optional<nonloc::ConcreteInt> ExtentCI =
           Extent.getAs<nonloc::ConcreteInt>()) {
     const llvm::APSInt &ExtentInt = ExtentCI->getValue();
     assert(ExtentInt.isNonNegative() || ExtentInt.isUnsigned());
@@ -894,7 +893,7 @@
   }
 
   // Is it a LazyCompoundVal?  All references get invalidated as well.
-  if (llvm::Optional<nonloc::LazyCompoundVal> LCS =
+  if (Optional<nonloc::LazyCompoundVal> LCS =
           V.getAs<nonloc::LazyCompoundVal>()) {
 
     const RegionStoreManager::SValListTy &Vals = RM.getInterestingValues(*LCS);
@@ -939,7 +938,7 @@
         // a pointer value, but the thing pointed by that pointer may
         // get invalidated.
         SVal V = RM.getBinding(B, loc::MemRegionVal(VR));
-        if (llvm::Optional<Loc> L = V.getAs<Loc>()) {
+        if (Optional<Loc> L = V.getAs<Loc>()) {
           if (const MemRegion *LR = L->getAsRegion())
             AddToWorkList(LR);
         }
@@ -1264,7 +1263,7 @@
 
   if (originalRegion != R) {
     if (Optional<SVal> OV = B.getDefaultBinding(R)) {
-      if (llvm::Optional<nonloc::LazyCompoundVal> V =
+      if (Optional<nonloc::LazyCompoundVal> V =
               OV->getAs<nonloc::LazyCompoundVal>())
         return std::make_pair(V->getStore(), V->getRegion());
     }
@@ -1346,8 +1345,7 @@
 
     const StringLiteral *Str = StrR->getStringLiteral();
     SVal Idx = R->getIndex();
-    if (llvm::Optional<nonloc::ConcreteInt> CI =
-            Idx.getAs<nonloc::ConcreteInt>()) {
+    if (Optional<nonloc::ConcreteInt> CI = Idx.getAs<nonloc::ConcreteInt>()) {
       int64_t i = CI->getValue().getSExtValue();
       // Abort on string underrun.  This can be possible by arbitrary
       // clients of getBindingForElement().
@@ -1652,7 +1650,7 @@
     if (V.isUnknownOrUndef() || V.isConstant())
       continue;
 
-    if (llvm::Optional<nonloc::LazyCompoundVal> InnerLCV =
+    if (Optional<nonloc::LazyCompoundVal> InnerLCV =
             V.getAs<nonloc::LazyCompoundVal>()) {
       const SValListTy &InnerList = getInterestingValues(*InnerLCV);
       List.insert(List.end(), InnerList.begin(), InnerList.end());
@@ -1670,7 +1668,7 @@
   // If we already have a lazy binding, and it's for the whole structure,
   // don't create a new lazy binding.
   if (Optional<SVal> V = B.getDefaultBinding(R)) {
-    if (llvm::Optional<nonloc::LazyCompoundVal> LCV =
+    if (Optional<nonloc::LazyCompoundVal> LCV =
             V->getAs<nonloc::LazyCompoundVal>()) {
       QualType RegionTy = R->getValueType();
       QualType SourceRegionTy = LCV->getRegion()->getValueType();
@@ -1728,7 +1726,7 @@
 //===----------------------------------------------------------------------===//
 
 StoreRef RegionStoreManager::killBinding(Store ST, Loc L) {
-  if (llvm::Optional<loc::MemRegionVal> LV = L.getAs<loc::MemRegionVal>())
+  if (Optional<loc::MemRegionVal> LV = L.getAs<loc::MemRegionVal>())
     if (const MemRegion* R = LV->getRegion())
       return StoreRef(getRegionBindings(ST).removeBinding(R)
                                            .asImmutableMap()
@@ -1820,7 +1818,7 @@
     Size = CAT->getSize().getZExtValue();
 
   // Check if the init expr is a string literal.
-  if (llvm::Optional<loc::MemRegionVal> MRV = Init.getAs<loc::MemRegionVal>()) {
+  if (Optional<loc::MemRegionVal> MRV = Init.getAs<loc::MemRegionVal>()) {
     const StringRegion *S = cast<StringRegion>(MRV->getRegion());
 
     // Treat the string as a lazy compound value.
@@ -2057,7 +2055,7 @@
 
 void removeDeadBindingsWorker::VisitBinding(SVal V) {
   // Is it a LazyCompoundVal?  All referenced regions are live as well.
-  if (llvm::Optional<nonloc::LazyCompoundVal> LCS =
+  if (Optional<nonloc::LazyCompoundVal> LCS =
           V.getAs<nonloc::LazyCompoundVal>()) {
 
     const RegionStoreManager::SValListTy &Vals = RM.getInterestingValues(*LCS);
diff --git a/lib/StaticAnalyzer/Core/SValBuilder.cpp b/lib/StaticAnalyzer/Core/SValBuilder.cpp
index d099a8f..c72e780 100644
--- a/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ b/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -78,8 +78,7 @@
     return val;
 
   // Common case: we have an appropriately sized integer.
-  if (llvm::Optional<nonloc::ConcreteInt> CI =
-          val.getAs<nonloc::ConcreteInt>()) {
+  if (Optional<nonloc::ConcreteInt> CI = val.getAs<nonloc::ConcreteInt>()) {
     const llvm::APSInt& I = CI->getValue();
     if (I.getBitWidth() == ArrayIndexWidth && I.isSigned())
       return val;
@@ -238,13 +237,11 @@
     return makeNonLoc(symLHS, Op, symRHS, ResultTy);
 
   if (symLHS && symLHS->computeComplexity() < MaxComp)
-    if (llvm::Optional<nonloc::ConcreteInt> rInt =
-            RHS.getAs<nonloc::ConcreteInt>())
+    if (Optional<nonloc::ConcreteInt> rInt = RHS.getAs<nonloc::ConcreteInt>())
       return makeNonLoc(symLHS, Op, rInt->getValue(), ResultTy);
 
   if (symRHS && symRHS->computeComplexity() < MaxComp)
-    if (llvm::Optional<nonloc::ConcreteInt> lInt =
-            LHS.getAs<nonloc::ConcreteInt>())
+    if (Optional<nonloc::ConcreteInt> lInt = LHS.getAs<nonloc::ConcreteInt>())
       return makeNonLoc(lInt->getValue(), Op, symRHS, ResultTy);
 
   return UnknownVal();
@@ -260,14 +257,14 @@
   if (lhs.isUnknown() || rhs.isUnknown())
     return UnknownVal();
 
-  if (llvm::Optional<Loc> LV = lhs.getAs<Loc>()) {
-    if (llvm::Optional<Loc> RV = rhs.getAs<Loc>())
+  if (Optional<Loc> LV = lhs.getAs<Loc>()) {
+    if (Optional<Loc> RV = rhs.getAs<Loc>())
       return evalBinOpLL(state, op, *LV, *RV, type);
 
     return evalBinOpLN(state, op, *LV, rhs.castAs<NonLoc>(), type);
   }
 
-  if (llvm::Optional<Loc> RV = rhs.getAs<Loc>()) {
+  if (Optional<Loc> RV = rhs.getAs<Loc>()) {
     // Support pointer arithmetic where the addend is on the left
     // and the pointer on the right.
     assert(op == BO_Add);
@@ -335,8 +332,7 @@
 
   // Check for casts from integers to pointers.
   if (Loc::isLocType(castTy) && originalTy->isIntegerType()) {
-    if (llvm::Optional<nonloc::LocAsInteger> LV =
-            val.getAs<nonloc::LocAsInteger>()) {
+    if (Optional<nonloc::LocAsInteger> LV = val.getAs<nonloc::LocAsInteger>()) {
       if (const MemRegion *R = LV->getLoc().getAsRegion()) {
         StoreManager &storeMgr = StateMgr.getStoreManager();
         R = storeMgr.castRegion(R, castTy);
diff --git a/lib/StaticAnalyzer/Core/SVals.cpp b/lib/StaticAnalyzer/Core/SVals.cpp
index 72959f5..da52a90 100644
--- a/lib/StaticAnalyzer/Core/SVals.cpp
+++ b/lib/StaticAnalyzer/Core/SVals.cpp
@@ -30,13 +30,13 @@
 //===----------------------------------------------------------------------===//
 
 bool SVal::hasConjuredSymbol() const {
-  if (llvm::Optional<nonloc::SymbolVal> SV = getAs<nonloc::SymbolVal>()) {
+  if (Optional<nonloc::SymbolVal> SV = getAs<nonloc::SymbolVal>()) {
     SymbolRef sym = SV->getSymbol();
     if (isa<SymbolConjured>(sym))
       return true;
   }
 
-  if (llvm::Optional<loc::MemRegionVal> RV = getAs<loc::MemRegionVal>()) {
+  if (Optional<loc::MemRegionVal> RV = getAs<loc::MemRegionVal>()) {
     const MemRegion *R = RV->getRegion();
     if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(R)) {
       SymbolRef sym = SR->getSymbol();
@@ -49,7 +49,7 @@
 }
 
 const FunctionDecl *SVal::getAsFunctionDecl() const {
-  if (llvm::Optional<loc::MemRegionVal> X = getAs<loc::MemRegionVal>()) {
+  if (Optional<loc::MemRegionVal> X = getAs<loc::MemRegionVal>()) {
     const MemRegion* R = X->getRegion();
     if (const FunctionTextRegion *CTR = R->getAs<FunctionTextRegion>())
       if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CTR->getDecl()))
@@ -66,10 +66,10 @@
 /// region. If that is the case, gets the underlining region.
 SymbolRef SVal::getAsLocSymbol() const {
   // FIXME: should we consider SymbolRef wrapped in CodeTextRegion?
-  if (llvm::Optional<nonloc::LocAsInteger> X = getAs<nonloc::LocAsInteger>())
+  if (Optional<nonloc::LocAsInteger> X = getAs<nonloc::LocAsInteger>())
     return X->getLoc().getAsLocSymbol();
 
-  if (llvm::Optional<loc::MemRegionVal> X = getAs<loc::MemRegionVal>()) {
+  if (Optional<loc::MemRegionVal> X = getAs<loc::MemRegionVal>()) {
     const MemRegion *R = X->stripCasts();
     if (const SymbolicRegion *SymR = dyn_cast<SymbolicRegion>(R))
       return SymR->getSymbol();
@@ -79,7 +79,7 @@
 
 /// Get the symbol in the SVal or its base region.
 SymbolRef SVal::getLocSymbolInBase() const {
-  llvm::Optional<loc::MemRegionVal> X = getAs<loc::MemRegionVal>();
+  Optional<loc::MemRegionVal> X = getAs<loc::MemRegionVal>();
 
   if (!X)
     return 0;
@@ -102,7 +102,7 @@
 ///  Otherwise return 0.
 SymbolRef SVal::getAsSymbol() const {
   // FIXME: should we consider SymbolRef wrapped in CodeTextRegion?
-  if (llvm::Optional<nonloc::SymbolVal> X = getAs<nonloc::SymbolVal>())
+  if (Optional<nonloc::SymbolVal> X = getAs<nonloc::SymbolVal>())
     return X->getSymbol();
 
   return getAsLocSymbol();
@@ -111,7 +111,7 @@
 /// getAsSymbolicExpression - If this Sval wraps a symbolic expression then
 ///  return that expression.  Otherwise return NULL.
 const SymExpr *SVal::getAsSymbolicExpression() const {
-  if (llvm::Optional<nonloc::SymbolVal> X = getAs<nonloc::SymbolVal>())
+  if (Optional<nonloc::SymbolVal> X = getAs<nonloc::SymbolVal>())
     return X->getSymbol();
 
   return getAsSymbol();
@@ -125,10 +125,10 @@
 }
 
 const MemRegion *SVal::getAsRegion() const {
-  if (llvm::Optional<loc::MemRegionVal> X = getAs<loc::MemRegionVal>())
+  if (Optional<loc::MemRegionVal> X = getAs<loc::MemRegionVal>())
     return X->getRegion();
 
-  if (llvm::Optional<nonloc::LocAsInteger> X = getAs<nonloc::LocAsInteger>())
+  if (Optional<nonloc::LocAsInteger> X = getAs<nonloc::LocAsInteger>())
     return X->getLoc().getAsRegion();
 
   return 0;
@@ -168,9 +168,9 @@
 }
 
 bool SVal::isConstant(int I) const {
-  if (llvm::Optional<loc::ConcreteInt> LV = getAs<loc::ConcreteInt>())
+  if (Optional<loc::ConcreteInt> LV = getAs<loc::ConcreteInt>())
     return LV->getValue() == I;
-  if (llvm::Optional<nonloc::ConcreteInt> NV = getAs<nonloc::ConcreteInt>())
+  if (Optional<nonloc::ConcreteInt> NV = getAs<nonloc::ConcreteInt>())
     return NV->getValue() == I;
   return false;
 }
diff --git a/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp b/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
index 3838830..de13241 100644
--- a/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
+++ b/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
@@ -24,7 +24,7 @@
 SimpleConstraintManager::~SimpleConstraintManager() {}
 
 bool SimpleConstraintManager::canReasonAbout(SVal X) const {
-  llvm::Optional<nonloc::SymbolVal> SymVal = X.getAs<nonloc::SymbolVal>();
+  Optional<nonloc::SymbolVal> SymVal = X.getAs<nonloc::SymbolVal>();
   if (SymVal && SymVal->isExpression()) {
     const SymExpr *SE = SymVal->getSymbol();
 
@@ -58,7 +58,7 @@
 ProgramStateRef SimpleConstraintManager::assume(ProgramStateRef state,
                                                DefinedSVal Cond,
                                                bool Assumption) {
-  if (llvm::Optional<NonLoc> NV = Cond.getAs<NonLoc>())
+  if (Optional<NonLoc> NV = Cond.getAs<NonLoc>())
     return assume(state, *NV, Assumption);
   return assume(state, Cond.castAs<Loc>(), Assumption);
 }
diff --git a/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp b/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
index 080e81d..3e50c33 100644
--- a/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ b/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -69,8 +69,7 @@
 
   bool isLocType = Loc::isLocType(castTy);
 
-  if (llvm::Optional<nonloc::LocAsInteger> LI =
-          val.getAs<nonloc::LocAsInteger>()) {
+  if (Optional<nonloc::LocAsInteger> LI = val.getAs<nonloc::LocAsInteger>()) {
     if (isLocType)
       return LI->getLoc();
 
@@ -607,10 +606,10 @@
     }
 
     // If both operands are constants, just perform the operation.
-    if (llvm::Optional<loc::ConcreteInt> rInt = rhs.getAs<loc::ConcreteInt>()) {
+    if (Optional<loc::ConcreteInt> rInt = rhs.getAs<loc::ConcreteInt>()) {
       SVal ResultVal =
           lhs.castAs<loc::ConcreteInt>().evalBinOp(BasicVals, op, *rInt);
-      if (llvm::Optional<Loc> Result = ResultVal.getAs<Loc>())
+      if (Optional<Loc> Result = ResultVal.getAs<Loc>())
         return evalCastFromLoc(*Result, resultTy);
       else
         return UnknownVal();
@@ -641,7 +640,7 @@
     return UnknownVal();
   }
   case loc::MemRegionKind: {
-    if (llvm::Optional<loc::ConcreteInt> rInt = rhs.getAs<loc::ConcreteInt>()) {
+    if (Optional<loc::ConcreteInt> rInt = rhs.getAs<loc::ConcreteInt>()) {
       // If one of the operands is a symbol and the other is a constant,
       // build an expression for use by the constraint manager.
       if (SymbolRef lSym = lhs.getAsLocSymbol())
@@ -739,7 +738,7 @@
         // Get the left index and cast it to the correct type.
         // If the index is unknown or undefined, bail out here.
         SVal LeftIndexVal = LeftER->getIndex();
-        llvm::Optional<NonLoc> LeftIndex = LeftIndexVal.getAs<NonLoc>();
+        Optional<NonLoc> LeftIndex = LeftIndexVal.getAs<NonLoc>();
         if (!LeftIndex)
           return UnknownVal();
         LeftIndexVal = evalCastFromNonLoc(*LeftIndex, ArrayIndexTy);
@@ -749,7 +748,7 @@
 
         // Do the same for the right index.
         SVal RightIndexVal = RightER->getIndex();
-        llvm::Optional<NonLoc> RightIndex = RightIndexVal.getAs<NonLoc>();
+        Optional<NonLoc> RightIndex = RightIndexVal.getAs<NonLoc>();
         if (!RightIndex)
           return UnknownVal();
         RightIndexVal = evalCastFromNonLoc(*RightIndex, ArrayIndexTy);
@@ -863,7 +862,7 @@
   // can generate comparisons that trigger this code.
   // FIXME: Are all locations guaranteed to have pointer width?
   if (BinaryOperator::isComparisonOp(op)) {
-    if (llvm::Optional<nonloc::ConcreteInt> rhsInt =
+    if (Optional<nonloc::ConcreteInt> rhsInt =
             rhs.getAs<nonloc::ConcreteInt>()) {
       const llvm::APSInt *x = &rhsInt->getValue();
       ASTContext &ctx = Context;
@@ -881,10 +880,8 @@
   // We are dealing with pointer arithmetic.
 
   // Handle pointer arithmetic on constant values.
-  if (llvm::Optional<nonloc::ConcreteInt> rhsInt =
-          rhs.getAs<nonloc::ConcreteInt>()) {
-    if (llvm::Optional<loc::ConcreteInt> lhsInt =
-            lhs.getAs<loc::ConcreteInt>()) {
+  if (Optional<nonloc::ConcreteInt> rhsInt = rhs.getAs<nonloc::ConcreteInt>()) {
+    if (Optional<loc::ConcreteInt> lhsInt = lhs.getAs<loc::ConcreteInt>()) {
       const llvm::APSInt &leftI = lhsInt->getValue();
       assert(leftI.isUnsigned());
       llvm::APSInt rightI(rhsInt->getValue(), /* isUnsigned */ true);
@@ -933,7 +930,7 @@
         elementType = resultTy->getPointeeType();
     }
 
-    if (llvm::Optional<NonLoc> indexV = index.getAs<NonLoc>()) {
+    if (Optional<NonLoc> indexV = index.getAs<NonLoc>()) {
       return loc::MemRegionVal(MemMgr.getElementRegion(elementType, *indexV,
                                                        superR, getContext()));
     }
@@ -946,10 +943,10 @@
   if (V.isUnknownOrUndef())
     return NULL;
 
-  if (llvm::Optional<loc::ConcreteInt> X = V.getAs<loc::ConcreteInt>())
+  if (Optional<loc::ConcreteInt> X = V.getAs<loc::ConcreteInt>())
     return &X->getValue();
 
-  if (llvm::Optional<nonloc::ConcreteInt> X = V.getAs<nonloc::ConcreteInt>())
+  if (Optional<nonloc::ConcreteInt> X = V.getAs<nonloc::ConcreteInt>())
     return &X->getValue();
 
   if (SymbolRef Sym = V.getAsSymbol())
diff --git a/lib/StaticAnalyzer/Core/Store.cpp b/lib/StaticAnalyzer/Core/Store.cpp
index 5177d0e..3695cbc 100644
--- a/lib/StaticAnalyzer/Core/Store.cpp
+++ b/lib/StaticAnalyzer/Core/Store.cpp
@@ -270,7 +270,7 @@
 }
 
 SVal StoreManager::evalDerivedToBase(SVal Derived, QualType BaseType) {
-  llvm::Optional<loc::MemRegionVal> DerivedRegVal =
+  Optional<loc::MemRegionVal> DerivedRegVal =
       Derived.getAs<loc::MemRegionVal>();
   if (!DerivedRegVal)
     return Derived;
@@ -290,8 +290,7 @@
                                    bool &Failed) {
   Failed = false;
 
-  llvm::Optional<loc::MemRegionVal> BaseRegVal =
-      Base.getAs<loc::MemRegionVal>();
+  Optional<loc::MemRegionVal> BaseRegVal = Base.getAs<loc::MemRegionVal>();
   if (!BaseRegVal)
     return UnknownVal();
   const MemRegion *BaseRegion = BaseRegVal->stripCasts(/*StripBases=*/false);