summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-01-02 22:26:07 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-01-02 22:26:07 +0000
commitf86e8cced6b381a631a37a0c0e1191879a7460bd (patch)
tree10f1a9246f3416f592b2849eca75ba50e300911d
parent567f886eb030a1efa6d7a87194e504a9f4b39462 (diff)
downloadbcm5719-llvm-f86e8cced6b381a631a37a0c0e1191879a7460bd.tar.gz
bcm5719-llvm-f86e8cced6b381a631a37a0c0e1191879a7460bd.zip
DiagnosticIds: Fix offset/ID calculation, no impact outside this code.
Patch by Will Dietz: Minor touchup so the values of Offset/ID reflect their intention. Previously, the sum (Offset+ID) was correct, but Offset/ID individually were wrong. Caught by investigating unsigned overflow reported by -fsanitize=integer. llvm-svn: 171421
-rw-r--r--clang/lib/Basic/DiagnosticIDs.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/clang/lib/Basic/DiagnosticIDs.cpp b/clang/lib/Basic/DiagnosticIDs.cpp
index 4716a449a7c..e1f400adaa5 100644
--- a/clang/lib/Basic/DiagnosticIDs.cpp
+++ b/clang/lib/Basic/DiagnosticIDs.cpp
@@ -125,8 +125,8 @@ static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) {
#define DIAG_START_COMMON 0 // Sentinel value.
#define CATEGORY(NAME, PREV) \
if (DiagID > DIAG_START_##NAME) { \
- Offset += NUM_BUILTIN_##PREV##_DIAGNOSTICS - DIAG_START_##PREV; \
- ID -= DIAG_START_##NAME - DIAG_START_##PREV + 1; \
+ Offset += NUM_BUILTIN_##PREV##_DIAGNOSTICS - DIAG_START_##PREV - 1; \
+ ID -= DIAG_START_##NAME - DIAG_START_##PREV; \
}
CATEGORY(DRIVER, COMMON)
CATEGORY(FRONTEND, DRIVER)
@@ -144,6 +144,8 @@ CATEGORY(ANALYSIS, SEMA)
if (ID + Offset >= StaticDiagInfoSize)
return 0;
+ assert(ID < StaticDiagInfoSize && Offset < StaticDiagInfoSize);
+
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
OpenPOWER on IntegriCloud