diff mbox

[4/7,D] libiberty: Remove wrongly spec'd mangle rule for encoded integers.

Message ID CABOHX+dkrgUS7PMNLvgcP=CGfQ97aC1W6Xtm=_SW3K_vXFnOVQ@mail.gmail.com
State New
Headers show

Commit Message

Iain Buclaw April 15, 2017, 3:24 p.m. UTC
This updates the implementation to reflect a part of the D ABI spec
that has been removed.  There should never be a bare integer value
encoded into a template argument list.  Integers are always prefixed
by `i' if they are positive or `N' if they are negative.

Have verified this indeed is the case using the code below, and
updated all coverage tests to match the compiler.

    module demangle;

    template test(alias T)
    {
        void test() { auto t = T; }
    }

    pragma(msg, (test!(cast(byte)123)).mangleof);
    pragma(msg, (test!(cast(int)123)).mangleof);
    pragma(msg, (test!(cast(short)123)).mangleof);
    pragma(msg, (test!(cast(ubyte)123)).mangleof);
    pragma(msg, (test!(cast(uint)123)).mangleof);
    pragma(msg, (test!(cast(ushort)123)).mangleof);
    pragma(msg, (test!(cast(long)123)).mangleof);
    pragma(msg, (test!(cast(ulong)123)).mangleof);
    pragma(msg, (test!(true)).mangleof);
    pragma(msg, (test!(false)).mangleof);
    pragma(msg, (test!('\x0a')).mangleof);
    pragma(msg, (test!(' ')).mangleof);
    pragma(msg, (test!('A')).mangleof);
    pragma(msg, (test!('~')).mangleof);
    pragma(msg, (test!('\u03e8')).mangleof);
    pragma(msg, (test!('\U000186a0')).mangleof);

---

Comments

Iain Buclaw April 20, 2017, 6:58 p.m. UTC | #1
On 15 April 2017 at 17:24, Iain Buclaw <ibuclaw@gdcproject.org> wrote:
> This updates the implementation to reflect a part of the D ABI spec
> that has been removed.  There should never be a bare integer value
> encoded into a template argument list.  Integers are always prefixed
> by `i' if they are positive or `N' if they are negative.
>
> Have verified this indeed is the case using the code below, and
> updated all coverage tests to match the compiler.
>
>     module demangle;
>
>     template test(alias T)
>     {
>         void test() { auto t = T; }
>     }
>
>     pragma(msg, (test!(cast(byte)123)).mangleof);
>     pragma(msg, (test!(cast(int)123)).mangleof);
>     pragma(msg, (test!(cast(short)123)).mangleof);
>     pragma(msg, (test!(cast(ubyte)123)).mangleof);
>     pragma(msg, (test!(cast(uint)123)).mangleof);
>     pragma(msg, (test!(cast(ushort)123)).mangleof);
>     pragma(msg, (test!(cast(long)123)).mangleof);
>     pragma(msg, (test!(cast(ulong)123)).mangleof);
>     pragma(msg, (test!(true)).mangleof);
>     pragma(msg, (test!(false)).mangleof);
>     pragma(msg, (test!('\x0a')).mangleof);
>     pragma(msg, (test!(' ')).mangleof);
>     pragma(msg, (test!('A')).mangleof);
>     pragma(msg, (test!('~')).mangleof);
>     pragma(msg, (test!('\u03e8')).mangleof);
>     pragma(msg, (test!('\U000186a0')).mangleof);
>
> ---

Hmm, it seems like D compilers until 3 years ago infact used to mangle
in this way.  Better keep it around then for a little while longer for
compatibility.  I'll follow-up with an amendment which doesn't remove
the cases, instead adding an explanatory comment on why it's present,
but still fixing up the coverage tests anyway, as they should try to
reflect as close to actual mangling as possible.

--
Iain.
diff mbox

Patch

commit 30ff1ef529c4711ab08e168c79e4971cd44f17f4
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Sat Apr 15 11:35:35 2017 +0200

    libiberty/ChangeLog:
    
    2017-04-15  Iain Buclaw  <ibuclaw@gdcproject.org>
    
    	* d-demangle.c (dlang_value): Remove fallthrough and cases for digits.
    	* testsuite/d-demangle-expected: Update integer value tests.

diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c
index 533653f..71be8fb 100644
--- a/libiberty/d-demangle.c
+++ b/libiberty/d-demangle.c
@@ -1242,9 +1242,6 @@  dlang_value (string *decl, const char *mangled, const char *name, char type)
       mangled++;
       if (*mangled < '0' || *mangled > '9')
 	return NULL;
-      /* Fall through */
-    case '0': case '1': case '2': case '3': case '4':
-    case '5': case '6': case '7': case '8': case '9':
       mangled = dlang_parse_integer (decl, mangled, type);
       break;
 
diff --git a/libiberty/testsuite/d-demangle-expected b/libiberty/testsuite/d-demangle-expected
index 530e0e6..0692729 100644
--- a/libiberty/testsuite/d-demangle-expected
+++ b/libiberty/testsuite/d-demangle-expected
@@ -698,35 +698,35 @@  _D8demangle13__T4testVPinZv
 demangle.test!(null)
 #
 --format=dlang
-_D8demangle14__T4testVg123Zv
+_D8demangle15__T4testVgi123Zv
 demangle.test!(123)
 #
 --format=dlang
-_D8demangle14__T4testVi123Zv
+_D8demangle15__T4testVii123Zv
 demangle.test!(123)
 #
 --format=dlang
-_D8demangle14__T4testVs123Zv
+_D8demangle15__T4testVsi123Zv
 demangle.test!(123)
 #
 --format=dlang
-_D8demangle14__T4testVh123Zv
+_D8demangle15__T4testVhi123Zv
 demangle.test!(123u)
 #
 --format=dlang
-_D8demangle14__T4testVk123Zv
+_D8demangle15__T4testVki123Zv
 demangle.test!(123u)
 #
 --format=dlang
-_D8demangle14__T4testVt123Zv
+_D8demangle15__T4testVti123Zv
 demangle.test!(123u)
 #
 --format=dlang
-_D8demangle14__T4testVl123Zv
+_D8demangle15__T4testVli123Zv
 demangle.test!(123L)
 #
 --format=dlang
-_D8demangle14__T4testVm123Zv
+_D8demangle15__T4testVmi123Zv
 demangle.test!(123uL)
 #
 --format=dlang
@@ -746,35 +746,35 @@  _D8demangle15__T4testVmN123Zv
 demangle.test!(-123uL)
 #
 --format=dlang
-_D8demangle12__T4testVb1Zv
+_D8demangle13__T4testVbi1Zv
 demangle.test!(true)
 #
 --format=dlang
-_D8demangle12__T4testVb0Zv
+_D8demangle13__T4testVbi0Zv
 demangle.test!(false)
 #
 --format=dlang
-_D8demangle13__T4testVa10Zv
+_D8demangle14__T4testVai10Zv
 demangle.test!('\x0a')
 #
 --format=dlang
-_D8demangle13__T4testVa32Zv
+_D8demangle14__T4testVai32Zv
 demangle.test!(' ')
 #
 --format=dlang
-_D8demangle13__T4testVa65Zv
+_D8demangle14__T4testVai65Zv
 demangle.test!('A')
 #
 --format=dlang
-_D8demangle14__T4testVa126Zv
+_D8demangle15__T4testVai126Zv
 demangle.test!('~')
 #
 --format=dlang
-_D8demangle15__T4testVu1000Zv
+_D8demangle16__T4testVui1000Zv
 demangle.test!('\u03e8')
 #
 --format=dlang
-_D8demangle17__T4testVw100000Zv
+_D8demangle18__T4testVwi100000Zv
 demangle.test!('\U000186a0')
 #
 --format=dlang
@@ -1076,7 +1076,7 @@  _D8demangle20__T2fnVAiA4i1i2i3i4Z2fnFZv
 demangle.fn!([1, 2, 3, 4]).fn()
 #
 --format=dlang
-_D8demangle10__T2fnVi1Z2fnFZv
+_D8demangle11__T2fnVii1Z2fnFZv
 demangle.fn!(1).fn()
 #
 --format=dlang
@@ -1104,7 +1104,7 @@  _D8demangle2fnFNgiZNgi
 demangle.fn(inout(int))
 #
 --format=dlang
-_D8demangle29__T2fnVa97Va9Va0Vu257Vw65537Z2fnFZv
+_D8demangle34__T2fnVai97Vai9Vai0Vui257Vwi65537Z2fnFZv
 demangle.fn!('a', '\x09', '\x00', '\u0101', '\U00010001').fn()
 #
 --format=dlang