diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2011-02-17 20:55:08 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2011-02-17 20:55:08 +0000 |
commit | 2a666fc2c7f77145c42c9c6a989996f209901287 (patch) | |
tree | 4cafea6352ec2d8af2f2b60a8568c63039f39c71 /clang/lib/Sema/SemaChecking.cpp | |
parent | d28cc8113b0241eae56cdd1b13a2634ac2045d86 (diff) | |
download | bcm5719-llvm-2a666fc2c7f77145c42c9c6a989996f209901287.tar.gz bcm5719-llvm-2a666fc2c7f77145c42c9c6a989996f209901287.zip |
Clean up the style of this function to match the conventions in the rest
of Clang, and reflows the code a bit to make it easier to read.
llvm-svn: 125773
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index a3ab52c0006..d00f0922741 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -3094,41 +3094,40 @@ void Sema::CheckCastAlign(Expr *Op, QualType T, SourceRange TRange) { << TRange << Op->getSourceRange(); } -void Sema::CheckArrayAccess(const clang::ArraySubscriptExpr *ae) { - const DeclRefExpr *dr = - dyn_cast<DeclRefExpr>(ae->getBase()->IgnoreParenImpCasts()); - if (!dr) +void Sema::CheckArrayAccess(const clang::ArraySubscriptExpr *E) { + const DeclRefExpr *DRE = + dyn_cast<DeclRefExpr>(E->getBase()->IgnoreParenImpCasts()); + if (!DRE) return; - const VarDecl *vd = dyn_cast<VarDecl>(dr->getDecl()); - if (!vd) + const VarDecl *Variable = dyn_cast<VarDecl>(DRE->getDecl()); + if (!Variable) return; - const ConstantArrayType *cat = Context.getAsConstantArrayType(vd->getType()); - if (!cat) + const ConstantArrayType *ArrayTy = + Context.getAsConstantArrayType(Variable->getType()); + if (!ArrayTy) return; - const Expr *idx = ae->getIdx(); - if (idx->isValueDependent()) + const Expr *IndexExpr = E->getIdx(); + if (IndexExpr->isValueDependent()) return; - llvm::APSInt result; - if (!idx->isIntegerConstantExpr(result, Context)) + llvm::APSInt index; + if (!IndexExpr->isIntegerConstantExpr(index, Context)) return; - 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)) { - Diag(ae->getBase()->getLocStart(), diag::warn_array_index_exceeds_bounds) - << result.toString(10, true) << size.toString(10, true) - << idx->getSourceRange(); - } - else + if (!index.isNegative()) { + const llvm::APInt &size = ArrayTy->getSize(); + if (size.getBitWidth() > index.getBitWidth()) + index = index.sext(size.getBitWidth()); + if (index.slt(size)) return; + + Diag(E->getBase()->getLocStart(), diag::warn_array_index_exceeds_bounds) + << index.toString(10, true) << size.toString(10, true) + << IndexExpr->getSourceRange(); + } else { + Diag(E->getBase()->getLocStart(), diag::warn_array_index_precedes_bounds) + << index.toString(10, true) << IndexExpr->getSourceRange(); } - Diag(vd->getLocStart(), diag::note_array_index_out_of_bounds) - << vd->getDeclName(); + Diag(Variable->getLocStart(), diag::note_array_index_out_of_bounds) + << Variable->getDeclName(); } |