[llvm-branch-commits] [cfe-branch] r154991 - in /cfe/branches/tooling: ./ include/clang/AST/ include/clang/Analysis/ include/clang/Basic/ include/clang/Frontend/ include/clang/Tooling/ lib/AST/ lib/Frontend/ lib/Rewrite/ lib/Sema/ lib/Tooling/ test/CodeGenCXX/ test/Misc/ test/Parser/ test/Rewriter/ test/SemaCXX/ test/SemaTemplate/ test/Tooling/ tools/clang-check/ unittests/Tooling/

Manuel Klimek klimek at google.com
Wed Apr 18 00:59:17 PDT 2012


Author: klimek
Date: Wed Apr 18 02:59:17 2012
New Revision: 154991

URL: http://llvm.org/viewvc/llvm-project?rev=154991&view=rev
Log:
Merging mainline.


Added:
    cfe/branches/tooling/test/Misc/unprintable.c
      - copied unchanged from r154990, cfe/trunk/test/Misc/unprintable.c
    cfe/branches/tooling/test/Misc/wnull-character.cpp
      - copied unchanged from r154990, cfe/trunk/test/Misc/wnull-character.cpp
    cfe/branches/tooling/test/Misc/wrong-encoding.c
      - copied unchanged from r154990, cfe/trunk/test/Misc/wrong-encoding.c
    cfe/branches/tooling/test/Rewriter/rewrite-modern-extern-c-func-decl.mm
      - copied unchanged from r154990, cfe/trunk/test/Rewriter/rewrite-modern-extern-c-func-decl.mm
    cfe/branches/tooling/test/Tooling/clang-check-args.cpp
      - copied unchanged from r154990, cfe/trunk/test/Tooling/clang-check-args.cpp
Modified:
    cfe/branches/tooling/   (props changed)
    cfe/branches/tooling/include/clang/AST/Decl.h
    cfe/branches/tooling/include/clang/Analysis/ProgramPoint.h
    cfe/branches/tooling/include/clang/Basic/BuiltinsHexagon.def
    cfe/branches/tooling/include/clang/Basic/ConvertUTF.h
    cfe/branches/tooling/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/branches/tooling/include/clang/Frontend/TextDiagnostic.h
    cfe/branches/tooling/include/clang/Tooling/CompilationDatabase.h
    cfe/branches/tooling/lib/AST/Decl.cpp
    cfe/branches/tooling/lib/Frontend/TextDiagnostic.cpp
    cfe/branches/tooling/lib/Rewrite/RewriteModernObjC.cpp
    cfe/branches/tooling/lib/Sema/SemaAccess.cpp
    cfe/branches/tooling/lib/Sema/SemaDecl.cpp
    cfe/branches/tooling/lib/Sema/SemaTemplateInstantiateDecl.cpp
    cfe/branches/tooling/lib/Tooling/CompilationDatabase.cpp
    cfe/branches/tooling/test/CodeGenCXX/cxx11-exception-spec.cpp
    cfe/branches/tooling/test/Misc/message-length.c
    cfe/branches/tooling/test/Parser/MicrosoftExtensions.cpp
    cfe/branches/tooling/test/SemaCXX/warn-unreachable.cpp   (props changed)
    cfe/branches/tooling/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
    cfe/branches/tooling/tools/clang-check/ClangCheck.cpp
    cfe/branches/tooling/unittests/Tooling/CompilationDatabaseTest.cpp

Propchange: cfe/branches/tooling/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Apr 18 02:59:17 2012
@@ -1,3 +1,3 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:146581-154921
+/cfe/trunk:146581-154990
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/tooling/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/AST/Decl.h?rev=154991&r1=154990&r2=154991&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/AST/Decl.h (original)
+++ cfe/branches/tooling/include/clang/AST/Decl.h Wed Apr 18 02:59:17 2012
@@ -245,7 +245,6 @@
     bool visibilityExplicit() const { return explicit_; }
 
     void setLinkage(Linkage L) { linkage_ = L; }
-    void setVisibility(Visibility V) { visibility_ = V; }
     void setVisibility(Visibility V, bool E) { visibility_ = V; explicit_ = E; }
 
     void mergeLinkage(Linkage L) {

Modified: cfe/branches/tooling/include/clang/Analysis/ProgramPoint.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Analysis/ProgramPoint.h?rev=154991&r1=154990&r2=154991&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Analysis/ProgramPoint.h (original)
+++ cfe/branches/tooling/include/clang/Analysis/ProgramPoint.h Wed Apr 18 02:59:17 2012
@@ -129,7 +129,7 @@
   static bool classof(const ProgramPoint*) { return true; }
 
   bool operator==(const ProgramPoint & RHS) const {
-    return Data1 == Data1 &&
+    return Data1 == RHS.Data1 &&
            Data2 == RHS.Data2 &&
            L == RHS.L &&
            Tag == RHS.Tag;

Modified: cfe/branches/tooling/include/clang/Basic/BuiltinsHexagon.def
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Basic/BuiltinsHexagon.def?rev=154991&r1=154990&r2=154991&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Basic/BuiltinsHexagon.def (original)
+++ cfe/branches/tooling/include/clang/Basic/BuiltinsHexagon.def Wed Apr 18 02:59:17 2012
@@ -1,10 +1,26 @@
+//===-- BuiltinsHexagon.def - Hexagon Builtin function database --*- C++ -*-==//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the Hexagon-specific builtin function database.  Users of
+// this file must define the BUILTIN macro to make use of this information.
+//
+//===----------------------------------------------------------------------===//
 
-// This one below is not generated from the autogenerated iset.py.
-// So make sure you donot overwrite this one.
+// The format of this database matches clang/Basic/Builtins.def.
+
+
+// This ones below are not autogenerated from iset.py.
+// Make sure you do not overwrite these.
 BUILTIN(__builtin_SI_to_SXTHI_asrh, "ii", "")
 BUILTIN(__builtin_circ_ldd, "LLi*LLi*LLi*ii", "")
-// This one above is not generated from the autogenerated iset.py.
-// So make sure you donot overwrite this one.
+// This ones above are not autogenerated from iset.py.
+// Make sure you do not overwrite these.
 
 BUILTIN(__builtin_HEXAGON_C2_cmpeq,"bii","")
 BUILTIN(__builtin_HEXAGON_C2_cmpgt,"bii","")

Modified: cfe/branches/tooling/include/clang/Basic/ConvertUTF.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Basic/ConvertUTF.h?rev=154991&r1=154990&r2=154991&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Basic/ConvertUTF.h (original)
+++ cfe/branches/tooling/include/clang/Basic/ConvertUTF.h Wed Apr 18 02:59:17 2012
@@ -151,9 +151,9 @@
 ConversionResult ConvertUTF32toUTF16 (
   const UTF32** sourceStart, const UTF32* sourceEnd,
   UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
+#endif
 
 Boolean isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd);
-#endif
 
 Boolean isLegalUTF8String(const UTF8 *source, const UTF8 *sourceEnd);
 

Modified: cfe/branches/tooling/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Basic/DiagnosticSemaKinds.td?rev=154991&r1=154990&r2=154991&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/branches/tooling/include/clang/Basic/DiagnosticSemaKinds.td Wed Apr 18 02:59:17 2012
@@ -3912,7 +3912,7 @@
 def err_nogetter_property_compound_assignment : Error<
   "a getter method is needed to perform a compound assignment on a property">;
 def err_nogetter_property_incdec : Error<
-  "no getter method %1 for %select{increment|decrement} of property">;
+  "no getter method %1 for %select{increment|decrement}0 of property">;
 def error_no_subobject_property_setting : Error<
   "expression is not assignable">;
 def err_qualified_objc_access : Error<

Modified: cfe/branches/tooling/include/clang/Frontend/TextDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Frontend/TextDiagnostic.h?rev=154991&r1=154990&r2=154991&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Frontend/TextDiagnostic.h (original)
+++ cfe/branches/tooling/include/clang/Frontend/TextDiagnostic.h Wed Apr 18 02:59:17 2012
@@ -18,6 +18,8 @@
 
 #include "clang/Frontend/DiagnosticRenderer.h"
 
+struct SourceColumnMap;
+
 namespace clang {
 
 /// \brief Class to encapsulate the logic for formatting and printing a textual
@@ -103,15 +105,16 @@
                            SmallVectorImpl<CharSourceRange>& Ranges,
                            ArrayRef<FixItHint> Hints);
 
+  void emitSnippet(StringRef SourceLine);
+
   void highlightRange(const CharSourceRange &R,
                       unsigned LineNo, FileID FID,
-                      const std::string &SourceLine,
+                      const SourceColumnMap &map,
                       std::string &CaretLine);
+
   std::string buildFixItInsertionLine(unsigned LineNo,
-                                      const char *LineStart,
-                                      const char *LineEnd,
+                                      const SourceColumnMap &map,
                                       ArrayRef<FixItHint> Hints);
-  void expandTabs(std::string &SourceLine, std::string &CaretLine);
   void emitParseableFixits(ArrayRef<FixItHint> Hints);
 };
 

Modified: cfe/branches/tooling/include/clang/Tooling/CompilationDatabase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Tooling/CompilationDatabase.h?rev=154991&r1=154990&r2=154991&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Tooling/CompilationDatabase.h (original)
+++ cfe/branches/tooling/include/clang/Tooling/CompilationDatabase.h Wed Apr 18 02:59:17 2012
@@ -33,22 +33,21 @@
 #include "llvm/ADT/OwningPtr.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/SourceMgr.h"
+#include "llvm/Support/YAMLParser.h"
 #include <string>
 #include <vector>
 
-namespace llvm {
-class MemoryBuffer;
-} // end namespace llvm
-
 namespace clang {
 namespace tooling {
 
 /// \brief Specifies the working directory and command of a compilation.
 struct CompileCommand {
   CompileCommand() {}
-  CompileCommand(StringRef Directory, ArrayRef<std::string> CommandLine)
-    : Directory(Directory), CommandLine(CommandLine) {}
+  CompileCommand(Twine Directory, ArrayRef<std::string> CommandLine)
+    : Directory(Directory.str()), CommandLine(CommandLine) {}
 
   /// \brief The working directory the command was executed from.
   std::string Directory;
@@ -95,6 +94,59 @@
     StringRef FilePath) const = 0;
 };
 
+/// \brief A compilation database that returns a single compile command line.
+///
+/// Useful when we want a tool to behave more like a compiler invocation.
+class FixedCompilationDatabase : public CompilationDatabase {
+public:
+  /// \brief Creates a FixedCompilationDatabase from the arguments after "--".
+  ///
+  /// Parses the given command line for "--". If "--" is found, the rest of
+  /// the arguments will make up the command line in the returned
+  /// FixedCompilationDatabase.
+  /// The arguments after "--" must not include positional parameters or the
+  /// argv[0] of the tool. Those will be added by the FixedCompilationDatabase
+  /// when a CompileCommand is requested. The argv[0] of the returned command
+  /// line will be "clang-tool".
+  ///
+  /// Returns NULL in case "--" is not found.
+  ///
+  /// The argument list is meant to be compatible with normal llvm command line
+  /// parsing in main methods.
+  /// int main(int argc, char **argv) {
+  ///   llvm::OwningPtr<FixedCompilationDatabase> Compilations(
+  ///     FixedCompilationDatabase::loadFromCommandLine(argc, argv));
+  ///   cl::ParseCommandLineOptions(argc, argv);
+  ///   ...
+  /// }
+  ///
+  /// \param Argc The number of command line arguments - will be changed to
+  /// the number of arguments before "--", if "--" was found in the argument
+  /// list.
+  /// \param Argv Points to the command line arguments.
+  /// \param Directory The base directory used in the FixedCompilationDatabase.
+  static FixedCompilationDatabase *loadFromCommandLine(int &Argc,
+                                                       const char **Argv,
+                                                       Twine Directory = ".");
+
+  /// \brief Constructs a compilation data base from a specified directory
+  /// and command line.
+  FixedCompilationDatabase(Twine Directory, ArrayRef<std::string> CommandLine);
+
+  /// \brief Returns the given compile command.
+  ///
+  /// Will always return a vector with one entry that contains the directory
+  /// and command line specified at construction with "clang-tool" as argv[0]
+  /// and 'FilePath' as positional argument.
+  virtual std::vector<CompileCommand> getCompileCommands(
+    StringRef FilePath) const;
+
+private:
+  /// This is built up to contain a single entry vector to be returned from
+  /// getCompileCommands after adding the positional argument.
+  std::vector<CompileCommand> CompileCommands;
+};
+
 /// \brief A JSON based compilation database.
 ///
 /// JSON compilation database files must contain a list of JSON objects which
@@ -114,7 +166,6 @@
 /// by setting the flag -DCMAKE_EXPORT_COMPILE_COMMANDS.
 class JSONCompilationDatabase : public CompilationDatabase {
 public:
-
   /// \brief Loads a JSON compilation database from the specified file.
   ///
   /// Returns NULL and sets ErrorMessage if the database could not be
@@ -139,7 +190,7 @@
 private:
   /// \brief Constructs a JSON compilation database on a memory buffer.
   JSONCompilationDatabase(llvm::MemoryBuffer *Database)
-    : Database(Database) {}
+    : Database(Database), YAMLStream(Database->getBuffer(), SM) {}
 
   /// \brief Parses the database file and creates the index.
   ///
@@ -147,14 +198,17 @@
   /// failed.
   bool parse(std::string &ErrorMessage);
 
-  // Tuple (directory, commandline) where 'commandline' is a JSON escaped bash
-  // escaped command line.
-  typedef std::pair<StringRef, StringRef> CompileCommandRef;
+  // Tuple (directory, commandline) where 'commandline' pointing to the
+  // corresponding nodes in the YAML stream.
+  typedef std::pair<llvm::yaml::ScalarNode*,
+                    llvm::yaml::ScalarNode*> CompileCommandRef;
 
   // Maps file paths to the compile command lines for that file.
   llvm::StringMap< std::vector<CompileCommandRef> > IndexByFile;
 
   llvm::OwningPtr<llvm::MemoryBuffer> Database;
+  llvm::SourceMgr SM;
+  llvm::yaml::Stream YAMLStream;
 };
 
 } // end namespace tooling

Modified: cfe/branches/tooling/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/AST/Decl.cpp?rev=154991&r1=154990&r2=154991&view=diff
==============================================================================
--- cfe/branches/tooling/lib/AST/Decl.cpp (original)
+++ cfe/branches/tooling/lib/AST/Decl.cpp Wed Apr 18 02:59:17 2012
@@ -325,8 +325,7 @@
       LinkageInfo TypeLV = getLVForType(Var->getType());
       if (TypeLV.linkage() != ExternalLinkage)
         return LinkageInfo::uniqueExternal();
-      LV.mergeVisibilityWithMin(TypeLV.visibility(),
-                                TypeLV.visibilityExplicit());
+      LV.mergeVisibilityWithMin(TypeLV);
     }
 
     if (Var->getStorageClass() == SC_PrivateExtern)
