diff options
| author | Ted Kremenek <kremenek@apple.com> | 2011-02-16 04:01:44 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2011-02-16 04:01:44 +0000 |
| commit | 108b2d56bf41636f17f8528fbb320f1450103c9b (patch) | |
| tree | af4dc9166995268d54555e9e7e576f79b970b193 /clang/lib | |
| parent | 490d02a3349ff7af8827c5c070fce539d3bed034 (diff) | |
| download | bcm5719-llvm-108b2d56bf41636f17f8528fbb320f1450103c9b.tar.gz bcm5719-llvm-108b2d56bf41636f17f8528fbb320f1450103c9b.zip | |
Tweak -Warray-bounds diagnostics based on feedback from Chandler.
llvm-svn: 125649
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index ea1f07d7834..a4c9eb68412 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/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(); } |

