summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorBruno Ricci <riccibrun@gmail.com>2019-01-08 13:52:54 +0000
committerBruno Ricci <riccibrun@gmail.com>2019-01-08 13:52:54 +0000
commitf605e825219bd14d35a2fa4796137acfc20f4215 (patch)
tree12d0f712aac2a6d1221943e1adeb29cbe0004738 /clang/lib/Sema/SemaChecking.cpp
parent32f08399eb298519bf0bffc36ca9eb24b20b33d6 (diff)
downloadbcm5719-llvm-f605e825219bd14d35a2fa4796137acfc20f4215.tar.gz
bcm5719-llvm-f605e825219bd14d35a2fa4796137acfc20f4215.zip
[Sema] Diagnose array access preceding the array bounds even when the base type is incomplete.
When the type of the base expression after IgnoreParenCasts is incomplete, it is still possible to diagnose an array access which precedes the array bounds. This is a follow-up on D55862 which added an early return when the type of the base expression after IgnoreParenCasts was incomplete. Differential Revision: https://reviews.llvm.org/D56050 Reviewed By: efriedma llvm-svn: 350622
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r--clang/lib/Sema/SemaChecking.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index b9284a5b467..cd96200b817 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -12383,12 +12383,6 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
return;
const Type *BaseType = ArrayTy->getElementType().getTypePtr();
- // It is possible that the type of the base expression after IgnoreParenCasts
- // is incomplete, even though the type of the base expression before
- // IgnoreParenCasts is complete (see PR39746 for an example). In this case we
- // have no information about whether the array access is out-of-bounds.
- if (BaseType->isIncompleteType())
- return;
Expr::EvalResult Result;
if (!IndexExpr->EvaluateAsInt(Result, Context, Expr::SE_AllowSideEffects))
@@ -12405,6 +12399,15 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
ND = ME->getMemberDecl();
if (index.isUnsigned() || !index.isNegative()) {
+ // It is possible that the type of the base expression after
+ // IgnoreParenCasts is incomplete, even though the type of the base
+ // expression before IgnoreParenCasts is complete (see PR39746 for an
+ // example). In this case we have no information about whether the array
+ // access exceeds the array bounds. However we can still diagnose an array
+ // access which precedes the array bounds.
+ if (BaseType->isIncompleteType())
+ return;
+
llvm::APInt size = ArrayTy->getSize();
if (!size.isStrictlyPositive())
return;
OpenPOWER on IntegriCloud