2010-11-19 04:06:41 +08:00
|
|
|
//===--- DiagnosticIDs.cpp - Diagnostic IDs Handling ----------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the Diagnostic IDs-related interfaces.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Basic/DiagnosticIDs.h"
|
2012-02-16 05:58:34 +08:00
|
|
|
#include "clang/Basic/AllDiagnostics.h"
|
2011-06-16 05:46:43 +08:00
|
|
|
#include "clang/Basic/DiagnosticCategories.h"
|
2010-11-19 04:06:41 +08:00
|
|
|
#include "clang/Basic/SourceManager.h"
|
2013-07-20 15:15:15 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2014-01-07 19:51:46 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2011-09-23 13:35:21 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-11-19 04:06:41 +08:00
|
|
|
#include <map>
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Builtin Diagnostic information
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Diagnostic classes.
|
|
|
|
enum {
|
|
|
|
CLASS_NOTE = 0x01,
|
2014-02-28 17:11:08 +08:00
|
|
|
CLASS_REMARK = 0x02,
|
|
|
|
CLASS_WARNING = 0x03,
|
|
|
|
CLASS_EXTENSION = 0x04,
|
|
|
|
CLASS_ERROR = 0x05
|
2010-11-19 04:06:41 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct StaticDiagInfoRec {
|
2013-07-22 05:56:18 +08:00
|
|
|
uint16_t DiagID;
|
2014-06-10 17:31:37 +08:00
|
|
|
unsigned DefaultSeverity : 3;
|
2010-11-19 04:06:41 +08:00
|
|
|
unsigned Class : 3;
|
2013-11-12 10:41:45 +08:00
|
|
|
unsigned SFINAE : 2;
|
2011-09-29 08:34:06 +08:00
|
|
|
unsigned WarnNoWerror : 1;
|
|
|
|
unsigned WarnShowInSystemHeader : 1;
|
2010-11-19 04:06:41 +08:00
|
|
|
unsigned Category : 5;
|
|
|
|
|
2012-02-16 04:57:03 +08:00
|
|
|
uint16_t OptionGroupIndex;
|
2011-05-25 13:05:01 +08:00
|
|
|
|
|
|
|
uint16_t DescriptionLen;
|
|
|
|
const char *DescriptionStr;
|
|
|
|
|
2012-02-16 04:57:03 +08:00
|
|
|
unsigned getOptionGroupIndex() const {
|
|
|
|
return OptionGroupIndex;
|
2011-05-25 13:05:01 +08:00
|
|
|
}
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef getDescription() const {
|
|
|
|
return StringRef(DescriptionStr, DescriptionLen);
|
2011-05-25 13:05:01 +08:00
|
|
|
}
|
2011-04-16 06:04:17 +08:00
|
|
|
|
Use -Rblah, not -Wblah, to control remark diagnostics. This was always the
intent when we added remark support, but was never implemented in the general
case, because the first -R flags didn't need it. (-Rpass= had special handling
to accomodate its argument.)
-Rno-foo, -Reverything, and -Rno-everything can be used to turn off a remark,
or to turn on or off all remarks. Per discussion on cfe-commits, -Weverything
does not affect remarks, and -Reverything does not affect warnings or errors.
The only "real" -R flag we have right now is -Rmodule-build; that flag is
effectively renamed from -Wmodule-build to -Rmodule-build by this change.
-Wpass and -Wno-pass (and their friends) are also renamed to -Rpass and
-Rno-pass by this change; it's not completely clear whether we intended to have
a -Rpass (with no =pattern), but that is unchanged by this commit, other than
the flag name. The default pattern is effectively one which matches no passes.
In future, we may want to make the default pattern be .*, so that -Reverything
works for -Rpass properly.
llvm-svn: 215046
2014-08-07 08:24:21 +08:00
|
|
|
diag::Flavor getFlavor() const {
|
|
|
|
return Class == CLASS_REMARK ? diag::Flavor::Remark
|
|
|
|
: diag::Flavor::WarningOrError;
|
|
|
|
}
|
|
|
|
|
2010-11-19 04:06:41 +08:00
|
|
|
bool operator<(const StaticDiagInfoRec &RHS) const {
|
|
|
|
return DiagID < RHS.DiagID;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-05-25 13:05:01 +08:00
|
|
|
} // namespace anonymous
|
|
|
|
|
2010-11-19 04:06:41 +08:00
|
|
|
static const StaticDiagInfoRec StaticDiagInfo[] = {
|
2014-06-10 17:31:37 +08:00
|
|
|
#define DIAG(ENUM, CLASS, DEFAULT_SEVERITY, DESC, GROUP, SFINAE, NOWERROR, \
|
|
|
|
SHOWINSYSHEADER, CATEGORY) \
|
|
|
|
{ \
|
|
|
|
diag::ENUM, DEFAULT_SEVERITY, CLASS, DiagnosticIDs::SFINAE, NOWERROR, \
|
|
|
|
SHOWINSYSHEADER, CATEGORY, GROUP, STR_SIZE(DESC, uint16_t), DESC \
|
|
|
|
} \
|
|
|
|
,
|
2010-11-19 04:06:41 +08:00
|
|
|
#include "clang/Basic/DiagnosticCommonKinds.inc"
|
|
|
|
#include "clang/Basic/DiagnosticDriverKinds.inc"
|
|
|
|
#include "clang/Basic/DiagnosticFrontendKinds.inc"
|
2011-12-09 08:02:23 +08:00
|
|
|
#include "clang/Basic/DiagnosticSerializationKinds.inc"
|
2010-11-19 04:06:41 +08:00
|
|
|
#include "clang/Basic/DiagnosticLexKinds.inc"
|
|
|
|
#include "clang/Basic/DiagnosticParseKinds.inc"
|
|
|
|
#include "clang/Basic/DiagnosticASTKinds.inc"
|
2012-07-12 05:38:39 +08:00
|
|
|
#include "clang/Basic/DiagnosticCommentKinds.inc"
|
2010-11-19 04:06:41 +08:00
|
|
|
#include "clang/Basic/DiagnosticSemaKinds.inc"
|
|
|
|
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
|
|
|
|
#undef DIAG
|
2011-04-16 06:04:17 +08:00
|
|
|
};
|
|
|
|
|
2013-07-20 15:15:15 +08:00
|
|
|
static const unsigned StaticDiagInfoSize = llvm::array_lengthof(StaticDiagInfo);
|
2011-04-16 06:04:17 +08:00
|
|
|
|
2010-11-19 04:06:41 +08:00
|
|
|
/// GetDiagInfo - Return the StaticDiagInfoRec entry for the specified DiagID,
|
|
|
|
/// or null if the ID is invalid.
|
|
|
|
static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) {
|
|
|
|
// If assertions are enabled, verify that the StaticDiagInfo array is sorted.
|
|
|
|
#ifndef NDEBUG
|
2013-07-22 02:58:40 +08:00
|
|
|
static bool IsFirst = true; // So the check is only performed on first call.
|
|
|
|
if (IsFirst) {
|
|
|
|
for (unsigned i = 1; i != StaticDiagInfoSize; ++i) {
|
|
|
|
assert(StaticDiagInfo[i-1].DiagID != StaticDiagInfo[i].DiagID &&
|
|
|
|
"Diag ID conflict, the enums at the start of clang::diag (in "
|
|
|
|
"DiagnosticIDs.h) probably need to be increased");
|
|
|
|
|
|
|
|
assert(StaticDiagInfo[i-1] < StaticDiagInfo[i] &&
|
|
|
|
"Improperly sorted diag info");
|
|
|
|
}
|
|
|
|
IsFirst = false;
|
2010-11-19 04:06:41 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-12-12 02:00:22 +08:00
|
|
|
// Out of bounds diag. Can't be in the table.
|
|
|
|
using namespace diag;
|
2013-07-20 15:15:15 +08:00
|
|
|
if (DiagID >= DIAG_UPPER_LIMIT || DiagID <= DIAG_START_COMMON)
|
2014-05-08 14:41:40 +08:00
|
|
|
return nullptr;
|
2010-11-19 04:06:41 +08:00
|
|
|
|
2012-12-12 02:00:22 +08:00
|
|
|
// Compute the index of the requested diagnostic in the static table.
|
2013-12-06 00:25:25 +08:00
|
|
|
// 1. Add the number of diagnostics in each category preceding the
|
2012-12-12 02:00:22 +08:00
|
|
|
// diagnostic and of the category the diagnostic is in. This gives us
|
|
|
|
// the offset of the category in the table.
|
|
|
|
// 2. Subtract the number of IDs in each category from our ID. This gives us
|
|
|
|
// the offset of the diagnostic in the category.
|
|
|
|
// This is cheaper than a binary search on the table as it doesn't touch
|
|
|
|
// memory at all.
|
|
|
|
unsigned Offset = 0;
|
2013-07-20 15:15:15 +08:00
|
|
|
unsigned ID = DiagID - DIAG_START_COMMON - 1;
|
2012-12-12 02:00:22 +08:00
|
|
|
#define CATEGORY(NAME, PREV) \
|
|
|
|
if (DiagID > DIAG_START_##NAME) { \
|
2013-01-03 06:26:07 +08:00
|
|
|
Offset += NUM_BUILTIN_##PREV##_DIAGNOSTICS - DIAG_START_##PREV - 1; \
|
|
|
|
ID -= DIAG_START_##NAME - DIAG_START_##PREV; \
|
2012-12-12 02:00:22 +08:00
|
|
|
}
|
|
|
|
CATEGORY(DRIVER, COMMON)
|
|
|
|
CATEGORY(FRONTEND, DRIVER)
|
|
|
|
CATEGORY(SERIALIZATION, FRONTEND)
|
|
|
|
CATEGORY(LEX, SERIALIZATION)
|
|
|
|
CATEGORY(PARSE, LEX)
|
|
|
|
CATEGORY(AST, PARSE)
|
|
|
|
CATEGORY(COMMENT, AST)
|
|
|
|
CATEGORY(SEMA, COMMENT)
|
|
|
|
CATEGORY(ANALYSIS, SEMA)
|
|
|
|
#undef CATEGORY
|
|
|
|
|
|
|
|
// Avoid out of bounds reads.
|
|
|
|
if (ID + Offset >= StaticDiagInfoSize)
|
2014-05-08 14:41:40 +08:00
|
|
|
return nullptr;
|
2012-12-12 02:00:22 +08:00
|
|
|
|
2013-01-03 06:26:07 +08:00
|
|
|
assert(ID < StaticDiagInfoSize && Offset < StaticDiagInfoSize);
|
|
|
|
|
2012-12-12 02:00:22 +08:00
|
|
|
const StaticDiagInfoRec *Found = &StaticDiagInfo[ID + Offset];
|
|
|
|
// If the diag id doesn't match we found a different diag, abort. This can
|
|
|
|
// happen when this function is called with an ID that points into a hole in
|
|
|
|
// the diagID space.
|
|
|
|
if (Found->DiagID != DiagID)
|
2014-05-08 14:41:40 +08:00
|
|
|
return nullptr;
|
2010-11-19 04:06:41 +08:00
|
|
|
return Found;
|
|
|
|
}
|
|
|
|
|
2014-06-10 17:31:37 +08:00
|
|
|
static DiagnosticMapping GetDefaultDiagMapping(unsigned DiagID) {
|
|
|
|
DiagnosticMapping Info = DiagnosticMapping::Make(
|
2014-06-12 18:15:20 +08:00
|
|
|
diag::Severity::Fatal, /*IsUser=*/false, /*IsPragma=*/false);
|
2011-09-29 09:52:06 +08:00
|
|
|
|
|
|
|
if (const StaticDiagInfoRec *StaticInfo = GetDiagInfo(DiagID)) {
|
2014-06-10 17:31:37 +08:00
|
|
|
Info.setSeverity((diag::Severity)StaticInfo->DefaultSeverity);
|
2011-09-29 08:34:06 +08:00
|
|
|
|
2011-09-29 09:52:06 +08:00
|
|
|
if (StaticInfo->WarnNoWerror) {
|
2014-06-12 18:15:20 +08:00
|
|
|
assert(Info.getSeverity() == diag::Severity::Warning &&
|
2011-09-29 08:34:06 +08:00
|
|
|
"Unexpected mapping with no-Werror bit!");
|
2011-09-29 09:52:06 +08:00
|
|
|
Info.setNoWarningAsError(true);
|
2011-09-29 08:34:06 +08:00
|
|
|
}
|
|
|
|
}
|
2011-09-29 09:52:06 +08:00
|
|
|
|
|
|
|
return Info;
|
2010-11-19 04:06:41 +08:00
|
|
|
}
|
|
|
|
|
2011-04-16 06:04:17 +08:00
|
|
|
/// getCategoryNumberForDiag - Return the category number that a specified
|
2010-11-19 04:06:41 +08:00
|
|
|
/// DiagID belongs to, or 0 if no category.
|
|
|
|
unsigned DiagnosticIDs::getCategoryNumberForDiag(unsigned DiagID) {
|
|
|
|
if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
|
|
|
|
return Info->Category;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-06-14 02:38:45 +08:00
|
|
|
namespace {
|
|
|
|
// The diagnostic category names.
|
|
|
|
struct StaticDiagCategoryRec {
|
|
|
|
const char *NameStr;
|
|
|
|
uint8_t NameLen;
|
2011-05-25 13:05:01 +08:00
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef getName() const {
|
|
|
|
return StringRef(NameStr, NameLen);
|
2011-06-14 02:38:45 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2011-05-25 13:05:01 +08:00
|
|
|
|
2011-09-29 09:42:25 +08:00
|
|
|
// Unfortunately, the split between DiagnosticIDs and Diagnostic is not
|
|
|
|
// particularly clean, but for now we just implement this method here so we can
|
|
|
|
// access GetDefaultDiagMapping.
|
2014-06-10 17:31:37 +08:00
|
|
|
DiagnosticMapping &
|
|
|
|
DiagnosticsEngine::DiagState::getOrAddMapping(diag::kind Diag) {
|
|
|
|
std::pair<iterator, bool> Result =
|
|
|
|
DiagMap.insert(std::make_pair(Diag, DiagnosticMapping()));
|
2011-09-29 09:42:25 +08:00
|
|
|
|
|
|
|
// Initialize the entry if we added it.
|
2011-09-29 10:03:01 +08:00
|
|
|
if (Result.second)
|
2014-06-10 17:31:37 +08:00
|
|
|
Result.first->second = GetDefaultDiagMapping(Diag);
|
2011-09-29 09:42:25 +08:00
|
|
|
|
|
|
|
return Result.first->second;
|
|
|
|
}
|
|
|
|
|
2011-06-14 02:38:45 +08:00
|
|
|
static const StaticDiagCategoryRec CategoryNameTable[] = {
|
2010-11-19 04:06:41 +08:00
|
|
|
#define GET_CATEGORY_TABLE
|
2011-06-16 05:46:43 +08:00
|
|
|
#define CATEGORY(X, ENUM) { X, STR_SIZE(X, uint8_t) },
|
2010-11-19 04:06:41 +08:00
|
|
|
#include "clang/Basic/DiagnosticGroups.inc"
|
|
|
|
#undef GET_CATEGORY_TABLE
|
2014-05-08 14:41:40 +08:00
|
|
|
{ nullptr, 0 }
|
2011-05-25 13:05:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// getNumberOfCategories - Return the number of categories
|
|
|
|
unsigned DiagnosticIDs::getNumberOfCategories() {
|
2013-07-15 11:38:40 +08:00
|
|
|
return llvm::array_lengthof(CategoryNameTable) - 1;
|
2011-05-25 13:05:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getCategoryNameFromID - Given a category ID, return the name of the
|
|
|
|
/// category, an empty string if CategoryID is zero, or null if CategoryID is
|
|
|
|
/// invalid.
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef DiagnosticIDs::getCategoryNameFromID(unsigned CategoryID) {
|
2011-05-25 13:05:01 +08:00
|
|
|
if (CategoryID >= getNumberOfCategories())
|
2011-07-23 18:55:15 +08:00
|
|
|
return StringRef();
|
2011-05-25 13:05:01 +08:00
|
|
|
return CategoryNameTable[CategoryID].getName();
|
2010-11-19 04:06:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-12 10:41:45 +08:00
|
|
|
DiagnosticIDs::SFINAEResponse
|
2010-11-19 04:06:41 +08:00
|
|
|
DiagnosticIDs::getDiagnosticSFINAEResponse(unsigned DiagID) {
|
2013-11-12 10:41:45 +08:00
|
|
|
if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
|
|
|
|
return static_cast<DiagnosticIDs::SFINAEResponse>(Info->SFINAE);
|
2010-11-19 04:06:41 +08:00
|
|
|
return SFINAE_Report;
|
|
|
|
}
|
|
|
|
|
2011-04-16 06:04:17 +08:00
|
|
|
/// getBuiltinDiagClass - Return the class field of the diagnostic.
|
2010-11-19 04:06:41 +08:00
|
|
|
///
|
|
|
|
static unsigned getBuiltinDiagClass(unsigned DiagID) {
|
|
|
|
if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
|
|
|
|
return Info->Class;
|
|
|
|
return ~0U;
|
|
|
|
}
|
|
|
|
|
2011-08-09 11:39:14 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2010-11-19 04:06:41 +08:00
|
|
|
// Custom Diagnostic information
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace diag {
|
|
|
|
class CustomDiagInfo {
|
|
|
|
typedef std::pair<DiagnosticIDs::Level, std::string> DiagDesc;
|
|
|
|
std::vector<DiagDesc> DiagInfo;
|
|
|
|
std::map<DiagDesc, unsigned> DiagIDs;
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// getDescription - Return the description of the specified custom
|
|
|
|
/// diagnostic.
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef getDescription(unsigned DiagID) const {
|
2014-08-01 09:42:01 +08:00
|
|
|
assert(DiagID - DIAG_UPPER_LIMIT < DiagInfo.size() &&
|
2013-03-02 05:41:22 +08:00
|
|
|
"Invalid diagnostic ID");
|
2011-05-25 13:05:01 +08:00
|
|
|
return DiagInfo[DiagID-DIAG_UPPER_LIMIT].second;
|
2010-11-19 04:06:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getLevel - Return the level of the specified custom diagnostic.
|
|
|
|
DiagnosticIDs::Level getLevel(unsigned DiagID) const {
|
2014-08-01 09:42:01 +08:00
|
|
|
assert(DiagID - DIAG_UPPER_LIMIT < DiagInfo.size() &&
|
2013-03-02 05:41:22 +08:00
|
|
|
"Invalid diagnostic ID");
|
2010-11-19 04:06:41 +08:00
|
|
|
return DiagInfo[DiagID-DIAG_UPPER_LIMIT].first;
|
|
|
|
}
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
unsigned getOrCreateDiagID(DiagnosticIDs::Level L, StringRef Message,
|
2010-11-19 04:06:41 +08:00
|
|
|
DiagnosticIDs &Diags) {
|
|
|
|
DiagDesc D(L, Message);
|
|
|
|
// Check to see if it already exists.
|
|
|
|
std::map<DiagDesc, unsigned>::iterator I = DiagIDs.lower_bound(D);
|
|
|
|
if (I != DiagIDs.end() && I->first == D)
|
|
|
|
return I->second;
|
|
|
|
|
|
|
|
// If not, assign a new ID.
|
|
|
|
unsigned ID = DiagInfo.size()+DIAG_UPPER_LIMIT;
|
|
|
|
DiagIDs.insert(std::make_pair(D, ID));
|
|
|
|
DiagInfo.push_back(D);
|
|
|
|
return ID;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end diag namespace
|
|
|
|
} // end clang namespace
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Common Diagnostic implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-05-08 14:41:40 +08:00
|
|
|
DiagnosticIDs::DiagnosticIDs() { CustomDiagInfo = nullptr; }
|
2010-11-19 04:06:41 +08:00
|
|
|
|
|
|
|
DiagnosticIDs::~DiagnosticIDs() {
|
|
|
|
delete CustomDiagInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getCustomDiagID - Return an ID for a diagnostic with the specified message
|
2013-03-02 05:41:22 +08:00
|
|
|
/// and level. If this is the first request for this diagnostic, it is
|
2010-11-19 04:06:41 +08:00
|
|
|
/// registered and created, otherwise the existing ID is returned.
|
2013-12-24 05:00:35 +08:00
|
|
|
///
|
2014-01-26 14:41:58 +08:00
|
|
|
/// \param FormatString A fixed diagnostic format string that will be hashed and
|
2013-12-24 05:00:35 +08:00
|
|
|
/// mapped to a unique DiagID.
|
2014-01-26 14:41:58 +08:00
|
|
|
unsigned DiagnosticIDs::getCustomDiagID(Level L, StringRef FormatString) {
|
2014-05-08 14:41:40 +08:00
|
|
|
if (!CustomDiagInfo)
|
2010-11-19 04:06:41 +08:00
|
|
|
CustomDiagInfo = new diag::CustomDiagInfo();
|
2014-01-26 14:41:58 +08:00
|
|
|
return CustomDiagInfo->getOrCreateDiagID(L, FormatString, *this);
|
2010-11-19 04:06:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// isBuiltinWarningOrExtension - Return true if the unmapped diagnostic
|
|
|
|
/// level of the specified diagnostic ID is a Warning or Extension.
|
|
|
|
/// This only works on builtin diagnostics, not custom ones, and is not legal to
|
|
|
|
/// call on NOTEs.
|
|
|
|
bool DiagnosticIDs::isBuiltinWarningOrExtension(unsigned DiagID) {
|
|
|
|
return DiagID < diag::DIAG_UPPER_LIMIT &&
|
|
|
|
getBuiltinDiagClass(DiagID) != CLASS_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Determine whether the given built-in diagnostic ID is a
|
|
|
|
/// Note.
|
|
|
|
bool DiagnosticIDs::isBuiltinNote(unsigned DiagID) {
|
|
|
|
return DiagID < diag::DIAG_UPPER_LIMIT &&
|
|
|
|
getBuiltinDiagClass(DiagID) == CLASS_NOTE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// isBuiltinExtensionDiag - Determine whether the given built-in diagnostic
|
|
|
|
/// ID is for an extension of some sort. This also returns EnabledByDefault,
|
|
|
|
/// which is set to indicate whether the diagnostic is ignored by default (in
|
|
|
|
/// which case -pedantic enables it) or treated as a warning/error by default.
|
|
|
|
///
|
|
|
|
bool DiagnosticIDs::isBuiltinExtensionDiag(unsigned DiagID,
|
|
|
|
bool &EnabledByDefault) {
|
|
|
|
if (DiagID >= diag::DIAG_UPPER_LIMIT ||
|
|
|
|
getBuiltinDiagClass(DiagID) != CLASS_EXTENSION)
|
|
|
|
return false;
|
2014-06-10 17:31:37 +08:00
|
|
|
|
2011-09-29 09:52:06 +08:00
|
|
|
EnabledByDefault =
|
2014-06-12 18:15:20 +08:00
|
|
|
GetDefaultDiagMapping(DiagID).getSeverity() != diag::Severity::Ignored;
|
2010-11-19 04:06:41 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-29 09:01:08 +08:00
|
|
|
bool DiagnosticIDs::isDefaultMappingAsError(unsigned DiagID) {
|
|
|
|
if (DiagID >= diag::DIAG_UPPER_LIMIT)
|
|
|
|
return false;
|
|
|
|
|
2014-06-12 18:15:20 +08:00
|
|
|
return GetDefaultDiagMapping(DiagID).getSeverity() == diag::Severity::Error;
|
2011-09-29 09:01:08 +08:00
|
|
|
}
|
|
|
|
|
2010-11-19 04:06:41 +08:00
|
|
|
/// getDescription - Given a diagnostic ID, return a description of the
|
|
|
|
/// issue.
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef DiagnosticIDs::getDescription(unsigned DiagID) const {
|
2010-11-19 04:06:41 +08:00
|
|
|
if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
|
2011-05-25 13:05:01 +08:00
|
|
|
return Info->getDescription();
|
2014-08-01 09:42:01 +08:00
|
|
|
assert(CustomDiagInfo && "Invalid CustomDiagInfo");
|
2010-11-19 04:06:41 +08:00
|
|
|
return CustomDiagInfo->getDescription(DiagID);
|
|
|
|
}
|
|
|
|
|
2014-06-12 18:15:20 +08:00
|
|
|
static DiagnosticIDs::Level toLevel(diag::Severity SV) {
|
|
|
|
switch (SV) {
|
|
|
|
case diag::Severity::Ignored:
|
|
|
|
return DiagnosticIDs::Ignored;
|
|
|
|
case diag::Severity::Remark:
|
|
|
|
return DiagnosticIDs::Remark;
|
|
|
|
case diag::Severity::Warning:
|
|
|
|
return DiagnosticIDs::Warning;
|
|
|
|
case diag::Severity::Error:
|
|
|
|
return DiagnosticIDs::Error;
|
|
|
|
case diag::Severity::Fatal:
|
|
|
|
return DiagnosticIDs::Fatal;
|
|
|
|
}
|
2014-06-13 03:33:26 +08:00
|
|
|
llvm_unreachable("unexpected severity");
|
2014-06-12 18:15:20 +08:00
|
|
|
}
|
|
|
|
|
2011-09-26 07:23:43 +08:00
|
|
|
/// getDiagnosticLevel - Based on the way the client configured the
|
|
|
|
/// DiagnosticsEngine object, classify the specified diagnostic ID into a Level,
|
|
|
|
/// by consumable the DiagnosticClient.
|
2010-12-16 02:44:22 +08:00
|
|
|
DiagnosticIDs::Level
|
|
|
|
DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, SourceLocation Loc,
|
2011-09-29 09:20:28 +08:00
|
|
|
const DiagnosticsEngine &Diag) const {
|
2010-11-19 04:06:41 +08:00
|
|
|
// Handle custom diagnostics, which cannot be mapped.
|
2014-08-01 09:42:01 +08:00
|
|
|
if (DiagID >= diag::DIAG_UPPER_LIMIT) {
|
|
|
|
assert(CustomDiagInfo && "Invalid CustomDiagInfo");
|
2010-11-19 04:06:41 +08:00
|
|
|
return CustomDiagInfo->getLevel(DiagID);
|
2014-08-01 09:42:01 +08:00
|
|
|
}
|
2010-11-19 04:06:41 +08:00
|
|
|
|
|
|
|
unsigned DiagClass = getBuiltinDiagClass(DiagID);
|
2012-07-12 00:50:36 +08:00
|
|
|
if (DiagClass == CLASS_NOTE) return DiagnosticIDs::Note;
|
2014-06-16 21:56:47 +08:00
|
|
|
return toLevel(getDiagnosticSeverity(DiagID, Loc, Diag));
|
2010-11-19 04:06:41 +08:00
|
|
|
}
|
|
|
|
|
2010-12-16 02:44:22 +08:00
|
|
|
/// \brief Based on the way the client configured the Diagnostic
|
2010-11-19 04:06:41 +08:00
|
|
|
/// object, classify the specified diagnostic ID into a Level, consumable by
|
|
|
|
/// the DiagnosticClient.
|
2010-12-16 02:44:22 +08:00
|
|
|
///
|
|
|
|
/// \param Loc The source location we are interested in finding out the
|
|
|
|
/// diagnostic state. Can be null in order to query the latest state.
|
2014-06-12 18:15:20 +08:00
|
|
|
diag::Severity
|
2014-06-16 21:56:47 +08:00
|
|
|
DiagnosticIDs::getDiagnosticSeverity(unsigned DiagID, SourceLocation Loc,
|
2014-06-12 18:15:20 +08:00
|
|
|
const DiagnosticsEngine &Diag) const {
|
2014-06-16 21:56:47 +08:00
|
|
|
assert(getBuiltinDiagClass(DiagID) != CLASS_NOTE);
|
2014-06-12 18:15:20 +08:00
|
|
|
|
2010-11-19 04:06:41 +08:00
|
|
|
// Specific non-error diagnostics may be mapped to various levels from ignored
|
|
|
|
// to error. Errors can only be mapped to fatal.
|
2014-06-12 18:15:20 +08:00
|
|
|
diag::Severity Result = diag::Severity::Fatal;
|
2010-11-19 04:06:41 +08:00
|
|
|
|
2011-09-26 07:23:43 +08:00
|
|
|
DiagnosticsEngine::DiagStatePointsTy::iterator
|
2010-12-16 02:44:22 +08:00
|
|
|
Pos = Diag.GetDiagStatePointForLoc(Loc);
|
2011-09-26 07:23:43 +08:00
|
|
|
DiagnosticsEngine::DiagState *State = Pos->State;
|
2010-12-16 02:44:22 +08:00
|
|
|
|
2011-09-29 09:42:25 +08:00
|
|
|
// Get the mapping information, or compute it lazily.
|
2014-06-10 17:31:37 +08:00
|
|
|
DiagnosticMapping &Mapping = State->getOrAddMapping((diag::kind)DiagID);
|
2010-11-19 04:06:41 +08:00
|
|
|
|
2014-06-12 18:15:20 +08:00
|
|
|
// TODO: Can a null severity really get here?
|
|
|
|
if (Mapping.getSeverity() != diag::Severity())
|
|
|
|
Result = Mapping.getSeverity();
|
2010-11-19 04:06:41 +08:00
|
|
|
|
2011-09-29 09:58:05 +08:00
|
|
|
// Upgrade ignored diagnostics if -Weverything is enabled.
|
2014-06-12 18:15:20 +08:00
|
|
|
if (Diag.EnableAllWarnings && Result == diag::Severity::Ignored &&
|
2014-08-22 04:44:44 +08:00
|
|
|
!Mapping.isUser() && getBuiltinDiagClass(DiagID) != CLASS_REMARK)
|
2014-06-12 18:15:20 +08:00
|
|
|
Result = diag::Severity::Warning;
|
2010-11-19 04:06:41 +08:00
|
|
|
|
2011-10-13 03:55:31 +08:00
|
|
|
// Ignore -pedantic diagnostics inside __extension__ blocks.
|
|
|
|
// (The diagnostics controlled by -pedantic are the extension diagnostics
|
|
|
|
// that are not enabled by default.)
|
2011-11-29 06:19:36 +08:00
|
|
|
bool EnabledByDefault = false;
|
2011-10-13 03:55:31 +08:00
|
|
|
bool IsExtensionDiag = isBuiltinExtensionDiag(DiagID, EnabledByDefault);
|
|
|
|
if (Diag.AllExtensionsSilenced && IsExtensionDiag && !EnabledByDefault)
|
2014-06-12 18:15:20 +08:00
|
|
|
return diag::Severity::Ignored;
|
2010-11-19 04:06:41 +08:00
|
|
|
|
2011-09-29 09:58:05 +08:00
|
|
|
// For extension diagnostics that haven't been explicitly mapped, check if we
|
|
|
|
// should upgrade the diagnostic.
|
2014-06-23 05:58:33 +08:00
|
|
|
if (IsExtensionDiag && !Mapping.isUser())
|
|
|
|
Result = std::max(Result, Diag.ExtBehavior);
|
2010-11-19 04:06:41 +08:00
|
|
|
|
2011-09-29 09:58:05 +08:00
|
|
|
// At this point, ignored errors can no longer be upgraded.
|
2014-06-12 18:15:20 +08:00
|
|
|
if (Result == diag::Severity::Ignored)
|
2011-09-29 09:58:05 +08:00
|
|
|
return Result;
|
2010-11-19 04:06:41 +08:00
|
|
|
|
2011-09-29 09:58:05 +08:00
|
|
|
// Honor -w, which is lower in priority than pedantic-errors, but higher than
|
|
|
|
// -Werror.
|
2014-06-12 18:15:20 +08:00
|
|
|
if (Result == diag::Severity::Warning && Diag.IgnoreAllWarnings)
|
|
|
|
return diag::Severity::Ignored;
|
2010-11-19 04:06:41 +08:00
|
|
|
|
2011-09-29 09:58:05 +08:00
|
|
|
// If -Werror is enabled, map warnings to errors unless explicitly disabled.
|
2014-06-12 18:15:20 +08:00
|
|
|
if (Result == diag::Severity::Warning) {
|
2014-06-10 17:31:37 +08:00
|
|
|
if (Diag.WarningsAsErrors && !Mapping.hasNoWarningAsError())
|
2014-06-12 18:15:20 +08:00
|
|
|
Result = diag::Severity::Error;
|
2010-11-19 04:06:41 +08:00
|
|
|
}
|
|
|
|
|
2011-09-29 09:58:05 +08:00
|
|
|
// If -Wfatal-errors is enabled, map errors to fatal unless explicity
|
|
|
|
// disabled.
|
2014-06-12 18:15:20 +08:00
|
|
|
if (Result == diag::Severity::Error) {
|
2014-06-10 17:31:37 +08:00
|
|
|
if (Diag.ErrorsAsFatal && !Mapping.hasNoErrorAsFatal())
|
2014-06-12 18:15:20 +08:00
|
|
|
Result = diag::Severity::Fatal;
|
2011-09-29 09:58:05 +08:00
|
|
|
}
|
2010-11-19 04:06:41 +08:00
|
|
|
|
2014-06-10 14:09:00 +08:00
|
|
|
// Custom diagnostics always are emitted in system headers.
|
|
|
|
bool ShowInSystemHeader =
|
|
|
|
!GetDiagInfo(DiagID) || GetDiagInfo(DiagID)->WarnShowInSystemHeader;
|
|
|
|
|
2011-09-29 10:03:01 +08:00
|
|
|
// If we are in a system header, we ignore it. We look at the diagnostic class
|
|
|
|
// because we also want to ignore extensions and warnings in -Werror and
|
2011-04-22 07:08:18 +08:00
|
|
|
// -pedantic-errors modes, which *map* warnings/extensions to errors.
|
2014-06-16 21:56:47 +08:00
|
|
|
if (Diag.SuppressSystemWarnings && !ShowInSystemHeader && Loc.isValid() &&
|
2011-04-22 07:08:18 +08:00
|
|
|
Diag.getSourceManager().isInSystemHeader(
|
2011-07-26 00:49:02 +08:00
|
|
|
Diag.getSourceManager().getExpansionLoc(Loc)))
|
2014-06-12 18:15:20 +08:00
|
|
|
return diag::Severity::Ignored;
|
2011-04-22 07:08:18 +08:00
|
|
|
|
2010-11-19 04:06:41 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2013-08-29 13:18:04 +08:00
|
|
|
#define GET_DIAG_ARRAYS
|
|
|
|
#include "clang/Basic/DiagnosticGroups.inc"
|
|
|
|
#undef GET_DIAG_ARRAYS
|
|
|
|
|
2013-08-29 14:06:18 +08:00
|
|
|
namespace {
|
|
|
|
struct WarningOption {
|
|
|
|
uint16_t NameOffset;
|
|
|
|
uint16_t Members;
|
|
|
|
uint16_t SubGroups;
|
|
|
|
|
|
|
|
// String is stored with a pascal-style length byte.
|
|
|
|
StringRef getName() const {
|
|
|
|
return StringRef(DiagGroupNames + NameOffset + 1,
|
|
|
|
DiagGroupNames[NameOffset]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2010-11-19 04:06:41 +08:00
|
|
|
|
|
|
|
// Second the table of options, sorted by name for fast binary lookup.
|
|
|
|
static const WarningOption OptionTable[] = {
|
|
|
|
#define GET_DIAG_TABLE
|
|
|
|
#include "clang/Basic/DiagnosticGroups.inc"
|
|
|
|
#undef GET_DIAG_TABLE
|
|
|
|
};
|
2013-07-15 11:38:40 +08:00
|
|
|
static const size_t OptionTableSize = llvm::array_lengthof(OptionTable);
|
2010-11-19 04:06:41 +08:00
|
|
|
|
2013-08-29 13:18:04 +08:00
|
|
|
static bool WarningOptionCompare(const WarningOption &LHS, StringRef RHS) {
|
|
|
|
return LHS.getName() < RHS;
|
2010-11-19 04:06:41 +08:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:57:03 +08:00
|
|
|
/// getWarningOptionForDiag - Return the lowest-level warning option that
|
|
|
|
/// enables the specified diagnostic. If there is no -Wfoo flag that controls
|
|
|
|
/// the diagnostic, this returns null.
|
|
|
|
StringRef DiagnosticIDs::getWarningOptionForDiag(unsigned DiagID) {
|
|
|
|
if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
|
|
|
|
return OptionTable[Info->getOptionGroupIndex()].getName();
|
|
|
|
return StringRef();
|
|
|
|
}
|
|
|
|
|
Use -Rblah, not -Wblah, to control remark diagnostics. This was always the
intent when we added remark support, but was never implemented in the general
case, because the first -R flags didn't need it. (-Rpass= had special handling
to accomodate its argument.)
-Rno-foo, -Reverything, and -Rno-everything can be used to turn off a remark,
or to turn on or off all remarks. Per discussion on cfe-commits, -Weverything
does not affect remarks, and -Reverything does not affect warnings or errors.
The only "real" -R flag we have right now is -Rmodule-build; that flag is
effectively renamed from -Wmodule-build to -Rmodule-build by this change.
-Wpass and -Wno-pass (and their friends) are also renamed to -Rpass and
-Rno-pass by this change; it's not completely clear whether we intended to have
a -Rpass (with no =pattern), but that is unchanged by this commit, other than
the flag name. The default pattern is effectively one which matches no passes.
In future, we may want to make the default pattern be .*, so that -Reverything
works for -Rpass properly.
llvm-svn: 215046
2014-08-07 08:24:21 +08:00
|
|
|
/// Return \c true if any diagnostics were found in this group, even if they
|
|
|
|
/// were filtered out due to having the wrong flavor.
|
|
|
|
static bool getDiagnosticsInGroup(diag::Flavor Flavor,
|
|
|
|
const WarningOption *Group,
|
2013-08-29 14:06:18 +08:00
|
|
|
SmallVectorImpl<diag::kind> &Diags) {
|
Use -Rblah, not -Wblah, to control remark diagnostics. This was always the
intent when we added remark support, but was never implemented in the general
case, because the first -R flags didn't need it. (-Rpass= had special handling
to accomodate its argument.)
-Rno-foo, -Reverything, and -Rno-everything can be used to turn off a remark,
or to turn on or off all remarks. Per discussion on cfe-commits, -Weverything
does not affect remarks, and -Reverything does not affect warnings or errors.
The only "real" -R flag we have right now is -Rmodule-build; that flag is
effectively renamed from -Wmodule-build to -Rmodule-build by this change.
-Wpass and -Wno-pass (and their friends) are also renamed to -Rpass and
-Rno-pass by this change; it's not completely clear whether we intended to have
a -Rpass (with no =pattern), but that is unchanged by this commit, other than
the flag name. The default pattern is effectively one which matches no passes.
In future, we may want to make the default pattern be .*, so that -Reverything
works for -Rpass properly.
llvm-svn: 215046
2014-08-07 08:24:21 +08:00
|
|
|
// An empty group is considered to be a warning group: we have empty groups
|
|
|
|
// for GCC compatibility, and GCC does not have remarks.
|
|
|
|
if (!Group->Members && !Group->SubGroups)
|
|
|
|
return Flavor == diag::Flavor::Remark ? true : false;
|
|
|
|
|
|
|
|
bool NotFound = true;
|
|
|
|
|
2011-09-29 09:47:16 +08:00
|
|
|
// Add the members of the option diagnostic set.
|
2013-08-28 12:02:50 +08:00
|
|
|
const int16_t *Member = DiagArrays + Group->Members;
|
Use -Rblah, not -Wblah, to control remark diagnostics. This was always the
intent when we added remark support, but was never implemented in the general
case, because the first -R flags didn't need it. (-Rpass= had special handling
to accomodate its argument.)
-Rno-foo, -Reverything, and -Rno-everything can be used to turn off a remark,
or to turn on or off all remarks. Per discussion on cfe-commits, -Weverything
does not affect remarks, and -Reverything does not affect warnings or errors.
The only "real" -R flag we have right now is -Rmodule-build; that flag is
effectively renamed from -Wmodule-build to -Rmodule-build by this change.
-Wpass and -Wno-pass (and their friends) are also renamed to -Rpass and
-Rno-pass by this change; it's not completely clear whether we intended to have
a -Rpass (with no =pattern), but that is unchanged by this commit, other than
the flag name. The default pattern is effectively one which matches no passes.
In future, we may want to make the default pattern be .*, so that -Reverything
works for -Rpass properly.
llvm-svn: 215046
2014-08-07 08:24:21 +08:00
|
|
|
for (; *Member != -1; ++Member) {
|
|
|
|
if (GetDiagInfo(*Member)->getFlavor() == Flavor) {
|
|
|
|
NotFound = false;
|
|
|
|
Diags.push_back(*Member);
|
|
|
|
}
|
|
|
|
}
|
2010-11-19 04:06:41 +08:00
|
|
|
|
2011-09-29 09:47:16 +08:00
|
|
|
// Add the members of the subgroups.
|
2013-08-28 12:02:50 +08:00
|
|
|
const int16_t *SubGroups = DiagSubGroups + Group->SubGroups;
|
|
|
|
for (; *SubGroups != (int16_t)-1; ++SubGroups)
|
Use -Rblah, not -Wblah, to control remark diagnostics. This was always the
intent when we added remark support, but was never implemented in the general
case, because the first -R flags didn't need it. (-Rpass= had special handling
to accomodate its argument.)
-Rno-foo, -Reverything, and -Rno-everything can be used to turn off a remark,
or to turn on or off all remarks. Per discussion on cfe-commits, -Weverything
does not affect remarks, and -Reverything does not affect warnings or errors.
The only "real" -R flag we have right now is -Rmodule-build; that flag is
effectively renamed from -Wmodule-build to -Rmodule-build by this change.
-Wpass and -Wno-pass (and their friends) are also renamed to -Rpass and
-Rno-pass by this change; it's not completely clear whether we intended to have
a -Rpass (with no =pattern), but that is unchanged by this commit, other than
the flag name. The default pattern is effectively one which matches no passes.
In future, we may want to make the default pattern be .*, so that -Reverything
works for -Rpass properly.
llvm-svn: 215046
2014-08-07 08:24:21 +08:00
|
|
|
NotFound &= getDiagnosticsInGroup(Flavor, &OptionTable[(short)*SubGroups],
|
|
|
|
Diags);
|
|
|
|
|
|
|
|
return NotFound;
|
2010-11-19 04:06:41 +08:00
|
|
|
}
|
|
|
|
|
Use -Rblah, not -Wblah, to control remark diagnostics. This was always the
intent when we added remark support, but was never implemented in the general
case, because the first -R flags didn't need it. (-Rpass= had special handling
to accomodate its argument.)
-Rno-foo, -Reverything, and -Rno-everything can be used to turn off a remark,
or to turn on or off all remarks. Per discussion on cfe-commits, -Weverything
does not affect remarks, and -Reverything does not affect warnings or errors.
The only "real" -R flag we have right now is -Rmodule-build; that flag is
effectively renamed from -Wmodule-build to -Rmodule-build by this change.
-Wpass and -Wno-pass (and their friends) are also renamed to -Rpass and
-Rno-pass by this change; it's not completely clear whether we intended to have
a -Rpass (with no =pattern), but that is unchanged by this commit, other than
the flag name. The default pattern is effectively one which matches no passes.
In future, we may want to make the default pattern be .*, so that -Reverything
works for -Rpass properly.
llvm-svn: 215046
2014-08-07 08:24:21 +08:00
|
|
|
bool
|
|
|
|
DiagnosticIDs::getDiagnosticsInGroup(diag::Flavor Flavor, StringRef Group,
|
|
|
|
SmallVectorImpl<diag::kind> &Diags) const {
|
|
|
|
const WarningOption *Found = std::lower_bound(
|
|
|
|
OptionTable, OptionTable + OptionTableSize, Group, WarningOptionCompare);
|
2010-11-19 04:06:41 +08:00
|
|
|
if (Found == OptionTable + OptionTableSize ||
|
2011-05-25 13:05:01 +08:00
|
|
|
Found->getName() != Group)
|
2011-09-29 09:47:16 +08:00
|
|
|
return true; // Option not found.
|
2010-11-19 04:06:41 +08:00
|
|
|
|
Use -Rblah, not -Wblah, to control remark diagnostics. This was always the
intent when we added remark support, but was never implemented in the general
case, because the first -R flags didn't need it. (-Rpass= had special handling
to accomodate its argument.)
-Rno-foo, -Reverything, and -Rno-everything can be used to turn off a remark,
or to turn on or off all remarks. Per discussion on cfe-commits, -Weverything
does not affect remarks, and -Reverything does not affect warnings or errors.
The only "real" -R flag we have right now is -Rmodule-build; that flag is
effectively renamed from -Wmodule-build to -Rmodule-build by this change.
-Wpass and -Wno-pass (and their friends) are also renamed to -Rpass and
-Rno-pass by this change; it's not completely clear whether we intended to have
a -Rpass (with no =pattern), but that is unchanged by this commit, other than
the flag name. The default pattern is effectively one which matches no passes.
In future, we may want to make the default pattern be .*, so that -Reverything
works for -Rpass properly.
llvm-svn: 215046
2014-08-07 08:24:21 +08:00
|
|
|
return ::getDiagnosticsInGroup(Flavor, Found, Diags);
|
2010-11-19 04:06:41 +08:00
|
|
|
}
|
|
|
|
|
Use -Rblah, not -Wblah, to control remark diagnostics. This was always the
intent when we added remark support, but was never implemented in the general
case, because the first -R flags didn't need it. (-Rpass= had special handling
to accomodate its argument.)
-Rno-foo, -Reverything, and -Rno-everything can be used to turn off a remark,
or to turn on or off all remarks. Per discussion on cfe-commits, -Weverything
does not affect remarks, and -Reverything does not affect warnings or errors.
The only "real" -R flag we have right now is -Rmodule-build; that flag is
effectively renamed from -Wmodule-build to -Rmodule-build by this change.
-Wpass and -Wno-pass (and their friends) are also renamed to -Rpass and
-Rno-pass by this change; it's not completely clear whether we intended to have
a -Rpass (with no =pattern), but that is unchanged by this commit, other than
the flag name. The default pattern is effectively one which matches no passes.
In future, we may want to make the default pattern be .*, so that -Reverything
works for -Rpass properly.
llvm-svn: 215046
2014-08-07 08:24:21 +08:00
|
|
|
void DiagnosticIDs::getAllDiagnostics(diag::Flavor Flavor,
|
|
|
|
SmallVectorImpl<diag::kind> &Diags) const {
|
2012-01-27 14:15:43 +08:00
|
|
|
for (unsigned i = 0; i != StaticDiagInfoSize; ++i)
|
Use -Rblah, not -Wblah, to control remark diagnostics. This was always the
intent when we added remark support, but was never implemented in the general
case, because the first -R flags didn't need it. (-Rpass= had special handling
to accomodate its argument.)
-Rno-foo, -Reverything, and -Rno-everything can be used to turn off a remark,
or to turn on or off all remarks. Per discussion on cfe-commits, -Weverything
does not affect remarks, and -Reverything does not affect warnings or errors.
The only "real" -R flag we have right now is -Rmodule-build; that flag is
effectively renamed from -Wmodule-build to -Rmodule-build by this change.
-Wpass and -Wno-pass (and their friends) are also renamed to -Rpass and
-Rno-pass by this change; it's not completely clear whether we intended to have
a -Rpass (with no =pattern), but that is unchanged by this commit, other than
the flag name. The default pattern is effectively one which matches no passes.
In future, we may want to make the default pattern be .*, so that -Reverything
works for -Rpass properly.
llvm-svn: 215046
2014-08-07 08:24:21 +08:00
|
|
|
if (StaticDiagInfo[i].getFlavor() == Flavor)
|
|
|
|
Diags.push_back(StaticDiagInfo[i].DiagID);
|
2012-01-27 14:15:43 +08:00
|
|
|
}
|
|
|
|
|
Use -Rblah, not -Wblah, to control remark diagnostics. This was always the
intent when we added remark support, but was never implemented in the general
case, because the first -R flags didn't need it. (-Rpass= had special handling
to accomodate its argument.)
-Rno-foo, -Reverything, and -Rno-everything can be used to turn off a remark,
or to turn on or off all remarks. Per discussion on cfe-commits, -Weverything
does not affect remarks, and -Reverything does not affect warnings or errors.
The only "real" -R flag we have right now is -Rmodule-build; that flag is
effectively renamed from -Wmodule-build to -Rmodule-build by this change.
-Wpass and -Wno-pass (and their friends) are also renamed to -Rpass and
-Rno-pass by this change; it's not completely clear whether we intended to have
a -Rpass (with no =pattern), but that is unchanged by this commit, other than
the flag name. The default pattern is effectively one which matches no passes.
In future, we may want to make the default pattern be .*, so that -Reverything
works for -Rpass properly.
llvm-svn: 215046
2014-08-07 08:24:21 +08:00
|
|
|
StringRef DiagnosticIDs::getNearestOption(diag::Flavor Flavor,
|
|
|
|
StringRef Group) {
|
2011-11-15 07:30:34 +08:00
|
|
|
StringRef Best;
|
2011-11-15 20:26:39 +08:00
|
|
|
unsigned BestDistance = Group.size() + 1; // Sanity threshold.
|
2011-11-15 07:30:34 +08:00
|
|
|
for (const WarningOption *i = OptionTable, *e = OptionTable + OptionTableSize;
|
|
|
|
i != e; ++i) {
|
|
|
|
// Don't suggest ignored warning flags.
|
|
|
|
if (!i->Members && !i->SubGroups)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
unsigned Distance = i->getName().edit_distance(Group, true, BestDistance);
|
Use -Rblah, not -Wblah, to control remark diagnostics. This was always the
intent when we added remark support, but was never implemented in the general
case, because the first -R flags didn't need it. (-Rpass= had special handling
to accomodate its argument.)
-Rno-foo, -Reverything, and -Rno-everything can be used to turn off a remark,
or to turn on or off all remarks. Per discussion on cfe-commits, -Weverything
does not affect remarks, and -Reverything does not affect warnings or errors.
The only "real" -R flag we have right now is -Rmodule-build; that flag is
effectively renamed from -Wmodule-build to -Rmodule-build by this change.
-Wpass and -Wno-pass (and their friends) are also renamed to -Rpass and
-Rno-pass by this change; it's not completely clear whether we intended to have
a -Rpass (with no =pattern), but that is unchanged by this commit, other than
the flag name. The default pattern is effectively one which matches no passes.
In future, we may want to make the default pattern be .*, so that -Reverything
works for -Rpass properly.
llvm-svn: 215046
2014-08-07 08:24:21 +08:00
|
|
|
if (Distance > BestDistance)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Don't suggest groups that are not of this kind.
|
|
|
|
llvm::SmallVector<diag::kind, 8> Diags;
|
|
|
|
if (::getDiagnosticsInGroup(Flavor, i, Diags) || Diags.empty())
|
|
|
|
continue;
|
|
|
|
|
2011-11-15 20:26:39 +08:00
|
|
|
if (Distance == BestDistance) {
|
|
|
|
// Two matches with the same distance, don't prefer one over the other.
|
|
|
|
Best = "";
|
|
|
|
} else if (Distance < BestDistance) {
|
|
|
|
// This is a better match.
|
2011-11-15 07:30:34 +08:00
|
|
|
Best = i->getName();
|
|
|
|
BestDistance = Distance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Best;
|
|
|
|
}
|
|
|
|
|
2010-11-19 04:06:41 +08:00
|
|
|
/// ProcessDiag - This is the method used to report a diagnostic that is
|
|
|
|
/// finally fully formed.
|
2011-09-26 07:23:43 +08:00
|
|
|
bool DiagnosticIDs::ProcessDiag(DiagnosticsEngine &Diag) const {
|
2011-09-26 09:18:08 +08:00
|
|
|
Diagnostic Info(&Diag);
|
2010-11-19 04:06:41 +08:00
|
|
|
|
|
|
|
if (Diag.SuppressAllDiagnostics)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
assert(Diag.getClient() && "DiagnosticClient not set!");
|
|
|
|
|
|
|
|
// Figure out the diagnostic level of this message.
|
|
|
|
unsigned DiagID = Info.getID();
|
2012-07-12 00:50:36 +08:00
|
|
|
DiagnosticIDs::Level DiagLevel
|
|
|
|
= getDiagnosticLevel(DiagID, Info.getLocation(), Diag);
|
2010-11-19 04:06:41 +08:00
|
|
|
|
|
|
|
if (DiagLevel != DiagnosticIDs::Note) {
|
|
|
|
// Record that a fatal error occurred only when we see a second
|
|
|
|
// non-note diagnostic. This allows notes to be attached to the
|
|
|
|
// fatal error, but suppresses any diagnostics that follow those
|
|
|
|
// notes.
|
|
|
|
if (Diag.LastDiagLevel == DiagnosticIDs::Fatal)
|
|
|
|
Diag.FatalErrorOccurred = true;
|
|
|
|
|
|
|
|
Diag.LastDiagLevel = DiagLevel;
|
|
|
|
}
|
|
|
|
|
2011-07-29 09:25:44 +08:00
|
|
|
// Update counts for DiagnosticErrorTrap even if a fatal error occurred.
|
|
|
|
if (DiagLevel >= DiagnosticIDs::Error) {
|
|
|
|
++Diag.TrapNumErrorsOccurred;
|
|
|
|
if (isUnrecoverable(DiagID))
|
|
|
|
++Diag.TrapNumUnrecoverableErrorsOccurred;
|
|
|
|
}
|
|
|
|
|
2010-11-19 04:06:41 +08:00
|
|
|
// If a fatal error has already been emitted, silence all subsequent
|
|
|
|
// diagnostics.
|
|
|
|
if (Diag.FatalErrorOccurred) {
|
|
|
|
if (DiagLevel >= DiagnosticIDs::Error &&
|
|
|
|
Diag.Client->IncludeInDiagnosticCounts()) {
|
|
|
|
++Diag.NumErrors;
|
|
|
|
++Diag.NumErrorsSuppressed;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the client doesn't care about this message, don't issue it. If this is
|
|
|
|
// a note and the last real diagnostic was ignored, ignore it too.
|
|
|
|
if (DiagLevel == DiagnosticIDs::Ignored ||
|
|
|
|
(DiagLevel == DiagnosticIDs::Note &&
|
|
|
|
Diag.LastDiagLevel == DiagnosticIDs::Ignored))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (DiagLevel >= DiagnosticIDs::Error) {
|
2011-07-29 09:25:44 +08:00
|
|
|
if (isUnrecoverable(DiagID))
|
2011-07-07 01:40:26 +08:00
|
|
|
Diag.UnrecoverableErrorOccurred = true;
|
2012-09-28 23:45:07 +08:00
|
|
|
|
2012-12-08 06:53:48 +08:00
|
|
|
// Warnings which have been upgraded to errors do not prevent compilation.
|
|
|
|
if (isDefaultMappingAsError(DiagID))
|
|
|
|
Diag.UncompilableErrorOccurred = true;
|
|
|
|
|
2012-09-28 23:45:07 +08:00
|
|
|
Diag.ErrorOccurred = true;
|
2010-11-19 04:06:41 +08:00
|
|
|
if (Diag.Client->IncludeInDiagnosticCounts()) {
|
|
|
|
++Diag.NumErrors;
|
|
|
|
}
|
|
|
|
|
2011-08-18 03:13:00 +08:00
|
|
|
// If we've emitted a lot of errors, emit a fatal error instead of it to
|
|
|
|
// stop a flood of bogus errors.
|
|
|
|
if (Diag.ErrorLimit && Diag.NumErrors > Diag.ErrorLimit &&
|
|
|
|
DiagLevel == DiagnosticIDs::Error) {
|
2010-11-19 04:06:41 +08:00
|
|
|
Diag.SetDelayedDiagnostic(diag::fatal_too_many_errors);
|
2011-08-18 03:13:00 +08:00
|
|
|
return false;
|
|
|
|
}
|
2010-11-19 04:06:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Finally, report it.
|
2012-07-12 00:50:36 +08:00
|
|
|
EmitDiag(Diag, DiagLevel);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiagnosticIDs::EmitDiag(DiagnosticsEngine &Diag, Level DiagLevel) const {
|
|
|
|
Diagnostic Info(&Diag);
|
|
|
|
assert(DiagLevel != DiagnosticIDs::Ignored && "Cannot emit ignored diagnostics!");
|
|
|
|
|
2011-09-26 07:23:43 +08:00
|
|
|
Diag.Client->HandleDiagnostic((DiagnosticsEngine::Level)DiagLevel, Info);
|
2010-11-19 04:06:41 +08:00
|
|
|
if (Diag.Client->IncludeInDiagnosticCounts()) {
|
|
|
|
if (DiagLevel == DiagnosticIDs::Warning)
|
|
|
|
++Diag.NumWarnings;
|
|
|
|
}
|
|
|
|
|
|
|
|
Diag.CurDiagID = ~0U;
|
|
|
|
}
|
2011-06-16 05:46:43 +08:00
|
|
|
|
|
|
|
bool DiagnosticIDs::isUnrecoverable(unsigned DiagID) const {
|
|
|
|
if (DiagID >= diag::DIAG_UPPER_LIMIT) {
|
2014-08-01 09:42:01 +08:00
|
|
|
assert(CustomDiagInfo && "Invalid CustomDiagInfo");
|
2011-06-16 05:46:43 +08:00
|
|
|
// Custom diagnostics.
|
|
|
|
return CustomDiagInfo->getLevel(DiagID) >= DiagnosticIDs::Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only errors may be unrecoverable.
|
2011-07-07 01:40:26 +08:00
|
|
|
if (getBuiltinDiagClass(DiagID) < CLASS_ERROR)
|
2011-06-16 05:46:43 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (DiagID == diag::err_unavailable ||
|
|
|
|
DiagID == diag::err_unavailable_message)
|
|
|
|
return false;
|
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
// Currently we consider all ARC errors as recoverable.
|
2011-10-20 13:07:47 +08:00
|
|
|
if (isARCDiagnostic(DiagID))
|
2011-06-16 07:02:42 +08:00
|
|
|
return false;
|
|
|
|
|
2011-06-16 05:46:43 +08:00
|
|
|
return true;
|
|
|
|
}
|
2011-10-20 13:07:47 +08:00
|
|
|
|
|
|
|
bool DiagnosticIDs::isARCDiagnostic(unsigned DiagID) {
|
|
|
|
unsigned cat = getCategoryNumberForDiag(DiagID);
|
|
|
|
return DiagnosticIDs::getCategoryNameFromID(cat).startswith("ARC ");
|
|
|
|
}
|