From ecbb1530e317e8b405d29dead5b080fe2ef9f50c Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Tue, 26 Mar 2019 14:40:06 +0000 Subject: [PATCH] d/dmd: Merge upstream dmd ab702e73e Fixes memory leak in the front-end symbol mangler, and introduces recognition and rejection of a few more C types and directives. Reviewed-on: https://github.com/dlang/dmd/pull/9492 From-SVN: r269945 --- gcc/d/dmd/MERGE | 2 +- gcc/d/dmd/dmangle.c | 3 ++- gcc/d/dmd/dscope.c | 10 +++++---- gcc/d/dmd/idgen.c | 9 ++++---- gcc/d/dmd/lexer.c | 21 +++++++++++++------ gcc/d/dmd/parse.c | 18 +++++++++++++++- .../gdc.test/fail_compilation/cerrors.d | 15 +++++++++++++ .../gdc.test/fail_compilation/ctypes.d | 13 ++++++++++++ .../gdc.test/fail_compilation/widechars.d | 10 +++++++++ 9 files changed, 84 insertions(+), 17 deletions(-) create mode 100644 gcc/testsuite/gdc.test/fail_compilation/cerrors.d create mode 100644 gcc/testsuite/gdc.test/fail_compilation/ctypes.d create mode 100644 gcc/testsuite/gdc.test/fail_compilation/widechars.d diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE index 3017f0d34af..ffad6cb524d 100644 --- a/gcc/d/dmd/MERGE +++ b/gcc/d/dmd/MERGE @@ -1,4 +1,4 @@ -74ac873be1862090b7ec0e4a876fd1b758520359 +ab702e73e56aefb3b77b8f8f42da94bc22143eeb The first line of this file holds the git revision number of the last merge done from the dlang/dmd repository. diff --git a/gcc/d/dmd/dmangle.c b/gcc/d/dmd/dmangle.c index 7f13947ae2b..44f4f826b41 100644 --- a/gcc/d/dmd/dmangle.c +++ b/gcc/d/dmd/dmangle.c @@ -306,8 +306,9 @@ public: buf2.reserve(32); Mangler v(&buf2); v.paramsToDecoBuffer(t->arguments); + const char *s = buf2.peekString(); int len = (int)buf2.offset; - buf->printf("%d%.*s", len, len, buf2.extractData()); + buf->printf("%d%.*s", len, len, s); } void visit(TypeNull *t) diff --git a/gcc/d/dmd/dscope.c b/gcc/d/dmd/dscope.c index 27c3fd58947..def448a2408 100644 --- a/gcc/d/dmd/dscope.c +++ b/gcc/d/dmd/dscope.c @@ -685,14 +685,16 @@ Dsymbol *Scope::search_correct(Identifier *ident) const char *Scope::search_correct_C(Identifier *ident) { TOK tok; - if (ident == Id::_NULL) + if (ident == Id::C_NULL) tok = TOKnull; - else if (ident == Id::_TRUE) + else if (ident == Id::C_TRUE) tok = TOKtrue; - else if (ident == Id::_FALSE) + else if (ident == Id::C_FALSE) tok = TOKfalse; - else if (ident == Id::_unsigned) + else if (ident == Id::C_unsigned) tok = TOKuns32; + else if (ident == Id::C_wchar_t) + tok = global.params.isWindows ? TOKwchar : TOKdchar; else return NULL; return Token::toChars(tok); diff --git a/gcc/d/dmd/idgen.c b/gcc/d/dmd/idgen.c index ec26b2c7008..e75004893aa 100644 --- a/gcc/d/dmd/idgen.c +++ b/gcc/d/dmd/idgen.c @@ -374,10 +374,11 @@ Msgtable msgtable[] = { "udaSelector", "selector" }, // C names, for undefined identifier error messages - { "_NULL", "NULL" }, - { "_TRUE", "TRUE" }, - { "_FALSE", "FALSE" }, - { "_unsigned", "unsigned" }, + { "C_NULL", "NULL" }, + { "C_TRUE", "TRUE" }, + { "C_FALSE", "FALSE" }, + { "C_unsigned", "unsigned" }, + { "C_wchar_t", "wchar_t" }, }; diff --git a/gcc/d/dmd/lexer.c b/gcc/d/dmd/lexer.c index b466f17e4be..8a2c90f1dfd 100644 --- a/gcc/d/dmd/lexer.c +++ b/gcc/d/dmd/lexer.c @@ -901,16 +901,25 @@ void Lexer::scan(Token *t) p++; Token n; scan(&n); - if (n.value == TOKidentifier && n.ident == Id::line) + if (n.value == TOKidentifier) { - poundLine(); - continue; + if (n.ident == Id::line) + { + poundLine(); + continue; + } + else + { + const Loc locx = loc(); + warning(locx, "C preprocessor directive `#%s` is not supported", n.ident->toChars()); + } } - else + else if (n.value == TOKif) { - t->value = TOKpound; - return; + error("C preprocessor directive `#if` is not supported, use `version` or `static if`"); } + t->value = TOKpound; + return; } default: diff --git a/gcc/d/dmd/parse.c b/gcc/d/dmd/parse.c index e0ee299eb6d..3afdbc257f8 100644 --- a/gcc/d/dmd/parse.c +++ b/gcc/d/dmd/parse.c @@ -3076,7 +3076,23 @@ Type *Parser::parseBasicType(bool dontLookDotIdents) case TOKuns16: t = Type::tuns16; goto LabelX; case TOKint32: t = Type::tint32; goto LabelX; case TOKuns32: t = Type::tuns32; goto LabelX; - case TOKint64: t = Type::tint64; goto LabelX; + case TOKint64: + t = Type::tint64; + nextToken(); + if (token.value == TOKint64) // if `long long` + { + error("use `long` for a 64 bit integer instead of `long long`"); + nextToken(); + } + else if (token.value == TOKfloat64) // if `long double` + { + error("use `real` instead of `long double`"); + t = Type::tfloat80; + nextToken(); + + } + break; + case TOKuns64: t = Type::tuns64; goto LabelX; case TOKint128: t = Type::tint128; goto LabelX; case TOKuns128: t = Type::tuns128; goto LabelX; diff --git a/gcc/testsuite/gdc.test/fail_compilation/cerrors.d b/gcc/testsuite/gdc.test/fail_compilation/cerrors.d new file mode 100644 index 00000000000..3d69d415e2b --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/cerrors.d @@ -0,0 +1,15 @@ +/* REQUIRED_ARGS: -wi +TEST_OUTPUT: +--- +fail_compilation/cerrors.d(11): Error: C preprocessor directive `#if` is not supported, use `version` or `static if` +fail_compilation/cerrors.d(11): Error: declaration expected, not `#` +fail_compilation/cerrors.d(15): Warning: C preprocessor directive `#endif` is not supported +fail_compilation/cerrors.d(15): Error: declaration expected, not `#` +--- +*/ + +#if 1 + +void test(wchar_t u); + +#endif diff --git a/gcc/testsuite/gdc.test/fail_compilation/ctypes.d b/gcc/testsuite/gdc.test/fail_compilation/ctypes.d new file mode 100644 index 00000000000..9f5ff18f751 --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/ctypes.d @@ -0,0 +1,13 @@ +/* +TEST_OUTPUT: +--- +fail_compilation/ctypes.d(11): Error: use `real` instead of `long double` +fail_compilation/ctypes.d(12): Error: use `long` for a 64 bit integer instead of `long long` +--- +*/ + +void test() +{ + long double r; + long long ll; +} diff --git a/gcc/testsuite/gdc.test/fail_compilation/widechars.d b/gcc/testsuite/gdc.test/fail_compilation/widechars.d new file mode 100644 index 00000000000..ccfc47aa817 --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/widechars.d @@ -0,0 +1,10 @@ + +/* +DISABLED: win32 win64 +TEST_OUTPUT: +--- +fail_compilation/widechars.d(10): Error: undefined identifier `wchar_t`, did you mean `dchar`? +--- +*/ + +wchar_t x; -- 2.30.2