blob: 6c15e259092a67549ad607d0f54ac93340b9a425 [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"
Chandler Carrutha2398d72011-12-09 00:02:23 +000024#include "clang/Serialization/SerializationDiagnostic.h"
Daniel Dunbar3f839462011-09-29 01:47:16 +000025#include "llvm/ADT/SmallVector.h"
David Blaikie9fe8c742011-09-23 05:35:21 +000026#include "llvm/Support/ErrorHandling.h"
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +000027
28#include <map>
29using namespace clang;
30
31//===----------------------------------------------------------------------===//
32// Builtin Diagnostic information
33//===----------------------------------------------------------------------===//
34
35namespace {
36
37// Diagnostic classes.
38enum {
39 CLASS_NOTE = 0x01,
40 CLASS_WARNING = 0x02,
41 CLASS_EXTENSION = 0x03,
42 CLASS_ERROR = 0x04
43};
44
45struct StaticDiagInfoRec {
46 unsigned short DiagID;
47 unsigned Mapping : 3;
48 unsigned Class : 3;
Douglas Gregor418df342011-01-27 21:06:28 +000049 unsigned SFINAE : 1;
50 unsigned AccessControl : 1;
Daniel Dunbar4213df32011-09-29 00:34:06 +000051 unsigned WarnNoWerror : 1;
52 unsigned WarnShowInSystemHeader : 1;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +000053 unsigned Category : 5;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +000054
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000055 uint8_t NameLen;
56 uint8_t OptionGroupLen;
57
58 uint16_t DescriptionLen;
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000059
60 const char *NameStr;
61 const char *OptionGroupStr;
62
63 const char *DescriptionStr;
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000064
Chris Lattner5f9e2722011-07-23 10:55:15 +000065 StringRef getName() const {
66 return StringRef(NameStr, NameLen);
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000067 }
Chris Lattner5f9e2722011-07-23 10:55:15 +000068 StringRef getOptionGroup() const {
69 return StringRef(OptionGroupStr, OptionGroupLen);
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000070 }
71
Chris Lattner5f9e2722011-07-23 10:55:15 +000072 StringRef getDescription() const {
73 return StringRef(DescriptionStr, DescriptionLen);
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000074 }
Douglas Gregor7d2b8c12011-04-15 22:04:17 +000075
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +000076 bool operator<(const StaticDiagInfoRec &RHS) const {
77 return DiagID < RHS.DiagID;
78 }
79};
80
Douglas Gregor7d2b8c12011-04-15 22:04:17 +000081struct StaticDiagNameIndexRec {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000082 const char *NameStr;
Douglas Gregor7d2b8c12011-04-15 22:04:17 +000083 unsigned short DiagID;
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000084 uint8_t NameLen;
85
Chris Lattner5f9e2722011-07-23 10:55:15 +000086 StringRef getName() const {
87 return StringRef(NameStr, NameLen);
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000088 }
89
Douglas Gregor7d2b8c12011-04-15 22:04:17 +000090 bool operator<(const StaticDiagNameIndexRec &RHS) const {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000091 return getName() < RHS.getName();
Douglas Gregor7d2b8c12011-04-15 22:04:17 +000092 }
93
94 bool operator==(const StaticDiagNameIndexRec &RHS) const {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000095 return getName() == RHS.getName();
Douglas Gregor7d2b8c12011-04-15 22:04:17 +000096 }
97};
98
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000099template <size_t SizeOfStr, typename FieldType>
100class StringSizerHelper {
101 char FIELD_TOO_SMALL[SizeOfStr <= FieldType(~0U) ? 1 : -1];
102public:
103 enum { Size = SizeOfStr };
104};
105
106} // namespace anonymous
107
108#define STR_SIZE(str, fieldTy) StringSizerHelper<sizeof(str)-1, fieldTy>::Size
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000109
110static const StaticDiagInfoRec StaticDiagInfo[] = {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000111#define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP, \
Daniel Dunbar4213df32011-09-29 00:34:06 +0000112 SFINAE,ACCESS,NOWERROR,SHOWINSYSHEADER, \
Benjamin Kramerf94d3922012-02-09 19:38:26 +0000113 CATEGORY) \
Daniel Dunbar4213df32011-09-29 00:34:06 +0000114 { diag::ENUM, DEFAULT_MAPPING, CLASS, SFINAE, ACCESS, \
115 NOWERROR, SHOWINSYSHEADER, CATEGORY, \
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000116 STR_SIZE(#ENUM, uint8_t), STR_SIZE(GROUP, uint8_t), \
Benjamin Kramerf94d3922012-02-09 19:38:26 +0000117 STR_SIZE(DESC, uint16_t), \
118 #ENUM, GROUP, DESC },
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000119#include "clang/Basic/DiagnosticCommonKinds.inc"
120#include "clang/Basic/DiagnosticDriverKinds.inc"
121#include "clang/Basic/DiagnosticFrontendKinds.inc"
Chandler Carrutha2398d72011-12-09 00:02:23 +0000122#include "clang/Basic/DiagnosticSerializationKinds.inc"
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000123#include "clang/Basic/DiagnosticLexKinds.inc"
124#include "clang/Basic/DiagnosticParseKinds.inc"
125#include "clang/Basic/DiagnosticASTKinds.inc"
126#include "clang/Basic/DiagnosticSemaKinds.inc"
127#include "clang/Basic/DiagnosticAnalysisKinds.inc"
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000128#undef DIAG
Benjamin Kramerf94d3922012-02-09 19:38:26 +0000129 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000130};
131
132static const unsigned StaticDiagInfoSize =
133 sizeof(StaticDiagInfo)/sizeof(StaticDiagInfo[0])-1;
134
135/// To be sorted before first use (since it's splitted among multiple files)
Benjamin Kramer81f9d142011-06-14 13:15:38 +0000136static const StaticDiagNameIndexRec StaticDiagNameIndex[] = {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000137#define DIAG_NAME_INDEX(ENUM) { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) },
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000138#include "clang/Basic/DiagnosticIndexName.inc"
139#undef DIAG_NAME_INDEX
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000140 { 0, 0, 0 }
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000141};
142
143static const unsigned StaticDiagNameIndexSize =
144 sizeof(StaticDiagNameIndex)/sizeof(StaticDiagNameIndex[0])-1;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000145
146/// GetDiagInfo - Return the StaticDiagInfoRec entry for the specified DiagID,
147/// or null if the ID is invalid.
148static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000149 // If assertions are enabled, verify that the StaticDiagInfo array is sorted.
150#ifndef NDEBUG
151 static bool IsFirst = true;
152 if (IsFirst) {
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000153 for (unsigned i = 1; i != StaticDiagInfoSize; ++i) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000154 assert(StaticDiagInfo[i-1].DiagID != StaticDiagInfo[i].DiagID &&
155 "Diag ID conflict, the enums at the start of clang::diag (in "
Fariborz Jahanianf84109e2011-01-07 18:59:25 +0000156 "DiagnosticIDs.h) probably need to be increased");
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000157
158 assert(StaticDiagInfo[i-1] < StaticDiagInfo[i] &&
159 "Improperly sorted diag info");
160 }
161 IsFirst = false;
162 }
163#endif
164
165 // Search the diagnostic table with a binary search.
Jeffrey Yasskin7c5109b2011-08-13 05:47:04 +0000166 StaticDiagInfoRec Find = { static_cast<unsigned short>(DiagID),
Benjamin Kramerf94d3922012-02-09 19:38:26 +0000167 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000168
169 const StaticDiagInfoRec *Found =
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000170 std::lower_bound(StaticDiagInfo, StaticDiagInfo + StaticDiagInfoSize, Find);
171 if (Found == StaticDiagInfo + StaticDiagInfoSize ||
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000172 Found->DiagID != DiagID)
173 return 0;
174
175 return Found;
176}
177
Daniel Dunbara5e41332011-09-29 01:52:06 +0000178static DiagnosticMappingInfo GetDefaultDiagMappingInfo(unsigned DiagID) {
Daniel Dunbaraeacae52011-09-29 02:03:01 +0000179 DiagnosticMappingInfo Info = DiagnosticMappingInfo::Make(
Daniel Dunbara5e41332011-09-29 01:52:06 +0000180 diag::MAP_FATAL, /*IsUser=*/false, /*IsPragma=*/false);
Daniel Dunbar4213df32011-09-29 00:34:06 +0000181
Daniel Dunbara5e41332011-09-29 01:52:06 +0000182 if (const StaticDiagInfoRec *StaticInfo = GetDiagInfo(DiagID)) {
183 Info.setMapping((diag::Mapping) StaticInfo->Mapping);
184
185 if (StaticInfo->WarnNoWerror) {
186 assert(Info.getMapping() == diag::MAP_WARNING &&
Daniel Dunbar4213df32011-09-29 00:34:06 +0000187 "Unexpected mapping with no-Werror bit!");
Daniel Dunbara5e41332011-09-29 01:52:06 +0000188 Info.setNoWarningAsError(true);
Daniel Dunbar4213df32011-09-29 00:34:06 +0000189 }
190
Daniel Dunbara5e41332011-09-29 01:52:06 +0000191 if (StaticInfo->WarnShowInSystemHeader) {
192 assert(Info.getMapping() == diag::MAP_WARNING &&
Daniel Dunbar4213df32011-09-29 00:34:06 +0000193 "Unexpected mapping with show-in-system-header bit!");
Daniel Dunbara5e41332011-09-29 01:52:06 +0000194 Info.setShowInSystemHeader(true);
Daniel Dunbar4213df32011-09-29 00:34:06 +0000195 }
Daniel Dunbar4213df32011-09-29 00:34:06 +0000196 }
Daniel Dunbara5e41332011-09-29 01:52:06 +0000197
198 return Info;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000199}
200
201/// getWarningOptionForDiag - Return the lowest-level warning option that
202/// enables the specified diagnostic. If there is no -Wfoo flag that controls
203/// the diagnostic, this returns null.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000204StringRef DiagnosticIDs::getWarningOptionForDiag(unsigned DiagID) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000205 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000206 return Info->getOptionGroup();
Chris Lattner5f9e2722011-07-23 10:55:15 +0000207 return StringRef();
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000208}
209
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000210/// getCategoryNumberForDiag - Return the category number that a specified
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000211/// DiagID belongs to, or 0 if no category.
212unsigned DiagnosticIDs::getCategoryNumberForDiag(unsigned DiagID) {
213 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
214 return Info->Category;
215 return 0;
216}
217
Benjamin Kramerdbda5132011-06-13 18:38:45 +0000218namespace {
219 // The diagnostic category names.
220 struct StaticDiagCategoryRec {
221 const char *NameStr;
222 uint8_t NameLen;
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000223
Chris Lattner5f9e2722011-07-23 10:55:15 +0000224 StringRef getName() const {
225 return StringRef(NameStr, NameLen);
Benjamin Kramerdbda5132011-06-13 18:38:45 +0000226 }
227 };
228}
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000229
Daniel Dunbarba494c62011-09-29 01:42:25 +0000230// Unfortunately, the split between DiagnosticIDs and Diagnostic is not
231// particularly clean, but for now we just implement this method here so we can
232// access GetDefaultDiagMapping.
233DiagnosticMappingInfo &DiagnosticsEngine::DiagState::getOrAddMappingInfo(
234 diag::kind Diag)
235{
236 std::pair<iterator, bool> Result = DiagMap.insert(
Daniel Dunbaraeacae52011-09-29 02:03:01 +0000237 std::make_pair(Diag, DiagnosticMappingInfo()));
Daniel Dunbarba494c62011-09-29 01:42:25 +0000238
239 // Initialize the entry if we added it.
Daniel Dunbaraeacae52011-09-29 02:03:01 +0000240 if (Result.second)
Daniel Dunbara5e41332011-09-29 01:52:06 +0000241 Result.first->second = GetDefaultDiagMappingInfo(Diag);
Daniel Dunbarba494c62011-09-29 01:42:25 +0000242
243 return Result.first->second;
244}
245
Benjamin Kramerdbda5132011-06-13 18:38:45 +0000246static const StaticDiagCategoryRec CategoryNameTable[] = {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000247#define GET_CATEGORY_TABLE
John McCall923cd572011-06-15 21:46:43 +0000248#define CATEGORY(X, ENUM) { X, STR_SIZE(X, uint8_t) },
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000249#include "clang/Basic/DiagnosticGroups.inc"
250#undef GET_CATEGORY_TABLE
251 { 0, 0 }
252};
253
254/// getNumberOfCategories - Return the number of categories
255unsigned DiagnosticIDs::getNumberOfCategories() {
256 return sizeof(CategoryNameTable) / sizeof(CategoryNameTable[0])-1;
257}
258
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000259/// getCategoryNameFromID - Given a category ID, return the name of the
260/// category, an empty string if CategoryID is zero, or null if CategoryID is
261/// invalid.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000262StringRef DiagnosticIDs::getCategoryNameFromID(unsigned CategoryID) {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000263 if (CategoryID >= getNumberOfCategories())
Chris Lattner5f9e2722011-07-23 10:55:15 +0000264 return StringRef();
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000265 return CategoryNameTable[CategoryID].getName();
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000266}
267
268
269
270DiagnosticIDs::SFINAEResponse
271DiagnosticIDs::getDiagnosticSFINAEResponse(unsigned DiagID) {
272 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) {
Douglas Gregor418df342011-01-27 21:06:28 +0000273 if (Info->AccessControl)
274 return SFINAE_AccessControl;
275
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000276 if (!Info->SFINAE)
277 return SFINAE_Report;
278
279 if (Info->Class == CLASS_ERROR)
280 return SFINAE_SubstitutionFailure;
281
282 // Suppress notes, warnings, and extensions;
283 return SFINAE_Suppress;
284 }
285
286 return SFINAE_Report;
287}
288
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000289/// getName - Given a diagnostic ID, return its name
Chris Lattner5f9e2722011-07-23 10:55:15 +0000290StringRef DiagnosticIDs::getName(unsigned DiagID) {
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000291 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000292 return Info->getName();
Chris Lattner5f9e2722011-07-23 10:55:15 +0000293 return StringRef();
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000294}
295
296/// getIdFromName - Given a diagnostic name, return its ID, or 0
Chris Lattner5f9e2722011-07-23 10:55:15 +0000297unsigned DiagnosticIDs::getIdFromName(StringRef Name) {
Benjamin Kramer81f9d142011-06-14 13:15:38 +0000298 const StaticDiagNameIndexRec *StaticDiagNameIndexEnd =
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000299 StaticDiagNameIndex + StaticDiagNameIndexSize;
300
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000301 if (Name.empty()) { return diag::DIAG_UPPER_LIMIT; }
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000302
Jeffrey Yasskin7c5109b2011-08-13 05:47:04 +0000303 assert(Name.size() == static_cast<uint8_t>(Name.size()) &&
304 "Name is too long");
305 StaticDiagNameIndexRec Find = { Name.data(), 0,
306 static_cast<uint8_t>(Name.size()) };
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000307
308 const StaticDiagNameIndexRec *Found =
309 std::lower_bound( StaticDiagNameIndex, StaticDiagNameIndexEnd, Find);
310 if (Found == StaticDiagNameIndexEnd ||
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000311 Found->getName() != Name)
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000312 return diag::DIAG_UPPER_LIMIT;
313
314 return Found->DiagID;
315}
316
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000317/// getBuiltinDiagClass - Return the class field of the diagnostic.
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000318///
319static unsigned getBuiltinDiagClass(unsigned DiagID) {
320 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
321 return Info->Class;
322 return ~0U;
323}
324
325//===----------------------------------------------------------------------===//
Ted Kremenek6948bc42011-08-09 03:39:14 +0000326// diag_iterator
327//===----------------------------------------------------------------------===//
328
329llvm::StringRef DiagnosticIDs::diag_iterator::getDiagName() const {
330 return static_cast<const StaticDiagNameIndexRec*>(impl)->getName();
331}
332
333unsigned DiagnosticIDs::diag_iterator::getDiagID() const {
334 return static_cast<const StaticDiagNameIndexRec*>(impl)->DiagID;
335}
336
337DiagnosticIDs::diag_iterator &DiagnosticIDs::diag_iterator::operator++() {
338 const StaticDiagNameIndexRec* ptr =
339 static_cast<const StaticDiagNameIndexRec*>(impl);;
340 ++ptr;
341 impl = ptr;
342 return *this;
343}
344
345DiagnosticIDs::diag_iterator DiagnosticIDs::diags_begin() {
346 return DiagnosticIDs::diag_iterator(StaticDiagNameIndex);
347}
348
349DiagnosticIDs::diag_iterator DiagnosticIDs::diags_end() {
350 return DiagnosticIDs::diag_iterator(StaticDiagNameIndex +
351 StaticDiagNameIndexSize);
352}
353
354//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000355// Custom Diagnostic information
356//===----------------------------------------------------------------------===//
357
358namespace clang {
359 namespace diag {
360 class CustomDiagInfo {
361 typedef std::pair<DiagnosticIDs::Level, std::string> DiagDesc;
362 std::vector<DiagDesc> DiagInfo;
363 std::map<DiagDesc, unsigned> DiagIDs;
364 public:
365
366 /// getDescription - Return the description of the specified custom
367 /// diagnostic.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000368 StringRef getDescription(unsigned DiagID) const {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000369 assert(this && DiagID-DIAG_UPPER_LIMIT < DiagInfo.size() &&
370 "Invalid diagnosic ID");
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000371 return DiagInfo[DiagID-DIAG_UPPER_LIMIT].second;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000372 }
373
374 /// getLevel - Return the level of the specified custom diagnostic.
375 DiagnosticIDs::Level getLevel(unsigned DiagID) const {
376 assert(this && DiagID-DIAG_UPPER_LIMIT < DiagInfo.size() &&
377 "Invalid diagnosic ID");
378 return DiagInfo[DiagID-DIAG_UPPER_LIMIT].first;
379 }
380
Chris Lattner5f9e2722011-07-23 10:55:15 +0000381 unsigned getOrCreateDiagID(DiagnosticIDs::Level L, StringRef Message,
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000382 DiagnosticIDs &Diags) {
383 DiagDesc D(L, Message);
384 // Check to see if it already exists.
385 std::map<DiagDesc, unsigned>::iterator I = DiagIDs.lower_bound(D);
386 if (I != DiagIDs.end() && I->first == D)
387 return I->second;
388
389 // If not, assign a new ID.
390 unsigned ID = DiagInfo.size()+DIAG_UPPER_LIMIT;
391 DiagIDs.insert(std::make_pair(D, ID));
392 DiagInfo.push_back(D);
393 return ID;
394 }
395 };
396
397 } // end diag namespace
398} // end clang namespace
399
400
401//===----------------------------------------------------------------------===//
402// Common Diagnostic implementation
403//===----------------------------------------------------------------------===//
404
405DiagnosticIDs::DiagnosticIDs() {
406 CustomDiagInfo = 0;
407}
408
409DiagnosticIDs::~DiagnosticIDs() {
410 delete CustomDiagInfo;
411}
412
413/// getCustomDiagID - Return an ID for a diagnostic with the specified message
414/// and level. If this is the first request for this diagnosic, it is
415/// registered and created, otherwise the existing ID is returned.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000416unsigned DiagnosticIDs::getCustomDiagID(Level L, StringRef Message) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000417 if (CustomDiagInfo == 0)
418 CustomDiagInfo = new diag::CustomDiagInfo();
419 return CustomDiagInfo->getOrCreateDiagID(L, Message, *this);
420}
421
422
423/// isBuiltinWarningOrExtension - Return true if the unmapped diagnostic
424/// level of the specified diagnostic ID is a Warning or Extension.
425/// This only works on builtin diagnostics, not custom ones, and is not legal to
426/// call on NOTEs.
427bool DiagnosticIDs::isBuiltinWarningOrExtension(unsigned DiagID) {
428 return DiagID < diag::DIAG_UPPER_LIMIT &&
429 getBuiltinDiagClass(DiagID) != CLASS_ERROR;
430}
431
432/// \brief Determine whether the given built-in diagnostic ID is a
433/// Note.
434bool DiagnosticIDs::isBuiltinNote(unsigned DiagID) {
435 return DiagID < diag::DIAG_UPPER_LIMIT &&
436 getBuiltinDiagClass(DiagID) == CLASS_NOTE;
437}
438
439/// isBuiltinExtensionDiag - Determine whether the given built-in diagnostic
440/// ID is for an extension of some sort. This also returns EnabledByDefault,
441/// which is set to indicate whether the diagnostic is ignored by default (in
442/// which case -pedantic enables it) or treated as a warning/error by default.
443///
444bool DiagnosticIDs::isBuiltinExtensionDiag(unsigned DiagID,
445 bool &EnabledByDefault) {
446 if (DiagID >= diag::DIAG_UPPER_LIMIT ||
447 getBuiltinDiagClass(DiagID) != CLASS_EXTENSION)
448 return false;
449
Daniel Dunbara5e41332011-09-29 01:52:06 +0000450 EnabledByDefault =
451 GetDefaultDiagMappingInfo(DiagID).getMapping() != diag::MAP_IGNORE;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000452 return true;
453}
454
Daniel Dunbar76101cf2011-09-29 01:01:08 +0000455bool DiagnosticIDs::isDefaultMappingAsError(unsigned DiagID) {
456 if (DiagID >= diag::DIAG_UPPER_LIMIT)
457 return false;
458
Daniel Dunbara5e41332011-09-29 01:52:06 +0000459 return GetDefaultDiagMappingInfo(DiagID).getMapping() == diag::MAP_ERROR;
Daniel Dunbar76101cf2011-09-29 01:01:08 +0000460}
461
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000462/// getDescription - Given a diagnostic ID, return a description of the
463/// issue.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000464StringRef DiagnosticIDs::getDescription(unsigned DiagID) const {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000465 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000466 return Info->getDescription();
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000467 return CustomDiagInfo->getDescription(DiagID);
468}
469
David Blaikied6471f72011-09-25 23:23:43 +0000470/// getDiagnosticLevel - Based on the way the client configured the
471/// DiagnosticsEngine object, classify the specified diagnostic ID into a Level,
472/// by consumable the DiagnosticClient.
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000473DiagnosticIDs::Level
474DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, SourceLocation Loc,
Daniel Dunbar1656aae2011-09-29 01:20:28 +0000475 const DiagnosticsEngine &Diag) const {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000476 // Handle custom diagnostics, which cannot be mapped.
477 if (DiagID >= diag::DIAG_UPPER_LIMIT)
478 return CustomDiagInfo->getLevel(DiagID);
479
480 unsigned DiagClass = getBuiltinDiagClass(DiagID);
481 assert(DiagClass != CLASS_NOTE && "Cannot get diagnostic level of a note!");
Daniel Dunbar1656aae2011-09-29 01:20:28 +0000482 return getDiagnosticLevel(DiagID, DiagClass, Loc, Diag);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000483}
484
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000485/// \brief Based on the way the client configured the Diagnostic
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000486/// object, classify the specified diagnostic ID into a Level, consumable by
487/// the DiagnosticClient.
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000488///
489/// \param Loc The source location we are interested in finding out the
490/// diagnostic state. Can be null in order to query the latest state.
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000491DiagnosticIDs::Level
492DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass,
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000493 SourceLocation Loc,
Daniel Dunbar1656aae2011-09-29 01:20:28 +0000494 const DiagnosticsEngine &Diag) const {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000495 // Specific non-error diagnostics may be mapped to various levels from ignored
496 // to error. Errors can only be mapped to fatal.
497 DiagnosticIDs::Level Result = DiagnosticIDs::Fatal;
498
David Blaikied6471f72011-09-25 23:23:43 +0000499 DiagnosticsEngine::DiagStatePointsTy::iterator
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000500 Pos = Diag.GetDiagStatePointForLoc(Loc);
David Blaikied6471f72011-09-25 23:23:43 +0000501 DiagnosticsEngine::DiagState *State = Pos->State;
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000502
Daniel Dunbarba494c62011-09-29 01:42:25 +0000503 // Get the mapping information, or compute it lazily.
504 DiagnosticMappingInfo &MappingInfo = State->getOrAddMappingInfo(
505 (diag::kind)DiagID);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000506
Daniel Dunbarb1c99c62011-09-29 01:30:00 +0000507 switch (MappingInfo.getMapping()) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000508 case diag::MAP_IGNORE:
Daniel Dunbarbe1aa412011-09-29 01:58:05 +0000509 Result = DiagnosticIDs::Ignored;
510 break;
511 case diag::MAP_WARNING:
512 Result = DiagnosticIDs::Warning;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000513 break;
514 case diag::MAP_ERROR:
515 Result = DiagnosticIDs::Error;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000516 break;
517 case diag::MAP_FATAL:
518 Result = DiagnosticIDs::Fatal;
519 break;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000520 }
521
Daniel Dunbarbe1aa412011-09-29 01:58:05 +0000522 // Upgrade ignored diagnostics if -Weverything is enabled.
523 if (Diag.EnableAllWarnings && Result == DiagnosticIDs::Ignored &&
524 !MappingInfo.isUser())
525 Result = DiagnosticIDs::Warning;
526
Bob Wilson18c407f2011-10-12 19:55:31 +0000527 // Ignore -pedantic diagnostics inside __extension__ blocks.
528 // (The diagnostics controlled by -pedantic are the extension diagnostics
529 // that are not enabled by default.)
Daniel Dunbarf3dee202011-11-28 22:19:36 +0000530 bool EnabledByDefault = false;
Bob Wilson18c407f2011-10-12 19:55:31 +0000531 bool IsExtensionDiag = isBuiltinExtensionDiag(DiagID, EnabledByDefault);
532 if (Diag.AllExtensionsSilenced && IsExtensionDiag && !EnabledByDefault)
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000533 return DiagnosticIDs::Ignored;
534
Daniel Dunbarbe1aa412011-09-29 01:58:05 +0000535 // For extension diagnostics that haven't been explicitly mapped, check if we
536 // should upgrade the diagnostic.
537 if (IsExtensionDiag && !MappingInfo.isUser()) {
538 switch (Diag.ExtBehavior) {
539 case DiagnosticsEngine::Ext_Ignore:
540 break;
541 case DiagnosticsEngine::Ext_Warn:
542 // Upgrade ignored diagnostics to warnings.
543 if (Result == DiagnosticIDs::Ignored)
544 Result = DiagnosticIDs::Warning;
545 break;
546 case DiagnosticsEngine::Ext_Error:
547 // Upgrade ignored or warning diagnostics to errors.
548 if (Result == DiagnosticIDs::Ignored || Result == DiagnosticIDs::Warning)
549 Result = DiagnosticIDs::Error;
550 break;
551 }
552 }
553
554 // At this point, ignored errors can no longer be upgraded.
555 if (Result == DiagnosticIDs::Ignored)
556 return Result;
557
558 // Honor -w, which is lower in priority than pedantic-errors, but higher than
559 // -Werror.
560 if (Result == DiagnosticIDs::Warning && Diag.IgnoreAllWarnings)
561 return DiagnosticIDs::Ignored;
562
563 // If -Werror is enabled, map warnings to errors unless explicitly disabled.
564 if (Result == DiagnosticIDs::Warning) {
565 if (Diag.WarningsAsErrors && !MappingInfo.hasNoWarningAsError())
566 Result = DiagnosticIDs::Error;
567 }
568
569 // If -Wfatal-errors is enabled, map errors to fatal unless explicity
570 // disabled.
571 if (Result == DiagnosticIDs::Error) {
572 if (Diag.ErrorsAsFatal && !MappingInfo.hasNoErrorAsFatal())
573 Result = DiagnosticIDs::Fatal;
574 }
575
Daniel Dunbaraeacae52011-09-29 02:03:01 +0000576 // If we are in a system header, we ignore it. We look at the diagnostic class
577 // because we also want to ignore extensions and warnings in -Werror and
Argyrios Kyrtzidiscfdadfe2011-04-21 23:08:18 +0000578 // -pedantic-errors modes, which *map* warnings/extensions to errors.
579 if (Result >= DiagnosticIDs::Warning &&
580 DiagClass != CLASS_ERROR &&
581 // Custom diagnostics always are emitted in system headers.
582 DiagID < diag::DIAG_UPPER_LIMIT &&
Daniel Dunbarbe1aa412011-09-29 01:58:05 +0000583 !MappingInfo.hasShowInSystemHeader() &&
Argyrios Kyrtzidiscfdadfe2011-04-21 23:08:18 +0000584 Diag.SuppressSystemWarnings &&
585 Loc.isValid() &&
586 Diag.getSourceManager().isInSystemHeader(
Chandler Carruth40278532011-07-25 16:49:02 +0000587 Diag.getSourceManager().getExpansionLoc(Loc)))
Argyrios Kyrtzidiscfdadfe2011-04-21 23:08:18 +0000588 return DiagnosticIDs::Ignored;
589
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000590 return Result;
591}
592
Daniel Dunbar3f839462011-09-29 01:47:16 +0000593struct clang::WarningOption {
594 // Be safe with the size of 'NameLen' because we don't statically check if
595 // the size will fit in the field; the struct size won't decrease with a
596 // shorter type anyway.
597 size_t NameLen;
598 const char *NameStr;
599 const short *Members;
600 const short *SubGroups;
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000601
Daniel Dunbar3f839462011-09-29 01:47:16 +0000602 StringRef getName() const {
603 return StringRef(NameStr, NameLen);
604 }
605};
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000606
607#define GET_DIAG_ARRAYS
608#include "clang/Basic/DiagnosticGroups.inc"
609#undef GET_DIAG_ARRAYS
610
611// Second the table of options, sorted by name for fast binary lookup.
612static const WarningOption OptionTable[] = {
613#define GET_DIAG_TABLE
614#include "clang/Basic/DiagnosticGroups.inc"
615#undef GET_DIAG_TABLE
616};
617static const size_t OptionTableSize =
618sizeof(OptionTable) / sizeof(OptionTable[0]);
619
620static bool WarningOptionCompare(const WarningOption &LHS,
621 const WarningOption &RHS) {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000622 return LHS.getName() < RHS.getName();
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000623}
624
Daniel Dunbar3f839462011-09-29 01:47:16 +0000625void DiagnosticIDs::getDiagnosticsInGroup(
626 const WarningOption *Group,
627 llvm::SmallVectorImpl<diag::kind> &Diags) const
628{
629 // Add the members of the option diagnostic set.
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000630 if (const short *Member = Group->Members) {
631 for (; *Member != -1; ++Member)
Daniel Dunbar3f839462011-09-29 01:47:16 +0000632 Diags.push_back(*Member);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000633 }
634
Daniel Dunbar3f839462011-09-29 01:47:16 +0000635 // Add the members of the subgroups.
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000636 if (const short *SubGroups = Group->SubGroups) {
637 for (; *SubGroups != (short)-1; ++SubGroups)
Daniel Dunbar3f839462011-09-29 01:47:16 +0000638 getDiagnosticsInGroup(&OptionTable[(short)*SubGroups], Diags);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000639 }
640}
641
Daniel Dunbar3f839462011-09-29 01:47:16 +0000642bool DiagnosticIDs::getDiagnosticsInGroup(
643 StringRef Group,
644 llvm::SmallVectorImpl<diag::kind> &Diags) const
645{
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000646 WarningOption Key = { Group.size(), Group.data(), 0, 0 };
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000647 const WarningOption *Found =
648 std::lower_bound(OptionTable, OptionTable + OptionTableSize, Key,
649 WarningOptionCompare);
650 if (Found == OptionTable + OptionTableSize ||
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000651 Found->getName() != Group)
Daniel Dunbar3f839462011-09-29 01:47:16 +0000652 return true; // Option not found.
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000653
Daniel Dunbar3f839462011-09-29 01:47:16 +0000654 getDiagnosticsInGroup(Found, Diags);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000655 return false;
656}
657
Argyrios Kyrtzidis11583c72012-01-27 06:15:43 +0000658void DiagnosticIDs::getAllDiagnostics(
659 llvm::SmallVectorImpl<diag::kind> &Diags) const {
660 for (unsigned i = 0; i != StaticDiagInfoSize; ++i)
661 Diags.push_back(StaticDiagInfo[i].DiagID);
662}
663
Benjamin Kramera70cb9d2011-11-14 23:30:34 +0000664StringRef DiagnosticIDs::getNearestWarningOption(StringRef Group) {
665 StringRef Best;
Benjamin Kramerdce63272011-11-15 12:26:39 +0000666 unsigned BestDistance = Group.size() + 1; // Sanity threshold.
Benjamin Kramera70cb9d2011-11-14 23:30:34 +0000667 for (const WarningOption *i = OptionTable, *e = OptionTable + OptionTableSize;
668 i != e; ++i) {
669 // Don't suggest ignored warning flags.
670 if (!i->Members && !i->SubGroups)
671 continue;
672
673 unsigned Distance = i->getName().edit_distance(Group, true, BestDistance);
Benjamin Kramerdce63272011-11-15 12:26:39 +0000674 if (Distance == BestDistance) {
675 // Two matches with the same distance, don't prefer one over the other.
676 Best = "";
677 } else if (Distance < BestDistance) {
678 // This is a better match.
Benjamin Kramera70cb9d2011-11-14 23:30:34 +0000679 Best = i->getName();
680 BestDistance = Distance;
681 }
682 }
683
684 return Best;
685}
686
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000687/// ProcessDiag - This is the method used to report a diagnostic that is
688/// finally fully formed.
David Blaikied6471f72011-09-25 23:23:43 +0000689bool DiagnosticIDs::ProcessDiag(DiagnosticsEngine &Diag) const {
David Blaikie40847cf2011-09-26 01:18:08 +0000690 Diagnostic Info(&Diag);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000691
692 if (Diag.SuppressAllDiagnostics)
693 return false;
694
695 assert(Diag.getClient() && "DiagnosticClient not set!");
696
697 // Figure out the diagnostic level of this message.
698 DiagnosticIDs::Level DiagLevel;
699 unsigned DiagID = Info.getID();
700
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000701 if (DiagID >= diag::DIAG_UPPER_LIMIT) {
702 // Handle custom diagnostics, which cannot be mapped.
703 DiagLevel = CustomDiagInfo->getLevel(DiagID);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000704 } else {
705 // Get the class of the diagnostic. If this is a NOTE, map it onto whatever
706 // the diagnostic level was for the previous diagnostic so that it is
707 // filtered the same as the previous diagnostic.
708 unsigned DiagClass = getBuiltinDiagClass(DiagID);
709 if (DiagClass == CLASS_NOTE) {
710 DiagLevel = DiagnosticIDs::Note;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000711 } else {
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000712 DiagLevel = getDiagnosticLevel(DiagID, DiagClass, Info.getLocation(),
713 Diag);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000714 }
715 }
716
717 if (DiagLevel != DiagnosticIDs::Note) {
718 // Record that a fatal error occurred only when we see a second
719 // non-note diagnostic. This allows notes to be attached to the
720 // fatal error, but suppresses any diagnostics that follow those
721 // notes.
722 if (Diag.LastDiagLevel == DiagnosticIDs::Fatal)
723 Diag.FatalErrorOccurred = true;
724
725 Diag.LastDiagLevel = DiagLevel;
726 }
727
Argyrios Kyrtzidisc0a575f2011-07-29 01:25:44 +0000728 // Update counts for DiagnosticErrorTrap even if a fatal error occurred.
729 if (DiagLevel >= DiagnosticIDs::Error) {
730 ++Diag.TrapNumErrorsOccurred;
731 if (isUnrecoverable(DiagID))
732 ++Diag.TrapNumUnrecoverableErrorsOccurred;
733 }
734
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000735 // If a fatal error has already been emitted, silence all subsequent
736 // diagnostics.
737 if (Diag.FatalErrorOccurred) {
738 if (DiagLevel >= DiagnosticIDs::Error &&
739 Diag.Client->IncludeInDiagnosticCounts()) {
740 ++Diag.NumErrors;
741 ++Diag.NumErrorsSuppressed;
742 }
743
744 return false;
745 }
746
747 // If the client doesn't care about this message, don't issue it. If this is
748 // a note and the last real diagnostic was ignored, ignore it too.
749 if (DiagLevel == DiagnosticIDs::Ignored ||
750 (DiagLevel == DiagnosticIDs::Note &&
751 Diag.LastDiagLevel == DiagnosticIDs::Ignored))
752 return false;
753
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000754 if (DiagLevel >= DiagnosticIDs::Error) {
Argyrios Kyrtzidisc0a575f2011-07-29 01:25:44 +0000755 if (isUnrecoverable(DiagID))
Douglas Gregor85bea972011-07-06 17:40:26 +0000756 Diag.UnrecoverableErrorOccurred = true;
Douglas Gregor85bea972011-07-06 17:40:26 +0000757
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000758 if (Diag.Client->IncludeInDiagnosticCounts()) {
759 Diag.ErrorOccurred = true;
760 ++Diag.NumErrors;
761 }
762
Douglas Gregorf1d59482011-08-17 19:13:00 +0000763 // If we've emitted a lot of errors, emit a fatal error instead of it to
764 // stop a flood of bogus errors.
765 if (Diag.ErrorLimit && Diag.NumErrors > Diag.ErrorLimit &&
766 DiagLevel == DiagnosticIDs::Error) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000767 Diag.SetDelayedDiagnostic(diag::fatal_too_many_errors);
Douglas Gregorf1d59482011-08-17 19:13:00 +0000768 return false;
769 }
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000770 }
771
Douglas Gregor4814fb52011-02-03 23:41:12 +0000772 // If we have any Fix-Its, make sure that all of the Fix-Its point into
Chandler Carruth3201f382011-07-26 05:17:23 +0000773 // source locations that aren't macro expansions. If any point into macro
774 // expansions, remove all of the Fix-Its.
Argyrios Kyrtzidiscbf46a02012-02-03 05:58:22 +0000775 for (unsigned I = 0, N = Diag.FixItHints.size(); I != N; ++I) {
Douglas Gregor4814fb52011-02-03 23:41:12 +0000776 const FixItHint &FixIt = Diag.FixItHints[I];
777 if (FixIt.RemoveRange.isInvalid() ||
778 FixIt.RemoveRange.getBegin().isMacroID() ||
779 FixIt.RemoveRange.getEnd().isMacroID()) {
Argyrios Kyrtzidiscbf46a02012-02-03 05:58:22 +0000780 Diag.FixItHints.clear();
Douglas Gregor4814fb52011-02-03 23:41:12 +0000781 break;
782 }
783 }
784
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000785 // Finally, report it.
David Blaikied6471f72011-09-25 23:23:43 +0000786 Diag.Client->HandleDiagnostic((DiagnosticsEngine::Level)DiagLevel, Info);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000787 if (Diag.Client->IncludeInDiagnosticCounts()) {
788 if (DiagLevel == DiagnosticIDs::Warning)
789 ++Diag.NumWarnings;
790 }
791
792 Diag.CurDiagID = ~0U;
793
794 return true;
795}
John McCall923cd572011-06-15 21:46:43 +0000796
797bool DiagnosticIDs::isUnrecoverable(unsigned DiagID) const {
798 if (DiagID >= diag::DIAG_UPPER_LIMIT) {
799 // Custom diagnostics.
800 return CustomDiagInfo->getLevel(DiagID) >= DiagnosticIDs::Error;
801 }
802
803 // Only errors may be unrecoverable.
Douglas Gregor85bea972011-07-06 17:40:26 +0000804 if (getBuiltinDiagClass(DiagID) < CLASS_ERROR)
John McCall923cd572011-06-15 21:46:43 +0000805 return false;
806
807 if (DiagID == diag::err_unavailable ||
808 DiagID == diag::err_unavailable_message)
809 return false;
810
John McCallf85e1932011-06-15 23:02:42 +0000811 // Currently we consider all ARC errors as recoverable.
Ted Kremenekafdc21a2011-10-20 05:07:47 +0000812 if (isARCDiagnostic(DiagID))
John McCallf85e1932011-06-15 23:02:42 +0000813 return false;
814
John McCall923cd572011-06-15 21:46:43 +0000815 return true;
816}
Ted Kremenekafdc21a2011-10-20 05:07:47 +0000817
818bool DiagnosticIDs::isARCDiagnostic(unsigned DiagID) {
819 unsigned cat = getCategoryNumberForDiag(DiagID);
820 return DiagnosticIDs::getCategoryNameFromID(cat).startswith("ARC ");
821}
822