Patchwork C++ PATCH for c++/62302 (wrong comdat group)

login
register
mail settings
Submitter Jason Merrill
Date Aug. 31, 2014, 6:20 p.m.
Message ID <54036781.3020002@redhat.com>
Download mbox | patch
Permalink /patch/384555/
State New
Headers show

Comments

Jason Merrill - Aug. 31, 2014, 6:20 p.m.
Honza's earlier change to the assert at the end of cdtor_comdat_group 
was wrong; we really do need to make sure that we've created the '5' 
group that we want.  This is complicated by the change to alias creation 
that automatically copies DECL_COMDAT_GROUP over, but since comdat 
groups are copied from DECL_ASSEMBLER_NAME anyway, we can just look 
there to find the names we want.

Tested x86_64-pc-linux-gnu, applying to trunk.

Patch

commit fad4e2d51d8773fb1297f51cc8771fd14635a4b0
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Aug 29 17:23:14 2014 -0400

    	PR c++/62302
    	* optimize.c (cdtor_comdat_group): Just look at the
    	DECL_ASSEMBLER_NAME of the 'tors.

diff --git a/gcc/cp/optimize.c b/gcc/cp/optimize.c
index f9a236e..31acb07 100644
--- a/gcc/cp/optimize.c
+++ b/gcc/cp/optimize.c
@@ -159,18 +159,12 @@  build_delete_destructor_body (tree delete_dtor, tree complete_dtor)
 static tree
 cdtor_comdat_group (tree complete, tree base)
 {
-  tree complete_name = DECL_COMDAT_GROUP (complete);
-  tree base_name = DECL_COMDAT_GROUP (base);
+  tree complete_name = DECL_ASSEMBLER_NAME (complete);
+  tree base_name = DECL_ASSEMBLER_NAME (base);
   char *grp_name;
   const char *p, *q;
   bool diff_seen = false;
   size_t idx;
-  if (complete_name == NULL)
-    complete_name = cxx_comdat_group (complete);
-  if (base_name == NULL)
-    base_name = cxx_comdat_group (base);
-  complete_name = DECL_ASSEMBLER_NAME (complete_name);
-  base_name = DECL_ASSEMBLER_NAME (base_name);
   gcc_assert (IDENTIFIER_LENGTH (complete_name)
 	      == IDENTIFIER_LENGTH (base_name));
   grp_name = XALLOCAVEC (char, IDENTIFIER_LENGTH (complete_name) + 1);
@@ -190,7 +184,7 @@  cdtor_comdat_group (tree complete, tree base)
 	diff_seen = true;
       }
   grp_name[idx] = '\0';
-  gcc_assert (diff_seen || symtab_node::get (complete)->alias);
+  gcc_assert (diff_seen);
   return get_identifier (grp_name);
 }
 
diff --git a/gcc/testsuite/g++.dg/abi/comdat1.C b/gcc/testsuite/g++.dg/abi/comdat1.C
new file mode 100644
index 0000000..e1025e3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/comdat1.C
@@ -0,0 +1,13 @@ 
+// PR c++/62302
+
+// { dg-do compile { target *-*-*gnu* } }
+// { dg-final { scan-assembler "_ZN3optIiED5Ev,comdat" } }
+// { dg-final { scan-assembler-not "_ZN3optIiED0Ev,comdat" } }
+// { dg-final { scan-assembler-not "_ZN3optIiED1Ev,comdat" } }
+// { dg-final { scan-assembler-not "_ZN3optIiED2Ev,comdat" } }
+
+struct Option {
+  virtual ~Option() {}
+};
+template <class DataType> class opt : public Option {};
+template class opt<int>;