aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-02-16 04:01:44 +0000
committerTed Kremenek <kremenek@apple.com>2011-02-16 04:01:44 +0000
commit8fd0a5dfb025a51f48b7931b95efbf35d3c5dfc3 (patch)
treec47468682e7862cb0a6c5ee08df2ca3018e05312 /lib/Sema/SemaChecking.cpp
parent792f975febd8d2da03d5628eb49400b227458705 (diff)
Tweak -Warray-bounds diagnostics based on feedback from Chandler.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125649 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaChecking.cpp')
-rw-r--r--lib/Sema/SemaChecking.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index ea1f07d783..a4c9eb6841 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -3095,18 +3095,24 @@ void Sema::CheckArrayAccess(const clang::ArraySubscriptExpr *ae) {
llvm::APSInt result;
if (!idx->isIntegerConstantExpr(result, Context))
return;
- unsigned kind = 2;
- if (result.slt(0))
- kind = /* precedes */ 0;
+
+ if (result.slt(0)) {
+ Diag(ae->getBase()->getLocStart(), diag::warn_array_index_precedes_bounds)
+ << result.toString(10, true) << idx->getSourceRange();
+ }
else {
const llvm::APInt &size = cat->getSize();
if (size.getBitWidth() > result.getBitWidth())
result = result.sext(size.getBitWidth());
- if (result.sge(size))
- kind = /* excedes */ 1;
+ if (result.sge(size)) {
+ Diag(ae->getBase()->getLocStart(), diag::warn_array_index_exceeds_bounds)
+ << result.toString(10, true) << size.toString(10, true)
+ << idx->getSourceRange();
+ }
+ else
+ return;
}
- if (kind < 2)
- Diag(ae->getBase()->getLocEnd(), diag::warn_array_index_out_of_bounds)
- << kind << idx->getSourceRange();
+ Diag(vd->getLocStart(), diag::note_array_index_out_of_bounds)
+ << vd->getDeclName();
}