Use of "sr" mangling code

Mark Mitchell mark at codesourcery.com
Tue Oct 15 06:23:41 UTC 2002


It was pointed out to me that the ABI description of the "sr" mangling
code left a lot to be desired:

(1) The mangling grammar didn't say what the operands to "sr" should
    be.

(2) It was not as clear as it should have been under what
    circumstances "sr" should be used.

I've attempted to fix that with this patch.

One particularly tricky issue is the mangling of something like:

  template <typename T> void g (S<&T::operator- >) {}

The key question is whether "operator+" should be treated as unary or
binary.  There is no way to know, given the template declaration, so
we just have to pick one arbitrarily.

In the draft patch, I went with binary, for no particular reason.

Here is a complete test case:

  struct A {
    int operator-();
  };
   
  typedef int (A::*P)();
  
  template <P> struct S {};
  
  template <typename T> void g (S<&T::operator->) {}
  
  template void g<A> (S<&A::operator-);

G++ doesn't get a vote in this question since it crashed on this test
case.

Intel, HP -- when you compile this program does the name for g look
like:

  _Z1gI1AEv1SIXadsrT_miEE

or

  _Z1gI1AEv1SIXadsrT_ngEE

?

Once we resolve that issue, I'll check in this patch, assuming, of
course that there are no other objections.

--
Mark Mitchell                   mark at codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

Index: abi.html
===================================================================
RCS file: /usr/local/Repository/cxx-abi/abi.html,v
retrieving revision 1.35
diff -c -5 -p -r1.35 abi.html
*** abi.html	11 Oct 2002 19:00:33 -0000	1.35
--- abi.html	15 Oct 2002 06:16:36 -0000
*************** the first of which is lowercase.
*** 3953,3975 ****
  		  ::= cl	# ()            
  		  ::= ix	# []            
  		  ::= qu	# ?             
  		  ::= st	# sizeof (a type)
  		  ::= sz	# sizeof (an expression)
- 		  ::= sr	# scope resolution (::), see below        
  		  ::= cv <type>	# (cast)        
  		  ::= v <digit> <source-name>	# vendor extended operator
  
  </pre></font></code>
  
  <p>
- The scope resolution operator is discussed with expressions below.
  Vendors who define builtin extended operators (e.g. __alignof)
  shall encode them as a 'v' prefix followed by
  the operand count as a single decimal digit, and
  the name in <length,ID> form.
! 
  
  <p>
  <a name=mangling-special>
  <h4> 5.1.4 Other Special Functions and Entities </h4>
  
--- 3953,3973 ----
  		  ::= cl	# ()            
  		  ::= ix	# []            
  		  ::= qu	# ?             
  		  ::= st	# sizeof (a type)
  		  ::= sz	# sizeof (an expression)
  		  ::= cv <type>	# (cast)        
  		  ::= v <digit> <source-name>	# vendor extended operator
  
  </pre></font></code>
  
  <p>
  Vendors who define builtin extended operators (e.g. __alignof)
  shall encode them as a 'v' prefix followed by
  the operand count as a single decimal digit, and
  the name in <length,ID> form.
! </p>
  
  <p>
  <a name=mangling-special>
  <h4> 5.1.4 Other Special Functions and Entities </h4>
  
*************** it represents the source token stream.
*** 4392,4423 ****
    <expression> ::= <<i>unary</i> operator-name> <expression>
  	       ::= <<i>binary</i> operator-name> <expression> <expression>
  	       ::= <<i>trinary</i> operator-name> <expression> <expression> <expression>
                 ::= st <type>
  	       ::= <expr-primary>
    <expr-primary> ::= <template-param>
! 		 ::= L <type> <<i>value</i> number> E	# literal
! 		 ::= L <mangled-name> E		# external name
  
  </pre></font></code>
  
  <p>
- Template arguments that could be pointer-to-member constants are
- difficult because it is often not possible to distinguish them from
- pointers to static member functions or data members without doing the
- substitution.
- Therefore, the <i>scope resolution</i> (sr) mangling operator is used
- if the LHS operand of :: involves a template parameter.
- Ignoring substitutions, <code>&T::j</code> as a template argument
- would be encoded <code>Xadsr1T1jE</code>.
- 
- <p>
  The encoding for a literal of an enumerated type is the encoding of the
  type name followed by the encoding of the numeric value of the literal
  in its base integral type
  (which deals with values that don't have names declared in the type).
  
  
  <p>
  <a name=mangling-scope>
  <h4> 5.1.6 Scope Encoding </h4>
  
--- 4390,4421 ----
    <expression> ::= <<i>unary</i> operator-name> <expression>
  	       ::= <<i>binary</i> operator-name> <expression> <expression>
  	       ::= <<i>trinary</i> operator-name> <expression> <expression> <expression>
                 ::= st <type>
  	       ::= <expr-primary>
+ 
    <expr-primary> ::= <template-param>
! 		 ::= L <type> <<i>value</i> number> E	                # literal
! 		 ::= L <mangled-name> E		                 # external name
!                  :: sr <type> <unqualified-name>                 # dependent name
!                  :: sr <type> <unqualified-name> <template-args> # dependent template-id
  
  </pre></font></code>
  
  <p>
  The encoding for a literal of an enumerated type is the encoding of the
  type name followed by the encoding of the numeric value of the literal
  in its base integral type
  (which deals with values that don't have names declared in the type).
  
+ <p>
+ If an expression is a qualified-name, and the qualifying scope is a
+ dependent type, one of the <code>sr</code> productions is used, rather
+ than the <code><mangled-name></code> production.  If the qualified
+ name refers to an operator for which both unary and binary manglings
+ are available, the mangling chosen is the mangling for the binary
+ version.
  
  <p>
  <a name=mangling-scope>
  <h4> 5.1.6 Scope Encoding </h4>
  
*************** unwind table location.
*** 4871,4880 ****
--- 4869,4882 ----
  
  <p> <hr> <p>
  <a name=revisions>
  <h2> Appendix R: Revision History </h2>
  <p> <hr> <p>
+ 
+ <p>
+ <font color=blue>[021014]</font>
+ Clarify use of <code>sr</code> in mangling.
  
  <p>
  <font color=blue>[021011]</font>
  Add mangling for unary plus.
  



More information about the cxx-abi-dev mailing list