diff mbox

C++ PATCH for abi_tag on builtin mangling abbreviations

Message ID 5425C501.3020403@redhat.com
State New
Headers show

Commit Message

Jason Merrill Sept. 26, 2014, 7:56 p.m. UTC
We were ignoring abi_tags on the standard mangling abbreviations, such 
as Ss = std::string.  This patch fixes that so that we append tags to 
the abbreviation, and add the result as a substitution.

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

Patch

commit 9e8c617e9135989151ba0a8d6f0d38c7913b2f23
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Aug 11 10:13:37 2014 -0400

    gcc/cp/
    	* mangle.c (is_std_substitution): Check for abi_tag.
    
    libiberty/
    	* cp-demangle.c (d_substitution): Handle abi tags on abbreviation.

diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index 9703d1c..4f94c19 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -512,6 +512,7 @@  find_substitution (tree node)
   const int size = vec_safe_length (G.substitutions);
   tree decl;
   tree type;
+  const char *abbr = NULL;
 
   if (DEBUG_MANGLE)
     fprintf (stderr, "  ++ find_substitution (%s at %p)\n",
@@ -530,13 +531,10 @@  find_substitution (tree node)
   if (decl
       && is_std_substitution (decl, SUBID_ALLOCATOR)
       && !CLASSTYPE_USE_TEMPLATE (TREE_TYPE (decl)))
-    {
-      write_string ("Sa");
-      return 1;
-    }
+    abbr = "Sa";
 
   /* Check for std::basic_string.  */
-  if (decl && is_std_substitution (decl, SUBID_BASIC_STRING))
+  else if (decl && is_std_substitution (decl, SUBID_BASIC_STRING))
     {
       if (TYPE_P (node))
 	{
@@ -555,26 +553,20 @@  find_substitution (tree node)
 					       SUBID_CHAR_TRAITS)
 		  && is_std_substitution_char (TREE_VEC_ELT (args, 2),
 					       SUBID_ALLOCATOR))
-		{
-		  write_string ("Ss");
-		  return 1;
-		}
+		abbr = "Ss";
 	    }
 	}
       else
 	/* Substitute for the template name only if this isn't a type.  */
-	{
-	  write_string ("Sb");
-	  return 1;
-	}
+	abbr = "Sb";
     }
 
   /* Check for basic_{i,o,io}stream.  */
-  if (TYPE_P (node)
-      && cp_type_quals (type) == TYPE_UNQUALIFIED
-      && CLASS_TYPE_P (type)
-      && CLASSTYPE_USE_TEMPLATE (type)
-      && CLASSTYPE_TEMPLATE_INFO (type) != NULL)
+  else if (TYPE_P (node)
+	   && cp_type_quals (type) == TYPE_UNQUALIFIED
+	   && CLASS_TYPE_P (type)
+	   && CLASSTYPE_USE_TEMPLATE (type)
+	   && CLASSTYPE_TEMPLATE_INFO (type) != NULL)
     {
       /* First, check for the template
 	 args <char, std::char_traits<char> > .  */
@@ -587,35 +579,29 @@  find_substitution (tree node)
 	{
 	  /* Got them.  Is this basic_istream?  */
 	  if (is_std_substitution (decl, SUBID_BASIC_ISTREAM))
-	    {
-	      write_string ("Si");
-	      return 1;
-	    }
+	    abbr = "Si";
 	  /* Or basic_ostream?  */
 	  else if (is_std_substitution (decl, SUBID_BASIC_OSTREAM))
-	    {
-	      write_string ("So");
-	      return 1;
-	    }
+	    abbr = "So";
 	  /* Or basic_iostream?  */
 	  else if (is_std_substitution (decl, SUBID_BASIC_IOSTREAM))
-	    {
-	      write_string ("Sd");
-	      return 1;
-	    }
+	    abbr = "Sd";
 	}
     }
 
   /* Check for namespace std.  */
-  if (decl && DECL_NAMESPACE_STD_P (decl))
+  else if (decl && DECL_NAMESPACE_STD_P (decl))
     {
       write_string ("St");
       return 1;
     }
 
+  tree tags = NULL_TREE;
+  if (OVERLOAD_TYPE_P (node))
+    tags = lookup_attribute ("abi_tag", TYPE_ATTRIBUTES (type));
   /* Now check the list of available substitutions for this mangling
      operation.  */
-  for (i = 0; i < size; ++i)
+  if (!abbr || tags) for (i = 0; i < size; ++i)
     {
       tree candidate = (*G.substitutions)[i];
       /* NODE is a matched to a candidate if it's the same decl node or
@@ -630,8 +616,17 @@  find_substitution (tree node)
 	}
     }
 
-  /* No substitution found.  */
-  return 0;
+  if (!abbr)
+    /* No substitution found.  */
+    return 0;
+
+  write_string (abbr);
+  if (tags)
+    {
+      write_abi_tags (tags);
+      add_substitution (node);
+    }
+  return 1;
 }
 
 
diff --git a/gcc/testsuite/g++.dg/abi/abi-tag9.C b/gcc/testsuite/g++.dg/abi/abi-tag9.C
new file mode 100644
index 0000000..9ec78a9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/abi-tag9.C
@@ -0,0 +1,11 @@ 
+// { dg-final { scan-assembler "_Z1fSsB3fooS_" } }
+
+namespace std {
+  template <class T> struct char_traits {};
+  template <class T> struct allocator {};
+  template <class T, class U, class V>
+  struct __attribute ((abi_tag ("foo"))) basic_string { };
+  typedef basic_string<char,char_traits<char>,allocator<char> > string;
+}
+
+void f(std::string,std::string) {}
diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index 4ecdb1e..db3d679 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -3702,7 +3702,13 @@  d_substitution (struct d_info *di, int prefix)
 		  len = p->simple_len;
 		}
 	      di->expansion += len;
-	      return d_make_sub (di, s, len);
+	      struct demangle_component *p = d_make_sub (di, s, len);
+	      if (d_peek_char (di) == 'B')
+		{
+		  p = d_abi_tags (di, p);
+		  d_add_substitution (di, p);
+		}
+	      return p;
 	    }
 	}
 
diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected
index f8420ef..a030685 100644
--- a/libiberty/testsuite/demangle-expected
+++ b/libiberty/testsuite/demangle-expected
@@ -4353,3 +4353,6 @@  xxx
 _QueueNotification_QueueController__$4PPPPPPPM_A_INotice___Z
 _QueueNotification_QueueController__$4PPPPPPPM_A_INotice___Z
 _QueueNotification_QueueController__$4PPPPPPPM_A_INotice___Z
+--format=gnu-v3
+_Z1fSsB3fooS_
+f(std::string[abi:foo], std::string[abi:foo])