d/dmd: Merge upstream dmd ab702e73e
authorIain Buclaw <ibuclaw@gcc.gnu.org>
Tue, 26 Mar 2019 14:40:06 +0000 (14:40 +0000)
committerIain Buclaw <ibuclaw@gcc.gnu.org>
Tue, 26 Mar 2019 14:40:06 +0000 (14:40 +0000)
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
gcc/d/dmd/dmangle.c
gcc/d/dmd/dscope.c
gcc/d/dmd/idgen.c
gcc/d/dmd/lexer.c
gcc/d/dmd/parse.c
gcc/testsuite/gdc.test/fail_compilation/cerrors.d [new file with mode: 0644]
gcc/testsuite/gdc.test/fail_compilation/ctypes.d [new file with mode: 0644]
gcc/testsuite/gdc.test/fail_compilation/widechars.d [new file with mode: 0644]

index 3017f0d34af581a4a97145f790a6ebd303ad97c7..ffad6cb524d9b63b1265326cf752e4a4339164cb 100644 (file)
@@ -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.
index 7f13947ae2bd2e2620261fa4866ee59ea5354a13..44f4f826b4189ac32c86522c54432f35b7ea3ec1 100644 (file)
@@ -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)
index 27c3fd58947402a2f292263f41c4298e10a12ebc..def448a2408080c694e05710748dc527fb112a91 100644 (file)
@@ -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);
index ec26b2c70088a7a415b18175ac9a8f27f042e5e7..e75004893aa25d13cd2cf404904a8062293cd594 100644 (file)
@@ -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" },
 };
 
 
index b466f17e4be3203a40b57c99f0dd94b03ea6ebac..8a2c90f1dfd2c6507ced714b42d065ff52b7abaf 100644 (file)
@@ -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:
index e0ee299eb6d3739742826e047228b3a28e6677e7..3afdbc257f80b4a8f720931cf679315be60d6147 100644 (file)
@@ -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 (file)
index 0000000..3d69d41
--- /dev/null
@@ -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 (file)
index 0000000..9f5ff18
--- /dev/null
@@ -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 (file)
index 0000000..ccfc47a
--- /dev/null
@@ -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;