blob: b0d2f449f6a28d1646f5290f53675089199b05cc [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"
Daniel Dunbar3f839462011-09-29 01:47:16 +000024#include "llvm/ADT/SmallVector.h"
David Blaikie9fe8c742011-09-23 05:35:21 +000025#include "llvm/Support/ErrorHandling.h"
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +000026
27#include <map>
28using namespace clang;
29
30//===----------------------------------------------------------------------===//
31// Builtin Diagnostic information
32//===----------------------------------------------------------------------===//
33
34namespace {
35
36// Diagnostic classes.
37enum {
38 CLASS_NOTE = 0x01,
39 CLASS_WARNING = 0x02,
40 CLASS_EXTENSION = 0x03,
41 CLASS_ERROR = 0x04
42};
43
44struct StaticDiagInfoRec {
45 unsigned short DiagID;
46 unsigned Mapping : 3;
47 unsigned Class : 3;
Douglas Gregor418df342011-01-27 21:06:28 +000048 unsigned SFINAE : 1;
49 unsigned AccessControl : 1;
Daniel Dunbar4213df32011-09-29 00:34:06 +000050 unsigned WarnNoWerror : 1;
51 unsigned WarnShowInSystemHeader : 1;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +000052 unsigned Category : 5;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +000053
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000054 uint8_t NameLen;
55 uint8_t OptionGroupLen;
56
57 uint16_t DescriptionLen;
58 uint16_t BriefExplanationLen;
59 uint16_t FullExplanationLen;
60
61 const char *NameStr;
62 const char *OptionGroupStr;
63
64 const char *DescriptionStr;
65 const char *BriefExplanationStr;
66 const char *FullExplanationStr;
67
Chris Lattner5f9e2722011-07-23 10:55:15 +000068 StringRef getName() const {
69 return StringRef(NameStr, NameLen);
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000070 }
Chris Lattner5f9e2722011-07-23 10:55:15 +000071 StringRef getOptionGroup() const {
72 return StringRef(OptionGroupStr, OptionGroupLen);
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000073 }
74
Chris Lattner5f9e2722011-07-23 10:55:15 +000075 StringRef getDescription() const {
76 return StringRef(DescriptionStr, DescriptionLen);
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000077 }
Chris Lattner5f9e2722011-07-23 10:55:15 +000078 StringRef getBriefExplanation() const {
79 return StringRef(BriefExplanationStr, BriefExplanationLen);
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000080 }
Chris Lattner5f9e2722011-07-23 10:55:15 +000081 StringRef getFullExplanation() const {
82 return StringRef(FullExplanationStr, FullExplanationLen);
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000083 }
Douglas Gregor7d2b8c12011-04-15 22:04:17 +000084
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +000085 bool operator<(const StaticDiagInfoRec &RHS) const {
86 return DiagID < RHS.DiagID;
87 }
88};
89
Douglas Gregor7d2b8c12011-04-15 22:04:17 +000090struct StaticDiagNameIndexRec {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000091 const char *NameStr;
Douglas Gregor7d2b8c12011-04-15 22:04:17 +000092 unsigned short DiagID;
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000093 uint8_t NameLen;
94
Chris Lattner5f9e2722011-07-23 10:55:15 +000095 StringRef getName() const {
96 return StringRef(NameStr, NameLen);
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +000097 }
98
Douglas Gregor7d2b8c12011-04-15 22:04:17 +000099 bool operator<(const StaticDiagNameIndexRec &RHS) const {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000100 return getName() < RHS.getName();
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000101 }
102
103 bool operator==(const StaticDiagNameIndexRec &RHS) const {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000104 return getName() == RHS.getName();
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000105 }
106};
107
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000108template <size_t SizeOfStr, typename FieldType>
109class StringSizerHelper {
110 char FIELD_TOO_SMALL[SizeOfStr <= FieldType(~0U) ? 1 : -1];
111public:
112 enum { Size = SizeOfStr };
113};
114
115} // namespace anonymous
116
117#define STR_SIZE(str, fieldTy) StringSizerHelper<sizeof(str)-1, fieldTy>::Size
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000118
119static const StaticDiagInfoRec StaticDiagInfo[] = {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000120#define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP, \
Daniel Dunbar4213df32011-09-29 00:34:06 +0000121 SFINAE,ACCESS,NOWERROR,SHOWINSYSHEADER, \
122 CATEGORY,BRIEF,FULL) \
123 { diag::ENUM, DEFAULT_MAPPING, CLASS, SFINAE, ACCESS, \
124 NOWERROR, SHOWINSYSHEADER, CATEGORY, \
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000125 STR_SIZE(#ENUM, uint8_t), STR_SIZE(GROUP, uint8_t), \
126 STR_SIZE(DESC, uint16_t), STR_SIZE(BRIEF, uint16_t), \
127 STR_SIZE(FULL, uint16_t), \
128 #ENUM, GROUP, DESC, BRIEF, FULL },
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000129#include "clang/Basic/DiagnosticCommonKinds.inc"
130#include "clang/Basic/DiagnosticDriverKinds.inc"
131#include "clang/Basic/DiagnosticFrontendKinds.inc"
132#include "clang/Basic/DiagnosticLexKinds.inc"
133#include "clang/Basic/DiagnosticParseKinds.inc"
134#include "clang/Basic/DiagnosticASTKinds.inc"
135#include "clang/Basic/DiagnosticSemaKinds.inc"
136#include "clang/Basic/DiagnosticAnalysisKinds.inc"
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000137#undef DIAG
Daniel Dunbar4213df32011-09-29 00:34:06 +0000138 { 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 +0000139};
140
141static const unsigned StaticDiagInfoSize =
142 sizeof(StaticDiagInfo)/sizeof(StaticDiagInfo[0])-1;
143
144/// To be sorted before first use (since it's splitted among multiple files)
Benjamin Kramer81f9d142011-06-14 13:15:38 +0000145static const StaticDiagNameIndexRec StaticDiagNameIndex[] = {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000146#define DIAG_NAME_INDEX(ENUM) { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) },
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000147#include "clang/Basic/DiagnosticIndexName.inc"
148#undef DIAG_NAME_INDEX
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000149 { 0, 0, 0 }
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000150};
151
152static const unsigned StaticDiagNameIndexSize =
153 sizeof(StaticDiagNameIndex)/sizeof(StaticDiagNameIndex[0])-1;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000154
155/// GetDiagInfo - Return the StaticDiagInfoRec entry for the specified DiagID,
156/// or null if the ID is invalid.
157static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000158 // If assertions are enabled, verify that the StaticDiagInfo array is sorted.
159#ifndef NDEBUG
160 static bool IsFirst = true;
161 if (IsFirst) {
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000162 for (unsigned i = 1; i != StaticDiagInfoSize; ++i) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000163 assert(StaticDiagInfo[i-1].DiagID != StaticDiagInfo[i].DiagID &&
164 "Diag ID conflict, the enums at the start of clang::diag (in "
Fariborz Jahanianf84109e2011-01-07 18:59:25 +0000165 "DiagnosticIDs.h) probably need to be increased");
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000166
167 assert(StaticDiagInfo[i-1] < StaticDiagInfo[i] &&
168 "Improperly sorted diag info");
169 }
170 IsFirst = false;
171 }
172#endif
173
174 // Search the diagnostic table with a binary search.
Jeffrey Yasskin7c5109b2011-08-13 05:47:04 +0000175 StaticDiagInfoRec Find = { static_cast<unsigned short>(DiagID),
Daniel Dunbar4213df32011-09-29 00:34:06 +0000176 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000177
178 const StaticDiagInfoRec *Found =
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000179 std::lower_bound(StaticDiagInfo, StaticDiagInfo + StaticDiagInfoSize, Find);
180 if (Found == StaticDiagInfo + StaticDiagInfoSize ||
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000181 Found->DiagID != DiagID)
182 return 0;
183
184 return Found;
185}
186
Daniel Dunbara5e41332011-09-29 01:52:06 +0000187static DiagnosticMappingInfo GetDefaultDiagMappingInfo(unsigned DiagID) {
188 DiagnosticMappingInfo Info = DiagnosticMappingInfo::MakeInfo(
189 diag::MAP_FATAL, /*IsUser=*/false, /*IsPragma=*/false);
Daniel Dunbar4213df32011-09-29 00:34:06 +0000190
Daniel Dunbara5e41332011-09-29 01:52:06 +0000191 if (const StaticDiagInfoRec *StaticInfo = GetDiagInfo(DiagID)) {
192 Info.setMapping((diag::Mapping) StaticInfo->Mapping);
193
194 if (StaticInfo->WarnNoWerror) {
195 assert(Info.getMapping() == diag::MAP_WARNING &&
Daniel Dunbar4213df32011-09-29 00:34:06 +0000196 "Unexpected mapping with no-Werror bit!");
Daniel Dunbara5e41332011-09-29 01:52:06 +0000197 Info.setNoWarningAsError(true);
Daniel Dunbar4213df32011-09-29 00:34:06 +0000198 }
199
Daniel Dunbara5e41332011-09-29 01:52:06 +0000200 if (StaticInfo->WarnShowInSystemHeader) {
201 assert(Info.getMapping() == diag::MAP_WARNING &&
Daniel Dunbar4213df32011-09-29 00:34:06 +0000202 "Unexpected mapping with show-in-system-header bit!");
Daniel Dunbara5e41332011-09-29 01:52:06 +0000203 Info.setShowInSystemHeader(true);
Daniel Dunbar4213df32011-09-29 00:34:06 +0000204 }
Daniel Dunbar4213df32011-09-29 00:34:06 +0000205 }
Daniel Dunbara5e41332011-09-29 01:52:06 +0000206
207 return Info;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000208}
209
210/// getWarningOptionForDiag - Return the lowest-level warning option that
211/// enables the specified diagnostic. If there is no -Wfoo flag that controls
212/// the diagnostic, this returns null.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000213StringRef DiagnosticIDs::getWarningOptionForDiag(unsigned DiagID) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000214 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000215 return Info->getOptionGroup();
Chris Lattner5f9e2722011-07-23 10:55:15 +0000216 return StringRef();
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000217}
218
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000219/// getCategoryNumberForDiag - Return the category number that a specified
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000220/// DiagID belongs to, or 0 if no category.
221unsigned DiagnosticIDs::getCategoryNumberForDiag(unsigned DiagID) {
222 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
223 return Info->Category;
224 return 0;
225}
226
Benjamin Kramerdbda5132011-06-13 18:38:45 +0000227namespace {
228 // The diagnostic category names.
229 struct StaticDiagCategoryRec {
230 const char *NameStr;
231 uint8_t NameLen;
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000232
Chris Lattner5f9e2722011-07-23 10:55:15 +0000233 StringRef getName() const {
234 return StringRef(NameStr, NameLen);
Benjamin Kramerdbda5132011-06-13 18:38:45 +0000235 }
236 };
237}
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000238
Daniel Dunbarba494c62011-09-29 01:42:25 +0000239// Unfortunately, the split between DiagnosticIDs and Diagnostic is not
240// particularly clean, but for now we just implement this method here so we can
241// access GetDefaultDiagMapping.
242DiagnosticMappingInfo &DiagnosticsEngine::DiagState::getOrAddMappingInfo(
243 diag::kind Diag)
244{
245 std::pair<iterator, bool> Result = DiagMap.insert(
246 std::make_pair(Diag, DiagnosticMappingInfo::MakeUnset()));
247
248 // Initialize the entry if we added it.
249 if (Result.second) {
250 assert(Result.first->second.isUnset() && "unexpected unset entry");
Daniel Dunbara5e41332011-09-29 01:52:06 +0000251 Result.first->second = GetDefaultDiagMappingInfo(Diag);
Daniel Dunbarba494c62011-09-29 01:42:25 +0000252 }
253
254 return Result.first->second;
255}
256
Benjamin Kramerdbda5132011-06-13 18:38:45 +0000257static const StaticDiagCategoryRec CategoryNameTable[] = {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000258#define GET_CATEGORY_TABLE
John McCall923cd572011-06-15 21:46:43 +0000259#define CATEGORY(X, ENUM) { X, STR_SIZE(X, uint8_t) },
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000260#include "clang/Basic/DiagnosticGroups.inc"
261#undef GET_CATEGORY_TABLE
262 { 0, 0 }
263};
264
265/// getNumberOfCategories - Return the number of categories
266unsigned DiagnosticIDs::getNumberOfCategories() {
267 return sizeof(CategoryNameTable) / sizeof(CategoryNameTable[0])-1;
268}
269
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000270/// getCategoryNameFromID - Given a category ID, return the name of the
271/// category, an empty string if CategoryID is zero, or null if CategoryID is
272/// invalid.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000273StringRef DiagnosticIDs::getCategoryNameFromID(unsigned CategoryID) {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000274 if (CategoryID >= getNumberOfCategories())
Chris Lattner5f9e2722011-07-23 10:55:15 +0000275 return StringRef();
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000276 return CategoryNameTable[CategoryID].getName();
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000277}
278
279
280
281DiagnosticIDs::SFINAEResponse
282DiagnosticIDs::getDiagnosticSFINAEResponse(unsigned DiagID) {
283 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) {
Douglas Gregor418df342011-01-27 21:06:28 +0000284 if (Info->AccessControl)
285 return SFINAE_AccessControl;
286
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000287 if (!Info->SFINAE)
288 return SFINAE_Report;
289
290 if (Info->Class == CLASS_ERROR)
291 return SFINAE_SubstitutionFailure;
292
293 // Suppress notes, warnings, and extensions;
294 return SFINAE_Suppress;
295 }
296
297 return SFINAE_Report;
298}
299
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000300/// getName - Given a diagnostic ID, return its name
Chris Lattner5f9e2722011-07-23 10:55:15 +0000301StringRef DiagnosticIDs::getName(unsigned DiagID) {
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000302 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000303 return Info->getName();
Chris Lattner5f9e2722011-07-23 10:55:15 +0000304 return StringRef();
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000305}
306
307/// getIdFromName - Given a diagnostic name, return its ID, or 0
Chris Lattner5f9e2722011-07-23 10:55:15 +0000308unsigned DiagnosticIDs::getIdFromName(StringRef Name) {
Benjamin Kramer81f9d142011-06-14 13:15:38 +0000309 const StaticDiagNameIndexRec *StaticDiagNameIndexEnd =
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000310 StaticDiagNameIndex + StaticDiagNameIndexSize;
311
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000312 if (Name.empty()) { return diag::DIAG_UPPER_LIMIT; }
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000313
Jeffrey Yasskin7c5109b2011-08-13 05:47:04 +0000314 assert(Name.size() == static_cast<uint8_t>(Name.size()) &&
315 "Name is too long");
316 StaticDiagNameIndexRec Find = { Name.data(), 0,
317 static_cast<uint8_t>(Name.size()) };
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000318
319 const StaticDiagNameIndexRec *Found =
320 std::lower_bound( StaticDiagNameIndex, StaticDiagNameIndexEnd, Find);
321 if (Found == StaticDiagNameIndexEnd ||
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000322 Found->getName() != Name)
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000323 return diag::DIAG_UPPER_LIMIT;
324
325 return Found->DiagID;
326}
327
328/// getBriefExplanation - Given a diagnostic ID, return a brief explanation
329/// of the issue
Chris Lattner5f9e2722011-07-23 10:55:15 +0000330StringRef DiagnosticIDs::getBriefExplanation(unsigned DiagID) {
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000331 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000332 return Info->getBriefExplanation();
Chris Lattner5f9e2722011-07-23 10:55:15 +0000333 return StringRef();
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000334}
335
336/// getFullExplanation - Given a diagnostic ID, return a full explanation
337/// of the issue
Chris Lattner5f9e2722011-07-23 10:55:15 +0000338StringRef DiagnosticIDs::getFullExplanation(unsigned DiagID) {
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000339 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000340 return Info->getFullExplanation();
Chris Lattner5f9e2722011-07-23 10:55:15 +0000341 return StringRef();
Douglas Gregor7d2b8c12011-04-15 22:04:17 +0000342}
343
344/// getBuiltinDiagClass - Return the class field of the diagnostic.
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000345///
346static unsigned getBuiltinDiagClass(unsigned DiagID) {
347 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
348 return Info->Class;
349 return ~0U;
350}
351
352//===----------------------------------------------------------------------===//
Ted Kremenek6948bc42011-08-09 03:39:14 +0000353// diag_iterator
354//===----------------------------------------------------------------------===//
355
356llvm::StringRef DiagnosticIDs::diag_iterator::getDiagName() const {
357 return static_cast<const StaticDiagNameIndexRec*>(impl)->getName();
358}
359
360unsigned DiagnosticIDs::diag_iterator::getDiagID() const {
361 return static_cast<const StaticDiagNameIndexRec*>(impl)->DiagID;
362}
363
364DiagnosticIDs::diag_iterator &DiagnosticIDs::diag_iterator::operator++() {
365 const StaticDiagNameIndexRec* ptr =
366 static_cast<const StaticDiagNameIndexRec*>(impl);;
367 ++ptr;
368 impl = ptr;
369 return *this;
370}
371
372DiagnosticIDs::diag_iterator DiagnosticIDs::diags_begin() {
373 return DiagnosticIDs::diag_iterator(StaticDiagNameIndex);
374}
375
376DiagnosticIDs::diag_iterator DiagnosticIDs::diags_end() {
377 return DiagnosticIDs::diag_iterator(StaticDiagNameIndex +
378 StaticDiagNameIndexSize);
379}
380
381//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000382// Custom Diagnostic information
383//===----------------------------------------------------------------------===//
384
385namespace clang {
386 namespace diag {
387 class CustomDiagInfo {
388 typedef std::pair<DiagnosticIDs::Level, std::string> DiagDesc;
389 std::vector<DiagDesc> DiagInfo;
390 std::map<DiagDesc, unsigned> DiagIDs;
391 public:
392
393 /// getDescription - Return the description of the specified custom
394 /// diagnostic.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000395 StringRef getDescription(unsigned DiagID) const {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000396 assert(this && DiagID-DIAG_UPPER_LIMIT < DiagInfo.size() &&
397 "Invalid diagnosic ID");
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000398 return DiagInfo[DiagID-DIAG_UPPER_LIMIT].second;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000399 }
400
401 /// getLevel - Return the level of the specified custom diagnostic.
402 DiagnosticIDs::Level getLevel(unsigned DiagID) const {
403 assert(this && DiagID-DIAG_UPPER_LIMIT < DiagInfo.size() &&
404 "Invalid diagnosic ID");
405 return DiagInfo[DiagID-DIAG_UPPER_LIMIT].first;
406 }
407
Chris Lattner5f9e2722011-07-23 10:55:15 +0000408 unsigned getOrCreateDiagID(DiagnosticIDs::Level L, StringRef Message,
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000409 DiagnosticIDs &Diags) {
410 DiagDesc D(L, Message);
411 // Check to see if it already exists.
412 std::map<DiagDesc, unsigned>::iterator I = DiagIDs.lower_bound(D);
413 if (I != DiagIDs.end() && I->first == D)
414 return I->second;
415
416 // If not, assign a new ID.
417 unsigned ID = DiagInfo.size()+DIAG_UPPER_LIMIT;
418 DiagIDs.insert(std::make_pair(D, ID));
419 DiagInfo.push_back(D);
420 return ID;
421 }
422 };
423
424 } // end diag namespace
425} // end clang namespace
426
427
428//===----------------------------------------------------------------------===//
429// Common Diagnostic implementation
430//===----------------------------------------------------------------------===//
431
432DiagnosticIDs::DiagnosticIDs() {
433 CustomDiagInfo = 0;
434}
435
436DiagnosticIDs::~DiagnosticIDs() {
437 delete CustomDiagInfo;
438}
439
440/// getCustomDiagID - Return an ID for a diagnostic with the specified message
441/// and level. If this is the first request for this diagnosic, it is
442/// registered and created, otherwise the existing ID is returned.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000443unsigned DiagnosticIDs::getCustomDiagID(Level L, StringRef Message) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000444 if (CustomDiagInfo == 0)
445 CustomDiagInfo = new diag::CustomDiagInfo();
446 return CustomDiagInfo->getOrCreateDiagID(L, Message, *this);
447}
448
449
450/// isBuiltinWarningOrExtension - Return true if the unmapped diagnostic
451/// level of the specified diagnostic ID is a Warning or Extension.
452/// This only works on builtin diagnostics, not custom ones, and is not legal to
453/// call on NOTEs.
454bool DiagnosticIDs::isBuiltinWarningOrExtension(unsigned DiagID) {
455 return DiagID < diag::DIAG_UPPER_LIMIT &&
456 getBuiltinDiagClass(DiagID) != CLASS_ERROR;
457}
458
459/// \brief Determine whether the given built-in diagnostic ID is a
460/// Note.
461bool DiagnosticIDs::isBuiltinNote(unsigned DiagID) {
462 return DiagID < diag::DIAG_UPPER_LIMIT &&
463 getBuiltinDiagClass(DiagID) == CLASS_NOTE;
464}
465
466/// isBuiltinExtensionDiag - Determine whether the given built-in diagnostic
467/// ID is for an extension of some sort. This also returns EnabledByDefault,
468/// which is set to indicate whether the diagnostic is ignored by default (in
469/// which case -pedantic enables it) or treated as a warning/error by default.
470///
471bool DiagnosticIDs::isBuiltinExtensionDiag(unsigned DiagID,
472 bool &EnabledByDefault) {
473 if (DiagID >= diag::DIAG_UPPER_LIMIT ||
474 getBuiltinDiagClass(DiagID) != CLASS_EXTENSION)
475 return false;
476
Daniel Dunbara5e41332011-09-29 01:52:06 +0000477 EnabledByDefault =
478 GetDefaultDiagMappingInfo(DiagID).getMapping() != diag::MAP_IGNORE;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000479 return true;
480}
481
Daniel Dunbar76101cf2011-09-29 01:01:08 +0000482bool DiagnosticIDs::isDefaultMappingAsError(unsigned DiagID) {
483 if (DiagID >= diag::DIAG_UPPER_LIMIT)
484 return false;
485
Daniel Dunbara5e41332011-09-29 01:52:06 +0000486 return GetDefaultDiagMappingInfo(DiagID).getMapping() == diag::MAP_ERROR;
Daniel Dunbar76101cf2011-09-29 01:01:08 +0000487}
488
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000489/// getDescription - Given a diagnostic ID, return a description of the
490/// issue.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000491StringRef DiagnosticIDs::getDescription(unsigned DiagID) const {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000492 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000493 return Info->getDescription();
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000494 return CustomDiagInfo->getDescription(DiagID);
495}
496
David Blaikied6471f72011-09-25 23:23:43 +0000497/// getDiagnosticLevel - Based on the way the client configured the
498/// DiagnosticsEngine object, classify the specified diagnostic ID into a Level,
499/// by consumable the DiagnosticClient.
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000500DiagnosticIDs::Level
501DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, SourceLocation Loc,
Daniel Dunbar1656aae2011-09-29 01:20:28 +0000502 const DiagnosticsEngine &Diag) const {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000503 // Handle custom diagnostics, which cannot be mapped.
504 if (DiagID >= diag::DIAG_UPPER_LIMIT)
505 return CustomDiagInfo->getLevel(DiagID);
506
507 unsigned DiagClass = getBuiltinDiagClass(DiagID);
508 assert(DiagClass != CLASS_NOTE && "Cannot get diagnostic level of a note!");
Daniel Dunbar1656aae2011-09-29 01:20:28 +0000509 return getDiagnosticLevel(DiagID, DiagClass, Loc, Diag);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000510}
511
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000512/// \brief Based on the way the client configured the Diagnostic
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000513/// object, classify the specified diagnostic ID into a Level, consumable by
514/// the DiagnosticClient.
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000515///
516/// \param Loc The source location we are interested in finding out the
517/// diagnostic state. Can be null in order to query the latest state.
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000518DiagnosticIDs::Level
519DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass,
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000520 SourceLocation Loc,
Daniel Dunbar1656aae2011-09-29 01:20:28 +0000521 const DiagnosticsEngine &Diag) const {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000522 // Specific non-error diagnostics may be mapped to various levels from ignored
523 // to error. Errors can only be mapped to fatal.
524 DiagnosticIDs::Level Result = DiagnosticIDs::Fatal;
525
David Blaikied6471f72011-09-25 23:23:43 +0000526 DiagnosticsEngine::DiagStatePointsTy::iterator
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000527 Pos = Diag.GetDiagStatePointForLoc(Loc);
David Blaikied6471f72011-09-25 23:23:43 +0000528 DiagnosticsEngine::DiagState *State = Pos->State;
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000529
Daniel Dunbarba494c62011-09-29 01:42:25 +0000530 // Get the mapping information, or compute it lazily.
531 DiagnosticMappingInfo &MappingInfo = State->getOrAddMappingInfo(
532 (diag::kind)DiagID);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000533
Daniel Dunbarb1c99c62011-09-29 01:30:00 +0000534 switch (MappingInfo.getMapping()) {
David Blaikieb219cfc2011-09-23 05:06:16 +0000535 default: llvm_unreachable("Unknown mapping!");
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000536 case diag::MAP_IGNORE:
Daniel Dunbarbe1aa412011-09-29 01:58:05 +0000537 Result = DiagnosticIDs::Ignored;
538 break;
539 case diag::MAP_WARNING:
540 Result = DiagnosticIDs::Warning;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000541 break;
542 case diag::MAP_ERROR:
543 Result = DiagnosticIDs::Error;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000544 break;
545 case diag::MAP_FATAL:
546 Result = DiagnosticIDs::Fatal;
547 break;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000548 }
549
Daniel Dunbarbe1aa412011-09-29 01:58:05 +0000550 // Upgrade ignored diagnostics if -Weverything is enabled.
551 if (Diag.EnableAllWarnings && Result == DiagnosticIDs::Ignored &&
552 !MappingInfo.isUser())
553 Result = DiagnosticIDs::Warning;
554
555 // Ignore any kind of extension diagnostics inside __extension__ blocks.
556 bool IsExtensionDiag = isBuiltinExtensionDiag(DiagID);
557 if (Diag.AllExtensionsSilenced && IsExtensionDiag)
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000558 return DiagnosticIDs::Ignored;
559
Daniel Dunbarbe1aa412011-09-29 01:58:05 +0000560 // For extension diagnostics that haven't been explicitly mapped, check if we
561 // should upgrade the diagnostic.
562 if (IsExtensionDiag && !MappingInfo.isUser()) {
563 switch (Diag.ExtBehavior) {
564 case DiagnosticsEngine::Ext_Ignore:
565 break;
566 case DiagnosticsEngine::Ext_Warn:
567 // Upgrade ignored diagnostics to warnings.
568 if (Result == DiagnosticIDs::Ignored)
569 Result = DiagnosticIDs::Warning;
570 break;
571 case DiagnosticsEngine::Ext_Error:
572 // Upgrade ignored or warning diagnostics to errors.
573 if (Result == DiagnosticIDs::Ignored || Result == DiagnosticIDs::Warning)
574 Result = DiagnosticIDs::Error;
575 break;
576 }
577 }
578
579 // At this point, ignored errors can no longer be upgraded.
580 if (Result == DiagnosticIDs::Ignored)
581 return Result;
582
583 // Honor -w, which is lower in priority than pedantic-errors, but higher than
584 // -Werror.
585 if (Result == DiagnosticIDs::Warning && Diag.IgnoreAllWarnings)
586 return DiagnosticIDs::Ignored;
587
588 // If -Werror is enabled, map warnings to errors unless explicitly disabled.
589 if (Result == DiagnosticIDs::Warning) {
590 if (Diag.WarningsAsErrors && !MappingInfo.hasNoWarningAsError())
591 Result = DiagnosticIDs::Error;
592 }
593
594 // If -Wfatal-errors is enabled, map errors to fatal unless explicity
595 // disabled.
596 if (Result == DiagnosticIDs::Error) {
597 if (Diag.ErrorsAsFatal && !MappingInfo.hasNoErrorAsFatal())
598 Result = DiagnosticIDs::Fatal;
599 }
600
Argyrios Kyrtzidiscfdadfe2011-04-21 23:08:18 +0000601 // If we are in a system header, we ignore it.
602 // We also want to ignore extensions and warnings in -Werror and
603 // -pedantic-errors modes, which *map* warnings/extensions to errors.
604 if (Result >= DiagnosticIDs::Warning &&
605 DiagClass != CLASS_ERROR &&
606 // Custom diagnostics always are emitted in system headers.
607 DiagID < diag::DIAG_UPPER_LIMIT &&
Daniel Dunbarbe1aa412011-09-29 01:58:05 +0000608 !MappingInfo.hasShowInSystemHeader() &&
Argyrios Kyrtzidiscfdadfe2011-04-21 23:08:18 +0000609 Diag.SuppressSystemWarnings &&
610 Loc.isValid() &&
611 Diag.getSourceManager().isInSystemHeader(
Chandler Carruth40278532011-07-25 16:49:02 +0000612 Diag.getSourceManager().getExpansionLoc(Loc)))
Argyrios Kyrtzidiscfdadfe2011-04-21 23:08:18 +0000613 return DiagnosticIDs::Ignored;
614
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000615 return Result;
616}
617
Daniel Dunbar3f839462011-09-29 01:47:16 +0000618struct clang::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
Daniel Dunbar3f839462011-09-29 01:47:16 +0000627 StringRef getName() const {
628 return StringRef(NameStr, NameLen);
629 }
630};
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000631
632#define GET_DIAG_ARRAYS
633#include "clang/Basic/DiagnosticGroups.inc"
634#undef GET_DIAG_ARRAYS
635
636// Second the table of options, sorted by name for fast binary lookup.
637static const WarningOption OptionTable[] = {
638#define GET_DIAG_TABLE
639#include "clang/Basic/DiagnosticGroups.inc"
640#undef GET_DIAG_TABLE
641};
642static const size_t OptionTableSize =
643sizeof(OptionTable) / sizeof(OptionTable[0]);
644
645static bool WarningOptionCompare(const WarningOption &LHS,
646 const WarningOption &RHS) {
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000647 return LHS.getName() < RHS.getName();
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000648}
649
Daniel Dunbar3f839462011-09-29 01:47:16 +0000650void DiagnosticIDs::getDiagnosticsInGroup(
651 const WarningOption *Group,
652 llvm::SmallVectorImpl<diag::kind> &Diags) const
653{
654 // Add the members of the option diagnostic set.
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000655 if (const short *Member = Group->Members) {
656 for (; *Member != -1; ++Member)
Daniel Dunbar3f839462011-09-29 01:47:16 +0000657 Diags.push_back(*Member);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000658 }
659
Daniel Dunbar3f839462011-09-29 01:47:16 +0000660 // Add the members of the subgroups.
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000661 if (const short *SubGroups = Group->SubGroups) {
662 for (; *SubGroups != (short)-1; ++SubGroups)
Daniel Dunbar3f839462011-09-29 01:47:16 +0000663 getDiagnosticsInGroup(&OptionTable[(short)*SubGroups], Diags);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000664 }
665}
666
Daniel Dunbar3f839462011-09-29 01:47:16 +0000667bool DiagnosticIDs::getDiagnosticsInGroup(
668 StringRef Group,
669 llvm::SmallVectorImpl<diag::kind> &Diags) const
670{
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000671 WarningOption Key = { Group.size(), Group.data(), 0, 0 };
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000672 const WarningOption *Found =
673 std::lower_bound(OptionTable, OptionTable + OptionTableSize, Key,
674 WarningOptionCompare);
675 if (Found == OptionTable + OptionTableSize ||
Argyrios Kyrtzidis477aab62011-05-25 05:05:01 +0000676 Found->getName() != Group)
Daniel Dunbar3f839462011-09-29 01:47:16 +0000677 return true; // Option not found.
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000678
Daniel Dunbar3f839462011-09-29 01:47:16 +0000679 getDiagnosticsInGroup(Found, Diags);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000680 return false;
681}
682
683/// ProcessDiag - This is the method used to report a diagnostic that is
684/// finally fully formed.
David Blaikied6471f72011-09-25 23:23:43 +0000685bool DiagnosticIDs::ProcessDiag(DiagnosticsEngine &Diag) const {
David Blaikie40847cf2011-09-26 01:18:08 +0000686 Diagnostic Info(&Diag);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000687
688 if (Diag.SuppressAllDiagnostics)
689 return false;
690
691 assert(Diag.getClient() && "DiagnosticClient not set!");
692
693 // Figure out the diagnostic level of this message.
694 DiagnosticIDs::Level DiagLevel;
695 unsigned DiagID = Info.getID();
696
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000697 if (DiagID >= diag::DIAG_UPPER_LIMIT) {
698 // Handle custom diagnostics, which cannot be mapped.
699 DiagLevel = CustomDiagInfo->getLevel(DiagID);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000700 } else {
701 // Get the class of the diagnostic. If this is a NOTE, map it onto whatever
702 // the diagnostic level was for the previous diagnostic so that it is
703 // filtered the same as the previous diagnostic.
704 unsigned DiagClass = getBuiltinDiagClass(DiagID);
705 if (DiagClass == CLASS_NOTE) {
706 DiagLevel = DiagnosticIDs::Note;
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000707 } else {
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000708 DiagLevel = getDiagnosticLevel(DiagID, DiagClass, Info.getLocation(),
709 Diag);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000710 }
711 }
712
713 if (DiagLevel != DiagnosticIDs::Note) {
714 // Record that a fatal error occurred only when we see a second
715 // non-note diagnostic. This allows notes to be attached to the
716 // fatal error, but suppresses any diagnostics that follow those
717 // notes.
718 if (Diag.LastDiagLevel == DiagnosticIDs::Fatal)
719 Diag.FatalErrorOccurred = true;
720
721 Diag.LastDiagLevel = DiagLevel;
722 }
723
Argyrios Kyrtzidisc0a575f2011-07-29 01:25:44 +0000724 // Update counts for DiagnosticErrorTrap even if a fatal error occurred.
725 if (DiagLevel >= DiagnosticIDs::Error) {
726 ++Diag.TrapNumErrorsOccurred;
727 if (isUnrecoverable(DiagID))
728 ++Diag.TrapNumUnrecoverableErrorsOccurred;
729 }
730
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000731 // If a fatal error has already been emitted, silence all subsequent
732 // diagnostics.
733 if (Diag.FatalErrorOccurred) {
734 if (DiagLevel >= DiagnosticIDs::Error &&
735 Diag.Client->IncludeInDiagnosticCounts()) {
736 ++Diag.NumErrors;
737 ++Diag.NumErrorsSuppressed;
738 }
739
740 return false;
741 }
742
743 // If the client doesn't care about this message, don't issue it. If this is
744 // a note and the last real diagnostic was ignored, ignore it too.
745 if (DiagLevel == DiagnosticIDs::Ignored ||
746 (DiagLevel == DiagnosticIDs::Note &&
747 Diag.LastDiagLevel == DiagnosticIDs::Ignored))
748 return false;
749
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000750 if (DiagLevel >= DiagnosticIDs::Error) {
Argyrios Kyrtzidisc0a575f2011-07-29 01:25:44 +0000751 if (isUnrecoverable(DiagID))
Douglas Gregor85bea972011-07-06 17:40:26 +0000752 Diag.UnrecoverableErrorOccurred = true;
Douglas Gregor85bea972011-07-06 17:40:26 +0000753
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000754 if (Diag.Client->IncludeInDiagnosticCounts()) {
755 Diag.ErrorOccurred = true;
756 ++Diag.NumErrors;
757 }
758
Douglas Gregorf1d59482011-08-17 19:13:00 +0000759 // If we've emitted a lot of errors, emit a fatal error instead of it to
760 // stop a flood of bogus errors.
761 if (Diag.ErrorLimit && Diag.NumErrors > Diag.ErrorLimit &&
762 DiagLevel == DiagnosticIDs::Error) {
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000763 Diag.SetDelayedDiagnostic(diag::fatal_too_many_errors);
Douglas Gregorf1d59482011-08-17 19:13:00 +0000764 return false;
765 }
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000766 }
767
Douglas Gregor4814fb52011-02-03 23:41:12 +0000768 // If we have any Fix-Its, make sure that all of the Fix-Its point into
Chandler Carruth3201f382011-07-26 05:17:23 +0000769 // source locations that aren't macro expansions. If any point into macro
770 // expansions, remove all of the Fix-Its.
Douglas Gregor4814fb52011-02-03 23:41:12 +0000771 for (unsigned I = 0, N = Diag.NumFixItHints; I != N; ++I) {
772 const FixItHint &FixIt = Diag.FixItHints[I];
773 if (FixIt.RemoveRange.isInvalid() ||
774 FixIt.RemoveRange.getBegin().isMacroID() ||
775 FixIt.RemoveRange.getEnd().isMacroID()) {
776 Diag.NumFixItHints = 0;
777 break;
778 }
779 }
780
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000781 // Finally, report it.
David Blaikied6471f72011-09-25 23:23:43 +0000782 Diag.Client->HandleDiagnostic((DiagnosticsEngine::Level)DiagLevel, Info);
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000783 if (Diag.Client->IncludeInDiagnosticCounts()) {
784 if (DiagLevel == DiagnosticIDs::Warning)
785 ++Diag.NumWarnings;
786 }
787
788 Diag.CurDiagID = ~0U;
789
790 return true;
791}
John McCall923cd572011-06-15 21:46:43 +0000792
793bool DiagnosticIDs::isUnrecoverable(unsigned DiagID) const {
794 if (DiagID >= diag::DIAG_UPPER_LIMIT) {
795 // Custom diagnostics.
796 return CustomDiagInfo->getLevel(DiagID) >= DiagnosticIDs::Error;
797 }
798
799 // Only errors may be unrecoverable.
Douglas Gregor85bea972011-07-06 17:40:26 +0000800 if (getBuiltinDiagClass(DiagID) < CLASS_ERROR)
John McCall923cd572011-06-15 21:46:43 +0000801 return false;
802
803 if (DiagID == diag::err_unavailable ||
804 DiagID == diag::err_unavailable_message)
805 return false;
806
John McCallf85e1932011-06-15 23:02:42 +0000807 // Currently we consider all ARC errors as recoverable.
808 if (getCategoryNumberForDiag(DiagID) ==
809 diag::DiagCat_Automatic_Reference_Counting_Issue)
810 return false;
811
John McCall923cd572011-06-15 21:46:43 +0000812 return true;
813}