Change the fixed array of FixitHints to a SmallVector to lift off
the limit on the number of fixits.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149676 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h
index 3aa1d55..8cb1e19 100644
--- a/include/clang/Basic/Diagnostic.h
+++ b/include/clang/Basic/Diagnostic.h
@@ -614,9 +614,6 @@
   signed char NumDiagArgs;
   /// NumRanges - This is the number of ranges in the DiagRanges array.
   unsigned char NumDiagRanges;
-  /// \brief The number of code modifications hints in the
-  /// FixItHints array.
-  unsigned char NumFixItHints;
 
   /// DiagArgumentsKind - This is an array of ArgumentKind::ArgumentKind enum
   /// values, with one for each argument.  This specifies whether the argument
@@ -638,11 +635,9 @@
   /// only support 10 ranges, could easily be extended if needed.
   CharSourceRange DiagRanges[10];
 
-  enum { MaxFixItHints = 6 };
-
   /// FixItHints - If valid, provides a hint with some code
   /// to insert, remove, or modify at a particular position.
-  FixItHint FixItHints[MaxFixItHints];
+  SmallVector<FixItHint, 6> FixItHints;
 
   DiagnosticMappingInfo makeMappingInfo(diag::Mapping Map, SourceLocation L) {
     bool isPragma = L.isValid();
@@ -720,12 +715,14 @@
 /// for example.
 class DiagnosticBuilder {
   mutable DiagnosticsEngine *DiagObj;
-  mutable unsigned NumArgs, NumRanges, NumFixItHints;
+  mutable unsigned NumArgs, NumRanges;
 
   void operator=(const DiagnosticBuilder&); // DO NOT IMPLEMENT
   friend class DiagnosticsEngine;
   explicit DiagnosticBuilder(DiagnosticsEngine *diagObj)
-    : DiagObj(diagObj), NumArgs(0), NumRanges(0), NumFixItHints(0) {}
+    : DiagObj(diagObj), NumArgs(0), NumRanges(0) {
+    DiagObj->FixItHints.clear();
+  }
 
   friend class PartialDiagnostic;
 
@@ -740,7 +737,6 @@
     D.DiagObj = 0;
     NumArgs = D.NumArgs;
     NumRanges = D.NumRanges;
-    NumFixItHints = D.NumFixItHints;
   }
 
   /// \brief Simple enumeration value used to give a name to the
@@ -750,7 +746,7 @@
   /// \brief Create an empty DiagnosticBuilder object that represents
   /// no actual diagnostic.
   explicit DiagnosticBuilder(SuppressKind)
-    : DiagObj(0), NumArgs(0), NumRanges(0), NumFixItHints(0) { }
+    : DiagObj(0), NumArgs(0), NumRanges(0) { }
 
   /// \brief Force the diagnostic builder to emit the diagnostic now.
   ///
@@ -816,12 +812,8 @@
   }
 
   void AddFixItHint(const FixItHint &Hint) const {
-    assert(NumFixItHints < DiagnosticsEngine::MaxFixItHints &&
-           "Too many fix-it hints!");
-    if (NumFixItHints >= DiagnosticsEngine::MaxFixItHints)
-      return;  // Don't crash in release builds
     if (DiagObj)
-      DiagObj->FixItHints[NumFixItHints++] = Hint;
+      DiagObj->FixItHints.push_back(Hint);
   }
 };
 
@@ -997,7 +989,7 @@
   }
 
   unsigned getNumFixItHints() const {
-    return DiagObj->NumFixItHints;
+    return DiagObj->FixItHints.size();
   }
 
   const FixItHint &getFixItHint(unsigned Idx) const {
@@ -1005,8 +997,8 @@
   }
 
   const FixItHint *getFixItHints() const {
-    return DiagObj->NumFixItHints?
-             &DiagObj->FixItHints[0] : 0;
+    return getNumFixItHints()?
+             DiagObj->FixItHints.data() : 0;
   }
 
   /// FormatDiagnostic - Format this diagnostic into a string, substituting the
diff --git a/include/clang/Basic/PartialDiagnostic.h b/include/clang/Basic/PartialDiagnostic.h
index 6049123..f6092e6 100644
--- a/include/clang/Basic/PartialDiagnostic.h
+++ b/include/clang/Basic/PartialDiagnostic.h
@@ -30,12 +30,11 @@
       // DiagnosticsEngine are private but DiagnosticsEngine declares
       // PartialDiagnostic a friend.  These enum values are redeclared
       // here so that the nested Storage class below can access them.
