Keep the source range of attributes. Depends on a llvm tablegen commit.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139600 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/AST/Attr.h b/include/clang/AST/Attr.h
index 7d57cd8..2f0eafa 100644
--- a/include/clang/AST/Attr.h
+++ b/include/clang/AST/Attr.h
@@ -109,8 +109,8 @@
 
 class InheritableAttr : public Attr {
 protected:
-  InheritableAttr(attr::Kind AK, SourceLocation L)
-    : Attr(AK, L) {}
+  InheritableAttr(attr::Kind AK, SourceRange R)
+    : Attr(AK, R) {}
 
 public:
   void setInherited(bool I) { Inherited = I; }
@@ -124,8 +124,8 @@
 
 class InheritableParamAttr : public InheritableAttr {
 protected:
-  InheritableParamAttr(attr::Kind AK, SourceLocation L)
-    : InheritableAttr(AK, L) {}
+  InheritableParamAttr(attr::Kind AK, SourceRange R)
+    : InheritableAttr(AK, R) {}
 
 public:
   // Implement isa/cast/dyncast/etc.
diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h
index 29c7141..c082444 100644
--- a/include/clang/Sema/Sema.h
+++ b/include/clang/Sema/Sema.h
@@ -5388,8 +5388,8 @@
   void FreeVisContext();
 
   /// AddAlignedAttr - Adds an aligned attribute to a particular declaration.
-  void AddAlignedAttr(SourceLocation AttrLoc, Decl *D, Expr *E);
-  void AddAlignedAttr(SourceLocation AttrLoc, Decl *D, TypeSourceInfo *T);
+  void AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E);
+  void AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *T);
 
   /// CastCategory - Get the correct forwarded implicit cast result category
   /// from the inner expression.
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index fc85832..7c7e3ab 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -368,9 +368,9 @@
     return;
 
   if (pointer)
-    D->addAttr(::new (S.Context) PtGuardedVarAttr(Attr.getLoc(), S.Context));
+    D->addAttr(::new (S.Context) PtGuardedVarAttr(Attr.getRange(), S.Context));
   else
-    D->addAttr(::new (S.Context) GuardedVarAttr(Attr.getLoc(), S.Context));
+    D->addAttr(::new (S.Context) GuardedVarAttr(Attr.getRange(), S.Context));
 }
 
 static void handleGuardedByAttr(Sema &S, Decl *D, const AttributeList &Attr,
@@ -401,10 +401,10 @@
     return;
 
   if (pointer)
-    D->addAttr(::new (S.Context) PtGuardedByAttr(Attr.getLoc(),
+    D->addAttr(::new (S.Context) PtGuardedByAttr(Attr.getRange(),
                                                  S.Context, Arg));
   else
-    D->addAttr(::new (S.Context) GuardedByAttr(Attr.getLoc(), S.Context, Arg));
+    D->addAttr(::new (S.Context) GuardedByAttr(Attr.getRange(), S.Context, Arg));
 }
 
 
@@ -422,9 +422,9 @@
   }
 
   if (scoped)
-    D->addAttr(::new (S.Context) ScopedLockableAttr(Attr.getLoc(), S.Context));
+    D->addAttr(::new (S.Context) ScopedLockableAttr(Attr.getRange(), S.Context));
   else
-    D->addAttr(::new (S.Context) LockableAttr(Attr.getLoc(), S.Context));
+    D->addAttr(::new (S.Context) LockableAttr(Attr.getRange(), S.Context));
 }
 
 static void handleNoThreadSafetyAttr(Sema &S, Decl *D,
@@ -440,7 +440,7 @@
     return;
   }
 
-  D->addAttr(::new (S.Context) NoThreadSafetyAnalysisAttr(Attr.getLoc(),
+  D->addAttr(::new (S.Context) NoThreadSafetyAnalysisAttr(Attr.getRange(),
                                                           S.Context));
 }
 
@@ -480,10 +480,10 @@
   Expr **StartArg = Size == 0 ? 0 : &Args[0];
 
   if (before)
-    D->addAttr(::new (S.Context) AcquiredBeforeAttr(Attr.getLoc(), S.Context,
+    D->addAttr(::new (S.Context) AcquiredBeforeAttr(Attr.getRange(), S.Context,
                                                     StartArg, Size));
   else
-    D->addAttr(::new (S.Context) AcquiredAfterAttr(Attr.getLoc(), S.Context,
+    D->addAttr(::new (S.Context) AcquiredAfterAttr(Attr.getRange(), S.Context,
                                                    StartArg, Size));
 }
 
@@ -510,11 +510,11 @@
   Expr **StartArg = Size == 0 ? 0 : &Args[0];
 
   if (exclusive)
-    D->addAttr(::new (S.Context) ExclusiveLockFunctionAttr(Attr.getLoc(),
+    D->addAttr(::new (S.Context) ExclusiveLockFunctionAttr(Attr.getRange(),
                                                            S.Context, StartArg,
                                                            Size));
   else
-    D->addAttr(::new (S.Context) SharedLockFunctionAttr(Attr.getLoc(),
+    D->addAttr(::new (S.Context) SharedLockFunctionAttr(Attr.getRange(),
                                                         S.Context, StartArg,
                                                         Size));
 }
@@ -550,11 +550,11 @@
   Expr **StartArg = Size == 0 ? 0 : &Args[0];
 
   if (exclusive)
-    D->addAttr(::new (S.Context) ExclusiveTrylockFunctionAttr(Attr.getLoc(),
+    D->addAttr(::new (S.Context) ExclusiveTrylockFunctionAttr(Attr.getRange(),
                                                               S.Context,
                                                               StartArg, Size));
   else
-    D->addAttr(::new (S.Context) SharedTrylockFunctionAttr(Attr.getLoc(),
+    D->addAttr(::new (S.Context) SharedTrylockFunctionAttr(Attr.getRange(),
                                                            S.Context, StartArg,
                                                            Size));
 }
@@ -582,11 +582,11 @@
   Expr **StartArg = Size == 0 ? 0 : &Args[0];
 
   if (exclusive)
-    D->addAttr(::new (S.Context) ExclusiveLocksRequiredAttr(Attr.getLoc(),
+    D->addAttr(::new (S.Context) ExclusiveLocksRequiredAttr(Attr.getRange(),
                                                             S.Context, StartArg,
                                                             Size));
   else
-    D->addAttr(::new (S.Context) SharedLocksRequiredAttr(Attr.getLoc(),
+    D->addAttr(::new (S.Context) SharedLocksRequiredAttr(Attr.getRange(),
                                                          S.Context, StartArg,
                                                          Size));
 }
@@ -612,7 +612,7 @@
   assert(Size == Attr.getNumArgs());
   Expr **StartArg = Size == 0 ? 0 : &Args[0];
 
-  D->addAttr(::new (S.Context) UnlockFunctionAttr(Attr.getLoc(), S.Context,
+  D->addAttr(::new (S.Context) UnlockFunctionAttr(Attr.getRange(), S.Context,
                                                   StartArg, Size));
 }
 
@@ -637,7 +637,7 @@
   if (!checkForLockableRecord(S, D, Attr, getRecordType(Arg->getType())))
     return;
 
-  D->addAttr(::new (S.Context) LockReturnedAttr(Attr.getLoc(), S.Context, Arg));
+  D->addAttr(::new (S.Context) LockReturnedAttr(Attr.getRange(), S.Context, Arg));
 }
 
 static void handleLocksExcludedAttr(Sema &S, Decl *D,
@@ -662,7 +662,7 @@
   assert(Size == Attr.getNumArgs());
   Expr **StartArg = Size == 0 ? 0 : &Args[0];
 
-  D->addAttr(::new (S.Context) LocksExcludedAttr(Attr.getLoc(), S.Context,
+  D->addAttr(::new (S.Context) LocksExcludedAttr(Attr.getRange(), S.Context,
                                                  StartArg, Size));
 }
 
@@ -716,7 +716,7 @@
     return;
 
   if (TagDecl *TD = dyn_cast<TagDecl>(D))
-    TD->addAttr(::new (S.Context) PackedAttr(Attr.getLoc(), S.Context));
+    TD->addAttr(::new (S.Context) PackedAttr(Attr.getRange(), S.Context));
   else if (FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
     // If the alignment is less than or equal to 8 bits, the packed attribute
     // has no effect.
@@ -725,14 +725,14 @@
       S.Diag(Attr.getLoc(), diag::warn_attribute_ignored_for_field_of_type)
         << Attr.getName() << FD->getType();
     else
-      FD->addAttr(::new (S.Context) PackedAttr(Attr.getLoc(), S.Context));
+      FD->addAttr(::new (S.Context) PackedAttr(Attr.getRange(), S.Context));
   } else
     S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
 }
 
 static void handleMsStructAttr(Sema &S, Decl *D, const AttributeList &Attr) {
   if (TagDecl *TD = dyn_cast<TagDecl>(D))
-    TD->addAttr(::new (S.Context) MsStructAttr(Attr.getLoc(), S.Context));
+    TD->addAttr(::new (S.Context) MsStructAttr(Attr.getRange(), S.Context));
   else
     S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
 }
@@ -745,7 +745,7 @@
   // The IBAction attributes only apply to instance methods.
   if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
     if (MD->isInstanceMethod()) {
-      D->addAttr(::new (S.Context) IBActionAttr(Attr.getLoc(), S.Context));
+      D->addAttr(::new (S.Context) IBActionAttr(Attr.getRange(), S.Context));
       return;
     }
 
@@ -760,7 +760,7 @@
   // The IBOutlet attributes only apply to instance variables of
   // Objective-C classes.
   if (isa<ObjCIvarDecl>(D) || isa<ObjCPropertyDecl>(D)) {
-    D->addAttr(::new (S.Context) IBOutletAttr(Attr.getLoc(), S.Context));
+    D->addAttr(::new (S.Context) IBOutletAttr(Attr.getRange(), S.Context));
     return;
   }
 
@@ -815,7 +815,7 @@
     S.Diag(Attr.getLoc(), diag::err_iboutletcollection_type) << II;
     return;
   }
-  D->addAttr(::new (S.Context) IBOutletCollectionAttr(Attr.getLoc(), S.Context,
+  D->addAttr(::new (S.Context) IBOutletCollectionAttr(Attr.getRange(), S.Context,
                                                       QT));
 }
 
@@ -921,7 +921,7 @@
   unsigned* start = &NonNullArgs[0];
   unsigned size = NonNullArgs.size();
   llvm::array_pod_sort(start, start + size);
-  D->addAttr(::new (S.Context) NonNullAttr(Attr.getLoc(), S.Context, start,
+  D->addAttr(::new (S.Context) NonNullAttr(Attr.getRange(), S.Context, start,
                                            size));
 }
 
@@ -1174,11 +1174,11 @@
     }
     // GCC will accept anything as the argument of weakref. Should we
     // check for an existing decl?
-    D->addAttr(::new (S.Context) AliasAttr(Attr.getLoc(), S.Context,
+    D->addAttr(::new (S.Context) AliasAttr(Attr.getRange(), S.Context,
                                            Str->getString()));
   }
 
-  D->addAttr(::new (S.Context) WeakRefAttr(Attr.getLoc(), S.Context));
+  D->addAttr(::new (S.Context) WeakRefAttr(Attr.getRange(), S.Context));
 }
 
 static void handleAliasAttr(Sema &S, Decl *D, const AttributeList &Attr) {
@@ -1205,7 +1205,7 @@
 
   // FIXME: check if target symbol exists in current file
 
-  D->addAttr(::new (S.Context) AliasAttr(Attr.getLoc(), S.Context,
+  D->addAttr(::new (S.Context) AliasAttr(Attr.getRange(), S.Context,
                                          Str->getString()));
 }
 
@@ -1220,7 +1220,7 @@
     return;
   }
 
-  D->addAttr(::new (S.Context) NakedAttr(Attr.getLoc(), S.Context));
+  D->addAttr(::new (S.Context) NakedAttr(Attr.getRange(), S.Context));
 }
 
 static void handleAlwaysInlineAttr(Sema &S, Decl *D,
@@ -1237,7 +1237,7 @@
     return;
   }
 
-  D->addAttr(::new (S.Context) AlwaysInlineAttr(Attr.getLoc(), S.Context));
+  D->addAttr(::new (S.Context) AlwaysInlineAttr(Attr.getRange(), S.Context));
 }
 
 static void handleMallocAttr(Sema &S, Decl *D, const AttributeList &Attr) {
@@ -1250,7 +1250,7 @@
   if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
     QualType RetTy = FD->getResultType();
     if (RetTy->isAnyPointerType() || RetTy->isBlockPointerType()) {
-      D->addAttr(::new (S.Context) MallocAttr(Attr.getLoc(), S.Context));
+      D->addAttr(::new (S.Context) MallocAttr(Attr.getRange(), S.Context));
       return;
     }
   }
@@ -1263,13 +1263,13 @@
   if (!checkAttributeNumArgs(S, Attr, 0))
     return;
 
-  D->addAttr(::new (S.Context) MayAliasAttr(Attr.getLoc(), S.Context));
+  D->addAttr(::new (S.Context) MayAliasAttr(Attr.getRange(), S.Context));
 }
 
 static void handleNoCommonAttr(Sema &S, Decl *D, const AttributeList &Attr) {
   assert(!Attr.isInvalid());
   if (isa<VarDecl>(D))
-    D->addAttr(::new (S.Context) NoCommonAttr(Attr.getLoc(), S.Context));
+    D->addAttr(::new (S.Context) NoCommonAttr(Attr.getRange(), S.Context));
   else
     S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
       << Attr.getName() << ExpectedVariable;
@@ -1278,7 +1278,7 @@
 static void handleCommonAttr(Sema &S, Decl *D, const AttributeList &Attr) {
   assert(!Attr.isInvalid());
   if (isa<VarDecl>(D))
-    D->addAttr(::new (S.Context) CommonAttr(Attr.getLoc(), S.Context));
+    D->addAttr(::new (S.Context) CommonAttr(Attr.getRange(), S.Context));
   else
     S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
       << Attr.getName() << ExpectedVariable;
@@ -1295,7 +1295,7 @@
     return;
   }
 
-  D->addAttr(::new (S.Context) NoReturnAttr(attr.getLoc(), S.Context));
+  D->addAttr(::new (S.Context) NoReturnAttr(attr.getRange(), S.Context));
 }
 
 bool Sema::CheckNoReturnAttr(const AttributeList &attr) {
@@ -1329,7 +1329,7 @@
     }
   }
   
-  D->addAttr(::new (S.Context) AnalyzerNoReturnAttr(Attr.getLoc(), S.Context));
+  D->addAttr(::new (S.Context) AnalyzerNoReturnAttr(Attr.getRange(), S.Context));
 }
 
 // PS3 PPU-specific.
@@ -1390,7 +1390,7 @@
     count++;
   }
 
-  D->addAttr(::new (S.Context) VecReturnAttr(Attr.getLoc(), S.Context));
+  D->addAttr(::new (S.Context) VecReturnAttr(Attr.getRange(), S.Context));
 }
 
 static void handleDependencyAttr(Sema &S, Decl *D, const AttributeList &Attr) {
@@ -1416,7 +1416,7 @@
     return;
   }
 
-  D->addAttr(::new (S.Context) UnusedAttr(Attr.getLoc(), S.Context));
+  D->addAttr(::new (S.Context) UnusedAttr(Attr.getRange(), S.Context));
 }
 
 static void handleUsedAttr(Sema &S, Decl *D, const AttributeList &Attr) {
@@ -1437,7 +1437,7 @@
     return;
   }
 
-  D->addAttr(::new (S.Context) UsedAttr(Attr.getLoc(), S.Context));
+  D->addAttr(::new (S.Context) UsedAttr(Attr.getRange(), S.Context));
 }
 
 static void handleConstructorAttr(Sema &S, Decl *D, const AttributeList &Attr) {
@@ -1466,7 +1466,7 @@
     return;
   }
 
-  D->addAttr(::new (S.Context) ConstructorAttr(Attr.getLoc(), S.Context,
+  D->addAttr(::new (S.Context) ConstructorAttr(Attr.getRange(), S.Context,
                                                priority));
 }
 
@@ -1496,7 +1496,7 @@
     return;
   }
 
-  D->addAttr(::new (S.Context) DestructorAttr(Attr.getLoc(), S.Context,
+  D->addAttr(::new (S.Context) DestructorAttr(Attr.getRange(), S.Context,
                                               priority));
 }
 
@@ -1519,7 +1519,7 @@
     Str = SE->getString();
   }
 
-  D->addAttr(::new (S.Context) DeprecatedAttr(Attr.getLoc(), S.Context, Str));
+  D->addAttr(::new (S.Context) DeprecatedAttr(Attr.getRange(), S.Context, Str));
 }
 
 static void handleUnavailableAttr(Sema &S, Decl *D, const AttributeList &Attr) {
@@ -1540,7 +1540,7 @@
     }
     Str = SE->getString();
   }
-  D->addAttr(::new (S.Context) UnavailableAttr(Attr.getLoc(), S.Context, Str));
+  D->addAttr(::new (S.Context) UnavailableAttr(Attr.getRange(), S.Context, Str));
 }
 
 static void handleArcWeakrefUnavailableAttr(Sema &S, Decl *D, 
@@ -1552,7 +1552,7 @@
   }
   
   D->addAttr(::new (S.Context) ArcWeakrefUnavailableAttr(
-                                          Attr.getLoc(), S.Context));
+                                          Attr.getRange(), S.Context));
 }
 
 static void handleAvailabilityAttr(Sema &S, Decl *D,
@@ -1600,7 +1600,7 @@
     return;
   }
 
