[libcxxabi] r200864 - Fix PR17222 - catching derived classes from thrown null pointer. Adds tests, too

Marshall Clow mclow.lists at gmail.com
Wed Feb 5 10:19:57 PST 2014


Author: marshall
Date: Wed Feb  5 12:19:57 2014
New Revision: 200864

URL: http://llvm.org/viewvc/llvm-project?rev=200864&view=rev
Log:
Fix PR17222 - catching derived classes from thrown null pointer. Adds tests, too

Modified:
    libcxxabi/trunk/src/private_typeinfo.cpp
    libcxxabi/trunk/test/catch_ptr_02.cpp

Modified: libcxxabi/trunk/src/private_typeinfo.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/private_typeinfo.cpp?rev=200864&r1=200863&r2=200864&view=diff
==============================================================================
--- libcxxabi/trunk/src/private_typeinfo.cpp (original)
+++ libcxxabi/trunk/src/private_typeinfo.cpp Wed Feb  5 12:19:57 2014
@@ -388,7 +388,8 @@ __pointer_type_info::can_catch(const __s
     thrown_class_type->has_unambiguous_public_base(&info, adjustedPtr, public_path);
     if (info.path_dst_ptr_to_static_ptr == public_path)
     {
-        adjustedPtr = const_cast<void*>(info.dst_ptr_leading_to_static_ptr);
+        if (adjustedPtr != NULL)
+            adjustedPtr = const_cast<void*>(info.dst_ptr_leading_to_static_ptr);
         return true;
     }
     return false;

Modified: libcxxabi/trunk/test/catch_ptr_02.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/catch_ptr_02.cpp?rev=200864&r1=200863&r2=200864&view=diff
==============================================================================
--- libcxxabi/trunk/test/catch_ptr_02.cpp (original)
+++ libcxxabi/trunk/test/catch_ptr_02.cpp Wed Feb  5 12:19:57 2014
@@ -33,7 +33,7 @@ void test2 ()
 {
     try
      {
-    	throw &a;
+        throw &a;
         assert(false);
     }
     catch ( A* )
@@ -77,10 +77,85 @@ void test4 ()
     }
 }
 
+struct base1 {int x;};
+struct base2 {int x;};
+struct derived : base1, base2 {};
+
+void test5 ()
+{
+    try
+    {
+        throw (derived*)0;
+        assert(false);
+    }
+    catch (base2 *p) {
+        assert (p == 0);
+    }
+    catch (...)
+    {
+        assert (false);
+    }
+}
+
+void test6 ()
+{
+    try
+    {
+        throw nullptr;
+        assert(false);
+    }
+    catch (base2 *p) {
+        assert (p == nullptr);
+    }
+    catch (...)
+    {
+        assert (false);
+    }
+}
+
+void test7 ()
+{
+    try
+    {
+        throw (derived*)12;
+        assert(false);
+    }
+    catch (base2 *p) {
+        assert ((unsigned long)p == 12+sizeof(base1));
+    }
+    catch (...)
+    {
+        assert (false);
+    }
+}
+
+
+struct vA {};
+struct vC : virtual public vA {};
+
+void test8 ()
+{
+    try
+    {
+        throw (vC*)0;
+        assert(false);
+    }
+    catch (vA *p) {
+        assert(p == 0);
+    }
+    catch (...)
+    {
+        assert (false);
+    }
+}
+
 int main()
 {
     test1();
     test2();
     test3();
     test4();
+    test5();
+    test6();
+    test7();
 }





More information about the cfe-commits mailing list