From 32a02648ebefcd05452b87f0bb6596afcdd58d46 Mon Sep 17 00:00:00 2001 From: Alexander Shaposhnikov Date: Tue, 13 Sep 2016 19:17:20 +0000 Subject: [PATCH] [analyzer] Fix ExprEngine::VisitMemberExpr AST may contain intermediate ParenExpr nodes between MemberExpr and ArrayToPointerDecay. This diff adjusts the check in ExprEngine::VisitMemberExpr accordingly. Test plan: make -j8 check-clang-analysis Differential revision: https://reviews.llvm.org/D24484 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@281373 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Core/ExprEngine.cpp | 2 +- test/Analysis/array-struct.c | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/StaticAnalyzer/Core/ExprEngine.cpp b/lib/StaticAnalyzer/Core/ExprEngine.cpp index 97f4d9fc19..a99ee88820 100644 --- a/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -2044,7 +2044,7 @@ void ExprEngine::VisitMemberExpr(const MemberExpr *M, ExplodedNode *Pred, if (!M->isGLValue()) { assert(M->getType()->isArrayType()); const ImplicitCastExpr *PE = - dyn_cast((*I)->getParentMap().getParent(M)); + dyn_cast((*I)->getParentMap().getParentIgnoreParens(M)); if (!PE || PE->getCastKind() != CK_ArrayToPointerDecay) { llvm_unreachable("should always be wrapped in ArrayToPointerDecay"); } diff --git a/test/Analysis/array-struct.c b/test/Analysis/array-struct.c index 28e09ad2e8..18f226a8ae 100644 --- a/test/Analysis/array-struct.c +++ b/test/Analysis/array-struct.c @@ -135,6 +135,17 @@ void f14() { void bar(int*); +struct s3 gets3() { + struct s3 s; + return s; +} + +void accessArrayFieldNoCrash() { + bar(gets3().a); + bar((gets3().a)); + bar(((gets3().a))); +} + // Test if the array is correctly invalidated. void f15() { int a[10]; -- 2.40.0