-  D->addAttr(::new (S.Context) AvailabilityAttr(Attr.getLoc(), S.Context,
+  D->addAttr(::new (S.Context) AvailabilityAttr(Attr.getRange(), S.Context,
                                                 Platform,
                                                 Introduced.Version,
                                                 Deprecated.Version,
@@ -1639,7 +1639,7 @@
     return;
   }
 
-  D->addAttr(::new (S.Context) VisibilityAttr(Attr.getLoc(), S.Context, type));
+  D->addAttr(::new (S.Context) VisibilityAttr(Attr.getRange(), S.Context, type));
 }
 
 static void handleObjCMethodFamilyAttr(Sema &S, Decl *decl,
@@ -1691,7 +1691,7 @@
     return;
   }
 
-  method->addAttr(new (S.Context) ObjCMethodFamilyAttr(Attr.getLoc(),
+  method->addAttr(new (S.Context) ObjCMethodFamilyAttr(Attr.getRange(),
                                                        S.Context, family));
 }
 
@@ -1706,7 +1706,7 @@
     return;
   }
 
-  D->addAttr(::new (S.Context) ObjCExceptionAttr(Attr.getLoc(), S.Context));
+  D->addAttr(::new (S.Context) ObjCExceptionAttr(Attr.getRange(), S.Context));
 }
 
 static void handleObjCNSObject(Sema &S, Decl *D, const AttributeList &Attr) {
@@ -1722,7 +1722,7 @@
       return;
     }
   }
