blob: d8a0afc1cc57e3a40e4c7e1fe430cd82a1299639 [file] [log] [blame]
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +00001//===--- DiagnosticIDs.cpp - Diagnostic IDs Handling ----------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Diagnostic IDs-related interfaces.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/ASTDiagnostic.h"
15#include "clang/Analysis/AnalysisDiagnostic.h"
16#include "clang/Basic/DiagnosticIDs.h"
John McCall923cd572011-06-15 21:46:43 +000017#include "clang/Basic/DiagnosticCategories.h"
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +000018#include "clang/Basic/SourceManager.h"
19#include "clang/Driver/DriverDiagnostic.h"
20#include "clang/Frontend/FrontendDiagnostic.h"
21#include "clang/Lex/LexDiagnostic.h"
22#include "clang/Parse/ParseDiagnostic.h"
23#include "clang/Sema/SemaDiagnostic.h"
David Blaikie9fe8c742011-09-23 05:35:21 +000024#include "llvm/Support/ErrorHandling.h"
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +000025
26#include <map>
27using namespace clang;
28
29//===----------------------------------------------------------------------===//
30// Builtin Diagnostic information
31//===----------------------------------------------------------------------===//
32
33namespace {
34
35// Diagnostic classes.
36enum {
37 CLASS_NOTE = 0x01,
38 CLASS_WARNING = 0x02,
39 CLASS_EXTENSION = 0x03,
40 CLASS_ERROR = 0x04
41};
42
43struct StaticDiagInfoRec {
44 unsigned short DiagID;
45 unsigned Mapping : 3;
46 unsigned Class : 3;
Douglas Gregor418df342011-01-27 21:06:28 +000047 unsigned SFINAE : 1;
48 unsigned AccessControl : 1;
Daniel Dunbar4213df32011-09-29 00:34:06 +000049 unsigned WarnNoWerror : 1;
50 unsigned WarnShowInSystemHeader : 1;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +000051 unsigned Category : 5;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +000052
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000053 uint8_t NameLen;
54 uint8_t OptionGroupLen;
55
56 uint16_t DescriptionLen;
57 uint16_t BriefExplanationLen;
58 uint16_t FullExplanationLen;
59
60 const char *NameStr;
61 const char *OptionGroupStr;
62
63 const char *DescriptionStr;
64 const char *BriefExplanationStr;
65 const char *FullExplanationStr;
66
Chris Lattner5f9e2722011-07-23 10:55:15 +000067 StringRef getName() const {
68 return StringRef(NameStr, NameLen);
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000069 }
Chris Lattner5f9e2722011-07-23 10:55:15 +000070 StringRef getOptionGroup() const {
71 return StringRef(OptionGroupStr, OptionGroupLen);
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000072 }
73
Chris Lattner5f9e2722011-07-23 10:55:15 +000074 StringRef getDescription() const {
75 return StringRef(DescriptionStr, DescriptionLen);
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000076 }
Chris Lattner5f9e2722011-07-23 10:55:15 +000077 StringRef getBriefExplanation() const {
78 return StringRef(BriefExplanationStr, BriefExplanationLen);
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000079 }
Chris Lattner5f9e2722011-07-23 10:55:15 +000080 StringRef getFullExplanation() const {
81 return StringRef(FullExplanationStr, FullExplanationLen);
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000082 }
Douglas Gregor7d2b8c12011-04-15 22:04:17 +000083
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +000084 bool operator<(const StaticDiagInfoRec &RHS) const {
85 return DiagID < RHS.DiagID;
86 }
87};
88
Douglas Gregor7d2b8c12011-04-15 22:04:17 +000089struct StaticDiagNameIndexRec {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000090 const char *NameStr;
Douglas Gregor7d2b8c12011-04-15 22:04:17 +000091 unsigned short DiagID;
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000092 uint8_t NameLen;
93
Chris Lattner5f9e2722011-07-23 10:55:15 +000094 StringRef getName() const {
95 return StringRef(NameStr, NameLen);
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000096 }
97
Douglas Gregor7d2b8c12011-04-15 22:04:17 +000098 bool operator<(const StaticDiagNameIndexRec &RHS) const {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000099 return getName() < RHS.getName();
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000100 }
101
102 bool operator==(const StaticDiagNameIndexRec &RHS) const {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000103 return getName() == RHS.getName();
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000104 }
105};
106
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000107template <size_t SizeOfStr, typename FieldType>
108class StringSizerHelper {
109 char FIELD_TOO_SMALL[SizeOfStr <= FieldType(~0U) ? 1 : -1];
110public:
111 enum { Size = SizeOfStr };
112};
113
114} // namespace anonymous
115
116#define STR_SIZE(str, fieldTy) StringSizerHelper<sizeof(str)-1, fieldTy>::Size
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000117
118static const StaticDiagInfoRec StaticDiagInfo[] = {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000119#define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP, \
Daniel Dunbar4213df32011-09-29 00:34:06 +0000120 SFINAE,ACCESS,NOWERROR,SHOWINSYSHEADER, \
121 CATEGORY,BRIEF,FULL) \
122 { diag::ENUM, DEFAULT_MAPPING, CLASS, SFINAE, ACCESS, \
123 NOWERROR, SHOWINSYSHEADER, CATEGORY, \
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000124 STR_SIZE(#ENUM, uint8_t), STR_SIZE(GROUP, uint8_t), \
125 STR_SIZE(DESC, uint16_t), STR_SIZE(BRIEF, uint16_t), \
126 STR_SIZE(FULL, uint16_t), \
127 #ENUM, GROUP, DESC, BRIEF, FULL },
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000128#include "clang/Basic/DiagnosticCommonKinds.inc"
129#include "clang/Basic/DiagnosticDriverKinds.inc"
130#include "clang/Basic/DiagnosticFrontendKinds.inc"
131#include "clang/Basic/DiagnosticLexKinds.inc"
132#include "clang/Basic/DiagnosticParseKinds.inc"
133#include "clang/Basic/DiagnosticASTKinds.inc"
134#include "clang/Basic/DiagnosticSemaKinds.inc"
135#include "clang/Basic/DiagnosticAnalysisKinds.inc"
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000136#undef DIAG
Daniel Dunbar4213df32011-09-29 00:34:06 +0000137 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000138};
139
140static const unsigned StaticDiagInfoSize =
141 sizeof(StaticDiagInfo)/sizeof(StaticDiagInfo[0])-1;
142
143/// To be sorted before first use (since it's splitted among multiple files)
Benjamin Kramer81f9d142011-06-14 13:15:38 +0000144static const StaticDiagNameIndexRec StaticDiagNameIndex[] = {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000145#define DIAG_NAME_INDEX(ENUM) { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) },
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000146#include "clang/Basic/DiagnosticIndexName.inc"
147#undef DIAG_NAME_INDEX
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000148 { 0, 0, 0 }
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000149};
150
151static const unsigned StaticDiagNameIndexSize =
152 sizeof(StaticDiagNameIndex)/sizeof(StaticDiagNameIndex[0])-1;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000153
154/// GetDiagInfo - Return the StaticDiagInfoRec entry for the specified DiagID,
155/// or null if the ID is invalid.
156static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000157 // If assertions are enabled, verify that the StaticDiagInfo array is sorted.
158#ifndef NDEBUG
159 static bool IsFirst = true;
160 if (IsFirst) {
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000161 for (unsigned i = 1; i != StaticDiagInfoSize; ++i) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000162 assert(StaticDiagInfo[i-1].DiagID != StaticDiagInfo[i].DiagID &&
163 "Diag ID conflict, the enums at the start of clang::diag (in "
Fariborz Jahanianf84109e2011-01-07 18:59:25 +0000164 "DiagnosticIDs.h) probably need to be increased");
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000165
166 assert(StaticDiagInfo[i-1] < StaticDiagInfo[i] &&
167 "Improperly sorted diag info");
168 }
169 IsFirst = false;
170 }
171#endif
172
173 // Search the diagnostic table with a binary search.
Jeffrey Yasskin7c5109b2011-08-13 05:47:04 +0000174 StaticDiagInfoRec Find = { static_cast<unsigned short>(DiagID),
Daniel Dunbar4213df32011-09-29 00:34:06 +0000175 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000176
177 const StaticDiagInfoRec *Found =
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000178 std::lower_bound(StaticDiagInfo, StaticDiagInfo + StaticDiagInfoSize, Find);
179 if (Found == StaticDiagInfo + StaticDiagInfoSize ||
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000180 Found->DiagID != DiagID)
181 return 0;
182
183 return Found;
184}
185
186static unsigned GetDefaultDiagMapping(unsigned DiagID) {
Daniel Dunbar4213df32011-09-29 00:34:06 +0000187 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) {
188 // Compute the effective mapping based on the extra bits.
189 unsigned Mapping = Info->Mapping;
190
191 if (Info->WarnNoWerror) {
192 assert(Mapping == diag::MAP_WARNING &&
193 "Unexpected mapping with no-Werror bit!");
194 Mapping = diag::MAP_WARNING_NO_WERROR;
195 }
196
197 if (Info->WarnShowInSystemHeader) {
198 assert(Mapping == diag::MAP_WARNING &&
199 "Unexpected mapping with show-in-system-header bit!");
200 Mapping = diag::MAP_WARNING_SHOW_IN_SYSTEM_HEADER;
201 }
202
203 return Mapping;
204 }
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000205 return diag::MAP_FATAL;
206}
207
208/// getWarningOptionForDiag - Return the lowest-level warning option that
209/// enables the specified diagnostic. If there is no -Wfoo flag that controls
210/// the diagnostic, this returns null.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000211StringRef DiagnosticIDs::getWarningOptionForDiag(unsigned DiagID) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000212 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000213 return Info->getOptionGroup();
Chris Lattner5f9e2722011-07-23 10:55:15 +0000214 return StringRef();
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000215}
216
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000217/// getCategoryNumberForDiag - Return the category number that a specified
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000218/// DiagID belongs to, or 0 if no category.
219unsigned DiagnosticIDs::getCategoryNumberForDiag(unsigned DiagID) {
220 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
221 return Info->Category;
222 return 0;
223}
224
Benjamin Kramerdbda5132011-06-13 18:38:45 +0000225namespace {
226 // The diagnostic category names.
227 struct StaticDiagCategoryRec {
228 const char *NameStr;
229 uint8_t NameLen;
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000230
Chris Lattner5f9e2722011-07-23 10:55:15 +0000231 StringRef getName() const {
232 return StringRef(NameStr, NameLen);
Benjamin Kramerdbda5132011-06-13 18:38:45 +0000233 }
234 };
235}
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000236
Benjamin Kramerdbda5132011-06-13 18:38:45 +0000237static const StaticDiagCategoryRec CategoryNameTable[] = {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000238#define GET_CATEGORY_TABLE
John McCall923cd572011-06-15 21:46:43 +0000239#define CATEGORY(X, ENUM) { X, STR_SIZE(X, uint8_t) },
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000240#include "clang/Basic/DiagnosticGroups.inc"
241#undef GET_CATEGORY_TABLE
242 { 0, 0 }
243};
244
245/// getNumberOfCategories - Return the number of categories
246unsigned DiagnosticIDs::getNumberOfCategories() {
247 return sizeof(CategoryNameTable) / sizeof(CategoryNameTable[0])-1;
248}
249
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000250/// getCategoryNameFromID - Given a category ID, return the name of the
251/// category, an empty string if CategoryID is zero, or null if CategoryID is
252/// invalid.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000253StringRef DiagnosticIDs::getCategoryNameFromID(unsigned CategoryID) {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000254 if (CategoryID >= getNumberOfCategories())
Chris Lattner5f9e2722011-07-23 10:55:15 +0000255 return StringRef();
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000256 return CategoryNameTable[CategoryID].getName();
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000257}
258
259
260
261DiagnosticIDs::SFINAEResponse
262DiagnosticIDs::getDiagnosticSFINAEResponse(unsigned DiagID) {
263 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) {
Douglas Gregor418df342011-01-27 21:06:28 +0000264 if (Info->AccessControl)
265 return SFINAE_AccessControl;
266
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000267 if (!Info->SFINAE)
268 return SFINAE_Report;
269
270 if (Info->Class == CLASS_ERROR)
271 return SFINAE_SubstitutionFailure;
272
273 // Suppress notes, warnings, and extensions;
274 return SFINAE_Suppress;
275 }
276
277 return SFINAE_Report;
278}
279
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000280/// getName - Given a diagnostic ID, return its name
Chris Lattner5f9e2722011-07-23 10:55:15 +0000281StringRef DiagnosticIDs::getName(unsigned DiagID) {
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000282 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000283 return Info->getName();
Chris Lattner5f9e2722011-07-23 10:55:15 +0000284 return StringRef();
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000285}
286
287/// getIdFromName - Given a diagnostic name, return its ID, or 0
Chris Lattner5f9e2722011-07-23 10:55:15 +0000288unsigned DiagnosticIDs::getIdFromName(StringRef Name) {
Benjamin Kramer81f9d142011-06-14 13:15:38 +0000289 const StaticDiagNameIndexRec *StaticDiagNameIndexEnd =
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000290 StaticDiagNameIndex + StaticDiagNameIndexSize;
291
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000292 if (Name.empty()) { return diag::DIAG_UPPER_LIMIT; }
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000293
Jeffrey Yasskin7c5109b2011-08-13 05:47:04 +0000294 assert(Name.size() == static_cast<uint8_t>(Name.size()) &&
295 "Name is too long");
296 StaticDiagNameIndexRec Find = { Name.data(), 0,
297 static_cast<uint8_t>(Name.size()) };
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000298
299 const StaticDiagNameIndexRec *Found =
300 std::lower_bound( StaticDiagNameIndex, StaticDiagNameIndexEnd, Find);
301 if (Found == StaticDiagNameIndexEnd ||
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000302 Found->getName() != Name)
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000303 return diag::DIAG_UPPER_LIMIT;
304
305 return Found->DiagID;
306}
307
308/// getBriefExplanation - Given a diagnostic ID, return a brief explanation
309/// of the issue
Chris Lattner5f9e2722011-07-23 10:55:15 +0000310StringRef DiagnosticIDs::getBriefExplanation(unsigned DiagID) {
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000311 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000312 return Info->getBriefExplanation();
Chris Lattner5f9e2722011-07-23 10:55:15 +0000313 return StringRef();
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000314}
315
316/// getFullExplanation - Given a diagnostic ID, return a full explanation
317/// of the issue
Chris Lattner5f9e2722011-07-23 10:55:15 +0000318StringRef DiagnosticIDs::getFullExplanation(unsigned DiagID) {
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000319 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000320 return Info->getFullExplanation();
Chris Lattner5f9e2722011-07-23 10:55:15 +0000321 return StringRef();
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000322}
323
324/// getBuiltinDiagClass - Return the class field of the diagnostic.
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000325///
326static unsigned getBuiltinDiagClass(unsigned DiagID) {
327 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
328 return Info->Class;
329 return ~0U;
330}
331
332//===----------------------------------------------------------------------===//
Ted Kremenek6948bc42011-08-09 03:39:14 +0000333// diag_iterator
334//===----------------------------------------------------------------------===//
335
336llvm::StringRef DiagnosticIDs::diag_iterator::getDiagName() const {
337 return static_cast<const StaticDiagNameIndexRec*>(impl)->getName();
338}
339
340unsigned DiagnosticIDs::diag_iterator::getDiagID() const {
341 return static_cast<const StaticDiagNameIndexRec*>(impl)->DiagID;
342}
343
344DiagnosticIDs::diag_iterator &DiagnosticIDs::diag_iterator::operator++() {
345 const StaticDiagNameIndexRec* ptr =
346 static_cast<const StaticDiagNameIndexRec*>(impl);;
347 ++ptr;
348 impl = ptr;
349 return *this;
350}
351
352DiagnosticIDs::diag_iterator DiagnosticIDs::diags_begin() {
353 return DiagnosticIDs::diag_iterator(StaticDiagNameIndex);
354}
355
356DiagnosticIDs::diag_iterator DiagnosticIDs::diags_end() {
357 return DiagnosticIDs::diag_iterator(StaticDiagNameIndex +
358 StaticDiagNameIndexSize);
359}
360
361//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000362// Custom Diagnostic information
363//===----------------------------------------------------------------------===//
364
365namespace clang {
366 namespace diag {
367 class CustomDiagInfo {
368 typedef std::pair<DiagnosticIDs::Level, std::string> DiagDesc;
369 std::vector<DiagDesc> DiagInfo;
370 std::map<DiagDesc, unsigned> DiagIDs;
371 public:
372
373 /// getDescription - Return the description of the specified custom
374 /// diagnostic.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000375 StringRef getDescription(unsigned DiagID) const {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000376 assert(this && DiagID-DIAG_UPPER_LIMIT < DiagInfo.size() &&
377 "Invalid diagnosic ID");
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000378 return DiagInfo[DiagID-DIAG_UPPER_LIMIT].second;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000379 }
380
381 /// getLevel - Return the level of the specified custom diagnostic.
382 DiagnosticIDs::Level getLevel(unsigned DiagID) const {
383 assert(this && DiagID-DIAG_UPPER_LIMIT < DiagInfo.size() &&
384 "Invalid diagnosic ID");
385 return DiagInfo[DiagID-DIAG_UPPER_LIMIT].first;
386 }
387
Chris Lattner5f9e2722011-07-23 10:55:15 +0000388 unsigned getOrCreateDiagID(DiagnosticIDs::Level L, StringRef Message,
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000389 DiagnosticIDs &Diags) {
390 DiagDesc D(L, Message);
391 // Check to see if it already exists.
392 std::map<DiagDesc, unsigned>::iterator I = DiagIDs.lower_bound(D);
393 if (I != DiagIDs.end() && I->first == D)
394 return I->second;
395
396 // If not, assign a new ID.
397 unsigned ID = DiagInfo.size()+DIAG_UPPER_LIMIT;
398 DiagIDs.insert(std::make_pair(D, ID));
399 DiagInfo.push_back(D);
400 return ID;
401 }
402 };
403
404 } // end diag namespace
405} // end clang namespace
406
407
408//===----------------------------------------------------------------------===//
409// Common Diagnostic implementation
410//===----------------------------------------------------------------------===//
411
412DiagnosticIDs::DiagnosticIDs() {
413 CustomDiagInfo = 0;
414}
415
416DiagnosticIDs::~DiagnosticIDs() {
417 delete CustomDiagInfo;
418}
419
420/// getCustomDiagID - Return an ID for a diagnostic with the specified message
421/// and level. If this is the first request for this diagnosic, it is
422/// registered and created, otherwise the existing ID is returned.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000423unsigned DiagnosticIDs::getCustomDiagID(Level L, StringRef Message) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000424 if (CustomDiagInfo == 0)
425 CustomDiagInfo = new diag::CustomDiagInfo();
426 return CustomDiagInfo->getOrCreateDiagID(L, Message, *this);
427}
428
429
430/// isBuiltinWarningOrExtension - Return true if the unmapped diagnostic
431/// level of the specified diagnostic ID is a Warning or Extension.
432/// This only works on builtin diagnostics, not custom ones, and is not legal to
433/// call on NOTEs.
434bool DiagnosticIDs::isBuiltinWarningOrExtension(unsigned DiagID) {
435 return DiagID < diag::DIAG_UPPER_LIMIT &&
436 getBuiltinDiagClass(DiagID) != CLASS_ERROR;
437}
438
439/// \brief Determine whether the given built-in diagnostic ID is a
440/// Note.
441bool DiagnosticIDs::isBuiltinNote(unsigned DiagID) {
442 return DiagID < diag::DIAG_UPPER_LIMIT &&
443 getBuiltinDiagClass(DiagID) == CLASS_NOTE;
444}
445
446/// isBuiltinExtensionDiag - Determine whether the given built-in diagnostic
447/// ID is for an extension of some sort. This also returns EnabledByDefault,
448/// which is set to indicate whether the diagnostic is ignored by default (in
449/// which case -pedantic enables it) or treated as a warning/error by default.
450///
451bool DiagnosticIDs::isBuiltinExtensionDiag(unsigned DiagID,
452 bool &EnabledByDefault) {
453 if (DiagID >= diag::DIAG_UPPER_LIMIT ||
454 getBuiltinDiagClass(DiagID) != CLASS_EXTENSION)
455 return false;
456
457 EnabledByDefault = GetDefaultDiagMapping(DiagID) != diag::MAP_IGNORE;
458 return true;
459}
460
Daniel Dunbar76101cf2011-09-29 01:01:08 +0000461bool DiagnosticIDs::isDefaultMappingAsError(unsigned DiagID) {
462 if (DiagID >= diag::DIAG_UPPER_LIMIT)
463 return false;
464
465 return GetDefaultDiagMapping(DiagID) == diag::MAP_ERROR;
466}
467
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000468/// getDescription - Given a diagnostic ID, return a description of the
469/// issue.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000470StringRef DiagnosticIDs::getDescription(unsigned DiagID) const {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000471 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000472 return Info->getDescription();
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000473 return CustomDiagInfo->getDescription(DiagID);
474}
475
David Blaikied6471f72011-09-25 23:23:43 +0000476/// getDiagnosticLevel - Based on the way the client configured the
477/// DiagnosticsEngine object, classify the specified diagnostic ID into a Level,
478/// by consumable the DiagnosticClient.
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000479DiagnosticIDs::Level
480DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, SourceLocation Loc,
Daniel Dunbar1656aae2011-09-29 01:20:28 +0000481 const DiagnosticsEngine &Diag) const {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000482 // Handle custom diagnostics, which cannot be mapped.
483 if (DiagID >= diag::DIAG_UPPER_LIMIT)
484 return CustomDiagInfo->getLevel(DiagID);
485
486 unsigned DiagClass = getBuiltinDiagClass(DiagID);
487 assert(DiagClass != CLASS_NOTE && "Cannot get diagnostic level of a note!");
Daniel Dunbar1656aae2011-09-29 01:20:28 +0000488 return getDiagnosticLevel(DiagID, DiagClass, Loc, Diag);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000489}
490
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000491/// \brief Based on the way the client configured the Diagnostic
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000492/// object, classify the specified diagnostic ID into a Level, consumable by
493/// the DiagnosticClient.
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000494///
495/// \param Loc The source location we are interested in finding out the
496/// diagnostic state. Can be null in order to query the latest state.
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000497DiagnosticIDs::Level
498DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass,
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000499 SourceLocation Loc,
Daniel Dunbar1656aae2011-09-29 01:20:28 +0000500 const DiagnosticsEngine &Diag) const {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000501 // Specific non-error diagnostics may be mapped to various levels from ignored
502 // to error. Errors can only be mapped to fatal.
503 DiagnosticIDs::Level Result = DiagnosticIDs::Fatal;
504
David Blaikied6471f72011-09-25 23:23:43 +0000505 DiagnosticsEngine::DiagStatePointsTy::iterator
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000506 Pos = Diag.GetDiagStatePointForLoc(Loc);
David Blaikied6471f72011-09-25 23:23:43 +0000507 DiagnosticsEngine::DiagState *State = Pos->State;
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000508
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000509 // Get the mapping information, if unset, compute it lazily.
Daniel Dunbarc3c4a892011-09-29 01:25:14 +0000510 unsigned MappingInfo = State->getMapping((diag::kind) DiagID);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000511 if (MappingInfo == 0) {
512 MappingInfo = GetDefaultDiagMapping(DiagID);
Argyrios Kyrtzidis3efd52c2011-01-14 20:54:07 +0000513 Diag.setDiagnosticMappingInternal(DiagID, MappingInfo, State, false, false);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000514 }
515
Argyrios Kyrtzidis144bc082011-04-21 23:08:23 +0000516 bool ShouldEmitInSystemHeader = false;
517
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000518 switch (MappingInfo & 7) {
David Blaikieb219cfc2011-09-23 05:06:16 +0000519 default: llvm_unreachable("Unknown mapping!");
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000520 case diag::MAP_IGNORE:
Ted Kremenek1e473cc2011-08-18 01:12:56 +0000521 if (Diag.EnableAllWarnings) {
522 // Leave the warning disabled if it was explicitly ignored.
523 if ((MappingInfo & 8) != 0)
524 return DiagnosticIDs::Ignored;
525
526 Result = Diag.WarningsAsErrors ? DiagnosticIDs::Error
527 : DiagnosticIDs::Warning;
528 }
529 // Otherwise, ignore this diagnostic unless this is an extension diagnostic
530 // and we're mapping them onto warnings or errors.
531 else if (!isBuiltinExtensionDiag(DiagID) || // Not an extension
David Blaikied6471f72011-09-25 23:23:43 +0000532 Diag.ExtBehavior == DiagnosticsEngine::Ext_Ignore || // Ext ignored
Ted Kremenek1e473cc2011-08-18 01:12:56 +0000533 (MappingInfo & 8) != 0) { // User explicitly mapped it.
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000534 return DiagnosticIDs::Ignored;
Ted Kremenek1e473cc2011-08-18 01:12:56 +0000535 }
536 else {
537 Result = DiagnosticIDs::Warning;
538 }
539
David Blaikied6471f72011-09-25 23:23:43 +0000540 if (Diag.ExtBehavior == DiagnosticsEngine::Ext_Error)
Ted Kremenek1e473cc2011-08-18 01:12:56 +0000541 Result = DiagnosticIDs::Error;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000542 if (Result == DiagnosticIDs::Error && Diag.ErrorsAsFatal)
543 Result = DiagnosticIDs::Fatal;
544 break;
545 case diag::MAP_ERROR:
546 Result = DiagnosticIDs::Error;
547 if (Diag.ErrorsAsFatal)
548 Result = DiagnosticIDs::Fatal;
549 break;
550 case diag::MAP_FATAL:
551 Result = DiagnosticIDs::Fatal;
552 break;
Argyrios Kyrtzidis144bc082011-04-21 23:08:23 +0000553 case diag::MAP_WARNING_SHOW_IN_SYSTEM_HEADER:
554 ShouldEmitInSystemHeader = true;
555 // continue as MAP_WARNING.
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000556 case diag::MAP_WARNING:
557 // If warnings are globally mapped to ignore or error, do it.
558 if (Diag.IgnoreAllWarnings)
559 return DiagnosticIDs::Ignored;
560
561 Result = DiagnosticIDs::Warning;
562
563 // If this is an extension diagnostic and we're in -pedantic-error mode, and
564 // if the user didn't explicitly map it, upgrade to an error.
David Blaikied6471f72011-09-25 23:23:43 +0000565 if (Diag.ExtBehavior == DiagnosticsEngine::Ext_Error &&
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000566 (MappingInfo & 8) == 0 &&
567 isBuiltinExtensionDiag(DiagID))
568 Result = DiagnosticIDs::Error;
569
570 if (Diag.WarningsAsErrors)
571 Result = DiagnosticIDs::Error;
572 if (Result == DiagnosticIDs::Error && Diag.ErrorsAsFatal)
573 Result = DiagnosticIDs::Fatal;
574 break;
575
576 case diag::MAP_WARNING_NO_WERROR:
577 // Diagnostics specified with -Wno-error=foo should be set to warnings, but
578 // not be adjusted by -Werror or -pedantic-errors.
579 Result = DiagnosticIDs::Warning;
580
581 // If warnings are globally mapped to ignore or error, do it.
582 if (Diag.IgnoreAllWarnings)
583 return DiagnosticIDs::Ignored;
584
585 break;
586
587 case diag::MAP_ERROR_NO_WFATAL:
588 // Diagnostics specified as -Wno-fatal-error=foo should be errors, but
589 // unaffected by -Wfatal-errors.
590 Result = DiagnosticIDs::Error;
591 break;
592 }
593
594 // Okay, we're about to return this as a "diagnostic to emit" one last check:
595 // if this is any sort of extension warning, and if we're in an __extension__
596 // block, silence it.
597 if (Diag.AllExtensionsSilenced && isBuiltinExtensionDiag(DiagID))
598 return DiagnosticIDs::Ignored;
599
Argyrios Kyrtzidiscfdadfe2011-04-21 23:08:18 +0000600 // If we are in a system header, we ignore it.
601 // We also want to ignore extensions and warnings in -Werror and
602 // -pedantic-errors modes, which *map* warnings/extensions to errors.
603 if (Result >= DiagnosticIDs::Warning &&
604 DiagClass != CLASS_ERROR &&
605 // Custom diagnostics always are emitted in system headers.
606 DiagID < diag::DIAG_UPPER_LIMIT &&
Argyrios Kyrtzidis144bc082011-04-21 23:08:23 +0000607 !ShouldEmitInSystemHeader &&
Argyrios Kyrtzidiscfdadfe2011-04-21 23:08:18 +0000608 Diag.SuppressSystemWarnings &&
609 Loc.isValid() &&
610 Diag.getSourceManager().isInSystemHeader(
Chandler Carruth40278532011-07-25 16:49:02 +0000611 Diag.getSourceManager().getExpansionLoc(Loc)))
Argyrios Kyrtzidiscfdadfe2011-04-21 23:08:18 +0000612 return DiagnosticIDs::Ignored;
613
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000614 return Result;
615}
616
Benjamin Kramerdbda5132011-06-13 18:38:45 +0000617namespace {
618 struct WarningOption {
619 // Be safe with the size of 'NameLen' because we don't statically check if
620 // the size will fit in the field; the struct size won't decrease with a
621 // shorter type anyway.
622 size_t NameLen;
623 const char *NameStr;
624 const short *Members;
625 const short *SubGroups;
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000626
Chris Lattner5f9e2722011-07-23 10:55:15 +0000627 StringRef getName() const {
628 return StringRef(NameStr, NameLen);
Benjamin Kramerdbda5132011-06-13 18:38:45 +0000629 }
630 };
631}
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000632
633#define GET_DIAG_ARRAYS
634#include "clang/Basic/DiagnosticGroups.inc"
635#undef GET_DIAG_ARRAYS
636
637// Second the table of options, sorted by name for fast binary lookup.
638static const WarningOption OptionTable[] = {
639#define GET_DIAG_TABLE
640#include "clang/Basic/DiagnosticGroups.inc"
641#undef GET_DIAG_TABLE
642};
643static const size_t OptionTableSize =
644sizeof(OptionTable) / sizeof(OptionTable[0]);
645
646static bool WarningOptionCompare(const WarningOption &LHS,
647 const WarningOption &RHS) {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000648 return LHS.getName() < RHS.getName();
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000649}
650
651static void MapGroupMembers(const WarningOption *Group, diag::Mapping Mapping,
David Blaikied6471f72011-09-25 23:23:43 +0000652 SourceLocation Loc, DiagnosticsEngine &Diag) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000653 // Option exists, poke all the members of its diagnostic set.
654 if (const short *Member = Group->Members) {
655 for (; *Member != -1; ++Member)
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000656 Diag.setDiagnosticMapping(*Member, Mapping, Loc);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000657 }
658
659 // Enable/disable all subgroups along with this one.
660 if (const short *SubGroups = Group->SubGroups) {
661 for (; *SubGroups != (short)-1; ++SubGroups)
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000662 MapGroupMembers(&OptionTable[(short)*SubGroups], Mapping, Loc, Diag);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000663 }
664}
665
666/// setDiagnosticGroupMapping - Change an entire diagnostic group (e.g.
667/// "unknown-pragmas" to have the specified mapping. This returns true and
668/// ignores the request if "Group" was unknown, false otherwise.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000669bool DiagnosticIDs::setDiagnosticGroupMapping(StringRef Group,
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000670 diag::Mapping Map,
671 SourceLocation Loc,
David Blaikied6471f72011-09-25 23:23:43 +0000672 DiagnosticsEngine &Diag) const {
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000673 assert((Loc.isValid() ||
674 Diag.DiagStatePoints.empty() ||
675 Diag.DiagStatePoints.back().Loc.isInvalid()) &&
676 "Loc should be invalid only when the mapping comes from command-line");
677 assert((Loc.isInvalid() || Diag.DiagStatePoints.empty() ||
678 Diag.DiagStatePoints.back().Loc.isInvalid() ||
679 !Diag.SourceMgr->isBeforeInTranslationUnit(Loc,
680 Diag.DiagStatePoints.back().Loc)) &&
681 "Source location of new mapping is before the previous one!");
682
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000683 WarningOption Key = { Group.size(), Group.data(), 0, 0 };
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000684 const WarningOption *Found =
685 std::lower_bound(OptionTable, OptionTable + OptionTableSize, Key,
686 WarningOptionCompare);
687 if (Found == OptionTable + OptionTableSize ||
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000688 Found->getName() != Group)
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000689 return true; // Option not found.
690
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000691 MapGroupMembers(Found, Map, Loc, Diag);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000692 return false;
693}
694
695/// ProcessDiag - This is the method used to report a diagnostic that is
696/// finally fully formed.
David Blaikied6471f72011-09-25 23:23:43 +0000697bool DiagnosticIDs::ProcessDiag(DiagnosticsEngine &Diag) const {
David Blaikie40847cf2011-09-26 01:18:08 +0000698 Diagnostic Info(&Diag);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000699
700 if (Diag.SuppressAllDiagnostics)
701 return false;
702
703 assert(Diag.getClient() && "DiagnosticClient not set!");
704
705 // Figure out the diagnostic level of this message.
706 DiagnosticIDs::Level DiagLevel;
707 unsigned DiagID = Info.getID();
708
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000709 if (DiagID >= diag::DIAG_UPPER_LIMIT) {
710 // Handle custom diagnostics, which cannot be mapped.
711 DiagLevel = CustomDiagInfo->getLevel(DiagID);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000712 } else {
713 // Get the class of the diagnostic. If this is a NOTE, map it onto whatever
714 // the diagnostic level was for the previous diagnostic so that it is
715 // filtered the same as the previous diagnostic.
716 unsigned DiagClass = getBuiltinDiagClass(DiagID);
717 if (DiagClass == CLASS_NOTE) {
718 DiagLevel = DiagnosticIDs::Note;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000719 } else {
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000720 DiagLevel = getDiagnosticLevel(DiagID, DiagClass, Info.getLocation(),
721 Diag);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000722 }
723 }
724
725 if (DiagLevel != DiagnosticIDs::Note) {
726 // Record that a fatal error occurred only when we see a second
727 // non-note diagnostic. This allows notes to be attached to the
728 // fatal error, but suppresses any diagnostics that follow those
729 // notes.
730 if (Diag.LastDiagLevel == DiagnosticIDs::Fatal)
731 Diag.FatalErrorOccurred = true;
732
733 Diag.LastDiagLevel = DiagLevel;
734 }
735
Argyrios Kyrtzidisc0a575f2011-07-29 01:25:44 +0000736 // Update counts for DiagnosticErrorTrap even if a fatal error occurred.
737 if (DiagLevel >= DiagnosticIDs::Error) {
738 ++Diag.TrapNumErrorsOccurred;
739 if (isUnrecoverable(DiagID))
740 ++Diag.TrapNumUnrecoverableErrorsOccurred;
741 }
742
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000743 // If a fatal error has already been emitted, silence all subsequent
744 // diagnostics.
745 if (Diag.FatalErrorOccurred) {
746 if (DiagLevel >= DiagnosticIDs::Error &&
747 Diag.Client->IncludeInDiagnosticCounts()) {
748 ++Diag.NumErrors;
749 ++Diag.NumErrorsSuppressed;
750 }
751
752 return false;
753 }
754
755 // If the client doesn't care about this message, don't issue it. If this is
756 // a note and the last real diagnostic was ignored, ignore it too.
757 if (DiagLevel == DiagnosticIDs::Ignored ||
758 (DiagLevel == DiagnosticIDs::Note &&
759 Diag.LastDiagLevel == DiagnosticIDs::Ignored))
760 return false;
761
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000762 if (DiagLevel >= DiagnosticIDs::Error) {
Argyrios Kyrtzidisc0a575f2011-07-29 01:25:44 +0000763 if (isUnrecoverable(DiagID))
Douglas Gregor85bea972011-07-06 17:40:26 +0000764 Diag.UnrecoverableErrorOccurred = true;
Douglas Gregor85bea972011-07-06 17:40:26 +0000765
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000766 if (Diag.Client->IncludeInDiagnosticCounts()) {
767 Diag.ErrorOccurred = true;
768 ++Diag.NumErrors;
769 }
770
Douglas Gregorf1d59482011-08-17 19:13:00 +0000771 // If we've emitted a lot of errors, emit a fatal error instead of it to
772 // stop a flood of bogus errors.
773 if (Diag.ErrorLimit && Diag.NumErrors > Diag.ErrorLimit &&
774 DiagLevel == DiagnosticIDs::Error) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000775 Diag.SetDelayedDiagnostic(diag::fatal_too_many_errors);
Douglas Gregorf1d59482011-08-17 19:13:00 +0000776 return false;
777 }
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000778 }
779
Douglas Gregor4814fb52011-02-03 23:41:12 +0000780 // If we have any Fix-Its, make sure that all of the Fix-Its point into
Chandler Carruth3201f382011-07-26 05:17:23 +0000781 // source locations that aren't macro expansions. If any point into macro
782 // expansions, remove all of the Fix-Its.
Douglas Gregor4814fb52011-02-03 23:41:12 +0000783 for (unsigned I = 0, N = Diag.NumFixItHints; I != N; ++I) {
784 const FixItHint &FixIt = Diag.FixItHints[I];
785 if (FixIt.RemoveRange.isInvalid() ||
786 FixIt.RemoveRange.getBegin().isMacroID() ||
787 FixIt.RemoveRange.getEnd().isMacroID()) {
788 Diag.NumFixItHints = 0;
789 break;
790 }
791 }
792
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000793 // Finally, report it.
David Blaikied6471f72011-09-25 23:23:43 +0000794 Diag.Client->HandleDiagnostic((DiagnosticsEngine::Level)DiagLevel, Info);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000795 if (Diag.Client->IncludeInDiagnosticCounts()) {
796 if (DiagLevel == DiagnosticIDs::Warning)
797 ++Diag.NumWarnings;
798 }
799
800 Diag.CurDiagID = ~0U;
801
802 return true;
803}
John McCall923cd572011-06-15 21:46:43 +0000804
805bool DiagnosticIDs::isUnrecoverable(unsigned DiagID) const {
806 if (DiagID >= diag::DIAG_UPPER_LIMIT) {
807 // Custom diagnostics.
808 return CustomDiagInfo->getLevel(DiagID) >= DiagnosticIDs::Error;
809 }
810
811 // Only errors may be unrecoverable.
Douglas Gregor85bea972011-07-06 17:40:26 +0000812 if (getBuiltinDiagClass(DiagID) < CLASS_ERROR)
John McCall923cd572011-06-15 21:46:43 +0000813 return false;
814
815 if (DiagID == diag::err_unavailable ||
816 DiagID == diag::err_unavailable_message)
817 return false;
818
John McCallf85e1932011-06-15 23:02:42 +0000819 // Currently we consider all ARC errors as recoverable.
820 if (getCategoryNumberForDiag(DiagID) ==
821 diag::DiagCat_Automatic_Reference_Counting_Issue)
822 return false;
823
John McCall923cd572011-06-15 21:46:43 +0000824 return true;
825}