@@ -581,7 +580,7 @@
     if (TypeLV.linkage() != ExternalLinkage)
       LV.mergeLinkage(UniqueExternalLinkage);
     if (!LV.visibilityExplicit())
-      LV.mergeVisibility(TypeLV.visibility(), TypeLV.visibilityExplicit());
+      LV.mergeVisibility(TypeLV);
   }
 
   return LV;
@@ -786,7 +785,7 @@
       LinkageInfo LV;
       if (Flags.ConsiderVisibilityAttributes) {
         if (llvm::Optional<Visibility> Vis = Function->getExplicitVisibility())
-          LV.setVisibility(*Vis);
+          LV.setVisibility(*Vis, true);
       }
       
       if (const FunctionDecl *Prev = Function->getPreviousDecl()) {
@@ -807,10 +806,10 @@
 
         LinkageInfo LV;
         if (Var->getStorageClass() == SC_PrivateExtern)
-          LV.setVisibility(HiddenVisibility);
+          LV.setVisibility(HiddenVisibility, true);
         else if (Flags.ConsiderVisibilityAttributes) {
           if (llvm::Optional<Visibility> Vis = Var->getExplicitVisibility())
-            LV.setVisibility(*Vis);
+            LV.setVisibility(*Vis, true);
         }
         
         if (const VarDecl *Prev = Var->getPreviousDecl()) {

Modified: cfe/branches/tooling/lib/Frontend/TextDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Frontend/TextDiagnostic.cpp?rev=154991&r1=154990&r2=154991&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Frontend/TextDiagnostic.cpp (original)
+++ cfe/branches/tooling/lib/Frontend/TextDiagnostic.cpp Wed Apr 18 02:59:17 2012
@@ -10,13 +10,17 @@
 #include "clang/Frontend/TextDiagnostic.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Basic/ConvertUTF.h"
 #include "clang/Frontend/DiagnosticOptions.h"
 #include "clang/Lex/Lexer.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/Locale.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringExtras.h"
 #include <algorithm>
+
 using namespace clang;
 
 static const enum raw_ostream::Colors noteColor =
@@ -36,23 +40,268 @@
 /// \brief Number of spaces to indent when word-wrapping.
 const unsigned WordWrapIndentation = 6;
 
+int bytesSincePreviousTabOrLineBegin(StringRef SourceLine, size_t i) {
+  int bytes = 0;
+  while (0<i) {
+    if (SourceLine[--i]=='\t')
+      break;
+    ++bytes;
+  }
+  return bytes;
+}
+
+/// \brief returns a printable representation of first item from input range
+///
+/// This function returns a printable representation of the next item in a line
+///  of source. If the next byte begins a valid and printable character, that
+///  character is returned along with 'true'.
+///
+/// Otherwise, if the next byte begins a valid, but unprintable character, a
+///  printable, escaped representation of the character is returned, along with
+///  'false'. Otherwise a printable, escaped representation of the next byte
+///  is returned along with 'false'.
+///
+/// \note The index is updated to be used with a subsequent call to
+///        printableTextForNextCharacter.
+///
+/// \param SourceLine The line of source
+/// \param i Pointer to byte index,
+/// \param TabStop used to expand tabs
+/// \return pair(printable text, 'true' iff original text was printable)
+///
+std::pair<SmallString<16>,bool>
+printableTextForNextCharacter(StringRef SourceLine, size_t *i,
+                              unsigned TabStop) {
+  assert(i && "i must not be null");
+  assert(*i<SourceLine.size() && "must point to a valid index");
+  
+  if (SourceLine[*i]=='\t') {
+    assert(0 < TabStop && TabStop <= DiagnosticOptions::MaxTabStop &&
+           "Invalid -ftabstop value");
+    unsigned col = bytesSincePreviousTabOrLineBegin(SourceLine, *i);
+    unsigned NumSpaces = TabStop - col%TabStop;
+    assert(0 < NumSpaces && NumSpaces <= TabStop
+           && "Invalid computation of space amt");
+    ++(*i);
+
+    SmallString<16> expandedTab;
+    expandedTab.assign(NumSpaces, ' ');
+    return std::make_pair(expandedTab, true);
+  }
+
+  // FIXME: this data is copied from the private implementation of ConvertUTF.h
+  static const char trailingBytesForUTF8[256] = {
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
+  };
+
+  unsigned char const *begin, *end;
+  begin = reinterpret_cast<unsigned char const *>(&*(SourceLine.begin() + *i));
+  end = begin + SourceLine.size();
+  
+  if (isLegalUTF8Sequence(begin, end)) {
+    UTF32 c;
+    UTF32 *cptr = &c;
+    unsigned char const *original_begin = begin;
+    char trailingBytes = trailingBytesForUTF8[(unsigned char)SourceLine[*i]];
+    unsigned char const *cp_end = begin+trailingBytes+1;
+
+    ConversionResult res = ConvertUTF8toUTF32(&begin, cp_end, &cptr, cptr+1,
+                                              strictConversion);
+    assert(conversionOK==res);
+    assert(0 < begin-original_begin
+           && "we must be further along in the string now");
+    *i += begin-original_begin;
+
+    if (!llvm::sys::locale::isPrint(c)) {
+      // If next character is valid UTF-8, but not printable
+      SmallString<16> expandedCP("<U+>");
+      while (c) {
+        expandedCP.insert(expandedCP.begin()+3, llvm::hexdigit(c%16));
+        c/=16;
+      }
+      while (expandedCP.size() < 8)
+        expandedCP.insert(expandedCP.begin()+3, llvm::hexdigit(0));
+      return std::make_pair(expandedCP, false);
+    }
+
+    // If next character is valid UTF-8, and printable
+    return std::make_pair(SmallString<16>(original_begin, cp_end), true);
+
+  }
+
+  // If next byte is not valid UTF-8 (and therefore not printable)
+  SmallString<16> expandedByte("<XX>");
+  unsigned char byte = SourceLine[*i];
+  expandedByte[1] = llvm::hexdigit(byte / 16);
+  expandedByte[2] = llvm::hexdigit(byte % 16);
+  ++(*i);
+  return std::make_pair(expandedByte, false);
+}
+
+void expandTabs(std::string &SourceLine, unsigned TabStop) {
+  size_t i = SourceLine.size();
+  while (i>0) {
+    i--;
+    if (SourceLine[i]!='\t')
+      continue;
+    size_t tmp_i = i;
+    std::pair<SmallString<16>,bool> res
+      = printableTextForNextCharacter(SourceLine, &tmp_i, TabStop);
+    SourceLine.replace(i, 1, res.first.c_str());
+  }
+}
+
+/// This function takes a raw source line and produces a mapping from the bytes
+///  of the printable representation of the line to the columns those printable
+///  characters will appear at (numbering the first column as 0).
+///
+/// If a byte 'i' corresponds to muliple columns (e.g. the byte contains a tab
+///  character) then the the array will map that byte to the first column the
+///  tab appears at and the next value in the map will have been incremented
+///  more than once.
+///
+/// If a byte is the first in a sequence of bytes that together map to a single
+///  entity in the output, then the array will map that byte to the appropriate
+///  column while the subsequent bytes will be -1.
+///
+/// The last element in the array does not correspond to any byte in the input
+///  and instead is the number of columns needed to display the source
+///
+/// example: (given a tabstop of 8)
+///
+///    "a \t \u3042" -> {0,1,2,8,9,-1,-1,11}
+///
+///  (\u3042 is represented in UTF-8 by three bytes and takes two columns to
+///   display)
+void byteToColumn(StringRef SourceLine, unsigned TabStop,
+                         SmallVectorImpl<int> &out) {
+  out.clear();
+
+  if (SourceLine.empty()) {
+    out.resize(1u,0);
+    return;
+  }
+  
+  out.resize(SourceLine.size()+1, -1);
+
+  int columns = 0;
+  size_t i = 0;
+  while (i<SourceLine.size()) {
+    out[i] = columns;
+    std::pair<SmallString<16>,bool> res
+      = printableTextForNextCharacter(SourceLine, &i, TabStop);
+    columns += llvm::sys::locale::columnWidth(res.first);
+  }
+  out.back() = columns;
+}
+
+/// This function takes a raw source line and produces a mapping from columns
+///  to the byte of the source line that produced the character displaying at
+///  that column. This is the inverse of the mapping produced by byteToColumn()
+///
+/// The last element in the array is the number of bytes in the source string
+///
+/// example: (given a tabstop of 8)
+///
+///    "a \t \u3042" -> {0,1,2,-1,-1,-1,-1,-1,3,4,-1,7}
+///
+///  (\u3042 is represented in UTF-8 by three bytes and takes two columns to
+///   display)
+void columnToByte(StringRef SourceLine, unsigned TabStop,
+                         SmallVectorImpl<int> &out) {
+  out.clear();
+
+  if (SourceLine.empty()) {
+    out.resize(1u, 0);
+    return;
+  }
+
+  int columns = 0;
+  size_t i = 0;
+  while (i<SourceLine.size()) {
+    out.resize(columns+1, -1);
+    out.back() = i;
+    std::pair<SmallString<16>,bool> res
+      = printableTextForNextCharacter(SourceLine, &i, TabStop);
+    columns += llvm::sys::locale::columnWidth(res.first);
+  }
+  out.resize(columns+1, -1);
+  out.back() = i;
+}
+
+struct SourceColumnMap {
+  SourceColumnMap(StringRef SourceLine, unsigned TabStop)
+  : m_SourceLine(SourceLine) {
+    
+    ::byteToColumn(SourceLine, TabStop, m_byteToColumn);
+    ::columnToByte(SourceLine, TabStop, m_columnToByte);
+    
+    assert(m_byteToColumn.size()==SourceLine.size()+1);
+    assert(0 < m_byteToColumn.size() && 0 < m_columnToByte.size());
+    assert(m_byteToColumn.size()
+           == static_cast<unsigned>(m_columnToByte.back()+1));
+    assert(static_cast<unsigned>(m_byteToColumn.back()+1)
+           == m_columnToByte.size());
+  }
+  int columns() const { return m_byteToColumn.back(); }
+  int bytes() const { return m_columnToByte.back(); }
+  int byteToColumn(int n) const {
+    assert(0<=n && n<static_cast<int>(m_byteToColumn.size()));
+    return m_byteToColumn[n];
+  }
+  int columnToByte(int n) const {
+    assert(0<=n && n<static_cast<int>(m_columnToByte.size()));
+    return m_columnToByte[n];
+  }
+  StringRef getSourceLine() const {
+    return m_SourceLine;
+  }
+  
+private:
+  const std::string m_SourceLine;
+  SmallVector<int,200> m_byteToColumn;
+  SmallVector<int,200> m_columnToByte;
+};
+
+// used in assert in selectInterestingSourceRegion()
+namespace {
+struct char_out_of_range {
+  const char lower,upper;
+  char_out_of_range(char lower, char upper) :
+    lower(lower), upper(upper) {}
+  bool operator()(char c) { return c < lower || upper < c; }
+};
+}
+
 /// \brief When the source code line we want to print is too long for
 /// the terminal, select the "interesting" region.
 static void selectInterestingSourceRegion(std::string &SourceLine,
                                           std::string &CaretLine,
                                           std::string &FixItInsertionLine,
-                                          unsigned EndOfCaretToken,
-                                          unsigned Columns) {
-  unsigned MaxSize = std::max(SourceLine.size(),
-                              std::max(CaretLine.size(), 
-                                       FixItInsertionLine.size()));
-  if (MaxSize > SourceLine.size())
-    SourceLine.resize(MaxSize, ' ');
-  if (MaxSize > CaretLine.size())
-    CaretLine.resize(MaxSize, ' ');
-  if (!FixItInsertionLine.empty() && MaxSize > FixItInsertionLine.size())
-    FixItInsertionLine.resize(MaxSize, ' ');
-    
+                                          unsigned Columns,
+                                          const SourceColumnMap &map) {
+  unsigned MaxColumns = std::max<unsigned>(map.columns(),
+                                           std::max(CaretLine.size(),
+                                                    FixItInsertionLine.size()));
+  // if the number of columns is less than the desired number we're done
+  if (MaxColumns <= Columns)
+    return;
+
+  // no special characters allowed in CaretLine or FixItInsertionLine
+  assert(CaretLine.end() ==
+         std::find_if(CaretLine.begin(), CaretLine.end(),
+         char_out_of_range(' ','~')));
+  assert(FixItInsertionLine.end() ==
+         std::find_if(FixItInsertionLine.begin(), FixItInsertionLine.end(),
+         char_out_of_range(' ','~')));
+
   // Find the slice that we need to display the full caret line
   // correctly.
   unsigned CaretStart = 0, CaretEnd = CaretLine.size();
@@ -64,10 +313,8 @@
     if (!isspace(CaretLine[CaretEnd - 1]))
       break;
 
-  // Make sure we don't chop the string shorter than the caret token
-  // itself.
-  if (CaretEnd < EndOfCaretToken)
-    CaretEnd = EndOfCaretToken;
+  // caret has already been inserted into CaretLine so the above whitespace
+  // check is guaranteed to include the caret
 
   // If we have a fix-it line, make sure the slice includes all of the
   // fix-it information.
@@ -81,10 +328,8 @@
       if (!isspace(FixItInsertionLine[FixItEnd - 1]))
         break;
 
-    if (FixItStart < CaretStart)
-      CaretStart = FixItStart;
-    if (FixItEnd > CaretEnd)
-      CaretEnd = FixItEnd;
+    CaretStart = std::min(FixItStart, CaretStart);
+    CaretEnd = std::max(FixItEnd, CaretEnd);
   }
 
   // CaretLine[CaretStart, CaretEnd) contains all of the interesting
@@ -92,62 +337,72 @@
   // number of columns we have, try to grow the slice to encompass
   // more context.
 
-  // If the end of the interesting region comes before we run out of
-  // space in the terminal, start at the beginning of the line.
-  if (Columns > 3 && CaretEnd < Columns - 3)
-    CaretStart = 0;
+  unsigned SourceStart = map.columnToByte(std::min<unsigned>(CaretStart,
+                                                             map.columns()));
+  unsigned SourceEnd = map.columnToByte(std::min<unsigned>(CaretEnd,
+                                                           map.columns()));
+
+  unsigned CaretColumnsOutsideSource = CaretEnd-CaretStart
+    - (map.byteToColumn(SourceEnd)-map.byteToColumn(SourceStart));
+
+  char const *front_ellipse = "  ...";
+  char const *front_space   = "     ";
+  char const *back_ellipse = "...";
+  unsigned ellipses_space = strlen(front_ellipse) + strlen(back_ellipse);
 
   unsigned TargetColumns = Columns;
-  if (TargetColumns > 8)
-    TargetColumns -= 8; // Give us extra room for the ellipses.
-  unsigned SourceLength = SourceLine.size();
-  while ((CaretEnd - CaretStart) < TargetColumns) {
+  // Give us extra room for the ellipses
+  //  and any of the caret line that extends past the source
+  if (TargetColumns > ellipses_space+CaretColumnsOutsideSource)
+    TargetColumns -= ellipses_space+CaretColumnsOutsideSource;
+
+  while (SourceStart>0 || SourceEnd<SourceLine.size()) {
     bool ExpandedRegion = false;
-    // Move the start of the interesting region left until we've
-    // pulled in something else interesting.
-    if (CaretStart == 1)
-      CaretStart = 0;
-    else if (CaretStart > 1) {
-      unsigned NewStart = CaretStart - 1;
+
+    if (SourceStart>0) {
+      unsigned NewStart = SourceStart-1;
 
       // Skip over any whitespace we see here; we're looking for
       // another bit of interesting text.
-      while (NewStart && isspace(SourceLine[NewStart]))
+      while (NewStart &&
+             (map.byteToColumn(NewStart)==-1 || isspace(SourceLine[NewStart])))
         --NewStart;
 
       // Skip over this bit of "interesting" text.
-      while (NewStart && !isspace(SourceLine[NewStart]))
+      while (NewStart &&
+             (map.byteToColumn(NewStart)!=-1 && !isspace(SourceLine[NewStart])))
         --NewStart;
 
       // Move up to the non-whitespace character we just saw.
       if (NewStart)
         ++NewStart;
 
-      // If we're still within our limit, update the starting
-      // position within the source/caret line.
-      if (CaretEnd - NewStart <= TargetColumns) {
-        CaretStart = NewStart;
+      unsigned NewColumns = map.byteToColumn(SourceEnd) -
+                              map.byteToColumn(NewStart);
+      if (NewColumns <= TargetColumns) {
+        SourceStart = NewStart;
         ExpandedRegion = true;
       }
     }
 
-    // Move the end of the interesting region right until we've
-    // pulled in something else interesting.
-    if (CaretEnd != SourceLength) {
-      assert(CaretEnd < SourceLength && "Unexpected caret position!");
-      unsigned NewEnd = CaretEnd;
+    if (SourceEnd<SourceLine.size()) {
+      unsigned NewEnd = SourceEnd+1;
 
       // Skip over any whitespace we see here; we're looking for
       // another bit of interesting text.
-      while (NewEnd != SourceLength && isspace(SourceLine[NewEnd - 1]))
+      while (NewEnd<SourceLine.size() &&
+             (map.byteToColumn(NewEnd)==-1 || isspace(SourceLine[NewEnd])))
         ++NewEnd;
 
       // Skip over this bit of "interesting" text.
-      while (NewEnd != SourceLength && !isspace(SourceLine[NewEnd - 1]))
+      while (NewEnd<SourceLine.size() &&
+             (map.byteToColumn(NewEnd)!=-1 && !isspace(SourceLine[NewEnd])))
         ++NewEnd;
 
-      if (NewEnd - CaretStart <= TargetColumns) {
-        CaretEnd = NewEnd;
+      unsigned NewColumns = map.byteToColumn(NewEnd) -
+                              map.byteToColumn(SourceStart);
+      if (NewColumns <= TargetColumns) {
+        SourceEnd = NewEnd;
         ExpandedRegion = true;
       }
     }
@@ -156,21 +411,41 @@
       break;
   }
 
+  CaretStart = map.byteToColumn(SourceStart);
+  CaretEnd = map.byteToColumn(SourceEnd) + CaretColumnsOutsideSource;
+
   // [CaretStart, CaretEnd) is the slice we want. Update the various
   // output lines to show only this slice, with two-space padding
   // before the lines so that it looks nicer.
-  if (CaretEnd < SourceLine.size())
-    SourceLine.replace(CaretEnd, std::string::npos, "...");
-  if (CaretEnd < CaretLine.size())
-    CaretLine.erase(CaretEnd, std::string::npos);
-  if (FixItInsertionLine.size() > CaretEnd)
-    FixItInsertionLine.erase(CaretEnd, std::string::npos);
-
-  if (CaretStart > 2) {
-    SourceLine.replace(0, CaretStart, "  ...");
-    CaretLine.replace(0, CaretStart, "     ");
-    if (FixItInsertionLine.size() >= CaretStart)
-      FixItInsertionLine.replace(0, CaretStart, "     ");
+
+  assert(CaretStart!=(unsigned)-1 && CaretEnd!=(unsigned)-1 &&
+         SourceStart!=(unsigned)-1 && SourceEnd!=(unsigned)-1);
+  assert(SourceStart <= SourceEnd);
+  assert(CaretStart <= CaretEnd);
+
+  unsigned BackColumnsRemoved
+    = map.byteToColumn(SourceLine.size())-map.byteToColumn(SourceEnd);
+  unsigned FrontColumnsRemoved = CaretStart;
+  unsigned ColumnsKept = CaretEnd-CaretStart;
+
+  // We checked up front that the line needed truncation
+  assert(FrontColumnsRemoved+ColumnsKept+BackColumnsRemoved > Columns);
+
+  // The line needs some trunctiona, and we'd prefer to keep the front
+  //  if possible, so remove the back
+  if (BackColumnsRemoved)
+    SourceLine.replace(SourceEnd, std::string::npos, back_ellipse);
+
+  // If that's enough then we're done
+  if (FrontColumnsRemoved+ColumnsKept <= Columns)
+    return;
+
+  // Otherwise remove the front as well
+  if (FrontColumnsRemoved) {
+    SourceLine.replace(0, SourceStart, front_ellipse);
+    CaretLine.replace(0, CaretStart, front_space);
+    if (!FixItInsertionLine.empty())
+      FixItInsertionLine.replace(0, CaretStart, front_space);
   }
 }
 
@@ -564,10 +839,13 @@
 
   // Get information about the buffer it points into.
   bool Invalid = false;
-  const char *BufStart = SM.getBufferData(FID, &Invalid).data();
+  StringRef BufData = SM.getBufferData(FID, &Invalid);
   if (Invalid)
     return;
 
+  const char *BufStart = BufData.data();
+  const char *BufEnd = BufStart + BufData.size();
+
   unsigned LineNo = SM.getLineNumber(FID, FileOffset);
   unsigned ColNo = SM.getColumnNumber(FID, FileOffset);
   unsigned CaretEndColNo
@@ -581,7 +859,7 @@
   // Compute the line end.  Scan forward from the error position to the end of
   // the line.
   const char *LineEnd = TokPtr;
-  while (*LineEnd != '\n' && *LineEnd != '\r' && *LineEnd != '\0')
+  while (*LineEnd != '\n' && *LineEnd != '\r' && LineEnd!=BufEnd)
     ++LineEnd;
 
   // FIXME: This shouldn't be necessary, but the CaretEndColNo can extend past
@@ -596,19 +874,30 @@
   // length as the line of source code.
   std::string CaretLine(LineEnd-LineStart, ' ');
 
+  const SourceColumnMap sourceColMap(SourceLine, DiagOpts.TabStop);
+
   // Highlight all of the characters covered by Ranges with ~ characters.
   for (SmallVectorImpl<CharSourceRange>::iterator I = Ranges.begin(),
                                                   E = Ranges.end();
        I != E; ++I)
-    highlightRange(*I, LineNo, FID, SourceLine, CaretLine);
+    highlightRange(*I, LineNo, FID, sourceColMap, CaretLine);
 
   // Next, insert the caret itself.
-  if (ColNo-1 < CaretLine.size())
-    CaretLine[ColNo-1] = '^';
-  else
-    CaretLine.push_back('^');
+  ColNo = sourceColMap.byteToColumn(ColNo-1);
+  if (CaretLine.size()<ColNo+1)
+    CaretLine.resize(ColNo+1, ' ');
+  CaretLine[ColNo] = '^';
 
-  expandTabs(SourceLine, CaretLine);
+  std::string FixItInsertionLine = buildFixItInsertionLine(LineNo,
+                                                           sourceColMap,
+                                                           Hints);
+
+  // If the source line is too long for our terminal, select only the
+  // "interesting" source region within that line.
+  unsigned Columns = DiagOpts.MessageLength;
+  if (Columns)
+    selectInterestingSourceRegion(SourceLine, CaretLine, FixItInsertionLine,
+                                  Columns, sourceColMap);
 
   // If we are in -fdiagnostics-print-source-range-info mode, we are trying
   // to produce easily machine parsable output.  Add a space before the
@@ -619,23 +908,12 @@
     CaretLine = ' ' + CaretLine;
   }
 
-  std::string FixItInsertionLine = buildFixItInsertionLine(LineNo,
-                                                           LineStart, LineEnd,
-                                                           Hints);
-
-  // If the source line is too long for our terminal, select only the
-  // "interesting" source region within that line.
-  unsigned Columns = DiagOpts.MessageLength;
-  if (Columns && SourceLine.size() > Columns)
-    selectInterestingSourceRegion(SourceLine, CaretLine, FixItInsertionLine,
-                                  CaretEndColNo, Columns);
-
   // Finally, remove any blank spaces from the end of CaretLine.
   while (CaretLine[CaretLine.size()-1] == ' ')
     CaretLine.erase(CaretLine.end()-1);
 
   // Emit what we have computed.
-  OS << SourceLine << '\n';
+  emitSnippet(SourceLine);
 
   if (DiagOpts.ShowColors)
     OS.changeColor(caretColor, true);
@@ -658,13 +936,49 @@
   emitParseableFixits(Hints);
 }
 
+void TextDiagnostic::emitSnippet(StringRef line)
+{
+  if (line.empty())
+    return;
+
+  size_t i = 0;
+  
+  std::string to_print;
+  bool print_reversed = false;
+  
+  while (i<line.size()) {
+    std::pair<SmallString<16>,bool> res
+        = printableTextForNextCharacter(line, &i, DiagOpts.TabStop);
+    bool was_printable = res.second;
+    
+    if (DiagOpts.ShowColors
+        && was_printable==print_reversed) {
+      if (print_reversed)
+        OS.reverseColor();
+      OS << to_print;
+      to_print.clear();
+      if (DiagOpts.ShowColors)
+        OS.resetColor();
+    }
+    
+    print_reversed = !was_printable;
+    to_print += res.first.str();
+  }
+  
+  if (print_reversed && DiagOpts.ShowColors)
+    OS.reverseColor();
+  OS << to_print;
+  if (print_reversed && DiagOpts.ShowColors)
+    OS.resetColor();
+  
+  OS << '\n';
+}
+
 /// \brief Highlight a SourceRange (with ~'s) for any characters on LineNo.
 void TextDiagnostic::highlightRange(const CharSourceRange &R,
                                     unsigned LineNo, FileID FID,
-                                    const std::string &SourceLine,
+                                    const SourceColumnMap &map,
                                     std::string &CaretLine) {
-  assert(CaretLine.size() == SourceLine.size() &&
-         "Expect a correspondence between source and caret line!");
   if (!R.isValid()) return;
 
   SourceLocation Begin = SM.getExpansionLoc(R.getBegin());
@@ -694,7 +1008,7 @@
   }
 
   // Compute the column number of the end.
-  unsigned EndColNo = CaretLine.size();
+  unsigned EndColNo = map.getSourceLine().size();
   if (EndLineNo == LineNo) {
     EndColNo = SM.getExpansionColumnNumber(End);
     if (EndColNo) {
@@ -714,15 +1028,17 @@
   // Check that a token range does not highlight only whitespace.
   if (R.isTokenRange()) {
     // Pick the first non-whitespace column.
-    while (StartColNo < SourceLine.size() &&
-           (SourceLine[StartColNo] == ' ' || SourceLine[StartColNo] == '\t'))
+    while (StartColNo < map.getSourceLine().size() &&
+           (map.getSourceLine()[StartColNo] == ' ' ||
+            map.getSourceLine()[StartColNo] == '\t'))
       ++StartColNo;
 
     // Pick the last non-whitespace column.
-    if (EndColNo > SourceLine.size())
-      EndColNo = SourceLine.size();
+    if (EndColNo > map.getSourceLine().size())
+      EndColNo = map.getSourceLine().size();
     while (EndColNo-1 &&
-           (SourceLine[EndColNo-1] == ' ' || SourceLine[EndColNo-1] == '\t'))
+           (map.getSourceLine()[EndColNo-1] == ' ' ||
+            map.getSourceLine()[EndColNo-1] == '\t'))
       --EndColNo;
 
     // If the start/end passed each other, then we are trying to highlight a
@@ -731,15 +1047,24 @@
     assert(StartColNo <= EndColNo && "Trying to highlight whitespace??");
   }
 
+  assert(StartColNo <= map.getSourceLine().size() && "Invalid range!");
+  assert(EndColNo <= map.getSourceLine().size() && "Invalid range!");
+
   // Fill the range with ~'s.
-  for (unsigned i = StartColNo; i < EndColNo; ++i)
-    CaretLine[i] = '~';
+  StartColNo = map.byteToColumn(StartColNo);
+  EndColNo = map.byteToColumn(EndColNo);
+
+  assert(StartColNo <= EndColNo && "Invalid range!");
+  if (CaretLine.size() < EndColNo)
+    CaretLine.resize(EndColNo,' ');
+  std::fill(CaretLine.begin()+StartColNo,CaretLine.begin()+EndColNo,'~');
 }
 
-std::string TextDiagnostic::buildFixItInsertionLine(unsigned LineNo,
-                                                    const char *LineStart,
-                                                    const char *LineEnd,
-                                                    ArrayRef<FixItHint> Hints) {
+std::string TextDiagnostic::buildFixItInsertionLine(
+  unsigned LineNo,
+  const SourceColumnMap &map,
+  ArrayRef<FixItHint> Hints) {
+
   std::string FixItInsertionLine;
   if (Hints.empty() || !DiagOpts.ShowFixits)
     return FixItInsertionLine;
@@ -755,13 +1080,32 @@
         // Insert the new code into the line just below the code
         // that the user wrote.
         unsigned HintColNo
-          = SM.getColumnNumber(HintLocInfo.first, HintLocInfo.second);
+          = SM.getColumnNumber(HintLocInfo.first, HintLocInfo.second) - 1;
+        // hint must start inside the source or right at the end
+        assert(HintColNo<static_cast<unsigned>(map.bytes())+1);
+        HintColNo = map.byteToColumn(HintColNo);
+
+        // FIXME: if the fixit includes tabs or other characters that do not
+        //  take up a single column per byte when displayed then
+        //  I->CodeToInsert.size() is not a column number and we're mixing
+        //  units (columns + bytes). We should get printable versions
+        //  of each fixit before using them.
         unsigned LastColumnModified
-          = HintColNo - 1 + I->CodeToInsert.size();
+          = HintColNo + I->CodeToInsert.size();
+
+        if (LastColumnModified > static_cast<unsigned>(map.bytes())) {
+          unsigned LastExistingColumn = map.byteToColumn(map.bytes());
+          unsigned AddedColumns = LastColumnModified-LastExistingColumn;
+          LastColumnModified = LastExistingColumn + AddedColumns;
+        } else {
+          LastColumnModified = map.byteToColumn(LastColumnModified);
+        }
+
         if (LastColumnModified > FixItInsertionLine.size())
           FixItInsertionLine.resize(LastColumnModified, ' ');
+        assert(HintColNo+I->CodeToInsert.size() <= FixItInsertionLine.size());
         std::copy(I->CodeToInsert.begin(), I->CodeToInsert.end(),
-                  FixItInsertionLine.begin() + HintColNo - 1);
+                  FixItInsertionLine.begin() + HintColNo);
       } else {
         FixItInsertionLine.clear();
         break;
@@ -769,72 +1113,11 @@
     }
   }
 
-  if (FixItInsertionLine.empty())
-    return FixItInsertionLine;
-
-  // Now that we have the entire fixit line, expand the tabs in it.
-  // Since we don't want to insert spaces in the middle of a word,
-  // find each word and the column it should line up with and insert
-  // spaces until they match.
-  unsigned FixItPos = 0;
-  unsigned LinePos = 0;
-  unsigned TabExpandedCol = 0;
-  unsigned LineLength = LineEnd - LineStart;
-
-  while (FixItPos < FixItInsertionLine.size() && LinePos < LineLength) {
-    // Find the next word in the FixIt line.
-    while (FixItPos < FixItInsertionLine.size() &&
-           FixItInsertionLine[FixItPos] == ' ')
-      ++FixItPos;
-    unsigned CharDistance = FixItPos - TabExpandedCol;
-
-    // Walk forward in the source line, keeping track of
-    // the tab-expanded column.
-    for (unsigned I = 0; I < CharDistance; ++I, ++LinePos)
-      if (LinePos >= LineLength || LineStart[LinePos] != '\t')
-        ++TabExpandedCol;
-      else
-        TabExpandedCol =
-          (TabExpandedCol/DiagOpts.TabStop + 1) * DiagOpts.TabStop;
-
-    // Adjust the fixit line to match this column.
-    FixItInsertionLine.insert(FixItPos, TabExpandedCol-FixItPos, ' ');
-    FixItPos = TabExpandedCol;
-
-    // Walk to the end of the word.
-    while (FixItPos < FixItInsertionLine.size() &&
-           FixItInsertionLine[FixItPos] != ' ')
-      ++FixItPos;
-  }
+  expandTabs(FixItInsertionLine, DiagOpts.TabStop);
 
   return FixItInsertionLine;
 }
 
-void TextDiagnostic::expandTabs(std::string &SourceLine,
-                                std::string &CaretLine) {
-  // Scan the source line, looking for tabs.  If we find any, manually expand
-  // them to spaces and update the CaretLine to match.
-  for (unsigned i = 0; i != SourceLine.size(); ++i) {
-    if (SourceLine[i] != '\t') continue;
-
-    // Replace this tab with at least one space.
-    SourceLine[i] = ' ';
-
-    // Compute the number of spaces we need to insert.
-    unsigned TabStop = DiagOpts.TabStop;
-    assert(0 < TabStop && TabStop <= DiagnosticOptions::MaxTabStop &&
-           "Invalid -ftabstop value");
-    unsigned NumSpaces = ((i+TabStop)/TabStop * TabStop) - (i+1);
-    assert(NumSpaces < TabStop && "Invalid computation of space amt");
-
-    // Insert spaces into the SourceLine.
-    SourceLine.insert(i+1, NumSpaces, ' ');
-
-    // Insert spaces or ~'s into CaretLine.
-    CaretLine.insert(i+1, NumSpaces, CaretLine[i] == '~' ? '~' : ' ');
-  }
-}
-
 void TextDiagnostic::emitParseableFixits(ArrayRef<FixItHint> Hints) {
   if (!DiagOpts.ShowParseableFixits)
     return;

Modified: cfe/branches/tooling/lib/Rewrite/RewriteModernObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Rewrite/RewriteModernObjC.cpp?rev=154991&r1=154990&r2=154991&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Rewrite/RewriteModernObjC.cpp (original)
+++ cfe/branches/tooling/lib/Rewrite/RewriteModernObjC.cpp Wed Apr 18 02:59:17 2012
@@ -304,7 +304,6 @@
     void RewriteFunctionDecl(FunctionDecl *FD);
     void RewriteBlockPointerType(std::string& Str, QualType Type);
     void RewriteBlockPointerTypeVariable(std::string& Str, ValueDecl *VD);
-    void RewriteBlockLiteralFunctionDecl(FunctionDecl *FD);
     void RewriteObjCQualifiedInterfaceTypes(Decl *Dcl);
     void RewriteTypeOfDecl(VarDecl *VD);
     void RewriteObjCQualifiedInterfaceTypes(Expr *E);
@@ -2246,30 +2245,6 @@
   }
 }
 
-
-void RewriteModernObjC::RewriteBlockLiteralFunctionDecl(FunctionDecl *FD) {
-  SourceLocation FunLocStart = FD->getTypeSpecStartLoc();
-  const FunctionType *funcType = FD->getType()->getAs<FunctionType>();
-  const FunctionProtoType *proto = dyn_cast<FunctionProtoType>(funcType);
-  if (!proto)
-    return;
-  QualType Type = proto->getResultType();
-  std::string FdStr = Type.getAsString(Context->getPrintingPolicy());
-  FdStr += " ";
-  FdStr += FD->getName();
-  FdStr +=  "(";
-  unsigned numArgs = proto->getNumArgs();
-  for (unsigned i = 0; i < numArgs; i++) {
-    QualType ArgType = proto->getArgType(i);
-    RewriteBlockPointerType(FdStr, ArgType);
-    if (i+1 < numArgs)
-      FdStr += ", ";
-  }
-  FdStr +=  ");\n";
-  InsertText(FunLocStart, FdStr);
-  CurFunctionDeclToDeclareForBlock = 0;
-}
-
 // SynthSuperContructorFunctionDecl - id __rw_objc_super(id obj, id super);
 void RewriteModernObjC::SynthSuperContructorFunctionDecl() {
   if (SuperContructorFunctionDecl)
@@ -4008,11 +3983,25 @@
   return S;
 }
 
+/// getFunctionSourceLocation - returns start location of a function
+/// definition. Complication arises when function has declared as
+/// extern "C" or extern "C" {...}
+static SourceLocation getFunctionSourceLocation (FunctionDecl *FD) {
+  if (!FD->isExternC() || FD->isMain())
+    return FD->getTypeSpecStartLoc();
+  const DeclContext *DC = FD->getDeclContext();
+  if (const LinkageSpecDecl *LSD = dyn_cast<LinkageSpecDecl>(DC)) {
+    SourceLocation BodyRBrace = LSD->getRBraceLoc();
+    // if it is extern "C" {...}, return function decl's own location.
+    if (BodyRBrace.isValid())
+      return FD->getTypeSpecStartLoc();
+    return LSD->getExternLoc();
+  }
+  return FD->getTypeSpecStartLoc();
+}
+
 void RewriteModernObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart,
                                           StringRef FunName) {
-  // Insert declaration for the function in which block literal is used.
-  if (CurFunctionDeclToDeclareForBlock && !Blocks.empty())
-    RewriteBlockLiteralFunctionDecl(CurFunctionDeclToDeclareForBlock);
   bool RewriteSC = (GlobalVarDecl &&
                     !Blocks.empty() &&
                     GlobalVarDecl->getStorageClass() == SC_Static &&
@@ -4121,7 +4110,7 @@
 }
 
 void RewriteModernObjC::InsertBlockLiteralsWithinFunction(FunctionDecl *FD) {
-  SourceLocation FunLocStart = FD->getTypeSpecStartLoc();
+  SourceLocation FunLocStart = getFunctionSourceLocation(FD);
   StringRef FuncName = FD->getName();
 
   SynthesizeBlockLiterals(FunLocStart, FuncName);
@@ -4731,10 +4720,6 @@
 ///
 ///
 void RewriteModernObjC::RewriteByRefVar(VarDecl *ND) {
-  // Insert declaration for the function in which block literal is
-  // used.
-  if (CurFunctionDeclToDeclareForBlock)
-    RewriteBlockLiteralFunctionDecl(CurFunctionDeclToDeclareForBlock);
   int flag = 0;
   int isa = 0;
   SourceLocation DeclLoc = ND->getTypeSpecStartLoc();
@@ -4773,7 +4758,7 @@
   // Insert this type in global scope. It is needed by helper function.
   SourceLocation FunLocStart;
   if (CurFunctionDef)
-     FunLocStart = CurFunctionDef->getTypeSpecStartLoc();
+     FunLocStart = getFunctionSourceLocation(CurFunctionDef);
   else {
     assert(CurMethodDef && "RewriteByRefVar - CurMethodDef is null");
     FunLocStart = CurMethodDef->getLocStart();

Modified: cfe/branches/tooling/lib/Sema/SemaAccess.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaAccess.cpp?rev=154991&r1=154990&r2=154991&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaAccess.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaAccess.cpp Wed Apr 18 02:59:17 2012
@@ -779,6 +779,13 @@
         // that the naming class has to be derived from the effective
         // context.
 
+        // Emulate a MSVC bug where the creation of pointer-to-member
+        // to protected member of base class is allowed but only from
+        // a static function member functions.
+        if (S.getLangOpts().MicrosoftMode && !EC.Functions.empty())
+          if (CXXMethodDecl* MD = dyn_cast<CXXMethodDecl>(EC.Functions.front()))
+            if (MD->isStatic()) return AR_accessible;
+
         // Despite the standard's confident wording, there is a case
         // where you can have an instance member that's neither in a
         // pointer-to-member expression nor in a member access:  when

Modified: cfe/branches/tooling/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaDecl.cpp?rev=154991&r1=154990&r2=154991&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaDecl.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaDecl.cpp Wed Apr 18 02:59:17 2012
@@ -7185,8 +7185,7 @@
   }
 }
 
-Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope,
-                                         Declarator &D) {
+Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) {
   assert(getCurFunctionDecl() == 0 && "Function parsing confused");
   assert(D.isFunctionDeclarator() && "Not a function declarator!");
   Scope *ParentScope = FnBodyScope->getParent();
@@ -7359,6 +7358,10 @@
     }
   }
 
+  // Ensure that the function's exception specification is instantiated.
+  if (const FunctionProtoType *FPT = FD->getType()->getAs<FunctionProtoType>())
+    ResolveExceptionSpec(D->getLocation(), FPT);
+
   // Checking attributes of current function definition
   // dllimport attribute.
   DLLImportAttr *DA = FD->getAttr<DLLImportAttr>();

Modified: cfe/branches/tooling/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=154991&r1=154990&r2=154991&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaTemplateInstantiateDecl.cpp Wed Apr 18 02:59:17 2012
@@ -2377,7 +2377,16 @@
 
 void Sema::InstantiateExceptionSpec(SourceLocation PointOfInstantiation,
                                     FunctionDecl *Decl) {
-  FunctionDecl *Tmpl = Decl->getTemplateInstantiationPattern();
+  // Find the template declaration which contains the exception specification.
+  // Per [except.spec]p4, prefer the exception spec on the primary template
+  // if this is an explicit instantiation.
+  FunctionDecl *Tmpl = 0;
+  if (Decl->getPrimaryTemplate())
+    Tmpl = Decl->getPrimaryTemplate()->getTemplatedDecl();
+  else if (FunctionDecl *MemTmpl = Decl->getInstantiatedFromMemberFunction())
+    Tmpl = MemTmpl;
+  else
+    Tmpl = Decl->getTemplateInstantiationPattern();
   assert(Tmpl && "can't instantiate non-template");
 
   if (Decl->getType()->castAs<FunctionProtoType>()->getExceptionSpecType()

Modified: cfe/branches/tooling/lib/Tooling/CompilationDatabase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Tooling/CompilationDatabase.cpp?rev=154991&r1=154990&r2=154991&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Tooling/CompilationDatabase.cpp (original)
+++ cfe/branches/tooling/lib/Tooling/CompilationDatabase.cpp Wed Apr 18 02:59:17 2012
@@ -13,7 +13,7 @@
 
 #include "clang/Tooling/CompilationDatabase.h"
 #include "llvm/ADT/SmallString.h"
-#include "llvm/Support/JSONParser.h"
+#include "llvm/Support/YAMLParser.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/system_error.h"
 
@@ -22,10 +22,10 @@
 
 namespace {
 
-/// \brief A parser for JSON escaped strings of command line arguments.
+/// \brief A parser for escaped strings of command line arguments.
 ///
 /// Assumes \-escaping for quoted arguments (see the documentation of
-/// unescapeJSONCommandLine(...)).
+/// unescapeCommandLine(...)).
 class CommandLineArgumentParser {
  public:
   CommandLineArgumentParser(StringRef CommandLine)
@@ -90,9 +90,6 @@
 
   bool next() {
     ++Position;
-    if (Position == Input.end()) return false;
-    // Remove the JSON escaping first. This is done unconditionally.
-    if (*Position == '\\') ++Position;
     return Position != Input.end();
   }
 
@@ -101,9 +98,9 @@
   std::vector<std::string> CommandLine;
 };
 
-std::vector<std::string> unescapeJSONCommandLine(
-    StringRef JSONEscapedCommandLine) {
-  CommandLineArgumentParser parser(JSONEscapedCommandLine);
+std::vector<std::string> unescapeCommandLine(
+    StringRef EscapedCommandLine) {
+  CommandLineArgumentParser parser(EscapedCommandLine);
   return parser.parse();
 }
 
@@ -124,6 +121,33 @@
   return Database.take();
 }
 
+FixedCompilationDatabase *
+FixedCompilationDatabase::loadFromCommandLine(int &Argc,
+                                              const char **Argv,
+                                              Twine Directory) {
+  const char **DoubleDash = std::find(Argv, Argv + Argc, StringRef("--"));
+  if (DoubleDash == Argv + Argc)
+    return NULL;
+  std::vector<std::string> CommandLine(DoubleDash + 1, Argv + Argc);
+  Argc = DoubleDash - Argv;
+  return new FixedCompilationDatabase(Directory, CommandLine);
+}
+
+FixedCompilationDatabase::
+FixedCompilationDatabase(Twine Directory, ArrayRef<std::string> CommandLine) {
+  std::vector<std::string> ToolCommandLine(1, "clang-tool");
+  ToolCommandLine.insert(ToolCommandLine.end(),
+                         CommandLine.begin(), CommandLine.end());
+  CompileCommands.push_back(CompileCommand(Directory, ToolCommandLine));
+}
+
+std::vector<CompileCommand>
+FixedCompilationDatabase::getCompileCommands(StringRef FilePath) const {
+  std::vector<CompileCommand> Result(CompileCommands);
+  Result[0].CommandLine.push_back(FilePath);
+  return Result;
+}
+
 JSONCompilationDatabase *
 JSONCompilationDatabase::loadFromFile(StringRef FilePath,
                                       std::string &ErrorMessage) {
@@ -162,65 +186,77 @@
   const std::vector<CompileCommandRef> &CommandsRef = CommandsRefI->getValue();
   std::vector<CompileCommand> Commands;
   for (int I = 0, E = CommandsRef.size(); I != E; ++I) {
+    llvm::SmallString<8> DirectoryStorage;
+    llvm::SmallString<1024> CommandStorage;
     Commands.push_back(CompileCommand(
       // FIXME: Escape correctly:
-      CommandsRef[I].first,
-      unescapeJSONCommandLine(CommandsRef[I].second)));
+      CommandsRef[I].first->getValue(DirectoryStorage),
+      unescapeCommandLine(CommandsRef[I].second->getValue(CommandStorage))));
   }
   return Commands;
 }
 
 bool JSONCompilationDatabase::parse(std::string &ErrorMessage) {
-  llvm::SourceMgr SM;
-  llvm::JSONParser Parser(Database->getBuffer(), &SM);
-  llvm::JSONValue *Root = Parser.parseRoot();
+  llvm::yaml::document_iterator I = YAMLStream.begin();
+  if (I == YAMLStream.end()) {
+    ErrorMessage = "Error while parsing YAML.";
+    return false;
+  }
+  llvm::yaml::Node *Root = I->getRoot();
   if (Root == NULL) {
-    ErrorMessage = "Error while parsing JSON.";
+    ErrorMessage = "Error while parsing YAML.";
     return false;
   }
-  llvm::JSONArray *Array = dyn_cast<llvm::JSONArray>(Root);
+  llvm::yaml::SequenceNode *Array =
+    llvm::dyn_cast<llvm::yaml::SequenceNode>(Root);
   if (Array == NULL) {
     ErrorMessage = "Expected array.";
     return false;
   }
-  for (llvm::JSONArray::const_iterator AI = Array->begin(), AE = Array->end();
+  for (llvm::yaml::SequenceNode::iterator AI = Array->begin(),
+                                          AE = Array->end();
        AI != AE; ++AI) {
-    const llvm::JSONObject *Object = dyn_cast<llvm::JSONObject>(*AI);
+    llvm::yaml::MappingNode *Object =
+      llvm::dyn_cast<llvm::yaml::MappingNode>(&*AI);
     if (Object == NULL) {
       ErrorMessage = "Expected object.";
       return false;
     }
-    StringRef EntryDirectory;
-    StringRef EntryFile;
-    StringRef EntryCommand;
-    for (llvm::JSONObject::const_iterator KVI = Object->begin(),
-                                          KVE = Object->end();
+    llvm::yaml::ScalarNode *Directory;
+    llvm::yaml::ScalarNode *Command;
+    llvm::SmallString<8> FileStorage;
+    llvm::StringRef File;
+    for (llvm::yaml::MappingNode::iterator KVI = Object->begin(),
+                                           KVE = Object->end();
          KVI != KVE; ++KVI) {
-      const llvm::JSONValue *Value = (*KVI)->Value;
+      llvm::yaml::Node *Value = (*KVI).getValue();
       if (Value == NULL) {
         ErrorMessage = "Expected value.";
         return false;
       }
-      const llvm::JSONString *ValueString =
-        dyn_cast<llvm::JSONString>(Value);
+      llvm::yaml::ScalarNode *ValueString =
+        llvm::dyn_cast<llvm::yaml::ScalarNode>(Value);
       if (ValueString == NULL) {
         ErrorMessage = "Expected string as value.";
         return false;
       }
-      if ((*KVI)->Key->getRawText() == "directory") {
-        EntryDirectory = ValueString->getRawText();
-      } else if ((*KVI)->Key->getRawText() == "file") {
-        EntryFile = ValueString->getRawText();
-      } else if ((*KVI)->Key->getRawText() == "command") {
-        EntryCommand = ValueString->getRawText();
+      llvm::yaml::ScalarNode *KeyString =
+        llvm::dyn_cast<llvm::yaml::ScalarNode>((*KVI).getKey());
+      llvm::SmallString<8> KeyStorage;
+      if (KeyString->getValue(KeyStorage) == "directory") {
+        Directory = ValueString;
+      } else if (KeyString->getValue(KeyStorage) == "command") {
+        Command = ValueString;
+      } else if (KeyString->getValue(KeyStorage) == "file") {
+        File = ValueString->getValue(FileStorage);
       } else {
-        ErrorMessage = (Twine("Unknown key: \"") +
-                        (*KVI)->Key->getRawText() + "\"").str();
+        ErrorMessage = ("Unknown key: \"" +
+                        KeyString->getRawValue() + "\"").str();
         return false;
       }
     }
-    IndexByFile[EntryFile].push_back(
-      CompileCommandRef(EntryDirectory, EntryCommand));
+    IndexByFile[File].push_back(
+      CompileCommandRef(Directory, Command));
   }
   return true;
 }

Modified: cfe/branches/tooling/test/CodeGenCXX/cxx11-exception-spec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/test/CodeGenCXX/cxx11-exception-spec.cpp?rev=154991&r1=154990&r2=154991&view=diff
==============================================================================
--- cfe/branches/tooling/test/CodeGenCXX/cxx11-exception-spec.cpp (original)
+++ cfe/branches/tooling/test/CodeGenCXX/cxx11-exception-spec.cpp Wed Apr 18 02:59:17 2012
@@ -1,18 +1,66 @@
-// RUN: %clang_cc1 -std=c++11 -verify -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -verify -fexceptions -fcxx-exceptions -triple x86_64-linux-gnu | FileCheck %s
 
-template<typename T> void f() noexcept(sizeof(T) == 4);
+void h();
+
+template<typename T> void f() noexcept(sizeof(T) == 4) { h(); }
+
+template<typename T> struct S {
+  static void f() noexcept(sizeof(T) == 4) { h(); }
+};
+
+// CHECK: define {{.*}} @_Z1fIsEvv() {
+template<> void f<short>() { h(); }
+// CHECK: define {{.*}} @_Z1fIA2_sEvv() nounwind {
+template<> void f<short[2]>() noexcept { h(); }
+
+// CHECK: define {{.*}} @_ZN1SIsE1fEv()
+// CHECK-NOT: nounwind
+template<> void S<short>::f() { h(); }
+// CHECK: define {{.*}} @_ZN1SIA2_sE1fEv() nounwind
+template<> void S<short[2]>::f() noexcept { h(); }
+
+// CHECK: define {{.*}} @_Z1fIDsEvv() {
+template void f<char16_t>();
+// CHECK: define {{.*}} @_Z1fIA2_DsEvv() nounwind {
+template void f<char16_t[2]>();
+
+// CHECK: define {{.*}} @_ZN1SIDsE1fEv()
+// CHECK-NOT: nounwind
+template void S<char16_t>::f();
+// CHECK: define {{.*}} @_ZN1SIA2_DsE1fEv() nounwind
+template void S<char16_t[2]>::f();
 
 void g() {
-  // CHECK: declare void @_Z1fIiEvv() nounwind
+  // CHECK: define {{.*}} @_Z1fIiEvv() nounwind {
   f<int>();
-  // CHECK: declare void @_Z1fIA2_iEvv()
+  // CHECK: define {{.*}} @_Z1fIA2_iEvv() {
   f<int[2]>();
-  // CHECK: declare void @_Z1fIfEvv() nounwind
+
+  // CHECK: define {{.*}} @_ZN1SIiE1fEv() nounwind
+  S<int>::f();
+  // CHECK: define {{.*}} @_ZN1SIA2_iE1fEv()
+  // CHECK-NOT: nounwind
+  S<int[2]>::f();
+
+  // CHECK: define {{.*}} @_Z1fIfEvv() nounwind {
   void (*f1)() = &f<float>;
-  // CHECK: declare void @_Z1fIdEvv()
+  // CHECK: define {{.*}} @_Z1fIdEvv() {
   void (*f2)() = &f<double>;
-  // CHECK: declare void @_Z1fIA4_cEvv() nounwind
+
+  // CHECK: define {{.*}} @_ZN1SIfE1fEv() nounwind
+  void (*f3)() = &S<float>::f;
+  // CHECK: define {{.*}} @_ZN1SIdE1fEv()
+  // CHECK-NOT: nounwind
+  void (*f4)() = &S<double>::f;
+
+  // CHECK: define {{.*}} @_Z1fIA4_cEvv() nounwind {
   (void)&f<char[4]>;
-  // CHECK: declare void @_Z1fIcEvv()
+  // CHECK: define {{.*}} @_Z1fIcEvv() {
   (void)&f<char>;
+
+  // CHECK: define {{.*}} @_ZN1SIA4_cE1fEv() nounwind
+  (void)&S<char[4]>::f;
+  // CHECK: define {{.*}} @_ZN1SIcE1fEv()
+  // CHECK-NOT: nounwind
+  (void)&S<char>::f;
 }

Modified: cfe/branches/tooling/test/Misc/message-length.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/test/Misc/message-length.c?rev=154991&r1=154990&r2=154991&view=diff
==============================================================================
--- cfe/branches/tooling/test/Misc/message-length.c (original)
+++ cfe/branches/tooling/test/Misc/message-length.c Wed Apr 18 02:59:17 2012
@@ -27,9 +27,8 @@
 
 #pragma STDC CX_LIMITED_RANGE    // some long comment text and a brace, eh {}
 
-
 // CHECK: FILE:23:78
-// CHECK: {{^  ...// some long comment text and a brace, eh {} }}
+// CHECK: {{^  ...// some long comment text and a brace, eh {}}}
 
 struct A { int x; };
 void h(struct A *a) {

Modified: cfe/branches/tooling/test/Parser/MicrosoftExtensions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/test/Parser/MicrosoftExtensions.cpp?rev=154991&r1=154990&r2=154991&view=diff
==============================================================================
--- cfe/branches/tooling/test/Parser/MicrosoftExtensions.cpp (original)
+++ cfe/branches/tooling/test/Parser/MicrosoftExtensions.cpp Wed Apr 18 02:59:17 2012
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-extensions -fdelayed-template-parsing
+// RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-extensions -fms-compatibility -fdelayed-template-parsing
 
 /* Microsoft attribute tests */
 [repeatable][source_annotation_attribute( Parameter|ReturnValue )]
@@ -284,3 +284,28 @@
   missing_template_keyword<int>();
 }
 
+
+
+
+namespace access_protected_PTM {
+
+class A {
+protected:
+  void f(); // expected-note {{must name member using the type of the current context 'access_protected_PTM::B'}}
+};
+
+class B : public A{
+public:
+  void test_access();
+  static void test_access_static();
+};
+
+void B::test_access() {
+  &A::f; // expected-error {{'f' is a protected member of 'access_protected_PTM::A'}}
+}
+
+void B::test_access_static() {
+  &A::f;
+}
+
+}
\ No newline at end of file

Propchange: cfe/branches/tooling/test/SemaCXX/warn-unreachable.cpp
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Apr 18 02:59:17 2012
@@ -1,2 +1,2 @@
 /cfe/branches/type-system-rewrite/test/SemaCXX/warn-unreachable.cpp:134693-134817
-/cfe/trunk/test/SemaCXX/warn-unreachable.cpp:121961,146581-154921
+/cfe/trunk/test/SemaCXX/warn-unreachable.cpp:121961,146581-154990

Modified: cfe/branches/tooling/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp?rev=154991&r1=154990&r2=154991&view=diff
==============================================================================
--- cfe/branches/tooling/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp (original)
+++ cfe/branches/tooling/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp Wed Apr 18 02:59:17 2012
@@ -105,3 +105,16 @@
 
   base<types> val = base<types>();
 }
+
+namespace pr9485 {
+  template <typename T> void f1(T) throw(typename T::exception); // expected-note {{candidate}}
+  template <typename T> void f1(T, int = 0) throw(typename T::noitpecxe); // expected-note {{candidate}}
+
+  template <typename T> void f2(T) noexcept(T::throws); // expected-note {{candidate}}
+  template <typename T> void f2(T, int = 0) noexcept(T::sworht); // expected-note {{candidate}}
+
+  void test() {
+    f1(0); // expected-error {{ambiguous}}
+    f2(0); // expected-error {{ambiguous}}
+  }
+}

Modified: cfe/branches/tooling/tools/clang-check/ClangCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/tools/clang-check/ClangCheck.cpp?rev=154991&r1=154990&r2=154991&view=diff
==============================================================================
--- cfe/branches/tooling/tools/clang-check/ClangCheck.cpp (original)
+++ cfe/branches/tooling/tools/clang-check/ClangCheck.cpp Wed Apr 18 02:59:17 2012
@@ -50,13 +50,17 @@
   cl::desc("<source0> [... <sourceN>]"),
   cl::OneOrMore);
 
-int main(int argc, char **argv) {
-  cl::ParseCommandLineOptions(argc, argv);
-  std::string ErrorMessage;
+int main(int argc, const char **argv) {
   llvm::OwningPtr<CompilationDatabase> Compilations(
-    CompilationDatabase::loadFromDirectory(BuildPath, ErrorMessage));
-  if (!Compilations)
-    llvm::report_fatal_error(ErrorMessage);
+    FixedCompilationDatabase::loadFromCommandLine(argc, argv));
+  cl::ParseCommandLineOptions(argc, argv);
+  if (!Compilations) {
+    std::string ErrorMessage;
+    Compilations.reset(CompilationDatabase::loadFromDirectory(BuildPath,
+                                                              ErrorMessage));
+    if (!Compilations)
+      llvm::report_fatal_error(ErrorMessage);
+  }
   ClangTool Tool(*Compilations, SourcePaths);
   return Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>());
 }

Modified: cfe/branches/tooling/unittests/Tooling/CompilationDatabaseTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/unittests/Tooling/CompilationDatabaseTest.cpp?rev=154991&r1=154990&r2=154991&view=diff
==============================================================================
--- cfe/branches/tooling/unittests/Tooling/CompilationDatabaseTest.cpp (original)
+++ cfe/branches/tooling/unittests/Tooling/CompilationDatabaseTest.cpp Wed Apr 18 02:59:17 2012
@@ -219,5 +219,74 @@
   EXPECT_EQ("", Empty[0]);
 }
 
+TEST(FixedCompilationDatabase, ReturnsFixedCommandLine) {
+  std::vector<std::string> CommandLine;
+  CommandLine.push_back("one");
+  CommandLine.push_back("two");
+  FixedCompilationDatabase Database(".", CommandLine);
+  std::vector<CompileCommand> Result =
+    Database.getCompileCommands("source");
+  ASSERT_EQ(1ul, Result.size());
+  std::vector<std::string> ExpectedCommandLine(1, "clang-tool");
+  ExpectedCommandLine.insert(ExpectedCommandLine.end(),
+                             CommandLine.begin(), CommandLine.end());
+  ExpectedCommandLine.push_back("source");
+  EXPECT_EQ(".", Result[0].Directory);
+  EXPECT_EQ(ExpectedCommandLine, Result[0].CommandLine);
+}
+
+TEST(ParseFixedCompilationDatabase, ReturnsNullOnEmptyArgumentList) {
+  int Argc = 0;
+  llvm::OwningPtr<FixedCompilationDatabase> Database(
+      FixedCompilationDatabase::loadFromCommandLine(Argc, NULL));
+  EXPECT_FALSE(Database);
+  EXPECT_EQ(0, Argc);
+}
+
+TEST(ParseFixedCompilationDatabase, ReturnsNullWithoutDoubleDash) {
+  int Argc = 2;
+  const char *Argv[] = { "1", "2" };
+  llvm::OwningPtr<FixedCompilationDatabase> Database(
+      FixedCompilationDatabase::loadFromCommandLine(Argc, Argv));
+  EXPECT_FALSE(Database);
+  EXPECT_EQ(2, Argc);
+}
+
+TEST(ParseFixedCompilationDatabase, ReturnsArgumentsAfterDoubleDash) {
+  int Argc = 5;
+  const char *Argv[] = { "1", "2", "--\0no-constant-folding", "3", "4" };
+  llvm::OwningPtr<FixedCompilationDatabase> Database(
+      FixedCompilationDatabase::loadFromCommandLine(Argc, Argv));
+  ASSERT_TRUE(Database);
+  std::vector<CompileCommand> Result =
+    Database->getCompileCommands("source");
+  ASSERT_EQ(1ul, Result.size());
+  ASSERT_EQ(".", Result[0].Directory);
+  std::vector<std::string> CommandLine;
+  CommandLine.push_back("clang-tool");
+  CommandLine.push_back("3");
+  CommandLine.push_back("4");
+  CommandLine.push_back("source");
+  ASSERT_EQ(CommandLine, Result[0].CommandLine);
+  EXPECT_EQ(2, Argc);
+}
+
+TEST(ParseFixedCompilationDatabase, ReturnsEmptyCommandLine) {
+  int Argc = 3;
+  const char *Argv[] = { "1", "2", "--\0no-constant-folding" };
+  llvm::OwningPtr<FixedCompilationDatabase> Database(
+      FixedCompilationDatabase::loadFromCommandLine(Argc, Argv));
+  ASSERT_TRUE(Database);
+  std::vector<CompileCommand> Result =
+    Database->getCompileCommands("source");
+  ASSERT_EQ(1ul, Result.size());
+  ASSERT_EQ(".", Result[0].Directory);
+  std::vector<std::string> CommandLine;
+  CommandLine.push_back("clang-tool");
+  CommandLine.push_back("source");
+  ASSERT_EQ(CommandLine, Result[0].CommandLine);
+  EXPECT_EQ(2, Argc);
+}
+
 } // end namespace tooling
 } // end namespace clang





More information about the llvm-branch-commits mailing list