[PATCH] D56917: [clang] add tests to ExprMutAnalyzer that reproduced a crash in ASTMatchers

Jonas Toth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 18 08:56:49 PST 2019


JonasToth created this revision.
JonasToth added reviewers: aaron.ballman, sammccall, rsmith.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, Szelethus, a.sidorin, baloghadamsoftware.
Herald added a reviewer: george.karpenkov.

This patch adds two unit-tests that are the result of reducing a crashing TU
when running ExprMutAnalyzer over it. They are added only to ensure the regression
that has been fixed with https://reviews.llvm.org/D56444 don't creep back.


Repository:
  rC Clang

https://reviews.llvm.org/D56917

Files:
  unittests/Analysis/ExprMutationAnalyzerTest.cpp


Index: unittests/Analysis/ExprMutationAnalyzerTest.cpp
===================================================================
--- unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -1109,4 +1109,48 @@
   EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x->mf()"));
 }
 
+TEST(ExprMutationAnalyzerTest, ReproduceFailure11) {
+  const std::string Reproducer =
+      "namespace std {"
+      "template <class a> a&& forward(a & A) { return static_cast<a&&>(A); }"
+      "template <class _Fp> struct __bind {"
+      "_Fp d;"
+      "template <class e> __bind(_Fp f, e &&) : d(forward(f)) {}"
+      "};"
+      "template <class _Fp, class h> void bind(_Fp f, h && g) {"
+      "__bind<_Fp>(f, g);"
+      "}"
+      "template <typename i, typename j> void async(i f, j && g) {"
+      "bind(f, g);"
+      "}"
+      "}"
+      "void k() {"
+      "int x = 42;"
+      "std::async([] {}, x);"
+      "}";
+  auto AST11 = buildASTFromCodeWithArgs(Reproducer, {"-std=c++11"});
+  auto Results11 =
+      match(withEnclosingCompound(declRefTo("x")), AST11->getASTContext());
+  EXPECT_FALSE(isMutated(Results11, AST11.get()));
+}
+
+TEST(ExprMutationAnalyzerTest, ReproduceFailureMinimal) {
+  const std::string Reproducer =
+      "namespace std {"
+      "template <class T> T forward(T & A) { return static_cast<T&&>(A); }"
+      "template <class T> struct __bind {"
+      "  T f;"
+      "  template <class V> __bind(T v, V &&) : f(forward(v)) {}"
+      "};"
+      "}"
+      "void f() {"
+      "  int x = 42;"
+      "  auto Lambda = [] {};"
+      "  std::__bind<decltype(Lambda)>(Lambda, x);"
+      "}";
+  auto AST11 = buildASTFromCodeWithArgs(Reproducer, {"-std=c++11"});
+  auto Results11 =
+      match(withEnclosingCompound(declRefTo("x")), AST11->getASTContext());
+  EXPECT_FALSE(isMutated(Results11, AST11.get()));
+}
 } // namespace clang


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56917.182533.patch
Type: text/x-patch
Size: 1913 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190118/344b38b4/attachment.bin>


More information about the cfe-commits mailing list