DiagnosticIDs: Forbid Diag ID from being valid
Diag ID is used throughout clang as a sentinel id meaning "this is an invalid diagnostic id." Confusingly, Diag ID maps to a valid, usable, diagnostic id. Instead, start diagnostic ids at ID one. Incidently, remove an unused element from StaticDiagInfo. llvm-svn: 186760
This commit is contained in:
parent
a9b57f6bea
commit
38af2a2158
|
@ -28,7 +28,8 @@ namespace clang {
|
||||||
namespace diag {
|
namespace diag {
|
||||||
// Start position for diagnostics.
|
// Start position for diagnostics.
|
||||||
enum {
|
enum {
|
||||||
DIAG_START_DRIVER = 300,
|
DIAG_START_COMMON = 0,
|
||||||
|
DIAG_START_DRIVER = DIAG_START_COMMON + 300,
|
||||||
DIAG_START_FRONTEND = DIAG_START_DRIVER + 100,
|
DIAG_START_FRONTEND = DIAG_START_DRIVER + 100,
|
||||||
DIAG_START_SERIALIZATION = DIAG_START_FRONTEND + 100,
|
DIAG_START_SERIALIZATION = DIAG_START_FRONTEND + 100,
|
||||||
DIAG_START_LEX = DIAG_START_SERIALIZATION + 120,
|
DIAG_START_LEX = DIAG_START_SERIALIZATION + 120,
|
||||||
|
@ -49,6 +50,7 @@ namespace clang {
|
||||||
enum {
|
enum {
|
||||||
#define DIAG(ENUM,FLAGS,DEFAULT_MAPPING,DESC,GROUP,\
|
#define DIAG(ENUM,FLAGS,DEFAULT_MAPPING,DESC,GROUP,\
|
||||||
SFINAE,ACCESS,CATEGORY,NOWERROR,SHOWINSYSHEADER) ENUM,
|
SFINAE,ACCESS,CATEGORY,NOWERROR,SHOWINSYSHEADER) ENUM,
|
||||||
|
#define COMMONSTART
|
||||||
#include "clang/Basic/DiagnosticCommonKinds.inc"
|
#include "clang/Basic/DiagnosticCommonKinds.inc"
|
||||||
NUM_BUILTIN_COMMON_DIAGNOSTICS
|
NUM_BUILTIN_COMMON_DIAGNOSTICS
|
||||||
#undef DIAG
|
#undef DIAG
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
#include "clang/Basic/AllDiagnostics.h"
|
#include "clang/Basic/AllDiagnostics.h"
|
||||||
#include "clang/Basic/DiagnosticCategories.h"
|
#include "clang/Basic/DiagnosticCategories.h"
|
||||||
#include "clang/Basic/SourceManager.h"
|
#include "clang/Basic/SourceManager.h"
|
||||||
#include "llvm/ADT/STLExtras.h"
|
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
|
#include "llvm/ADT/STLExtras.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
using namespace clang;
|
using namespace clang;
|
||||||
|
@ -83,11 +83,9 @@ static const StaticDiagInfoRec StaticDiagInfo[] = {
|
||||||
#include "clang/Basic/DiagnosticSemaKinds.inc"
|
#include "clang/Basic/DiagnosticSemaKinds.inc"
|
||||||
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
|
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
|
||||||
#undef DIAG
|
#undef DIAG
|
||||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const unsigned StaticDiagInfoSize =
|
static const unsigned StaticDiagInfoSize = llvm::array_lengthof(StaticDiagInfo);
|
||||||
llvm::array_lengthof(StaticDiagInfo)-1;
|
|
||||||
|
|
||||||
/// GetDiagInfo - Return the StaticDiagInfoRec entry for the specified DiagID,
|
/// GetDiagInfo - Return the StaticDiagInfoRec entry for the specified DiagID,
|
||||||
/// or null if the ID is invalid.
|
/// or null if the ID is invalid.
|
||||||
|
@ -106,7 +104,7 @@ static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) {
|
||||||
|
|
||||||
// Out of bounds diag. Can't be in the table.
|
// Out of bounds diag. Can't be in the table.
|
||||||
using namespace diag;
|
using namespace diag;
|
||||||
if (DiagID >= DIAG_UPPER_LIMIT)
|
if (DiagID >= DIAG_UPPER_LIMIT || DiagID <= DIAG_START_COMMON)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Compute the index of the requested diagnostic in the static table.
|
// Compute the index of the requested diagnostic in the static table.
|
||||||
|
@ -118,8 +116,7 @@ static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) {
|
||||||
// This is cheaper than a binary search on the table as it doesn't touch
|
// This is cheaper than a binary search on the table as it doesn't touch
|
||||||
// memory at all.
|
// memory at all.
|
||||||
unsigned Offset = 0;
|
unsigned Offset = 0;
|
||||||
unsigned ID = DiagID;
|
unsigned ID = DiagID - DIAG_START_COMMON - 1;
|
||||||
#define DIAG_START_COMMON 0 // Sentinel value.
|
|
||||||
#define CATEGORY(NAME, PREV) \
|
#define CATEGORY(NAME, PREV) \
|
||||||
if (DiagID > DIAG_START_##NAME) { \
|
if (DiagID > DIAG_START_##NAME) { \
|
||||||
Offset += NUM_BUILTIN_##PREV##_DIAGNOSTICS - DIAG_START_##PREV - 1; \
|
Offset += NUM_BUILTIN_##PREV##_DIAGNOSTICS - DIAG_START_##PREV - 1; \
|
||||||
|
@ -135,7 +132,6 @@ CATEGORY(COMMENT, AST)
|
||||||
CATEGORY(SEMA, COMMENT)
|
CATEGORY(SEMA, COMMENT)
|
||||||
CATEGORY(ANALYSIS, SEMA)
|
CATEGORY(ANALYSIS, SEMA)
|
||||||
#undef CATEGORY
|
#undef CATEGORY
|
||||||
#undef DIAG_START_COMMON
|
|
||||||
|
|
||||||
// Avoid out of bounds reads.
|
// Avoid out of bounds reads.
|
||||||
if (ID + Offset >= StaticDiagInfoSize)
|
if (ID + Offset >= StaticDiagInfoSize)
|
||||||
|
|
Loading…
Reference in New Issue