[cfe-commits] r154611 - in /cfe/trunk: lib/Analysis/CFG.cpp test/Analysis/lambdas.cpp

Ted Kremenek kremenek at apple.com
Thu Apr 12 13:34:52 PDT 2012


Author: kremenek
Date: Thu Apr 12 15:34:52 2012
New Revision: 154611

URL: http://llvm.org/viewvc/llvm-project?rev=154611&view=rev
Log:
Include lambda capture init expressions in CFG.

Added:
    cfe/trunk/test/Analysis/lambdas.cpp
Modified:
    cfe/trunk/lib/Analysis/CFG.cpp

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=154611&r1=154610&r2=154611&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Thu Apr 12 15:34:52 2012
@@ -342,6 +342,7 @@
   CFGBlock *VisitImplicitCastExpr(ImplicitCastExpr *E, AddStmtChoice asc);
   CFGBlock *VisitIndirectGotoStmt(IndirectGotoStmt *I);
   CFGBlock *VisitLabelStmt(LabelStmt *L);
+  CFGBlock *VisitLambdaExpr(LambdaExpr *L);
   CFGBlock *VisitMemberExpr(MemberExpr *M, AddStmtChoice asc);
   CFGBlock *VisitObjCAtCatchStmt(ObjCAtCatchStmt *S);
   CFGBlock *VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S);
@@ -985,7 +986,6 @@
       return VisitBinaryOperator(cast<BinaryOperator>(S), asc);
 
     case Stmt::BlockExprClass:
-    case Stmt::LambdaExprClass:
       return VisitNoRecurse(cast<Expr>(S), asc);
 
     case Stmt::BreakStmtClass:
@@ -1066,6 +1066,9 @@
     case Stmt::LabelStmtClass:
       return VisitLabelStmt(cast<LabelStmt>(S));
 
+    case Stmt::LambdaExprClass:
+      return VisitLambdaExpr(cast<LambdaExpr>(S), asc);
+
     case Stmt::MemberExprClass:
       return VisitMemberExpr(cast<MemberExpr>(S), asc);
 
@@ -1718,6 +1721,19 @@
   return LabelBlock;
 }
 
+CFGBlock *CFGBuilder::VisitLambdaExpr(LambdaExpr *E, AddStmtChoice asc) {
+  CFGBlock *LastBlock = VisitNoRecurse(E, asc);
+  for (LambdaExpr::capture_init_iterator it = E->capture_init_begin(),
+       et = E->capture_init_end(); it != et; ++it) {
+    if (Expr *Init = *it) {
+      CFGBlock *Tmp = Visit(Init);
+      if (Tmp != 0)
+        LastBlock = Tmp;
+    }
+  }
+  return LastBlock;
+}
+  
 CFGBlock *CFGBuilder::VisitGotoStmt(GotoStmt *G) {
   // Goto is a control-flow statement.  Thus we stop processing the current
   // block and create a new one.

Added: cfe/trunk/test/Analysis/lambdas.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/lambdas.cpp?rev=154611&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/lambdas.cpp (added)
+++ cfe/trunk/test/Analysis/lambdas.cpp Thu Apr 12 15:34:52 2012
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -analyze -analyzer-checker=debug.DumpCFG %s > %t 2>&1
+// RUN: FileCheck --input-file=%t %s
+
+struct X { X(const X&); };
+void f(X x) { (void) [x]{}; }
+
+// CHECK: [B2 (ENTRY)]
+// CHECK:   Succs (1): B1
+// CHECK: [B1]
+// CHECK:   1: x
+// CHECK:   2: [B1.1] (ImplicitCastExpr, NoOp, const struct X)
+// CHECK:   3: [B1.2] (CXXConstructExpr, struct X)
+// CHECK:   4: [=x]     {
+// CHECK:    }
+// CHECK:   5: (void)[B1.4] (CStyleCastExpr, ToVoid, void)
+// CHECK:   Preds (1): B2
+// CHECK:   Succs (1): B0
+// CHECK: [B0 (EXIT)]
+// CHECK:   Preds (1): B1
+





More information about the cfe-commits mailing list