[test-suite] r203860 - Adding a few more EH tests to Regression/C++

Renato Golin renato.golin at linaro.org
Thu Mar 13 15:30:11 PDT 2014


Author: rengolin
Date: Thu Mar 13 17:30:11 2014
New Revision: 203860

URL: http://llvm.org/viewvc/llvm-project?rev=203860&view=rev
Log:
Adding a few more EH tests to Regression/C++

Adding a few more corner cases to EH testing, all passing on both
x86_64 and ARM. If this breaks any other architecture, feel free to
revert and open a bug in bugzilla.


Added:
    test-suite/trunk/SingleSource/Regression/C++/EH/class_hierarchy.cpp
    test-suite/trunk/SingleSource/Regression/C++/EH/class_hierarchy.reference_output
Modified:
    test-suite/trunk/SingleSource/Regression/C++/EH/ctor_dtor_count.cpp
    test-suite/trunk/SingleSource/Regression/C++/EH/ctor_dtor_count.reference_output
    test-suite/trunk/SingleSource/Regression/C++/EH/inlined_cleanup.cpp
    test-suite/trunk/SingleSource/Regression/C++/EH/inlined_cleanup.reference_output

Added: test-suite/trunk/SingleSource/Regression/C++/EH/class_hierarchy.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Regression/C%2B%2B/EH/class_hierarchy.cpp?rev=203860&view=auto
==============================================================================
--- test-suite/trunk/SingleSource/Regression/C++/EH/class_hierarchy.cpp (added)
+++ test-suite/trunk/SingleSource/Regression/C++/EH/class_hierarchy.cpp Thu Mar 13 17:30:11 2014
@@ -0,0 +1,76 @@
+#include <cassert>
+#include <cstdio>
+#include <cstring>
+#include <exception>
+
+class Base : public std::exception {
+protected:
+  unsigned n;
+  char * desc;
+  void init(unsigned N, const char* name) {
+    n = N;
+    desc = new char[10+strlen(name)];
+    sprintf(desc, "n: %s class", name);
+  }
+  Base () {}
+public:
+  Base (unsigned N) {
+    assert(N < 10);
+    init(N, "base");
+  }
+  const char * what() {
+    desc[0] = (n+'0');
+    return desc;
+  }
+};
+
+class Derived : public Base {
+public:
+  Derived (unsigned n) {
+    assert(n < 20);
+    init(n-10, "derived");
+  }
+};
+
+class Unused : public Base {
+public:
+  Unused() : Base(0) {}
+};
+
+class Unused2 : public std::exception {
+};
+
+class Unused3 {
+};
+
+void func (unsigned n) {
+  if (n < 10)
+    throw(Base(n));
+  else if (n < 20)
+    throw(Derived(n));
+  else if (n < 21)
+    throw (Unused());
+  else if (n < 22)
+    throw (Unused2());
+  else if (n < 23)
+    throw (std::exception());
+  else
+    throw "what?";
+}
+
+int main() {
+  for (unsigned i=0; i<25; i++) {
+    try {
+      func(i);
+    } catch (Derived &e) {
+      printf("Caught exception: %s\n", e.what());
+    } catch (Base &e) {
+      printf("Caught exception: %s\n", e.what());
+    } catch (std::exception &e) {
+      printf("Caught exception: %s\n", e.what());
+    } catch (...) {
+      printf("Caught unknown exception\n");
+    }
+  }
+  return 0;
+}

Added: test-suite/trunk/SingleSource/Regression/C++/EH/class_hierarchy.reference_output
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Regression/C%2B%2B/EH/class_hierarchy.reference_output?rev=203860&view=auto
==============================================================================
--- test-suite/trunk/SingleSource/Regression/C++/EH/class_hierarchy.reference_output (added)
+++ test-suite/trunk/SingleSource/Regression/C++/EH/class_hierarchy.reference_output Thu Mar 13 17:30:11 2014
@@ -0,0 +1,26 @@
+Caught exception: 0: base class
+Caught exception: 1: base class
+Caught exception: 2: base class
+Caught exception: 3: base class
+Caught exception: 4: base class
+Caught exception: 5: base class
+Caught exception: 6: base class
+Caught exception: 7: base class
+Caught exception: 8: base class
+Caught exception: 9: base class
+Caught exception: 0: derived class
+Caught exception: 1: derived class
+Caught exception: 2: derived class
+Caught exception: 3: derived class
+Caught exception: 4: derived class
+Caught exception: 5: derived class
+Caught exception: 6: derived class
+Caught exception: 7: derived class
+Caught exception: 8: derived class
+Caught exception: 9: derived class
+Caught exception: 0: base class
+Caught exception: std::exception
+Caught exception: std::exception
+Caught unknown exception
+Caught unknown exception
+exit 0

Modified: test-suite/trunk/SingleSource/Regression/C++/EH/ctor_dtor_count.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Regression/C%2B%2B/EH/ctor_dtor_count.cpp?rev=203860&r1=203859&r2=203860&view=diff
==============================================================================
--- test-suite/trunk/SingleSource/Regression/C++/EH/ctor_dtor_count.cpp (original)
+++ test-suite/trunk/SingleSource/Regression/C++/EH/ctor_dtor_count.cpp Thu Mar 13 17:30:11 2014
@@ -13,11 +13,82 @@ struct B {
   B() { A a; throw 1; }
 };
 
