aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorMatt Beaumont-Gay <matthewbg@google.com>2011-12-14 16:02:15 +0000
committerMatt Beaumont-Gay <matthewbg@google.com>2011-12-14 16:02:15 +0000
commit80fb7dd8e0c56632dc68f5864f70abb2fde0e1df (patch)
tree175c7b87af3e5aff83b5d971e8e13688bb99005f /lib/Sema/SemaChecking.cpp
parentdfba0278ce3b9cd86f5a050163ccb998aeb74aa6 (diff)
r146430 lost some compile-time performance on MultiSource/Benchmarks/MiBench/security-rijndael; this gets most of it back.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146562 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaChecking.cpp')
-rw-r--r--lib/Sema/SemaChecking.cpp43
1 files changed, 24 insertions, 19 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index bb567d0986..5de124de4d 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -4274,20 +4274,21 @@ static bool IsTailPaddedMemberArray(Sema &S, llvm::APInt Size,
}
void Sema::CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
- bool isSubscript, bool AllowOnePastEnd) {
- const Type *EffectiveType = getElementType(BaseExpr);
- BaseExpr = BaseExpr->IgnoreParenCasts();
+ const ArraySubscriptExpr *ASE,
+ bool AllowOnePastEnd) {
IndexExpr = IndexExpr->IgnoreParenCasts();
+ if (IndexExpr->isValueDependent())
+ return;
+ const Type *EffectiveType = getElementType(BaseExpr);
+ BaseExpr = BaseExpr->IgnoreParenCasts();
const ConstantArrayType *ArrayTy =
Context.getAsConstantArrayType(BaseExpr->getType());
if (!ArrayTy)
return;
- if (IndexExpr->isValueDependent())
- return;
llvm::APSInt index;
- if (!IndexExpr->isIntegerConstantExpr(index, Context))
+ if (!IndexExpr->EvaluateAsInt(index, Context))
return;
const NamedDecl *ND = NULL;
@@ -4336,8 +4337,22 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
if (IsTailPaddedMemberArray(*this, size, ND))
return;
+ // Suppress the warning if the subscript expression (as identified by the
+ // ']' location) and the index expression are both from macro expansions
+ // within a system header.
+ if (ASE) {
+ SourceLocation RBracketLoc = SourceMgr.getSpellingLoc(
+ ASE->getRBracketLoc());
+ if (SourceMgr.isInSystemHeader(RBracketLoc)) {
+ SourceLocation IndexLoc = SourceMgr.getSpellingLoc(
+ IndexExpr->getLocStart());
+ if (SourceMgr.isFromSameFile(RBracketLoc, IndexLoc))
+ return;
+ }
+ }
+
unsigned DiagID = diag::warn_ptr_arith_exceeds_bounds;
- if (isSubscript)
+ if (ASE)
DiagID = diag::warn_array_index_exceeds_bounds;
DiagRuntimeBehavior(BaseExpr->getLocStart(), BaseExpr,
@@ -4347,7 +4362,7 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
<< IndexExpr->getSourceRange());
} else {
unsigned DiagID = diag::warn_array_index_precedes_bounds;
- if (!isSubscript) {
+ if (!ASE) {
DiagID = diag::warn_ptr_arith_precedes_bounds;
if (index.isNegative()) index = -index;
}
@@ -4381,17 +4396,7 @@ void Sema::CheckArrayAccess(const Expr *expr) {
switch (expr->getStmtClass()) {
case Stmt::ArraySubscriptExprClass: {
const ArraySubscriptExpr *ASE = cast<ArraySubscriptExpr>(expr);
- // Suppress the warning if the subscript expression (as identified by
- // the ']' location) and the index expression are both from macro
- // expansions within a system header.
- SourceLocation RBracketLoc = SourceMgr.getSpellingLoc(
- ASE->getRBracketLoc());
- SourceLocation IndexLoc = SourceMgr.getSpellingLoc(
- ASE->getIdx()->IgnoreParens()->getLocStart());
- if (SourceMgr.isFromSameFile(RBracketLoc, IndexLoc) &&
- SourceMgr.isInSystemHeader(RBracketLoc))
- return;
- CheckArrayAccess(ASE->getBase(), ASE->getIdx(), true,
+ CheckArrayAccess(ASE->getBase(), ASE->getIdx(), ASE,
AllowOnePastEnd > 0);
return;
}