aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/decl.c12
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/ubsan/vptr-13.C19
4 files changed, 44 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 6ed074e..6ecd48d 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2018-08-29 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/87095
+ * decl.c (begin_destructor_body): If current_class_type has
+ virtual bases and the primary base is nearly empty virtual base,
+ voidify clearing of vptr and make it conditional on in-charge
+ argument.
+
2018-08-29 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/85265
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 7fee3da..c6711f7 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -15698,6 +15698,18 @@ begin_destructor_body (void)
tree stmt = cp_build_modify_expr (input_location, vtbl_ptr,
NOP_EXPR, vtbl,
tf_warning_or_error);
+ /* If the vptr is shared with some virtual nearly empty base,
+ don't clear it if not in charge, the dtor of the virtual
+ nearly empty base will do that later. */
+ if (CLASSTYPE_VBASECLASSES (current_class_type)
+ && CLASSTYPE_PRIMARY_BINFO (current_class_type)
+ && BINFO_VIRTUAL_P
+ (CLASSTYPE_PRIMARY_BINFO (current_class_type)))
+ {
+ stmt = convert_to_void (stmt, ICV_STATEMENT,
+ tf_warning_or_error);
+ stmt = build_if_in_charge (stmt);
+ }
finish_decl_cleanup (NULL_TREE, stmt);
}
else
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 78bbd7f..e38dab2 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2018-08-29 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/87095
+ * g++.dg/ubsan/vptr-13.C: New test.
+
2018-08-29 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/85265
diff --git a/gcc/testsuite/g++.dg/ubsan/vptr-13.C b/gcc/testsuite/g++.dg/ubsan/vptr-13.C
new file mode 100644
index 0000000..345581f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ubsan/vptr-13.C
@@ -0,0 +1,19 @@
+// PR c++/87095
+// { dg-do run }
+// { dg-options "-fsanitize=vptr -fno-sanitize-recover=vptr" }
+
+struct A
+{
+ virtual ~A () {}
+};
+
+struct B : virtual A {};
+
+struct C : B {};
+
+int
+main ()
+{
+ C c;
+ return 0;
+}