From a0fb00f9837bd0d2e5948f16f6a6b82a7a628f51 Mon Sep 17 00:00:00 2001
From: dim <dim@FreeBSD.org>
Date: Sat, 26 Feb 2011 22:09:03 +0000
Subject: Vendor import of clang trunk r126547:
 http://llvm.org/svn/llvm-project/cfe/trunk@126547

---
 lib/Frontend/ASTUnit.cpp                 |   3 +-
 lib/Frontend/CompilerInvocation.cpp      |  52 ++++++++-------
 lib/Frontend/DocumentXML.cpp             |   5 ++
 lib/Frontend/InitHeaderSearch.cpp        | 107 ++++++++++++++++++-------------
 lib/Frontend/InitPreprocessor.cpp        |  37 +++++------
 lib/Frontend/TextDiagnosticPrinter.cpp   |  14 +++-
 lib/Frontend/VerifyDiagnosticsClient.cpp |   8 +--
 7 files changed, 136 insertions(+), 90 deletions(-)

(limited to 'lib/Frontend')

diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp
index 4a5a51d..a7942e6 100644
--- a/lib/Frontend/ASTUnit.cpp
+++ b/lib/Frontend/ASTUnit.cpp
@@ -389,7 +389,8 @@ public:
 
   virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers,
                                     llvm::StringRef OriginalFileName,