-      MaxArguments = DiagnosticsEngine::MaxArguments,
-      MaxFixItHints = DiagnosticsEngine::MaxFixItHints
+      MaxArguments = DiagnosticsEngine::MaxArguments
   };
 
   struct Storage {
-    Storage() : NumDiagArgs(0), NumDiagRanges(0), NumFixItHints(0) { }
+    Storage() : NumDiagArgs(0), NumDiagRanges(0) { }
 
     enum {
         /// MaxArguments - The maximum number of arguments we can hold. We
@@ -51,10 +50,6 @@
     /// NumDiagRanges - This is the number of ranges in the DiagRanges array.
     unsigned char NumDiagRanges;
 
-    /// \brief The number of code modifications hints in the
-    /// FixItHints array.
-    unsigned char NumFixItHints;
-
     /// DiagArgumentsKind - This is an array of ArgumentKind::ArgumentKind enum
     /// values, with one for each argument.  This specifies whether the argument
     /// is in DiagArgumentsStr or in DiagArguments.
@@ -74,11 +69,9 @@
     /// only support 10 ranges, could easily be extended if needed.
     CharSourceRange DiagRanges[10];
 
-    enum { MaxFixItHints = PartialDiagnostic::MaxFixItHints };
-
     /// FixItHints - If valid, provides a hint with some code
     /// to insert, remove, or modify at a particular position.
-    FixItHint FixItHints[MaxFixItHints];
+    SmallVector<FixItHint, 6>  FixItHints;
   };
 
   /// \brief An allocator for Storage objects, which uses a small cache to
@@ -101,7 +94,7 @@
       Storage *Result = FreeList[--NumFreeListEntries];
       Result->NumDiagArgs = 0;
       Result->NumDiagRanges = 0;
-      Result->NumFixItHints = 0;
+      Result->FixItHints.clear();
       return Result;
     }
 
@@ -172,12 +165,7 @@
     if (!DiagStorage)
       DiagStorage = getStorage();
 
-    assert(DiagStorage->NumFixItHints < Storage::MaxFixItHints &&
-           "Too many code modification hints!");
-    if (DiagStorage->NumFixItHints >= Storage::MaxFixItHints)
-      return;  // Don't crash in release builds
-    DiagStorage->FixItHints[DiagStorage->NumFixItHints++]
-      = Hint;
+    DiagStorage->FixItHints.push_back(Hint);
   }
 
 public:
@@ -281,7 +269,7 @@
       DB.AddSourceRange(DiagStorage->DiagRanges[i]);
 
     // Add all fix-its.
-    for (unsigned i = 0, e = DiagStorage->NumFixItHints; i != e; ++i)
+    for (unsigned i = 0, e = DiagStorage->FixItHints.size(); i != e; ++i)
       DB.AddFixItHint(DiagStorage->FixItHints[i]);
   }
 
diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp
index d18d760..c330215 100644
--- a/lib/Basic/Diagnostic.cpp
+++ b/lib/Basic/Diagnostic.cpp
@@ -330,14 +330,11 @@
          RE = storedDiag.range_end(); RI != RE; ++RI)
     DiagRanges[i++] = *RI;
 
-  NumFixItHints = storedDiag.fixit_size();
-  assert(NumFixItHints < DiagnosticsEngine::MaxFixItHints &&
-      "Too many fix-it hints!");
-  i = 0;
+  FixItHints.clear();
   for (StoredDiagnostic::fixit_iterator
          FI = storedDiag.fixit_begin(),
          FE = storedDiag.fixit_end(); FI != FE; ++FI)
-    FixItHints[i++] = *FI;
+    FixItHints.push_back(*FI);
 
   assert(Client && "DiagnosticConsumer not set!");
   Level DiagLevel = storedDiag.getLevel();
@@ -354,7 +351,6 @@
 void DiagnosticBuilder::FlushCounts() {
   DiagObj->NumDiagArgs = NumArgs;
   DiagObj->NumDiagRanges = NumRanges;
-  DiagObj->NumFixItHints = NumFixItHints;
 }
 
 bool DiagnosticBuilder::Emit() {
diff --git a/lib/Basic/DiagnosticIDs.cpp b/lib/Basic/DiagnosticIDs.cpp
index 9f09f72..1e8f44d 100644
--- a/lib/Basic/DiagnosticIDs.cpp
+++ b/lib/Basic/DiagnosticIDs.cpp
@@ -799,12 +799,12 @@
   // If we have any Fix-Its, make sure that all of the Fix-Its point into
   // source locations that aren't macro expansions. If any point into macro
   // expansions, remove all of the Fix-Its.
-  for (unsigned I = 0, N = Diag.NumFixItHints; I != N; ++I) {
+  for (unsigned I = 0, N = Diag.FixItHints.size(); I != N; ++I) {
     const FixItHint &FixIt = Diag.FixItHints[I];
     if (FixIt.RemoveRange.isInvalid() ||
         FixIt.RemoveRange.getBegin().isMacroID() ||
         FixIt.RemoveRange.getEnd().isMacroID()) {
-      Diag.NumFixItHints = 0;
+      Diag.FixItHints.clear();
       break;
     }    
   }