-  D->addAttr(::new (S.Context) ObjCNSObjectAttr(Attr.getLoc(), S.Context));
+  D->addAttr(::new (S.Context) ObjCNSObjectAttr(Attr.getRange(), S.Context));
 }
 
 static void
@@ -1737,7 +1737,7 @@
     return;
   }
 
-  D->addAttr(::new (S.Context) OverloadableAttr(Attr.getLoc(), S.Context));
+  D->addAttr(::new (S.Context) OverloadableAttr(Attr.getRange(), S.Context));
 }
 
 static void handleBlocksAttr(Sema &S, Decl *D, const AttributeList &Attr) {
@@ -1761,7 +1761,7 @@
     return;
   }
 
-  D->addAttr(::new (S.Context) BlocksAttr(Attr.getLoc(), S.Context, type));
+  D->addAttr(::new (S.Context) BlocksAttr(Attr.getRange(), S.Context, type));
 }
 
 static void handleSentinelAttr(Sema &S, Decl *D, const AttributeList &Attr) {
@@ -1852,7 +1852,7 @@
       << Attr.getName() << ExpectedFunctionMethodOrBlock;
     return;
   }
-  D->addAttr(::new (S.Context) SentinelAttr(Attr.getLoc(), S.Context, sentinel,
+  D->addAttr(::new (S.Context) SentinelAttr(Attr.getRange(), S.Context, sentinel,
                                             nullPos));
 }
 
@@ -1879,7 +1879,7 @@
       return;
     }
   
-  D->addAttr(::new (S.Context) WarnUnusedResultAttr(Attr.getLoc(), S.Context));
+  D->addAttr(::new (S.Context) WarnUnusedResultAttr(Attr.getRange(), S.Context));
 }
 
 static void handleWeakAttr(Sema &S, Decl *D, const AttributeList &Attr) {
@@ -1903,7 +1903,7 @@
     return;
   }
 