-                                    std::string &SuggestedPredefines) {
+                                    std::string &SuggestedPredefines,
+                                    FileManager &FileMgr) {
     Predefines = Buffers[0].Data;
     for (unsigned I = 1, N = Buffers.size(); I != N; ++I) {
       Predefines += Buffers[I].Data;
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index 103d251..b9d15ad 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -78,6 +78,8 @@ static void AnalyzerOptsToArgs(const AnalyzerOptions &Opts,
                                std::vector<std::string> &Res) {
   for (unsigned i = 0, e = Opts.AnalysisList.size(); i != e; ++i)
     Res.push_back(getAnalysisName(Opts.AnalysisList[i]));
+  if (Opts.ShowCheckerHelp)
+    Res.push_back("-analyzer-checker-help");
   if (Opts.AnalysisStoreOpt != BasicStoreModel) {
     Res.push_back("-analyzer-store");
     Res.push_back(getAnalysisStoreName(Opts.AnalysisStoreOpt));
@@ -114,8 +116,6 @@ static void AnalyzerOptsToArgs(const AnalyzerOptions &Opts,
     Res.push_back("-analyzer-viz-egraph-ubigraph");
   if (Opts.EnableExperimentalChecks)
     Res.push_back("-analyzer-experimental-checks");
-  if (Opts.EnableExperimentalInternalChecks)
-    Res.push_back("-analyzer-experimental-internal-checks");
   if (Opts.BufferOverflows)
     Res.push_back("-analyzer-check-buffer-overflows");
 
@@ -473,11 +473,6 @@ static void HeaderSearchOptsToArgs(const HeaderSearchOptions &Opts,
     Res.push_back(Opts.Sysroot);
   }
 
-  for (unsigned i = 0, e = Opts.CXXSystemIncludes.size(); i != e; ++i) {
-    Res.push_back("-cxx-system-include");
-    Res.push_back(Opts.CXXSystemIncludes[i]);
-  }
-
   /// User specified include entries.
   for (unsigned i = 0, e = Opts.UserEntries.size(); i != e; ++i) {
     const HeaderSearchOptions::Entry &E = Opts.UserEntries[i];
@@ -490,6 +485,8 @@ static void HeaderSearchOptsToArgs(const HeaderSearchOptions &Opts,
         Res.push_back("-iquote");
       } else if (E.Group == frontend::System) {
         Res.push_back("-isystem");
+      } else if (E.Group == frontend::CXXSystem) {
+        Res.push_back("-cxx-isystem");
       } else {
         assert(E.Group == frontend::Angled && "Invalid group!");
         Res.push_back(E.IsFramework ? "-F" : "-I");
@@ -588,10 +585,12 @@ static void LangOptsToArgs(const LangOptions &Opts,
     Res.push_back("-faltivec");
   if (Opts.Exceptions)
     Res.push_back("-fexceptions");
+  if (Opts.ObjCExceptions)
+    Res.push_back("-fobjc-exceptions");
+  if (Opts.CXXExceptions)
+    Res.push_back("-fcxx-exceptions");
   if (Opts.SjLjExceptions)
     Res.push_back("-fsjlj-exceptions");
-  if (!Opts.ObjCExceptions)
-    Res.push_back("-fno-objc-exceptions");
   if (!Opts.RTTI)
     Res.push_back("-fno-rtti");
   if (Opts.MSBitfields)
@@ -862,6 +861,7 @@ static void ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args,
       Opts.AnalysisDiagOpt = Value;
   }
 
+  Opts.ShowCheckerHelp = Args.hasArg(OPT_analyzer_checker_help);
   Opts.VisualizeEGDot = Args.hasArg(OPT_analyzer_viz_egraph_graphviz);
   Opts.VisualizeEGUbi = Args.hasArg(OPT_analyzer_viz_egraph_ubigraph);
   Opts.AnalyzeAll = Args.hasArg(OPT_analyzer_opt_analyze_headers);
@@ -876,8 +876,6 @@ static void ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args,
   Opts.CFGAddImplicitDtors = Args.hasArg(OPT_analysis_CFGAddImplicitDtors);
   Opts.CFGAddInitializers = Args.hasArg(OPT_analysis_CFGAddInitializers);
   Opts.EnableExperimentalChecks = Args.hasArg(OPT_analyzer_experimental_checks);
-  Opts.EnableExperimentalInternalChecks =
-    Args.hasArg(OPT_analyzer_experimental_internal_checks);
   Opts.TrimGraph = Args.hasArg(OPT_trim_egraph);
   Opts.MaxNodes = Args.getLastArgIntValue(OPT_analyzer_max_nodes, 150000,Diags);
   Opts.MaxLoop = Args.getLastArgIntValue(OPT_analyzer_max_loop, 4, Diags);
@@ -892,8 +890,13 @@ static void ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args,
     const Arg *A = *it;
     A->claim();
     bool enable = (A->getOption().getID() == OPT_analyzer_checker);
-    Opts.CheckersControlList.push_back(std::make_pair(A->getValue(Args),
-                                                      enable));
+    // We can have a list of comma separated checker names, e.g:
+    // '-analyzer-checker=cocoa,unix'
+    llvm::StringRef checkerList = A->getValue(Args);
+    llvm::SmallVector<llvm::StringRef, 4> checkers;
+    checkerList.split(checkers, ",");
+    for (unsigned i = 0, e = checkers.size(); i != e; ++i)
+      Opts.CheckersControlList.push_back(std::make_pair(checkers[i], enable));
   }
 }
 
@@ -1236,7 +1239,6 @@ std::string CompilerInvocation::GetResourcesPath(const char *Argv0,
 
 static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) {
   using namespace cc1options;
-  Opts.CXXSystemIncludes = Args.getAllArgValues(OPT_cxx_system_include);
   Opts.Sysroot = Args.getLastArgValue(OPT_isysroot, "/");
   Opts.Verbose = Args.hasArg(OPT_v);
   Opts.UseBuiltinIncludes = !Args.hasArg(OPT_nobuiltininc);
@@ -1272,10 +1274,12 @@ static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) {
   for (arg_iterator it = Args.filtered_begin(OPT_iquote),
          ie = Args.filtered_end(); it != ie; ++it)
     Opts.AddPath((*it)->getValue(Args), frontend::Quoted, true, false, true);
-  for (arg_iterator it = Args.filtered_begin(OPT_isystem, OPT_iwithsysroot),
-         ie = Args.filtered_end(); it != ie; ++it)
-    Opts.AddPath((*it)->getValue(Args), frontend::System, true, false,
-                 (*it)->getOption().matches(OPT_iwithsysroot));
+  for (arg_iterator it = Args.filtered_begin(OPT_cxx_isystem, OPT_isystem,
+         OPT_iwithsysroot), ie = Args.filtered_end(); it != ie; ++it)
+    Opts.AddPath((*it)->getValue(Args),
+                 ((*it)->getOption().matches(OPT_cxx_isystem) ?
+                   frontend::CXXSystem : frontend::System),
+                 true, false, (*it)->getOption().matches(OPT_iwithsysroot));
 
   // FIXME: Need options for the various environment variables!
 }
@@ -1457,7 +1461,10 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
   if (Args.hasArg(OPT_fno_threadsafe_statics))
     Opts.ThreadsafeStatics = 0;
   Opts.Exceptions = Args.hasArg(OPT_fexceptions);
-  Opts.ObjCExceptions = !Args.hasArg(OPT_fno_objc_exceptions);
+  Opts.ObjCExceptions = Args.hasArg(OPT_fobjc_exceptions);
+  Opts.CXXExceptions = Args.hasArg(OPT_fcxx_exceptions);
+  Opts.SjLjExceptions = Args.hasArg(OPT_fsjlj_exceptions);
+
   Opts.RTTI = !Args.hasArg(OPT_fno_rtti);
   Opts.Blocks = Args.hasArg(OPT_fblocks);
   Opts.CharIsSigned = !Args.hasArg(OPT_fno_signed_char);
@@ -1486,8 +1493,6 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
   Opts.CatchUndefined = Args.hasArg(OPT_fcatch_undefined_behavior);
   Opts.EmitAllDecls = Args.hasArg(OPT_femit_all_decls);
   Opts.PICLevel = Args.getLastArgIntValue(OPT_pic_level, 0, Diags);
-  Opts.SjLjExceptions = Args.hasArg(OPT_fsjlj_exceptions);
-  Opts.ObjCExceptions = !Args.hasArg(OPT_fno_objc_exceptions);
   Opts.Static = Args.hasArg(OPT_static_define);
   Opts.DumpRecordLayouts = Args.hasArg(OPT_fdump_record_layouts);
   Opts.DumpVTableLayouts = Args.hasArg(OPT_fdump_vtable_layouts);
@@ -1658,8 +1663,11 @@ void CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
   InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), *Args, Diags);
   ParseCodeGenArgs(Res.getCodeGenOpts(), *Args, DashX, Diags);
   ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), *Args);
-  if (DashX != IK_AST && DashX != IK_LLVM_IR)
+  if (DashX != IK_AST && DashX != IK_LLVM_IR) {
     ParseLangArgs(Res.getLangOpts(), *Args, DashX, Diags);
+    if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
+      Res.getLangOpts().ObjCExceptions = 1;
+  }
   // FIXME: ParsePreprocessorArgs uses the FileManager to read the contents of
   // PCH file and find the original header name. Remove the need to do that in
   // ParsePreprocessorArgs and remove the FileManager 
diff --git a/lib/Frontend/DocumentXML.cpp b/lib/Frontend/DocumentXML.cpp
index b24ece5..a09db0b 100644
--- a/lib/Frontend/DocumentXML.cpp
+++ b/lib/Frontend/DocumentXML.cpp
@@ -14,6 +14,7 @@
 
 #include "clang/Frontend/DocumentXML.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/Basic/SourceManager.h"
 #include "llvm/ADT/StringExtras.h"
@@ -218,6 +219,10 @@ void DocumentXML::addPtrAttribute(const char* pAttributeName,
     addPtrAttribute(pAttributeName, pNNS->getAsNamespace());
     break;
   }
+  case NestedNameSpecifier::NamespaceAlias: {
+    addPtrAttribute(pAttributeName, pNNS->getAsNamespaceAlias());
+    break;
+  }
   case NestedNameSpecifier::TypeSpec: {
     addPtrAttribute(pAttributeName, pNNS->getAsType());
     break;
diff --git a/lib/Frontend/InitHeaderSearch.cpp b/lib/Frontend/InitHeaderSearch.cpp
index 4855b62..2e3162c 100644
--- a/lib/Frontend/InitHeaderSearch.cpp
+++ b/lib/Frontend/InitHeaderSearch.cpp
@@ -42,7 +42,9 @@ namespace {
 ///  a HeaderSearch object. InitHeaderSearch stores several search path lists
 ///  internally, which can be sent to a HeaderSearch object in one swoop.
 class InitHeaderSearch {
-  std::vector<DirectoryLookup> IncludeGroup[4];
+  std::vector<std::pair<IncludeDirGroup, DirectoryLookup> > IncludePath;
+  typedef std::vector<std::pair<IncludeDirGroup,
+                      DirectoryLookup> >::const_iterator path_iterator;
   HeaderSearch& Headers;
   bool Verbose;
   std::string IncludeSysroot;
@@ -94,7 +96,7 @@ public:
 
   /// Realize - Merges all search path lists into one list and send it to
   /// HeaderSearch.
-  void Realize();
+  void Realize(const LangOptions &Lang);
 };
 
 }
@@ -131,8 +133,8 @@ void InitHeaderSearch::AddPath(const llvm::Twine &Path,
 
   // If the directory exists, add it.
   if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) {
-    IncludeGroup[Group].push_back(DirectoryLookup(DE, Type, isUserSupplied,
-                                                  isFramework));
+    IncludePath.push_back(std::make_pair(Group, DirectoryLookup(DE, Type,
+                          isUserSupplied, isFramework)));
     return;
   }
 
@@ -142,7 +144,8 @@ void InitHeaderSearch::AddPath(const llvm::Twine &Path,
     if (const FileEntry *FE = FM.getFile(MappedPathStr)) {
       if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) {
         // It is a headermap, add it to the search path.
-        IncludeGroup[Group].push_back(DirectoryLookup(HM, Type,isUserSupplied));
+        IncludePath.push_back(std::make_pair(Group, DirectoryLookup(HM, Type,
+                              isUserSupplied)));
         return;
       }
     }
@@ -179,29 +182,29 @@ void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(llvm::StringRef Base,
                                                    llvm::StringRef Dir64,
                                                    const llvm::Triple &triple) {
   // Add the base dir
-  AddPath(Base, System, true, false, false);
+  AddPath(Base, CXXSystem, true, false, false);
 
   // Add the multilib dirs
   llvm::Triple::ArchType arch = triple.getArch();
   bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64;
   if (is64bit)
-    AddPath(Base + "/" + ArchDir + "/" + Dir64, System, true, false, false);
+    AddPath(Base + "/" + ArchDir + "/" + Dir64, CXXSystem, true, false, false);
   else
-    AddPath(Base + "/" + ArchDir + "/" + Dir32, System, true, false, false);
+    AddPath(Base + "/" + ArchDir + "/" + Dir32, CXXSystem, true, false, false);
 
   // Add the backward dir
-  AddPath(Base + "/backward", System, true, false, false);
+  AddPath(Base + "/backward", CXXSystem, true, false, false);
 }
 
 void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(llvm::StringRef Base,
                                                      llvm::StringRef Arch,
                                                      llvm::StringRef Version) {
   AddPath(Base + "/" + Arch + "/" + Version + "/include/c++",
-          System, true, false, false);
+          CXXSystem, true, false, false);
   AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch,
-          System, true, false, false);
+          CXXSystem, true, false, false);
   AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward",
