blob: b7f130acd5945ad1372944e53ab80e2697b05294 [file] [log] [blame]
Chris Lattner22eb9722006-06-18 05:43:12 +00001//===--- Diagnostic.cpp - C Language Family Diagnostic Handling -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner22eb9722006-06-18 05:43:12 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Diagnostic-related interfaces.
11//
12//===----------------------------------------------------------------------===//
13
Ted Kremenek39a76652010-04-12 19:54:17 +000014#include "clang/Basic/Diagnostic.h"
Chris Lattnerb91fd172008-11-19 07:32:16 +000015#include "clang/Basic/IdentifierTable.h"
Ted Kremenek39a76652010-04-12 19:54:17 +000016#include "clang/Basic/PartialDiagnostic.h"
Chris Lattner23be0672008-11-19 06:51:40 +000017#include "llvm/ADT/SmallVector.h"
Daniel Dunbare3633792009-10-17 18:12:14 +000018#include "llvm/Support/raw_ostream.h"
Ted Kremenek84de4a12011-03-21 18:40:07 +000019#include "llvm/Support/CrashRecoveryContext.h"
20
Chris Lattner22eb9722006-06-18 05:43:12 +000021using namespace clang;
22
David Blaikie9c902b52011-09-25 23:23:43 +000023static void DummyArgToStringFn(DiagnosticsEngine::ArgumentKind AK, intptr_t QT,
Chris Lattner63ecc502008-11-23 09:21:17 +000024 const char *Modifier, unsigned ML,
25 const char *Argument, unsigned ArgLen,
David Blaikie9c902b52011-09-25 23:23:43 +000026 const DiagnosticsEngine::ArgumentValue *PrevArgs,
Chris Lattnerc243f292009-10-20 05:25:22 +000027 unsigned NumPrevArgs,
Chris Lattner0e62c1c2011-07-23 10:55:15 +000028 SmallVectorImpl<char> &Output,
Chandler Carruthd5173952011-07-11 17:49:21 +000029 void *Cookie,
Chris Lattner0e62c1c2011-07-23 10:55:15 +000030 SmallVectorImpl<intptr_t> &QualTypeVals) {
Chris Lattner63ecc502008-11-23 09:21:17 +000031 const char *Str = "<can't format argument>";
Chris Lattner6a2ed6f2008-11-23 09:13:29 +000032 Output.append(Str, Str+strlen(Str));
33}
34
35
David Blaikie9c902b52011-09-25 23:23:43 +000036DiagnosticsEngine::DiagnosticsEngine(
37 const llvm::IntrusiveRefCntPtr<DiagnosticIDs> &diags,
David Blaikiee2eefae2011-09-25 23:39:51 +000038 DiagnosticConsumer *client, bool ShouldOwnClient)
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +000039 : Diags(diags), Client(client), OwnsDiagClient(ShouldOwnClient),
40 SourceMgr(0) {
Chris Lattner63ecc502008-11-23 09:21:17 +000041 ArgToStringFn = DummyArgToStringFn;
Chris Lattnercf868c42009-02-19 23:53:20 +000042 ArgToStringCookie = 0;
Mike Stump11289f42009-09-09 15:08:12 +000043
Douglas Gregor0e119552010-07-31 00:40:00 +000044 AllExtensionsSilenced = 0;
45 IgnoreAllWarnings = false;
46 WarningsAsErrors = false;
Ted Kremenekfbbdced2011-08-18 01:12:56 +000047 EnableAllWarnings = false;
Douglas Gregor0e119552010-07-31 00:40:00 +000048 ErrorsAsFatal = false;
49 SuppressSystemWarnings = false;
50 SuppressAllDiagnostics = false;
51 ShowOverloads = Ovl_All;
52 ExtBehavior = Ext_Ignore;
53
54 ErrorLimit = 0;
55 TemplateBacktraceLimit = 0;
Douglas Gregor0e119552010-07-31 00:40:00 +000056
Douglas Gregoraa21cc42010-07-19 21:46:24 +000057 Reset();
Chris Lattnerae411572006-07-05 00:55:08 +000058}
59
David Blaikie9c902b52011-09-25 23:23:43 +000060DiagnosticsEngine::~DiagnosticsEngine() {
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +000061 if (OwnsDiagClient)
62 delete Client;
Chris Lattnere6535cf2007-12-02 01:09:57 +000063}
64
David Blaikiee2eefae2011-09-25 23:39:51 +000065void DiagnosticsEngine::setClient(DiagnosticConsumer *client,
David Blaikie9c902b52011-09-25 23:23:43 +000066 bool ShouldOwnClient) {
Douglas Gregor7a964ad2011-01-31 22:04:05 +000067 if (OwnsDiagClient && Client)
68 delete Client;
69
70 Client = client;
71 OwnsDiagClient = ShouldOwnClient;
72}
Chris Lattnerfb42a182009-07-12 21:18:45 +000073
David Blaikie9c902b52011-09-25 23:23:43 +000074void DiagnosticsEngine::pushMappings(SourceLocation Loc) {
Argyrios Kyrtzidis1cb0de12010-12-15 18:44:22 +000075 DiagStateOnPushStack.push_back(GetCurDiagState());
Chris Lattnerfb42a182009-07-12 21:18:45 +000076}
77
David Blaikie9c902b52011-09-25 23:23:43 +000078bool DiagnosticsEngine::popMappings(SourceLocation Loc) {
Argyrios Kyrtzidis1cb0de12010-12-15 18:44:22 +000079 if (DiagStateOnPushStack.empty())
Chris Lattnerfb42a182009-07-12 21:18:45 +000080 return false;
81
Argyrios Kyrtzidis1cb0de12010-12-15 18:44:22 +000082 if (DiagStateOnPushStack.back() != GetCurDiagState()) {
83 // State changed at some point between push/pop.
84 PushDiagStatePoint(DiagStateOnPushStack.back(), Loc);
85 }
86 DiagStateOnPushStack.pop_back();
Chris Lattnerfb42a182009-07-12 21:18:45 +000087 return true;
88}
89
David Blaikie9c902b52011-09-25 23:23:43 +000090void DiagnosticsEngine::Reset() {
Douglas Gregoraa21cc42010-07-19 21:46:24 +000091 ErrorOccurred = false;
92 FatalErrorOccurred = false;
Douglas Gregor8a60bbe2011-07-06 17:40:26 +000093 UnrecoverableErrorOccurred = false;
Douglas Gregoraa21cc42010-07-19 21:46:24 +000094
95 NumWarnings = 0;
96 NumErrors = 0;
97 NumErrorsSuppressed = 0;
Argyrios Kyrtzidis1fa8b4b2011-07-29 01:25:44 +000098 TrapNumErrorsOccurred = 0;
99 TrapNumUnrecoverableErrorsOccurred = 0;
Douglas Gregor8a60bbe2011-07-06 17:40:26 +0000100
Douglas Gregoraa21cc42010-07-19 21:46:24 +0000101 CurDiagID = ~0U;
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000102 // Set LastDiagLevel to an "unset" state. If we set it to 'Ignored', notes
David Blaikie9c902b52011-09-25 23:23:43 +0000103 // using a DiagnosticsEngine associated to a translation unit that follow
104 // diagnostics from a DiagnosticsEngine associated to anoter t.u. will not be
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000105 // displayed.
106 LastDiagLevel = (DiagnosticIDs::Level)-1;
Douglas Gregoraa21cc42010-07-19 21:46:24 +0000107 DelayedDiagID = 0;
Argyrios Kyrtzidisbbbeea12011-03-26 18:58:17 +0000108
109 // Clear state related to #pragma diagnostic.
110 DiagStates.clear();
111 DiagStatePoints.clear();
112 DiagStateOnPushStack.clear();
113
114 // Create a DiagState and DiagStatePoint representing diagnostic changes
115 // through command-line.
116 DiagStates.push_back(DiagState());
117 PushDiagStatePoint(&DiagStates.back(), SourceLocation());
Douglas Gregoraa21cc42010-07-19 21:46:24 +0000118}
Chris Lattner22eb9722006-06-18 05:43:12 +0000119
David Blaikie9c902b52011-09-25 23:23:43 +0000120void DiagnosticsEngine::SetDelayedDiagnostic(unsigned DiagID, StringRef Arg1,
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000121 StringRef Arg2) {
Douglas Gregor85795312010-03-22 15:10:57 +0000122 if (DelayedDiagID)
123 return;
124
125 DelayedDiagID = DiagID;
Douglas Gregor96380982010-03-22 15:47:45 +0000126 DelayedDiagArg1 = Arg1.str();
127 DelayedDiagArg2 = Arg2.str();
Douglas Gregor85795312010-03-22 15:10:57 +0000128}
129
David Blaikie9c902b52011-09-25 23:23:43 +0000130void DiagnosticsEngine::ReportDelayed() {
Douglas Gregor85795312010-03-22 15:10:57 +0000131 Report(DelayedDiagID) << DelayedDiagArg1 << DelayedDiagArg2;
132 DelayedDiagID = 0;
133 DelayedDiagArg1.clear();
134 DelayedDiagArg2.clear();
135}
136
David Blaikie9c902b52011-09-25 23:23:43 +0000137DiagnosticsEngine::DiagStatePointsTy::iterator
138DiagnosticsEngine::GetDiagStatePointForLoc(SourceLocation L) const {
Argyrios Kyrtzidis1cb0de12010-12-15 18:44:22 +0000139 assert(!DiagStatePoints.empty());
140 assert(DiagStatePoints.front().Loc.isInvalid() &&
141 "Should have created a DiagStatePoint for command-line");
142
143 FullSourceLoc Loc(L, *SourceMgr);
144 if (Loc.isInvalid())
145 return DiagStatePoints.end() - 1;
146
147 DiagStatePointsTy::iterator Pos = DiagStatePoints.end();
148 FullSourceLoc LastStateChangePos = DiagStatePoints.back().Loc;
149 if (LastStateChangePos.isValid() &&
150 Loc.isBeforeInTranslationUnitThan(LastStateChangePos))
151 Pos = std::upper_bound(DiagStatePoints.begin(), DiagStatePoints.end(),
152 DiagStatePoint(0, Loc));
153 --Pos;
154 return Pos;
155}
156
157/// \brief This allows the client to specify that certain
158/// warnings are ignored. Notes can never be mapped, errors can only be
159/// mapped to fatal, and WARNINGs and EXTENSIONs can be mapped arbitrarily.
160///
161/// \param The source location that this change of diagnostic state should
162/// take affect. It can be null if we are setting the latest state.
David Blaikie9c902b52011-09-25 23:23:43 +0000163void DiagnosticsEngine::setDiagnosticMapping(diag::kind Diag, diag::Mapping Map,
Argyrios Kyrtzidis1cb0de12010-12-15 18:44:22 +0000164 SourceLocation L) {
165 assert(Diag < diag::DIAG_UPPER_LIMIT &&
166 "Can only map builtin diagnostics");
167 assert((Diags->isBuiltinWarningOrExtension(Diag) ||
168 (Map == diag::MAP_FATAL || Map == diag::MAP_ERROR)) &&
169 "Cannot map errors into warnings!");
170 assert(!DiagStatePoints.empty());
171
Argyrios Kyrtzidis243aedb2011-01-14 20:54:07 +0000172 bool isPragma = L.isValid();
Argyrios Kyrtzidis1cb0de12010-12-15 18:44:22 +0000173 FullSourceLoc Loc(L, *SourceMgr);
174 FullSourceLoc LastStateChangePos = DiagStatePoints.back().Loc;
175
176 // Common case; setting all the diagnostics of a group in one place.
177 if (Loc.isInvalid() || Loc == LastStateChangePos) {
Argyrios Kyrtzidis243aedb2011-01-14 20:54:07 +0000178 setDiagnosticMappingInternal(Diag, Map, GetCurDiagState(), true, isPragma);
Argyrios Kyrtzidis1cb0de12010-12-15 18:44:22 +0000179 return;
180 }
181
182 // Another common case; modifying diagnostic state in a source location
183 // after the previous one.
184 if ((Loc.isValid() && LastStateChangePos.isInvalid()) ||
185 LastStateChangePos.isBeforeInTranslationUnitThan(Loc)) {
Chris Lattner57540c52011-04-15 05:22:18 +0000186 // A diagnostic pragma occurred, create a new DiagState initialized with
Argyrios Kyrtzidis1cb0de12010-12-15 18:44:22 +0000187 // the current one and a new DiagStatePoint to record at which location
188 // the new state became active.
189 DiagStates.push_back(*GetCurDiagState());
190 PushDiagStatePoint(&DiagStates.back(), Loc);
Argyrios Kyrtzidis243aedb2011-01-14 20:54:07 +0000191 setDiagnosticMappingInternal(Diag, Map, GetCurDiagState(), true, isPragma);
Argyrios Kyrtzidis1cb0de12010-12-15 18:44:22 +0000192 return;
193 }
194
195 // We allow setting the diagnostic state in random source order for
196 // completeness but it should not be actually happening in normal practice.
197
198 DiagStatePointsTy::iterator Pos = GetDiagStatePointForLoc(Loc);
199 assert(Pos != DiagStatePoints.end());
200
201 // Update all diagnostic states that are active after the given location.
202 for (DiagStatePointsTy::iterator
203 I = Pos+1, E = DiagStatePoints.end(); I != E; ++I) {
Argyrios Kyrtzidis243aedb2011-01-14 20:54:07 +0000204 setDiagnosticMappingInternal(Diag, Map, I->State, true, isPragma);
Argyrios Kyrtzidis1cb0de12010-12-15 18:44:22 +0000205 }
206
207 // If the location corresponds to an existing point, just update its state.
208 if (Pos->Loc == Loc) {
Argyrios Kyrtzidis243aedb2011-01-14 20:54:07 +0000209 setDiagnosticMappingInternal(Diag, Map, Pos->State, true, isPragma);
Argyrios Kyrtzidis1cb0de12010-12-15 18:44:22 +0000210 return;
211 }
212
213 // Create a new state/point and fit it into the vector of DiagStatePoints
214 // so that the vector is always ordered according to location.
215 Pos->Loc.isBeforeInTranslationUnitThan(Loc);
216 DiagStates.push_back(*Pos->State);
217 DiagState *NewState = &DiagStates.back();
Argyrios Kyrtzidis243aedb2011-01-14 20:54:07 +0000218 setDiagnosticMappingInternal(Diag, Map, NewState, true, isPragma);
Argyrios Kyrtzidis1cb0de12010-12-15 18:44:22 +0000219 DiagStatePoints.insert(Pos+1, DiagStatePoint(NewState,
220 FullSourceLoc(Loc, *SourceMgr)));
221}
222
David Blaikie9c902b52011-09-25 23:23:43 +0000223void DiagnosticsEngine::Report(const StoredDiagnostic &storedDiag) {
Argyrios Kyrtzidise9af37d2011-05-05 07:54:59 +0000224 assert(CurDiagID == ~0U && "Multiple diagnostics in flight at once!");
225
226 CurDiagLoc = storedDiag.getLocation();
227 CurDiagID = storedDiag.getID();
228 NumDiagArgs = 0;
229
230 NumDiagRanges = storedDiag.range_size();
231 assert(NumDiagRanges < sizeof(DiagRanges)/sizeof(DiagRanges[0]) &&
232 "Too many arguments to diagnostic!");
233 unsigned i = 0;
234 for (StoredDiagnostic::range_iterator
235 RI = storedDiag.range_begin(),
236 RE = storedDiag.range_end(); RI != RE; ++RI)
237 DiagRanges[i++] = *RI;
238
239 NumFixItHints = storedDiag.fixit_size();
David Blaikie9c902b52011-09-25 23:23:43 +0000240 assert(NumFixItHints < DiagnosticsEngine::MaxFixItHints &&
241 "Too many fix-it hints!");
Argyrios Kyrtzidise9af37d2011-05-05 07:54:59 +0000242 i = 0;
243 for (StoredDiagnostic::fixit_iterator
244 FI = storedDiag.fixit_begin(),
245 FE = storedDiag.fixit_end(); FI != FE; ++FI)
246 FixItHints[i++] = *FI;
247
David Blaikiee2eefae2011-09-25 23:39:51 +0000248 assert(Client && "DiagnosticConsumer not set!");
Argyrios Kyrtzidise9af37d2011-05-05 07:54:59 +0000249 Level DiagLevel = storedDiag.getLevel();
250 DiagnosticInfo Info(this, storedDiag.getMessage());
251 Client->HandleDiagnostic(DiagLevel, Info);
252 if (Client->IncludeInDiagnosticCounts()) {
David Blaikie9c902b52011-09-25 23:23:43 +0000253 if (DiagLevel == DiagnosticsEngine::Warning)
Argyrios Kyrtzidise9af37d2011-05-05 07:54:59 +0000254 ++NumWarnings;
255 }
256
257 CurDiagID = ~0U;
258}
259
Douglas Gregorb3921592010-10-13 17:22:14 +0000260void DiagnosticBuilder::FlushCounts() {
261 DiagObj->NumDiagArgs = NumArgs;
262 DiagObj->NumDiagRanges = NumRanges;
263 DiagObj->NumFixItHints = NumFixItHints;
264}
265
Douglas Gregor85795312010-03-22 15:10:57 +0000266bool DiagnosticBuilder::Emit() {
267 // If DiagObj is null, then its soul was stolen by the copy ctor
268 // or the user called Emit().
269 if (DiagObj == 0) return false;
270
271 // When emitting diagnostics, we set the final argument count into
David Blaikie9c902b52011-09-25 23:23:43 +0000272 // the DiagnosticsEngine object.
Douglas Gregorb3921592010-10-13 17:22:14 +0000273 FlushCounts();
Douglas Gregor85795312010-03-22 15:10:57 +0000274
275 // Process the diagnostic, sending the accumulated information to the
David Blaikiee2eefae2011-09-25 23:39:51 +0000276 // DiagnosticConsumer.
Douglas Gregor85795312010-03-22 15:10:57 +0000277 bool Emitted = DiagObj->ProcessDiag();
278
279 // Clear out the current diagnostic object.
Douglas Gregor96380982010-03-22 15:47:45 +0000280 unsigned DiagID = DiagObj->CurDiagID;
Douglas Gregor85795312010-03-22 15:10:57 +0000281 DiagObj->Clear();
282
283 // If there was a delayed diagnostic, emit it now.
Douglas Gregor96380982010-03-22 15:47:45 +0000284 if (DiagObj->DelayedDiagID && DiagObj->DelayedDiagID != DiagID)
Douglas Gregor85795312010-03-22 15:10:57 +0000285 DiagObj->ReportDelayed();
286
287 // This diagnostic is dead.
288 DiagObj = 0;
289
290 return Emitted;
291}
292
Nico Weber4c311642008-08-10 19:59:06 +0000293
David Blaikiee2eefae2011-09-25 23:39:51 +0000294DiagnosticConsumer::~DiagnosticConsumer() {}
Nico Weber4c311642008-08-10 19:59:06 +0000295
David Blaikiee2eefae2011-09-25 23:39:51 +0000296void DiagnosticConsumer::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
Argyrios Kyrtzidisc79346a2010-11-18 20:06:46 +0000297 const DiagnosticInfo &Info) {
298 if (!IncludeInDiagnosticCounts())
299 return;
300
David Blaikie9c902b52011-09-25 23:23:43 +0000301 if (DiagLevel == DiagnosticsEngine::Warning)
Argyrios Kyrtzidisc79346a2010-11-18 20:06:46 +0000302 ++NumWarnings;
David Blaikie9c902b52011-09-25 23:23:43 +0000303 else if (DiagLevel >= DiagnosticsEngine::Error)
Argyrios Kyrtzidisc79346a2010-11-18 20:06:46 +0000304 ++NumErrors;
305}
Chris Lattner23be0672008-11-19 06:51:40 +0000306
Chris Lattner2b786902008-11-21 07:50:02 +0000307/// ModifierIs - Return true if the specified modifier matches specified string.
308template <std::size_t StrLen>
309static bool ModifierIs(const char *Modifier, unsigned ModifierLen,
310 const char (&Str)[StrLen]) {
311 return StrLen-1 == ModifierLen && !memcmp(Modifier, Str, StrLen-1);
312}
313
John McCall8cb7a8a32010-01-14 20:11:39 +0000314/// ScanForward - Scans forward, looking for the given character, skipping
315/// nested clauses and escaped characters.
316static const char *ScanFormat(const char *I, const char *E, char Target) {
317 unsigned Depth = 0;
318
319 for ( ; I != E; ++I) {
320 if (Depth == 0 && *I == Target) return I;
321 if (Depth != 0 && *I == '}') Depth--;
322
323 if (*I == '%') {
324 I++;
325 if (I == E) break;
326
327 // Escaped characters get implicitly skipped here.
328
329 // Format specifier.
330 if (!isdigit(*I) && !ispunct(*I)) {
331 for (I++; I != E && !isdigit(*I) && *I != '{'; I++) ;
332 if (I == E) break;
333 if (*I == '{')
334 Depth++;
335 }
336 }
337 }
338 return E;
339}
340
Chris Lattner2b786902008-11-21 07:50:02 +0000341/// HandleSelectModifier - Handle the integer 'select' modifier. This is used
342/// like this: %select{foo|bar|baz}2. This means that the integer argument
343/// "%2" has a value from 0-2. If the value is 0, the diagnostic prints 'foo'.
344/// If the value is 1, it prints 'bar'. If it has the value 2, it prints 'baz'.
345/// This is very useful for certain classes of variant diagnostics.
John McCalle4d54322010-01-13 23:58:20 +0000346static void HandleSelectModifier(const DiagnosticInfo &DInfo, unsigned ValNo,
Chris Lattner2b786902008-11-21 07:50:02 +0000347 const char *Argument, unsigned ArgumentLen,
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000348 SmallVectorImpl<char> &OutStr) {
Chris Lattner2b786902008-11-21 07:50:02 +0000349 const char *ArgumentEnd = Argument+ArgumentLen;
Mike Stump11289f42009-09-09 15:08:12 +0000350
Chris Lattner2b786902008-11-21 07:50:02 +0000351 // Skip over 'ValNo' |'s.
352 while (ValNo) {
John McCall8cb7a8a32010-01-14 20:11:39 +0000353 const char *NextVal = ScanFormat(Argument, ArgumentEnd, '|');
Chris Lattner2b786902008-11-21 07:50:02 +0000354 assert(NextVal != ArgumentEnd && "Value for integer select modifier was"
355 " larger than the number of options in the diagnostic string!");
356 Argument = NextVal+1; // Skip this string.
357 --ValNo;
358 }
Mike Stump11289f42009-09-09 15:08:12 +0000359
Chris Lattner2b786902008-11-21 07:50:02 +0000360 // Get the end of the value. This is either the } or the |.
John McCall8cb7a8a32010-01-14 20:11:39 +0000361 const char *EndPtr = ScanFormat(Argument, ArgumentEnd, '|');
John McCalle4d54322010-01-13 23:58:20 +0000362
363 // Recursively format the result of the select clause into the output string.
364 DInfo.FormatDiagnostic(Argument, EndPtr, OutStr);
Chris Lattner2b786902008-11-21 07:50:02 +0000365}
366
367/// HandleIntegerSModifier - Handle the integer 's' modifier. This adds the
368/// letter 's' to the string if the value is not 1. This is used in cases like
369/// this: "you idiot, you have %4 parameter%s4!".
370static void HandleIntegerSModifier(unsigned ValNo,
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000371 SmallVectorImpl<char> &OutStr) {
Chris Lattner2b786902008-11-21 07:50:02 +0000372 if (ValNo != 1)
373 OutStr.push_back('s');
374}
375
John McCall9015cde2010-01-14 00:50:32 +0000376/// HandleOrdinalModifier - Handle the integer 'ord' modifier. This
377/// prints the ordinal form of the given integer, with 1 corresponding
378/// to the first ordinal. Currently this is hard-coded to use the
379/// English form.
380static void HandleOrdinalModifier(unsigned ValNo,
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000381 SmallVectorImpl<char> &OutStr) {
John McCall9015cde2010-01-14 00:50:32 +0000382 assert(ValNo != 0 && "ValNo must be strictly positive!");
383
384 llvm::raw_svector_ostream Out(OutStr);
385
386 // We could use text forms for the first N ordinals, but the numeric
387 // forms are actually nicer in diagnostics because they stand out.
388 Out << ValNo;
389
390 // It is critically important that we do this perfectly for
391 // user-written sequences with over 100 elements.
392 switch (ValNo % 100) {
393 case 11:
394 case 12:
395 case 13:
396 Out << "th"; return;
397 default:
398 switch (ValNo % 10) {
399 case 1: Out << "st"; return;
400 case 2: Out << "nd"; return;
401 case 3: Out << "rd"; return;
402 default: Out << "th"; return;
403 }
404 }
405}
406
Chris Lattner2b786902008-11-21 07:50:02 +0000407
Sebastian Redl15b02d22008-11-22 13:44:36 +0000408/// PluralNumber - Parse an unsigned integer and advance Start.
Chris Lattner2fe29202009-04-15 17:13:42 +0000409static unsigned PluralNumber(const char *&Start, const char *End) {
Sebastian Redl15b02d22008-11-22 13:44:36 +0000410 // Programming 101: Parse a decimal number :-)
411 unsigned Val = 0;
412 while (Start != End && *Start >= '0' && *Start <= '9') {
413 Val *= 10;
414 Val += *Start - '0';
415 ++Start;
416 }
417 return Val;
418}
419
420/// TestPluralRange - Test if Val is in the parsed range. Modifies Start.
Chris Lattner2fe29202009-04-15 17:13:42 +0000421static bool TestPluralRange(unsigned Val, const char *&Start, const char *End) {
Sebastian Redl15b02d22008-11-22 13:44:36 +0000422 if (*Start != '[') {
423 unsigned Ref = PluralNumber(Start, End);
424 return Ref == Val;
425 }
426
427 ++Start;
428 unsigned Low = PluralNumber(Start, End);
429 assert(*Start == ',' && "Bad plural expression syntax: expected ,");
430 ++Start;
431 unsigned High = PluralNumber(Start, End);
432 assert(*Start == ']' && "Bad plural expression syntax: expected )");
433 ++Start;
434 return Low <= Val && Val <= High;
435}
436
437/// EvalPluralExpr - Actual expression evaluator for HandlePluralModifier.
Chris Lattner2fe29202009-04-15 17:13:42 +0000438static bool EvalPluralExpr(unsigned ValNo, const char *Start, const char *End) {
Sebastian Redl15b02d22008-11-22 13:44:36 +0000439 // Empty condition?
440 if (*Start == ':')
441 return true;
442
443 while (1) {
444 char C = *Start;
445 if (C == '%') {
446 // Modulo expression
447 ++Start;
448 unsigned Arg = PluralNumber(Start, End);
449 assert(*Start == '=' && "Bad plural expression syntax: expected =");
450 ++Start;
451 unsigned ValMod = ValNo % Arg;
452 if (TestPluralRange(ValMod, Start, End))
453 return true;
454 } else {
Sebastian Redl3ceaf622008-11-27 07:28:14 +0000455 assert((C == '[' || (C >= '0' && C <= '9')) &&
Sebastian Redl15b02d22008-11-22 13:44:36 +0000456 "Bad plural expression syntax: unexpected character");
457 // Range expression
458 if (TestPluralRange(ValNo, Start, End))
459 return true;
460 }
461
462 // Scan for next or-expr part.
463 Start = std::find(Start, End, ',');
Mike Stump11289f42009-09-09 15:08:12 +0000464 if (Start == End)
Sebastian Redl15b02d22008-11-22 13:44:36 +0000465 break;
466 ++Start;
467 }
468 return false;
469}
470
471/// HandlePluralModifier - Handle the integer 'plural' modifier. This is used
472/// for complex plural forms, or in languages where all plurals are complex.
473/// The syntax is: %plural{cond1:form1|cond2:form2|:form3}, where condn are
474/// conditions that are tested in order, the form corresponding to the first
475/// that applies being emitted. The empty condition is always true, making the
476/// last form a default case.
477/// Conditions are simple boolean expressions, where n is the number argument.
478/// Here are the rules.
479/// condition := expression | empty
480/// empty := -> always true
481/// expression := numeric [',' expression] -> logical or
482/// numeric := range -> true if n in range
483/// | '%' number '=' range -> true if n % number in range
484/// range := number
485/// | '[' number ',' number ']' -> ranges are inclusive both ends
486///
487/// Here are some examples from the GNU gettext manual written in this form:
488/// English:
489/// {1:form0|:form1}
490/// Latvian:
491/// {0:form2|%100=11,%10=0,%10=[2,9]:form1|:form0}
492/// Gaeilge:
493/// {1:form0|2:form1|:form2}
494/// Romanian:
495/// {1:form0|0,%100=[1,19]:form1|:form2}
496/// Lithuanian:
497/// {%10=0,%100=[10,19]:form2|%10=1:form0|:form1}
498/// Russian (requires repeated form):
499/// {%100=[11,14]:form2|%10=1:form0|%10=[2,4]:form1|:form2}
500/// Slovak
501/// {1:form0|[2,4]:form1|:form2}
502/// Polish (requires repeated form):
503/// {1:form0|%100=[10,20]:form2|%10=[2,4]:form1|:form2}
John McCall43b61682010-10-14 01:55:31 +0000504static void HandlePluralModifier(const DiagnosticInfo &DInfo, unsigned ValNo,
Sebastian Redl15b02d22008-11-22 13:44:36 +0000505 const char *Argument, unsigned ArgumentLen,
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000506 SmallVectorImpl<char> &OutStr) {
Sebastian Redl15b02d22008-11-22 13:44:36 +0000507 const char *ArgumentEnd = Argument + ArgumentLen;
508 while (1) {
509 assert(Argument < ArgumentEnd && "Plural expression didn't match.");
510 const char *ExprEnd = Argument;
511 while (*ExprEnd != ':') {
512 assert(ExprEnd != ArgumentEnd && "Plural missing expression end");
513 ++ExprEnd;
514 }
515 if (EvalPluralExpr(ValNo, Argument, ExprEnd)) {
516 Argument = ExprEnd + 1;
John McCall8cb7a8a32010-01-14 20:11:39 +0000517 ExprEnd = ScanFormat(Argument, ArgumentEnd, '|');
John McCall43b61682010-10-14 01:55:31 +0000518
519 // Recursively format the result of the plural clause into the
520 // output string.
521 DInfo.FormatDiagnostic(Argument, ExprEnd, OutStr);
Sebastian Redl15b02d22008-11-22 13:44:36 +0000522 return;
523 }
John McCall8cb7a8a32010-01-14 20:11:39 +0000524 Argument = ScanFormat(Argument, ArgumentEnd - 1, '|') + 1;
Sebastian Redl15b02d22008-11-22 13:44:36 +0000525 }
526}
527
528
Chris Lattner23be0672008-11-19 06:51:40 +0000529/// FormatDiagnostic - Format this diagnostic into a string, substituting the
530/// formal arguments into the %0 slots. The result is appended onto the Str
531/// array.
532void DiagnosticInfo::
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000533FormatDiagnostic(SmallVectorImpl<char> &OutStr) const {
Argyrios Kyrtzidise9af37d2011-05-05 07:54:59 +0000534 if (!StoredDiagMessage.empty()) {
535 OutStr.append(StoredDiagMessage.begin(), StoredDiagMessage.end());
536 return;
537 }
538
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000539 StringRef Diag =
Argyrios Kyrtzidis0e37afa2011-05-25 05:05:01 +0000540 getDiags()->getDiagnosticIDs()->getDescription(getID());
Mike Stump11289f42009-09-09 15:08:12 +0000541
Argyrios Kyrtzidis0e37afa2011-05-25 05:05:01 +0000542 FormatDiagnostic(Diag.begin(), Diag.end(), OutStr);
John McCalle4d54322010-01-13 23:58:20 +0000543}
544
545void DiagnosticInfo::
546FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000547 SmallVectorImpl<char> &OutStr) const {
John McCalle4d54322010-01-13 23:58:20 +0000548
Chris Lattnerc243f292009-10-20 05:25:22 +0000549 /// FormattedArgs - Keep track of all of the arguments formatted by
550 /// ConvertArgToString and pass them into subsequent calls to
551 /// ConvertArgToString, allowing the implementation to avoid redundancies in
552 /// obvious cases.
David Blaikie9c902b52011-09-25 23:23:43 +0000553 SmallVector<DiagnosticsEngine::ArgumentValue, 8> FormattedArgs;
Chandler Carruthd5173952011-07-11 17:49:21 +0000554
555 /// QualTypeVals - Pass a vector of arrays so that QualType names can be
556 /// compared to see if more information is needed to be printed.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000557 SmallVector<intptr_t, 2> QualTypeVals;
Chandler Carruthd5173952011-07-11 17:49:21 +0000558 for (unsigned i = 0, e = getNumArgs(); i < e; ++i)
David Blaikie9c902b52011-09-25 23:23:43 +0000559 if (getArgKind(i) == DiagnosticsEngine::ak_qualtype)
Chandler Carruthd5173952011-07-11 17:49:21 +0000560 QualTypeVals.push_back(getRawArg(i));
561
Chris Lattner23be0672008-11-19 06:51:40 +0000562 while (DiagStr != DiagEnd) {
563 if (DiagStr[0] != '%') {
564 // Append non-%0 substrings to Str if we have one.
565 const char *StrEnd = std::find(DiagStr, DiagEnd, '%');
566 OutStr.append(DiagStr, StrEnd);
567 DiagStr = StrEnd;
Chris Lattner2b786902008-11-21 07:50:02 +0000568 continue;
John McCall8cb7a8a32010-01-14 20:11:39 +0000569 } else if (ispunct(DiagStr[1])) {
570 OutStr.push_back(DiagStr[1]); // %% -> %.
Chris Lattner23be0672008-11-19 06:51:40 +0000571 DiagStr += 2;
Chris Lattner2b786902008-11-21 07:50:02 +0000572 continue;
573 }
Mike Stump11289f42009-09-09 15:08:12 +0000574
Chris Lattner2b786902008-11-21 07:50:02 +0000575 // Skip the %.
576 ++DiagStr;
Mike Stump11289f42009-09-09 15:08:12 +0000577
Chris Lattner2b786902008-11-21 07:50:02 +0000578 // This must be a placeholder for a diagnostic argument. The format for a
579 // placeholder is one of "%0", "%modifier0", or "%modifier{arguments}0".
580 // The digit is a number from 0-9 indicating which argument this comes from.
581 // The modifier is a string of digits from the set [-a-z]+, arguments is a
582 // brace enclosed string.
583 const char *Modifier = 0, *Argument = 0;
584 unsigned ModifierLen = 0, ArgumentLen = 0;
Mike Stump11289f42009-09-09 15:08:12 +0000585
Chris Lattner2b786902008-11-21 07:50:02 +0000586 // Check to see if we have a modifier. If so eat it.
587 if (!isdigit(DiagStr[0])) {
588 Modifier = DiagStr;
589 while (DiagStr[0] == '-' ||
590 (DiagStr[0] >= 'a' && DiagStr[0] <= 'z'))
591 ++DiagStr;
592 ModifierLen = DiagStr-Modifier;
Chris Lattner23be0672008-11-19 06:51:40 +0000593
Chris Lattner2b786902008-11-21 07:50:02 +0000594 // If we have an argument, get it next.
595 if (DiagStr[0] == '{') {
596 ++DiagStr; // Skip {.
597 Argument = DiagStr;
Mike Stump11289f42009-09-09 15:08:12 +0000598
John McCall8cb7a8a32010-01-14 20:11:39 +0000599 DiagStr = ScanFormat(DiagStr, DiagEnd, '}');
600 assert(DiagStr != DiagEnd && "Mismatched {}'s in diagnostic string!");
Chris Lattner2b786902008-11-21 07:50:02 +0000601 ArgumentLen = DiagStr-Argument;
602 ++DiagStr; // Skip }.
Chris Lattner23be0672008-11-19 06:51:40 +0000603 }
Chris Lattner2b786902008-11-21 07:50:02 +0000604 }
Mike Stump11289f42009-09-09 15:08:12 +0000605
Chris Lattner2b786902008-11-21 07:50:02 +0000606 assert(isdigit(*DiagStr) && "Invalid format for argument in diagnostic");
Chris Lattner6a2ed6f2008-11-23 09:13:29 +0000607 unsigned ArgNo = *DiagStr++ - '0';
Chris Lattner2b786902008-11-21 07:50:02 +0000608
David Blaikie9c902b52011-09-25 23:23:43 +0000609 DiagnosticsEngine::ArgumentKind Kind = getArgKind(ArgNo);
Chris Lattnerc243f292009-10-20 05:25:22 +0000610
611 switch (Kind) {
Chris Lattnere3d20d92008-11-23 21:45:46 +0000612 // ---- STRINGS ----
David Blaikie9c902b52011-09-25 23:23:43 +0000613 case DiagnosticsEngine::ak_std_string: {
Chris Lattner6a2ed6f2008-11-23 09:13:29 +0000614 const std::string &S = getArgStdStr(ArgNo);
Chris Lattner2b786902008-11-21 07:50:02 +0000615 assert(ModifierLen == 0 && "No modifiers for strings yet");
616 OutStr.append(S.begin(), S.end());
617 break;
618 }
David Blaikie9c902b52011-09-25 23:23:43 +0000619 case DiagnosticsEngine::ak_c_string: {
Chris Lattner6a2ed6f2008-11-23 09:13:29 +0000620 const char *S = getArgCStr(ArgNo);
Chris Lattner2b786902008-11-21 07:50:02 +0000621 assert(ModifierLen == 0 && "No modifiers for strings yet");
Daniel Dunbar69a79b12009-04-20 06:13:16 +0000622
623 // Don't crash if get passed a null pointer by accident.
624 if (!S)
625 S = "(null)";
Mike Stump11289f42009-09-09 15:08:12 +0000626
Chris Lattner2b786902008-11-21 07:50:02 +0000627 OutStr.append(S, S + strlen(S));
628 break;
629 }
Chris Lattnere3d20d92008-11-23 21:45:46 +0000630 // ---- INTEGERS ----
David Blaikie9c902b52011-09-25 23:23:43 +0000631 case DiagnosticsEngine::ak_sint: {
Chris Lattner6a2ed6f2008-11-23 09:13:29 +0000632 int Val = getArgSInt(ArgNo);
Mike Stump11289f42009-09-09 15:08:12 +0000633
Chris Lattner2b786902008-11-21 07:50:02 +0000634 if (ModifierIs(Modifier, ModifierLen, "select")) {
John McCall43b61682010-10-14 01:55:31 +0000635 HandleSelectModifier(*this, (unsigned)Val, Argument, ArgumentLen,
636 OutStr);
Chris Lattner2b786902008-11-21 07:50:02 +0000637 } else if (ModifierIs(Modifier, ModifierLen, "s")) {
638 HandleIntegerSModifier(Val, OutStr);
Sebastian Redl15b02d22008-11-22 13:44:36 +0000639 } else if (ModifierIs(Modifier, ModifierLen, "plural")) {
John McCall43b61682010-10-14 01:55:31 +0000640 HandlePluralModifier(*this, (unsigned)Val, Argument, ArgumentLen,
641 OutStr);
John McCall9015cde2010-01-14 00:50:32 +0000642 } else if (ModifierIs(Modifier, ModifierLen, "ordinal")) {
643 HandleOrdinalModifier((unsigned)Val, OutStr);
Chris Lattner2b786902008-11-21 07:50:02 +0000644 } else {
645 assert(ModifierLen == 0 && "Unknown integer modifier");
Daniel Dunbare3633792009-10-17 18:12:14 +0000646 llvm::raw_svector_ostream(OutStr) << Val;
Chris Lattner91aea712008-11-19 07:22:31 +0000647 }
Chris Lattner2b786902008-11-21 07:50:02 +0000648 break;
649 }
David Blaikie9c902b52011-09-25 23:23:43 +0000650 case DiagnosticsEngine::ak_uint: {
Chris Lattner6a2ed6f2008-11-23 09:13:29 +0000651 unsigned Val = getArgUInt(ArgNo);
Mike Stump11289f42009-09-09 15:08:12 +0000652
Chris Lattner2b786902008-11-21 07:50:02 +0000653 if (ModifierIs(Modifier, ModifierLen, "select")) {
John McCalle4d54322010-01-13 23:58:20 +0000654 HandleSelectModifier(*this, Val, Argument, ArgumentLen, OutStr);
Chris Lattner2b786902008-11-21 07:50:02 +0000655 } else if (ModifierIs(Modifier, ModifierLen, "s")) {
656 HandleIntegerSModifier(Val, OutStr);
Sebastian Redl15b02d22008-11-22 13:44:36 +0000657 } else if (ModifierIs(Modifier, ModifierLen, "plural")) {
John McCall43b61682010-10-14 01:55:31 +0000658 HandlePluralModifier(*this, (unsigned)Val, Argument, ArgumentLen,
659 OutStr);
John McCall9015cde2010-01-14 00:50:32 +0000660 } else if (ModifierIs(Modifier, ModifierLen, "ordinal")) {
661 HandleOrdinalModifier(Val, OutStr);
Chris Lattner2b786902008-11-21 07:50:02 +0000662 } else {
663 assert(ModifierLen == 0 && "Unknown integer modifier");
Daniel Dunbare3633792009-10-17 18:12:14 +0000664 llvm::raw_svector_ostream(OutStr) << Val;
Chris Lattner91aea712008-11-19 07:22:31 +0000665 }
Chris Lattner6a2ed6f2008-11-23 09:13:29 +0000666 break;
Chris Lattner2b786902008-11-21 07:50:02 +0000667 }
Chris Lattnere3d20d92008-11-23 21:45:46 +0000668 // ---- NAMES and TYPES ----
David Blaikie9c902b52011-09-25 23:23:43 +0000669 case DiagnosticsEngine::ak_identifierinfo: {
Chris Lattnere3d20d92008-11-23 21:45:46 +0000670 const IdentifierInfo *II = getArgIdentifier(ArgNo);
671 assert(ModifierLen == 0 && "No modifiers for strings yet");
Daniel Dunbar69a79b12009-04-20 06:13:16 +0000672
673 // Don't crash if get passed a null pointer by accident.
674 if (!II) {
675 const char *S = "(null)";
676 OutStr.append(S, S + strlen(S));
677 continue;
678 }
679
Daniel Dunbar07d07852009-10-18 21:17:35 +0000680 llvm::raw_svector_ostream(OutStr) << '\'' << II->getName() << '\'';
Chris Lattnere3d20d92008-11-23 21:45:46 +0000681 break;
682 }
David Blaikie9c902b52011-09-25 23:23:43 +0000683 case DiagnosticsEngine::ak_qualtype:
684 case DiagnosticsEngine::ak_declarationname:
685 case DiagnosticsEngine::ak_nameddecl:
686 case DiagnosticsEngine::ak_nestednamespec:
687 case DiagnosticsEngine::ak_declcontext:
Chris Lattnerc243f292009-10-20 05:25:22 +0000688 getDiags()->ConvertArgToString(Kind, getRawArg(ArgNo),
Chris Lattner63ecc502008-11-23 09:21:17 +0000689 Modifier, ModifierLen,
Chris Lattnerc243f292009-10-20 05:25:22 +0000690 Argument, ArgumentLen,
691 FormattedArgs.data(), FormattedArgs.size(),
Chandler Carruthd5173952011-07-11 17:49:21 +0000692 OutStr, QualTypeVals);
Chris Lattner6a2ed6f2008-11-23 09:13:29 +0000693 break;
Nico Weber4c311642008-08-10 19:59:06 +0000694 }
Chris Lattnerc243f292009-10-20 05:25:22 +0000695
696 // Remember this argument info for subsequent formatting operations. Turn
697 // std::strings into a null terminated string to make it be the same case as
698 // all the other ones.
David Blaikie9c902b52011-09-25 23:23:43 +0000699 if (Kind != DiagnosticsEngine::ak_std_string)
Chris Lattnerc243f292009-10-20 05:25:22 +0000700 FormattedArgs.push_back(std::make_pair(Kind, getRawArg(ArgNo)));
701 else
David Blaikie9c902b52011-09-25 23:23:43 +0000702 FormattedArgs.push_back(std::make_pair(DiagnosticsEngine::ak_c_string,
Chris Lattnerc243f292009-10-20 05:25:22 +0000703 (intptr_t)getArgStdStr(ArgNo).c_str()));
704
Nico Weber4c311642008-08-10 19:59:06 +0000705 }
Nico Weber4c311642008-08-10 19:59:06 +0000706}
Ted Kremenekea06ec12009-01-23 20:28:53 +0000707
Douglas Gregor33cdd812010-02-18 18:08:43 +0000708StoredDiagnostic::StoredDiagnostic() { }
709
David Blaikie9c902b52011-09-25 23:23:43 +0000710StoredDiagnostic::StoredDiagnostic(DiagnosticsEngine::Level Level, unsigned ID,
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000711 StringRef Message)
Benjamin Kramer929bd682010-11-19 17:36:51 +0000712 : ID(ID), Level(Level), Loc(), Message(Message) { }
Douglas Gregor33cdd812010-02-18 18:08:43 +0000713
David Blaikie9c902b52011-09-25 23:23:43 +0000714StoredDiagnostic::StoredDiagnostic(DiagnosticsEngine::Level Level,
Douglas Gregor33cdd812010-02-18 18:08:43 +0000715 const DiagnosticInfo &Info)
Douglas Gregora750e8e2010-11-19 16:18:16 +0000716 : ID(Info.getID()), Level(Level)
717{
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000718 assert((Info.getLocation().isInvalid() || Info.hasSourceManager()) &&
719 "Valid source location without setting a source manager for diagnostic");
720 if (Info.getLocation().isValid())
721 Loc = FullSourceLoc(Info.getLocation(), Info.getSourceManager());
Douglas Gregor33cdd812010-02-18 18:08:43 +0000722 llvm::SmallString<64> Message;
723 Info.FormatDiagnostic(Message);
724 this->Message.assign(Message.begin(), Message.end());
725
726 Ranges.reserve(Info.getNumRanges());
727 for (unsigned I = 0, N = Info.getNumRanges(); I != N; ++I)
728 Ranges.push_back(Info.getRange(I));
729
Douglas Gregora771f462010-03-31 17:46:05 +0000730 FixIts.reserve(Info.getNumFixItHints());
731 for (unsigned I = 0, N = Info.getNumFixItHints(); I != N; ++I)
732 FixIts.push_back(Info.getFixItHint(I));
Douglas Gregor33cdd812010-02-18 18:08:43 +0000733}
734
David Blaikie9c902b52011-09-25 23:23:43 +0000735StoredDiagnostic::StoredDiagnostic(DiagnosticsEngine::Level Level, unsigned ID,
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000736 StringRef Message, FullSourceLoc Loc,
Chris Lattner54b16772011-07-23 17:14:25 +0000737 ArrayRef<CharSourceRange> Ranges,
738 ArrayRef<FixItHint> Fixits)
Douglas Gregor925296b2011-07-19 16:10:42 +0000739 : ID(ID), Level(Level), Loc(Loc), Message(Message)
740{
741 this->Ranges.assign(Ranges.begin(), Ranges.end());
742 this->FixIts.assign(FixIts.begin(), FixIts.end());
743}
744
Douglas Gregor33cdd812010-02-18 18:08:43 +0000745StoredDiagnostic::~StoredDiagnostic() { }
746
Ted Kremenekea06ec12009-01-23 20:28:53 +0000747/// IncludeInDiagnosticCounts - This method (whose default implementation
748/// returns true) indicates whether the diagnostics handled by this
David Blaikiee2eefae2011-09-25 23:39:51 +0000749/// DiagnosticConsumer should be included in the number of diagnostics
David Blaikie9c902b52011-09-25 23:23:43 +0000750/// reported by DiagnosticsEngine.
David Blaikiee2eefae2011-09-25 23:39:51 +0000751bool DiagnosticConsumer::IncludeInDiagnosticCounts() const { return true; }
Douglas Gregor89336232010-03-29 23:34:08 +0000752
753PartialDiagnostic::StorageAllocator::StorageAllocator() {
754 for (unsigned I = 0; I != NumCached; ++I)
755 FreeList[I] = Cached + I;
756 NumFreeListEntries = NumCached;
757}
758
759PartialDiagnostic::StorageAllocator::~StorageAllocator() {
Ted Kremenek84de4a12011-03-21 18:40:07 +0000760 // Don't assert if we are in a CrashRecovery context, as this
761 // invariant may be invalidated during a crash.
Ted Kremenek0aaa67b2011-03-21 18:40:10 +0000762 assert((NumFreeListEntries == NumCached || llvm::CrashRecoveryContext::isRecoveringFromCrash()) && "A partial is on the lamb");
Douglas Gregor89336232010-03-29 23:34:08 +0000763}