Hi,

This patch merges the D front-end with upstream dmd 02a64d2e13.

Moves the special handling of reading from stdin out of the language
semantic routines. All references to `__stdin.d` have also been removed
from the front-end implementation.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32, and
committed to mainline.

Regards,
Iain.

---
gcc/d/ChangeLog:

        * dmd/MERGE: Merge upstream dmd 02a64d2e13.
---
 gcc/d/dmd/MERGE                               |  2 +-
 gcc/d/dmd/dmodule.d                           |  8 ---
 gcc/d/dmd/file_manager.d                      | 55 ++-----------------
 gcc/d/dmd/globals.d                           |  1 +
 gcc/d/dmd/globals.h                           |  1 +
 .../gdc.test/fail_compilation/fail21045.d     | 12 ++++
 6 files changed, 20 insertions(+), 59 deletions(-)
 create mode 100644 gcc/testsuite/gdc.test/fail_compilation/fail21045.d

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index 116074932ae..08b4e78aba5 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-032e24446b3d8c6cfe3043d62534d5ce6d004c34
+02a64d2e1359119b91d2b932e61ed712f272507a
 
 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/dmodule.d b/gcc/d/dmd/dmodule.d
index 6c7416856a1..1d14c085d3d 100644
--- a/gcc/d/dmd/dmodule.d
+++ b/gcc/d/dmd/dmodule.d
@@ -58,12 +58,10 @@ import dmd.visitor;
 
 version (Windows)
 {
-    import core.sys.windows.winbase : getpid = GetCurrentProcessId;
     enum PathSeparator = '\\';
 }
 else version (Posix)
 {
-    import core.sys.posix.unistd : getpid;
     enum PathSeparator = '/';
 }
 else
@@ -577,12 +575,6 @@ extern (C++) final class Module : Package
         else
         {
             const(char)[] argdoc;
-            OutBuffer buf;
-            if (arg == "__stdin.d")
-            {
-                buf.printf("__stdin_%d.d", getpid());
-                arg = buf[];
-            }
             if (global.params.preservePaths)
                 argdoc = arg;
             else
diff --git a/gcc/d/dmd/file_manager.d b/gcc/d/dmd/file_manager.d
index fc7824f0390..8a6ec998e69 100644
--- a/gcc/d/dmd/file_manager.d
+++ b/gcc/d/dmd/file_manager.d
@@ -16,7 +16,6 @@ import dmd.root.stringtable : StringTable;
 import dmd.root.file : File, Buffer;
 import dmd.root.filename : FileName, isDirSeparator;
 import dmd.root.string : toDString;
-import dmd.errors;
 import dmd.globals;
 import dmd.identifier;
 import dmd.location;
@@ -184,9 +183,6 @@ nothrow:
         scope(exit) FileName.free(sdi.ptr);
 
         const sd = FileName.forceExt(filename, mars_ext);
-        // Special file name representing `stdin`, always assume its presence
-        if (sd == "__stdin.d")
-            return sd;
         if (checkLocal && FileName.exists(sd) == 1)
             return sd;
         scope(exit) FileName.free(sd.ptr);
@@ -312,20 +308,12 @@ nothrow:
         if (auto val = files.lookup(name))      // if `name` is cached
             return val.value;                   // return its contents
 
-        OutBuffer buf;
-        if (name == "__stdin.d")                // special name for reading 
from stdin
-        {
-            if (readFromStdin(buf))
-                fatal();
-        }
-        else
-        {
-            if (FileName.exists(name) != 1) // if not an ordinary file
-                return null;
+        if (FileName.exists(name) != 1) // if not an ordinary file
+            return null;
 
-            if (File.read(name, buf))
-                return null;        // failed
-        }
+        OutBuffer buf;
+        if (File.read(name, buf))
+            return null;        // failed
 
         buf.write32(0);         // terminating dchar 0
 
@@ -351,36 +339,3 @@ nothrow:
         return val == null ? null : val.value;
     }
 }
-
-private bool readFromStdin(ref OutBuffer sink) nothrow
-{
-    import core.stdc.stdio;
-    import dmd.errors;
-
-    enum BufIncrement = 128 * 1024;
-
-    for (size_t j; 1; ++j)
-    {
-        char[] buffer = sink.allocate(BufIncrement);
-
-        // Fill up buffer
-        size_t filled = 0;
-        do
-        {
-            filled += fread(buffer.ptr + filled, 1, buffer.length - filled, 
stdin);
-            if (ferror(stdin))
-            {
-                import core.stdc.errno;
-                error(Loc.initial, "cannot read from stdin, errno = %d", 
errno);
-                return true;
-            }
-            if (feof(stdin)) // successful completion
-            {
-                sink.setsize(j * BufIncrement + filled);
-                return false;
-            }
-        } while (filled < BufIncrement);
-    }
-
-    assert(0);
-}
diff --git a/gcc/d/dmd/globals.d b/gcc/d/dmd/globals.d
index 900c554e5f4..132683e624a 100644
--- a/gcc/d/dmd/globals.d
+++ b/gcc/d/dmd/globals.d
@@ -160,6 +160,7 @@ extern (C++) struct ImportPathInfo {
 extern (C++) struct Param
 {
     bool obj = true;        // write object file
+    bool readStdin;         // saw "-" on command line, read source file from 
stdin
     bool multiobj;          // break one object file into multiple ones
     bool trace;             // insert profiling hooks
     bool tracegc;           // instrument calls to 'new'
diff --git a/gcc/d/dmd/globals.h b/gcc/d/dmd/globals.h
index 69fe709f4b0..59952a2c105 100644
--- a/gcc/d/dmd/globals.h
+++ b/gcc/d/dmd/globals.h
@@ -168,6 +168,7 @@ struct ImportPathInfo
 struct Param
 {
     d_bool obj;           // write object file
+    d_bool readStdin;     // read source file from stdin
     d_bool multiobj;      // break one object file into multiple ones
     d_bool trace;         // insert profiling hooks
     d_bool tracegc;       // instrument calls to 'new'
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail21045.d 
b/gcc/testsuite/gdc.test/fail_compilation/fail21045.d
new file mode 100644
index 00000000000..c43eda3f972
--- /dev/null
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail21045.d
@@ -0,0 +1,12 @@
+/*
+TEST_OUTPUT:
+---
+fail_compilation/fail21045.d(12): Error: unable to read module `__stdin`
+fail_compilation/fail21045.d(12):        Expected '__stdin.d' or 
'__stdin/package.d' in one of the following import paths:
+import path[0] = fail_compilation
+import path[1] = $p:druntime/import$
+import path[2] = $p:phobos$
+---
+*/
+
+import __stdin;
-- 
2.43.0

Reply via email to