-          System, true, false, false);
+          CXXSystem, true, false, false);
 }
 
   // FIXME: This probably should goto to some platform utils place.
@@ -567,13 +570,17 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) {
     break;
   case llvm::Triple::MinGW32:
     // mingw-w64-20110207
-    AddPath("c:/MinGW/include/c++/4.5.3", System, true, false, false);
-    AddPath("c:/MinGW/include/c++/4.5.3/x86_64-w64-mingw32", System, true, false, false);
-    AddPath("c:/MinGW/include/c++/4.5.3/backward", System, true, false, false);
+    AddPath("c:/MinGW/include/c++/4.5.3", CXXSystem, true, false, false);
+    AddPath("c:/MinGW/include/c++/4.5.3/x86_64-w64-mingw32", CXXSystem, true,
+            false, false);
+    AddPath("c:/MinGW/include/c++/4.5.3/backward", CXXSystem, true, false,
+            false);
     // mingw-w64-20101129
-    AddPath("c:/MinGW/include/c++/4.5.2", System, true, false, false);
-    AddPath("c:/MinGW/include/c++/4.5.2/x86_64-w64-mingw32", System, true, false, false);
-    AddPath("c:/MinGW/include/c++/4.5.2/backward", System, true, false, false);
+    AddPath("c:/MinGW/include/c++/4.5.2", CXXSystem, true, false, false);
+    AddPath("c:/MinGW/include/c++/4.5.2/x86_64-w64-mingw32", CXXSystem, true,
+            false, false);
+    AddPath("c:/MinGW/include/c++/4.5.2/backward", CXXSystem, true, false,
+            false);
     // Try gcc 4.5.0
     AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0");
     // Try gcc 4.4.0
@@ -613,7 +620,7 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) {
     }
     break;
   case llvm::Triple::DragonFly:
