[analyzer] Fix ExprEngine::VisitMemberExpr
authorAlexander Shaposhnikov <shal1t712@gmail.com>
Tue, 13 Sep 2016 19:17:20 +0000 (19:17 +0000)
committerAlexander Shaposhnikov <shal1t712@gmail.com>
Tue, 13 Sep 2016 19:17:20 +0000 (19:17 +0000)
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

llvm-svn: 281373

clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/test/Analysis/array-struct.c

index 97f4d9f..a99ee88 100644 (file)
@@ -2044,7 +2044,7 @@ void ExprEngine::VisitMemberExpr(const MemberExpr *M, ExplodedNode *Pred,
         if (!M->isGLValue()) {
           assert(M->getType()->isArrayType());
           const ImplicitCastExpr *PE =
-            dyn_cast<ImplicitCastExpr>((*I)->getParentMap().getParent(M));
+            dyn_cast<ImplicitCastExpr>((*I)->getParentMap().getParentIgnoreParens(M));
           if (!PE || PE->getCastKind() != CK_ArrayToPointerDecay) {
             llvm_unreachable("should always be wrapped in ArrayToPointerDecay");
           }
index 28e09ad..18f226a 100644 (file)
@@ -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];