Patchwork C++ PATCH to user-defined literal operator mangling

login
register
mail settings
Submitter Jason Merrill
Date March 7, 2012, 8:20 p.m.
Message ID <4F57C319.1040505@redhat.com>
Download mbox | patch
Permalink /patch/145338/
State New
Headers show

Comments

Jason Merrill - March 7, 2012, 8:20 p.m.
In c++/52521 it was pointed out that our mangling of user-defined 
literals was wrong.

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

Patch

commit 287cd9ecf4877db64774f5a29828081a62a53f5b
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Mar 7 14:01:56 2012 -0500

    	PR c++/52521
    	* mangle.c (write_literal_operator_name): The length comes after the
    	operator prefix.

diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index 1379e3b..5d6beb5 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -1292,18 +1292,16 @@  write_source_name (tree identifier)
 }
 
 /* Write a user-defined literal operator.
+          ::= li <source-name>    # "" <source-name>
    IDENTIFIER is an LITERAL_IDENTIFIER_NODE.  */
 
 static void
 write_literal_operator_name (tree identifier)
 {
   const char* suffix = UDLIT_OP_SUFFIX (identifier);
-  char* buffer = XNEWVEC (char, strlen (UDLIT_OP_MANGLED_PREFIX)
-			      + strlen (suffix) + 10);
-  sprintf (buffer, UDLIT_OP_MANGLED_FORMAT, suffix);
-
-  write_unsigned_number (strlen (buffer));
-  write_identifier (buffer);
+  write_identifier (UDLIT_OP_MANGLED_PREFIX);
+  write_unsigned_number (strlen (suffix));
+  write_identifier (suffix);
 }
 
 /* Encode 0 as _, and 1+ as n-1_.  */
diff --git a/gcc/testsuite/g++.dg/cpp0x/udlit-mangle.C b/gcc/testsuite/g++.dg/cpp0x/udlit-mangle.C
new file mode 100644
index 0000000..6de31b6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/udlit-mangle.C
@@ -0,0 +1,8 @@ 
+// PR c++/52521
+// { dg-options -std=c++0x }
+// { dg-final { scan-assembler "_Zli2_wPKc" } }
+
+int operator "" _w(const char*);
+int main() {
+  123_w;
+}