[clang-tools-extra] r178167 - cpp11-migrate segfaults transforming map<string, int>::iterator
Ariel J. Bernal
ariel.j.bernal at intel.com
Wed Mar 27 11:49:31 PDT 2013
Author: ajbernal
Date: Wed Mar 27 13:49:31 2013
New Revision: 178167
URL: http://llvm.org/viewvc/llvm-project?rev=178167&view=rev
Log:
cpp11-migrate segfaults transforming map<string,int>::iterator
cpp11-migrate segfaults when -use-auto tries to resolve initializing
expression resulting in an expression with cleanups.
- Skip expressions with cleanups from the initializer
- Added test case
Fixes PR15550
Modified:
clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAutoActions.cpp
clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/Inputs/test_std_container.h
clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/iterator.cpp
Modified: clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAutoActions.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAutoActions.cpp?rev=178167&r1=178166&r2=178167&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAutoActions.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAutoActions.cpp Wed Mar 27 13:49:31 2013
@@ -28,7 +28,14 @@ void UseAutoFixer::run(const MatchFinder
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");
Modified: clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/Inputs/test_std_container.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/Inputs/test_std_container.h?rev=178167&r1=178166&r2=178167&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/Inputs/test_std_container.h (original)
+++ clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/Inputs/test_std_container.h Wed Mar 27 13:49:31 2013
@@ -107,6 +107,9 @@ public:
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
Modified: clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/iterator.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/iterator.cpp?rev=178167&r1=178166&r2=178167&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/iterator.cpp (original)
+++ clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/iterator.cpp Wed Mar 27 13:49:31 2013
@@ -148,5 +148,13 @@ int main(int argc, char **argv) {
// CHECK: auto && I2 = Vec.begin();
}
+ // Passing a string as an argument to introduce a temporary object
+ // that will create an expression with cleanups. Bugzilla: 15550
+ {
+ std::unordered_map<int> MapFind;
+ std::unordered_map<int>::iterator I = MapFind.find("foo");
+ // CHECK: auto I = MapFind.find("foo");
+ }
+
return 0;
}
More information about the cfe-commits
mailing list