<div dir="ltr">On Sat, Sep 7, 2013 at 1:40 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div class="h5">On Sat, Sep 7, 2013 at 12:33 PM, David Majnemer <span dir="ltr"><<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>></span> wrote:<br>
</div></div><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">

<div><div>On Sat, Sep 7, 2013 at 10:35 AM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div><p dir="ltr"><br>
On 7 Sep 2013 02:39, "David Majnemer" <<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>> wrote:<br>
><br>
> Hi rsmith, rjmccall, eli.friedman, doug.gregor,<br>
><br>
> We would previously treat nullptr literals as we were mangling the for<br>
> the null pointer value of the template parameter's type instead.<br>
><br>
> This fixes PR17141.<br>
><br>
> <a href="http://llvm-reviews.chandlerc.com/D1625" target="_blank">http://llvm-reviews.chandlerc.com/D1625</a><br>
><br>
> Files:<br>
>   lib/AST/ItaniumMangle.cpp<br>
>   test/CodeGenCXX/mangle-nullptr-arg.cpp<br>
>   test/CodeGenCXX/visibility.cpp<br>
><br>
> Index: lib/AST/ItaniumMangle.cpp<br>
> ===================================================================<br>
> --- lib/AST/ItaniumMangle.cpp<br>
> +++ lib/AST/ItaniumMangle.cpp<br>
> @@ -3337,10 +3337,8 @@<br>
>      break;<br>
>    }<br>
>    case TemplateArgument::NullPtr: {<br>
> -    //  <expr-primary> ::= L <type> 0 E<br>
> -    Out << 'L';<br>
> -    mangleType(A.getNullPtrType());<br>
> -    Out << "0E";<br>
> +    //  <expr-primary> ::= L <nullptr type> E<br>
> +    Out << "LDnE";<br>
>      break;<br>
>    }<br>
>    case TemplateArgument::Pack: {<br>
> Index: test/CodeGenCXX/mangle-nullptr-arg.cpp<br>
> ===================================================================<br>
> --- test/CodeGenCXX/mangle-nullptr-arg.cpp<br>
> +++ test/CodeGenCXX/mangle-nullptr-arg.cpp<br>
> @@ -2,15 +2,15 @@<br>
><br>
>  template<int *ip> struct IP {};<br>
><br>
> -// CHECK-LABEL: define void @_Z5test12IPILPi0EE<br>
> +// CHECK-LABEL: define void @_Z5test12IPILDnEE<br>
>  void test1(IP<nullptr>) {}</p>
</div></div><p dir="ltr">The old mangling was correct here.</p><div>
<p dir="ltr">>  struct X{ };<br>
>  template<int X::*pm> struct PM {};<br>
><br>
> -// CHECK-LABEL: define void @_Z5test22PMILM1Xi0EE<br>
> +// CHECK-LABEL: define void @_Z5test22PMILDnEE<br>
>  void test2(PM<nullptr>) { }</p>
</div><p dir="ltr">And here. You should only change the mangling of a null pointer of type std::nullptr_t.</p></blockquote></div></div><div>I considered only changing the mangling for std::nullptr_t type arguments but the following wording in the standard discouraged me:</div>


<div><br></div><div>"The pointer literal nullptr is encoded as "LDnE"."</div><div><br></div><div>I don't see where in the ABI we get the latitude to mangle this as-if it were (param-type)0. That said there are obvious problems with giving all of them the "LDnE" mangling. I will only use the different mangling for nullptr_t template parameters.</div>

</div></div></div></blockquote><div><br></div></div></div><div>Frequently the document lags behind discussion on cxx-abi-dev. The most recent discussion on this is here:</div><div><br></div><div><a href="http://sourcerytools.com/pipermail/cxx-abi-dev/2011-August/002422.html" target="_blank">http://sourcerytools.com/pipermail/cxx-abi-dev/2011-August/002422.html</a><br>

</div><div><br></div><div>The LDnE mangling was agreed over a year beforehand, here:</div><div><br></div><div><a href="http://sourcerytools.com/pipermail/cxx-abi-dev/2010-July/002353.html" target="_blank">http://sourcerytools.com/pipermail/cxx-abi-dev/2010-July/002353.html</a><br>

</div><div><br></div><div>... however, looking at that in more detail, it looks like all that was agreed was that "nullptr" is mangled as LDnE as an expression, not necessarily as a template argument. And it certainly makes sense to me to use the L <type> 0 E mangling for all null pointer template arguments.</div>
<div class="im">
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">

<div><span style="color:rgb(80,0,80)">Also, maybe this ABI break should be listed in the release notes.</span></div><div>Will do. </div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<p dir="ltr">Does GCC implement this rule yet?</p></blockquote></div><div>They do not but icc 13.0.1 does.</div></div></div></div></blockquote><div><br></div></div><div>I'm now wondering if we and gcc are correct here, and EDG and icc are wrong. Hopefully John can provide his interpretation :)<br>
</div></div></div></div></blockquote><div><br></div><div>I think that you are right and that this is a defect in the specification.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>
</div><div class="im"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra">

<div class="gmail_quote"><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><div>
<p dir="ltr">> -// CHECK-LABEL: define void @_Z5test316DependentTypePtrIPiLS0_0EE<br>
> +// CHECK-LABEL: define void @_Z5test316DependentTypePtrIPiLDnEE<br>
>  template<typename T, T x> struct DependentTypePtr {};<br>
>  void test3(DependentTypePtr<int*,nullptr>) { }<br>
> Index: test/CodeGenCXX/visibility.cpp<br>
> ===================================================================<br>
> --- test/CodeGenCXX/visibility.cpp<br>
> +++ test/CodeGenCXX/visibility.cpp<br>
> @@ -971,8 +971,8 @@<br>
>    void f() {<br>
>      zed<nullptr>();<br>
>    }<br>
> -  // CHECK-LABEL: define internal void @_ZN6test523zedILPNS_12_GLOBAL__N_13fooE0EEEvv<br>
> -  // CHECK-HIDDEN-LABEL: define internal void @_ZN6test523zedILPNS_12_GLOBAL__N_13fooE0EEEvv<br>
> +  // CHECK-LABEL: define internal void @_ZN6test523zedILDnEEEvv<br>
> +  // CHECK-HIDDEN-LABEL: define internal void @_ZN6test523zedILDnEEEvv<br>
>  }<br>
><br>
>  namespace test53 {</p></div></div></blockquote></div></div></div></div></blockquote></div></div></div></div>
</blockquote></div><br></div></div>