-    AddPath("/usr/include/c++/4.1", System, true, false, false);
+    AddPath("/usr/include/c++/4.1", CXXSystem, true, false, false);
     break;
   case llvm::Triple::Linux:
     //===------------------------------------------------------------------===//
@@ -809,13 +816,8 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) {
 void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang,
                                                     const llvm::Triple &triple,
                                             const HeaderSearchOptions &HSOpts) {
-  if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes) {
-    if (!HSOpts.CXXSystemIncludes.empty()) {
-      for (unsigned i = 0, e = HSOpts.CXXSystemIncludes.size(); i != e; ++i)
-        AddPath(HSOpts.CXXSystemIncludes[i], System, true, false, false);
-    } else
-      AddDefaultCPlusPlusIncludePaths(triple);
-  }
+  if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes)
+    AddDefaultCPlusPlusIncludePaths(triple);
 
   AddDefaultCIncludePaths(triple, HSOpts);
 
@@ -829,11 +831,11 @@ void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang,
 /// RemoveDuplicates - If there are duplicate directory entries in the specified
 /// search list, remove the later (dead) ones.
 static void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList,
-                             bool Verbose) {
+                             unsigned First, bool Verbose) {
   llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs;
   llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs;
   llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps;
-  for (unsigned i = 0; i != SearchList.size(); ++i) {
+  for (unsigned i = First; i != SearchList.size(); ++i) {
     unsigned DirToRemove = i;
 
     const DirectoryLookup &CurEntry = SearchList[i];
@@ -908,32 +910,49 @@ static void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList,
 }
 
 
-void InitHeaderSearch::Realize() {
+void InitHeaderSearch::Realize(const LangOptions &Lang) {
   // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList.
   std::vector<DirectoryLookup> SearchList;
-  SearchList = IncludeGroup[Angled];
-  SearchList.insert(SearchList.end(), IncludeGroup[System].begin(),
-                    IncludeGroup[System].end());
-  SearchList.insert(SearchList.end(), IncludeGroup[After].begin(),
-                    IncludeGroup[After].end());
-  RemoveDuplicates(SearchList, Verbose);
-  RemoveDuplicates(IncludeGroup[Quoted], Verbose);
+  SearchList.reserve(IncludePath.size());
+
+  /* Quoted arguments go first. */
+  for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
+       it != ie; ++it) {
+    if (it->first == Quoted)
+      SearchList.push_back(it->second);
+  }
+  /* Deduplicate and remember index */
+  RemoveDuplicates(SearchList, 0, Verbose);
+  unsigned quoted = SearchList.size();
+
+  for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
+       it != ie; ++it) {
+    if (it->first == Angled)
+      SearchList.push_back(it->second);
+  }
 
-  // Prepend QUOTED list on the search list.
-  SearchList.insert(SearchList.begin(), IncludeGroup[Quoted].begin(),
-                    IncludeGroup[Quoted].end());
+  for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
+       it != ie; ++it) {
+    if (it->first == System || (Lang.CPlusPlus && it->first == CXXSystem))
+      SearchList.push_back(it->second);
+  }
+
+  for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
+       it != ie; ++it) {
+    if (it->first == After)
+      SearchList.push_back(it->second);
+  }
 