-  nd->addAttr(::new (S.Context) WeakAttr(Attr.getLoc(), S.Context));
+  nd->addAttr(::new (S.Context) WeakAttr(Attr.getRange(), S.Context));
 }
 
 static void handleWeakImportAttr(Sema &S, Decl *D, const AttributeList &Attr) {
@@ -1930,7 +1930,7 @@
     return;
   }
 
-  D->addAttr(::new (S.Context) WeakImportAttr(Attr.getLoc(), S.Context));
+  D->addAttr(::new (S.Context) WeakImportAttr(Attr.getRange(), S.Context));
 }
 
 static void handleReqdWorkGroupSize(Sema &S, Decl *D,
@@ -1951,7 +1951,7 @@
     }
     WGSize[i] = (unsigned) ArgNum.getZExtValue();
   }
-  D->addAttr(::new (S.Context) ReqdWorkGroupSizeAttr(Attr.getLoc(), S.Context,
+  D->addAttr(::new (S.Context) ReqdWorkGroupSizeAttr(Attr.getRange(), S.Context,
                                                      WGSize[0], WGSize[1],
                                                      WGSize[2]));
 }
@@ -1984,7 +1984,7 @@
     return;
   }
   
-  D->addAttr(::new (S.Context) SectionAttr(Attr.getLoc(), S.Context,
+  D->addAttr(::new (S.Context) SectionAttr(Attr.getRange(), S.Context,
                                            SE->getString()));
 }
 
@@ -2000,7 +2000,7 @@
     if (Existing->getLocation().isInvalid())
       Existing->setRange(Attr.getRange());
   } else {
-    D->addAttr(::new (S.Context) NoThrowAttr(Attr.getLoc(), S.Context));
+    D->addAttr(::new (S.Context) NoThrowAttr(Attr.getRange(), S.Context));
   }
 }
 
@@ -2015,7 +2015,7 @@
    if (Existing->getLocation().isInvalid())
      Existing->setRange(Attr.getRange());
   } else {
-    D->addAttr(::new (S.Context) ConstAttr(Attr.getLoc(), S.Context));
+    D->addAttr(::new (S.Context) ConstAttr(Attr.getRange(), S.Context));
   }
 }
 
@@ -2024,7 +2024,7 @@
   if (!checkAttributeNumArgs(S, Attr, 0))
     return;
 
-  D->addAttr(::new (S.Context) PureAttr(Attr.getLoc(), S.Context));
+  D->addAttr(::new (S.Context) PureAttr(Attr.getRange(), S.Context));
 }
 
 static void handleCleanupAttr(Sema &S, Decl *D, const AttributeList &Attr) {
@@ -2083,7 +2083,7 @@
     return;
   }
 
-  D->addAttr(::new (S.Context) CleanupAttr(Attr.getLoc(), S.Context, FD));
+  D->addAttr(::new (S.Context) CleanupAttr(Attr.getRange(), S.Context, FD));
   S.MarkDeclarationReferenced(Attr.getParameterLoc(), FD);
 }
 
@@ -2158,7 +2158,7 @@
     return;
   }
 
-  D->addAttr(::new (S.Context) FormatArgAttr(Attr.getLoc(), S.Context,
+  D->addAttr(::new (S.Context) FormatArgAttr(Attr.getRange(), S.Context,
                                              Idx.getZExtValue()));
 }
 
@@ -2242,7 +2242,7 @@
     Attr.setInvalid();
     return;
   }
-  D->addAttr(::new (S.Context) InitPriorityAttr(Attr.getLoc(), S.Context,
+  D->addAttr(::new (S.Context) InitPriorityAttr(Attr.getRange(), S.Context,
                                                 prioritynum));
 }
 
@@ -2398,7 +2398,7 @@
     }
   }
   
-  D->addAttr(::new (S.Context) FormatAttr(Attr.getLoc(), S.Context, Format,
+  D->addAttr(::new (S.Context) FormatAttr(Attr.getRange(), S.Context, Format,
                                           Idx.getZExtValue(),
                                           FirstArg.getZExtValue()));
 }
@@ -2467,7 +2467,7 @@
     }
   }
 
-  RD->addAttr(::new (S.Context) TransparentUnionAttr(Attr.getLoc(), S.Context));
+  RD->addAttr(::new (S.Context) TransparentUnionAttr(Attr.getRange(), S.Context));
 }
 
 static void handleAnnotateAttr(Sema &S, Decl *D, const AttributeList &Attr) {
@@ -2492,7 +2492,7 @@
       if ((*i)->getAnnotation() == SE->getString())
           return;
   }
-  D->addAttr(::new (S.Context) AnnotateAttr(Attr.getLoc(), S.Context,
+  D->addAttr(::new (S.Context) AnnotateAttr(Attr.getRange(), S.Context,
                                             SE->getString()));
 }
 
@@ -2508,20 +2508,21 @@
   //       weaker alignment, rather than being silently ignored.
 
   if (Attr.getNumArgs() == 0) {
-    D->addAttr(::new (S.Context) AlignedAttr(Attr.getLoc(), S.Context, true, 0));
+    D->addAttr(::new (S.Context) AlignedAttr(Attr.getRange(), S.Context, true, 0));
     return;
   }
 
-  S.AddAlignedAttr(Attr.getLoc(), D, Attr.getArg(0));
+  S.AddAlignedAttr(Attr.getRange(), D, Attr.getArg(0));
 }
 
