public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [RFA] PR c++/40808
@ 2009-10-23 14:02 Dodji Seketeli
  2009-10-23 16:13 ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Dodji Seketeli @ 2009-10-23 14:02 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason

Hello,

In this PR we crash during the mangling of a template-id that has an empty
argument list (e.g: foo<>). Please read
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40808 for the extensive
details.

Jason suggested the following (slight) change to the template arguments mangling specification:

-     <template-args> ::= I <template-arg>+ E
+     <template-args> ::= I <template-arg>* E

The patch below implements that change.

Tested against trunk and 4.4 on x86-64-unknown-linux-gnu.

Comments ?

Thanks.

commit 47d6944f5a162e87cdc51c46a4b84610216adb41
Author: Dodji Seketeli <dodji@redhat.com>
Date:   Fri Oct 23 14:02:19 2009 +0200

    Fix for PR c++/40808
    
    gcc/cp/ChangeLog:
    
    	PR c++/40808
    	* mangle.c (write_template_args): Allow mangling of empty template
    	arguments list. Updated function comment.
    
    gcc/testsuite/ChangeLog:
    
    	PR c++/40808
    	* g++.dg/abi/mangle33.C: New test

diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index d96a929..876930b 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -2284,21 +2284,22 @@ write_class_enum_type (const tree type)
 /* Non-terminal <template-args>.  ARGS is a TREE_VEC of template
    arguments.
 
-     <template-args> ::= I <template-arg>+ E  */
+     <template-args> ::= I <template-arg>* E  */
 
 static void
 write_template_args (tree args)
 {
   int i;
-  int length = TREE_VEC_LENGTH (args);
+  int length = 0;
 
   MANGLE_TRACE_TREE ("template-args", args);
 
   write_char ('I');
 
-  gcc_assert (length > 0);
+  if (args)
+    length = TREE_VEC_LENGTH (args);
 
-  if (TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
+  if (args && TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
     {
       /* We have nested template args.  We want the innermost template
 	 argument list.  */
diff --git a/gcc/testsuite/g++.dg/abi/mangle33.C b/gcc/testsuite/g++.dg/abi/mangle33.C
new file mode 100644
index 0000000..1312f79
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/mangle33.C
@@ -0,0 +1,41 @@
+// Contributed by Dodji Seketeli <dodji@redhat.com>
+// Origin PR c++/40808
+// { dg-do compile }
+// This tests the mangling of empty template argument list in a template
+// id.
+// { dg-final {scan-assembler "_ZNK5DummyclI3GenEENT_3SigIE10ResultTypeERKS2_" } }
+
+
+struct Void {};
+
+template <class R> struct FunType {
+  typedef R ResultType;
+};
+
+struct WrongNumberOfSigArgs {};
+
+template <typename R> struct CFunType {
+  template <class Dummy1=Void, class Dummy2=Void> struct Sig : public
+FunType<WrongNumberOfSigArgs> {};
+  template <class Dummy> struct Sig<Void,Dummy> : public FunType<R> {};
+};
+
+struct Dummy {
+  template <typename F> typename F::template Sig<>::ResultType operator()(F
+const& f) const {
+    return typename F::template Sig<>::ResultType(0);
+  }
+};
+
+struct Gen: public CFunType<int> {
+  int operator()() const {return 0;}
+  Gen() {}
+};
+
+int myfunction() {
+  return Dummy()(Gen());
+}
+
+int main() {
+  myfunction();
+}
-- 
Dodji Seketeli
Red Hat

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFA] PR c++/40808
  2009-10-23 14:02 [RFA] PR c++/40808 Dodji Seketeli
@ 2009-10-23 16:13 ` Jason Merrill
  2009-10-23 16:31   ` Dodji Seketeli
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2009-10-23 16:13 UTC (permalink / raw)
  To: Dodji Seketeli; +Cc: gcc-patches

On 10/23/2009 06:34 AM, Dodji Seketeli wrote:
> +// { dg-final {scan-assembler "_ZNK5DummyclI3GenEENT_3SigIE10ResultTypeERKS2_" } }

Does this test actually run without a space between { and scan-assembler?

Jason

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFA] PR c++/40808
  2009-10-23 16:13 ` Jason Merrill
@ 2009-10-23 16:31   ` Dodji Seketeli
  2009-10-23 20:07     ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Dodji Seketeli @ 2009-10-23 16:31 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

On Fri, Oct 23, 2009 at 08:47:28AM -0700, Jason Merrill wrote:
> On 10/23/2009 06:34 AM, Dodji Seketeli wrote:
>> +// { dg-final {scan-assembler "_ZNK5DummyclI3GenEENT_3SigIE10ResultTypeERKS2_" } }
>
> Does this test actually run without a space between { and scan-assembler?

Yes it does. But I have changed the line nevertheless.
Incidentally, Jakub noticed that my tree was a bit outdated as there now is
a mangle33.C file in the tree already. I have renamed the test file
to mangle34.C instead.

commit 00c533bedac6f1ca950d13b1287e726da9d0d1ec
Author: Dodji Seketeli <dodji@redhat.com>
Date:   Fri Oct 23 14:02:19 2009 +0200

    Fix for PR c++/40808
    
    gcc/cp/ChangeLog:
    
    	PR c++/40808
    	* mangle.c (write_template_args): Allow mangling of empty template
    	argument list. Updated function comments.
    
    gcc/testsuite/ChangeLog:
    
    	PR c++/40808
    	* g++.dg/abi/mangle34.C: New test

diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index f9a5503..d4bcbac 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -2284,21 +2284,22 @@ write_class_enum_type (const tree type)
 /* Non-terminal <template-args>.  ARGS is a TREE_VEC of template
    arguments.
 
-     <template-args> ::= I <template-arg>+ E  */
+     <template-args> ::= I <template-arg>* E  */
 
 static void
 write_template_args (tree args)
 {
   int i;
-  int length = TREE_VEC_LENGTH (args);
+  int length = 0;
 
   MANGLE_TRACE_TREE ("template-args", args);
 
   write_char ('I');
 
-  gcc_assert (length > 0);
+  if (args)
+    length = TREE_VEC_LENGTH (args);
 
-  if (TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
+  if (args && TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
     {
       /* We have nested template args.  We want the innermost template
 	 argument list.  */
diff --git a/gcc/testsuite/g++.dg/abi/mangle34.C b/gcc/testsuite/g++.dg/abi/mangle34.C
new file mode 100644
index 0000000..08c3bc0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/mangle34.C
@@ -0,0 +1,41 @@
+// Contributed by Dodji Seketeli <dodji@redhat.com>
+// Origin PR c++/40808
+// { dg-do compile }
+// This tests the mangling of empty template argument list in a template
+// id.
+// { dg-final { scan-assembler "_ZNK5DummyclI3GenEENT_3SigIE10ResultTypeERKS2_" } }
+
+
+struct Void {};
+
+template <class R> struct FunType {
+  typedef R ResultType;
+};
+
+struct WrongNumberOfSigArgs {};
+
+template <typename R> struct CFunType {
+  template <class Dummy1=Void, class Dummy2=Void> struct Sig : public
+FunType<WrongNumberOfSigArgs> {};
+  template <class Dummy> struct Sig<Void,Dummy> : public FunType<R> {};
+};
+
+struct Dummy {
+  template <typename F> typename F::template Sig<>::ResultType operator()(F
+const& f) const {
+    return typename F::template Sig<>::ResultType(0);
+  }
+};
+
+struct Gen: public CFunType<int> {
+  int operator()() const {return 0;}
+  Gen() {}
+};
+
+int myfunction() {
+  return Dummy()(Gen());
+}
+
+int main() {
+  myfunction();
+}
-- 
Dodji Seketeli
Red Hat

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFA] PR c++/40808
  2009-10-23 16:31   ` Dodji Seketeli
@ 2009-10-23 20:07     ` Jason Merrill
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2009-10-23 20:07 UTC (permalink / raw)
  To: Dodji Seketeli; +Cc: gcc-patches

OK.

Jason

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-10-23 20:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-23 14:02 [RFA] PR c++/40808 Dodji Seketeli
2009-10-23 16:13 ` Jason Merrill
2009-10-23 16:31   ` Dodji Seketeli
2009-10-23 20:07     ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).