blob: 3d8bbd0ef0dd2537502d3591ccf6a2cd0351969a [file] [log] [blame]
Argyrios Kyrtzidisd0040642010-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
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +000014#include "clang/Basic/DiagnosticIDs.h"
David Blaikieaf90ec12012-02-15 21:58:34 +000015#include "clang/Basic/AllDiagnostics.h"
John McCalla877d922011-06-15 21:46:43 +000016#include "clang/Basic/DiagnosticCategories.h"
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +000017#include "clang/Basic/SourceManager.h"
David Majnemer38af2a22013-07-20 07:15:15 +000018#include "llvm/ADT/STLExtras.h"
Chandler Carruth5553d0d2014-01-07 11:51:46 +000019#include "llvm/ADT/SmallVector.h"
David Blaikie76bd3c82011-09-23 05:35:21 +000020#include "llvm/Support/ErrorHandling.h"
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +000021#include <map>
22using namespace clang;
23
24//===----------------------------------------------------------------------===//
25// Builtin Diagnostic information
26//===----------------------------------------------------------------------===//
27
28namespace {
29
30// Diagnostic classes.
31enum {
32 CLASS_NOTE = 0x01,
Tobias Grosser74160242014-02-28 09:11:08 +000033 CLASS_REMARK = 0x02,
34 CLASS_WARNING = 0x03,
35 CLASS_EXTENSION = 0x04,
36 CLASS_ERROR = 0x05
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +000037};
38
39struct StaticDiagInfoRec {
Craig Topperea6caba2013-07-21 21:56:18 +000040 uint16_t DiagID;
Alp Tokerc726c362014-06-10 09:31:37 +000041 unsigned DefaultSeverity : 3;
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +000042 unsigned Class : 3;
Richard Smith16e1b072013-11-12 02:41:45 +000043 unsigned SFINAE : 2;
Daniel Dunbar6de48ee2011-09-29 00:34:06 +000044 unsigned WarnNoWerror : 1;
45 unsigned WarnShowInSystemHeader : 1;
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +000046 unsigned Category : 5;
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +000047
Benjamin Kramera8cafe22012-02-15 20:57:03 +000048 uint16_t OptionGroupIndex;
Argyrios Kyrtzidis0e37afa2011-05-25 05:05:01 +000049
50 uint16_t DescriptionLen;
Argyrios Kyrtzidis0e37afa2011-05-25 05:05:01 +000051 const char *DescriptionStr;
Argyrios Kyrtzidis0e37afa2011-05-25 05:05:01 +000052
Benjamin Kramera8cafe22012-02-15 20:57:03 +000053 unsigned getOptionGroupIndex() const {
54 return OptionGroupIndex;
Argyrios Kyrtzidis0e37afa2011-05-25 05:05:01 +000055 }
56
Chris Lattner0e62c1c2011-07-23 10:55:15 +000057 StringRef getDescription() const {
58 return StringRef(DescriptionStr, DescriptionLen);
Argyrios Kyrtzidis0e37afa2011-05-25 05:05:01 +000059 }
Douglas Gregor46ce91a2011-04-15 22:04:17 +000060
Richard Smith3be1cb22014-08-07 00:24:21 +000061 diag::Flavor getFlavor() const {
62 return Class == CLASS_REMARK ? diag::Flavor::Remark
63 : diag::Flavor::WarningOrError;
64 }
65
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +000066 bool operator<(const StaticDiagInfoRec &RHS) const {
67 return DiagID < RHS.DiagID;
68 }
69};
70
Alexander Kornienkoab9db512015-06-22 23:07:51 +000071} // namespace anonymous
Argyrios Kyrtzidis0e37afa2011-05-25 05:05:01 +000072
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +000073static const StaticDiagInfoRec StaticDiagInfo[] = {
Alp Tokerc726c362014-06-10 09:31:37 +000074#define DIAG(ENUM, CLASS, DEFAULT_SEVERITY, DESC, GROUP, SFINAE, NOWERROR, \
75 SHOWINSYSHEADER, CATEGORY) \
76 { \
77 diag::ENUM, DEFAULT_SEVERITY, CLASS, DiagnosticIDs::SFINAE, NOWERROR, \
78 SHOWINSYSHEADER, CATEGORY, GROUP, STR_SIZE(DESC, uint16_t), DESC \
79 } \
80 ,
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +000081#include "clang/Basic/DiagnosticCommonKinds.inc"
82#include "clang/Basic/DiagnosticDriverKinds.inc"
83#include "clang/Basic/DiagnosticFrontendKinds.inc"
Chandler Carruth22a11b72011-12-09 00:02:23 +000084#include "clang/Basic/DiagnosticSerializationKinds.inc"
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +000085#include "clang/Basic/DiagnosticLexKinds.inc"
86#include "clang/Basic/DiagnosticParseKinds.inc"
87#include "clang/Basic/DiagnosticASTKinds.inc"
Dmitri Gribenkof26054f2012-07-11 21:38:39 +000088#include "clang/Basic/DiagnosticCommentKinds.inc"
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +000089#include "clang/Basic/DiagnosticSemaKinds.inc"
90#include "clang/Basic/DiagnosticAnalysisKinds.inc"
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +000091#undef DIAG
Douglas Gregor46ce91a2011-04-15 22:04:17 +000092};
93
David Majnemer38af2a22013-07-20 07:15:15 +000094static const unsigned StaticDiagInfoSize = llvm::array_lengthof(StaticDiagInfo);
Douglas Gregor46ce91a2011-04-15 22:04:17 +000095
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +000096/// GetDiagInfo - Return the StaticDiagInfoRec entry for the specified DiagID,
97/// or null if the ID is invalid.
98static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) {
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +000099 // If assertions are enabled, verify that the StaticDiagInfo array is sorted.
100#ifndef NDEBUG
Craig Topper31e71a32013-07-21 18:58:40 +0000101 static bool IsFirst = true; // So the check is only performed on first call.
102 if (IsFirst) {
103 for (unsigned i = 1; i != StaticDiagInfoSize; ++i) {
Richard Barton8c11bcf2015-10-16 20:15:29 +0000104 assert(StaticDiagInfo[i-1] < StaticDiagInfo[i] &&
Craig Topper31e71a32013-07-21 18:58:40 +0000105 "Diag ID conflict, the enums at the start of clang::diag (in "
106 "DiagnosticIDs.h) probably need to be increased");
Craig Topper31e71a32013-07-21 18:58:40 +0000107 }
108 IsFirst = false;
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000109 }
110#endif
111
Benjamin Kramer256f1dd2012-12-11 18:00:22 +0000112 // Out of bounds diag. Can't be in the table.
113 using namespace diag;
David Majnemer38af2a22013-07-20 07:15:15 +0000114 if (DiagID >= DIAG_UPPER_LIMIT || DiagID <= DIAG_START_COMMON)
Craig Topperf1186c52014-05-08 06:41:40 +0000115 return nullptr;
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000116
Benjamin Kramer256f1dd2012-12-11 18:00:22 +0000117 // Compute the index of the requested diagnostic in the static table.
Alp Tokerf6a24ce2013-12-05 16:25:25 +0000118 // 1. Add the number of diagnostics in each category preceding the
Benjamin Kramer256f1dd2012-12-11 18:00:22 +0000119 // diagnostic and of the category the diagnostic is in. This gives us
120 // the offset of the category in the table.
121 // 2. Subtract the number of IDs in each category from our ID. This gives us
122 // the offset of the diagnostic in the category.
123 // This is cheaper than a binary search on the table as it doesn't touch
124 // memory at all.
125 unsigned Offset = 0;
David Majnemer38af2a22013-07-20 07:15:15 +0000126 unsigned ID = DiagID - DIAG_START_COMMON - 1;
Benjamin Kramer256f1dd2012-12-11 18:00:22 +0000127#define CATEGORY(NAME, PREV) \
128 if (DiagID > DIAG_START_##NAME) { \
Argyrios Kyrtzidisf86e8cc2013-01-02 22:26:07 +0000129 Offset += NUM_BUILTIN_##PREV##_DIAGNOSTICS - DIAG_START_##PREV - 1; \
130 ID -= DIAG_START_##NAME - DIAG_START_##PREV; \
Benjamin Kramer256f1dd2012-12-11 18:00:22 +0000131 }
132CATEGORY(DRIVER, COMMON)
133CATEGORY(FRONTEND, DRIVER)
134CATEGORY(SERIALIZATION, FRONTEND)
135CATEGORY(LEX, SERIALIZATION)
136CATEGORY(PARSE, LEX)
137CATEGORY(AST, PARSE)
138CATEGORY(COMMENT, AST)
139CATEGORY(SEMA, COMMENT)
140CATEGORY(ANALYSIS, SEMA)
141#undef CATEGORY
Benjamin Kramer256f1dd2012-12-11 18:00:22 +0000142
143 // Avoid out of bounds reads.
144 if (ID + Offset >= StaticDiagInfoSize)
Craig Topperf1186c52014-05-08 06:41:40 +0000145 return nullptr;
Benjamin Kramer256f1dd2012-12-11 18:00:22 +0000146
Argyrios Kyrtzidisf86e8cc2013-01-02 22:26:07 +0000147 assert(ID < StaticDiagInfoSize && Offset < StaticDiagInfoSize);
148
Benjamin Kramer256f1dd2012-12-11 18:00:22 +0000149 const StaticDiagInfoRec *Found = &StaticDiagInfo[ID + Offset];
150 // If the diag id doesn't match we found a different diag, abort. This can
151 // happen when this function is called with an ID that points into a hole in
152 // the diagID space.
153 if (Found->DiagID != DiagID)
Craig Topperf1186c52014-05-08 06:41:40 +0000154 return nullptr;
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000155 return Found;
156}
157
Alp Tokerc726c362014-06-10 09:31:37 +0000158static DiagnosticMapping GetDefaultDiagMapping(unsigned DiagID) {
159 DiagnosticMapping Info = DiagnosticMapping::Make(
Alp Toker46df1c02014-06-12 10:15:20 +0000160 diag::Severity::Fatal, /*IsUser=*/false, /*IsPragma=*/false);
Daniel Dunbar6de48ee2011-09-29 00:34:06 +0000161
Daniel Dunbarfffcf212011-09-29 01:52:06 +0000162 if (const StaticDiagInfoRec *StaticInfo = GetDiagInfo(DiagID)) {
Alp Tokerc726c362014-06-10 09:31:37 +0000163 Info.setSeverity((diag::Severity)StaticInfo->DefaultSeverity);
Daniel Dunbarfffcf212011-09-29 01:52:06 +0000164
165 if (StaticInfo->WarnNoWerror) {
Alp Toker46df1c02014-06-12 10:15:20 +0000166 assert(Info.getSeverity() == diag::Severity::Warning &&
Daniel Dunbar6de48ee2011-09-29 00:34:06 +0000167 "Unexpected mapping with no-Werror bit!");
Daniel Dunbarfffcf212011-09-29 01:52:06 +0000168 Info.setNoWarningAsError(true);
Daniel Dunbar6de48ee2011-09-29 00:34:06 +0000169 }
Daniel Dunbar6de48ee2011-09-29 00:34:06 +0000170 }
Daniel Dunbarfffcf212011-09-29 01:52:06 +0000171
172 return Info;
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000173}
174
Douglas Gregor46ce91a2011-04-15 22:04:17 +0000175/// getCategoryNumberForDiag - Return the category number that a specified
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000176/// DiagID belongs to, or 0 if no category.
177unsigned DiagnosticIDs::getCategoryNumberForDiag(unsigned DiagID) {
178 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
179 return Info->Category;
180 return 0;
181}
182
Benjamin Kramerdc0a46d2011-06-13 18:38:45 +0000183namespace {
184 // The diagnostic category names.
185 struct StaticDiagCategoryRec {
186 const char *NameStr;
187 uint8_t NameLen;
Argyrios Kyrtzidis0e37afa2011-05-25 05:05:01 +0000188
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000189 StringRef getName() const {
190 return StringRef(NameStr, NameLen);
Benjamin Kramerdc0a46d2011-06-13 18:38:45 +0000191 }
192 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000193}
Argyrios Kyrtzidis0e37afa2011-05-25 05:05:01 +0000194
Daniel Dunbare8c12a22011-09-29 01:42:25 +0000195// Unfortunately, the split between DiagnosticIDs and Diagnostic is not
196// particularly clean, but for now we just implement this method here so we can
197// access GetDefaultDiagMapping.
Alp Tokerc726c362014-06-10 09:31:37 +0000198DiagnosticMapping &
199DiagnosticsEngine::DiagState::getOrAddMapping(diag::kind Diag) {
200 std::pair<iterator, bool> Result =
201 DiagMap.insert(std::make_pair(Diag, DiagnosticMapping()));
Daniel Dunbare8c12a22011-09-29 01:42:25 +0000202
203 // Initialize the entry if we added it.
Daniel Dunbar866fcd32011-09-29 02:03:01 +0000204 if (Result.second)
Alp Tokerc726c362014-06-10 09:31:37 +0000205 Result.first->second = GetDefaultDiagMapping(Diag);
Daniel Dunbare8c12a22011-09-29 01:42:25 +0000206
207 return Result.first->second;
208}
209
Benjamin Kramerdc0a46d2011-06-13 18:38:45 +0000210static const StaticDiagCategoryRec CategoryNameTable[] = {
Argyrios Kyrtzidis0e37afa2011-05-25 05:05:01 +0000211#define GET_CATEGORY_TABLE
John McCalla877d922011-06-15 21:46:43 +0000212#define CATEGORY(X, ENUM) { X, STR_SIZE(X, uint8_t) },
Argyrios Kyrtzidis0e37afa2011-05-25 05:05:01 +0000213#include "clang/Basic/DiagnosticGroups.inc"
214#undef GET_CATEGORY_TABLE
Craig Topperf1186c52014-05-08 06:41:40 +0000215 { nullptr, 0 }
Argyrios Kyrtzidis0e37afa2011-05-25 05:05:01 +0000216};
217
218/// getNumberOfCategories - Return the number of categories
219unsigned DiagnosticIDs::getNumberOfCategories() {
Craig Toppere5ce8312013-07-15 03:38:40 +0000220 return llvm::array_lengthof(CategoryNameTable) - 1;
Argyrios Kyrtzidis0e37afa2011-05-25 05:05:01 +0000221}
222
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000223/// getCategoryNameFromID - Given a category ID, return the name of the
224/// category, an empty string if CategoryID is zero, or null if CategoryID is
225/// invalid.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000226StringRef DiagnosticIDs::getCategoryNameFromID(unsigned CategoryID) {
Argyrios Kyrtzidis0e37afa2011-05-25 05:05:01 +0000227 if (CategoryID >= getNumberOfCategories())
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000228 return StringRef();
Argyrios Kyrtzidis0e37afa2011-05-25 05:05:01 +0000229 return CategoryNameTable[CategoryID].getName();
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000230}
231
232
233
Richard Smith16e1b072013-11-12 02:41:45 +0000234DiagnosticIDs::SFINAEResponse
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000235DiagnosticIDs::getDiagnosticSFINAEResponse(unsigned DiagID) {
Richard Smith16e1b072013-11-12 02:41:45 +0000236 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
237 return static_cast<DiagnosticIDs::SFINAEResponse>(Info->SFINAE);
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000238 return SFINAE_Report;
239}
240
Douglas Gregor46ce91a2011-04-15 22:04:17 +0000241/// getBuiltinDiagClass - Return the class field of the diagnostic.
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000242///
243static unsigned getBuiltinDiagClass(unsigned DiagID) {
244 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
245 return Info->Class;
246 return ~0U;
247}
248
249//===----------------------------------------------------------------------===//
250// Custom Diagnostic information
251//===----------------------------------------------------------------------===//
252
253namespace clang {
254 namespace diag {
255 class CustomDiagInfo {
256 typedef std::pair<DiagnosticIDs::Level, std::string> DiagDesc;
257 std::vector<DiagDesc> DiagInfo;
258 std::map<DiagDesc, unsigned> DiagIDs;
259 public:
260
261 /// getDescription - Return the description of the specified custom
262 /// diagnostic.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000263 StringRef getDescription(unsigned DiagID) const {
Richard Trieu428058f2014-08-01 01:42:01 +0000264 assert(DiagID - DIAG_UPPER_LIMIT < DiagInfo.size() &&
Stefanus Du Toitb3318502013-03-01 21:41:22 +0000265 "Invalid diagnostic ID");
Argyrios Kyrtzidis0e37afa2011-05-25 05:05:01 +0000266 return DiagInfo[DiagID-DIAG_UPPER_LIMIT].second;
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000267 }
268
269 /// getLevel - Return the level of the specified custom diagnostic.
270 DiagnosticIDs::Level getLevel(unsigned DiagID) const {
Richard Trieu428058f2014-08-01 01:42:01 +0000271 assert(DiagID - DIAG_UPPER_LIMIT < DiagInfo.size() &&
Stefanus Du Toitb3318502013-03-01 21:41:22 +0000272 "Invalid diagnostic ID");
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000273 return DiagInfo[DiagID-DIAG_UPPER_LIMIT].first;
274 }
275
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000276 unsigned getOrCreateDiagID(DiagnosticIDs::Level L, StringRef Message,
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000277 DiagnosticIDs &Diags) {
278 DiagDesc D(L, Message);
279 // Check to see if it already exists.
280 std::map<DiagDesc, unsigned>::iterator I = DiagIDs.lower_bound(D);
281 if (I != DiagIDs.end() && I->first == D)
282 return I->second;
283
284 // If not, assign a new ID.
285 unsigned ID = DiagInfo.size()+DIAG_UPPER_LIMIT;
286 DiagIDs.insert(std::make_pair(D, ID));
287 DiagInfo.push_back(D);
288 return ID;
289 }
290 };
291
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000292 } // end diag namespace
293} // end clang namespace
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000294
295
296//===----------------------------------------------------------------------===//
297// Common Diagnostic implementation
298//===----------------------------------------------------------------------===//
299
Craig Topperf1186c52014-05-08 06:41:40 +0000300DiagnosticIDs::DiagnosticIDs() { CustomDiagInfo = nullptr; }
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000301
302DiagnosticIDs::~DiagnosticIDs() {
303 delete CustomDiagInfo;
304}
305
306/// getCustomDiagID - Return an ID for a diagnostic with the specified message
Stefanus Du Toitb3318502013-03-01 21:41:22 +0000307/// and level. If this is the first request for this diagnostic, it is
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000308/// registered and created, otherwise the existing ID is returned.
Alp Toker61d41af2013-12-23 21:00:35 +0000309///
Alp Toker9e6d27d2014-01-26 06:41:58 +0000310/// \param FormatString A fixed diagnostic format string that will be hashed and
Alp Toker61d41af2013-12-23 21:00:35 +0000311/// mapped to a unique DiagID.
Alp Toker9e6d27d2014-01-26 06:41:58 +0000312unsigned DiagnosticIDs::getCustomDiagID(Level L, StringRef FormatString) {
Craig Topperf1186c52014-05-08 06:41:40 +0000313 if (!CustomDiagInfo)
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000314 CustomDiagInfo = new diag::CustomDiagInfo();
Alp Toker9e6d27d2014-01-26 06:41:58 +0000315 return CustomDiagInfo->getOrCreateDiagID(L, FormatString, *this);
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000316}
317
318
319/// isBuiltinWarningOrExtension - Return true if the unmapped diagnostic
320/// level of the specified diagnostic ID is a Warning or Extension.
321/// This only works on builtin diagnostics, not custom ones, and is not legal to
322/// call on NOTEs.
323bool DiagnosticIDs::isBuiltinWarningOrExtension(unsigned DiagID) {
324 return DiagID < diag::DIAG_UPPER_LIMIT &&
325 getBuiltinDiagClass(DiagID) != CLASS_ERROR;
326}
327
328/// \brief Determine whether the given built-in diagnostic ID is a
329/// Note.
330bool DiagnosticIDs::isBuiltinNote(unsigned DiagID) {
331 return DiagID < diag::DIAG_UPPER_LIMIT &&
332 getBuiltinDiagClass(DiagID) == CLASS_NOTE;
333}
334
335/// isBuiltinExtensionDiag - Determine whether the given built-in diagnostic
336/// ID is for an extension of some sort. This also returns EnabledByDefault,
337/// which is set to indicate whether the diagnostic is ignored by default (in
338/// which case -pedantic enables it) or treated as a warning/error by default.
339///
340bool DiagnosticIDs::isBuiltinExtensionDiag(unsigned DiagID,
341 bool &EnabledByDefault) {
342 if (DiagID >= diag::DIAG_UPPER_LIMIT ||
343 getBuiltinDiagClass(DiagID) != CLASS_EXTENSION)
344 return false;
Alp Tokerc726c362014-06-10 09:31:37 +0000345
Daniel Dunbarfffcf212011-09-29 01:52:06 +0000346 EnabledByDefault =
Alp Toker46df1c02014-06-12 10:15:20 +0000347 GetDefaultDiagMapping(DiagID).getSeverity() != diag::Severity::Ignored;
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000348 return true;
349}
350
Daniel Dunbaraa111382011-09-29 01:01:08 +0000351bool DiagnosticIDs::isDefaultMappingAsError(unsigned DiagID) {
352 if (DiagID >= diag::DIAG_UPPER_LIMIT)
353 return false;
354
Alp Toker46df1c02014-06-12 10:15:20 +0000355 return GetDefaultDiagMapping(DiagID).getSeverity() == diag::Severity::Error;
Daniel Dunbaraa111382011-09-29 01:01:08 +0000356}
357
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000358/// getDescription - Given a diagnostic ID, return a description of the
359/// issue.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000360StringRef DiagnosticIDs::getDescription(unsigned DiagID) const {
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000361 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
Argyrios Kyrtzidis0e37afa2011-05-25 05:05:01 +0000362 return Info->getDescription();
Richard Trieu428058f2014-08-01 01:42:01 +0000363 assert(CustomDiagInfo && "Invalid CustomDiagInfo");
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000364 return CustomDiagInfo->getDescription(DiagID);
365}
366
Alp Toker46df1c02014-06-12 10:15:20 +0000367static DiagnosticIDs::Level toLevel(diag::Severity SV) {
368 switch (SV) {
369 case diag::Severity::Ignored:
370 return DiagnosticIDs::Ignored;
371 case diag::Severity::Remark:
372 return DiagnosticIDs::Remark;
373 case diag::Severity::Warning:
374 return DiagnosticIDs::Warning;
375 case diag::Severity::Error:
376 return DiagnosticIDs::Error;
377 case diag::Severity::Fatal:
378 return DiagnosticIDs::Fatal;
379 }
Saleem Abdulrasoolfbfbaf62014-06-12 19:33:26 +0000380 llvm_unreachable("unexpected severity");
Alp Toker46df1c02014-06-12 10:15:20 +0000381}
382
David Blaikie9c902b52011-09-25 23:23:43 +0000383/// getDiagnosticLevel - Based on the way the client configured the
384/// DiagnosticsEngine object, classify the specified diagnostic ID into a Level,
385/// by consumable the DiagnosticClient.
Argyrios Kyrtzidis1cb0de12010-12-15 18:44:22 +0000386DiagnosticIDs::Level
387DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, SourceLocation Loc,
Daniel Dunbar400e7e32011-09-29 01:20:28 +0000388 const DiagnosticsEngine &Diag) const {
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000389 // Handle custom diagnostics, which cannot be mapped.
Richard Trieu428058f2014-08-01 01:42:01 +0000390 if (DiagID >= diag::DIAG_UPPER_LIMIT) {
391 assert(CustomDiagInfo && "Invalid CustomDiagInfo");
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000392 return CustomDiagInfo->getLevel(DiagID);
Richard Trieu428058f2014-08-01 01:42:01 +0000393 }
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000394
395 unsigned DiagClass = getBuiltinDiagClass(DiagID);
Jordan Rose6f524ac2012-07-11 16:50:36 +0000396 if (DiagClass == CLASS_NOTE) return DiagnosticIDs::Note;
Alp Toker04278ec2014-06-16 13:56:47 +0000397 return toLevel(getDiagnosticSeverity(DiagID, Loc, Diag));
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000398}
399
Argyrios Kyrtzidis1cb0de12010-12-15 18:44:22 +0000400/// \brief Based on the way the client configured the Diagnostic
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000401/// object, classify the specified diagnostic ID into a Level, consumable by
402/// the DiagnosticClient.
Argyrios Kyrtzidis1cb0de12010-12-15 18:44:22 +0000403///
404/// \param Loc The source location we are interested in finding out the
405/// diagnostic state. Can be null in order to query the latest state.
Alp Toker46df1c02014-06-12 10:15:20 +0000406diag::Severity
Alp Toker04278ec2014-06-16 13:56:47 +0000407DiagnosticIDs::getDiagnosticSeverity(unsigned DiagID, SourceLocation Loc,
Alp Toker46df1c02014-06-12 10:15:20 +0000408 const DiagnosticsEngine &Diag) const {
Alp Toker04278ec2014-06-16 13:56:47 +0000409 assert(getBuiltinDiagClass(DiagID) != CLASS_NOTE);
Alp Toker46df1c02014-06-12 10:15:20 +0000410
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000411 // Specific non-error diagnostics may be mapped to various levels from ignored
412 // to error. Errors can only be mapped to fatal.
Alp Toker46df1c02014-06-12 10:15:20 +0000413 diag::Severity Result = diag::Severity::Fatal;
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000414
David Blaikie9c902b52011-09-25 23:23:43 +0000415 DiagnosticsEngine::DiagStatePointsTy::iterator
Argyrios Kyrtzidis1cb0de12010-12-15 18:44:22 +0000416 Pos = Diag.GetDiagStatePointForLoc(Loc);
David Blaikie9c902b52011-09-25 23:23:43 +0000417 DiagnosticsEngine::DiagState *State = Pos->State;
Argyrios Kyrtzidis1cb0de12010-12-15 18:44:22 +0000418
Daniel Dunbare8c12a22011-09-29 01:42:25 +0000419 // Get the mapping information, or compute it lazily.
Alp Tokerc726c362014-06-10 09:31:37 +0000420 DiagnosticMapping &Mapping = State->getOrAddMapping((diag::kind)DiagID);
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000421
Alp Toker46df1c02014-06-12 10:15:20 +0000422 // TODO: Can a null severity really get here?
423 if (Mapping.getSeverity() != diag::Severity())
424 Result = Mapping.getSeverity();
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000425
Daniel Dunbar58d0af62011-09-29 01:58:05 +0000426 // Upgrade ignored diagnostics if -Weverything is enabled.
Alp Toker46df1c02014-06-12 10:15:20 +0000427 if (Diag.EnableAllWarnings && Result == diag::Severity::Ignored &&
Richard Smithe423ed32014-08-21 20:44:44 +0000428 !Mapping.isUser() && getBuiltinDiagClass(DiagID) != CLASS_REMARK)
Alp Toker46df1c02014-06-12 10:15:20 +0000429 Result = diag::Severity::Warning;
Daniel Dunbar58d0af62011-09-29 01:58:05 +0000430
Bob Wilson73a4deb2011-10-12 19:55:31 +0000431 // Ignore -pedantic diagnostics inside __extension__ blocks.
432 // (The diagnostics controlled by -pedantic are the extension diagnostics
433 // that are not enabled by default.)
Daniel Dunbar787032b2011-11-28 22:19:36 +0000434 bool EnabledByDefault = false;
Bob Wilson73a4deb2011-10-12 19:55:31 +0000435 bool IsExtensionDiag = isBuiltinExtensionDiag(DiagID, EnabledByDefault);
436 if (Diag.AllExtensionsSilenced && IsExtensionDiag && !EnabledByDefault)
Alp Toker46df1c02014-06-12 10:15:20 +0000437 return diag::Severity::Ignored;
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000438
Daniel Dunbar58d0af62011-09-29 01:58:05 +0000439 // For extension diagnostics that haven't been explicitly mapped, check if we
440 // should upgrade the diagnostic.
Alp Tokerac4e8e52014-06-22 21:58:33 +0000441 if (IsExtensionDiag && !Mapping.isUser())
442 Result = std::max(Result, Diag.ExtBehavior);
Daniel Dunbar58d0af62011-09-29 01:58:05 +0000443
444 // At this point, ignored errors can no longer be upgraded.
Alp Toker46df1c02014-06-12 10:15:20 +0000445 if (Result == diag::Severity::Ignored)
Daniel Dunbar58d0af62011-09-29 01:58:05 +0000446 return Result;
447
448 // Honor -w, which is lower in priority than pedantic-errors, but higher than
449 // -Werror.
Alp Toker46df1c02014-06-12 10:15:20 +0000450 if (Result == diag::Severity::Warning && Diag.IgnoreAllWarnings)
451 return diag::Severity::Ignored;
Daniel Dunbar58d0af62011-09-29 01:58:05 +0000452
453 // If -Werror is enabled, map warnings to errors unless explicitly disabled.
Alp Toker46df1c02014-06-12 10:15:20 +0000454 if (Result == diag::Severity::Warning) {
Alp Tokerc726c362014-06-10 09:31:37 +0000455 if (Diag.WarningsAsErrors && !Mapping.hasNoWarningAsError())
Alp Toker46df1c02014-06-12 10:15:20 +0000456 Result = diag::Severity::Error;
Daniel Dunbar58d0af62011-09-29 01:58:05 +0000457 }
458
459 // If -Wfatal-errors is enabled, map errors to fatal unless explicity
460 // disabled.
Alp Toker46df1c02014-06-12 10:15:20 +0000461 if (Result == diag::Severity::Error) {
Alp Tokerc726c362014-06-10 09:31:37 +0000462 if (Diag.ErrorsAsFatal && !Mapping.hasNoErrorAsFatal())
Alp Toker46df1c02014-06-12 10:15:20 +0000463 Result = diag::Severity::Fatal;
Daniel Dunbar58d0af62011-09-29 01:58:05 +0000464 }
465
Alp Tokered2c0332014-06-10 06:09:00 +0000466 // Custom diagnostics always are emitted in system headers.
467 bool ShowInSystemHeader =
468 !GetDiagInfo(DiagID) || GetDiagInfo(DiagID)->WarnShowInSystemHeader;
469
Daniel Dunbar866fcd32011-09-29 02:03:01 +0000470 // If we are in a system header, we ignore it. We look at the diagnostic class
471 // because we also want to ignore extensions and warnings in -Werror and
Argyrios Kyrtzidis8a8b8772011-04-21 23:08:18 +0000472 // -pedantic-errors modes, which *map* warnings/extensions to errors.
Alp Toker04278ec2014-06-16 13:56:47 +0000473 if (Diag.SuppressSystemWarnings && !ShowInSystemHeader && Loc.isValid() &&
Argyrios Kyrtzidis8a8b8772011-04-21 23:08:18 +0000474 Diag.getSourceManager().isInSystemHeader(
Chandler Carruth35f53202011-07-25 16:49:02 +0000475 Diag.getSourceManager().getExpansionLoc(Loc)))
Alp Toker46df1c02014-06-12 10:15:20 +0000476 return diag::Severity::Ignored;
Argyrios Kyrtzidis8a8b8772011-04-21 23:08:18 +0000477
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000478 return Result;
479}
480
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000481#define GET_DIAG_ARRAYS
482#include "clang/Basic/DiagnosticGroups.inc"
483#undef GET_DIAG_ARRAYS
484
Craig Topperb78e9d92013-08-29 06:06:18 +0000485namespace {
486 struct WarningOption {
487 uint16_t NameOffset;
488 uint16_t Members;
489 uint16_t SubGroups;
Craig Topperda7cf8a2013-08-29 05:18:04 +0000490
Craig Topperb78e9d92013-08-29 06:06:18 +0000491 // String is stored with a pascal-style length byte.
492 StringRef getName() const {
493 return StringRef(DiagGroupNames + NameOffset + 1,
494 DiagGroupNames[NameOffset]);
495 }
496 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000497}
Craig Topperda7cf8a2013-08-29 05:18:04 +0000498
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000499// Second the table of options, sorted by name for fast binary lookup.
500static const WarningOption OptionTable[] = {
501#define GET_DIAG_TABLE
502#include "clang/Basic/DiagnosticGroups.inc"
503#undef GET_DIAG_TABLE
504};
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000505
Craig Topperda7cf8a2013-08-29 05:18:04 +0000506static bool WarningOptionCompare(const WarningOption &LHS, StringRef RHS) {
507 return LHS.getName() < RHS;
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000508}
509
Benjamin Kramera8cafe22012-02-15 20:57:03 +0000510/// getWarningOptionForDiag - Return the lowest-level warning option that
511/// enables the specified diagnostic. If there is no -Wfoo flag that controls
512/// the diagnostic, this returns null.
513StringRef DiagnosticIDs::getWarningOptionForDiag(unsigned DiagID) {
514 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
515 return OptionTable[Info->getOptionGroupIndex()].getName();
516 return StringRef();
517}
518
Richard Smith3be1cb22014-08-07 00:24:21 +0000519/// Return \c true if any diagnostics were found in this group, even if they
520/// were filtered out due to having the wrong flavor.
521static bool getDiagnosticsInGroup(diag::Flavor Flavor,
522 const WarningOption *Group,
Craig Topperb78e9d92013-08-29 06:06:18 +0000523 SmallVectorImpl<diag::kind> &Diags) {
Richard Smith3be1cb22014-08-07 00:24:21 +0000524 // An empty group is considered to be a warning group: we have empty groups
525 // for GCC compatibility, and GCC does not have remarks.
526 if (!Group->Members && !Group->SubGroups)
David Blaikie7a3cbb22015-03-09 02:02:07 +0000527 return Flavor == diag::Flavor::Remark;
Richard Smith3be1cb22014-08-07 00:24:21 +0000528
529 bool NotFound = true;
530
Daniel Dunbard908c122011-09-29 01:47:16 +0000531 // Add the members of the option diagnostic set.
Craig Topperd80c17e2013-08-28 04:02:50 +0000532 const int16_t *Member = DiagArrays + Group->Members;
Richard Smith3be1cb22014-08-07 00:24:21 +0000533 for (; *Member != -1; ++Member) {
534 if (GetDiagInfo(*Member)->getFlavor() == Flavor) {
535 NotFound = false;
536 Diags.push_back(*Member);
537 }
538 }
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000539
Daniel Dunbard908c122011-09-29 01:47:16 +0000540 // Add the members of the subgroups.
Craig Topperd80c17e2013-08-28 04:02:50 +0000541 const int16_t *SubGroups = DiagSubGroups + Group->SubGroups;
542 for (; *SubGroups != (int16_t)-1; ++SubGroups)
Richard Smith3be1cb22014-08-07 00:24:21 +0000543 NotFound &= getDiagnosticsInGroup(Flavor, &OptionTable[(short)*SubGroups],
544 Diags);
545
546 return NotFound;
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000547}
548
Richard Smith3be1cb22014-08-07 00:24:21 +0000549bool
550DiagnosticIDs::getDiagnosticsInGroup(diag::Flavor Flavor, StringRef Group,
551 SmallVectorImpl<diag::kind> &Diags) const {
Craig Topperc00e9532015-10-17 17:10:43 +0000552 const WarningOption *Found = std::lower_bound(std::begin(OptionTable),
553 std::end(OptionTable),
554 Group, WarningOptionCompare);
555 if (Found == std::end(OptionTable) || Found->getName() != Group)
Daniel Dunbard908c122011-09-29 01:47:16 +0000556 return true; // Option not found.
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000557
Richard Smith3be1cb22014-08-07 00:24:21 +0000558 return ::getDiagnosticsInGroup(Flavor, Found, Diags);
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000559}
560
Richard Smith3be1cb22014-08-07 00:24:21 +0000561void DiagnosticIDs::getAllDiagnostics(diag::Flavor Flavor,
562 SmallVectorImpl<diag::kind> &Diags) const {
Argyrios Kyrtzidis9ffada92012-01-27 06:15:43 +0000563 for (unsigned i = 0; i != StaticDiagInfoSize; ++i)
Richard Smith3be1cb22014-08-07 00:24:21 +0000564 if (StaticDiagInfo[i].getFlavor() == Flavor)
565 Diags.push_back(StaticDiagInfo[i].DiagID);
Argyrios Kyrtzidis9ffada92012-01-27 06:15:43 +0000566}
567
Richard Smith3be1cb22014-08-07 00:24:21 +0000568StringRef DiagnosticIDs::getNearestOption(diag::Flavor Flavor,
569 StringRef Group) {
Benjamin Kramer116d8872011-11-14 23:30:34 +0000570 StringRef Best;
Benjamin Kramer176a5cb2011-11-15 12:26:39 +0000571 unsigned BestDistance = Group.size() + 1; // Sanity threshold.
Craig Topperc00e9532015-10-17 17:10:43 +0000572 for (const WarningOption &O : llvm::makeArrayRef(OptionTable)) {
Benjamin Kramer116d8872011-11-14 23:30:34 +0000573 // Don't suggest ignored warning flags.
Craig Topperc00e9532015-10-17 17:10:43 +0000574 if (!O.Members && !O.SubGroups)
Benjamin Kramer116d8872011-11-14 23:30:34 +0000575 continue;
576
Craig Topperc00e9532015-10-17 17:10:43 +0000577 unsigned Distance = O.getName().edit_distance(Group, true, BestDistance);
Richard Smith3be1cb22014-08-07 00:24:21 +0000578 if (Distance > BestDistance)
579 continue;
580
581 // Don't suggest groups that are not of this kind.
582 llvm::SmallVector<diag::kind, 8> Diags;
Craig Topperc00e9532015-10-17 17:10:43 +0000583 if (::getDiagnosticsInGroup(Flavor, &O, Diags) || Diags.empty())
Richard Smith3be1cb22014-08-07 00:24:21 +0000584 continue;
585
Benjamin Kramer176a5cb2011-11-15 12:26:39 +0000586 if (Distance == BestDistance) {
587 // Two matches with the same distance, don't prefer one over the other.
588 Best = "";
589 } else if (Distance < BestDistance) {
590 // This is a better match.
Craig Topperc00e9532015-10-17 17:10:43 +0000591 Best = O.getName();
Benjamin Kramer116d8872011-11-14 23:30:34 +0000592 BestDistance = Distance;
593 }
594 }
595
596 return Best;
597}
598
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000599/// ProcessDiag - This is the method used to report a diagnostic that is
600/// finally fully formed.
David Blaikie9c902b52011-09-25 23:23:43 +0000601bool DiagnosticIDs::ProcessDiag(DiagnosticsEngine &Diag) const {
David Blaikieb5784322011-09-26 01:18:08 +0000602 Diagnostic Info(&Diag);
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000603
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000604 assert(Diag.getClient() && "DiagnosticClient not set!");
605
606 // Figure out the diagnostic level of this message.
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000607 unsigned DiagID = Info.getID();
Jordan Rose6f524ac2012-07-11 16:50:36 +0000608 DiagnosticIDs::Level DiagLevel
609 = getDiagnosticLevel(DiagID, Info.getLocation(), Diag);
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000610
Richard Smitha2686712014-12-05 21:52:58 +0000611 // Update counts for DiagnosticErrorTrap even if a fatal error occurred
612 // or diagnostics are suppressed.
613 if (DiagLevel >= DiagnosticIDs::Error) {
614 ++Diag.TrapNumErrorsOccurred;
615 if (isUnrecoverable(DiagID))
616 ++Diag.TrapNumUnrecoverableErrorsOccurred;
617 }
618
619 if (Diag.SuppressAllDiagnostics)
620 return false;
621
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000622 if (DiagLevel != DiagnosticIDs::Note) {
623 // Record that a fatal error occurred only when we see a second
624 // non-note diagnostic. This allows notes to be attached to the
625 // fatal error, but suppresses any diagnostics that follow those
626 // notes.
627 if (Diag.LastDiagLevel == DiagnosticIDs::Fatal)
628 Diag.FatalErrorOccurred = true;
629
630 Diag.LastDiagLevel = DiagLevel;
631 }
632
633 // If a fatal error has already been emitted, silence all subsequent
634 // diagnostics.
635 if (Diag.FatalErrorOccurred) {
636 if (DiagLevel >= DiagnosticIDs::Error &&
637 Diag.Client->IncludeInDiagnosticCounts()) {
638 ++Diag.NumErrors;
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000639 }
640
641 return false;
642 }
643
644 // If the client doesn't care about this message, don't issue it. If this is
645 // a note and the last real diagnostic was ignored, ignore it too.
646 if (DiagLevel == DiagnosticIDs::Ignored ||
647 (DiagLevel == DiagnosticIDs::Note &&
648 Diag.LastDiagLevel == DiagnosticIDs::Ignored))
649 return false;
650
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000651 if (DiagLevel >= DiagnosticIDs::Error) {
Argyrios Kyrtzidis1fa8b4b2011-07-29 01:25:44 +0000652 if (isUnrecoverable(DiagID))
Douglas Gregor8a60bbe2011-07-06 17:40:26 +0000653 Diag.UnrecoverableErrorOccurred = true;
Daniel Jasperd2e6f652012-09-28 15:45:07 +0000654
DeLesley Hutchins8ecd4912012-12-07 22:53:48 +0000655 // Warnings which have been upgraded to errors do not prevent compilation.
656 if (isDefaultMappingAsError(DiagID))
657 Diag.UncompilableErrorOccurred = true;
658
Daniel Jasperd2e6f652012-09-28 15:45:07 +0000659 Diag.ErrorOccurred = true;
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000660 if (Diag.Client->IncludeInDiagnosticCounts()) {
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000661 ++Diag.NumErrors;
662 }
663
Douglas Gregor14208802011-08-17 19:13:00 +0000664 // If we've emitted a lot of errors, emit a fatal error instead of it to
665 // stop a flood of bogus errors.
666 if (Diag.ErrorLimit && Diag.NumErrors > Diag.ErrorLimit &&
667 DiagLevel == DiagnosticIDs::Error) {
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000668 Diag.SetDelayedDiagnostic(diag::fatal_too_many_errors);
Douglas Gregor14208802011-08-17 19:13:00 +0000669 return false;
670 }
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000671 }
672
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000673 // Finally, report it.
Jordan Rose6f524ac2012-07-11 16:50:36 +0000674 EmitDiag(Diag, DiagLevel);
675 return true;
676}
677
678void DiagnosticIDs::EmitDiag(DiagnosticsEngine &Diag, Level DiagLevel) const {
679 Diagnostic Info(&Diag);
680 assert(DiagLevel != DiagnosticIDs::Ignored && "Cannot emit ignored diagnostics!");
681
David Blaikie9c902b52011-09-25 23:23:43 +0000682 Diag.Client->HandleDiagnostic((DiagnosticsEngine::Level)DiagLevel, Info);
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000683 if (Diag.Client->IncludeInDiagnosticCounts()) {
684 if (DiagLevel == DiagnosticIDs::Warning)
685 ++Diag.NumWarnings;
686 }
687
688 Diag.CurDiagID = ~0U;
Argyrios Kyrtzidisd0040642010-11-18 20:06:41 +0000689}
John McCalla877d922011-06-15 21:46:43 +0000690
691bool DiagnosticIDs::isUnrecoverable(unsigned DiagID) const {
692 if (DiagID >= diag::DIAG_UPPER_LIMIT) {
Richard Trieu428058f2014-08-01 01:42:01 +0000693 assert(CustomDiagInfo && "Invalid CustomDiagInfo");
John McCalla877d922011-06-15 21:46:43 +0000694 // Custom diagnostics.
695 return CustomDiagInfo->getLevel(DiagID) >= DiagnosticIDs::Error;
696 }
697
698 // Only errors may be unrecoverable.
Douglas Gregor8a60bbe2011-07-06 17:40:26 +0000699 if (getBuiltinDiagClass(DiagID) < CLASS_ERROR)
John McCalla877d922011-06-15 21:46:43 +0000700 return false;
701
702 if (DiagID == diag::err_unavailable ||
703 DiagID == diag::err_unavailable_message)
704 return false;
705
John McCall31168b02011-06-15 23:02:42 +0000706 // Currently we consider all ARC errors as recoverable.
Ted Kremenek337c5b82011-10-20 05:07:47 +0000707 if (isARCDiagnostic(DiagID))
John McCall31168b02011-06-15 23:02:42 +0000708 return false;
709
John McCalla877d922011-06-15 21:46:43 +0000710 return true;
711}
Ted Kremenek337c5b82011-10-20 05:07:47 +0000712
713bool DiagnosticIDs::isARCDiagnostic(unsigned DiagID) {
714 unsigned cat = getCategoryNumberForDiag(DiagID);
715 return DiagnosticIDs::getCategoryNameFromID(cat).startswith("ARC ");
716}