Index: include/clang/Frontend/ASTUnit.h
===================================================================
--- include/clang/Frontend/ASTUnit.h	(revision 166899)
+++ include/clang/Frontend/ASTUnit.h	(working copy)
@@ -267,8 +267,8 @@
                              const char **ArgBegin, const char **ArgEnd,
                              ASTUnit &AST, bool CaptureDiagnostics);
 
-  void TranslateStoredDiagnostics(ASTReader *MMan, StringRef ModName,
-                                  SourceManager &SrcMan,
+  static void TranslateStoredDiagnostics(ASTReader *MMan, StringRef ModName,
+                                         const SourceManager &SrcMan,
                       const SmallVectorImpl<StoredDiagnostic> &Diags,
                             SmallVectorImpl<StoredDiagnostic> &Out);
 
@@ -467,7 +467,7 @@
 
   const FileSystemOptions &getFileSystemOpts() const { return FileSystemOpts; }
 
-  const std::string &getOriginalSourceFileName();
+  const std::string &getOriginalSourceFileName() const { return OriginalSourceFile; }
 
   ASTDeserializationListener *getDeserializationListener();
 
@@ -548,26 +548,26 @@
   /// \brief If \p Loc is a loaded location from the preamble, returns
   /// the corresponding local location of the main file, otherwise it returns
   /// \p Loc.
-  SourceLocation mapLocationFromPreamble(SourceLocation Loc);
+  SourceLocation mapLocationFromPreamble(SourceLocation Loc) const;
 
   /// \brief If \p Loc is a local location of the main file but inside the
   /// preamble chunk, returns the corresponding loaded location from the
   /// preamble, otherwise it returns \p Loc.
-  SourceLocation mapLocationToPreamble(SourceLocation Loc);
+  SourceLocation mapLocationToPreamble(SourceLocation Loc) const;
 
-  bool isInPreambleFileID(SourceLocation Loc);
-  bool isInMainFileID(SourceLocation Loc);
-  SourceLocation getStartOfMainFileID();
-  SourceLocation getEndOfPreambleFileID();
+  bool isInPreambleFileID(SourceLocation Loc) const;
+  bool isInMainFileID(SourceLocation Loc) const;
+  SourceLocation getStartOfMainFileID() const;
+  SourceLocation getEndOfPreambleFileID() const;
 
   /// \see mapLocationFromPreamble.
-  SourceRange mapRangeFromPreamble(SourceRange R) {
+  SourceRange mapRangeFromPreamble(SourceRange R) const {
     return SourceRange(mapLocationFromPreamble(R.getBegin()),
                        mapLocationFromPreamble(R.getEnd()));
   }
 
   /// \see mapLocationToPreamble.
-  SourceRange mapRangeToPreamble(SourceRange R) {
+  SourceRange mapRangeToPreamble(SourceRange R) const {
     return SourceRange(mapLocationToPreamble(R.getBegin()),
                        mapLocationToPreamble(R.getEnd()));
   }
@@ -631,7 +631,7 @@
 
   /// \brief Returns true if the ASTUnit was constructed from a serialized
   /// module file.
-  bool isModuleFile();
+  bool isModuleFile() const;
 
   llvm::MemoryBuffer *getBufferForFile(StringRef Filename,
                                        std::string *ErrorStr = 0);
Index: lib/Frontend/ASTUnit.cpp
===================================================================
--- lib/Frontend/ASTUnit.cpp	(revision 166899)
+++ lib/Frontend/ASTUnit.cpp	(working copy)
@@ -312,7 +312,7 @@
       // Part of the nested-name-specifier in C++0x.
       if (LangOpts.CPlusPlus0x)
         IsNestedNameSpecifier = true;
-    } else if (RecordDecl *Record = dyn_cast<RecordDecl>(ND)) {
+    } else if (const RecordDecl * Record = dyn_cast<RecordDecl const>(ND)) {
       if (Record->isUnion())
         Contexts |= (1LL << CodeCompletionContext::CCC_UnionTag);
       else
@@ -380,7 +380,8 @@
 
       // Keep track of the type of this completion in an ASTContext-agnostic 
       // way.
-      QualType UsageType = getDeclUsageType(*Ctx, Results[I].Declaration);
+      const QualType UsageType = getDeclUsageType(*Ctx,
+                                                  Results[I].Declaration);
       if (UsageType.isNull()) {
         CachedResult.TypeClass = STC_Void;
         CachedResult.Type = 0;
@@ -426,7 +427,7 @@
             isa<NamespaceAliasDecl>(Results[I].Declaration))
           NNSContexts |= (1LL << CodeCompletionContext::CCC_Namespace);
 
-        if (unsigned RemainingContexts 
+        if (const unsigned RemainingContexts 
                                 = NNSContexts & ~CachedResult.ShowInContexts) {
           // If there any contexts where this completion can be a 
           // nested-name-specifier but isn't already an option, create a 
@@ -632,10 +633,6 @@
   StoredDiags.push_back(StoredDiagnostic(Level, Info));
 }
 
-const std::string &ASTUnit::getOriginalSourceFileName() {
-  return OriginalSourceFile;
-}
-
 ASTDeserializationListener *ASTUnit::getDeserializationListener() {
   if (WriterData)
     return &WriterData->Writer;
@@ -680,9 +677,9 @@
   OwningPtr<ASTUnit> AST(new ASTUnit(true));
 
   // Recover resources if we crash before exiting this method.
-  llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit>
+  const llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit>
     ASTUnitCleanup(AST.get());
-  llvm::CrashRecoveryContextCleanupRegistrar<DiagnosticsEngine,
+  const llvm::CrashRecoveryContextCleanupRegistrar<DiagnosticsEngine,
     llvm::CrashRecoveryContextReleaseRefCleanup<DiagnosticsEngine> >
     DiagCleanup(Diags.getPtr());
 
@@ -864,12 +861,11 @@
   if (!(DC->isTranslationUnit() || DC->getLookupParent()->isTranslationUnit()))
     return;
 
-  if (NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
+  if (const NamedDecl * const ND = dyn_cast<NamedDecl const>(D)) {
     if (ND->getIdentifier())
       Hash = llvm::HashString(ND->getIdentifier()->getName(), Hash);
-    else if (DeclarationName Name = ND->getDeclName()) {
-      std::string NameStr = Name.getAsString();
-      Hash = llvm::HashString(NameStr, Hash);
+    else if (const DeclarationName &Name = ND->getDeclName()) {
+      Hash = llvm::HashString(Name.getAsString(), Hash);
     }
     return;
   }  
@@ -904,7 +900,7 @@
 
   void handleFileLevelDecl(Decl *D) {
     Unit.addFileLevelDecl(D);
-    if (NamespaceDecl *NSD = dyn_cast<NamespaceDecl>(D)) {
+    if (const NamespaceDecl * const NSD = dyn_cast<NamespaceDecl const>(D)) {
       for (NamespaceDecl::decl_iterator
              I = NSD->decls_begin(), E = NSD->decls_end(); I != E; ++I)
         handleFileLevelDecl(*I);
@@ -1038,8 +1034,8 @@
 }
 
 static void checkAndSanitizeDiags(SmallVectorImpl<StoredDiagnostic> &
-                                                              StoredDiagnostics,
-                                  SourceManager &SM) {
+                                                            StoredDiagnostics,
+                                  const SourceManager &SM) {
   // The stored diagnostic has the old source manager in it; update
   // the locations to refer into the new source manager. Since we've
   // been careful to make sure that the source manager's state
@@ -1166,7 +1162,7 @@
     goto error;
 
   if (OverrideMainBuffer) {
-    std::string ModName = getPreambleFile(this);
+    const std::string &ModName = getPreambleFile(this);
     TranslateStoredDiagnostics(Clang->getModuleManager(), ModName,
                                getSourceManager(), PreambleDiagnostics,
                                StoredDiagnostics);
@@ -1211,7 +1207,6 @@
   if (TmpFile)
     return TmpFile;
   
-  std::string Error;
   const char *TmpDir = ::getenv("TMPDIR");
   if (!TmpDir)
     TmpDir = ::getenv("TEMP");
@@ -1247,7 +1242,7 @@
   // command line (to another file) or directly through the compiler invocation
   // (to a memory buffer).
   llvm::MemoryBuffer *Buffer = 0;
-  llvm::sys::PathWithStatus MainFilePath(FrontendOpts.Inputs[0].File);
+  const llvm::sys::PathWithStatus MainFilePath(FrontendOpts.Inputs[0].File);
   if (const llvm::sys::FileStatus *MainFileStatus = MainFilePath.getFileStatus()) {
     // Check whether there is a file-file remapping of the main file
     for (PreprocessorOptions::remapped_file_iterator
@@ -1280,7 +1275,7 @@
            E = PreprocessorOpts.remapped_file_buffer_end();
          M != E;
          ++M) {
-      llvm::sys::PathWithStatus MPath(M->first);    
+      const llvm::sys::PathWithStatus MPath(M->first);    
       if (const llvm::sys::FileStatus *MStatus = MPath.getFileStatus()) {
         if (MainFileStatus->uniqueID == MStatus->uniqueID) {
           // We found a remapping. 
@@ -1425,7 +1420,7 @@
              F = FilesInPreamble.begin(), FEnd = FilesInPreamble.end();
            !AnyFileChanged && F != FEnd; 
            ++F) {
-        llvm::StringMap<std::pair<off_t, time_t> >::iterator Overridden
+        const llvm::StringMap<std::pair<off_t, time_t> >::iterator Overridden
           = OverriddenFiles.find(F->first());
         if (Overridden != OverriddenFiles.end()) {
           // This file was remapped; check whether the newly-mapped file 
@@ -1489,7 +1484,7 @@
 
   // Create a temporary file for the precompiled preamble. In rare 
   // circumstances, this can fail.
-  std::string PreamblePCHPath = GetPreamblePCHPath();
+  const std::string &PreamblePCHPath = GetPreamblePCHPath();
   if (PreamblePCHPath.empty()) {
     // Try again next time.
     PreambleRebuildCounter = 1;
@@ -1512,7 +1507,8 @@
 
   // Save the preamble text for later; we'll need to compare against it for
   // subsequent reparses.
-  StringRef MainFilename = PreambleInvocation->getFrontendOpts().Inputs[0].File;
+  const StringRef &MainFilename
+    = PreambleInvocation->getFrontendOpts().Inputs[0].File;
   Preamble.assign(FileMgr->getFile(MainFilename),
                   NewPreamble.first->getBufferStart(), 
                   NewPreamble.first->getBufferStart() 
@@ -1530,7 +1526,7 @@
   const_cast<char*>(PreambleBuffer->getBufferEnd())[-1] = '\n';  
   
   // Remap the main source file to the preamble buffer.
-  llvm::sys::PathWithStatus MainFilePath(FrontendOpts.Inputs[0].File);
+  const llvm::sys::PathWithStatus MainFilePath(FrontendOpts.Inputs[0].File);
   PreprocessorOpts.addRemappedFile(MainFilePath.str(), PreambleBuffer);
   
   // Tell the compiler invocation to generate a temporary precompiled header.
@@ -1544,7 +1540,7 @@
   OwningPtr<CompilerInstance> Clang(new CompilerInstance());
 
   // Recover resources if we crash before exiting this method.
-  llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
+  const llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
     CICleanup(Clang.get());
 
   Clang->setInvocation(&*PreambleInvocation);
@@ -1633,7 +1629,7 @@
   // Keep track of all of the files that the source manager knows about,
   // so we can verify whether they have changed or not.
   FilesInPreamble.clear();
-  SourceManager &SourceMgr = Clang->getSourceManager();
+  const SourceManager &SourceMgr = Clang->getSourceManager();
   const llvm::MemoryBuffer *MainFileBuffer
     = SourceMgr.getBuffer(SourceMgr.getMainFileID());
   for (SourceManager::fileinfo_iterator F = SourceMgr.fileinfo_begin(),
@@ -1751,9 +1747,9 @@
     = IncludeBriefCommentsInCodeCompletion;
 
   // Recover resources if we crash before exiting this method.
-  llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit>
+  const llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit>
     ASTUnitCleanup(OwnAST.get());
-  llvm::CrashRecoveryContextCleanupRegistrar<DiagnosticsEngine,
+  const llvm::CrashRecoveryContextCleanupRegistrar<DiagnosticsEngine,
     llvm::CrashRecoveryContextReleaseRefCleanup<DiagnosticsEngine> >
     DiagCleanup(Diags.getPtr());
 
@@ -1766,7 +1762,7 @@
   OwningPtr<CompilerInstance> Clang(new CompilerInstance());
 
   // Recover resources if we crash before exiting this method.
-  llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
+  const llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
     CICleanup(Clang.get());
 
   Clang->setInvocation(CI);
@@ -1906,9 +1902,9 @@
   AST->UserFilesAreVolatile = UserFilesAreVolatile;
   
   // Recover resources if we crash before exiting this method.
-  llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit>
+  const llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit>
     ASTUnitCleanup(AST.get());
-  llvm::CrashRecoveryContextCleanupRegistrar<DiagnosticsEngine,
+  const llvm::CrashRecoveryContextCleanupRegistrar<DiagnosticsEngine,
     llvm::CrashRecoveryContextReleaseRefCleanup<DiagnosticsEngine> >
     DiagCleanup(Diags.getPtr());
 
@@ -1947,8 +1943,8 @@
 
   {
 
-    CaptureDroppedDiagnostics Capture(CaptureDiagnostics, *Diags, 
-                                      StoredDiagnostics);
+    const CaptureDroppedDiagnostics Capture(CaptureDiagnostics, *Diags, 
+                                            StoredDiagnostics);
 
     CI = clang::createInvocationFromCommandLine(
                                            llvm::makeArrayRef(ArgBegin, ArgEnd),
@@ -1959,7 +1955,7 @@
 
   // Override any files that need remapping
   for (unsigned I = 0; I != NumRemappedFiles; ++I) {
-    FilenameOrMemBuf fileOrBuf = RemappedFiles[I].second;
+    const FilenameOrMemBuf fileOrBuf = RemappedFiles[I].second;
     if (const llvm::MemoryBuffer *
             memBuf = fileOrBuf.dyn_cast<const llvm::MemoryBuffer *>()) {
       CI->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first, memBuf);
@@ -2000,7 +1996,7 @@
   CI = 0; // Zero out now to ease cleanup during crash recovery.
   
   // Recover resources if we crash before exiting this method.
-  llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit>
+  const llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit>
     ASTUnitCleanup(AST.get());
 
   if (AST->LoadFromCompilerInvocation(PrecompilePreamble)) {
@@ -2037,7 +2033,7 @@
   }
   Invocation->getPreprocessorOpts().clearRemappedFiles();
   for (unsigned I = 0; I != NumRemappedFiles; ++I) {
-    FilenameOrMemBuf fileOrBuf = RemappedFiles[I].second;
+    const FilenameOrMemBuf fileOrBuf = RemappedFiles[I].second;
     if (const llvm::MemoryBuffer *
             memBuf = fileOrBuf.dyn_cast<const llvm::MemoryBuffer *>()) {
       Invocation->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first,
@@ -2062,7 +2058,7 @@
     getDiagnostics().setNumWarnings(NumWarningsInPreamble);
 
   // Parse the sources
-  bool Result = Parse(OverrideMainBuffer);
+  const bool Result = Parse(OverrideMainBuffer);
   
   // If we're caching global code-completion results, and the top-level 
   // declarations have changed, clear out the code-completion cache.
@@ -2145,7 +2141,7 @@
 static void CalculateHiddenNames(const CodeCompletionContext &Context,
                                  CodeCompletionResult *Results,
                                  unsigned NumResults,
-                                 ASTContext &Ctx,
+                                 const ASTContext &Ctx,
                           llvm::StringSet<llvm::BumpPtrAllocator> &HiddenNames){
   bool OnlyTagNames = false;
   switch (Context.getKind()) {
@@ -2216,8 +2212,8 @@
     if (!Hiding)
       continue;
     
-    DeclarationName Name = Results[I].Declaration->getDeclName();
-    if (IdentifierInfo *Identifier = Name.getAsIdentifierInfo())
+    const DeclarationName &Name = Results[I].Declaration->getDeclName();
+    if (const IdentifierInfo *Identifier = Name.getAsIdentifierInfo())
       HiddenNames.insert(Identifier->getName());
     else
       HiddenNames.insert(Name.getAsString());
@@ -2231,7 +2227,7 @@
                                             unsigned NumResults) { 
   // Merge the results we were given with the results we cached.
   bool AddedResult = false;
-  uint64_t InContexts =
+  const uint64_t InContexts =
       Context.getKind() == CodeCompletionContext::CCC_Recovery
         ? NormalContexts : (1LL << Context.getKind());
   // Contains the set of names that are hidden by "local" completion results.
@@ -2270,15 +2266,16 @@
                                          S.getLangOpts(),
                                Context.getPreferredType()->isAnyPointerType());        
       } else if (C->Type) {
-        CanQualType Expected
+        const CanQualType &Expected
           = S.Context.getCanonicalType(
                                Context.getPreferredType().getUnqualifiedType());
-        SimplifiedTypeClass ExpectedSTC = getSimplifiedTypeClass(Expected);
+        const SimplifiedTypeClass ExpectedSTC
+          = getSimplifiedTypeClass(Expected);
         if (ExpectedSTC == C->TypeClass) {
           // We know this type is similar; check for an exact match.
           llvm::StringMap<unsigned> &CachedCompletionTypes
             = AST.getCachedCompletionTypes();
-          llvm::StringMap<unsigned>::iterator Pos
+          const llvm::StringMap<unsigned>::iterator &Pos
             = CachedCompletionTypes.find(QualType(Expected).getAsString());
           if (Pos != CachedCompletionTypes.end() && Pos->second == C->Type)
             Priority /= CCF_ExactTypeMatch;
@@ -2360,7 +2357,7 @@
   OwningPtr<CompilerInstance> Clang(new CompilerInstance());
 
   // Recover resources if we crash before exiting this method.
-  llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
+  const llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
     CICleanup(Clang.get());
 
   Clang->setInvocation(&*CCInvocation);
@@ -2369,9 +2366,9 @@
   // Set up diagnostics, capturing any diagnostics produced.
   Clang->setDiagnostics(&Diag);
   ProcessWarningOptions(Diag, CCInvocation->getDiagnosticOpts());
-  CaptureDroppedDiagnostics Capture(true, 
-                                    Clang->getDiagnostics(), 
-                                    StoredDiagnostics);
+  const CaptureDroppedDiagnostics Capture(true, 
+                                          Clang->getDiagnostics(), 
+                                          StoredDiagnostics);
   
   // Create the target instance.
   Clang->setTarget(TargetInfo::CreateTargetInfo(Clang->getDiagnostics(),
@@ -2429,8 +2426,8 @@
   llvm::MemoryBuffer *OverrideMainBuffer = 0;
   if (!getPreambleFile(this).empty()) {
     using llvm::sys::FileStatus;
-    llvm::sys::PathWithStatus CompleteFilePath(File);
-    llvm::sys::PathWithStatus MainPath(OriginalSourceFile);
+    const llvm::sys::PathWithStatus CompleteFilePath(File);
+    const llvm::sys::PathWithStatus MainPath(OriginalSourceFile);
     if (const FileStatus *CompleteFileStatus = CompleteFilePath.getFileStatus())
       if (const FileStatus *MainStatus = MainPath.getFileStatus())
         if (CompleteFileStatus->getUniqueID() == MainStatus->getUniqueID() &&
@@ -2467,7 +2464,7 @@
   Act.reset(new SyntaxOnlyAction);
   if (Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0])) {
     if (OverrideMainBuffer) {
-      std::string ModName = getPreambleFile(this);
+      const std::string &ModName = getPreambleFile(this);
       TranslateStoredDiagnostics(Clang->getModuleManager(), ModName,
                                  getSourceManager(), PreambleDiagnostics,
                                  StoredDiagnostics);
@@ -2525,7 +2522,7 @@
 }
 
 bool ASTUnit::serialize(raw_ostream &OS) {
-  bool hasErrors = getDiagnostics().hasErrorOccurred();
+  const bool hasErrors = getDiagnostics().hasErrorOccurred();
 
   if (WriterData)
     return serializeUnit(WriterData->Writer, WriterData->Buffer,
@@ -2549,7 +2546,7 @@
 void ASTUnit::TranslateStoredDiagnostics(
                           ASTReader *MMan,
                           StringRef ModName,
-                          SourceManager &SrcMgr,
+                          const SourceManager &SrcMgr,
                           const SmallVectorImpl<StoredDiagnostic> &Diags,
                           SmallVectorImpl<StoredDiagnostic> &Out) {
   // The stored diagnostic has the old source manager in it; update
@@ -2569,7 +2566,7 @@
     const StoredDiagnostic &SD = Diags[I];
     SourceLocation L = SD.getLocation();
     TranslateSLoc(L, Remap);
-    FullSourceLoc Loc(L, SrcMgr);
+    const FullSourceLoc Loc(L, SrcMgr);
 
     SmallVector<CharSourceRange, 4> Ranges;
     Ranges.reserve(SD.range_size());
@@ -2617,8 +2614,8 @@
   if (D->isFromASTFile())
     return;
 
-  SourceManager &SM = *SourceMgr;
-  SourceLocation Loc = D->getLocation();
+  const SourceManager &SM = *SourceMgr;
+  const SourceLocation &Loc = D->getLocation();
   if (Loc.isInvalid() || !SM.isLocalSourceLocation(Loc))
     return;
 
@@ -2626,7 +2623,7 @@
   if (!D->getLexicalDeclContext()->isFileContext())
     return;
 
-  SourceLocation FileLoc = SM.getFileLoc(Loc);
+  const SourceLocation &FileLoc = SM.getFileLoc(Loc);
   assert(SM.isLocalSourceLocation(FileLoc));
   FileID FID;
   unsigned Offset;
@@ -2638,15 +2635,15 @@
   if (!Decls)
     Decls = new LocDeclsTy();
 
-  std::pair<unsigned, Decl *> LocDecl(Offset, D);
+  const std::pair<unsigned, Decl *> LocDecl(Offset, D);
 
   if (Decls->empty() || Decls->back().first <= Offset) {
     Decls->push_back(LocDecl);
     return;
   }
 
-  LocDeclsTy::iterator
-    I = std::upper_bound(Decls->begin(), Decls->end(), LocDecl, compLocDecl);
+  const LocDeclsTy::iterator &I
+    = std::upper_bound(Decls->begin(), Decls->end(), LocDecl, compLocDecl);
 
   Decls->insert(I, LocDecl);
 }
@@ -2662,7 +2659,7 @@
                                                          Decls);
   }
 
-  FileDeclsTy::iterator I = FileDecls.find(File);
+  const FileDeclsTy::iterator &I = FileDecls.find(File);
   if (I == FileDecls.end())
     return;
 
@@ -2697,21 +2694,21 @@
 SourceLocation ASTUnit::getLocation(const FileEntry *File,
                                     unsigned Line, unsigned Col) const {
   const SourceManager &SM = getSourceManager();
-  SourceLocation Loc = SM.translateFileLineCol(File, Line, Col);
+  const SourceLocation &Loc = SM.translateFileLineCol(File, Line, Col);
   return SM.getMacroArgExpandedLocation(Loc);
 }
 
 SourceLocation ASTUnit::getLocation(const FileEntry *File,
                                     unsigned Offset) const {
   const SourceManager &SM = getSourceManager();
-  SourceLocation FileLoc = SM.translateFileLineCol(File, 1, 1);
+  const SourceLocation &FileLoc = SM.translateFileLineCol(File, 1, 1);
   return SM.getMacroArgExpandedLocation(FileLoc.getLocWithOffset(Offset));
 }
 
 /// \brief If \arg Loc is a loaded location from the preamble, returns
 /// the corresponding local location of the main file, otherwise it returns
 /// \arg Loc.
-SourceLocation ASTUnit::mapLocationFromPreamble(SourceLocation Loc) {
+SourceLocation ASTUnit::mapLocationFromPreamble(SourceLocation Loc) const {
   FileID PreambleID;
   if (SourceMgr)
     PreambleID = SourceMgr->getPreambleFileID();
@@ -2721,8 +2718,8 @@
 
   unsigned Offs;
   if (SourceMgr->isInFileID(Loc, PreambleID, &Offs) && Offs < Preamble.size()) {
-    SourceLocation FileLoc
-        = SourceMgr->getLocForStartOfFile(SourceMgr->getMainFileID());
+    const SourceLocation &FileLoc
+      = SourceMgr->getLocForStartOfFile(SourceMgr->getMainFileID());
     return FileLoc.getLocWithOffset(Offs);
   }
 
@@ -2732,7 +2729,7 @@
 /// \brief If \arg Loc is a local location of the main file but inside the
 /// preamble chunk, returns the corresponding loaded location from the
 /// preamble, otherwise it returns \arg Loc.
-SourceLocation ASTUnit::mapLocationToPreamble(SourceLocation Loc) {
+SourceLocation ASTUnit::mapLocationToPreamble(SourceLocation Loc) const {
   FileID PreambleID;
   if (SourceMgr)
     PreambleID = SourceMgr->getPreambleFileID();
@@ -2743,14 +2740,15 @@
   unsigned Offs;
   if (SourceMgr->isInFileID(Loc, SourceMgr->getMainFileID(), &Offs) &&
       Offs < Preamble.size()) {
-    SourceLocation FileLoc = SourceMgr->getLocForStartOfFile(PreambleID);
+    const SourceLocation &FileLoc
+      = SourceMgr->getLocForStartOfFile(PreambleID);
     return FileLoc.getLocWithOffset(Offs);
   }
 
   return Loc;
 }
 
-bool ASTUnit::isInPreambleFileID(SourceLocation Loc) {
+bool ASTUnit::isInPreambleFileID(SourceLocation Loc) const {
   FileID FID;
   if (SourceMgr)
     FID = SourceMgr->getPreambleFileID();
@@ -2761,7 +2759,7 @@
   return SourceMgr->isInFileID(Loc, FID);
 }
 
-bool ASTUnit::isInMainFileID(SourceLocation Loc) {
+bool ASTUnit::isInMainFileID(SourceLocation Loc) const {
   FileID FID;
   if (SourceMgr)
     FID = SourceMgr->getMainFileID();
@@ -2772,7 +2770,7 @@
   return SourceMgr->isInFileID(Loc, FID);
 }
 
-SourceLocation ASTUnit::getEndOfPreambleFileID() {
+SourceLocation ASTUnit::getEndOfPreambleFileID() const {
   FileID FID;
   if (SourceMgr)
     FID = SourceMgr->getPreambleFileID();
@@ -2783,7 +2781,7 @@
   return SourceMgr->getLocForEndOfFile(FID);
 }
 
-SourceLocation ASTUnit::getStartOfMainFileID() {
+SourceLocation ASTUnit::getStartOfMainFileID() const {
   FileID FID;
   if (SourceMgr)
     FID = SourceMgr->getMainFileID();
@@ -2869,7 +2867,7 @@
   return 0;
 }
 
-bool ASTUnit::isModuleFile() {
+bool ASTUnit::isModuleFile() const {
   return isMainFileAST() && !ASTFileLangOpts.CurrentModule.empty();
 }
 
