[d] Committed merge with upstream dmd

Message ID CABOHX+d5qfcm=BMU_+Xtx5YCxqqJ4SgUgYcABeQwdu1v6pyiWg@mail.gmail.com
State New
Headers show
Series
  • [d] Committed merge with upstream dmd
Related show

Commit Message

Iain Buclaw March 26, 2019, 2:40 p.m.
Hi,

This patch merges the D front-end implementation with dmd upstream ab702e73e.

Backports memory leak fix in the mangler, and introduces recognition
and rejection of more C types and directives.

Bootstrapped and regression tested on x86_64-linux-gnu.

Committed to trunk as r269945.

-- 
Iain
---

Patch

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;