Updated to Clang 3.5a.

Change-Id: I8127eb568f674c2e72635b639a3295381fe8af82
diff --git a/tools/libclang/CIndexDiagnostic.cpp b/tools/libclang/CIndexDiagnostic.cpp
index 0e9dde8..cf9dc6f 100644
--- a/tools/libclang/CIndexDiagnostic.cpp
+++ b/tools/libclang/CIndexDiagnostic.cpp
@@ -51,32 +51,35 @@
       Message(Msg), Loc(L) {}
 
   virtual ~CXDiagnosticCustomNoteImpl() {}
-  
-  CXDiagnosticSeverity getSeverity() const {
+
+  CXDiagnosticSeverity getSeverity() const override {
     return CXDiagnostic_Note;
   }
-  
-  CXSourceLocation getLocation() const {
+
+  CXSourceLocation getLocation() const override {
     return Loc;
   }
-  
-  CXString getSpelling() const {
+
+  CXString getSpelling() const override {
     return cxstring::createRef(Message.c_str());
   }
-  
-  CXString getDiagnosticOption(CXString *Disable) const {
+
+  CXString getDiagnosticOption(CXString *Disable) const override {
     if (Disable)
       *Disable = cxstring::createEmpty();
     return cxstring::createEmpty();
   }
-  
-  unsigned getCategory() const { return 0; }
-  CXString getCategoryText() const { return cxstring::createEmpty(); }
 
-  unsigned getNumRanges() const { return 0; }
-  CXSourceRange getRange(unsigned Range) const { return clang_getNullRange(); }
-  unsigned getNumFixIts() const { return 0; }
-  CXString getFixIt(unsigned FixIt, CXSourceRange *ReplacementRange) const {
+  unsigned getCategory() const override { return 0; }
+  CXString getCategoryText() const override { return cxstring::createEmpty(); }
+
+  unsigned getNumRanges() const override { return 0; }
+  CXSourceRange getRange(unsigned Range) const override {
+    return clang_getNullRange();
+  }
+  unsigned getNumFixIts() const override { return 0; }
+  CXString getFixIt(unsigned FixIt,
+                    CXSourceRange *ReplacementRange) const override {
     if (ReplacementRange)
       *ReplacementRange = clang_getNullRange();
     return cxstring::createEmpty();
@@ -93,9 +96,9 @@
   
   virtual ~CXDiagnosticRenderer() {}
 
-  virtual void beginDiagnostic(DiagOrStoredDiag D,
-                               DiagnosticsEngine::Level Level) {    
-    
+  void beginDiagnostic(DiagOrStoredDiag D,
+                       DiagnosticsEngine::Level Level) override {
+
     const StoredDiagnostic *SD = D.dyn_cast<const StoredDiagnostic*>();
     if (!SD)
       return;
@@ -109,13 +112,13 @@
     if (Level != DiagnosticsEngine::Note)
       CurrentSet = &CD->getChildDiagnostics();
   }
-  
-  virtual void emitDiagnosticMessage(SourceLocation Loc, PresumedLoc PLoc,
-                                     DiagnosticsEngine::Level Level,
-                                     StringRef Message,
-                                     ArrayRef<CharSourceRange> Ranges,
-                                     const SourceManager *SM,
-                                     DiagOrStoredDiag D) {
+
+  void emitDiagnosticMessage(SourceLocation Loc, PresumedLoc PLoc,
+                             DiagnosticsEngine::Level Level,
+                             StringRef Message,
+                             ArrayRef<CharSourceRange> Ranges,
+                             const SourceManager *SM,
+                             DiagOrStoredDiag D) override {
     if (!D.isNull())
       return;
     
@@ -127,20 +130,20 @@
     CXDiagnosticImpl *CD = new CXDiagnosticCustomNoteImpl(Message, L);
     CurrentSet->appendDiagnostic(CD);
   }
-  
-  virtual void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
-                                 DiagnosticsEngine::Level Level,
-                                 ArrayRef<CharSourceRange> Ranges,
-                                 const SourceManager &SM) {}
 
-  virtual void emitCodeContext(SourceLocation Loc,
-                               DiagnosticsEngine::Level Level,
-                               SmallVectorImpl<CharSourceRange>& Ranges,
-                               ArrayRef<FixItHint> Hints,
-                               const SourceManager &SM) {}
-  
-  virtual void emitNote(SourceLocation Loc, StringRef Message,
-                        const SourceManager *SM) {
+  void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
+                         DiagnosticsEngine::Level Level,
+                         ArrayRef<CharSourceRange> Ranges,
+                         const SourceManager &SM) override {}
+
+  void emitCodeContext(SourceLocation Loc,
+                       DiagnosticsEngine::Level Level,
+                       SmallVectorImpl<CharSourceRange>& Ranges,
+                       ArrayRef<FixItHint> Hints,
+                       const SourceManager &SM) override {}
+
+  void emitNote(SourceLocation Loc, StringRef Message,
+                const SourceManager *SM) override {
     CXSourceLocation L;
     if (SM)
       L = translateSourceLocation(*SM, LangOpts, Loc);
@@ -208,12 +211,21 @@
 extern "C" {
 
 unsigned clang_getNumDiagnostics(CXTranslationUnit Unit) {
+  if (cxtu::isNotUsableTU(Unit)) {
+    LOG_BAD_TU(Unit);
+    return 0;
+  }
   if (!cxtu::getASTUnit(Unit))
     return 0;
   return lazyCreateDiags(Unit, /*checkIfChanged=*/true)->getNumDiagnostics();
 }
 
 CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit, unsigned Index) {
+  if (cxtu::isNotUsableTU(Unit)) {
+    LOG_BAD_TU(Unit);
+    return 0;
+  }
+
   CXDiagnosticSet D = clang_getDiagnosticSetFromTU(Unit);
   if (!D)
     return 0;
@@ -224,8 +236,12 @@
 
   return Diags->getDiagnostic(Index);
 }
-  
+
 CXDiagnosticSet clang_getDiagnosticSetFromTU(CXTranslationUnit Unit) {
+  if (cxtu::isNotUsableTU(Unit)) {
+    LOG_BAD_TU(Unit);
+    return 0;
+  }
   if (!cxtu::getASTUnit(Unit))
     return 0;
   return static_cast<CXDiagnostic>(lazyCreateDiags(Unit));
@@ -292,6 +308,7 @@
   switch (Severity) {
   case CXDiagnostic_Ignored: llvm_unreachable("impossible");
   case CXDiagnostic_Note: Out << "note: "; break;
+  case CXDiagnostic_Remark: Out << "remark: "; break;
   case CXDiagnostic_Warning: Out << "warning: "; break;
   case CXDiagnostic_Error: Out << "error: "; break;
   case CXDiagnostic_Fatal: Out << "fatal error: "; break;
@@ -437,9 +454,10 @@
 }
 
 void clang_disposeDiagnosticSet(CXDiagnosticSet Diags) {
-  CXDiagnosticSetImpl *D = static_cast<CXDiagnosticSetImpl*>(Diags);
-  if (D->isExternallyManaged())
-    delete D;
+  if (CXDiagnosticSetImpl *D = static_cast<CXDiagnosticSetImpl *>(Diags)) {
+    if (D->isExternallyManaged())
+      delete D;
+  }
 }
   
 CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags,