[cfe-commits] r166529 - in /cfe/trunk: lib/StaticAnalyzer/Core/ExprEngine.cpp test/Analysis/member-expr.cpp

Jordan Rose jordan_rose at apple.com
Tue Oct 23 16:59:09 PDT 2012


Author: jrose
Date: Tue Oct 23 18:59:08 2012
New Revision: 166529

URL: http://llvm.org/viewvc/llvm-project?rev=166529&view=rev
Log:
[analyzer] Handle 'SomeVar.SomeEnumConstant', which is legal in C++.

This caused assertion failures analyzing LLVM.

<rdar://problem/12560282>

Added:
    cfe/trunk/test/Analysis/member-expr.cpp
Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=166529&r1=166528&r2=166529&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Tue Oct 23 18:59:08 2012
@@ -1512,13 +1512,13 @@
 
   StmtNodeBuilder Bldr(Pred, TopDst, *currBldrCtx);
   ExplodedNodeSet Dst;
-  Decl *member = M->getMemberDecl();
+  ValueDecl *Member = M->getMemberDecl();
 
-  // Handle static member variables accessed via member syntax.
-  if (VarDecl *VD = dyn_cast<VarDecl>(member)) {
-    assert(M->isGLValue());
+  // Handle static member variables and enum constants accessed via
+  // member syntax.
+  if (isa<VarDecl>(Member) || isa<EnumConstantDecl>(Member)) {
     Bldr.takeNodes(Pred);
-    VisitCommonDeclRefExpr(M, VD, Pred, Dst);
+    VisitCommonDeclRefExpr(M, Member, Pred, Dst);
     Bldr.addNodes(Dst);
     return;
   }
@@ -1528,7 +1528,7 @@
   Expr *BaseExpr = M->getBase();
 
   // Handle C++ method calls.
-  if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(member)) {
+  if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(Member)) {
     if (MD->isInstance())
       state = createTemporaryRegionIfNeeded(state, LCtx, BaseExpr);
 
@@ -1543,7 +1543,7 @@
   state = createTemporaryRegionIfNeeded(state, LCtx, BaseExpr);
   SVal baseExprVal = state->getSVal(BaseExpr, LCtx);
 
-  FieldDecl *field = cast<FieldDecl>(member);
+  FieldDecl *field = cast<FieldDecl>(Member);
   SVal L = state->getLValue(field, baseExprVal);
   if (M->isGLValue()) {
     if (field->getType()->isReferenceType()) {

Added: cfe/trunk/test/Analysis/member-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/member-expr.cpp?rev=166529&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/member-expr.cpp (added)
+++ cfe/trunk/test/Analysis/member-expr.cpp Tue Oct 23 18:59:08 2012
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection %s -verify
+
+void clang_analyzer_eval(int);
+
+namespace EnumsViaMemberExpr {
+  struct Foo {
+    enum E {
+      Bar = 1
+    };
+  };
+
+  void testEnumVal(Foo Baz) {
+    clang_analyzer_eval(Baz.Bar == Foo::Bar); // expected-warning{{TRUE}}
+  }
+
+  void testEnumRef(Foo &Baz) {
+    clang_analyzer_eval(Baz.Bar == Foo::Bar); // expected-warning{{TRUE}}
+  }
+
+  void testEnumPtr(Foo *Baz) {
+    clang_analyzer_eval(Baz->Bar == Foo::Bar); // expected-warning{{TRUE}}
+  }
+}
\ No newline at end of file





More information about the cfe-commits mailing list