+  RemoveDuplicates(SearchList, quoted, Verbose);
 
   bool DontSearchCurDir = false;  // TODO: set to true if -I- is set?
-  Headers.SetSearchPaths(SearchList, IncludeGroup[Quoted].size(),
-                         DontSearchCurDir);
+  Headers.SetSearchPaths(SearchList, quoted, DontSearchCurDir);
 
   // If verbose, print the list of directories that will be searched.
   if (Verbose) {
     llvm::errs() << "#include \"...\" search starts here:\n";
-    unsigned QuotedIdx = IncludeGroup[Quoted].size();
     for (unsigned i = 0, e = SearchList.size(); i != e; ++i) {
-      if (i == QuotedIdx)
+      if (i == quoted)
         llvm::errs() << "#include <...> search starts here:\n";
       const char *Name = SearchList[i].getName();
       const char *Suffix;
@@ -978,5 +997,5 @@ void clang::ApplyHeaderSearchOptions(HeaderSearch &HS,
   if (HSOpts.UseStandardIncludes)
     Init.AddDefaultSystemIncludePaths(Lang, Triple, HSOpts);
 
-  Init.Realize();
+  Init.Realize(Lang);
 }
diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp
index d0111a5..91b5280 100644
--- a/lib/Frontend/InitPreprocessor.cpp
+++ b/lib/Frontend/InitPreprocessor.cpp
@@ -48,12 +48,13 @@ static void DefineBuiltinMacro(MacroBuilder &Builder, llvm::StringRef Macro,
   }
 }
 
-std::string clang::NormalizeDashIncludePath(llvm::StringRef File) {
+std::string clang::NormalizeDashIncludePath(llvm::StringRef File,
+                                            FileManager &FileMgr) {
   // Implicit include paths should be resolved relative to the current
   // working directory first, and then use the regular header search
   // mechanism. The proper way to handle this is to have the
   // predefines buffer located at the current working directory, but
-  // it has not file entry. For now, workaround this by using an
+  // it has no file entry. For now, workaround this by using an
   // absolute path if we find the file here, and otherwise letting
   // header search handle it.
   llvm::SmallString<128> Path(File);
@@ -61,21 +62,25 @@ std::string clang::NormalizeDashIncludePath(llvm::StringRef File) {
   bool exists;
   if (llvm::sys::fs::exists(Path.str(), exists) || !exists)
     Path = File;
+  else if (exists)
+    FileMgr.getFile(File);
 
   return Lexer::Stringify(Path.str());
 }
 
 /// AddImplicitInclude - Add an implicit #include of the specified file to the
 /// predefines buffer.
-static void AddImplicitInclude(MacroBuilder &Builder, llvm::StringRef File) {
+static void AddImplicitInclude(MacroBuilder &Builder, llvm::StringRef File,
+                               FileManager &FileMgr) {
   Builder.append("#include \"" +
-                 llvm::Twine(NormalizeDashIncludePath(File)) + "\"");
+                 llvm::Twine(NormalizeDashIncludePath(File, FileMgr)) + "\"");
 }
 
 static void AddImplicitIncludeMacros(MacroBuilder &Builder,
-                                     llvm::StringRef File) {
+                                     llvm::StringRef File,
+                                     FileManager &FileMgr) {
   Builder.append("#__include_macros \"" +
-                 llvm::Twine(NormalizeDashIncludePath(File)) + "\"");
+                 llvm::Twine(NormalizeDashIncludePath(File, FileMgr)) + "\"");
   // Marker token to stop the __include_macros fetch loop.
   Builder.append("##"); // ##?
 }
@@ -94,7 +99,7 @@ static void AddImplicitIncludePTH(MacroBuilder &Builder, Preprocessor &PP,
     return;
   }
 
-  AddImplicitInclude(Builder, OriginalFile);
+  AddImplicitInclude(Builder, OriginalFile, PP.getFileManager());
 }
 
 /// PickFP - This is used to pick a value based on the FP semantics of the
@@ -169,15 +174,10 @@ static void DefineFloatMacros(MacroBuilder &Builder, llvm::StringRef Prefix,
 /// signedness of 'isSigned' and with a value suffix of 'ValSuffix' (e.g. LL).
 static void DefineTypeSize(llvm::StringRef MacroName, unsigned TypeWidth,
                            llvm::StringRef ValSuffix, bool isSigned,
-                           MacroBuilder& Builder) {
-  long long MaxVal;
-  if (isSigned) {
-    assert(TypeWidth != 1);
-    MaxVal = ~0ULL >> (65-TypeWidth);
-  } else
-    MaxVal = ~0ULL >> (64-TypeWidth);
-
-  Builder.defineMacro(MacroName, llvm::Twine(MaxVal) + ValSuffix);
+                           MacroBuilder &Builder) {
+  llvm::APInt MaxVal = isSigned ? llvm::APInt::getSignedMaxValue(TypeWidth)
+                                : llvm::APInt::getMaxValue(TypeWidth);
+  Builder.defineMacro(MacroName, MaxVal.toString(10, isSigned) + ValSuffix);
 }
 
 /// DefineTypeSize - An overloaded helper that uses TargetInfo to determine
@@ -590,7 +590,8 @@ void clang::InitializePreprocessor(Preprocessor &PP,
   // If -imacros are specified, include them now.  These are processed before
   // any -include directives.
   for (unsigned i = 0, e = InitOpts.MacroIncludes.size(); i != e; ++i)
-    AddImplicitIncludeMacros(Builder, InitOpts.MacroIncludes[i]);
+    AddImplicitIncludeMacros(Builder, InitOpts.MacroIncludes[i],
+                             PP.getFileManager());
 
   // Process -include directives.
   for (unsigned i = 0, e = InitOpts.Includes.size(); i != e; ++i) {
@@ -598,7 +599,7 @@ void clang::InitializePreprocessor(Preprocessor &PP,
     if (Path == InitOpts.ImplicitPTHInclude)
       AddImplicitIncludePTH(Builder, PP, Path);
     else
-      AddImplicitInclude(Builder, Path);
+      AddImplicitInclude(Builder, Path, PP.getFileManager());
   }
 
   // Exit the command line and go back to <built-in> (2 is LC_LEAVE).
diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp
index 04c6a68..0849153 100644
--- a/lib/Frontend/TextDiagnosticPrinter.cpp
+++ b/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -905,9 +905,21 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
 
   std::string OptionName;
   if (DiagOpts->ShowOptionNames) {
+    // Was this a warning mapped to an error using -Werror or pragma?
+    if (Level == Diagnostic::Error &&
+        DiagnosticIDs::isBuiltinWarningOrExtension(Info.getID())) {
+      diag::Mapping mapping = diag::MAP_IGNORE;
+      Info.getDiags()->getDiagnosticLevel(Info.getID(), Info.getLocation(), 
+                                          &mapping);
+      if (mapping == diag::MAP_WARNING)
+        OptionName += "-Werror";
+    }
+
     if (const char *
           Opt = DiagnosticIDs::getWarningOptionForDiag(Info.getID())) {
-      OptionName = "-W";
+      if (!OptionName.empty())
+        OptionName += ',';
+      OptionName += "-W";
       OptionName += Opt;
     } else if (Info.getID() == diag::fatal_too_many_errors) {
       OptionName = "-ferror-limit=";
diff --git a/lib/Frontend/VerifyDiagnosticsClient.cpp b/lib/Frontend/VerifyDiagnosticsClient.cpp
index 51b351f..fff417e 100644
--- a/lib/Frontend/VerifyDiagnosticsClient.cpp
+++ b/lib/Frontend/VerifyDiagnosticsClient.cpp
@@ -369,7 +369,7 @@ static unsigned PrintProblem(Diagnostic &Diags, SourceManager *SourceMgr,
     if (I->first.isInvalid() || !SourceMgr)
       OS << "\n  (frontend)";
     else
-      OS << "\n  Line " << SourceMgr->getInstantiationLineNumber(I->first);
+      OS << "\n  Line " << SourceMgr->getPresumedLineNumber(I->first);
     OS << ": " << I->second;
   }
 
@@ -391,7 +391,7 @@ static unsigned PrintProblem(Diagnostic &Diags, SourceManager *SourceMgr,
     if (D.Location.isInvalid() || !SourceMgr)
       OS << "\n  (frontend)";
     else
-      OS << "\n  Line " << SourceMgr->getInstantiationLineNumber(D.Location);
+      OS << "\n  Line " << SourceMgr->getPresumedLineNumber(D.Location);
     OS << ": " << D.Text;
   }
 
@@ -413,12 +413,12 @@ static unsigned CheckLists(Diagnostic &Diags, SourceManager &SourceMgr,
 
   for (DirectiveList::iterator I = Left.begin(), E = Left.end(); I != E; ++I) {
     Directive& D = **I;
-    unsigned LineNo1 = SourceMgr.getInstantiationLineNumber(D.Location);
+    unsigned LineNo1 = SourceMgr.getPresumedLineNumber(D.Location);
 
     for (unsigned i = 0; i < D.Count; ++i) {
       DiagList::iterator II, IE;
       for (II = Right.begin(), IE = Right.end(); II != IE; ++II) {
-        unsigned LineNo2 = SourceMgr.getInstantiationLineNumber(II->first);
+        unsigned LineNo2 = SourceMgr.getPresumedLineNumber(II->first);
         if (LineNo1 != LineNo2)
           continue;
 
-- 
cgit v1.1