Patchwork Fix small vtable verification bugs.

login
register
mail settings
Submitter Caroline Tice
Date Dec. 6, 2013, 7:30 p.m.
Message ID <CABtf2+TCcgL+cRBAR9Ww528OWvsCQNwmpwNPi8e4DKZX4ihO3A@mail.gmail.com>
Download mbox | patch
Permalink /patch/298226/
State New
Headers show

Comments

Caroline Tice - Dec. 6, 2013, 7:30 p.m.
The attached  patch fixes two small problems with the current vtable
verification code:  it makes the libvtv function decls globally
visible, and it  updates all uses of the verified vtable pointer with
the verification results, rather than just the first use.

I have bootstrapped the compiler with this patch, both with and
without vtable verification enabled, and have run the regression
testsuites, both with and without vtable verification enabled, with no
regressions.  I have only tested this on Linux.

Is this patch OK to commit?

-- Caroline Tice
cmtice@google.com

gcc ChangeLog:

2013-12-06  Caroline Tice  <cmtice@google.com>

        Submitting patch from Stephen Checkoway, s@cs.jhu.edu
        * vtable-class-hierarchy.c (init_functions): Make the libvtv
function decls externally visible.


gcc/cp ChangeLog:

2013-12-06  Caroline Tice  <cmtice@google.com>

        Submitting patch from Stephen Checkoway, s@cs.jhu.edu
        * vtable-class-hierarchy.c (init_functions): Make the libvtv
        function decls externally visible.
Jeff Law - Dec. 6, 2013, 8:48 p.m.
On 12/06/13 12:30, Caroline Tice wrote:
> The attached  patch fixes two small problems with the current vtable
> verification code:  it makes the libvtv function decls globally
> visible, and it  updates all uses of the verified vtable pointer with
> the verification results, rather than just the first use.
>
> I have bootstrapped the compiler with this patch, both with and
> without vtable verification enabled, and have run the regression
> testsuites, both with and without vtable verification enabled, with no
> regressions.  I have only tested this on Linux.
>
> Is this patch OK to commit?
>
> -- Caroline Tice
> cmtice@google.com
>
> gcc ChangeLog:
>
> 2013-12-06  Caroline Tice  <cmtice@google.com>
>
>          Submitting patch from Stephen Checkoway, s@cs.jhu.edu
>          * vtable-class-hierarchy.c (init_functions): Make the libvtv
> function decls externally visible.
>
>
> gcc/cp ChangeLog:
>
> 2013-12-06  Caroline Tice  <cmtice@google.com>
>
>          Submitting patch from Stephen Checkoway, s@cs.jhu.edu
>          * vtable-class-hierarchy.c (init_functions): Make the libvtv
>          function decls externally visible.
OK.
jeff

Patch

Index: gcc/cp/vtable-class-hierarchy.c
===================================================================
--- gcc/cp/vtable-class-hierarchy.c	(revision 205756)
+++ gcc/cp/vtable-class-hierarchy.c	(working copy)
@@ -258,6 +258,7 @@  init_functions (void)
   DECL_ATTRIBUTES (vlt_register_set_fndecl) =
                     tree_cons (get_identifier ("leaf"), NULL,
                                DECL_ATTRIBUTES (vlt_register_set_fndecl));
+  DECL_EXTERNAL(vlt_register_set_fndecl) = 1;
   TREE_PUBLIC (vlt_register_set_fndecl) = 1;
   DECL_PRESERVE_P (vlt_register_set_fndecl) = 1;
   SET_DECL_LANGUAGE (vlt_register_set_fndecl, lang_cplusplus);
@@ -301,6 +302,7 @@  init_functions (void)
   DECL_ATTRIBUTES (vlt_register_pairs_fndecl) =
                     tree_cons (get_identifier ("leaf"), NULL,
                                DECL_ATTRIBUTES (vlt_register_pairs_fndecl));
+  DECL_EXTERNAL(vlt_register_pairs_fndecl) = 1;
   TREE_PUBLIC (vlt_register_pairs_fndecl) = 1;
   DECL_PRESERVE_P (vlt_register_pairs_fndecl) = 1;
   SET_DECL_LANGUAGE (vlt_register_pairs_fndecl, lang_cplusplus);
Index: gcc/vtable-verify.c
===================================================================
--- gcc/vtable-verify.c	(revision 205756)
+++ gcc/vtable-verify.c	(working copy)
@@ -646,9 +646,6 @@  verify_bb_vtables (basic_block bb)
 
               if (vtable_map_node && vtable_map_node->vtbl_map_decl)
                 {
-                  use_operand_p use_p;
-                  ssa_op_iter iter;
-
                   vtable_map_node->is_used = true;
                   vtbl_var_decl = vtable_map_node->vtbl_map_decl;
 
@@ -695,35 +692,27 @@  verify_bb_vtables (basic_block bb)
                   gimple_call_set_lhs (call_stmt, tmp0);
                   update_stmt (call_stmt);
 
-                  /* Find the next stmt, after the vptr assignment
-                     statememt, which should use the result of the
-                     vptr assignment statement value. */
-                  gsi_next (&gsi_vtbl_assign);
-                  gimple next_stmt = gsi_stmt (gsi_vtbl_assign);
-
-                  if (!next_stmt)
-                    return;
-
-                  /* Find any/all uses of 'lhs' in next_stmt, and
-                     replace them with 'tmp0'.  */
+                  /* Replace all uses of lhs with tmp0. */
                   found = false;
-                  FOR_EACH_PHI_OR_STMT_USE (use_p, next_stmt, iter,
-                                            SSA_OP_ALL_USES)
+                  imm_use_iterator iterator;
+                  gimple use_stmt;
+                  FOR_EACH_IMM_USE_STMT (use_stmt, iterator, lhs)
                     {
-                      tree op = USE_FROM_PTR (use_p);
-                      if (op == lhs)
-                        {
-                          SET_USE (use_p, tmp0);
-                          found = true;
-                        }
+                      use_operand_p use_p;
+                      if (use_stmt == call_stmt)
+                        continue;
+                      FOR_EACH_IMM_USE_ON_STMT (use_p, iterator)
+                        SET_USE (use_p, tmp0);
+                      update_stmt (use_stmt);
+                      found = true;
                     }
-                  update_stmt (next_stmt);
+
                   gcc_assert (found);
 
                   /* Insert the new verification call just after the
                      statement that gets the vtable pointer out of the
                      object.  */
-                  gsi_vtbl_assign = gsi_for_stmt (stmt);
+                  gcc_assert (gsi_stmt (gsi_vtbl_assign) == stmt);
                   gsi_insert_after (&gsi_vtbl_assign, call_stmt,
                                     GSI_NEW_STMT);