diff options
author | Matt Beaumont-Gay <matthewbg@google.com> | 2011-12-12 22:35:02 +0000 |
---|---|---|
committer | Matt Beaumont-Gay <matthewbg@google.com> | 2011-12-12 22:35:02 +0000 |
commit | 9d570c438cd31923b548bbb5d0ca84d68b3f13c7 (patch) | |
tree | ee2eeaba41f00aab93e0310db3dab0cffaee04d0 /clang/lib/Sema/SemaChecking.cpp | |
parent | 055d0c961b7feee0d875cd791afa2451d98980dc (diff) | |
download | bcm5719-llvm-9d570c438cd31923b548bbb5d0ca84d68b3f13c7.tar.gz bcm5719-llvm-9d570c438cd31923b548bbb5d0ca84d68b3f13c7.zip |
Suppress -Warray-bounds in certain cases involving macros from system headers.
The motivation here is a "clever" implementation of strncmp(), which peels the first few comparisons via chained conditional expressions which ensure that the input arrays are known at compile time to be sufficiently large.
llvm-svn: 146430
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 1c93931b5c1..bb567d0986a 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -4275,7 +4275,7 @@ 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); + const Type *EffectiveType = getElementType(BaseExpr); BaseExpr = BaseExpr->IgnoreParenCasts(); IndexExpr = IndexExpr->IgnoreParenCasts(); @@ -4381,6 +4381,16 @@ 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, AllowOnePastEnd > 0); return; |