Skip to content

Commit

Permalink
Merge pull request #2030 from dawgfoto/fixupPragmaMangle
Browse files Browse the repository at this point in the history
remove test cases with non-graphical characters
  • Loading branch information
yebblies committed May 15, 2013
2 parents 5251804 + e9629f8 commit 20fac37
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 47 deletions.
35 changes: 35 additions & 0 deletions src/attrib.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "parse.h"
#include "template.h"
#include "hdrgen.h"
#include "utf.h"


/********************************* AttribDeclaration ****************************/
Expand Down Expand Up @@ -1095,6 +1096,40 @@ void PragmaDeclaration::semantic(Scope *sc)

if (se->sz != 1)
error("mangled name characters can only be of type char");

for (size_t i = 0; i < se->len; )
{
unsigned char *p = (unsigned char *)se->string;
dchar_t c = p[i];
if (c < 0x80)
{
if (c >= 'A' && c <= 'Z' ||
c >= 'a' && c <= 'z' ||
c >= '0' && c <= '9' ||
c != 0 && strchr("$%().:?@[]_", c))
{
++i;
continue;
}
else
{
error("char 0x%02x not allowed in mangled name", c);
break;
}
}

if (const char* msg = utf_decodeChar((unsigned char *)se->string, se->len, &i, &c))
{
error("%s", msg);
break;
}

if (!isUniAlpha(c))
{
error("char 0x%04x not allowed in mangled name", c);
break;
}
}
}
}
else if (global.params.ignoreUnsupportedPragmas)
Expand Down
1 change: 1 addition & 0 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ Dsymbols *Parser::parseDeclDefs(int once, Dsymbol **pLastDecl)
case TOKpragma:
{ Identifier *ident;
Expressions *args = NULL;
Loc loc = this->loc;

nextToken();
check(TOKlparen);
Expand Down
2 changes: 1 addition & 1 deletion test/fail_compilation/mangle1.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/mangle1.d(9): Error: pragma mangle can only apply to a single declaration
fail_compilation/mangle1.d(8): Error: pragma mangle can only apply to a single declaration
---
*/

Expand Down
42 changes: 42 additions & 0 deletions test/fail_compilation/mangle2.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
TEST_OUTPUT:
---
fail_compilation/mangle2.d(20): Error: pragma mangle char 0x20 not allowed in mangled name
fail_compilation/mangle2.d(21): Error: pragma mangle char 0x20 not allowed in mangled name
fail_compilation/mangle2.d(24): Error: pragma mangle char 0x0a not allowed in mangled name
fail_compilation/mangle2.d(25): Error: pragma mangle char 0x0a not allowed in mangled name
fail_compilation/mangle2.d(28): Error: pragma mangle char 0x07 not allowed in mangled name
fail_compilation/mangle2.d(29): Error: pragma mangle char 0x07 not allowed in mangled name
fail_compilation/mangle2.d(32): Error: pragma mangle char 0x01 not allowed in mangled name
fail_compilation/mangle2.d(33): Error: pragma mangle char 0x01 not allowed in mangled name
fail_compilation/mangle2.d(36): Error: pragma mangle char 0x00 not allowed in mangled name
fail_compilation/mangle2.d(37): Error: pragma mangle char 0x00 not allowed in mangled name
fail_compilation/mangle2.d(40): Error: pragma mangle Outside Unicode code space
fail_compilation/mangle2.d(41): Error: pragma mangle Outside Unicode code space
---
*/

//spaces
__gshared pragma(mangle, "test 9") ubyte test9_1;
__gshared extern pragma(mangle, "test 9") ubyte test9_1_e;

//\n chars
__gshared pragma(mangle, "test\n9") ubyte test9_2;
__gshared extern pragma(mangle, "test\n9") ubyte test9_2_e;

//\a chars
__gshared pragma(mangle, "test\a9") ubyte test9_3;
__gshared extern pragma(mangle, "test\a9") ubyte test9_3_e;

//\x01 chars
__gshared pragma(mangle, "test\x019") ubyte test9_4;
__gshared extern pragma(mangle, "test\x019") ubyte test9_4_e;

//\0 chars
__gshared pragma(mangle, "test\09") ubyte test9_5;
__gshared extern pragma(mangle, "test\09") ubyte test9_5_e;

//\xff chars
__gshared pragma(mangle, "test\xff9") ubyte test9_6;
__gshared extern pragma(mangle, "test\xff9") ubyte test9_6_e;

50 changes: 4 additions & 46 deletions test/runnable/mangle.d
Original file line number Diff line number Diff line change
Expand Up @@ -38,60 +38,18 @@ void test8()
assert(getModuleInfo!(object).name == "object");
}

//spaces
__gshared pragma(mangle, "test 9") ubyte test9_1;
__gshared extern pragma(mangle, "test 9") ubyte test9_1_e;

//\n chars
__gshared pragma(mangle, "test\n9") ubyte test9_2;
__gshared extern pragma(mangle, "test\n9") ubyte test9_2_e;

//\a chars
__gshared pragma(mangle, "test\a9") ubyte test9_3;
__gshared extern pragma(mangle, "test\a9") ubyte test9_3_e;

//\x01 chars
__gshared pragma(mangle, "test\x019") ubyte test9_4;
__gshared extern pragma(mangle, "test\x019") ubyte test9_4_e;

//\0 chars
__gshared pragma(mangle, "test\09") ubyte test9_5;
__gshared extern pragma(mangle, "test\09") ubyte test9_5_e;

//\xff chars
__gshared pragma(mangle, "test\xff9") ubyte test9_6;
__gshared extern pragma(mangle, "test\xff9") ubyte test9_6_e;

//UTF-8 chars
__gshared pragma(mangle, "test_эльфийские_письмена_9") ubyte test9_7;
__gshared extern pragma(mangle, "test_эльфийские_письмена_9") ubyte test9_7_e;
__gshared pragma(mangle, "test_эльфийские_письмена_9") ubyte test9_1;
__gshared extern pragma(mangle, "test_эльфийские_письмена_9") ubyte test9_1_e;

void test10()
void test9()
{
test9_1 = 42;
assert(test9_1_e == 42);

test9_2 = 42;
assert(test9_2_e == 42);

test9_3 = 42;
assert(test9_3_e == 42);

test9_4 = 42;
assert(test9_4_e == 42);

test9_5 = 42;
assert(test9_5_e == 42);

test9_6 = 42;
assert(test9_6_e == 42);

test9_7 = 42;
assert(test9_7_e == 42);
}

void main()
{
test8();
test10();
test9();
}

0 comments on commit 20fac37

Please sign in to comment.