[PATCH] cpp11-migrate segfaults transforming map<string, int>::iterator

Ariel Bernal ariel.j.bernal at intel.com
Tue Mar 26 10:13:52 PDT 2013


Hi revane,

Bugzilla: 15550
cpp11-migrate segfaults when -use-auto tries to resolve initializing expression resulting in an expression with cleanups

http://llvm-reviews.chandlerc.com/D579

Files:
  cpp11-migrate/UseAuto/UseAutoActions.cpp
  test/cpp11-migrate/UseAuto/Inputs/test_std_container.h
  test/cpp11-migrate/UseAuto/iterator.cpp

Index: cpp11-migrate/UseAuto/UseAutoActions.cpp
===================================================================
--- cpp11-migrate/UseAuto/UseAutoActions.cpp
+++ cpp11-migrate/UseAuto/UseAutoActions.cpp
@@ -28,7 +28,14 @@
   if (!SM.isFromMainFile(D->getLocStart()))
     return;
 
-  const CXXConstructExpr *Construct = cast<CXXConstructExpr>(D->getInit());
+  const Expr *ExprInit = D->getInit();
+
+  // Skip expressions with cleanups from the initializer expression.
+  if (const ExprWithCleanups *E = dyn_cast<ExprWithCleanups>(ExprInit))
+    ExprInit = E->getSubExpr();
+
+  const CXXConstructExpr *Construct = cast<CXXConstructExpr>(ExprInit);
+
   assert(Construct->getNumArgs() == 1u &&
          "Expected constructor with single argument");
 
Index: test/cpp11-migrate/UseAuto/Inputs/test_std_container.h
===================================================================
--- test/cpp11-migrate/UseAuto/Inputs/test_std_container.h
+++ test/cpp11-migrate/UseAuto/Inputs/test_std_container.h
@@ -107,6 +107,9 @@
 
   const_reverse_iterator rbegin() const { return const_reverse_iterator(); }
   const_reverse_iterator rend() const { return const_reverse_iterator(); }
+
+  template <typename K>
+  iterator find(const K& key) { return iterator(); }
 };
 
 #if USE_INLINE_NAMESPACE
Index: test/cpp11-migrate/UseAuto/iterator.cpp
===================================================================
--- test/cpp11-migrate/UseAuto/iterator.cpp
+++ test/cpp11-migrate/UseAuto/iterator.cpp
@@ -148,5 +148,13 @@
     // CHECK: auto && I2 = Vec.begin();
   }
 
+  // Passing a string as an argument to introduce a temporary object
+  // that will create an expression with cleanups
+  std::unordered_map<int> MapFind;
+  {
+    std::unordered_map<int>::iterator it = MapFind.find("foo");
+    // CHECK: auto it = MapFind.find("foo");
+  }
+
   return 0;
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D579.1.patch
Type: text/x-patch
Size: 1863 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130326/251b904d/attachment.bin>


More information about the cfe-commits mailing list