-int main() {
+int simple() {
   try {
     B b;
   } catch (...) {}
-  if (!c) printf("All ok!\n");
+  if (!c) printf("Deriv ok!\n");
+  try {
+    B* b = new B();
+  } catch (...) {}
+  if (!c) printf("Deriv pointer ok!\n");
+  try {
+    throw A();
+  } catch (...) {}
+  if (!c) printf("Base ok!\n");
+  try {
+    throw new A();
+  } catch (A *a) {delete a;}
+  if (!c) printf("Base pointer ok!\n");
+  try {
+    A a;
+    throw A(a);
+  } catch (A &a) {}
+  if (!c) printf("Copy ok!\n");
+  try {
+    A a;
+    throw new A(a);
+  } catch (A *a) {delete a;}
+  if (!c) printf("Copy pointer ok!\n");
   return c;
 }
 
+static int k;
+
+struct C : public A {
+  C() : A() { ++k; }
+};
+
+struct T {
+  T(int a) {
+    if (a < 0)
+      throw a;
+  }
+};
+
+struct M {
+  A a;
+  T t;
+  C c;
+  M(int n) : t(n) {}
+};
+
+int member() {
+  try {
+    M(10);
+  } catch (...) {
+    printf("ooops\n");
+    return 1;
+  }
+  if (!c && k == 1) printf("Member positive ok!\n");
+  try {
+    M(0);
+  } catch (...) {
+    printf("ooops\n");
+    return 1;
+  }
+  if (!c && k == 2) printf("Member zero ok!\n");
+  try {
+    M(-10);
+    printf("ooops\n");
+    return 1;
+  } catch (...) {
+    printf("caught negative T\n");
+  }
+  if (!c && k == 2) printf("Member negative ok!\n");
+  return c;
+}
+
+int main() {
+  return simple() + member();
+}

Modified: test-suite/trunk/SingleSource/Regression/C++/EH/ctor_dtor_count.reference_output
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Regression/C%2B%2B/EH/ctor_dtor_count.reference_output?rev=203860&r1=203859&r2=203860&view=diff
==============================================================================
--- test-suite/trunk/SingleSource/Regression/C++/EH/ctor_dtor_count.reference_output (original)
+++ test-suite/trunk/SingleSource/Regression/C++/EH/ctor_dtor_count.reference_output Thu Mar 13 17:30:11 2014
@@ -1,2 +1,11 @@
-All ok!
+Deriv ok!
+Deriv pointer ok!
+Base ok!
+Base pointer ok!
+Copy ok!
+Copy pointer ok!
+Member positive ok!
+Member zero ok!
+caught negative T
+Member negative ok!
 exit 0

Modified: test-suite/trunk/SingleSource/Regression/C++/EH/inlined_cleanup.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Regression/C%2B%2B/EH/inlined_cleanup.cpp?rev=203860&r1=203859&r2=203860&view=diff
==============================================================================
--- test-suite/trunk/SingleSource/Regression/C++/EH/inlined_cleanup.cpp (original)
+++ test-suite/trunk/SingleSource/Regression/C++/EH/inlined_cleanup.cpp Thu Mar 13 17:30:11 2014
@@ -1,14 +1,19 @@
-#include <stdio.h>
+#include <cstdio>
+#include <cstring>
 
 class Cleanup {
+  char name[10];
 public:
+  Cleanup(const char* n) {
+    strcpy(name, n);
+  }
   ~Cleanup() {
-    printf("In cleanup!\n");
+    printf("Cleanup for %s!\n", name);
   }
 };
 
 static void foo() {
-  Cleanup C;
+  Cleanup C("num");
   throw 3;
 }
 
@@ -18,5 +23,20 @@ int main(void) {
   } catch (int i) {
     printf("Caught %d!\n", i);
   }
+  try {
+    Cleanup a("a");
+    throw Cleanup("c");
+    Cleanup b("b");
+  } catch (Cleanup &c) {
+    printf("Caught cleanup!\n");
+  }
+  try {
+    Cleanup a("ap");
+    throw new Cleanup("cp");
+    Cleanup b("bp");
+  } catch (Cleanup *c) {
+    printf("Caught cleanup!\n");
+    delete c;
+  }
   return 0;
 }

Modified: test-suite/trunk/SingleSource/Regression/C++/EH/inlined_cleanup.reference_output
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Regression/C%2B%2B/EH/inlined_cleanup.reference_output?rev=203860&r1=203859&r2=203860&view=diff
==============================================================================
--- test-suite/trunk/SingleSource/Regression/C++/EH/inlined_cleanup.reference_output (original)
+++ test-suite/trunk/SingleSource/Regression/C++/EH/inlined_cleanup.reference_output Thu Mar 13 17:30:11 2014
@@ -1,3 +1,9 @@
-In cleanup!
+Cleanup for num!
 Caught 3!
+Cleanup for a!
+Caught cleanup!
+Cleanup for c!
+Cleanup for ap!
+Caught cleanup!
+Cleanup for cp!
 exit 0





More information about the llvm-commits mailing list