-void Sema::AddAlignedAttr(SourceLocation AttrLoc, Decl *D, Expr *E) {
+void Sema::AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E) {
   if (E->isTypeDependent() || E->isValueDependent()) {
     // Save dependent expressions in the AST to be instantiated.
-    D->addAttr(::new (Context) AlignedAttr(AttrLoc, Context, true, E));
+    D->addAttr(::new (Context) AlignedAttr(AttrRange, Context, true, E));
     return;
   }
 
+  SourceLocation AttrLoc = AttrRange.getBegin();
   // FIXME: Cache the number on the Attr object?
   llvm::APSInt Alignment(32);
   if (!E->isIntegerConstantExpr(Alignment, Context)) {
@@ -2535,13 +2536,13 @@
     return;
   }
 
-  D->addAttr(::new (Context) AlignedAttr(AttrLoc, Context, true, E));
+  D->addAttr(::new (Context) AlignedAttr(AttrRange, Context, true, E));
 }
 
-void Sema::AddAlignedAttr(SourceLocation AttrLoc, Decl *D, TypeSourceInfo *TS) {
+void Sema::AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *TS) {
   // FIXME: Cache the number on the Attr object if non-dependent?
   // FIXME: Perform checking of type validity
-  D->addAttr(::new (Context) AlignedAttr(AttrLoc, Context, false, TS));
+  D->addAttr(::new (Context) AlignedAttr(AttrRange, Context, false, TS));
   return;
 }
 
@@ -2615,7 +2616,7 @@
     OldTy = VD->getType();
   else {
     S.Diag(D->getLocation(), diag::err_attr_wrong_decl)
-      << "mode" << SourceRange(Attr.getLoc(), Attr.getLoc());
+      << "mode" << Attr.getRange();
     return;
   }
 
@@ -2726,7 +2727,7 @@
     return;
   }
 
-  D->addAttr(::new (S.Context) NoDebugAttr(Attr.getLoc(), S.Context));
+  D->addAttr(::new (S.Context) NoDebugAttr(Attr.getRange(), S.Context));
 }
 
 static void handleNoInlineAttr(Sema &S, Decl *D, const AttributeList &Attr) {
@@ -2741,7 +2742,7 @@
     return;
   }
 
-  D->addAttr(::new (S.Context) NoInlineAttr(Attr.getLoc(), S.Context));
+  D->addAttr(::new (S.Context) NoInlineAttr(Attr.getRange(), S.Context));
 }
 
 static void handleNoInstrumentFunctionAttr(Sema &S, Decl *D,
@@ -2757,7 +2758,7 @@
     return;
   }
 
-  D->addAttr(::new (S.Context) NoInstrumentFunctionAttr(Attr.getLoc(),
+  D->addAttr(::new (S.Context) NoInstrumentFunctionAttr(Attr.getRange(),
                                                         S.Context));
 }
 
@@ -2775,7 +2776,7 @@
       return;
     }
 
-    D->addAttr(::new (S.Context) CUDAConstantAttr(Attr.getLoc(), S.Context));
+    D->addAttr(::new (S.Context) CUDAConstantAttr(Attr.getRange(), S.Context));
   } else {
     S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "constant";
   }
@@ -2795,7 +2796,7 @@
       return;
     }
 
-    D->addAttr(::new (S.Context) CUDADeviceAttr(Attr.getLoc(), S.Context));
+    D->addAttr(::new (S.Context) CUDADeviceAttr(Attr.getRange(), S.Context));
   } else {
     S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "device";
   }
@@ -2828,7 +2829,7 @@
       return;
     }
 
-    D->addAttr(::new (S.Context) CUDAGlobalAttr(Attr.getLoc(), S.Context));
+    D->addAttr(::new (S.Context) CUDAGlobalAttr(Attr.getRange(), S.Context));
   } else {
     S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "global";
   }
@@ -2847,7 +2848,7 @@
       return;
     }
 
-    D->addAttr(::new (S.Context) CUDAHostAttr(Attr.getLoc(), S.Context));
+    D->addAttr(::new (S.Context) CUDAHostAttr(Attr.getRange(), S.Context));
   } else {
     S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "host";
   }
@@ -2866,7 +2867,7 @@
       return;
     }
 
-    D->addAttr(::new (S.Context) CUDASharedAttr(Attr.getLoc(), S.Context));
+    D->addAttr(::new (S.Context) CUDASharedAttr(Attr.getRange(), S.Context));
   } else {
     S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "shared";
   }
@@ -2889,7 +2890,7 @@
     return;
   }
 
