[PATCH] D24484: [analyzer] Fix ExprEngine::VisitMemberExpr

Alexander Shaposhnikov via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 12 17:23:40 PDT 2016


alexshap created this revision.
alexshap added reviewers: NoQ, bcraig, zaks.anna.
alexshap added a subscriber: cfe-commits.
alexshap set the repository for this revision to rL LLVM.
alexshap changed the visibility of this Differential Revision from "Public (No Login Required)" to "All Users".

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 

Repository:
  rL LLVM

https://reviews.llvm.org/D24484

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

Index: test/Analysis/array-struct.c
===================================================================
--- test/Analysis/array-struct.c
+++ test/Analysis/array-struct.c
@@ -135,6 +135,17 @@
 
 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];
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===================================================================
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -2044,7 +2044,7 @@
         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");
           }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24484.71082.patch
Type: text/x-patch
Size: 1117 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160913/5220d631/attachment-0001.bin>


More information about the cfe-commits mailing list