-  D->addAttr(::new (S.Context) GNUInlineAttr(Attr.getLoc(), S.Context));
+  D->addAttr(::new (S.Context) GNUInlineAttr(Attr.getRange(), S.Context));
 }
 
 static void handleCallConvAttr(Sema &S, Decl *D, const AttributeList &Attr) {
@@ -2909,19 +2910,19 @@
 
   switch (Attr.getKind()) {
   case AttributeList::AT_fastcall:
-    D->addAttr(::new (S.Context) FastCallAttr(Attr.getLoc(), S.Context));
+    D->addAttr(::new (S.Context) FastCallAttr(Attr.getRange(), S.Context));
     return;
   case AttributeList::AT_stdcall:
-    D->addAttr(::new (S.Context) StdCallAttr(Attr.getLoc(), S.Context));
+    D->addAttr(::new (S.Context) StdCallAttr(Attr.getRange(), S.Context));
     return;
   case AttributeList::AT_thiscall:
-    D->addAttr(::new (S.Context) ThisCallAttr(Attr.getLoc(), S.Context));
+    D->addAttr(::new (S.Context) ThisCallAttr(Attr.getRange(), S.Context));
     return;
   case AttributeList::AT_cdecl:
-    D->addAttr(::new (S.Context) CDeclAttr(Attr.getLoc(), S.Context));
+    D->addAttr(::new (S.Context) CDeclAttr(Attr.getRange(), S.Context));
     return;
   case AttributeList::AT_pascal:
-    D->addAttr(::new (S.Context) PascalAttr(Attr.getLoc(), S.Context));
+    D->addAttr(::new (S.Context) PascalAttr(Attr.getRange(), S.Context));
     return;
   case AttributeList::AT_pcs: {
     Expr *Arg = Attr.getArg(0);
@@ -2945,7 +2946,7 @@
       return;
     }
 
-    D->addAttr(::new (S.Context) PcsAttr(Attr.getLoc(), S.Context, PCS));
+    D->addAttr(::new (S.Context) PcsAttr(Attr.getRange(), S.Context, PCS));
   }
   default:
     llvm_unreachable("unexpected attribute kind");
@@ -2955,7 +2956,7 @@
 
 static void handleOpenCLKernelAttr(Sema &S, Decl *D, const AttributeList &Attr){
   assert(!Attr.isInvalid());
-  D->addAttr(::new (S.Context) OpenCLKernelAttr(Attr.getLoc(), S.Context));
+  D->addAttr(::new (S.Context) OpenCLKernelAttr(Attr.getRange(), S.Context));
 }
 
 bool Sema::CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC) {
@@ -3017,7 +3018,7 @@
     return;
   }
 
-  D->addAttr(::new (S.Context) RegparmAttr(Attr.getLoc(), S.Context, numParams));
+  D->addAttr(::new (S.Context) RegparmAttr(Attr.getRange(), S.Context, numParams));
 }
 
 /// Checks a regparm attribute, returning true if it is ill-formed and
@@ -3097,7 +3098,7 @@
       }
     }
 
-    D->addAttr(::new (S.Context) CUDALaunchBoundsAttr(Attr.getLoc(), S.Context,
+    D->addAttr(::new (S.Context) CUDALaunchBoundsAttr(Attr.getRange(), S.Context,
                                                       MaxThreads.getZExtValue(),
                                                      MinBlocks.getZExtValue()));
   } else {
@@ -3120,7 +3121,7 @@
   ParmVarDecl *param = dyn_cast<ParmVarDecl>(D);
   if (!param) {
     S.Diag(D->getLocStart(), diag::warn_attribute_wrong_decl_type)
-      << SourceRange(Attr.getLoc()) << Attr.getName() << ExpectedParameter;
+      << Attr.getRange() << Attr.getName() << ExpectedParameter;
     return;
   }
 
@@ -3135,25 +3136,25 @@
 
   if (!typeOK) {
     S.Diag(D->getLocStart(), diag::warn_ns_attribute_wrong_parameter_type)
-      << SourceRange(Attr.getLoc()) << Attr.getName() << cf;
+      << Attr.getRange() << Attr.getName() << cf;
     return;
   }
 
   if (cf)
-    param->addAttr(::new (S.Context) CFConsumedAttr(Attr.getLoc(), S.Context));
+    param->addAttr(::new (S.Context) CFConsumedAttr(Attr.getRange(), S.Context));
   else
-    param->addAttr(::new (S.Context) NSConsumedAttr(Attr.getLoc(), S.Context));
+    param->addAttr(::new (S.Context) NSConsumedAttr(Attr.getRange(), S.Context));
 }
 
 static void handleNSConsumesSelfAttr(Sema &S, Decl *D,
                                      const AttributeList &Attr) {
   if (!isa<ObjCMethodDecl>(D)) {
     S.Diag(D->getLocStart(), diag::warn_attribute_wrong_decl_type)
-      << SourceRange(Attr.getLoc()) << Attr.getName() << ExpectedMethod;
+      << Attr.getRange() << Attr.getName() << ExpectedMethod;
     return;
   }
 
-  D->addAttr(::new (S.Context) NSConsumesSelfAttr(Attr.getLoc(), S.Context));
+  D->addAttr(::new (S.Context) NSConsumesSelfAttr(Attr.getRange(), S.Context));
 }
 
 static void handleNSReturnsRetainedAttr(Sema &S, Decl *D,
@@ -3172,7 +3173,7 @@
     returnType = FD->getResultType();
   else {
     S.Diag(D->getLocStart(), diag::warn_attribute_wrong_decl_type)
-        << SourceRange(Attr.getLoc()) << Attr.getName()
+        << Attr.getRange() << Attr.getName()
         << ExpectedFunctionOrMethod;
     return;
   }
@@ -3197,8 +3198,7 @@
 
   if (!typeOK) {
     S.Diag(D->getLocStart(), diag::warn_ns_attribute_wrong_return_type)
-      << SourceRange(Attr.getLoc())
-      << Attr.getName() << isa<ObjCMethodDecl>(D) << cf;
+      << Attr.getRange() << Attr.getName() << isa<ObjCMethodDecl>(D) << cf;
     return;
   }
 
@@ -3207,23 +3207,23 @@
       assert(0 && "invalid ownership attribute");
       return;
     case AttributeList::AT_ns_returns_autoreleased:
-      D->addAttr(::new (S.Context) NSReturnsAutoreleasedAttr(Attr.getLoc(),
+      D->addAttr(::new (S.Context) NSReturnsAutoreleasedAttr(Attr.getRange(),
                                                              S.Context));
       return;
     case AttributeList::AT_cf_returns_not_retained:
-      D->addAttr(::new (S.Context) CFReturnsNotRetainedAttr(Attr.getLoc(),
+      D->addAttr(::new (S.Context) CFReturnsNotRetainedAttr(Attr.getRange(),
                                                             S.Context));
       return;
     case AttributeList::AT_ns_returns_not_retained:
-      D->addAttr(::new (S.Context) NSReturnsNotRetainedAttr(Attr.getLoc(),
+      D->addAttr(::new (S.Context) NSReturnsNotRetainedAttr(Attr.getRange(),
                                                             S.Context));
       return;
     case AttributeList::AT_cf_returns_retained:
-      D->addAttr(::new (S.Context) CFReturnsRetainedAttr(Attr.getLoc(),
+      D->addAttr(::new (S.Context) CFReturnsRetainedAttr(Attr.getRange(),
                                                          S.Context));
       return;
     case AttributeList::AT_ns_returns_retained:
-      D->addAttr(::new (S.Context) NSReturnsRetainedAttr(Attr.getLoc(),
+      D->addAttr(::new (S.Context) NSReturnsRetainedAttr(Attr.getRange(),
                                                          S.Context));
       return;
   };
@@ -3253,24 +3253,22 @@
   }
 
   method->addAttr(
-    ::new (S.Context) ObjCReturnsInnerPointerAttr(loc, S.Context));
+    ::new (S.Context) ObjCReturnsInnerPointerAttr(attr.getRange(), S.Context));
 }
 
 static void handleObjCOwnershipAttr(Sema &S, Decl *D,
                                     const AttributeList &Attr) {
   if (hasDeclarator(D)) return;
 
-  SourceLocation L = Attr.getLoc();
   S.Diag(D->getLocStart(), diag::err_attribute_wrong_decl_type)
-    << SourceRange(L, L) << Attr.getName() << 12 /* variable */;
+    << Attr.getRange() << Attr.getName() << 12 /* variable */;
 }
 
 static void handleObjCPreciseLifetimeAttr(Sema &S, Decl *D,
                                           const AttributeList &Attr) {
   if (!isa<VarDecl>(D) && !isa<FieldDecl>(D)) {
-    SourceLocation L = Attr.getLoc();
     S.Diag(D->getLocStart(), diag::err_attribute_wrong_decl_type)
-      << SourceRange(L, L) << Attr.getName() << 12 /* variable */;
+      << Attr.getRange() << Attr.getName() << 12 /* variable */;
     return;
   }
 
@@ -3309,7 +3307,7 @@
   }
 
   D->addAttr(::new (S.Context)
-                 ObjCPreciseLifetimeAttr(Attr.getLoc(), S.Context));
+                 ObjCPreciseLifetimeAttr(Attr.getRange(), S.Context));
 }
 
 static bool isKnownDeclSpecAttr(const AttributeList &Attr) {
@@ -3370,7 +3368,7 @@
       I++;
     }
 
-    D->addAttr(::new (S.Context) UuidAttr(Attr.getLoc(), S.Context,
+    D->addAttr(::new (S.Context) UuidAttr(Attr.getRange(), S.Context,
                                           Str->getString()));
   } else
     S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "uuid";
diff --git a/lib/Sema/TargetAttributesSema.cpp b/lib/Sema/TargetAttributesSema.cpp
index 37fafd2..0560a8b 100644
--- a/lib/Sema/TargetAttributesSema.cpp
+++ b/lib/Sema/TargetAttributesSema.cpp
@@ -147,7 +147,8 @@
     return;
   }
 
-  D->addAttr(::new (S.Context) X86ForceAlignArgPointerAttr(Attr.getLoc(), S.Context));
+  D->addAttr(::new (S.Context) X86ForceAlignArgPointerAttr(Attr.getRange(),
+                                                           S.Context));
 }
 
 static void HandleDLLImportAttr(Decl *D, const AttributeList &Attr, Sema &S) {
diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp
index 9210056..b794938 100644
--- a/lib/Serialization/ASTReaderDecl.cpp
+++ b/lib/Serialization/ASTReaderDecl.cpp
@@ -1361,7 +1361,7 @@
   for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
     Attr *New = 0;
     attr::Kind Kind = (attr::Kind)Record[Idx++];
-    SourceLocation Loc = ReadSourceLocation(F, Record, Idx);
+    SourceRange Range = ReadSourceRange(F, Record, Idx);
 
 #include "clang/Serialization/AttrPCHRead.inc"
 
diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp
index 943d177..5515f3b 100644
--- a/lib/Serialization/ASTWriter.cpp
+++ b/lib/Serialization/ASTWriter.cpp
@@ -2770,7 +2770,7 @@
   for (AttrVec::const_iterator i = Attrs.begin(), e = Attrs.end(); i != e; ++i){
     const Attr * A = *i;
     Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs
-    AddSourceLocation(A->getLocation(), Record);
+    AddSourceRange(A->getRange(), Record);
 
 #include "clang/Serialization/AttrPCHWrite.inc"