[gcc r14-9420] d: Fix -fpreview=in ICEs with forward referenced parameter [PR112285]

2024-03-10 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:a84b98c62d90bf9e8b01038f624a62725e6a44db

commit r14-9420-ga84b98c62d90bf9e8b01038f624a62725e6a44db
Author: Iain Buclaw 
Date:   Sun Mar 10 17:49:06 2024 +0100

d: Fix -fpreview=in ICEs with forward referenced parameter [PR112285]

The way that the target hook preferPassByRef is implemented, it relied
on the GCC "back-end" tree type to determine whether or not to use `ref'
ABI for D `in' parameters; e.g: prefer by value if it is expected that
the target will pass the type around in registers.

Building the GCC tree type depends on the AST type being complete - all
semantic processing is finished - but as this hook is called from the
front-end, this will not be the case for forward referenced or
self-referencing types.

The consensus in upstream is that `in' parameters should always be
implicitly `ref', but as the front-end does not yet support all types
being rvalue references, limit this just static arrays and structs.

PR d/112285
PR d/112290

gcc/d/ChangeLog:

* d-target.cc (Target::preferPassByRef): Return true for all static
array and struct types.

gcc/testsuite/ChangeLog:

* gdc.dg/pr112285.d: New test.
* gdc.dg/pr112290.d: New test.

Diff:
---
 gcc/d/d-target.cc   | 25 +
 gcc/testsuite/gdc.dg/pr112285.d | 13 +
 gcc/testsuite/gdc.dg/pr112290.d | 15 +++
 3 files changed, 33 insertions(+), 20 deletions(-)

diff --git a/gcc/d/d-target.cc b/gcc/d/d-target.cc
index b9d124422b7..127b9d7ce7c 100644
--- a/gcc/d/d-target.cc
+++ b/gcc/d/d-target.cc
@@ -575,31 +575,16 @@ Target::supportsLinkerDirective (void) const
 }
 
 /* Decides whether an `in' parameter of the specified POD type PARAM_TYPE is to
-   be passed by reference or by valie.  This is used only when compiling with
+   be passed by reference or by value.  This is used only when compiling with
`-fpreview=in' enabled.  */
 
 bool
 Target::preferPassByRef (Type *param_type)
 {
-  if (param_type->size () == SIZE_INVALID)
+  /* See note in Target::isReturnOnStack.  */
+  Type *tb = param_type->toBasetype ();
+  if (tb->size () == SIZE_INVALID)
 return false;
 
-  tree type = build_ctype (param_type);
-
-  /* Prefer a `ref' if the type is an aggregate, and its size is greater than
- its alignment.  */
-  if (AGGREGATE_TYPE_P (type)
-  && (!valid_constant_size_p (TYPE_SIZE_UNIT (type))
- || compare_tree_int (TYPE_SIZE_UNIT (type), TYPE_ALIGN (type)) > 0))
-return true;
-
-  /* If the back-end is always going to pass this by invisible reference.  */
-  if (pass_by_reference (NULL, function_arg_info (type, true)))
-return true;
-
-  /* If returning the parameter means the caller will do RVO.  */
-  if (targetm.calls.return_in_memory (type, NULL_TREE))
-return true;
-
-  return false;
+  return (tb->ty == TY::Tstruct || tb->ty == TY::Tsarray);
 }
diff --git a/gcc/testsuite/gdc.dg/pr112285.d b/gcc/testsuite/gdc.dg/pr112285.d
new file mode 100644
index 000..5ca100a74a9
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr112285.d
@@ -0,0 +1,13 @@
+// { dg-do compile }
+// { dg-additional-options "-fpreview=in" }
+struct S112285
+{
+}
+
+class C112285
+{
+S112285 s;
+void f112285(in C112285)
+{
+}
+}
diff --git a/gcc/testsuite/gdc.dg/pr112290.d b/gcc/testsuite/gdc.dg/pr112290.d
new file mode 100644
index 000..7456fc21be1
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr112290.d
@@ -0,0 +1,15 @@
+// { dg-do compile }
+// { dg-additional-options "-fpreview=in" }
+struct S112290a
+{
+S112290b* p;
+bool opEquals(in S112290a)
+{
+return p == p;
+}
+}
+
+struct S112290b
+{
+string s;
+}


[gcc r13-8415] d: Fix -fpreview=in ICEs with forward referenced parameter [PR112285]

2024-03-10 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:025ff57c19efae6c8d76df6b93e7d9827017acc9

commit r13-8415-g025ff57c19efae6c8d76df6b93e7d9827017acc9
Author: Iain Buclaw 
Date:   Sun Mar 10 17:49:06 2024 +0100

d: Fix -fpreview=in ICEs with forward referenced parameter [PR112285]

The way that the target hook preferPassByRef is implemented, it relied
on the GCC "back-end" tree type to determine whether or not to use `ref'
ABI for D `in' parameters; e.g: prefer by value if it is expected that
the target will pass the type around in registers.

Building the GCC tree type depends on the AST type being complete - all
semantic processing is finished - but as this hook is called from the
front-end, this will not be the case for forward referenced or
self-referencing types.

The consensus in upstream is that `in' parameters should always be
implicitly `ref', but as the front-end does not yet support all types
being rvalue references, limit this just static arrays and structs.

PR d/112285
PR d/112290

gcc/d/ChangeLog:

* d-target.cc (Target::preferPassByRef): Return true for all static
array and struct types.

gcc/testsuite/ChangeLog:

* gdc.dg/pr112285.d: New test.
* gdc.dg/pr112290.d: New test.
* gdc.test/compilable/previewin.d: Adjust testcase.

(cherry picked from commit a84b98c62d90bf9e8b01038f624a62725e6a44db)

Diff:
---
 gcc/d/d-target.cc | 25 +
 gcc/testsuite/gdc.dg/pr112285.d   | 13 +
 gcc/testsuite/gdc.dg/pr112290.d   | 15 +++
 gcc/testsuite/gdc.test/compilable/previewin.d |  6 --
 4 files changed, 33 insertions(+), 26 deletions(-)

diff --git a/gcc/d/d-target.cc b/gcc/d/d-target.cc
index 4c7a212703e..73366fdde16 100644
--- a/gcc/d/d-target.cc
+++ b/gcc/d/d-target.cc
@@ -575,31 +575,16 @@ Target::supportsLinkerDirective (void) const
 }
 
 /* Decides whether an `in' parameter of the specified POD type PARAM_TYPE is to
-   be passed by reference or by valie.  This is used only when compiling with
+   be passed by reference or by value.  This is used only when compiling with
`-fpreview=in' enabled.  */
 
 bool
 Target::preferPassByRef (Type *param_type)
 {
-  if (param_type->size () == SIZE_INVALID)
+  /* See note in Target::isReturnOnStack.  */
+  Type *tb = param_type->toBasetype ();
+  if (tb->size () == SIZE_INVALID)
 return false;
 
-  tree type = build_ctype (param_type);
-
-  /* Prefer a `ref' if the type is an aggregate, and its size is greater than
- its alignment.  */
-  if (AGGREGATE_TYPE_P (type)
-  && (!valid_constant_size_p (TYPE_SIZE_UNIT (type))
- || compare_tree_int (TYPE_SIZE_UNIT (type), TYPE_ALIGN (type)) > 0))
-return true;
-
-  /* If the back-end is always going to pass this by invisible reference.  */
-  if (pass_by_reference (NULL, function_arg_info (type, true)))
-return true;
-
-  /* If returning the parameter means the caller will do RVO.  */
-  if (targetm.calls.return_in_memory (type, NULL_TREE))
-return true;
-
-  return false;
+  return (tb->ty == TY::Tstruct || tb->ty == TY::Tsarray);
 }
diff --git a/gcc/testsuite/gdc.dg/pr112285.d b/gcc/testsuite/gdc.dg/pr112285.d
new file mode 100644
index 000..5ca100a74a9
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr112285.d
@@ -0,0 +1,13 @@
+// { dg-do compile }
+// { dg-additional-options "-fpreview=in" }
+struct S112285
+{
+}
+
+class C112285
+{
+S112285 s;
+void f112285(in C112285)
+{
+}
+}
diff --git a/gcc/testsuite/gdc.dg/pr112290.d b/gcc/testsuite/gdc.dg/pr112290.d
new file mode 100644
index 000..7456fc21be1
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr112290.d
@@ -0,0 +1,15 @@
+// { dg-do compile }
+// { dg-additional-options "-fpreview=in" }
+struct S112290a
+{
+S112290b* p;
+bool opEquals(in S112290a)
+{
+return p == p;
+}
+}
+
+struct S112290b
+{
+string s;
+}
diff --git a/gcc/testsuite/gdc.test/compilable/previewin.d 
b/gcc/testsuite/gdc.test/compilable/previewin.d
index 8926fbd6aa7..558005c5280 100644
--- a/gcc/testsuite/gdc.test/compilable/previewin.d
+++ b/gcc/testsuite/gdc.test/compilable/previewin.d
@@ -79,14 +79,11 @@ version (Win64)
 {
 void checkReal(in real p)
 {
-// ref for x87 real, value for double-precision real
-static assert(__traits(isRef, p) == (real.sizeof > 8));
 }
 
 struct RGB { ubyte r, g, b; }
 void checkNonPowerOf2(in RGB p)
 {
-static assert(__traits(isRef, p));
 }
 }
 else version (X86_64) // Posix x86_64
@@ -94,7 +91,6 @@ else version (X86_64) // Posix x86_64
 struct Empty {} // 1 dummy byte passed on the stack
 void checkEmptyStruct(in Empty p)
 {
-static assert(!__traits(isRef, p));
 }
 
 static if (is(__vector(double[4])))
@@ -102,7 +98,6 @@ else version (X86_64) // Posix x86_6

[gcc r12-10202] d: Fix -fpreview=in ICEs with forward referenced parameter [PR112285]

2024-03-10 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:ec3a01024dd86c51d1e563df9395123765cf548d

commit r12-10202-gec3a01024dd86c51d1e563df9395123765cf548d
Author: Iain Buclaw 
Date:   Sun Mar 10 17:49:06 2024 +0100

d: Fix -fpreview=in ICEs with forward referenced parameter [PR112285]

The way that the target hook preferPassByRef is implemented, it relied
on the GCC "back-end" tree type to determine whether or not to use `ref'
ABI for D `in' parameters; e.g: prefer by value if it is expected that
the target will pass the type around in registers.

Building the GCC tree type depends on the AST type being complete - all
semantic processing is finished - but as this hook is called from the
front-end, this will not be the case for forward referenced or
self-referencing types.

The consensus in upstream is that `in' parameters should always be
implicitly `ref', but as the front-end does not yet support all types
being rvalue references, limit this just static arrays and structs.

PR d/112285
PR d/112290

gcc/d/ChangeLog:

* d-target.cc (Target::preferPassByRef): Return true for all static
array and struct types.

gcc/testsuite/ChangeLog:

* gdc.dg/pr112285.d: New test.
* gdc.dg/pr112290.d: New test.
* gdc.test/compilable/previewin.d: Adjust testcase.

(cherry picked from commit 025ff57c19efae6c8d76df6b93e7d9827017acc9)

Diff:
---
 gcc/d/d-target.cc | 25 +
 gcc/testsuite/gdc.dg/pr112285.d   | 13 +
 gcc/testsuite/gdc.dg/pr112290.d   | 15 +++
 gcc/testsuite/gdc.test/compilable/previewin.d |  6 --
 4 files changed, 33 insertions(+), 26 deletions(-)

diff --git a/gcc/d/d-target.cc b/gcc/d/d-target.cc
index d4350e593e4..f80ea466e24 100644
--- a/gcc/d/d-target.cc
+++ b/gcc/d/d-target.cc
@@ -586,31 +586,16 @@ Target::supportsLinkerDirective (void) const
 }
 
 /* Decides whether an `in' parameter of the specified POD type PARAM_TYPE is to
-   be passed by reference or by valie.  This is used only when compiling with
+   be passed by reference or by value.  This is used only when compiling with
`-fpreview=in' enabled.  */
 
 bool
 Target::preferPassByRef (Type *param_type)
 {
-  if (param_type->size () == SIZE_INVALID)
+  /* See note in Target::isReturnOnStack.  */
+  Type *tb = param_type->toBasetype ();
+  if (tb->size () == SIZE_INVALID)
 return false;
 
-  tree type = build_ctype (param_type);
-
-  /* Prefer a `ref' if the type is an aggregate, and its size is greater than
- its alignment.  */
-  if (AGGREGATE_TYPE_P (type)
-  && (!valid_constant_size_p (TYPE_SIZE_UNIT (type))
- || compare_tree_int (TYPE_SIZE_UNIT (type), TYPE_ALIGN (type)) > 0))
-return true;
-
-  /* If the back-end is always going to pass this by invisible reference.  */
-  if (pass_by_reference (NULL, function_arg_info (type, true)))
-return true;
-
-  /* If returning the parameter means the caller will do RVO.  */
-  if (targetm.calls.return_in_memory (type, NULL_TREE))
-return true;
-
-  return false;
+  return (tb->ty == TY::Tstruct || tb->ty == TY::Tsarray);
 }
diff --git a/gcc/testsuite/gdc.dg/pr112285.d b/gcc/testsuite/gdc.dg/pr112285.d
new file mode 100644
index 000..5ca100a74a9
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr112285.d
@@ -0,0 +1,13 @@
+// { dg-do compile }
+// { dg-additional-options "-fpreview=in" }
+struct S112285
+{
+}
+
+class C112285
+{
+S112285 s;
+void f112285(in C112285)
+{
+}
+}
diff --git a/gcc/testsuite/gdc.dg/pr112290.d b/gcc/testsuite/gdc.dg/pr112290.d
new file mode 100644
index 000..7456fc21be1
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr112290.d
@@ -0,0 +1,15 @@
+// { dg-do compile }
+// { dg-additional-options "-fpreview=in" }
+struct S112290a
+{
+S112290b* p;
+bool opEquals(in S112290a)
+{
+return p == p;
+}
+}
+
+struct S112290b
+{
+string s;
+}
diff --git a/gcc/testsuite/gdc.test/compilable/previewin.d 
b/gcc/testsuite/gdc.test/compilable/previewin.d
index 8926fbd6aa7..558005c5280 100644
--- a/gcc/testsuite/gdc.test/compilable/previewin.d
+++ b/gcc/testsuite/gdc.test/compilable/previewin.d
@@ -79,14 +79,11 @@ version (Win64)
 {
 void checkReal(in real p)
 {
-// ref for x87 real, value for double-precision real
-static assert(__traits(isRef, p) == (real.sizeof > 8));
 }
 
 struct RGB { ubyte r, g, b; }
 void checkNonPowerOf2(in RGB p)
 {
-static assert(__traits(isRef, p));
 }
 }
 else version (X86_64) // Posix x86_64
@@ -94,7 +91,6 @@ else version (X86_64) // Posix x86_64
 struct Empty {} // 1 dummy byte passed on the stack
 void checkEmptyStruct(in Empty p)
 {
-static assert(!__traits(isRef, p));
 }
 
 static if (is(__vector(double[4])))
@@ -102,7 +98,6 @@ else version (X86_64) // Posix x86_

[gcc r14-9505] d: Merge upstream dmd, druntime 855353a1d9

2024-03-17 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:2d454f982914c481a268f1c63e431b2682cc3be0

commit r14-9505-g2d454f982914c481a268f1c63e431b2682cc3be0
Author: Iain Buclaw 
Date:   Sun Mar 17 12:00:57 2024 +0100

d: Merge upstream dmd, druntime 855353a1d9

D front-end changes:

- Import dmd v2.108.0-rc.1.
- Add support for Named Arguments for functions.
- Hex strings now convert to integer arrays.

D runtime changes:

- Import druntime v2.108.0-rc.1.

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 855353a1d9.
* dmd/VERSION:

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 855353a1d9.

Diff:
---
 gcc/d/dmd/MERGE|  2 +-
 gcc/d/dmd/VERSION  |  2 +-
 gcc/d/dmd/cxxfrontend.d| 10 +++
 gcc/d/dmd/dcast.d  | 31 +---
 gcc/d/dmd/dinterpret.d |  2 +-
 gcc/d/dmd/dsymbolsem.d |  7 +-
 gcc/d/dmd/dtemplate.d  | 48 +---
 gcc/d/dmd/enum.h   |  6 ++
 gcc/d/dmd/expression.h | 15 
 gcc/d/dmd/expressionsem.d  |  9 ++-
 gcc/d/dmd/hdrgen.d |  3 +-
 gcc/d/dmd/lexer.d  |  1 -
 gcc/d/dmd/mtype.d  | 17 +++--
 gcc/d/dmd/mtype.h  |  5 +-
 gcc/d/dmd/root/filename.d  |  2 +-
 gcc/d/dmd/root/filename.h  |  2 +-
 gcc/d/dmd/template.h   | 16 +---
 gcc/d/dmd/templatesem.d| 85 ++
 gcc/d/dmd/typesem.d| 16 +++-
 .../gdc.test/compilable/named_arguments_auto_ref.d | 39 ++
 .../gdc.test/compilable/named_arguments_ifti.d | 27 +++
 .../gdc.test/fail_compilation/hexstring.d  |  5 +-
 .../fail_compilation/named_arguments_error.d   | 11 ++-
 .../fail_compilation/named_arguments_ifti_error.d  | 20 +
 gcc/testsuite/gdc.test/runnable/literal.d  | 10 ++-
 libphobos/libdruntime/MERGE|  2 +-
 .../core/internal/gc/impl/conservative/gc.d|  4 +-
 .../libdruntime/core/internal/gc/impl/manual/gc.d  |  2 +-
 .../libdruntime/core/internal/gc/impl/proto/gc.d   |  2 +-
 29 files changed, 294 insertions(+), 107 deletions(-)

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index 4c0a0bc2aac..a00872ef864 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-f8bae0455851a1dfc8113d69323415f6de549e39
+855353a1d9e16d43e85b6cf2b03aef388619bd16
 
 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/VERSION b/gcc/d/dmd/VERSION
index 416807683f5..8ca452f8912 100644
--- a/gcc/d/dmd/VERSION
+++ b/gcc/d/dmd/VERSION
@@ -1 +1 @@
-v2.108.0-beta.1
+v2.108.0-rc.1
diff --git a/gcc/d/dmd/cxxfrontend.d b/gcc/d/dmd/cxxfrontend.d
index 8c046343468..a0432d2e1b4 100644
--- a/gcc/d/dmd/cxxfrontend.d
+++ b/gcc/d/dmd/cxxfrontend.d
@@ -14,6 +14,7 @@ import dmd.aggregate : AggregateDeclaration;
 import dmd.arraytypes;
 import dmd.astenums;
 import dmd.common.outbuffer : OutBuffer;
+import dmd.denum : EnumDeclaration;
 import dmd.dmodule /*: Module*/;
 import dmd.dscope : Scope;
 import dmd.dstruct /*: StructDeclaration*/;
@@ -213,6 +214,15 @@ void genCppHdrFiles(ref Modules ms)
 return dmd.dtoh.genCppHdrFiles(ms);
 }
 
+/***
+ * enumsem.d
+ */
+Expression getDefaultValue(EnumDeclaration ed, const ref Loc loc)
+{
+import dmd.enumsem;
+return dmd.enumsem.getDefaultValue(ed, loc);
+}
+
 /***
  * expression.d
  */
diff --git a/gcc/d/dmd/dcast.d b/gcc/d/dmd/dcast.d
index a49bd575f4b..8a713f424d6 100644
--- a/gcc/d/dmd/dcast.d
+++ b/gcc/d/dmd/dcast.d
@@ -629,7 +629,7 @@ MATCH implicitConvTo(Expression e, Type t)
 
 TY tyn = e.type.nextOf().ty;
 
-if (!tyn.isSomeChar)
+if (!tyn.isSomeChar && !e.hexString)
 return visit(e);
 
 switch (t.ty)
@@ -703,6 +703,11 @@ MATCH implicitConvTo(Expression e, Type t)
 return MATCH.nomatch;
 m = MATCH.constant;
 }
+if (e.hexString && tn.isintegral && (tn.size == e.sz || 
(!e.committed && (e.len % tn.size) == 0)))
+{
+m = MATCH.convert;
+return m;
+}
 if (!e.committed)
 {
 switch (tn.ty)
@@ -719,9 +724,6 @@ MATCH implicitConvTo(Expression e, Type t)
 if (e.postfix != 'd')
 m = MATCH.convert;
 return m;
-   

[gcc r14-9821] d: Merge upstream dmd, druntime b65767825f, phobos 92dc5a4e9.

2024-04-06 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:09992f8b881aa2dfbee1e9d6954c3ca90cd3fe41

commit r14-9821-g09992f8b881aa2dfbee1e9d6954c3ca90cd3fe41
Author: Iain Buclaw 
Date:   Sat Apr 6 14:14:11 2024 +0200

d: Merge upstream dmd, druntime b65767825f, phobos 92dc5a4e9.

Synchronizing with the upstream release of v2.108.0.

D front-end changes:

- Import dmd v2.108.0.

D runtime changes:

- Import druntime v2.108.0.

Phobos changes:

- Import phobos v2.108.0.

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd b65767825f.
* dmd/VERSION: Bump version to v2.108.0.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime b65767825f.
* src/MERGE: Merge upstream phobos 92dc5a4e9.

Diff:
---
 gcc/d/dmd/MERGE|  2 +-
 gcc/d/dmd/VERSION  |  2 +-
 libphobos/libdruntime/MERGE|  2 +-
 .../libdruntime/core/internal/array/duplication.d  | 14 ++-
 libphobos/src/MERGE|  2 +-
 .../allocator/building_blocks/kernighan_ritchie.d  |  4 +-
 libphobos/src/std/net/curl.d   |  5 ++-
 libphobos/src/std/typecons.d   | 47 +-
 8 files changed, 68 insertions(+), 10 deletions(-)

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index a00872ef864..dc47db87a80 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-855353a1d9e16d43e85b6cf2b03aef388619bd16
+b65767825f365dbc153457fc86e1054b03196c6d
 
 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/VERSION b/gcc/d/dmd/VERSION
index 8ca452f8912..5868b874955 100644
--- a/gcc/d/dmd/VERSION
+++ b/gcc/d/dmd/VERSION
@@ -1 +1 @@
-v2.108.0-rc.1
+v2.108.0
diff --git a/libphobos/libdruntime/MERGE b/libphobos/libdruntime/MERGE
index a00872ef864..dc47db87a80 100644
--- a/libphobos/libdruntime/MERGE
+++ b/libphobos/libdruntime/MERGE
@@ -1,4 +1,4 @@
-855353a1d9e16d43e85b6cf2b03aef388619bd16
+b65767825f365dbc153457fc86e1054b03196c6d
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
diff --git a/libphobos/libdruntime/core/internal/array/duplication.d 
b/libphobos/libdruntime/core/internal/array/duplication.d
index eec6af92fef..9df84893bb9 100644
--- a/libphobos/libdruntime/core/internal/array/duplication.d
+++ b/libphobos/libdruntime/core/internal/array/duplication.d
@@ -21,9 +21,9 @@ U[] _dup(T, U)(scope T[] a) pure nothrow @trusted if 
(__traits(isPOD, T))
 {
 import core.stdc.string : memcpy;
 import core.internal.array.construction: _d_newarrayUPureNothrow;
-auto arr = _d_newarrayUPureNothrow!T(a.length, is(T == shared));
+auto arr = _d_newarrayUPureNothrow!U(a.length, is(U == shared));
 memcpy(cast(void*) arr.ptr, cast(const(void)*) a.ptr, T.sizeof * 
a.length);
-return *cast(U[]*) &arr;
+return arr;
 }
 }
 
@@ -358,3 +358,13 @@ U[] _dup(T, U)(T[] a) if (!__traits(isPOD, T))
 static assert(test!Copy());
 assert(test!Copy());
 }
+
+// https://issues.dlang.org/show_bug.cgi?id=24453
+@safe unittest
+{
+static inout(char)[] foo(ref scope return inout(char)[] s)
+{
+auto bla = s.idup;
+return s;
+}
+}
diff --git a/libphobos/src/MERGE b/libphobos/src/MERGE
index ff34bece2a3..a4f25db810e 100644
--- a/libphobos/src/MERGE
+++ b/libphobos/src/MERGE
@@ -1,4 +1,4 @@
-a2ade9dec49e70c6acd447df52321988a4c2fb9f
+92dc5a4e98591a0e6b0af4ff0f84f096fea09016
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/phobos repository.
diff --git 
a/libphobos/src/std/experimental/allocator/building_blocks/kernighan_ritchie.d 
b/libphobos/src/std/experimental/allocator/building_blocks/kernighan_ritchie.d
index 6883d33adae..167cf1bc6bc 100644
--- 
a/libphobos/src/std/experimental/allocator/building_blocks/kernighan_ritchie.d
+++ 
b/libphobos/src/std/experimental/allocator/building_blocks/kernighan_ritchie.d
@@ -647,7 +647,7 @@ fronting the GC allocator.
 import std.experimental.allocator.gc_allocator : GCAllocator;
 import std.typecons : Ternary;
 // KRRegion fronting a general-purpose allocator
-ubyte[1024 * 128] buf;
+align(KRRegion!().alignment) ubyte[1024 * 128] buf;
 auto alloc = fallbackAllocator(KRRegion!()(buf), GCAllocator.instance);
 auto b = alloc.allocate(100);
 assert(b.length == 100);
@@ -916,7 +916,7 @@ version (StdUnittest)
 @system unittest
 {   import std.typecons : Ternary;
 
-ubyte[1024] b;
+align(KRRegion!().alignment) ubyte[1024] b;
 auto alloc = KRRegion!()(b);
 
 auto k = alloc.allocate(128);
diff --git a/libphobos/src/std/net/curl.d b/libphobos/src/std/net/curl.d
index 6aec366c657..3f823013e65 100644
--- a/libphobos/src/std/net/curl.d

[gcc r14-10036] d: Fix ICE in build_deref, at d/d-codegen.cc:1650 [PR111650]

2024-04-19 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:4d4929fe0654d51b52a2bf6e6188d7aad0bf17ac

commit r14-10036-g4d4929fe0654d51b52a2bf6e6188d7aad0bf17ac
Author: Iain Buclaw 
Date:   Fri Apr 19 10:51:12 2024 +0200

d: Fix ICE in build_deref, at d/d-codegen.cc:1650 [PR111650]

PR d/111650

gcc/d/ChangeLog:

* decl.cc (get_fndecl_arguments): Move generation of frame type to 
...
(DeclVisitor::visit (FuncDeclaration *)): ... here, after the call 
to
build_closure.

gcc/testsuite/ChangeLog:

* gdc.dg/pr111650.d: New test.

Diff:
---
 gcc/d/decl.cc   | 20 ++--
 gcc/testsuite/gdc.dg/pr111650.d | 21 +
 2 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 3b7627d3dfa..0a87c85ae2e 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -163,16 +163,6 @@ get_fndecl_arguments (FuncDeclaration *decl)
  tree parm_decl = get_symbol_decl (decl->vthis);
  DECL_ARTIFICIAL (parm_decl) = 1;
  TREE_READONLY (parm_decl) = 1;
-
- if (decl->vthis->type == Type::tvoidptr)
-   {
- /* Replace generic pointer with back-end closure type
-(this wins for gdb).  */
- tree frame_type = FRAMEINFO_TYPE (get_frameinfo (decl));
- gcc_assert (frame_type != NULL_TREE);
- TREE_TYPE (parm_decl) = build_pointer_type (frame_type);
-   }
-
  param_list = chainon (param_list, parm_decl);
}
 
@@ -1072,6 +1062,16 @@ public:
 /* May change cfun->static_chain.  */
 build_closure (d);
 
+/* Replace generic pointer with back-end closure type
+   (this wins for gdb).  */
+if (d->vthis && d->vthis->type == Type::tvoidptr)
+  {
+   tree frame_type = FRAMEINFO_TYPE (get_frameinfo (d));
+   gcc_assert (frame_type != NULL_TREE);
+   tree parm_decl = get_symbol_decl (d->vthis);
+   TREE_TYPE (parm_decl) = build_pointer_type (frame_type);
+  }
+
 if (d->vresult)
   declare_local_var (d->vresult);
 
diff --git a/gcc/testsuite/gdc.dg/pr111650.d b/gcc/testsuite/gdc.dg/pr111650.d
new file mode 100644
index 000..4298a76d38f
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr111650.d
@@ -0,0 +1,21 @@
+// { dg-do compile }
+ref V require(K, V)(ref V[K] aa, K key, lazy V value);
+
+struct Root
+{
+ulong[3] f;
+}
+
+Root[ulong] roots;
+
+Root getRoot(int fd, ulong rootID)
+{
+return roots.require(rootID,
+{
+Root result;
+inoLookup(fd, () => result);
+return result;
+}());
+}
+
+void inoLookup(int, scope Root delegate()) { }


[gcc r12-10924] d: Fix ICE in build_deref, at d/d-codegen.cc:1650 [PR111650]

2025-01-21 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:4d320a7df4b25c2eb060a2a16fee8b993301be55

commit r12-10924-g4d320a7df4b25c2eb060a2a16fee8b993301be55
Author: Iain Buclaw 
Date:   Fri Apr 19 10:51:12 2024 +0200

d: Fix ICE in build_deref, at d/d-codegen.cc:1650 [PR111650]

PR d/111650

gcc/d/ChangeLog:

* decl.cc (get_fndecl_arguments): Move generation of frame type to 
...
(DeclVisitor::visit (FuncDeclaration *)): ... here, after the call 
to
build_closure.

gcc/testsuite/ChangeLog:

* gdc.dg/pr111650.d: New test.

(cherry picked from commit 4d4929fe0654d51b52a2bf6e6188d7aad0bf17ac)

Diff:
---
 gcc/d/decl.cc   | 20 ++--
 gcc/testsuite/gdc.dg/pr111650.d | 21 +
 2 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index a2dd8b84c59f..6c2705d9864f 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -162,16 +162,6 @@ get_fndecl_arguments (FuncDeclaration *decl)
  tree parm_decl = get_symbol_decl (decl->vthis);
  DECL_ARTIFICIAL (parm_decl) = 1;
  TREE_READONLY (parm_decl) = 1;
-
- if (decl->vthis->type == Type::tvoidptr)
-   {
- /* Replace generic pointer with back-end closure type
-(this wins for gdb).  */
- tree frame_type = FRAMEINFO_TYPE (get_frameinfo (decl));
- gcc_assert (frame_type != NULL_TREE);
- TREE_TYPE (parm_decl) = build_pointer_type (frame_type);
-   }
-
  param_list = chainon (param_list, parm_decl);
}
 
@@ -1047,6 +1037,16 @@ public:
 /* May change cfun->static_chain.  */
 build_closure (d);
 
+/* Replace generic pointer with back-end closure type
+   (this wins for gdb).  */
+if (d->vthis && d->vthis->type == Type::tvoidptr)
+  {
+   tree frame_type = FRAMEINFO_TYPE (get_frameinfo (d));
+   gcc_assert (frame_type != NULL_TREE);
+   tree parm_decl = get_symbol_decl (d->vthis);
+   TREE_TYPE (parm_decl) = build_pointer_type (frame_type);
+  }
+
 if (d->vresult)
   declare_local_var (d->vresult);
 
diff --git a/gcc/testsuite/gdc.dg/pr111650.d b/gcc/testsuite/gdc.dg/pr111650.d
new file mode 100644
index ..4298a76d38f9
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr111650.d
@@ -0,0 +1,21 @@
+// { dg-do compile }
+ref V require(K, V)(ref V[K] aa, K key, lazy V value);
+
+struct Root
+{
+ulong[3] f;
+}
+
+Root[ulong] roots;
+
+Root getRoot(int fd, ulong rootID)
+{
+return roots.require(rootID,
+{
+Root result;
+inoLookup(fd, () => result);
+return result;
+}());
+}
+
+void inoLookup(int, scope Root delegate()) { }


[gcc r13-9338] d: Fix ICE in build_deref, at d/d-codegen.cc:1650 [PR111650]

2025-01-21 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:24291f6e40e4b37954b368361fc97fc8fb1bf864

commit r13-9338-g24291f6e40e4b37954b368361fc97fc8fb1bf864
Author: Iain Buclaw 
Date:   Fri Apr 19 10:51:12 2024 +0200

d: Fix ICE in build_deref, at d/d-codegen.cc:1650 [PR111650]

PR d/111650

gcc/d/ChangeLog:

* decl.cc (get_fndecl_arguments): Move generation of frame type to 
...
(DeclVisitor::visit (FuncDeclaration *)): ... here, after the call 
to
build_closure.

gcc/testsuite/ChangeLog:

* gdc.dg/pr111650.d: New test.

(cherry picked from commit 4d4929fe0654d51b52a2bf6e6188d7aad0bf17ac)

Diff:
---
 gcc/d/decl.cc   | 20 ++--
 gcc/testsuite/gdc.dg/pr111650.d | 21 +
 2 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 2a135b516aa6..84274b3f3c31 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -163,16 +163,6 @@ get_fndecl_arguments (FuncDeclaration *decl)
  tree parm_decl = get_symbol_decl (decl->vthis);
  DECL_ARTIFICIAL (parm_decl) = 1;
  TREE_READONLY (parm_decl) = 1;
-
- if (decl->vthis->type == Type::tvoidptr)
-   {
- /* Replace generic pointer with back-end closure type
-(this wins for gdb).  */
- tree frame_type = FRAMEINFO_TYPE (get_frameinfo (decl));
- gcc_assert (frame_type != NULL_TREE);
- TREE_TYPE (parm_decl) = build_pointer_type (frame_type);
-   }
-
  param_list = chainon (param_list, parm_decl);
}
 
@@ -1060,6 +1050,16 @@ public:
 /* May change cfun->static_chain.  */
 build_closure (d);
 
+/* Replace generic pointer with back-end closure type
+   (this wins for gdb).  */
+if (d->vthis && d->vthis->type == Type::tvoidptr)
+  {
+   tree frame_type = FRAMEINFO_TYPE (get_frameinfo (d));
+   gcc_assert (frame_type != NULL_TREE);
+   tree parm_decl = get_symbol_decl (d->vthis);
+   TREE_TYPE (parm_decl) = build_pointer_type (frame_type);
+  }
+
 if (d->vresult)
   declare_local_var (d->vresult);
 
diff --git a/gcc/testsuite/gdc.dg/pr111650.d b/gcc/testsuite/gdc.dg/pr111650.d
new file mode 100644
index ..4298a76d38f9
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr111650.d
@@ -0,0 +1,21 @@
+// { dg-do compile }
+ref V require(K, V)(ref V[K] aa, K key, lazy V value);
+
+struct Root
+{
+ulong[3] f;
+}
+
+Root[ulong] roots;
+
+Root getRoot(int fd, ulong rootID)
+{
+return roots.require(rootID,
+{
+Root result;
+inoLookup(fd, () => result);
+return result;
+}());
+}
+
+void inoLookup(int, scope Root delegate()) { }


[gcc r14-11223] d: Fix ICE in expand_d_format when diagnosing empty enum [PR117115]

2025-01-17 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:4abeaeba435054ad0ab59cf570620b37c06ffcc4

commit r14-11223-g4abeaeba435054ad0ab59cf570620b37c06ffcc4
Author: Iain Buclaw 
Date:   Fri Jan 17 20:10:39 2025 +0100

d: Fix ICE in expand_d_format when diagnosing empty enum [PR117115]

This was fixed in upstream dmd, and merged in r15-6824. Backport the
individual fix from the upstream merge for releases/gcc-14.

PR d/117115

gcc/testsuite/ChangeLog:

* gdc.dg/pr117115.d: New test.

(cherry picked from commit 975c4f1a5de4ede89ee9499cd1a73d613a4aeae4)

Diff:
---
 gcc/d/dmd/enumsem.d | 2 +-
 gcc/testsuite/gdc.dg/pr117115.d | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/d/dmd/enumsem.d b/gcc/d/dmd/enumsem.d
index 3886ca25e97b..06683b254907 100644
--- a/gcc/d/dmd/enumsem.d
+++ b/gcc/d/dmd/enumsem.d
@@ -186,7 +186,7 @@ void enumSemantic(Scope* sc, EnumDeclaration ed)
 
 if (ed.members.length == 0)
 {
-.error(ed.loc, "%s `%s enum `%s` must have at least one member", 
ed.kind, ed.toPrettyChars, ed.toChars());
+.error(ed.loc, "%s `%s` enum `%s` must have at least one member", 
ed.kind, ed.toPrettyChars, ed.toChars());
 ed.errors = true;
 ed.semanticRun = PASS.semanticdone;
 return;
diff --git a/gcc/testsuite/gdc.dg/pr117115.d b/gcc/testsuite/gdc.dg/pr117115.d
new file mode 100644
index ..b012268b509e
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr117115.d
@@ -0,0 +1,3 @@
+// { dg-do compile }
+
+enum E117115 {} // { dg-error "must have at least one member" }


[gcc r14-11230] d: Fix failing test with 32-bit compiler [PR114434]

2025-01-20 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:ffa44df6768368dc516c9626ec388a3561c7644f

commit r14-11230-gffa44df6768368dc516c9626ec388a3561c7644f
Author: Iain Buclaw 
Date:   Mon Jan 20 20:01:03 2025 +0100

d: Fix failing test with 32-bit compiler [PR114434]

Since the introduction of gdc.test/runnable/test23514.d, it's exposed an
incorrect compilation when adding a 64-bit constant to a link-time
address.  The current cast to size_t causes a loss of precision, which
can result in incorrect compilation.

PR d/114434

gcc/d/ChangeLog:

* expr.cc (ExprVisitor::visit (PtrExp *)): Get the offset as a
dinteger_t rather than a size_t.
(ExprVisitor::visit (SymOffExp *)): Likewise.

(cherry picked from commit 9ab38952a2033d6d4a8e31c3c4d2ab1a25a406c6)

Diff:
---
 gcc/d/expr.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index d055e0b4025b..733302f8e2ee 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -1497,7 +1497,7 @@ public:
   void visit (PtrExp *e) final override
   {
 Type *tnext = NULL;
-size_t offset;
+dinteger_t offset;
 tree result;
 
 if (e->e1->op == EXP::add)
@@ -2072,7 +2072,7 @@ public:
   void visit (SymOffExp *e) final override
   {
 /* Build the address and offset of the symbol.  */
-size_t soffset = e->isSymOffExp ()->offset;
+dinteger_t soffset = e->isSymOffExp ()->offset;
 tree result = get_decl_tree (e->var);
 TREE_USED (result) = 1;


[gcc r13-9336] d: Fix failing test with 32-bit compiler [PR114434]

2025-01-20 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:76d660277e5cd61055c3838bf59c90321d4686fb

commit r13-9336-g76d660277e5cd61055c3838bf59c90321d4686fb
Author: Iain Buclaw 
Date:   Mon Jan 20 20:01:03 2025 +0100

d: Fix failing test with 32-bit compiler [PR114434]

Since the introduction of gdc.test/runnable/test23514.d, it's exposed an
incorrect compilation when adding a 64-bit constant to a link-time
address.  The current cast to size_t causes a loss of precision, which
can result in incorrect compilation.

PR d/114434

gcc/d/ChangeLog:

* expr.cc (ExprVisitor::visit (PtrExp *)): Get the offset as a
dinteger_t rather than a size_t.
(ExprVisitor::visit (SymOffExp *)): Likewise.

(cherry picked from commit 9ab38952a2033d6d4a8e31c3c4d2ab1a25a406c6)

Diff:
---
 gcc/d/expr.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 2bbb2ebd22be..5d91349bf5b5 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -1513,7 +1513,7 @@ public:
   void visit (PtrExp *e) final override
   {
 Type *tnext = NULL;
-size_t offset;
+dinteger_t offset;
 tree result;
 
 if (e->e1->op == EXP::add)
@@ -2091,7 +2091,7 @@ public:
   void visit (SymOffExp *e) final override
   {
 /* Build the address and offset of the symbol.  */
-size_t soffset = e->isSymOffExp ()->offset;
+dinteger_t soffset = e->isSymOffExp ()->offset;
 tree result = get_decl_tree (e->var);
 TREE_USED (result) = 1;


[gcc r15-7071] d: Fix failing test with 32-bit compiler [PR114434]

2025-01-20 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:9ab38952a2033d6d4a8e31c3c4d2ab1a25a406c6

commit r15-7071-g9ab38952a2033d6d4a8e31c3c4d2ab1a25a406c6
Author: Iain Buclaw 
Date:   Mon Jan 20 20:01:03 2025 +0100

d: Fix failing test with 32-bit compiler [PR114434]

Since the introduction of gdc.test/runnable/test23514.d, it's exposed an
incorrect compilation when adding a 64-bit constant to a link-time
address.  The current cast to size_t causes a loss of precision, which
can result in incorrect compilation.

PR d/114434

gcc/d/ChangeLog:

* expr.cc (ExprVisitor::visit (PtrExp *)): Get the offset as a
dinteger_t rather than a size_t.
(ExprVisitor::visit (SymOffExp *)): Likewise.

Diff:
---
 gcc/d/expr.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 304d6bd203c5..f04ec33320a4 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -1499,7 +1499,7 @@ public:
   void visit (PtrExp *e) final override
   {
 Type *tnext = NULL;
-size_t offset;
+dinteger_t offset;
 tree result;
 
 if (e->e1->op == EXP::add)
@@ -2074,7 +2074,7 @@ public:
   void visit (SymOffExp *e) final override
   {
 /* Build the address and offset of the symbol.  */
-size_t soffset = e->isSymOffExp ()->offset;
+dinteger_t soffset = e->isSymOffExp ()->offset;
 tree result = get_decl_tree (e->var);
 TREE_USED (result) = 1;


[gcc r12-10921] d: Fix failing test with 32-bit compiler [PR114434]

2025-01-20 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:f4b8c08c86237e7eb29defb2f8ae3bff22581e5f

commit r12-10921-gf4b8c08c86237e7eb29defb2f8ae3bff22581e5f
Author: Iain Buclaw 
Date:   Mon Jan 20 20:01:03 2025 +0100

d: Fix failing test with 32-bit compiler [PR114434]

Since the introduction of gdc.test/runnable/test23514.d, it's exposed an
incorrect compilation when adding a 64-bit constant to a link-time
address.  The current cast to size_t causes a loss of precision, which
can result in incorrect compilation.

PR d/114434

gcc/d/ChangeLog:

* expr.cc (ExprVisitor::visit (PtrExp *)): Get the offset as a
dinteger_t rather than a size_t.
(ExprVisitor::visit (SymOffExp *)): Likewise.

gcc/testsuite/ChangeLog:

* gdc.test/runnable/test23514.d: New test.

(cherry picked from commit 9ab38952a2033d6d4a8e31c3c4d2ab1a25a406c6)

Diff:
---
 gcc/d/expr.cc   |  4 ++--
 gcc/testsuite/gdc.test/runnable/test23514.d | 13 +
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 7afd98975b15..c308a068fc17 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -1537,7 +1537,7 @@ public:
   void visit (PtrExp *e)
   {
 Type *tnext = NULL;
-size_t offset;
+dinteger_t offset;
 tree result;
 
 if (e->e1->op == EXP::add)
@@ -2115,7 +2115,7 @@ public:
   void visit (SymOffExp *e)
   {
 /* Build the address and offset of the symbol.  */
-size_t soffset = e->isSymOffExp ()->offset;
+dinteger_t soffset = e->isSymOffExp ()->offset;
 tree result = get_decl_tree (e->var);
 TREE_USED (result) = 1;
 
diff --git a/gcc/testsuite/gdc.test/runnable/test23514.d 
b/gcc/testsuite/gdc.test/runnable/test23514.d
new file mode 100644
index ..1ba7e218d528
--- /dev/null
+++ b/gcc/testsuite/gdc.test/runnable/test23514.d
@@ -0,0 +1,13 @@
+// DISABLED: win64
+// https://issues.dlang.org/show_bug.cgi?id=23514
+
+// Note: this test is disabled on Win64 because of an issue with the Windows
+// MS-COFF backend causing it to fail.
+
+enum ulong offset = 0x___UL;
+
+void main()
+{
+ulong voffset = offset;
+assert((cast(ulong)&main + voffset) == (cast(ulong)&main + offset));
+}


[gcc r15-7111] libphobos: Add MIPS64 implementation of fiber_switchContext [PR118584]

2025-01-21 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:79186e392c77c1862197a49421f77644e3b8c05d

commit r15-7111-g79186e392c77c1862197a49421f77644e3b8c05d
Author: Iain Buclaw 
Date:   Tue Jan 21 19:41:05 2025 +0100

libphobos: Add MIPS64 implementation of fiber_switchContext [PR118584]

Replaces the generic implementation.  The `core.thread.fiber' module
already defines version=AsmExternal on mips64el-linux-gnuabi64.

PR d/118584

libphobos/ChangeLog:

* libdruntime/config/mips/switchcontext.S: Add MIPS64 N64 ABI
implementation of fiber_switchContext.

Diff:
---
 libphobos/libdruntime/config/mips/switchcontext.S | 78 +++
 1 file changed, 78 insertions(+)

diff --git a/libphobos/libdruntime/config/mips/switchcontext.S 
b/libphobos/libdruntime/config/mips/switchcontext.S
index d2fed64c78c1..078ad0b3cce3 100644
--- a/libphobos/libdruntime/config/mips/switchcontext.S
+++ b/libphobos/libdruntime/config/mips/switchcontext.S
@@ -99,4 +99,82 @@ fiber_switchContext:
 .end fiber_switchContext
 .size fiber_switchContext,.-fiber_switchContext
 
+#endif /* _MIPS_SIM == _ABIO32 */
+
+#if defined(__mips64) && _MIPS_SIM == _ABI64
+/
+ * MIPS 64 ASM BITS
+ * $a0 - void** - ptr to old stack pointer
+ * $a1 - void*  - new stack pointer
+ *
+ */
+.text
+.globl fiber_switchContext
+.align 2
+.ent fiber_switchContext,0
+fiber_switchContext:
+.cfi_startproc
+daddiu $sp, $sp, -(10 * 8)
+
+// fp regs and return address are stored below the stack
+// because we don't want the GC to scan them.
+
+#ifdef __mips_hard_float
+#define BELOW (8 * 8 + 8)
+s.d  $f24, (0 * 8 - BELOW)($sp)
+s.d  $f25, (1 * 8 - BELOW)($sp)
+s.d  $f26, (2 * 8 - BELOW)($sp)
+s.d  $f27, (3 * 8 - BELOW)($sp)
+s.d  $f28, (4 * 8 - BELOW)($sp)
+s.d  $f29, (5 * 8 - BELOW)($sp)
+s.d  $f30, (6 * 8 - BELOW)($sp)
+s.d  $f31, (7 * 8 - BELOW)($sp)
+#endif
+sd $ra, -8($sp)
+
+sd  $s0, (0 * 8)($sp)
+sd  $s1, (1 * 8)($sp)
+sd  $s2, (2 * 8)($sp)
+sd  $s3, (3 * 8)($sp)
+sd  $s4, (4 * 8)($sp)
+sd  $s5, (5 * 8)($sp)
+sd  $s6, (6 * 8)($sp)
+sd  $s7, (7 * 8)($sp)
+sd  $gp, (8 * 8)($sp)
+sd  $fp, (9 * 8)($sp)
+
+// swap stack pointer
+sd   $sp, 0($a0)
+move $sp, $a1
+
+#ifdef __mips_hard_float
+l.d  $f24, (0 * 8 - BELOW)($sp)
+l.d  $f25, (1 * 8 - BELOW)($sp)
+l.d  $f26, (2 * 8 - BELOW)($sp)
+l.d  $f27, (3 * 8 - BELOW)($sp)
+l.d  $f28, (4 * 8 - BELOW)($sp)
+l.d  $f29, (5 * 8 - BELOW)($sp)
+l.d  $f30, (6 * 8 - BELOW)($sp)
+l.d  $f31, (7 * 8 - BELOW)($sp)
 #endif
+ld $ra, -8($sp)
+
+ld $s0, (0 * 8)($sp)
+ld $s1, (1 * 8)($sp)
+ld $s2, (2 * 8)($sp)
+ld $s3, (3 * 8)($sp)
+ld $s4, (4 * 8)($sp)
+ld $s5, (5 * 8)($sp)
+ld $s6, (6 * 8)($sp)
+ld $s7, (7 * 8)($sp)
+ld $gp, (8 * 8)($sp)
+ld $fp, (9 * 8)($sp)
+
+daddiu $sp, $sp, (10 * 8)
+
+jr $ra // return
+.cfi_endproc
+.end fiber_switchContext
+.size fiber_switchContext,.-fiber_switchContext
+
+#endif /* defined(__mips64) && _MIPS_SIM == _ABI64 */


[gcc r15-6876] libphobos: Bump soname to version 6 [PR117701]

2025-01-13 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:a52812a65cc10ef604100162c7c97ad7f4b37214

commit r15-6876-ga52812a65cc10ef604100162c7c97ad7f4b37214
Author: Iain Buclaw 
Date:   Mon Jan 13 20:52:49 2025 +0100

libphobos: Bump soname to version 6 [PR117701]

Each major release is not binary compatible with the previous.

PR d/117701

libphobos/ChangeLog:

* configure: Regenerate.
* configure.ac (libtool_VERSION): Update to 6:0:0.

Diff:
---
 libphobos/configure| 2 +-
 libphobos/configure.ac | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libphobos/configure b/libphobos/configure
index 9b6a41879d36..b9fecbc0175e 100755
--- a/libphobos/configure
+++ b/libphobos/configure
@@ -15741,7 +15741,7 @@ SPEC_PHOBOS_DEPS="$LIBS"
 
 
 # Libdruntime / phobos soname version
-libtool_VERSION=5:0:0
+libtool_VERSION=6:0:0
 
 
 # Set default flags (after DRUNTIME_WERROR!)
diff --git a/libphobos/configure.ac b/libphobos/configure.ac
index 9fcd34504827..92449feb7e95 100644
--- a/libphobos/configure.ac
+++ b/libphobos/configure.ac
@@ -258,7 +258,7 @@ SPEC_PHOBOS_DEPS="$LIBS"
 AC_SUBST(SPEC_PHOBOS_DEPS)
 
 # Libdruntime / phobos soname version
-libtool_VERSION=5:0:0
+libtool_VERSION=6:0:0
 AC_SUBST(libtool_VERSION)
 
 # Set default flags (after DRUNTIME_WERROR!)


[gcc r15-6557] testsuite, d: Fix failing pr110406.d test

2025-01-05 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:345ad67fc2ee321d5c2e5371711a2d249b92b956

commit r15-6557-g345ad67fc2ee321d5c2e5371711a2d249b92b956
Author: Iain Buclaw 
Date:   Sun Jan 5 11:19:31 2025 +0100

testsuite, d: Fix failing pr110406.d test

At some point during GCC 15 development, the compiler-generated code for
D ModuleInfo support now gets transformed into the following on x86:

_12 = (uint) &__stop_minfo;
_13 = (uint) &__start_minfo;
_14 = (uint) &gdc.dso_slot;
_15 = {1, _14, _13, _12};
gdc.dso_initialized = 0;
MEM  [(void *)&D.1974 + 16B] = {};
MEM  [(void *)&D.1974] = _15;
_d_dso_registry (&D.1974);

This causes the scan-tree-dump-not test to fail. As ModuleInfo is not
what's being checked for in PR110406, remove its generation altogether.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/pr110406.d: Add -fno-moduleinfo to dg-options.

Diff:
---
 gcc/testsuite/gdc.dg/torture/pr110406.d | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gdc.dg/torture/pr110406.d 
b/gcc/testsuite/gdc.dg/torture/pr110406.d
index c380e4bdec86..169aec7b6e50 100644
--- a/gcc/testsuite/gdc.dg/torture/pr110406.d
+++ b/gcc/testsuite/gdc.dg/torture/pr110406.d
@@ -1,6 +1,6 @@
 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110406
 // { dg-do compile { target i?86-*-* x86_64-*-* } }
-// { dg-options "-fdump-tree-optimized" }
+// { dg-options "-fno-moduleinfo -fdump-tree-optimized" }
 struct cpuid_abcd_t
 {
 uint eax;


[gcc r15-6965] d: Add testcase for fixed PR116373

2025-01-16 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:c7dab40d7569c51ac4e62ceea05c7c049da426bb

commit r15-6965-gc7dab40d7569c51ac4e62ceea05c7c049da426bb
Author: Iain Buclaw 
Date:   Thu Jan 16 17:20:06 2025 +0100

d: Add testcase for fixed PR116373

This was fixed in upstream, and merged in r15-6559-g332cf038fda109.

PR d/116373

gcc/testsuite/ChangeLog:

* gdc.dg/pr116373.d: New test.

Diff:
---
 gcc/testsuite/gdc.dg/pr116373.d | 8 
 1 file changed, 8 insertions(+)

diff --git a/gcc/testsuite/gdc.dg/pr116373.d b/gcc/testsuite/gdc.dg/pr116373.d
new file mode 100644
index ..b58863bacf29
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr116373.d
@@ -0,0 +1,8 @@
+// { dg-do compile }
+int[] x;
+
+void foo (int[] y = x[]) {}
+
+void main () {
+foo();
+}


[gcc r14-11216] d: Fix ICE in dmd.expressionsem.resolveLoc

2025-01-16 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:258d5c062719725310421d0b4f0d03110e3e88a2

commit r14-11216-g258d5c062719725310421d0b4f0d03110e3e88a2
Author: Iain Buclaw 
Date:   Thu Jan 16 17:20:06 2025 +0100

d: Fix ICE in dmd.expressionsem.resolveLoc

This was fixed in upstream, and merged in r15-6559-g332cf038fda109.
Backport the individual fix from the upstream merge for releases/gcc-14.

PR d/116373

gcc/d/ChangeLog:

* dmd/expressionsem.d (resolveLoc): Check for null pointer before
resolving bounds of slice.

gcc/testsuite/ChangeLog:

* gdc.dg/pr116373.d: New test.

(cherry picked from commit c7dab40d7569c51ac4e62ceea05c7c049da426bb)

Diff:
---
 gcc/d/dmd/expressionsem.d   | 6 --
 gcc/testsuite/gdc.dg/pr116373.d | 8 
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/gcc/d/dmd/expressionsem.d b/gcc/d/dmd/expressionsem.d
index 7ae7f400d166..a6425d311439 100644
--- a/gcc/d/dmd/expressionsem.d
+++ b/gcc/d/dmd/expressionsem.d
@@ -15331,8 +15331,10 @@ Expression resolveLoc(Expression exp, const ref Loc 
loc, Scope* sc)
 Expression visitSlice(SliceExp exp)
 {
 exp.e1 = exp.e1.resolveLoc(loc, sc);
-exp.lwr = exp.lwr.resolveLoc(loc, sc);
-exp.upr = exp.upr.resolveLoc(loc, sc);
+if (exp.lwr)
+exp.lwr = exp.lwr.resolveLoc(loc, sc);
+if (exp.upr)
+exp.upr = exp.upr.resolveLoc(loc, sc);
 
 return exp;
 }
diff --git a/gcc/testsuite/gdc.dg/pr116373.d b/gcc/testsuite/gdc.dg/pr116373.d
new file mode 100644
index ..b58863bacf29
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr116373.d
@@ -0,0 +1,8 @@
+// { dg-do compile }
+int[] x;
+
+void foo (int[] y = x[]) {}
+
+void main () {
+foo();
+}


[gcc r15-7006] d: Add testcase for fixed PR117115

2025-01-17 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:975c4f1a5de4ede89ee9499cd1a73d613a4aeae4

commit r15-7006-g975c4f1a5de4ede89ee9499cd1a73d613a4aeae4
Author: Iain Buclaw 
Date:   Fri Jan 17 20:10:39 2025 +0100

d: Add testcase for fixed PR117115

This was fixed in upstream dmd, and merged in r15-6824.

PR d/117115

gcc/testsuite/ChangeLog:

* gdc.dg/pr117115.d: New test.

Diff:
---
 gcc/testsuite/gdc.dg/pr117115.d | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/testsuite/gdc.dg/pr117115.d b/gcc/testsuite/gdc.dg/pr117115.d
new file mode 100644
index ..b012268b509e
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr117115.d
@@ -0,0 +1,3 @@
+// { dg-do compile }
+
+enum E117115 {} // { dg-error "must have at least one member" }


[gcc r15-6899] d: Merge upstream dmd, druntime d6f693b46a, phobos 336bed6d8.

2025-01-14 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:c8894b681143041205d41e02ede112cef082bf2f

commit r15-6899-gc8894b681143041205d41e02ede112cef082bf2f
Author: Iain Buclaw 
Date:   Tue Jan 14 20:51:45 2025 +0100

d: Merge upstream dmd, druntime d6f693b46a, phobos 336bed6d8.

D front-end changes:

- Import latest fixes from dmd v2.110.0-rc.1.

D runtime changes:

- Import latest fixes from druntime v2.110.0-rc.1.

Phobos changes:

- Import latest fixes from phobos v2.110.0-rc.1.

Included in the merge are fixes for the following PRs:

PR d/118438
PR d/118448
PR d/118449

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd d6f693b46a.
* d-incpath.cc (add_import_paths): Update for new front-end 
interface.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime d6f693b46a.
* src/MERGE: Merge upstream phobos 336bed6d8.
* testsuite/libphobos.init_fini/custom_gc.d: Adjust test.

Diff:
---
 gcc/d/d-incpath.cc |   4 +-
 gcc/d/dmd/MERGE|   2 +-
 gcc/d/dmd/clone.d  | 201 -
 gcc/d/dmd/ctfeexpr.d   |  48 +++--
 gcc/d/dmd/dcast.d  |  18 +-
 gcc/d/dmd/dimport.d|   9 +-
 gcc/d/dmd/dmodule.d|  29 ++-
 gcc/d/dmd/doc.d|   6 +-
 gcc/d/dmd/dstruct.d|   4 +-
 gcc/d/dmd/dsymbolsem.d |  34 +++-
 gcc/d/dmd/dtemplate.d  |  11 +-
 gcc/d/dmd/dtoh.d   |   2 +-
 gcc/d/dmd/errors.d |  20 +-
 gcc/d/dmd/expression.d |  13 +-
 gcc/d/dmd/expressionsem.d  |  16 +-
 gcc/d/dmd/file_manager.d   |  29 ++-
 gcc/d/dmd/func.d   |   4 +-
 gcc/d/dmd/funcsem.d|  13 +-
 gcc/d/dmd/globals.d|   9 +-
 gcc/d/dmd/globals.h|  15 +-
 gcc/d/dmd/hdrgen.d |   4 +-
 gcc/d/dmd/json.d   |   2 +-
 gcc/d/dmd/lexer.d  |   2 +-
 gcc/d/dmd/mtype.d  |   2 +-
 gcc/d/dmd/parse.d  |   6 +-
 gcc/d/dmd/pragmasem.d  |  13 +-
 gcc/d/dmd/semantic3.d  |   2 +-
 gcc/d/dmd/templateparamsem.d   |   9 +-
 gcc/d/dmd/traits.d |   3 +-
 gcc/d/dmd/typesem.d|   4 +-
 gcc/d/dmd/typinf.d |   1 -
 gcc/testsuite/gdc.test/compilable/copyCtor2.d  |  14 ++
 gcc/testsuite/gdc.test/compilable/cppmangle.d  |   6 +
 gcc/testsuite/gdc.test/compilable/testInference.d  |  20 +-
 .../gdc.test/fail_compilation/failCopyCtor2.d  |  19 --
 .../gdc.test/fail_compilation/retscope2.d  |   2 +-
 .../gdc.test/fail_compilation/retscope3.d  |   4 +-
 .../gdc.test/fail_compilation/retscope6.d  |   2 +-
 .../gdc.test/fail_compilation/test18282.d  |  16 +-
 gcc/testsuite/gdc.test/runnable/rvalue1.d  |  51 ++
 libphobos/libdruntime/MERGE|   2 +-
 libphobos/libdruntime/core/builtins.d  |  21 ++-
 libphobos/libdruntime/core/demangle.d  |  11 +-
 libphobos/libdruntime/core/internal/gc/os.d|   4 +-
 libphobos/libdruntime/core/sys/posix/sys/socket.d  |   9 +
 libphobos/src/MERGE|   2 +-
 libphobos/src/std/functional.d |   6 +-
 libphobos/src/std/socket.d |   2 +-
 libphobos/src/std/typecons.d   |   2 +-
 .../testsuite/libphobos.init_fini/custom_gc.d  |  10 +
 50 files changed, 471 insertions(+), 267 deletions(-)

diff --git a/gcc/d/d-incpath.cc b/gcc/d/d-incpath.cc
index 3f62f437cb98..155dc99c5550 100644
--- a/gcc/d/d-incpath.cc
+++ b/gcc/d/d-incpath.cc
@@ -133,7 +133,7 @@ add_import_paths (const char *iprefix, const char 
*imultilib, bool stdinc)
  bool found = false;
  for (size_t i = 0; i < global.params.imppath.length; i++)
{
- if (strcmp (path, global.params.imppath[i]) == 0)
+ if (strcmp (path, global.params.imppath[i].path) == 0)
{
  found = true;
  break;
@@ -160,7 +160,7 @@ add_import_paths (const char *iprefix, const char 
*imultilib, bool stdinc)
   /* Add import search paths.  */
   for (size_t i = 0; i < global.params.imppath.length; i++)
 {
-  const char *path 

[gcc r15-6983] d: Fix record layout of compiler-generated TypeInfo_Class [PR115249]

2025-01-16 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:d740694ff89ab5c78652a1f66b058ca16634ddbc

commit r15-6983-gd740694ff89ab5c78652a1f66b058ca16634ddbc
Author: Iain Buclaw 
Date:   Fri Jan 17 00:23:45 2025 +0100

d: Fix record layout of compiler-generated TypeInfo_Class [PR115249]

In r14-8766, the layout of TypeInfo_Class changed in the runtime
library, but didn't get reflected in the compiler-generated data,
causing a corruption of runtime type introspection on BigEndian targets.

This adjusts the size of the `ClassFlags' field from uint to ushort, and
adds a new ushort `depth' field in the space where ClassFlags used to
occupy.

PR d/115249

gcc/d/ChangeLog:

* typeinfo.cc (create_tinfo_types): Update internal Typenfo
representation.
(TypeInfoVisitor::visit (TypeInfoClassDeclaration *)): Likewise.

Diff:
---
 gcc/d/typeinfo.cc | 19 +--
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/gcc/d/typeinfo.cc b/gcc/d/typeinfo.cc
index 66cfa2c59296..f548451c8ba5 100644
--- a/gcc/d/typeinfo.cc
+++ b/gcc/d/typeinfo.cc
@@ -258,10 +258,10 @@ create_tinfo_types (Module *mod)
  Identifier::idPool ("TypeInfo_Class"),
  array_type_node, array_type_node, array_type_node,
  array_type_node, ptr_type_node, ptr_type_node,
- ptr_type_node, d_uint_type, ptr_type_node,
- array_type_node, ptr_type_node, ptr_type_node,
- d_uint_type, d_uint_type, d_uint_type, d_uint_type,
- NULL);
+ ptr_type_node, d_ushort_type, d_ushort_type,
+ ptr_type_node, array_type_node, ptr_type_node,
+ ptr_type_node, d_uint_type, d_uint_type, d_uint_type,
+ d_uint_type, NULL);
 
   object_module = mod;
 }
@@ -813,6 +813,7 @@ public:
void *destructor;
void function(Object) classInvariant;
ClassFlags m_flags;
+   ushort depth;
void *deallocator;
OffsetTypeInfo[] m_offTi;
void function(Object) defaultConstructor;
@@ -918,7 +919,10 @@ public:
flags |= ClassFlags::noPointers;
 
 Lhaspointers:
-   this->layout_field (build_integer_cst (flags, d_uint_type));
+   this->layout_field (build_integer_cst (flags, d_ushort_type));
+
+   /* ushort depth;  (not implemented)  */
+   this->layout_field (build_zero_cst (d_ushort_type));
 
/* void *deallocator;  */
this->layout_field (null_pointer_node);
@@ -979,7 +983,10 @@ public:
if (cd->isCOMinterface ())
  flags |= ClassFlags::isCOMclass;
 
-   this->layout_field (build_integer_cst (flags, d_uint_type));
+   this->layout_field (build_integer_cst (flags, d_ushort_type));
+
+   /* ushort depth;  (not implemented)  */
+   this->layout_field (build_zero_cst (d_ushort_type));
 
/* void *deallocator;
   OffsetTypeInfo[] m_offTi;  (not implemented)


[gcc r14-11217] d: Fix record layout of compiler-generated TypeInfo_Class [PR115249]

2025-01-16 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:1487310d2707203e0f9b5b1794daf1f381e3e622

commit r14-11217-g1487310d2707203e0f9b5b1794daf1f381e3e622
Author: Iain Buclaw 
Date:   Fri Jan 17 00:23:45 2025 +0100

d: Fix record layout of compiler-generated TypeInfo_Class [PR115249]

In r14-8766, the layout of TypeInfo_Class changed in the runtime
library, but didn't get reflected in the compiler-generated data,
causing a corruption of runtime type introspection on BigEndian targets.

This adjusts the size of the `ClassFlags' field from uint to ushort, and
adds a new ushort `depth' field in the space where ClassFlags used to
occupy.

PR d/115249

gcc/d/ChangeLog:

* typeinfo.cc (create_tinfo_types): Update internal Typenfo
representation.
(TypeInfoVisitor::visit (TypeInfoClassDeclaration *)): Likewise.

(cherry picked from commit d740694ff89ab5c78652a1f66b058ca16634ddbc)

Diff:
---
 gcc/d/typeinfo.cc | 19 +--
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/gcc/d/typeinfo.cc b/gcc/d/typeinfo.cc
index cadcbe8164e9..aa702892c4d7 100644
--- a/gcc/d/typeinfo.cc
+++ b/gcc/d/typeinfo.cc
@@ -258,10 +258,10 @@ create_tinfo_types (Module *mod)
  Identifier::idPool ("TypeInfo_Class"),
  array_type_node, array_type_node, array_type_node,
  array_type_node, ptr_type_node, ptr_type_node,
- ptr_type_node, d_uint_type, ptr_type_node,
- array_type_node, ptr_type_node, ptr_type_node,
- d_uint_type, d_uint_type, d_uint_type, d_uint_type,
- NULL);
+ ptr_type_node, d_ushort_type, d_ushort_type,
+ ptr_type_node, array_type_node, ptr_type_node,
+ ptr_type_node, d_uint_type, d_uint_type, d_uint_type,
+ d_uint_type, NULL);
 
   object_module = mod;
 }
@@ -813,6 +813,7 @@ public:
void *destructor;
void function(Object) classInvariant;
ClassFlags m_flags;
+   ushort depth;
void *deallocator;
OffsetTypeInfo[] m_offTi;
void function(Object) defaultConstructor;
@@ -918,7 +919,10 @@ public:
flags |= ClassFlags::noPointers;
 
 Lhaspointers:
-   this->layout_field (build_integer_cst (flags, d_uint_type));
+   this->layout_field (build_integer_cst (flags, d_ushort_type));
+
+   /* ushort depth;  (not implemented)  */
+   this->layout_field (build_zero_cst (d_ushort_type));
 
/* void *deallocator;  */
this->layout_field (null_pointer_node);
@@ -979,7 +983,10 @@ public:
if (cd->isCOMinterface ())
  flags |= ClassFlags::isCOMclass;
 
-   this->layout_field (build_integer_cst (flags, d_uint_type));
+   this->layout_field (build_integer_cst (flags, d_ushort_type));
+
+   /* ushort depth;  (not implemented)  */
+   this->layout_field (build_zero_cst (d_ushort_type));
 
/* void *deallocator;
   OffsetTypeInfo[] m_offTi;  (not implemented)


[gcc r15-8268] d: Update the copyright years of dmd sources to 2025

2025-03-18 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:f2af60465cd129b8deb3283baaf8fbac1a5941d4

commit r15-8268-gf2af60465cd129b8deb3283baaf8fbac1a5941d4
Author: Iain Buclaw 
Date:   Sat Mar 15 16:32:48 2025 +0100

d: Update the copyright years of dmd sources to 2025

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 51be8bb729.

Reviewed-on: https://github.com/dlang/dmd/pull/20958

Diff:
---
 gcc/d/dmd/MERGE  | 2 +-
 gcc/d/dmd/access.d   | 2 +-
 gcc/d/dmd/aggregate.d| 2 +-
 gcc/d/dmd/aggregate.h| 2 +-
 gcc/d/dmd/aliasthis.d| 2 +-
 gcc/d/dmd/aliasthis.h| 2 +-
 gcc/d/dmd/arrayop.d  | 2 +-
 gcc/d/dmd/arraytypes.d   | 2 +-
 gcc/d/dmd/arraytypes.h   | 2 +-
 gcc/d/dmd/ast_node.d | 2 +-
 gcc/d/dmd/ast_node.h | 2 +-
 gcc/d/dmd/astenums.d | 2 +-
 gcc/d/dmd/attrib.d   | 2 +-
 gcc/d/dmd/attrib.h   | 2 +-
 gcc/d/dmd/attribsem.d| 2 +-
 gcc/d/dmd/blockexit.d| 2 +-
 gcc/d/dmd/builtin.d  | 2 +-
 gcc/d/dmd/canthrow.d | 2 +-
 gcc/d/dmd/chkformat.d| 2 +-
 gcc/d/dmd/clone.d| 2 +-
 gcc/d/dmd/common/bitfields.d | 2 +-
 gcc/d/dmd/common/charactertables.d   | 2 +-
 gcc/d/dmd/common/charactertables.h   | 2 +-
 gcc/d/dmd/common/file.d  | 2 +-
 gcc/d/dmd/common/outbuffer.d | 2 +-
 gcc/d/dmd/common/outbuffer.h | 2 +-
 gcc/d/dmd/common/smallbuffer.d   | 2 +-
 gcc/d/dmd/compiler.d | 2 +-
 gcc/d/dmd/compiler.h | 2 +-
 gcc/d/dmd/cond.d | 2 +-
 gcc/d/dmd/cond.h | 2 +-
 gcc/d/dmd/constfold.d| 2 +-
 gcc/d/dmd/cparse.d   | 2 +-
 gcc/d/dmd/ctfe.h | 2 +-
 gcc/d/dmd/ctfeexpr.d | 2 +-
 gcc/d/dmd/ctorflow.d | 2 +-
 gcc/d/dmd/cxxfrontend.d  | 2 +-
 gcc/d/dmd/dcast.d| 2 +-
 gcc/d/dmd/dclass.d   | 2 +-
 gcc/d/dmd/declaration.d  | 2 +-
 gcc/d/dmd/declaration.h  | 2 +-
 gcc/d/dmd/delegatize.d   | 2 +-
 gcc/d/dmd/denum.d| 2 +-
 gcc/d/dmd/deps.d | 2 +-
 gcc/d/dmd/dimport.d  | 2 +-
 gcc/d/dmd/dinterpret.d   | 2 +-
 gcc/d/dmd/dmacro.d   | 2 +-
 gcc/d/dmd/dmodule.d  | 2 +-
 gcc/d/dmd/doc.d  | 2 +-
 gcc/d/dmd/doc.h  | 2 +-
 gcc/d/dmd/dscope.d   | 2 +-
 gcc/d/dmd/dstruct.d  | 2 +-
 gcc/d/dmd/dsymbol.d  | 2 +-
 gcc/d/dmd/dsymbol.h  | 2 +-
 gcc/d/dmd/dsymbolsem.d   | 2 +-
 gcc/d/dmd/dtemplate.d| 2 +-
 gcc/d/dmd/dtoh.d | 2 +-
 gcc/d/dmd/dversion.d | 2 +-
 gcc/d/dmd/entity.d   | 2 +-
 gcc/d/dmd/enum.h | 2 +-
 gcc/d/dmd/enumsem.d  | 2 +-
 gcc/d/dmd/errors.d   | 2 +-
 gcc/d/dmd/errors.h   | 2 +-
 gcc/d/dmd/errorsink.d| 2 +-
 gcc/d/dmd/escape.d   | 2 +-
 gcc/d/dmd/expression.d   | 2 +-
 gcc/d/dmd/expression.h   | 2 +-
 gcc/d/dmd/expressionsem.d| 2 +-
 gcc/d/dmd/file_manager.d | 2 +-
 gcc/d/dmd/func.d | 2 +-
 gcc/d/dmd/funcsem.d  | 2 +-
 gcc/d/dmd/globals.d  | 4 ++--
 gcc/d/dmd/globals.h  | 2 +-
 gcc/d/dmd/gluelayer.d| 2 +-
 gcc/d/dmd/hdrgen.d   | 2 +-
 gcc/d/dmd/hdrgen.h   | 2 +-
 gcc/d/dmd/iasm.d | 2 +-
 gcc/d/dmd/iasmgcc.d  | 2 +-
 gcc/d/dmd/id.d   | 2 +-
 gcc/d/dmd/id.h   | 2 +-
 gcc/d/dmd/identifier.d   | 2 +-
 gcc/d/dmd/identifier.h   | 2 +-
 gcc/d/dmd/impcnvtab.d| 2 +-
 gcc/d/dmd/imphint.d  | 2 +-
 gcc/d/dmd/import.h   | 2 +-
 gcc/d/dmd/importc.d  | 2 +-
 gcc/d/dmd/init.d  

[gcc r15-8270] d: Add missing Declaration bitfield setters/getters

2025-03-18 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:a03e9d4932713c1696bb2bc134da8e8eac3edb94

commit r15-8270-ga03e9d4932713c1696bb2bc134da8e8eac3edb94
Author: Iain Buclaw 
Date:   Tue Mar 18 18:47:45 2025 +0100

d: Add missing Declaration bitfield setters/getters

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd fde0f8c40a.

Reviewed-on: https://github.com/dlang/dmd/pull/21014

Diff:
---
 gcc/d/dmd/MERGE | 2 +-
 gcc/d/dmd/declaration.h | 4 
 gcc/d/dmd/func.d| 4 ++--
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index 57973b181157..1be4da416f45 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-51be8bb729cfa41ff5af4f5b2a9b7b9902bfdaa1
+fde0f8c40a1b8eb78c3485cb0e940035bfe6fb00
 
 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/declaration.h b/gcc/d/dmd/declaration.h
index c535e4cbb14a..c7e45526084d 100644
--- a/gcc/d/dmd/declaration.h
+++ b/gcc/d/dmd/declaration.h
@@ -128,6 +128,10 @@ public:
 short inuse;// used to detect cycles
 uint8_t bitFields;
 
+LINK _linkage() const;
+LINK _linkage(LINK v);
+bool noUnderscore() const;
+
 const char *kind() const override;
 uinteger_t size(Loc loc) override final;
 
diff --git a/gcc/d/dmd/func.d b/gcc/d/dmd/func.d
index cc17be741c30..e96c3326b758 100644
--- a/gcc/d/dmd/func.d
+++ b/gcc/d/dmd/func.d
@@ -1006,12 +1006,12 @@ extern (C++) class FuncDeclaration : Declaration
 /**
  * Generate a FuncDeclaration for a runtime library function.
  */
-extern (D) static FuncDeclaration genCfunc(Parameters* fparams, Type 
treturn, const(char)* name, STC stc = STC.none)
+extern(D) static FuncDeclaration genCfunc(Parameters* fparams, Type 
treturn, const(char)* name, STC stc = STC.none)
 {
 return genCfunc(fparams, treturn, Identifier.idPool(name[0 .. 
strlen(name)]), stc);
 }
 
-extern (D) static FuncDeclaration genCfunc(Parameters* fparams, Type 
treturn, Identifier id, STC stc = STC.none)
+extern(D) static FuncDeclaration genCfunc(Parameters* fparams, Type 
treturn, Identifier id, STC stc = STC.none)
 {
 FuncDeclaration fd;
 TypeFunction tf;


[gcc r14-11425] d: Merge upstream dmd, druntime af92b68a81, phobos c970ca67f

2025-03-19 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:c6b1b62f11ed65b68bc1cebefe686a2fa75eb724

commit r14-11425-gc6b1b62f11ed65b68bc1cebefe686a2fa75eb724
Author: Iain Buclaw 
Date:   Thu Mar 20 01:09:13 2025 +0100

d: Merge upstream dmd, druntime af92b68a81, phobos c970ca67f

D front-end changes:

- Import dmd v2.108.1.

D runtime changes:

- Import druntime v2.108.1.

Phobos changes:

- Import phobos v2.108.1.

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd af92b68a81.
* dmd/VERSION: Bump version to v2.108.1.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime af92b68a81.
* src/MERGE: Merge upstream phobos c970ca67f.

Diff:
---
 gcc/d/dmd/MERGE|   2 +-
 gcc/d/dmd/VERSION  |   2 +-
 gcc/d/dmd/cparse.d |  70 --
 gcc/d/dmd/escape.d |  16 +-
 gcc/d/dmd/expressionsem.d  |   3 +-
 gcc/d/dmd/initsem.d|  17 +-
 gcc/d/dmd/traits.d |   2 +-
 .../gdc.test/compilable/returnscope_without_safe.d |  16 ++
 gcc/testsuite/gdc.test/compilable/test24479.d  |  35 +++
 .../gdc.test/runnable/imports/issue18919b.d|   6 +
 gcc/testsuite/gdc.test/runnable/issue18919.d   |   4 +
 gcc/testsuite/gdc.test/runnable/test24498.d|  21 ++
 libphobos/libdruntime/MERGE|   2 +-
 .../libdruntime/core/internal/array/construction.d |  17 +-
 libphobos/src/MERGE|   2 +-
 libphobos/src/std/internal/test/range.d|  91 +++
 libphobos/src/std/logger/core.d|   6 +-
 libphobos/src/std/range/package.d  | 262 ++---
 18 files changed, 508 insertions(+), 66 deletions(-)

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index dc47db87a80c..4041ed9ea765 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-b65767825f365dbc153457fc86e1054b03196c6d
+af92b68a81888702896620db1d10ee477b6b31e8
 
 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/VERSION b/gcc/d/dmd/VERSION
index 5868b8749552..99582f5e05fa 100644
--- a/gcc/d/dmd/VERSION
+++ b/gcc/d/dmd/VERSION
@@ -1 +1 @@
-v2.108.0
+v2.108.1
diff --git a/gcc/d/dmd/cparse.d b/gcc/d/dmd/cparse.d
index aeedb493efc3..bfd28c475202 100644
--- a/gcc/d/dmd/cparse.d
+++ b/gcc/d/dmd/cparse.d
@@ -1919,6 +1919,14 @@ final class CParser(AST) : Parser!AST
 auto s = cparseFunctionDefinition(id, dt.isTypeFunction(), 
specifier);
 typedefTab.setDim(typedefTabLengthSave);
 symbols = symbolsSave;
+if (specifier.mod & MOD.x__stdcall)
+{
+// If this function is __stdcall, wrap it in a 
LinkDeclaration so that
+// it's extern(Windows) when imported in D.
+auto decls = new AST.Dsymbols(1);
+(*decls)[0] = s;
+s = new AST.LinkDeclaration(s.loc, LINK.windows, decls);
+}
 symbols.push(s);
 return;
 }
@@ -2071,13 +2079,14 @@ final class CParser(AST) : Parser!AST
 }
 }
 s = applySpecifier(s, specifier);
-if (level == LVL.local)
+if (level == LVL.local || (specifier.mod & MOD.x__stdcall))
 {
-// Wrap the declaration in `extern (C) { declaration }`
+// Wrap the declaration in `extern (C/Windows) { 
declaration }`
 // Necessary for function pointers, but harmless to apply 
to all.
 auto decls = new AST.Dsymbols(1);
 (*decls)[0] = s;
-s = new AST.LinkDeclaration(s.loc, linkage, decls);
+const lkg = specifier.mod & MOD.x__stdcall ? LINK.windows 
: linkage;
+s = new AST.LinkDeclaration(s.loc, lkg, decls);
 }
 symbols.push(s);
 }
@@ -5860,13 +5869,15 @@ final class CParser(AST) : Parser!AST
 
 const(char)* endp = &slice[length - 7];
 
+AST.Dsymbols newSymbols;
+
 size_t[void*] defineTab;// hash table of #define's turned into 
Symbol's
-// indexed by Identifier, returns index 
into symbols[]
+// indexed by Identifier, returns index 
into newSymbols[]
 // The memory for this is leaked
 
-void addVar(AST.Dsymbol s)
+void addSym(AST.Dsymbol s)
 {
-//printf("addVar() %s\n", s.toChars());
+//printf("addSym() %s\n", s.toChars());
 if (au

[gcc r15-8682] d: Fix ICE type variant differs by TYPE_PACKED [PR117621]

2025-03-23 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:597168191e2909aec745f4dc084e1f8d44fdb3e4

commit r15-8682-g597168191e2909aec745f4dc084e1f8d44fdb3e4
Author: Iain Buclaw 
Date:   Sun Mar 23 12:57:27 2025 +0100

d: Fix ICE type variant differs by TYPE_PACKED [PR117621]

Introduced by r13-1104-gf4c3ce32fa54c1, which had an accidental self
assignment of TYPE_PACKED when it should have been assigned to the
type's variants.

PR d/117621

gcc/d/ChangeLog:

* types.cc (finish_aggregate_type): Propagate TYPE_PACKED to 
variants.

gcc/testsuite/ChangeLog:

* gdc.dg/pr117621.d: New test.

Diff:
---
 gcc/d/types.cc  |  2 +-
 gcc/testsuite/gdc.dg/pr117621.d | 11 +++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index 47ef66c25807..98074f1fb687 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -704,7 +704,7 @@ finish_aggregate_type (unsigned structsize, unsigned 
alignsize, tree type)
   TYPE_LANG_SPECIFIC (t) = TYPE_LANG_SPECIFIC (type);
   TYPE_SIZE (t) = TYPE_SIZE (type);
   TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (type);
-  TYPE_PACKED (type) = TYPE_PACKED (type);
+  TYPE_PACKED (t) = TYPE_PACKED (type);
   SET_TYPE_ALIGN (t, TYPE_ALIGN (type));
   TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (type);
 }
diff --git a/gcc/testsuite/gdc.dg/pr117621.d b/gcc/testsuite/gdc.dg/pr117621.d
new file mode 100644
index ..f0b96cbff2cd
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr117621.d
@@ -0,0 +1,11 @@
+// { dg-do "compile" }
+// { dg-options "-g" }
+void pr117621()
+{
+auto fun()(inout int)
+{
+struct S {}
+return inout(S)();
+}
+auto s = fun(0);
+}


[gcc r14-11439] d: Fix ICE type variant differs by TYPE_PACKED [PR117621]

2025-03-23 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:e4e7d446ec3efba0c70bebfa9ba6385c233ef083

commit r14-11439-ge4e7d446ec3efba0c70bebfa9ba6385c233ef083
Author: Iain Buclaw 
Date:   Sun Mar 23 12:57:27 2025 +0100

d: Fix ICE type variant differs by TYPE_PACKED [PR117621]

Introduced by r13-1104-gf4c3ce32fa54c1, which had an accidental self
assignment of TYPE_PACKED when it should have been assigned to the
type's variants.

PR d/117621

gcc/d/ChangeLog:

* types.cc (finish_aggregate_type): Propagate TYPE_PACKED to 
variants.

gcc/testsuite/ChangeLog:

* gdc.dg/pr117621.d: New test.

(cherry picked from commit a12dd79ff4e469652be6d8ef501e1d70178b44cd)

Diff:
---
 gcc/d/types.cc  |  2 +-
 gcc/testsuite/gdc.dg/pr117621.d | 11 +++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index 9fa2f888cb22..02f69af166d6 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -704,7 +704,7 @@ finish_aggregate_type (unsigned structsize, unsigned 
alignsize, tree type)
   TYPE_LANG_SPECIFIC (t) = TYPE_LANG_SPECIFIC (type);
   TYPE_SIZE (t) = TYPE_SIZE (type);
   TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (type);
-  TYPE_PACKED (type) = TYPE_PACKED (type);
+  TYPE_PACKED (t) = TYPE_PACKED (type);
   SET_TYPE_ALIGN (t, TYPE_ALIGN (type));
   TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (type);
 }
diff --git a/gcc/testsuite/gdc.dg/pr117621.d b/gcc/testsuite/gdc.dg/pr117621.d
new file mode 100644
index ..f0b96cbff2cd
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr117621.d
@@ -0,0 +1,11 @@
+// { dg-do "compile" }
+// { dg-options "-g" }
+void pr117621()
+{
+auto fun()(inout int)
+{
+struct S {}
+return inout(S)();
+}
+auto s = fun(0);
+}


[gcc r13-9445] d: Fix ICE type variant differs by TYPE_PACKED [PR117621]

2025-03-23 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:72d85f2163306c8ba234d228d8071ed368cbd2f2

commit r13-9445-g72d85f2163306c8ba234d228d8071ed368cbd2f2
Author: Iain Buclaw 
Date:   Sun Mar 23 12:57:27 2025 +0100

d: Fix ICE type variant differs by TYPE_PACKED [PR117621]

Introduced by r13-1104-gf4c3ce32fa54c1, which had an accidental self
assignment of TYPE_PACKED when it should have been assigned to the
type's variants.

PR d/117621

gcc/d/ChangeLog:

* types.cc (finish_aggregate_type): Propagate TYPE_PACKED to 
variants.

gcc/testsuite/ChangeLog:

* gdc.dg/pr117621.d: New test.

(cherry picked from commit a12dd79ff4e469652be6d8ef501e1d70178b44cd)

Diff:
---
 gcc/d/types.cc  |  2 +-
 gcc/testsuite/gdc.dg/pr117621.d | 11 +++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index 05050f9edd02..32b322c87190 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -704,7 +704,7 @@ finish_aggregate_type (unsigned structsize, unsigned 
alignsize, tree type)
   TYPE_LANG_SPECIFIC (t) = TYPE_LANG_SPECIFIC (type);
   TYPE_SIZE (t) = TYPE_SIZE (type);
   TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (type);
-  TYPE_PACKED (type) = TYPE_PACKED (type);
+  TYPE_PACKED (t) = TYPE_PACKED (type);
   SET_TYPE_ALIGN (t, TYPE_ALIGN (type));
   TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (type);
 }
diff --git a/gcc/testsuite/gdc.dg/pr117621.d b/gcc/testsuite/gdc.dg/pr117621.d
new file mode 100644
index ..f0b96cbff2cd
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr117621.d
@@ -0,0 +1,11 @@
+// { dg-do "compile" }
+// { dg-options "-g" }
+void pr117621()
+{
+auto fun()(inout int)
+{
+struct S {}
+return inout(S)();
+}
+auto s = fun(0);
+}


[gcc r15-8665] libphobos: Add module declaration to rt.invariant

2025-03-22 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:499c58f443e97198c30776f54bc57ea2af48245d

commit r15-8665-g499c58f443e97198c30776f54bc57ea2af48245d
Author: Iain Buclaw 
Date:   Sat Mar 22 10:26:47 2025 +0100

libphobos: Add module declaration to rt.invariant

This prevents conflicts with a user-provided `invariant.d' module.

gcc/d/ChangeLog:

* runtime.def (INVARIANT): Update signature of run-time function.

libphobos/ChangeLog:

* libdruntime/Makefile.am (DRUNTIME_DSOURCES): Rename rt/invariant.d
to rt/invariant_.d.
* libdruntime/Makefile.in: Regenerate.
* libdruntime/rt/invariant.d: Move to...
* libdruntime/rt/invariant_.d: ...here.

Diff:
---
 gcc/d/runtime.def  | 4 ++--
 libphobos/libdruntime/Makefile.am  | 2 +-
 libphobos/libdruntime/Makefile.in  | 6 +++---
 libphobos/libdruntime/rt/{invariant.d => invariant_.d} | 9 ++---
 4 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/gcc/d/runtime.def b/gcc/d/runtime.def
index e4261946e00b..4aff0a6e16a5 100644
--- a/gcc/d/runtime.def
+++ b/gcc/d/runtime.def
@@ -142,8 +142,8 @@ DEF_D_RUNTIME (CXA_END_CATCH, "__cxa_end_catch", RT(VOID), 
P0(), 0)
 
 /* When invariant() contracts are turned on, used after testing whether a
class != null for validating the state of a class.  */
-DEF_D_RUNTIME (INVARIANT, "_D9invariant12_d_invariantFC6ObjectZv", RT(VOID),
-  P1(OBJECT), 0)
+DEF_D_RUNTIME (INVARIANT, "_D2rt10invariant_12_d_invariantFC6ObjectZv",
+  RT(VOID), P1(OBJECT), 0)
 
 #undef P0
 #undef P1
diff --git a/libphobos/libdruntime/Makefile.am 
b/libphobos/libdruntime/Makefile.am
index 595e3f974c0c..252c6a3eebbc 100644
--- a/libphobos/libdruntime/Makefile.am
+++ b/libphobos/libdruntime/Makefile.am
@@ -222,7 +222,7 @@ DRUNTIME_DSOURCES = core/atomic.d core/attribute.d 
core/bitop.d \
gcc/unwind/generic.d gcc/unwind/package.d gcc/unwind/pe.d object.d \
rt/aApply.d rt/aApplyR.d rt/aaA.d rt/adi.d rt/arraycat.d rt/cast_.d \
rt/config.d rt/critical_.d rt/deh.d rt/dmain2.d rt/ehalloc.d \
-   rt/invariant.d rt/lifetime.d rt/memory.d rt/minfo.d rt/monitor_.d \
+   rt/invariant_.d rt/lifetime.d rt/memory.d rt/minfo.d rt/monitor_.d \
rt/profilegc.d rt/sections.d rt/tlsgc.d rt/util/typeinfo.d \
rt/util/utility.d
 
diff --git a/libphobos/libdruntime/Makefile.in 
b/libphobos/libdruntime/Makefile.in
index 4832fd15c408..52b0c377241e 100644
--- a/libphobos/libdruntime/Makefile.in
+++ b/libphobos/libdruntime/Makefile.in
@@ -248,7 +248,7 @@ am__objects_1 = core/atomic.lo core/attribute.lo 
core/bitop.lo \
gcc/unwind/generic.lo gcc/unwind/package.lo gcc/unwind/pe.lo \
object.lo rt/aApply.lo rt/aApplyR.lo rt/aaA.lo rt/adi.lo \
rt/arraycat.lo rt/cast_.lo rt/config.lo rt/critical_.lo \
-   rt/deh.lo rt/dmain2.lo rt/ehalloc.lo rt/invariant.lo \
+   rt/deh.lo rt/dmain2.lo rt/ehalloc.lo rt/invariant_.lo \
rt/lifetime.lo rt/memory.lo rt/minfo.lo rt/monitor_.lo \
rt/profilegc.lo rt/sections.lo rt/tlsgc.lo rt/util/typeinfo.lo \
rt/util/utility.lo
@@ -903,7 +903,7 @@ DRUNTIME_DSOURCES = core/atomic.d core/attribute.d 
core/bitop.d \
gcc/unwind/generic.d gcc/unwind/package.d gcc/unwind/pe.d object.d \
rt/aApply.d rt/aApplyR.d rt/aaA.d rt/adi.d rt/arraycat.d rt/cast_.d \
rt/config.d rt/critical_.d rt/deh.d rt/dmain2.d rt/ehalloc.d \
-   rt/invariant.d rt/lifetime.d rt/memory.d rt/minfo.d rt/monitor_.d \
+   rt/invariant_.d rt/lifetime.d rt/memory.d rt/minfo.d rt/monitor_.d \
rt/profilegc.d rt/sections.d rt/tlsgc.d rt/util/typeinfo.d \
rt/util/utility.d
 
@@ -1413,7 +1413,7 @@ rt/critical_.lo: rt/$(am__dirstamp)
 rt/deh.lo: rt/$(am__dirstamp)
 rt/dmain2.lo: rt/$(am__dirstamp)
 rt/ehalloc.lo: rt/$(am__dirstamp)
-rt/invariant.lo: rt/$(am__dirstamp)
+rt/invariant_.lo: rt/$(am__dirstamp)
 rt/lifetime.lo: rt/$(am__dirstamp)
 rt/memory.lo: rt/$(am__dirstamp)
 rt/minfo.lo: rt/$(am__dirstamp)
diff --git a/libphobos/libdruntime/rt/invariant.d 
b/libphobos/libdruntime/rt/invariant_.d
similarity index 70%
rename from libphobos/libdruntime/rt/invariant.d
rename to libphobos/libdruntime/rt/invariant_.d
index e536196e8c8f..2a64dc89da6c 100644
--- a/libphobos/libdruntime/rt/invariant.d
+++ b/libphobos/libdruntime/rt/invariant_.d
@@ -4,15 +4,10 @@
  * Copyright: Copyright Digital Mars 2007 - 2010.
  * License:   $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
  * Authors:   Walter Bright
- * Source: $(DRUNTIMESRC rt/_invariant.d)
- */
-
-/*  Copyright Digital Mars 2007 - 2010.
- * Distributed under the Boost Software License, Version 1.0.
- *(See accompanying file LICENSE or copy at
- *  http://www.boost.org/LICENSE_1_0.txt)
+ * Source: $(DRUNTIMESRC rt/_invariant_.d)
  */
 
+module rt.invariant_;
 
 /**
  *


[gcc r15-8668] d: Improve UFCS/property error message

2025-03-22 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:33a428f966d6583d47524a5274f519d4490d0e01

commit r15-8668-g33a428f966d6583d47524a5274f519d4490d0e01
Author: Iain Buclaw 
Date:   Sat Mar 22 10:49:06 2025 +0100

d: Improve UFCS/property error message

Improves on the speller suggestions for UFCS by using the location of
the suggested symbol, and considering that local functions aren't
eligible for UFCS instead of making a nonsensical suggestion, such as
"no property foo, did you mean foo?".

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 9d2f034398.

Reviewed-on: https://github.com/dlang/dmd/pull/21046

Diff:
---
 gcc/d/dmd/MERGE   |  2 +-
 gcc/d/dmd/typesem.d   | 14 +++--
 gcc/testsuite/gdc.test/fail_compilation/fail347.d |  4 +--
 gcc/testsuite/gdc.test/fail_compilation/ufcs.d| 36 ++-
 4 files changed, 36 insertions(+), 20 deletions(-)

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index 9982d0dd83ef..0b554f126a6d 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-94950cae582d89f5ba2720786522f669f620f9d1
+9d2f034398c33be1a28d8c60721014a6ab34d652
 
 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/typesem.d b/gcc/d/dmd/typesem.d
index 65bad387ef80..c5a3b83379a9 100644
--- a/gcc/d/dmd/typesem.d
+++ b/gcc/d/dmd/typesem.d
@@ -3444,8 +3444,16 @@ Expression getProperty(Type t, Scope* scope_, Loc loc, 
Identifier ident, int fla
 auto s2 = scope_.search_correct(ident);
 // UFCS
 if (s2 && s2.isFuncDeclaration)
-errorSupplemental(loc, "did you mean %s `%s`?",
-s2.kind(), s2.toChars());
+{
+if (s2.ident == ident)
+{
+errorSupplemental(s2.loc, "cannot call %s `%s` with 
UFCS because it is not declared at module scope",
+s2.kind(), s2.toChars());
+}
+else
+errorSupplemental(s2.loc, "did you mean %s `%s`?",
+s2.kind(), s2.toChars());
+}
 else if (src.type.ty == Tpointer)
 {
 // structPtr.field
@@ -3454,7 +3462,7 @@ Expression getProperty(Type t, Scope* scope_, Loc loc, 
Identifier ident, int fla
 {
 if (auto s3 = as.search_correct(ident))
 {
-errorSupplemental(loc, "did you mean %s `%s`?",
+errorSupplemental(s3.loc, "did you mean %s `%s`?",
 s3.kind(), s3.toChars());
 }
 }
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail347.d 
b/gcc/testsuite/gdc.test/fail_compilation/fail347.d
index e495ba257e35..c56acf5642cd 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/fail347.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail347.d
@@ -5,10 +5,10 @@ TEST_OUTPUT:
 fail_compilation/fail347.d(26): Error: undefined identifier `bbr`, did you 
mean variable `bar`?
 fail_compilation/fail347.d(27): Error: no property `ofo` for type `S`, did you 
mean `fail347.S.foo`?
 fail_compilation/fail347.d(29): Error: no property `fool` for `sp` of type 
`fail347.S*`
-fail_compilation/fail347.d(29):did you mean variable `foo`?
+fail_compilation/fail347.d(20):did you mean variable `foo`?
 fail_compilation/fail347.d(30): Error: undefined identifier `strlenx`, did you 
mean function `strlen`?
 fail_compilation/fail347.d(31): Error: no property `strlenx` for `"hello"` of 
type `string`
-fail_compilation/fail347.d(31):did you mean function `strlen`?
+fail_compilation/imports/fail347a.d(3):did you mean function `strlen`?
 ---
 */
 
diff --git a/gcc/testsuite/gdc.test/fail_compilation/ufcs.d 
b/gcc/testsuite/gdc.test/fail_compilation/ufcs.d
index 3a92a691e2f4..87efbcf65c9e 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/ufcs.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/ufcs.d
@@ -1,23 +1,28 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/ufcs.d(26): Error: no property `regularF` for `s` of type `S`
-fail_compilation/ufcs.d(26):the following error occured while looking 
for a UFCS match
-fail_compilation/ufcs.d(26): Error: function `regularF` is not callable using 
argument types `(S)`
-fail_compilation/ufcs.d(26):expected 0 argument(s), not 1
-fail_compilation/ufcs.d(31):`ufcs.regularF()` declared here
-fail_compilation/ufcs.d(27): Error: no property `templateF` for `s` of type `S`
-fail_compilation/ufcs.d(27):the following error occured while looking 
for a UFCS match
-fail_compilation/ufcs.d(27): Error: template `templateF` is not callable using 
argument types `!()(S)`
-fail_compilation/ufcs.d(32):

[gcc r15-8664] libphobos: Fix IEEE typo in std.numeric link

2025-03-22 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:e6ff1dc191f2dc6fd96d755fdc18fcbaade56e12

commit r15-8664-ge6ff1dc191f2dc6fd96d755fdc18fcbaade56e12
Author: Iain Buclaw 
Date:   Sat Mar 22 10:15:09 2025 +0100

libphobos: Fix IEEE typo in std.numeric link

libphobos/ChangeLog:

* src/MERGE: Merge upstream phobos d4c9efef1.

Reviewed-on: https://github.com/dlang/phobos/pull/10700

Diff:
---
 libphobos/src/MERGE | 2 +-
 libphobos/src/std/numeric.d | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libphobos/src/MERGE b/libphobos/src/MERGE
index a4888fc96180..7eb4c35ff842 100644
--- a/libphobos/src/MERGE
+++ b/libphobos/src/MERGE
@@ -1,4 +1,4 @@
-79cbde1ab69bae9372f310d663edfc43166095e3
+d4c9efef156385204d382cd941dc58bb750d7141
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/phobos repository.
diff --git a/libphobos/src/std/numeric.d b/libphobos/src/std/numeric.d
index 9966b1ce77fc..918984fd52ee 100644
--- a/libphobos/src/std/numeric.d
+++ b/libphobos/src/std/numeric.d
@@ -37,7 +37,7 @@ public enum CustomFloatFlags
  * Store values in normalized form by default. The actual precision of the
  * significand is extended by 1 bit by assuming an implicit leading bit of 
1
  * instead of 0. i.e. `1.` instead of `0.`.
- * True for all $(LINK2 https://en.wikipedia.org/wiki/IEEE_floating_point, 
IEE754) types
+ * True for all $(LINK2 https://en.wikipedia.org/wiki/IEEE_floating_point, 
IEEE754) types
  */
 storeNormalized = 2,


[gcc r15-8669] d: Bump front-end language version to v2.111.0-rc.1.

2025-03-22 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:a6cb7e917b1f7aa1c3ab44a62bcb7f5d81fc79e4

commit r15-8669-ga6cb7e917b1f7aa1c3ab44a62bcb7f5d81fc79e4
Author: Iain Buclaw 
Date:   Sat Mar 22 10:54:10 2025 +0100

d: Bump front-end language version to v2.111.0-rc.1.

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 032e24446b.
* dmd/VERSION: Bump version to v2.111.0-rc.1.

Diff:
---
 gcc/d/dmd/MERGE   | 2 +-
 gcc/d/dmd/VERSION | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index 0b554f126a6d..116074932aed 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-9d2f034398c33be1a28d8c60721014a6ab34d652
+032e24446b3d8c6cfe3043d62534d5ce6d004c34
 
 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/VERSION b/gcc/d/dmd/VERSION
index 2f668e5056b6..0172d7d7add4 100644
--- a/gcc/d/dmd/VERSION
+++ b/gcc/d/dmd/VERSION
@@ -1 +1 @@
-v2.111.0-beta.1
+v2.111.0-rc.1


[gcc r15-8666] d: Indexing a cast(AA) yields no lvalue anymore

2025-03-22 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:76df0e069f6c8ba5aa93ae10606ba61fa990883c

commit r15-8666-g76df0e069f6c8ba5aa93ae10606ba61fa990883c
Author: Iain Buclaw 
Date:   Sat Mar 22 10:33:24 2025 +0100

d: Indexing a cast(AA) yields no lvalue anymore

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 8db14cf846.

Reviewed-on: https://github.com/dlang/dmd/pull/21029

Diff:
---
 gcc/d/dmd/MERGE |  2 +-
 gcc/d/dmd/expression.d  |  1 +
 gcc/testsuite/gdc.test/runnable/test21020.d | 11 +++
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index 1be4da416f45..f274580f2d60 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-fde0f8c40a1b8eb78c3485cb0e940035bfe6fb00
+8db14cf8467ca25256904d51169b176c9c89afb1
 
 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/expression.d b/gcc/d/dmd/expression.d
index ef5c0b09eb45..4bf1f9f25f86 100644
--- a/gcc/d/dmd/expression.d
+++ b/gcc/d/dmd/expression.d
@@ -3632,6 +3632,7 @@ extern (C++) final class CastExp : UnaExp
 if (rvalue || !e1.isLvalue())
 return false;
 return (to.ty == Tsarray && (e1.type.ty == Tvector || e1.type.ty == 
Tsarray)) ||
+(to.ty == Taarray && e1.type.ty == Taarray) ||
 e1.type.mutableOf.unSharedOf().equals(to.mutableOf().unSharedOf());
 }
 
diff --git a/gcc/testsuite/gdc.test/runnable/test21020.d 
b/gcc/testsuite/gdc.test/runnable/test21020.d
new file mode 100644
index ..484db30a56cd
--- /dev/null
+++ b/gcc/testsuite/gdc.test/runnable/test21020.d
@@ -0,0 +1,11 @@
+// https://github.com/dlang/dmd/issues/21020
+
+shared struct Queue {
+int[int] map;
+}
+
+void main() {
+auto queue = Queue();
+(cast(int[int]) queue.map)[1] = 2;
+assert(queue.map[1] == 2);
+}


[gcc r15-8667] d: Add C++23 to CppStdRevision enum

2025-03-22 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:1f42269ee49240ac68a877c29a26306fcc246c2d

commit r15-8667-g1f42269ee49240ac68a877c29a26306fcc246c2d
Author: Iain Buclaw 
Date:   Sat Mar 22 10:42:21 2025 +0100

d: Add C++23 to CppStdRevision enum

D front-end changes:

- The compiler now accepts `-fextern-std=c++23'

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 94950cae58.
* d-lang.cc (d_handle_option): Add case for CppStdRevisionCpp23.
* gdc.texi: Document -fextern-std=c++23.
* lang.opt (fextern-std=): Add c++23.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 94950cae58.

Reviewed-on: https://github.com/dlang/dmd/pull/21043

Diff:
---
 gcc/d/d-lang.cc  | 1 +
 gcc/d/dmd/MERGE  | 2 +-
 gcc/d/dmd/globals.d  | 1 +
 gcc/d/dmd/globals.h  | 3 ++-
 gcc/d/gdc.texi   | 2 ++
 gcc/d/lang.opt   | 3 +++
 libphobos/libdruntime/MERGE  | 2 +-
 libphobos/libdruntime/core/stdcpp/xutility.d | 1 +
 8 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index 21f46ffb6aa8..b3786be3c905 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -510,6 +510,7 @@ d_handle_option (size_t scode, const char *arg, 
HOST_WIDE_INT value,
case CppStdRevisionCpp14:
case CppStdRevisionCpp17:
case CppStdRevisionCpp20:
+   case CppStdRevisionCpp23:
  global.params.cplusplus = (CppStdRevision) value;
  break;
 
diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index f274580f2d60..9982d0dd83ef 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-8db14cf8467ca25256904d51169b176c9c89afb1
+94950cae582d89f5ba2720786522f669f620f9d1
 
 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/globals.d b/gcc/d/dmd/globals.d
index 4a637b519c9a..900c554e5f45 100644
--- a/gcc/d/dmd/globals.d
+++ b/gcc/d/dmd/globals.d
@@ -62,6 +62,7 @@ enum CppStdRevision : uint
 cpp14 = 2014_02,
 cpp17 = 2017_03,
 cpp20 = 2020_02,
+cpp23 = 2023_02,
 }
 
 /// Trivalent boolean to represent the state of a `revert`able change
diff --git a/gcc/d/dmd/globals.h b/gcc/d/dmd/globals.h
index cdb0663b18d1..69fe709f4b0a 100644
--- a/gcc/d/dmd/globals.h
+++ b/gcc/d/dmd/globals.h
@@ -73,7 +73,8 @@ enum CppStdRevision
 CppStdRevisionCpp11 = 201103,
 CppStdRevisionCpp14 = 201402,
 CppStdRevisionCpp17 = 201703,
-CppStdRevisionCpp20 = 202002
+CppStdRevisionCpp20 = 202002,
+CppStdRevisionCpp23 = 202302,
 };
 
 /// Trivalent boolean to represent the state of a `revert`able change
diff --git a/gcc/d/gdc.texi b/gcc/d/gdc.texi
index 1a84d6dc4517..2cb0c4a62676 100644
--- a/gcc/d/gdc.texi
+++ b/gcc/d/gdc.texi
@@ -273,6 +273,8 @@ Sets @code{__traits(getTargetInfo, "cppStd")} to 
@code{201703}.
 This is the default.
 @item c++20
 Sets @code{__traits(getTargetInfo, "cppStd")} to @code{202002}.
+@item c++23
+Sets @code{__traits(getTargetInfo, "cppStd")} to @code{202302}.
 @end table
 
 @opindex finvariants
diff --git a/gcc/d/lang.opt b/gcc/d/lang.opt
index f769a71aee81..50c6f2f4da4d 100644
--- a/gcc/d/lang.opt
+++ b/gcc/d/lang.opt
@@ -320,6 +320,9 @@ Enum(extern_stdcpp) String(c++17) Value(201703)
 EnumValue
 Enum(extern_stdcpp) String(c++20) Value(202002)
 
+EnumValue
+Enum(extern_stdcpp) String(c++23) Value(202302)
+
 fignore-unknown-pragmas
 D
 Ignore unsupported pragmas.
diff --git a/libphobos/libdruntime/MERGE b/libphobos/libdruntime/MERGE
index 18c9d1190ced..9982d0dd83ef 100644
--- a/libphobos/libdruntime/MERGE
+++ b/libphobos/libdruntime/MERGE
@@ -1,4 +1,4 @@
-d2ee11364c25ca8865eb0acb9596a6147532ef41
+94950cae582d89f5ba2720786522f669f620f9d1
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
diff --git a/libphobos/libdruntime/core/stdcpp/xutility.d 
b/libphobos/libdruntime/core/stdcpp/xutility.d
index 5e2e711ba67b..f93df68debaf 100644
--- a/libphobos/libdruntime/core/stdcpp/xutility.d
+++ b/libphobos/libdruntime/core/stdcpp/xutility.d
@@ -35,6 +35,7 @@ enum CppStdRevision : uint
 cpp14 = 201402,
 cpp17 = 201703,
 cpp20 = 202002,
+cpp23 = 202302,
 }
 
 /**


[gcc r15-8865] testsuite: d: Break up Wbuiltin_declaration_mismatch2.d into smaller tests

2025-03-24 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:0d998b38a6fd280973fa6e91d3e34e544eef8fb2

commit r15-8865-g0d998b38a6fd280973fa6e91d3e34e544eef8fb2
Author: Iain Buclaw 
Date:   Mon Mar 24 14:07:49 2025 +0100

testsuite: d: Break up Wbuiltin_declaration_mismatch2.d into smaller tests

gcc/testsuite/ChangeLog:

* gdc.dg/Wbuiltin_declaration_mismatch2.d: Split test into ...
* gdc.dg/Wbuiltin_declaration_mismatch3.d: New test.
* gdc.dg/Wbuiltin_declaration_mismatch4.d: New test.
* gdc.dg/Wbuiltin_declaration_mismatch5.d: New test.
* gdc.dg/Wbuiltin_declaration_mismatch6.d: New test.

Diff:
---
 .../gdc.dg/Wbuiltin_declaration_mismatch2.d| 176 -
 .../gdc.dg/Wbuiltin_declaration_mismatch3.d|  61 +++
 .../gdc.dg/Wbuiltin_declaration_mismatch4.d|  51 ++
 .../gdc.dg/Wbuiltin_declaration_mismatch5.d|  53 +++
 .../gdc.dg/Wbuiltin_declaration_mismatch6.d|  61 +++
 5 files changed, 226 insertions(+), 176 deletions(-)

diff --git a/gcc/testsuite/gdc.dg/Wbuiltin_declaration_mismatch2.d 
b/gcc/testsuite/gdc.dg/Wbuiltin_declaration_mismatch2.d
index 0d12bcb8b079..8dcba79bfc3d 100644
--- a/gcc/testsuite/gdc.dg/Wbuiltin_declaration_mismatch2.d
+++ b/gcc/testsuite/gdc.dg/Wbuiltin_declaration_mismatch2.d
@@ -28,183 +28,7 @@ void test_load_store()
 storeUnaligned!fake4(null, f); // { dg-warning "mismatch in return type" }
 }
 
-void test_shuffle()
-{
-shuffle!(int, int, int)(0, 0, 0); // { dg-warning "mismatch in return 
type" }
-shuffle!(double, int, int)(0, 0, 0); // { dg-warning "mismatch in return 
type" }
-shuffle!(fake4, int, int)(f, 0, 0); // { dg-warning "mismatch in return 
type" }
-
-shuffle!(int4, int, int)(0, 0, 0); // { dg-warning "mismatch in argument 
2" }
-shuffle!(int4, double, int)(0, 0, 0); // { dg-warning "mismatch in 
argument 2" }
-shuffle!(int4, fake4, int)(0, f, 0); // { dg-warning "mismatch in argument 
2" }
-
-shuffle!(int4, int4, int)(0, 0, 0); // { dg-warning "mismatch in argument 
3" }
-shuffle!(int4, int4, double)(0, 0, 0); // { dg-warning "mismatch in 
argument 3" }
-shuffle!(int4, int4, fake4)(0, 0, f); // { dg-warning "mismatch in 
argument 3" }
-
-shuffle!(int4, int4, int4)(0, 0, 0);
-shuffle!(int4, short8, int4)(0, 0, 0); // { dg-error "mismatch in argument 
2" }
-shuffle!(int4, float4, int4)(0, 0, 0); // { dg-error "mismatch in argument 
2" }
-shuffle!(int4, byte16, int4)(0, 0, 0); // { dg-error "mismatch in argument 
2" }
-shuffle!(int4, int4, short8)(0, 0, 0); // { dg-error "mismatch in argument 
3" }
-shuffle!(int4, int4, float4)(0, 0, 0); // { dg-error "mismatch in argument 
3" }
-shuffle!(int4, int4, byte16)(0, 0, 0); // { dg-error "mismatch in argument 
3" }
-
-shuffle!(float4, int4, int4)(0, 0, 0); // { dg-error "mismatch in argument 
2" }
-shuffle!(float4, short8, int4)(0, 0, 0); // { dg-error "mismatch in 
argument 2" }
-shuffle!(float4, float4, int4)(0, 0, 0);
-shuffle!(float4, byte16, int4)(0, 0, 0); // { dg-error "mismatch in 
argument 2" }
-shuffle!(float4, float4, short8)(0, 0, 0); // { dg-error "mismatch in 
argument 3" }
-shuffle!(float4, float4, float4)(0, 0, 0); // { dg-error "mismatch in 
argument 3" }
-shuffle!(float4, float4, byte16)(0, 0, 0); // { dg-error "mismatch in 
argument 3" }
-
-shuffle!(short8, int4, int4)(0, 0, 0); // { dg-error "mismatch in argument 
2" }
-shuffle!(short8, short8, int4)(0, 0, 0); // { dg-error "mismatch in 
argument 3" }
-shuffle!(short8, float4, int4)(0, 0, 0); // { dg-error "mismatch in 
argument 2" }
-shuffle!(short8, byte16, int4)(0, 0, 0); // { dg-error "mismatch in 
argument 2" }
-shuffle!(short8, short8, short8)(0, 0, 0);
-shuffle!(short8, short8, float4)(0, 0, 0); // { dg-error "mismatch in 
argument 3" }
-shuffle!(short8, short8, byte16)(0, 0, 0); // { dg-error "mismatch in 
argument 3" }
-
-shuffle!(byte16, int4, int4)(0, 0, 0); // { dg-error "mismatch in argument 
2" }
-shuffle!(byte16, short8, int4)(0, 0, 0); // { dg-error "mismatch in 
argument 2" }
-shuffle!(byte16, float4, int4)(0, 0, 0); // { dg-error "mismatch in 
argument 2" }
-shuffle!(byte16, byte16, int4)(0, 0, 0); // { dg-error "mismatch in 
argument 3" }
-shuffle!(byte16, byte16, short8)(0, 0, 0); // { dg-error "mismatch in 
argument 3" }
-shuffle!(byte16, byte16, float4)(0, 0, 0); // { dg-error "mismatch in 
argument 3" }
-shuffle!(byte16, byte16, byte16)(0, 0, 0);
-}
-
-void test_shufflevector()
-{
-shufflevector!(int, int4, int, int, int, int)(0, 0, 0, 0, 0, 0); // { 
dg-warning "mismatch in argument 1" }
-shufflevector!(double, int4, int, int, int, int)(0, 0, 0, 0, 0, 0); // { 
dg-warning "mismatch in argument 1" }
-shufflevector!(fake4, int4, int, int, int, int)(f, 0, 0, 0, 0, 0); // { 
dg-warning "mismatch in argument 1" }
-
-shufflevector!(int4, int, int, int, int, int)(0, 0,

[gcc r15-8269] libphobos: Merge changes in upstream druntime testsuite

2025-03-18 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:b3b54f9c9a74909a41ea566c2135c9e01121994c

commit r15-8269-gb3b54f9c9a74909a41ea566c2135c9e01121994c
Author: Iain Buclaw 
Date:   Sat Mar 15 16:32:48 2025 +0100

libphobos: Merge changes in upstream druntime testsuite

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime d2ee11364c.
* testsuite/libphobos.aa/test_aa.d: Add new test.
* testsuite/libphobos.betterc/test19933.d: Adjust imports.
* testsuite/libphobos.config/test22523.d: Likewise.
* testsuite/libphobos.exceptions/assert_fail.d: Adjust test.
* testsuite/libphobos.exceptions/chain.d: Adjust imports.
* testsuite/libphobos.exceptions/future_message.d: Likewise.
* testsuite/libphobos.exceptions/line_trace.d: Likewise.
* testsuite/libphobos.exceptions/long_backtrace_trunc.d: Likewise.
* testsuite/libphobos.exceptions/static_dtor.d: Likewise.
* testsuite/libphobos.gc/forkgc.d: Likewise.
* testsuite/libphobos.gc/precisegc.d: Likewise.
* testsuite/libphobos.gc/recoverfree.d: Likewise.
* testsuite/libphobos.hash/test_hash.d: Likewise.
* testsuite/libphobos.init_fini/custom_gc.d: Likewise.
* testsuite/libphobos.init_fini/thread_join.d: Likewise.
* testsuite/libphobos.thread/external_threads.d: Likewise.
* testsuite/libphobos.thread/fiber_guard_page.d: Likewise.
* testsuite/libphobos.thread/tlsgc_sections.d: Likewise.
* testsuite/libphobos.thread/tlsstack.d: Likewise.
* testsuite/libphobos.unittest/customhandler.d: Likewise.

Diff:
---
 libphobos/libdruntime/MERGE|  2 +-
 libphobos/testsuite/libphobos.aa/test_aa.d | 44 +-
 libphobos/testsuite/libphobos.betterc/test19933.d  |  2 +-
 libphobos/testsuite/libphobos.config/test22523.d   |  2 +-
 .../testsuite/libphobos.exceptions/assert_fail.d   |  8 
 libphobos/testsuite/libphobos.exceptions/chain.d   |  2 +-
 .../libphobos.exceptions/future_message.d  |  2 +-
 .../testsuite/libphobos.exceptions/line_trace.d|  2 +-
 .../libphobos.exceptions/long_backtrace_trunc.d|  2 +-
 .../testsuite/libphobos.exceptions/static_dtor.d   |  2 +-
 libphobos/testsuite/libphobos.gc/forkgc.d  |  2 +-
 libphobos/testsuite/libphobos.gc/precisegc.d   |  2 +-
 libphobos/testsuite/libphobos.gc/recoverfree.d |  1 -
 libphobos/testsuite/libphobos.hash/test_hash.d |  4 +-
 .../testsuite/libphobos.init_fini/custom_gc.d  |  4 +-
 .../testsuite/libphobos.init_fini/thread_join.d|  1 -
 .../testsuite/libphobos.thread/external_threads.d  |  3 +-
 .../testsuite/libphobos.thread/fiber_guard_page.d  |  4 +-
 .../testsuite/libphobos.thread/tlsgc_sections.d|  2 +-
 libphobos/testsuite/libphobos.thread/tlsstack.d|  2 +-
 .../testsuite/libphobos.unittest/customhandler.d   |  2 +-
 21 files changed, 71 insertions(+), 24 deletions(-)

diff --git a/libphobos/libdruntime/MERGE b/libphobos/libdruntime/MERGE
index 070d9fec28b9..18c9d1190ced 100644
--- a/libphobos/libdruntime/MERGE
+++ b/libphobos/libdruntime/MERGE
@@ -1,4 +1,4 @@
-603225372b211bb66dd0ea1a939043ace5a650cf
+d2ee11364c25ca8865eb0acb9596a6147532ef41
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
diff --git a/libphobos/testsuite/libphobos.aa/test_aa.d 
b/libphobos/testsuite/libphobos.aa/test_aa.d
index 11ad2f90ff1d..5c3ba05d83d3 100644
--- a/libphobos/testsuite/libphobos.aa/test_aa.d
+++ b/libphobos/testsuite/libphobos.aa/test_aa.d
@@ -40,6 +40,7 @@ void main()
 testZeroSizedValue();
 testTombstonePurging();
 testClear();
+testTypeInfoCollect();
 }
 
 void testKeysValues1()
@@ -585,8 +586,6 @@ void issue13078() nothrow pure
 
 void issue14104()
 {
-import core.stdc.stdio;
-
 alias K = const(ubyte)*;
 size_t[K] aa;
 immutable key = cast(K)(cast(size_t) uint.max + 1);
@@ -907,3 +906,44 @@ void testClear()
 assert(aa.length == 1);
 assert(aa[5] == 6);
 }
+
+// https://github.com/dlang/dmd/issues/17503
+void testTypeInfoCollect()
+{
+import core.memory;
+
+static struct S
+{
+int x;
+~this() {}
+}
+
+static struct AAHolder
+{
+S[int] aa;
+}
+
+static S* getBadS()
+{
+auto aaholder = new AAHolder;
+aaholder.aa[0] = S();
+auto s = 0 in aaholder.aa; // keep a pointer to the entry
+GC.free(aaholder); // but not a pointer to the AA.
+return s;
+}
+
+static void stackStomp()
+{
+import core.stdc.string : memset;
+ubyte[4 * 4096] x;
+memset(x.ptr, 0, x.sizeof);
+}
+
+auto s = getBadS();
+stackStomp(); // destroy any stale references to the AA or s except in the 
current frame;
+GC.collect(); // BUG: this used to invalidate the fake type info, should

[gcc r15-8274] libphobos: Avoid setting union members in std.json, set the whole union instead

2025-03-18 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:ef4248460d53dc9b43a59f8b7c782a9d9f9b2754

commit r15-8274-gef4248460d53dc9b43a59f8b7c782a9d9f9b2754
Author: Iain Buclaw 
Date:   Tue Mar 18 19:12:14 2025 +0100

libphobos: Avoid setting union members in std.json, set the whole union 
instead

libphobos/ChangeLog:

* src/MERGE: Merge upstream phobos cafe86453.

Reviewed-on: https://github.com/dlang/phobos/pull/10683

Diff:
---
 libphobos/src/MERGE  |  2 +-
 libphobos/src/std/json.d | 44 
 2 files changed, 17 insertions(+), 29 deletions(-)

diff --git a/libphobos/src/MERGE b/libphobos/src/MERGE
index a5a685de2362..93b7a4d1ac2c 100644
--- a/libphobos/src/MERGE
+++ b/libphobos/src/MERGE
@@ -1,4 +1,4 @@
-0faae92d62bdc1cc1982f0e9c65830ece1677289
+cafe8645336bfc60be03b5a558164b3bc7df79ef
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/phobos repository.
diff --git a/libphobos/src/std/json.d b/libphobos/src/std/json.d
index 7182f6ee8072..eb08de8f048d 100644
--- a/libphobos/src/std/json.d
+++ b/libphobos/src/std/json.d
@@ -562,8 +562,7 @@ struct JSONValue
 else static if (is(T : string))
 {
 type_tag = JSONType.string;
-string t = arg;
-() @trusted { store.str = t; }();
+store = Store(str: arg);
 }
 // https://issues.dlang.org/show_bug.cgi?id=15884
 else static if (isSomeString!T)
@@ -572,7 +571,7 @@ struct JSONValue
 // FIXME: std.Array.Array(Range) is not deduced as 'pure'
 () @trusted {
 import std.utf : byUTF;
-store.str = cast(immutable)(arg.byUTF!char.array);
+store = Store(str: cast(immutable)(arg.byUTF!char.array));
 }();
 }
 else static if (is(T : bool))
@@ -582,17 +581,17 @@ struct JSONValue
 else static if (is(T : ulong) && isUnsigned!T)
 {
 type_tag = JSONType.uinteger;
-store.uinteger = arg;
+store = Store(uinteger: arg);
 }
 else static if (is(T : long))
 {
 type_tag = JSONType.integer;
-store.integer = arg;
+store = Store(integer: arg);
 }
 else static if (isFloatingPoint!T)
 {
 type_tag = JSONType.float_;
-store.floating = arg;
+store = Store(floating: arg);
 }
 else static if (is(T : Value[Key], Key, Value))
 {
@@ -600,45 +599,34 @@ struct JSONValue
 type_tag = JSONType.object;
 static if (is(Value : JSONValue))
 {
-JSONValue[string] t = arg;
-() @trusted {
-store.object.isOrdered = false;
-store.object.unordered = t;
-}();
+store = Store(object: Store.Object(false, unordered: arg));
 }
 else
 {
 JSONValue[string] aa;
 foreach (key, value; arg)
 aa[key] = JSONValue(value);
-() @trusted {
-store.object.isOrdered = false;
-store.object.unordered = aa;
-}();
+store = Store(object: Store.Object(false, unordered: aa));
 }
 }
 else static if (is(T : OrderedObjectMember[]))
 {
 type_tag = JSONType.object;
-() @trusted {
-store.object.isOrdered = true;
-store.object.ordered = arg;
-}();
+store = Store(object: Store.Object(true, ordered: arg));
 }
 else static if (isArray!T)
 {
 type_tag = JSONType.array;
 static if (is(ElementEncodingType!T : JSONValue))
 {
-JSONValue[] t = arg;
-() @trusted { store.array = t; }();
+store = Store(array: arg);
 }
 else
 {
 JSONValue[] new_arg = new JSONValue[arg.length];
 foreach (i, e; arg)
 new_arg[i] = JSONValue(e);
-() @trusted { store.array = new_arg; }();
+store = Store(array: new_arg);
 }
 }
 else static if (is(T : JSONValue))
@@ -658,14 +646,14 @@ struct JSONValue
 type_tag = JSONType.array;
 static if (is(ElementEncodingType!T : JSONValue))
 {
-store.array = arg;
+store = Store(array: arg);
 }
 else
 {
 JSONValue[] new_arg = new JSONValue[arg.length];
 foreach (i, e; arg)
 new_arg[i] = JSONValue(e);
-store.array = new_arg;
+store = Store(array: new_arg);
 }
 }
 
@@ -1616,13 +1604,13 @@ if (isSomeFiniteCharInputRange!T)
 if (isFloat)
   

[gcc r15-8275] libphobos: Fix std.getopt doesn't accept const(string)[] anymore

2025-03-18 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:1ad1bcc991b32d72d4de4758c0dcac611f20cda8

commit r15-8275-g1ad1bcc991b32d72d4de4758c0dcac611f20cda8
Author: Iain Buclaw 
Date:   Tue Mar 18 19:15:40 2025 +0100

libphobos: Fix std.getopt doesn't accept const(string)[] anymore

Instead of passing receiver into the conversion function, just return
the value and assign it to the receiver. Renamed the conversion function
and also cleaned up all the `typeof' calls, which were very verbose.

libphobos/ChangeLog:

* src/MERGE: Merge upstream phobos 79cbde1ab.

Reviewed-on: https://github.com/dlang/phobos/pull/10684

Diff:
---
 libphobos/src/MERGE|  2 +-
 libphobos/src/std/getopt.d | 73 +-
 2 files changed, 41 insertions(+), 34 deletions(-)

diff --git a/libphobos/src/MERGE b/libphobos/src/MERGE
index 93b7a4d1ac2c..a4888fc96180 100644
--- a/libphobos/src/MERGE
+++ b/libphobos/src/MERGE
@@ -1,4 +1,4 @@
-cafe8645336bfc60be03b5a558164b3bc7df79ef
+79cbde1ab69bae9372f310d663edfc43166095e3
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/phobos repository.
diff --git a/libphobos/src/std/getopt.d b/libphobos/src/std/getopt.d
index 1a9072207f5d..fc5cdac73cec 100644
--- a/libphobos/src/std/getopt.d
+++ b/libphobos/src/std/getopt.d
@@ -610,14 +610,14 @@ private template optionValidator(A...)
 alias optionValidator = message;
 }
 
-private void handleConversion(R)(string option, string value, R* receiver,
+private auto getoptTo(R)(string option, string value,
 size_t idx, string file = __FILE__, size_t line = __LINE__)
 {
 import std.conv : to, ConvException;
 import std.format : format;
 try
 {
-*receiver = to!(typeof(*receiver))(value);
+return to!R(value);
 }
 catch (ConvException e)
 {
@@ -876,12 +876,18 @@ private bool handleOption(R)(string option, R receiver, 
ref string[] args,
 // (and potentially args[i + 1] too, but that comes later)
 args = args[0 .. i] ~ args[i + 1 .. $];
 
-static if (is(typeof(*receiver) == bool))
+static if (is(typeof(*receiver)))
+alias Target = typeof(*receiver);
+else
+// delegate
+alias Target = void;
+
+static if (is(Target == bool))
 {
 if (val.length)
 {
 // parse '--b=true/false'
-handleConversion(option, val, receiver, i);
+*receiver = getoptTo!(Target)(option, val, i);
 }
 else
 {
@@ -894,23 +900,23 @@ private bool handleOption(R)(string option, R receiver, 
ref string[] args,
 import std.exception : enforce;
 // non-boolean option, which might include an argument
 enum isCallbackWithLessThanTwoParameters =
-(is(typeof(receiver) == delegate) || is(typeof(*receiver) == 
function)) &&
+(is(R == delegate) || is(Target == function)) &&
 !is(typeof(receiver("", "")));
 if (!isCallbackWithLessThanTwoParameters && !(val.length) && 
!incremental)
 {
 // Eat the next argument too.  Check to make sure there's one
 // to be eaten first, though.
 enforce!GetOptException(i < args.length,
-"Missing value for argument " ~ a ~ ".");
+"Missing value for argument " ~ a ~ ".");
 val = args[i];
 args = args[0 .. i] ~ args[i + 1 .. $];
 }
-static if (is(typeof(*receiver) == enum) ||
-is(typeof(*receiver) == string))
+static if (is(Target == enum) ||
+is(Target == string))
 {
-handleConversion(option, val, receiver, i);
+*receiver = getoptTo!Target(option, val, i);
 }
-else static if (is(typeof(*receiver) : real))
+else static if (is(Target : real))
 {
 // numeric receiver
 if (incremental)
@@ -919,16 +925,16 @@ private bool handleOption(R)(string option, R receiver, 
ref string[] args,
 }
 else
 {
-handleConversion(option, val, receiver, i);
+*receiver = getoptTo!Target(option, val, i);
 }
 }
-else static if (is(typeof(*receiver) == string))
+else static if (is(Target == string))
 {
 // string receiver
-*receiver = to!(typeof(*receiver))(val);
+*receiver = getoptTo!(Target)(option, val, i);
 }
-else static if (is(typeof(receiver) == delegate) ||
-is(typeof(*receiver) == function))
+else static if (is(R == delegate) ||
+is(Target =

[gcc r15-8935] d: import __stdin causes compilation to pause while reading from stdin

2025-03-26 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:7c4f409524dabf23cb59b2663dc6cfa819a4287a

commit r15-8935-g7c4f409524dabf23cb59b2663dc6cfa819a4287a
Author: Iain Buclaw 
Date:   Tue Mar 25 19:37:34 2025 +0100

d: import __stdin causes compilation to pause while reading from stdin

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.

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 02a64d2e13.

Diff:
---
 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(-)

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index 116074932aed..08b4e78aba59 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 6c7416856a1e..1d14c085d3d7 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 fc7824f03901..8a6ec998e69a 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 900c554e5f45..132683e624a1 100644
--- a/gcc/d/dmd/globals.d
+++ b/gcc/d/dmd/globals.d
@@ -160,6 +160,7 @@ extern (C++) struct ImportPa

[gcc r15-9342] d: Fix forward referenced enums missing type names in debug info [PR118309]

2025-04-09 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:cee353c2653d274768a67677c8ea37fd23422b3c

commit r15-9342-gcee353c2653d274768a67677c8ea37fd23422b3c
Author: Iain Buclaw 
Date:   Wed Apr 9 20:02:02 2025 +0200

d: Fix forward referenced enums missing type names in debug info [PR118309]

Calling `rest_of_type_compilation' as the D types were built meant that
debug info was being emitted before all forward references were
resolved, resulting in DW_AT_name's to be missing.

Instead, defer outputting type debug information until all modules have
been parsed and generated in `d_finish_compilation'.

PR d/118309

gcc/d/ChangeLog:

* modules.cc: Include debug.h
(d_finish_compilation): Call debug_hooks->type_decl on all 
TYPE_DECLs.
* types.cc: Remove toplev.h include.
(finish_aggregate_type): Don't call rest_of_type_compilation or
rest_of_decl_compilation on type.
(TypeVisitor::visit (TypeEnum *)): Likewise.

gcc/testsuite/ChangeLog:

* gdc.dg/debug/dwarf2/pr118309.d: New test.

Diff:
---
 gcc/d/modules.cc |  9 +++
 gcc/d/types.cc   | 15 ++--
 gcc/testsuite/gdc.dg/debug/dwarf2/pr118309.d | 36 
 3 files changed, 47 insertions(+), 13 deletions(-)

diff --git a/gcc/d/modules.cc b/gcc/d/modules.cc
index 813d94bc5c4e..14e4a4850431 100644
--- a/gcc/d/modules.cc
+++ b/gcc/d/modules.cc
@@ -30,6 +30,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "function.h"
 #include "cgraph.h"
 #include "stor-layout.h"
+#include "debug.h"
 #include "toplev.h"
 #include "target.h"
 #include "common/common-target.h"
@@ -927,6 +928,14 @@ d_finish_compilation (tree *vec, int len)
   /* Complete all generated thunks.  */
   symtab->process_same_body_aliases ();
 
+  /* Output debug information for all type declarations in this unit.  */
+  for (int i = 0; i < len; i++)
+{
+  tree decl = vec[i];
+  if (TREE_CODE (decl) == TYPE_DECL)
+   debug_hooks->type_decl (decl, false);
+}
+
   /* Process all file scopes in this compilation, and the external_scope,
  through wrapup_global_declarations.  */
   for (int i = 0; i < len; i++)
diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index ea62bc9d05e1..e43fa88a5d4c 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -33,7 +33,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "langhooks.h"
 #include "tm.h"
 #include "function.h"
-#include "toplev.h"
 #include "target.h"
 #include "stringpool.h"
 #include "stor-layout.h"
@@ -709,13 +708,8 @@ finish_aggregate_type (unsigned structsize, unsigned 
alignsize, tree type)
   TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (type);
 }
 
-  /* Finish debugging output for this type.  */
-  rest_of_type_compilation (type, TYPE_FILE_SCOPE_P (type));
+  /* Complete any other forward-referenced fields of this aggregate type.  */
   finish_incomplete_fields (type);
-
-  /* Finish processing of TYPE_DECL.  */
-  rest_of_decl_compilation (TYPE_NAME (type),
-   DECL_FILE_SCOPE_P (TYPE_NAME (type)), 0);
 }
 
 /* Returns true if the class or struct type TYPE has already been layed out by
@@ -1185,13 +1179,8 @@ public:
 
layout_type (t->ctype);
 
-   /* Finish debugging output for this type.  */
-   rest_of_type_compilation (t->ctype, TYPE_FILE_SCOPE_P (t->ctype));
+   /* Complete forward-referenced fields of this enum type.  */
finish_incomplete_fields (t->ctype);
-
-   /* Finish processing of TYPE_DECL.  */
-   rest_of_decl_compilation (TYPE_NAME (t->ctype),
- DECL_FILE_SCOPE_P (TYPE_NAME (t->ctype)), 0);
   }
   }
 
diff --git a/gcc/testsuite/gdc.dg/debug/dwarf2/pr118309.d 
b/gcc/testsuite/gdc.dg/debug/dwarf2/pr118309.d
new file mode 100644
index ..50e42164eef1
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/dwarf2/pr118309.d
@@ -0,0 +1,36 @@
+// { dg-do compile }
+// { dg-options "-fno-druntime -gdwarf-4 -dA -fno-merge-debug-strings" }
+// { dg-final { scan-assembler-times "DIE\[^\n\r\]*DW_TAG_enumeration_type" 1 
} }
+// { dg-final { scan-assembler-times " DW_AT_enum_class" 1 } }
+// { dg-final { scan-assembler-times "\"E..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"E1..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"C1..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"C2..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"C3..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"C4..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"S1..\"\[^\n\]*DW_AT_name" 1 } }
+
+module expression;
+extern (C++):
+class C1
+{
+bool bfn() { return true; }
+}
+class C2 : C1
+{
+C4 cfn() { return null; }
+}
+class C3 : C2
+{
+S1.E s;
+}
+class C4 : C3
+{
+S1 s;
+}
+struct S1
+{

[gcc r15-9333] d: Use CONSTRUCTOR_ZERO_PADDING_BITS in the D FE [PR117832]

2025-04-09 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:3e3b665cc77791f2e088aeee124d8a9fb7f6eb41

commit r15-9333-g3e3b665cc77791f2e088aeee124d8a9fb7f6eb41
Author: Iain Buclaw 
Date:   Wed Apr 9 14:49:14 2025 +0200

d: Use CONSTRUCTOR_ZERO_PADDING_BITS in the D FE [PR117832]

Adds a new wrapper function for `build_constructor', and calls it
instead to ensure that all CONSTRUCTOR nodes explicitly created by the
front-end have CONSTRUCTOR_ZERO_PADDING_BITS set.

Some places may not be necessary as it's guaranteed for there to be no
padding in the type, such as D dynamic arrays.  Other places this gets
turned into a double-memset when optimizations are turned off, as the
front-end already generates a memset call to zero out all padding on
initializing a variable.  The optimizer sees through this so will
correctly clear all bits once, so this can be improved later as-needed.

PR d/117832

gcc/d/ChangeLog:

* d-tree.h (build_padded_constructor): New prototype.
* d-codegen.cc (build_padded_constructor): New function.
(d_array_value): Call it.
(build_memset_call): Likewise.
(build_struct_literal): Likewise.
(underlying_complex_expr): Likewise.
(build_array_from_val): Likewise.
(build_array_from_exprs): Likewise.
(d_build_call): Likewise.
(get_frame_for_symbol): Likewise.
* d-convert.cc (convert_for_rvalue): Likewise.
(convert_for_assignment): Likewise.
* decl.cc (class DeclVisitor): Likewise.
* expr.cc (class ExprVisitor): Likewise.
* modules.cc (layout_moduleinfo): Likewise.
* typeinfo.cc (class TypeInfoVisitor): Likewise.

Diff:
---
 gcc/d/d-codegen.cc | 32 +++-
 gcc/d/d-convert.cc |  4 ++--
 gcc/d/d-tree.h |  1 +
 gcc/d/decl.cc  |  2 +-
 gcc/d/expr.cc  | 22 --
 gcc/d/modules.cc   |  4 ++--
 gcc/d/typeinfo.cc  |  8 
 7 files changed, 45 insertions(+), 28 deletions(-)

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index ad71486e3ba8..1a7575aac22c 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -317,7 +317,7 @@ d_array_value (tree type, tree len, tree data)
   CONSTRUCTOR_APPEND_ELT (ce, len_field, len);
   CONSTRUCTOR_APPEND_ELT (ce, ptr_field, data);
 
-  return build_constructor (type, ce);
+  return build_padded_constructor (type, ce);
 }
 
 /* Returns value representing the array length of expression EXP.
@@ -898,7 +898,10 @@ build_memset_call (tree ptr, tree num)
 {
   tree cst = build_zero_cst (valtype);
   if (TREE_CODE (cst) == CONSTRUCTOR)
-   return build_memcpy_call (ptr, build_address (cst), num);
+   {
+ CONSTRUCTOR_ZERO_PADDING_BITS (cst) = 1;
+ return build_memcpy_call (ptr, build_address (cst), num);
+   }
 
   return modify_expr (build_deref (ptr), cst);
 }
@@ -1205,7 +1208,7 @@ build_struct_literal (tree type, vec  *init)
 {
   /* If the initializer was empty, use default zero initialization.  */
   if (vec_safe_is_empty (init))
-return build_constructor (type, NULL);
+return build_padded_constructor (type, NULL);
 
   /* Struct literals can be seen for special enums representing `_Complex',
  make sure to reinterpret the literal as the correct type.  */
@@ -1306,7 +1309,7 @@ build_struct_literal (tree type, vec  *init)
   /* Ensure that we have consumed all values.  */
   gcc_assert (vec_safe_is_empty (init) || ANON_AGGR_TYPE_P (type));
 
-  tree ctor = build_constructor (type, ve);
+  tree ctor = build_padded_constructor (type, ve);
 
   if (constant_p)
 TREE_CONSTANT (ctor) = 1;
@@ -1314,6 +1317,17 @@ build_struct_literal (tree type, vec  *init)
   return ctor;
 }
 
+/* Return a new zero padded CONSTRUCTOR node whose type is TYPE and values are
+   in the vec pointed to by VALS.  */
+
+tree
+build_padded_constructor (tree type, vec *vals)
+{
+  tree ctor = build_constructor (type, vals);
+  CONSTRUCTOR_ZERO_PADDING_BITS (ctor) = 1;
+  return ctor;
+}
+
 /* Given the TYPE of an anonymous field inside T, return the
FIELD_DECL for the field.  If not found return NULL_TREE.
Because anonymous types can nest, we must also search all
@@ -1647,7 +1661,7 @@ underlying_complex_expr (tree type, tree expr)
 real_part (expr));
   CONSTRUCTOR_APPEND_ELT (ve, TREE_CHAIN (TYPE_FIELDS (type)),
 imaginary_part (expr));
-  return build_constructor (type, ve);
+  return build_padded_constructor (type, ve);
 }
 
   /* Replace type in the reinterpret cast with a cast to the record type.  */
@@ -1852,7 +1866,7 @@ build_array_from_val (Type *type, tree val)
   for (size_t i = 0; i < dims; i++)
 CONSTRUCTOR_APPEND_ELT (elms, size_int (i), val);
 
-  return build_constructor (build_ctype (type), elms);
+  return build_padded_constructor (build_ctype (type), elms);
 }
 
 /*

[gcc r14-11399] libphobos: Default to libc closefrom in spawnProcessPosix [PR119112]

2025-03-15 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:ca0ea3d4192313ad00da4ff734baffcecafe0b1f

commit r14-11399-gca0ea3d4192313ad00da4ff734baffcecafe0b1f
Author: Iain Buclaw 
Date:   Mon Mar 10 20:52:49 2025 +0100

libphobos: Default to libc closefrom in spawnProcessPosix [PR119112]

This is a backport of two changes in upstream Phobos.

- The current implementation of spawnProcessPosix is broken on systems
with a large `ulimit -n' because it always OOMs making it impossible to
spawn processes. Using the libc implementation, when available, for
doing file descriptor operations en-mass solves this problem.

- The fallback code now reads the list of file descriptors in use from
/dev/fd or /proc/this/fd, avoiding the need to scroll through the entire
list of possible file descriptors. This fixes the fork process being
very slow and memory intensive when RLIMIT_NOFILE is too high.

PR d/119112

libphobos/ChangeLog:

* libdruntime/core/sys/freebsd/unistd.d (closefrom): Add binding.
* libdruntime/core/sys/linux/unistd.d (closefrom): Likewise.
* libdruntime/core/sys/openbsd/unistd.d (closefrom): Likewise.
* src/std/process.d (enum InternalError): Add closefds_dup2.
(spawnProcessPosix): Use closefrom when available.

Reviewed-on: https://github.com/dlang/phobos/pull/9048
Reviewed-on: https://github.com/dlang/phobos/pull/9077

Diff:
---
 libphobos/libdruntime/core/sys/freebsd/unistd.d |   2 +
 libphobos/libdruntime/core/sys/linux/unistd.d   |   4 +
 libphobos/libdruntime/core/sys/openbsd/unistd.d |   2 +
 libphobos/src/std/process.d | 194 ++--
 4 files changed, 158 insertions(+), 44 deletions(-)

diff --git a/libphobos/libdruntime/core/sys/freebsd/unistd.d 
b/libphobos/libdruntime/core/sys/freebsd/unistd.d
index 493cda1c8c9f..ebb7afa2726c 100644
--- a/libphobos/libdruntime/core/sys/freebsd/unistd.d
+++ b/libphobos/libdruntime/core/sys/freebsd/unistd.d
@@ -17,3 +17,5 @@ extern(C):
 nothrow:
 
 int getosreldate() pure @trusted;
+
+void closefrom(int);
diff --git a/libphobos/libdruntime/core/sys/linux/unistd.d 
b/libphobos/libdruntime/core/sys/linux/unistd.d
index faa226cf407c..548870268dbf 100644
--- a/libphobos/libdruntime/core/sys/linux/unistd.d
+++ b/libphobos/libdruntime/core/sys/linux/unistd.d
@@ -5,6 +5,7 @@ public import core.sys.posix.unistd;
 version (linux):
 extern(C):
 nothrow:
+@nogc:
 
 // Additional seek constants for sparse file handling
 // from Linux's unistd.h, stdio.h, and linux/fs.h
@@ -21,3 +22,6 @@ char* getpass(const(char)* prompt);
 
 // Exit all threads in a process
 void exit_group(int status);
+
+/// Close all open file descriptors greater or equal to `lowfd`
+void closefrom(int lowfd);
diff --git a/libphobos/libdruntime/core/sys/openbsd/unistd.d 
b/libphobos/libdruntime/core/sys/openbsd/unistd.d
index 4232c0360497..9618543d8da8 100644
--- a/libphobos/libdruntime/core/sys/openbsd/unistd.d
+++ b/libphobos/libdruntime/core/sys/openbsd/unistd.d
@@ -19,3 +19,5 @@ int getthrname(pid_t, char*, size_t);
 int pledge(const scope char*, const scope char*);
 int setthrname(pid_t, const scope char*);
 int unveil(const scope char*, const scope char*);
+
+int closefrom(int);
diff --git a/libphobos/src/std/process.d b/libphobos/src/std/process.d
index 494910f35350..3b8922179178 100644
--- a/libphobos/src/std/process.d
+++ b/libphobos/src/std/process.d
@@ -872,6 +872,7 @@ version (Posix) private enum InternalError : ubyte
 doubleFork,
 malloc,
 preExec,
+closefds_dup2,
 }
 
 /*
@@ -1000,7 +1001,7 @@ private Pid spawnProcessPosix(scope const(char[])[] args,
 if (config.flags & Config.Flags.detached)
 close(pidPipe[0]);
 close(forkPipe[0]);
-immutable forkPipeOut = forkPipe[1];
+auto forkPipeOut = forkPipe[1];
 immutable pidPipeOut = pidPipe[1];
 
 // Set the working directory.
@@ -1034,56 +1035,157 @@ private Pid spawnProcessPosix(scope const(char[])[] 
args,
 
 if (!(config.flags & Config.Flags.inheritFDs))
 {
-// NOTE: malloc() and getrlimit() are not on the POSIX async
-// signal safe functions list, but practically this should
-// not be a problem. Java VM and CPython also use malloc()
-// in its own implementation via opendir().
-import core.stdc.stdlib : malloc;
-import core.sys.posix.poll : pollfd, poll, POLLNVAL;
-import core.sys.posix.sys.resource : rlimit, getrlimit, 
RLIMIT_NOFILE;
-
-// Get the maximum number of file descriptors that could be 
open.
-rlimit r;
-if (getrlimit(RLIMIT_NOFILE, &r) != 0)
-{
-abortOnError(forkPipeOut, InternalError.getrlimit, .errno);
-}
-immutable maxDescriptors = cast(int) r.rlim_cur;

[gcc r15-9319] libphobos: Merge with upstream phobos 35977c802

2025-04-08 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:7767158577fd5a5cfdd9bf0c7ba8d47942d8940a

commit r15-9319-g7767158577fd5a5cfdd9bf0c7ba8d47942d8940a
Author: Iain Buclaw 
Date:   Tue Apr 8 16:41:10 2025 +0200

libphobos: Merge with upstream phobos 35977c802

Synchronizes recent bug fixes targeted for v2.111.1.

libphobos/ChangeLog:

* src/MERGE: Merge upstream phobos 35977c802.
* src/Makefile.am (PHOBOS_DSOURCES): Add
std/internal/windows/bcrypt.d.
* src/Makefile.in: Regenerate.

Diff:
---
 libphobos/src/MERGE |  2 +-
 libphobos/src/Makefile.am   | 17 
 libphobos/src/Makefile.in   | 19 +
 libphobos/src/std/file.d|  4 +-
 libphobos/src/std/internal/windows/bcrypt.d | 65 +
 libphobos/src/std/random.d  | 18 +---
 6 files changed, 89 insertions(+), 36 deletions(-)

diff --git a/libphobos/src/MERGE b/libphobos/src/MERGE
index 3dfe00877913..d870a91ba963 100644
--- a/libphobos/src/MERGE
+++ b/libphobos/src/MERGE
@@ -1,4 +1,4 @@
-60034b56e2a036a66fa78cbc0ec0290956423684
+35977c8029e7bb4dbe1b887688dabebe04ebea02
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/phobos repository.
diff --git a/libphobos/src/Makefile.am b/libphobos/src/Makefile.am
index 94e28f3d175d..5d690dddf2bd 100644
--- a/libphobos/src/Makefile.am
+++ b/libphobos/src/Makefile.am
@@ -144,14 +144,15 @@ PHOBOS_DSOURCES = etc/c/curl.d etc/c/odbc/odbc32.d 
etc/c/odbc/odbc64.d \
std/internal/unicode_comp.d std/internal/unicode_decomp.d \
std/internal/unicode_grapheme.d std/internal/unicode_norm.d \
std/internal/unicode_tables.d std/internal/windows/advapi32.d \
-   std/json.d std/logger/core.d std/logger/filelogger.d \
-   std/logger/multilogger.d std/logger/nulllogger.d std/logger/package.d \
-   std/math/algebraic.d std/math/constants.d std/math/exponential.d \
-   std/math/hardware.d std/math/operations.d std/math/package.d \
-   std/math/remainder.d std/math/rounding.d std/math/traits.d \
-   std/math/trigonometry.d std/mathspecial.d std/meta.d std/mmfile.d \
-   std/net/curl.d std/net/isemail.d std/numeric.d std/outbuffer.d \
-   std/package.d std/parallelism.d std/path.d std/process.d std/random.d \
+   std/internal/windows/bcrypt.d std/json.d std/logger/core.d \
+   std/logger/filelogger.d std/logger/multilogger.d \
+   std/logger/nulllogger.d std/logger/package.d std/math/algebraic.d \
+   std/math/constants.d std/math/exponential.d std/math/hardware.d \
+   std/math/operations.d std/math/package.d std/math/remainder.d \
+   std/math/rounding.d std/math/traits.d std/math/trigonometry.d \
+   std/mathspecial.d std/meta.d std/mmfile.d std/net/curl.d \
+   std/net/isemail.d std/numeric.d std/outbuffer.d std/package.d \
+   std/parallelism.d std/path.d std/process.d std/random.d \
std/range/interfaces.d std/range/package.d std/range/primitives.d \
std/regex/internal/backtracking.d std/regex/internal/generator.d \
std/regex/internal/ir.d std/regex/internal/kickstart.d \
diff --git a/libphobos/src/Makefile.in b/libphobos/src/Makefile.in
index d052aa805c2c..2bf7e3f28747 100644
--- a/libphobos/src/Makefile.in
+++ b/libphobos/src/Makefile.in
@@ -252,6 +252,7 @@ am__dirstamp = $(am__leading_dot)dirstamp
 @ENABLE_LIBDRUNTIME_ONLY_FALSE@std/internal/unicode_norm.lo \
 @ENABLE_LIBDRUNTIME_ONLY_FALSE@std/internal/unicode_tables.lo \
 @ENABLE_LIBDRUNTIME_ONLY_FALSE@std/internal/windows/advapi32.lo \
+@ENABLE_LIBDRUNTIME_ONLY_FALSE@std/internal/windows/bcrypt.lo \
 @ENABLE_LIBDRUNTIME_ONLY_FALSE@std/json.lo std/logger/core.lo \
 @ENABLE_LIBDRUNTIME_ONLY_FALSE@std/logger/filelogger.lo \
 @ENABLE_LIBDRUNTIME_ONLY_FALSE@std/logger/multilogger.lo \
@@ -612,14 +613,15 @@ libgphobos_la_LINK = $(LIBTOOL) --tag=D 
$(libgphobos_la_LIBTOOLFLAGS) \
 @ENABLE_LIBDRUNTIME_ONLY_FALSE@std/internal/unicode_comp.d 
std/internal/unicode_decomp.d \
 @ENABLE_LIBDRUNTIME_ONLY_FALSE@std/internal/unicode_grapheme.d 
std/internal/unicode_norm.d \
 @ENABLE_LIBDRUNTIME_ONLY_FALSE@std/internal/unicode_tables.d 
std/internal/windows/advapi32.d \
-@ENABLE_LIBDRUNTIME_ONLY_FALSE@std/json.d std/logger/core.d 
std/logger/filelogger.d \
-@ENABLE_LIBDRUNTIME_ONLY_FALSE@std/logger/multilogger.d 
std/logger/nulllogger.d std/logger/package.d \
-@ENABLE_LIBDRUNTIME_ONLY_FALSE@std/math/algebraic.d 
std/math/constants.d std/math/exponential.d \
-@ENABLE_LIBDRUNTIME_ONLY_FALSE@std/math/hardware.d 
std/math/operations.d std/math/package.d \
-@ENABLE_LIBDRUNTIME_ONLY_FALSE@std/math/remainder.d 
std/math/rounding.d std/math/traits.d \
-@ENABLE_LIBDRUNTIME_ONLY_FALSE@std/math/trigonometry.d 
std/mathspecial.d std/meta.d std/mmfile.d \
-

[gcc r15-9318] d: Fix infinite loop in isAliasThisTuple

2025-04-08 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:639376154eaffe683f4027c95a08c5d30922b12d

commit r15-9318-g639376154eaffe683f4027c95a08c5d30922b12d
Author: Iain Buclaw 
Date:   Tue Apr 8 16:36:15 2025 +0200

d: Fix infinite loop in isAliasThisTuple

This reverts a change in the upstream D implementation of the compiler,
as the refactoring introduced a regression.

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 51816cd01d.

Reviewed-on: https://github.com/dlang/dmd/pull/21155

Diff:
---
 gcc/d/dmd/MERGE   |  2 +-
 gcc/d/dmd/expressionsem.d | 30 +++
 gcc/testsuite/gdc.test/compilable/test21153.d |  8 +++
 3 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index bd297b612c4e..a05a50eefb8d 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-ed17b3e95dc3fc3264a4c91843da824f5541f3e1
+51816cd01deee5cc1d7d2c6e1e24788ec655b73e
 
 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/expressionsem.d b/gcc/d/dmd/expressionsem.d
index b0278cbaca1b..19111e31baa0 100644
--- a/gcc/d/dmd/expressionsem.d
+++ b/gcc/d/dmd/expressionsem.d
@@ -641,21 +641,25 @@ TupleDeclaration isAliasThisTuple(Expression e)
 Type t = e.type.toBasetype();
 while (true)
 {
-Dsymbol s = t.toDsymbol(null);
-if (!s)
-return null;
-auto ad = s.isAggregateDeclaration();
-if (!ad)
-return null;
-s = ad.aliasthis ? ad.aliasthis.sym : null;
-if (s && s.isVarDeclaration())
+if (Dsymbol s = t.toDsymbol(null))
 {
-TupleDeclaration td = 
s.isVarDeclaration().toAlias().isTupleDeclaration();
-if (td && td.isexp)
-return td;
+if (auto ad = s.isAggregateDeclaration())
+{
+s = ad.aliasthis ? ad.aliasthis.sym : null;
+if (s && s.isVarDeclaration())
+{
+TupleDeclaration td = 
s.isVarDeclaration().toAlias().isTupleDeclaration();
+if (td && td.isexp)
+return td;
+}
+if (Type att = t.aliasthisOf())
+{
+t = att;
+continue;
+}
+}
 }
-if (Type att = t.aliasthisOf())
-t = att;
+return null;
 }
 }
 
diff --git a/gcc/testsuite/gdc.test/compilable/test21153.d 
b/gcc/testsuite/gdc.test/compilable/test21153.d
new file mode 100644
index ..cd92a31240be
--- /dev/null
+++ b/gcc/testsuite/gdc.test/compilable/test21153.d
@@ -0,0 +1,8 @@
+// https://github.com/dlang/dmd/issues/21153
+alias AliasSeq(TList...) = TList;
+class DataClass;
+void reduce(DataClass[] r)
+{
+alias Args = AliasSeq!(DataClass);
+Args result = r[0];
+}


[gcc r15-9379] d: Merge upstream dmd 1b34fea478, phobos 40ffbb364

2025-04-11 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:b905ce8caf04253e02e153d60d6ea8f99d300af6

commit r15-9379-gb905ce8caf04253e02e153d60d6ea8f99d300af6
Author: Iain Buclaw 
Date:   Fri Apr 11 12:39:23 2025 +0200

d: Merge upstream dmd 1b34fea478, phobos 40ffbb364

D front-end changes:

- Import latest fixes from dmd v2.111.1-rc.1.

Phobos changes:

- Import latest fixes from phobos v2.111.1-rc.1.
- Restore compatibility with older Linux platforms where
  `getrandom' is unavailable.

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 1b34fea478.

libphobos/ChangeLog:

* src/MERGE: Merge upstream phobos 40ffbb364.
* Makefile.in: Regenerate.
* configure: Regenerate.
* configure.ac: Call DRUNTIME_OS_FEATURES.
* libdruntime/Makefile.am (AM_DFLAGS): Add OS_DFLAGS.
* libdruntime/Makefile.in: Regenerate.
* m4/druntime/os.m4 (DRUNTIME_OS_FEATURES): Define.
* src/Makefile.am: Add OS_DFLAGS.
* src/Makefile.in: Regenerate.
* testsuite/Makefile.in: Regenerate.
* testsuite/testsuite_flags.in: Add OS_DFLAGS.

Diff:
---
 gcc/d/dmd/MERGE|  2 +-
 gcc/d/dmd/globals.h|  1 +
 gcc/d/dmd/lexer.d  |  4 +-
 gcc/d/dmd/location.d   | 23 +---
 gcc/d/dmd/typesem.d| 16 +-
 gcc/testsuite/gdc.test/compilable/test21179.d  | 11 
 .../gdc.test/fail_compilation/fail_pretty_errors.d | 18 +++---
 libphobos/Makefile.in  |  1 +
 libphobos/configure| 53 -
 libphobos/configure.ac |  1 +
 libphobos/libdruntime/Makefile.am  |  3 +-
 libphobos/libdruntime/Makefile.in  |  4 +-
 libphobos/m4/druntime/os.m4| 27 +
 libphobos/src/MERGE|  2 +-
 libphobos/src/Makefile.am  |  3 +-
 libphobos/src/Makefile.in  |  4 +-
 libphobos/src/std/format/write.d   | 11 +++-
 libphobos/src/std/random.d | 66 ++
 libphobos/testsuite/Makefile.in|  1 +
 libphobos/testsuite/testsuite_flags.in |  2 +-
 20 files changed, 210 insertions(+), 43 deletions(-)

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index a05a50eefb8d..ee5eb853284b 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-51816cd01deee5cc1d7d2c6e1e24788ec655b73e
+1b34fea4788136b54ec77c6ed9678754d109fc79
 
 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/globals.h b/gcc/d/dmd/globals.h
index 59952a2c1053..62a575e322e3 100644
--- a/gcc/d/dmd/globals.h
+++ b/gcc/d/dmd/globals.h
@@ -421,6 +421,7 @@ struct SourceLoc
 uint32_t line;
 uint32_t column;
 uint32_t fileOffset;
+DString fileContent;
 };
 
 struct Loc
diff --git a/gcc/d/dmd/lexer.d b/gcc/d/dmd/lexer.d
index 63313ac2eddf..ed9f7f1ce775 100644
--- a/gcc/d/dmd/lexer.d
+++ b/gcc/d/dmd/lexer.d
@@ -132,7 +132,7 @@ class Lexer
 // debug printf("Lexer::Lexer(%p)\n", base);
 // debug printf("lexer.filename = %s\n", filename);
 token = Token.init;
-this.baseLoc = newBaseLoc(filename, endoffset);
+this.baseLoc = newBaseLoc(filename, base[0 .. endoffset]);
 this.linnum = 1;
 this.base = base;
 this.end = base + endoffset;
@@ -224,7 +224,7 @@ class Lexer
 inTokenStringConstant = 0;
 lastDocLine = 0;
 
-baseLoc = newBaseLoc("#defines", slice.length);
+baseLoc = newBaseLoc("#defines", slice);
 scanloc = baseLoc.getLoc(0);
 }
 
diff --git a/gcc/d/dmd/location.d b/gcc/d/dmd/location.d
index 54b3fb6e0aed..393ffb8a92d4 100644
--- a/gcc/d/dmd/location.d
+++ b/gcc/d/dmd/location.d
@@ -64,7 +64,7 @@ nothrow:
 extern (C++) static Loc singleFilename(const char* filename)
 {
 Loc result;
-locFileTable ~= new BaseLoc(filename.toDString, locIndex, 0, [0]);
+locFileTable ~= new BaseLoc(filename.toDString, null, locIndex, 0, 
[0]);
 result.index = locIndex++;
 return result;
 }
@@ -235,16 +235,20 @@ struct SourceLoc
 uint column; /// column number (starts at 1)
 uint fileOffset; /// byte index into file
 
+/// Index `fileOffset` into this to to obtain source code context of this 
location
+const(char)[] fileContent;
+
 // aliases for backwards compatibility
 alias linnum = line;
 alias charnum = column;
 
-this(const(char)[] filename, uint line, uint column, uint fileOffset = 0) 
nothrow @nogc pure @safe
+this(const(char)[] filename, uint line, uint column, uint fil

[gcc r15-9544] d: Fix infinite loop regression in CTFE

2025-04-17 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:0eae20c899e327aec0e48b9ff2d856aba44b2639

commit r15-9544-g0eae20c899e327aec0e48b9ff2d856aba44b2639
Author: Iain Buclaw 
Date:   Thu Apr 17 08:21:40 2025 +0200

d: Fix infinite loop regression in CTFE

An infinite loop was introduced by a previous refactoring in the
semantic pass for DeclarationExp nodes. Ensure the loop properly
terminates and add tests cases.

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 956e73d64e.

gcc/testsuite/ChangeLog:

* gdc.test/fail_compilation/test21247.d: New test.
* gdc.test/fail_compilation/test21247b.d: New test.

Reviewed-on: https://github.com/dlang/dmd/pull/21248

Diff:
---
 gcc/d/dmd/MERGE  |  2 +-
 gcc/d/dmd/expressionsem.d|  6 +++---
 gcc/testsuite/gdc.test/fail_compilation/test21247.d  | 20 
 gcc/testsuite/gdc.test/fail_compilation/test21247b.d | 14 ++
 4 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index ee5eb853284b..58d19b4e951d 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-1b34fea4788136b54ec77c6ed9678754d109fc79
+956e73d64e532a68213970316c2590c572ec03f3
 
 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/expressionsem.d b/gcc/d/dmd/expressionsem.d
index 19111e31baa0..b02f6ea64102 100644
--- a/gcc/d/dmd/expressionsem.d
+++ b/gcc/d/dmd/expressionsem.d
@@ -6978,10 +6978,10 @@ private extern (C++) final class 
ExpressionSemanticVisitor : Visitor
 while (1)
 {
 AttribDeclaration ad = s.isAttribDeclaration();
-if (!ad)
-break;
-if (ad.decl && ad.decl.length == 1)
+if (ad && ad.decl && ad.decl.length == 1)
 s = (*ad.decl)[0];
+else
+break;
 }
 
 //printf("inserting '%s' %p into sc = %p\n", s.toChars(), s, sc);
diff --git a/gcc/testsuite/gdc.test/fail_compilation/test21247.d 
b/gcc/testsuite/gdc.test/fail_compilation/test21247.d
new file mode 100644
index ..c3e4105a05c3
--- /dev/null
+++ b/gcc/testsuite/gdc.test/fail_compilation/test21247.d
@@ -0,0 +1,20 @@
+/*
+TEST_OUTPUT:
+---
+fail_compilation/test21247.d(13): Error: anonymous union can only be a part of 
an aggregate, not function `hang_dmd`
+fail_compilation/test21247.d(17): Error: undefined identifier `u`
+fail_compilation/test21247.d(18): Error: undefined identifier `b`
+fail_compilation/test21247.d(20):called from here: `hang_dmd(0u)`
+---
+ */
+// https://github.com/dlang/dmd/issues/21247
+ubyte[4] hang_dmd(uint a)
+{
+union {
+uint u = void;
+ubyte[4] b;
+}
+u = a;
+return b;
+}
+enum T = hang_dmd(0);
diff --git a/gcc/testsuite/gdc.test/fail_compilation/test21247b.d 
b/gcc/testsuite/gdc.test/fail_compilation/test21247b.d
new file mode 100644
index ..ecd4603c064b
--- /dev/null
+++ b/gcc/testsuite/gdc.test/fail_compilation/test21247b.d
@@ -0,0 +1,14 @@
+/*
+TEST_OUTPUT:
+---
+fail_compilation/test21247b.d(10): Error: anonymous union can only be a part 
of an aggregate, not function `test21247`
+---
+ */
+// https://github.com/dlang/dmd/issues/21247
+void test21247()
+{
+union {
+uint u = void;
+ubyte[4] b;
+}
+}


[gcc r12-11061] d: Fix ICE in dwarf2out_imported_module_or_decl, at dwarf2out.cc:27676 [PR119817]

2025-04-20 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:0701c8d32507d9014c5b425157a034632d01e45f

commit r12-11061-g0701c8d32507d9014c5b425157a034632d01e45f
Author: Iain Buclaw 
Date:   Tue Apr 15 14:49:34 2025 +0200

d: Fix ICE in dwarf2out_imported_module_or_decl, at dwarf2out.cc:27676 
[PR119817]

The ImportVisitor method for handling the importing of overload sets was
pushing NULL_TREE to the array of import decls, which in turn got passed
to `debug_hooks->imported_module_or_decl', triggering the observed
internal compiler error.

NULL_TREE is returned from `build_import_decl' when the symbol was
ignored for being non-trivial to represent in debug, for example,
template or tuple declarations.  So similarly "skip" adding the symbol
when this is the case for overload sets too.

PR d/119817

gcc/d/ChangeLog:

* imports.cc (ImportVisitor::visit (OverloadSet *)): Don't push
NULL_TREE to vector of import symbols.

gcc/testsuite/ChangeLog:

* gdc.dg/debug/imports/m119817/a.d: New test.
* gdc.dg/debug/imports/m119817/b.d: New test.
* gdc.dg/debug/imports/m119817/package.d: New test.
* gdc.dg/debug/pr119817.d: New test.

(cherry picked from commit f5ed7d19c965de9ccb158d77e929b17459bf65b5)

Diff:
---
 gcc/d/imports.cc | 6 +-
 gcc/testsuite/gdc.dg/debug/imports/m119817/a.d   | 2 ++
 gcc/testsuite/gdc.dg/debug/imports/m119817/b.d   | 2 ++
 gcc/testsuite/gdc.dg/debug/imports/m119817/package.d | 4 
 gcc/testsuite/gdc.dg/debug/pr119817.d| 4 
 5 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/d/imports.cc b/gcc/d/imports.cc
index c8447b9674c5..fb8cde4d5bbc 100644
--- a/gcc/d/imports.cc
+++ b/gcc/d/imports.cc
@@ -182,7 +182,11 @@ public:
 vec_alloc (tset, d->a.length);
 
 for (size_t i = 0; i < d->a.length; i++)
-  vec_safe_push (tset, build_import_decl (d->a[i]));
+  {
+   tree overload = build_import_decl (d->a[i]);
+   if (overload != NULL_TREE)
+ vec_safe_push (tset, overload);
+  }
 
 this->result_ = build_tree_list_vec (tset);
 tset->truncate (0);
diff --git a/gcc/testsuite/gdc.dg/debug/imports/m119817/a.d 
b/gcc/testsuite/gdc.dg/debug/imports/m119817/a.d
new file mode 100644
index ..a13747240c43
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/m119817/a.d
@@ -0,0 +1,2 @@
+module imports.m119817.a;
+void f119817()() { }
diff --git a/gcc/testsuite/gdc.dg/debug/imports/m119817/b.d 
b/gcc/testsuite/gdc.dg/debug/imports/m119817/b.d
new file mode 100644
index ..aef0e373ca6e
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/m119817/b.d
@@ -0,0 +1,2 @@
+module imports.m119817.b;
+void f119817() { }
diff --git a/gcc/testsuite/gdc.dg/debug/imports/m119817/package.d 
b/gcc/testsuite/gdc.dg/debug/imports/m119817/package.d
new file mode 100644
index ..188827e669f5
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/m119817/package.d
@@ -0,0 +1,4 @@
+module imports.m119817;
+public import
+imports.m119817.a,
+imports.m119817.b;
diff --git a/gcc/testsuite/gdc.dg/debug/pr119817.d 
b/gcc/testsuite/gdc.dg/debug/pr119817.d
new file mode 100644
index ..91e2be0eaa67
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/pr119817.d
@@ -0,0 +1,4 @@
+// { dg-do compile }
+// { dg-additional-sources "imports/m119817/package.d imports/m119817/a.d 
imports/m119817/b.d" }
+module pr119817;
+import imports.m119817 : f119817;


[gcc r14-11665] d: Fix forward referenced enums missing type names in debug info [PR118309]

2025-04-19 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:aec3b99d3dee8a35adabb23c7835dfbd41e45520

commit r14-11665-gaec3b99d3dee8a35adabb23c7835dfbd41e45520
Author: Iain Buclaw 
Date:   Wed Apr 9 20:02:02 2025 +0200

d: Fix forward referenced enums missing type names in debug info [PR118309]

Calling `rest_of_type_compilation' as the D types were built meant that
debug info was being emitted before all forward references were
resolved, resulting in DW_AT_name's to be missing.

Instead, defer outputting type debug information until all modules have
been parsed and generated in `d_finish_compilation'.

PR d/118309

gcc/d/ChangeLog:

* modules.cc: Include debug.h
(d_finish_compilation): Call debug_hooks->type_decl on all 
TYPE_DECLs.
* types.cc: Remove toplev.h include.
(finish_aggregate_type): Don't call rest_of_type_compilation or
rest_of_decl_compilation on type.
(TypeVisitor::visit (TypeEnum *)): Likewise.

gcc/testsuite/ChangeLog:

* gdc.dg/debug/dwarf2/pr118309.d: New test.

(cherry picked from commit cee353c2653d274768a67677c8ea37fd23422b3c)

Diff:
---
 gcc/d/modules.cc |  9 +++
 gcc/d/types.cc   | 15 ++--
 gcc/testsuite/gdc.dg/debug/dwarf2/pr118309.d | 36 
 3 files changed, 47 insertions(+), 13 deletions(-)

diff --git a/gcc/d/modules.cc b/gcc/d/modules.cc
index b111ee90cea0..17d91d2ead9c 100644
--- a/gcc/d/modules.cc
+++ b/gcc/d/modules.cc
@@ -30,6 +30,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "function.h"
 #include "cgraph.h"
 #include "stor-layout.h"
+#include "debug.h"
 #include "toplev.h"
 #include "target.h"
 #include "common/common-target.h"
@@ -927,6 +928,14 @@ d_finish_compilation (tree *vec, int len)
   /* Complete all generated thunks.  */
   symtab->process_same_body_aliases ();
 
+  /* Output debug information for all type declarations in this unit.  */
+  for (int i = 0; i < len; i++)
+{
+  tree decl = vec[i];
+  if (TREE_CODE (decl) == TYPE_DECL)
+   debug_hooks->type_decl (decl, false);
+}
+
   /* Process all file scopes in this compilation, and the external_scope,
  through wrapup_global_declarations.  */
   for (int i = 0; i < len; i++)
diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index 6b045bde0a44..d1340bcd6aea 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -33,7 +33,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "langhooks.h"
 #include "tm.h"
 #include "function.h"
-#include "toplev.h"
 #include "target.h"
 #include "stringpool.h"
 #include "stor-layout.h"
@@ -709,13 +708,8 @@ finish_aggregate_type (unsigned structsize, unsigned 
alignsize, tree type)
   TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (type);
 }
 
-  /* Finish debugging output for this type.  */
-  rest_of_type_compilation (type, TYPE_FILE_SCOPE_P (type));
+  /* Complete any other forward-referenced fields of this aggregate type.  */
   finish_incomplete_fields (type);
-
-  /* Finish processing of TYPE_DECL.  */
-  rest_of_decl_compilation (TYPE_NAME (type),
-   DECL_FILE_SCOPE_P (TYPE_NAME (type)), 0);
 }
 
 /* Returns true if the class or struct type TYPE has already been layed out by
@@ -1185,13 +1179,8 @@ public:
 
layout_type (t->ctype);
 
-   /* Finish debugging output for this type.  */
-   rest_of_type_compilation (t->ctype, TYPE_FILE_SCOPE_P (t->ctype));
+   /* Complete forward-referenced fields of this enum type.  */
finish_incomplete_fields (t->ctype);
-
-   /* Finish processing of TYPE_DECL.  */
-   rest_of_decl_compilation (TYPE_NAME (t->ctype),
- DECL_FILE_SCOPE_P (TYPE_NAME (t->ctype)), 0);
   }
   }
 
diff --git a/gcc/testsuite/gdc.dg/debug/dwarf2/pr118309.d 
b/gcc/testsuite/gdc.dg/debug/dwarf2/pr118309.d
new file mode 100644
index ..50e42164eef1
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/dwarf2/pr118309.d
@@ -0,0 +1,36 @@
+// { dg-do compile }
+// { dg-options "-fno-druntime -gdwarf-4 -dA -fno-merge-debug-strings" }
+// { dg-final { scan-assembler-times "DIE\[^\n\r\]*DW_TAG_enumeration_type" 1 
} }
+// { dg-final { scan-assembler-times " DW_AT_enum_class" 1 } }
+// { dg-final { scan-assembler-times "\"E..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"E1..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"C1..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"C2..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"C3..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"C4..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"S1..\"\[^\n\]*DW_AT_name" 1 } }
+
+module expression;
+extern (C++):
+class C1
+{
+bool bfn() { return true; }
+}
+class C2 : C1
+{
+C4 cfn() { return null; }
+}

[gcc r14-11667] d: Fix ICE: type variant differs by TYPE_MAX_VALUE with -g [PR119826]

2025-04-19 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:88b3c896602036b61005501981b6f4a4deca59b0

commit r14-11667-g88b3c896602036b61005501981b6f4a4deca59b0
Author: Iain Buclaw 
Date:   Wed Apr 16 01:28:53 2025 +0200

d: Fix ICE: type variant differs by TYPE_MAX_VALUE with -g [PR119826]

Forward referenced enum types were never fixed up after the main
ENUMERAL_TYPE was finished.  All flags set are now propagated to all
variants after its mode, size, and alignment has been calculated.

PR d/119826

gcc/d/ChangeLog:

* types.cc (TypeVisitor::visit (TypeEnum *)): Propagate flags of 
main
enum types to all forward-referenced variants.

gcc/testsuite/ChangeLog:

* gdc.dg/debug/imports/pr119826b.d: New test.
* gdc.dg/debug/pr119826.d: New test.

(cherry picked from commit c5ffab99a5a962aa955310e74ca0a4be5c1acf30)

Diff:
---
 gcc/d/types.cc | 20 
 gcc/testsuite/gdc.dg/debug/imports/pr119826b.d | 14 ++
 gcc/testsuite/gdc.dg/debug/pr119826.d  |  8 
 3 files changed, 42 insertions(+)

diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index d1340bcd6aea..e9257c9c3776 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -1179,6 +1179,26 @@ public:
 
layout_type (t->ctype);
 
+   /* Fix up all forward-referenced variants of this enum type.  */
+   for (tree v = TYPE_MAIN_VARIANT (t->ctype); v;
+v = TYPE_NEXT_VARIANT (v))
+ {
+   if (v == t->ctype)
+ continue;
+
+   TYPE_VALUES (v) = TYPE_VALUES (t->ctype);
+   TYPE_LANG_SPECIFIC (v) = TYPE_LANG_SPECIFIC (t->ctype);
+   TYPE_MIN_VALUE (v) = TYPE_MIN_VALUE (t->ctype);
+   TYPE_MAX_VALUE (v) = TYPE_MAX_VALUE (t->ctype);
+   TYPE_UNSIGNED (v) = TYPE_UNSIGNED (t->ctype);
+   TYPE_SIZE (v) = TYPE_SIZE (t->ctype);
+   TYPE_SIZE_UNIT (v) = TYPE_SIZE_UNIT (t->ctype);
+   SET_TYPE_MODE (v, TYPE_MODE (t->ctype));
+   TYPE_PRECISION (v) = TYPE_PRECISION (t->ctype);
+   SET_TYPE_ALIGN (v, TYPE_ALIGN (t->ctype));
+   TYPE_USER_ALIGN (v) = TYPE_USER_ALIGN (t->ctype);
+ }
+
/* Complete forward-referenced fields of this enum type.  */
finish_incomplete_fields (t->ctype);
   }
diff --git a/gcc/testsuite/gdc.dg/debug/imports/pr119826b.d 
b/gcc/testsuite/gdc.dg/debug/imports/pr119826b.d
new file mode 100644
index ..3c5a6acbb877
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/pr119826b.d
@@ -0,0 +1,14 @@
+module imports.pr119826b;
+
+import pr119826 : t119826;
+
+class C119826
+{
+enum E119826 { Evalue }
+const E119826 em = void;
+}
+
+void f119826(C119826 c)
+{
+t119826(c.em);
+}
diff --git a/gcc/testsuite/gdc.dg/debug/pr119826.d 
b/gcc/testsuite/gdc.dg/debug/pr119826.d
new file mode 100644
index ..2fb98c7ba9df
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/pr119826.d
@@ -0,0 +1,8 @@
+// { dg-do compile }
+// { dg-additional-sources "imports/pr119826b.d" }
+module pr119826;
+
+int t119826(A)(A args)
+{
+assert(false);
+}


[gcc r14-11666] d: Fix ICE in dwarf2out_imported_module_or_decl, at dwarf2out.cc:27676 [PR119817]

2025-04-19 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:d1b7ee4879aca90c9828b6b9f4937ed15513adfa

commit r14-11666-gd1b7ee4879aca90c9828b6b9f4937ed15513adfa
Author: Iain Buclaw 
Date:   Tue Apr 15 14:49:34 2025 +0200

d: Fix ICE in dwarf2out_imported_module_or_decl, at dwarf2out.cc:27676 
[PR119817]

The ImportVisitor method for handling the importing of overload sets was
pushing NULL_TREE to the array of import decls, which in turn got passed
to `debug_hooks->imported_module_or_decl', triggering the observed
internal compiler error.

NULL_TREE is returned from `build_import_decl' when the symbol was
ignored for being non-trivial to represent in debug, for example,
template or tuple declarations.  So similarly "skip" adding the symbol
when this is the case for overload sets too.

PR d/119817

gcc/d/ChangeLog:

* imports.cc (ImportVisitor::visit (OverloadSet *)): Don't push
NULL_TREE to vector of import symbols.

gcc/testsuite/ChangeLog:

* gdc.dg/debug/imports/m119817/a.d: New test.
* gdc.dg/debug/imports/m119817/b.d: New test.
* gdc.dg/debug/imports/m119817/package.d: New test.
* gdc.dg/debug/pr119817.d: New test.

(cherry picked from commit f5ed7d19c965de9ccb158d77e929b17459bf65b5)

Diff:
---
 gcc/d/imports.cc | 6 +-
 gcc/testsuite/gdc.dg/debug/imports/m119817/a.d   | 2 ++
 gcc/testsuite/gdc.dg/debug/imports/m119817/b.d   | 2 ++
 gcc/testsuite/gdc.dg/debug/imports/m119817/package.d | 4 
 gcc/testsuite/gdc.dg/debug/pr119817.d| 4 
 5 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/d/imports.cc b/gcc/d/imports.cc
index 074d9e65333e..00b09c8c87f8 100644
--- a/gcc/d/imports.cc
+++ b/gcc/d/imports.cc
@@ -182,7 +182,11 @@ public:
 vec_alloc (tset, d->a.length);
 
 for (size_t i = 0; i < d->a.length; i++)
-  vec_safe_push (tset, build_import_decl (d->a[i]));
+  {
+   tree overload = build_import_decl (d->a[i]);
+   if (overload != NULL_TREE)
+ vec_safe_push (tset, overload);
+  }
 
 this->result_ = build_tree_list_vec (tset);
 tset->truncate (0);
diff --git a/gcc/testsuite/gdc.dg/debug/imports/m119817/a.d 
b/gcc/testsuite/gdc.dg/debug/imports/m119817/a.d
new file mode 100644
index ..a13747240c43
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/m119817/a.d
@@ -0,0 +1,2 @@
+module imports.m119817.a;
+void f119817()() { }
diff --git a/gcc/testsuite/gdc.dg/debug/imports/m119817/b.d 
b/gcc/testsuite/gdc.dg/debug/imports/m119817/b.d
new file mode 100644
index ..aef0e373ca6e
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/m119817/b.d
@@ -0,0 +1,2 @@
+module imports.m119817.b;
+void f119817() { }
diff --git a/gcc/testsuite/gdc.dg/debug/imports/m119817/package.d 
b/gcc/testsuite/gdc.dg/debug/imports/m119817/package.d
new file mode 100644
index ..188827e669f5
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/m119817/package.d
@@ -0,0 +1,4 @@
+module imports.m119817;
+public import
+imports.m119817.a,
+imports.m119817.b;
diff --git a/gcc/testsuite/gdc.dg/debug/pr119817.d 
b/gcc/testsuite/gdc.dg/debug/pr119817.d
new file mode 100644
index ..91e2be0eaa67
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/pr119817.d
@@ -0,0 +1,4 @@
+// { dg-do compile }
+// { dg-additional-sources "imports/m119817/package.d imports/m119817/a.d 
imports/m119817/b.d" }
+module pr119817;
+import imports.m119817 : f119817;


[gcc r13-9553] d: Fix ICE in dwarf2out_imported_module_or_decl, at dwarf2out.cc:27676 [PR119817]

2025-04-19 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:3c91f94bbb09c5380c3cc07c4c8fabab332eb962

commit r13-9553-g3c91f94bbb09c5380c3cc07c4c8fabab332eb962
Author: Iain Buclaw 
Date:   Tue Apr 15 14:49:34 2025 +0200

d: Fix ICE in dwarf2out_imported_module_or_decl, at dwarf2out.cc:27676 
[PR119817]

The ImportVisitor method for handling the importing of overload sets was
pushing NULL_TREE to the array of import decls, which in turn got passed
to `debug_hooks->imported_module_or_decl', triggering the observed
internal compiler error.

NULL_TREE is returned from `build_import_decl' when the symbol was
ignored for being non-trivial to represent in debug, for example,
template or tuple declarations.  So similarly "skip" adding the symbol
when this is the case for overload sets too.

PR d/119817

gcc/d/ChangeLog:

* imports.cc (ImportVisitor::visit (OverloadSet *)): Don't push
NULL_TREE to vector of import symbols.

gcc/testsuite/ChangeLog:

* gdc.dg/debug/imports/m119817/a.d: New test.
* gdc.dg/debug/imports/m119817/b.d: New test.
* gdc.dg/debug/imports/m119817/package.d: New test.
* gdc.dg/debug/pr119817.d: New test.

(cherry picked from commit f5ed7d19c965de9ccb158d77e929b17459bf65b5)

Diff:
---
 gcc/d/imports.cc | 6 +-
 gcc/testsuite/gdc.dg/debug/imports/m119817/a.d   | 2 ++
 gcc/testsuite/gdc.dg/debug/imports/m119817/b.d   | 2 ++
 gcc/testsuite/gdc.dg/debug/imports/m119817/package.d | 4 
 gcc/testsuite/gdc.dg/debug/pr119817.d| 4 
 5 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/d/imports.cc b/gcc/d/imports.cc
index 3172b799cb04..6133672638a6 100644
--- a/gcc/d/imports.cc
+++ b/gcc/d/imports.cc
@@ -182,7 +182,11 @@ public:
 vec_alloc (tset, d->a.length);
 
 for (size_t i = 0; i < d->a.length; i++)
-  vec_safe_push (tset, build_import_decl (d->a[i]));
+  {
+   tree overload = build_import_decl (d->a[i]);
+   if (overload != NULL_TREE)
+ vec_safe_push (tset, overload);
+  }
 
 this->result_ = build_tree_list_vec (tset);
 tset->truncate (0);
diff --git a/gcc/testsuite/gdc.dg/debug/imports/m119817/a.d 
b/gcc/testsuite/gdc.dg/debug/imports/m119817/a.d
new file mode 100644
index ..a13747240c43
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/m119817/a.d
@@ -0,0 +1,2 @@
+module imports.m119817.a;
+void f119817()() { }
diff --git a/gcc/testsuite/gdc.dg/debug/imports/m119817/b.d 
b/gcc/testsuite/gdc.dg/debug/imports/m119817/b.d
new file mode 100644
index ..aef0e373ca6e
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/m119817/b.d
@@ -0,0 +1,2 @@
+module imports.m119817.b;
+void f119817() { }
diff --git a/gcc/testsuite/gdc.dg/debug/imports/m119817/package.d 
b/gcc/testsuite/gdc.dg/debug/imports/m119817/package.d
new file mode 100644
index ..188827e669f5
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/m119817/package.d
@@ -0,0 +1,4 @@
+module imports.m119817;
+public import
+imports.m119817.a,
+imports.m119817.b;
diff --git a/gcc/testsuite/gdc.dg/debug/pr119817.d 
b/gcc/testsuite/gdc.dg/debug/pr119817.d
new file mode 100644
index ..91e2be0eaa67
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/pr119817.d
@@ -0,0 +1,4 @@
+// { dg-do compile }
+// { dg-additional-sources "imports/m119817/package.d imports/m119817/a.d 
imports/m119817/b.d" }
+module pr119817;
+import imports.m119817 : f119817;


[gcc r13-9554] d: Fix ICE: type variant differs by TYPE_MAX_VALUE with -g [PR119826]

2025-04-19 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:9f12448fcbc25c0459b477cb6c1cef7012849346

commit r13-9554-g9f12448fcbc25c0459b477cb6c1cef7012849346
Author: Iain Buclaw 
Date:   Wed Apr 16 01:28:53 2025 +0200

d: Fix ICE: type variant differs by TYPE_MAX_VALUE with -g [PR119826]

Forward referenced enum types were never fixed up after the main
ENUMERAL_TYPE was finished.  All flags set are now propagated to all
variants after its mode, size, and alignment has been calculated.

PR d/119826

gcc/d/ChangeLog:

* types.cc (TypeVisitor::visit (TypeEnum *)): Propagate flags of 
main
enum types to all forward-referenced variants.

gcc/testsuite/ChangeLog:

* gdc.dg/debug/imports/pr119826b.d: New test.
* gdc.dg/debug/pr119826.d: New test.

(cherry picked from commit c5ffab99a5a962aa955310e74ca0a4be5c1acf30)

Diff:
---
 gcc/d/types.cc | 20 
 gcc/testsuite/gdc.dg/debug/imports/pr119826b.d | 14 ++
 gcc/testsuite/gdc.dg/debug/pr119826.d  |  8 
 3 files changed, 42 insertions(+)

diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index 954686f2317f..9088cf4b8431 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -1179,6 +1179,26 @@ public:
 
layout_type (t->ctype);
 
+   /* Fix up all forward-referenced variants of this enum type.  */
+   for (tree v = TYPE_MAIN_VARIANT (t->ctype); v;
+v = TYPE_NEXT_VARIANT (v))
+ {
+   if (v == t->ctype)
+ continue;
+
+   TYPE_VALUES (v) = TYPE_VALUES (t->ctype);
+   TYPE_LANG_SPECIFIC (v) = TYPE_LANG_SPECIFIC (t->ctype);
+   TYPE_MIN_VALUE (v) = TYPE_MIN_VALUE (t->ctype);
+   TYPE_MAX_VALUE (v) = TYPE_MAX_VALUE (t->ctype);
+   TYPE_UNSIGNED (v) = TYPE_UNSIGNED (t->ctype);
+   TYPE_SIZE (v) = TYPE_SIZE (t->ctype);
+   TYPE_SIZE_UNIT (v) = TYPE_SIZE_UNIT (t->ctype);
+   SET_TYPE_MODE (v, TYPE_MODE (t->ctype));
+   TYPE_PRECISION (v) = TYPE_PRECISION (t->ctype);
+   SET_TYPE_ALIGN (v, TYPE_ALIGN (t->ctype));
+   TYPE_USER_ALIGN (v) = TYPE_USER_ALIGN (t->ctype);
+ }
+
/* Complete forward-referenced fields of this enum type.  */
finish_incomplete_fields (t->ctype);
   }
diff --git a/gcc/testsuite/gdc.dg/debug/imports/pr119826b.d 
b/gcc/testsuite/gdc.dg/debug/imports/pr119826b.d
new file mode 100644
index ..3c5a6acbb877
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/pr119826b.d
@@ -0,0 +1,14 @@
+module imports.pr119826b;
+
+import pr119826 : t119826;
+
+class C119826
+{
+enum E119826 { Evalue }
+const E119826 em = void;
+}
+
+void f119826(C119826 c)
+{
+t119826(c.em);
+}
diff --git a/gcc/testsuite/gdc.dg/debug/pr119826.d 
b/gcc/testsuite/gdc.dg/debug/pr119826.d
new file mode 100644
index ..2fb98c7ba9df
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/pr119826.d
@@ -0,0 +1,8 @@
+// { dg-do compile }
+// { dg-additional-sources "imports/pr119826b.d" }
+module pr119826;
+
+int t119826(A)(A args)
+{
+assert(false);
+}


[gcc r13-9552] d: Fix forward referenced enums missing type names in debug info [PR118309]

2025-04-19 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:849dcb45c5a79fa29c3cf706c987157deea4ac9d

commit r13-9552-g849dcb45c5a79fa29c3cf706c987157deea4ac9d
Author: Iain Buclaw 
Date:   Wed Apr 9 20:02:02 2025 +0200

d: Fix forward referenced enums missing type names in debug info [PR118309]

Calling `rest_of_type_compilation' as the D types were built meant that
debug info was being emitted before all forward references were
resolved, resulting in DW_AT_name's to be missing.

Instead, defer outputting type debug information until all modules have
been parsed and generated in `d_finish_compilation'.

PR d/118309

gcc/d/ChangeLog:

* modules.cc: Include debug.h
(d_finish_compilation): Call debug_hooks->type_decl on all 
TYPE_DECLs.
* types.cc: Remove toplev.h include.
(finish_aggregate_type): Don't call rest_of_type_compilation or
rest_of_decl_compilation on type.
(TypeVisitor::visit (TypeEnum *)): Likewise.

gcc/testsuite/ChangeLog:

* gdc.dg/debug/dwarf2/pr118309.d: New test.

(cherry picked from commit cee353c2653d274768a67677c8ea37fd23422b3c)

Diff:
---
 gcc/d/modules.cc |  9 +++
 gcc/d/types.cc   | 15 ++--
 gcc/testsuite/gdc.dg/debug/dwarf2/pr118309.d | 36 
 3 files changed, 47 insertions(+), 13 deletions(-)

diff --git a/gcc/d/modules.cc b/gcc/d/modules.cc
index be93d8af093a..3d43d82623f6 100644
--- a/gcc/d/modules.cc
+++ b/gcc/d/modules.cc
@@ -30,6 +30,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "function.h"
 #include "cgraph.h"
 #include "stor-layout.h"
+#include "debug.h"
 #include "toplev.h"
 #include "target.h"
 #include "common/common-target.h"
@@ -908,6 +909,14 @@ d_finish_compilation (tree *vec, int len)
   /* Complete all generated thunks.  */
   symtab->process_same_body_aliases ();
 
+  /* Output debug information for all type declarations in this unit.  */
+  for (int i = 0; i < len; i++)
+{
+  tree decl = vec[i];
+  if (TREE_CODE (decl) == TYPE_DECL)
+   debug_hooks->type_decl (decl, false);
+}
+
   /* Process all file scopes in this compilation, and the external_scope,
  through wrapup_global_declarations.  */
   for (int i = 0; i < len; i++)
diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index 0a8679756b0a..954686f2317f 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -33,7 +33,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "langhooks.h"
 #include "tm.h"
 #include "function.h"
-#include "toplev.h"
 #include "target.h"
 #include "stringpool.h"
 #include "stor-layout.h"
@@ -709,13 +708,8 @@ finish_aggregate_type (unsigned structsize, unsigned 
alignsize, tree type)
   TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (type);
 }
 
-  /* Finish debugging output for this type.  */
-  rest_of_type_compilation (type, TYPE_FILE_SCOPE_P (type));
+  /* Complete any other forward-referenced fields of this aggregate type.  */
   finish_incomplete_fields (type);
-
-  /* Finish processing of TYPE_DECL.  */
-  rest_of_decl_compilation (TYPE_NAME (type),
-   DECL_FILE_SCOPE_P (TYPE_NAME (type)), 0);
 }
 
 /* Returns true if the class or struct type TYPE has already been layed out by
@@ -1185,13 +1179,8 @@ public:
 
layout_type (t->ctype);
 
-   /* Finish debugging output for this type.  */
-   rest_of_type_compilation (t->ctype, TYPE_FILE_SCOPE_P (t->ctype));
+   /* Complete forward-referenced fields of this enum type.  */
finish_incomplete_fields (t->ctype);
-
-   /* Finish processing of TYPE_DECL.  */
-   rest_of_decl_compilation (TYPE_NAME (t->ctype),
- DECL_FILE_SCOPE_P (TYPE_NAME (t->ctype)), 0);
   }
   }
 
diff --git a/gcc/testsuite/gdc.dg/debug/dwarf2/pr118309.d 
b/gcc/testsuite/gdc.dg/debug/dwarf2/pr118309.d
new file mode 100644
index ..50e42164eef1
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/dwarf2/pr118309.d
@@ -0,0 +1,36 @@
+// { dg-do compile }
+// { dg-options "-fno-druntime -gdwarf-4 -dA -fno-merge-debug-strings" }
+// { dg-final { scan-assembler-times "DIE\[^\n\r\]*DW_TAG_enumeration_type" 1 
} }
+// { dg-final { scan-assembler-times " DW_AT_enum_class" 1 } }
+// { dg-final { scan-assembler-times "\"E..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"E1..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"C1..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"C2..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"C3..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"C4..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"S1..\"\[^\n\]*DW_AT_name" 1 } }
+
+module expression;
+extern (C++):
+class C1
+{
+bool bfn() { return true; }
+}
+class C2 : C1
+{
+C4 cfn() { return null; }
+}
+

[gcc r16-161] Add m32c*-*-* to the list of obsolete targets

2025-04-26 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:0035613389a939043d654aea7a76faae95f69422

commit r16-161-g0035613389a939043d654aea7a76faae95f69422
Author: Iain Buclaw 
Date:   Fri Apr 25 19:45:07 2025 +0200

Add m32c*-*-* to the list of obsolete targets

This patch marks m32c*-*-* targets obsolete in GCC 16.  The target has
not had a maintainer since GCC 9, and fails to compile even the
simplest of functions since GCC 8 (reported in PR83670).

contrib/ChangeLog:

* config-list.mk: Add m32c*-*-* to the list of obsoleted targets.

gcc/ChangeLog:

* config.gcc (LIST): --enable-obsolete for m32c-elf.

Diff:
---
 contrib/config-list.mk | 2 +-
 gcc/config.gcc | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/contrib/config-list.mk b/contrib/config-list.mk
index fc9fc9902bff..58bb4c5c186b 100644
--- a/contrib/config-list.mk
+++ b/contrib/config-list.mk
@@ -65,7 +65,7 @@ LIST = \
   ia64-hp-vmsOPT-enable-obsolete iq2000-elf lm32-elf \
   lm32-rtems lm32-uclinux \
   loongarch64-linux-gnuf64 loongarch64-linux-gnuf32 loongarch64-linux-gnusf \
-  m32c-elf m32r-elf m32rle-elf \
+  m32c-elfOPT-enable-obsolete m32r-elf m32rle-elf \
   m68k-elf m68k-netbsdelf \
   m68k-uclinux m68k-linux m68k-rtems \
   mcore-elf microblaze-linux microblaze-elf \
diff --git a/gcc/config.gcc b/gcc/config.gcc
index d98df883fce5..6dbe880c9d45 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -273,6 +273,7 @@ esac
 # Obsolete configurations.
 case ${target} in
  ia64*-*-hpux* | ia64*-*-*vms* | ia64*-*-elf*  \
+   | m32c*-*-* \
  )
 if test "x$enable_obsolete" != xyes; then
   echo "*** Configuration ${target} is obsolete." >&2


[gcc r15-9403] d: Add option to include imported modules in the compilation [PR109023]

2025-04-12 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:9a7b6668f8f79be8fa73982b8b0bde33c1d8c61f

commit r15-9403-g9a7b6668f8f79be8fa73982b8b0bde33c1d8c61f
Author: Iain Buclaw 
Date:   Sat Apr 12 11:13:50 2025 +0200

d: Add option to include imported modules in the compilation [PR109023]

Adds the ability to include imported modules in the compilation, as if
they were given on the command line.  When this option is enabled, all
imported modules are compiled except those that are part of libphobos.

PR d/109023

gcc/d/ChangeLog:

* d-compiler.cc: Include dmd/errors.h.
(Compiler::onImport): Implement.
* d-lang.cc (d_handle_option): Handle -finclude-imports.
(d_parse_file): Run semantic on included imports.
* gdc.texi: Document -finclude-imports.
* lang.opt: Add finclude-imports.
* lang.opt.urls: Regenerate.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/imports/pr109023.d: New test.
* gdc.dg/torture/pr109023.d: New test.

Diff:
---
 gcc/d/d-compiler.cc | 37 +++--
 gcc/d/d-lang.cc | 19 +
 gcc/d/gdc.texi  |  6 
 gcc/d/lang.opt  |  4 +++
 gcc/d/lang.opt.urls |  3 ++
 gcc/testsuite/gdc.dg/torture/imports/pr109023.d |  3 ++
 gcc/testsuite/gdc.dg/torture/pr109023.d |  6 
 7 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/gcc/d/d-compiler.cc b/gcc/d/d-compiler.cc
index 160539d08ae0..e18f5d33e6aa 100644
--- a/gcc/d/d-compiler.cc
+++ b/gcc/d/d-compiler.cc
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "coretypes.h"
 
 #include "dmd/compiler.h"
+#include "dmd/errors.h"
 #include "dmd/expression.h"
 #include "dmd/identifier.h"
 #include "dmd/module.h"
@@ -164,7 +165,39 @@ Compiler::onParseModule (Module *m)
driver intends on compiling the import.  */
 
 bool
-Compiler::onImport (Module *)
+Compiler::onImport (Module *m)
 {
-  return false;
+  if (!includeImports)
+return false;
+
+  if (m->filetype != FileType::d && m->filetype != FileType::c)
+return false;
+
+  /* All imports modules are included except those in the runtime library.  */
+  ModuleDeclaration *md = m->md;
+  if (md && md->id)
+{
+  if (md->packages.length >= 1)
+   {
+ if (!strcmp (md->packages.ptr[0]->toChars (), "core")
+ || !strcmp (md->packages.ptr[0]->toChars (), "std")
+ || !strcmp (md->packages.ptr[0]->toChars (), "gcc")
+ || !strcmp (md->packages.ptr[0]->toChars (), "etc"))
+   return false;
+   }
+  else if (!strcmp (md->id->toChars (), "object"))
+   return false;
+}
+  else if (m->ident)
+{
+  if (!strcmp (m->ident->toChars (), "object"))
+   return false;
+}
+
+  /* This import will be compiled.  */
+  if (global.params.v.verbose)
+message ("compileimport (%s)", m->srcfile.toChars ());
+
+  compiledImports.push (m);
+  return true;
 }
diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index 0dab76bbfbd5..ec2ea59938c4 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -523,6 +523,10 @@ d_handle_option (size_t scode, const char *arg, 
HOST_WIDE_INT value,
   global.params.ignoreUnsupportedPragmas = value;
   break;
 
+case OPT_finclude_imports:
+  includeImports = true;
+  break;
+
 case OPT_finvariants:
   global.params.useInvariants = value ? CHECKENABLEon : CHECKENABLEoff;
   break;
@@ -1309,6 +1313,21 @@ d_parse_file (void)
   dmd::semantic3 (m, NULL);
 }
 
+  if (includeImports)
+{
+  for (size_t i = 0; i < compiledImports.length; i++)
+   {
+ Module *m = compiledImports[i];
+ gcc_assert (m->isRoot ());
+
+ if (global.params.v.verbose)
+   message ("semantic3 %s", m->toChars ());
+
+ dmd::semantic3 (m, NULL);
+ modules.push (m);
+   }
+}
+
   Module::runDeferredSemantic3 ();
 
   /* Check again, incase semantic3 pass loaded any more modules.  */
diff --git a/gcc/d/gdc.texi b/gcc/d/gdc.texi
index 2cb0c4a62676..3a8bea01050f 100644
--- a/gcc/d/gdc.texi
+++ b/gcc/d/gdc.texi
@@ -277,6 +277,12 @@ Sets @code{__traits(getTargetInfo, "cppStd")} to 
@code{202002}.
 Sets @code{__traits(getTargetInfo, "cppStd")} to @code{202302}.
 @end table
 
+@opindex finclude-imports
+@item -finclude-imports
+Include imported modules in the compilation, as if they were given on the
+command line.  When this option is enabled, all imported modules are compiled
+except those that are part of libphobos.
+
 @opindex finvariants
 @opindex fno-invariants
 @item -fno-invariants
diff --git a/gcc/d/lang.opt b/gcc/d/lang.opt
index 50c6f2f4da4d..298ff5843ef2 100644
--- a/gcc/d/lang.opt
+++ b/gcc/d/lang.opt
@@ -327,6 +327,10 @@ fignore-unknown-pragmas
 D
 Ignore unsupported pragmas.
 
+finc

[gcc r15-9402] d: Fix -fonly= argument only matches when including full path [PR119758]

2025-04-12 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:8a03d014ec096b3e8c9941a6bf724d3daaeeb289

commit r15-9402-g8a03d014ec096b3e8c9941a6bf724d3daaeeb289
Author: Iain Buclaw 
Date:   Sat Apr 12 09:40:24 2025 +0200

d: Fix -fonly= argument only matches when including full path [PR119758]

Using `strcmp' to match the `-fonly=' argument with the input source
file made the feature inflexible to use.  By mistake, the driver was
also found to omit all other modules on the command line as well, which
differed from the documentation on the flag:

Tell the compiler to parse and run semantic analysis on all modules
on the command line, but only generate code for the given argument.

New tests added to check the feature, which didn't exist before.

PR d/119758

gcc/d/ChangeLog:

* d-lang.cc (d_parse_file): Use endswith in test for -fonly= 
argument.
* d-spec.cc (lang_specific_driver): Rework -fonly= and pass all 
input
files to the front-end compiler when the option is seen.

gcc/testsuite/ChangeLog:

* gdc.dg/driver_fonly1.d: New test.
* gdc.dg/driver_fonly2.d: New test.
* gdc.dg/driver_fonly3.d: New test.
* gdc.dg/imports/fonly.d: New test.

Diff:
---
 gcc/d/d-lang.cc  |  6 ++---
 gcc/d/d-spec.cc  | 50 +++-
 gcc/testsuite/gdc.dg/driver_fonly1.d |  2 ++
 gcc/testsuite/gdc.dg/driver_fonly2.d |  8 ++
 gcc/testsuite/gdc.dg/driver_fonly3.d |  8 ++
 gcc/testsuite/gdc.dg/imports/fonly.d |  3 +++
 6 files changed, 51 insertions(+), 26 deletions(-)

diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index b3786be3c905..0dab76bbfbd5 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -1085,9 +1085,9 @@ d_parse_file (void)
   /* Buffer for contents of .ddoc files.  */
   OutBuffer ddocbuf;
 
-  /* In this mode, the first file name is supposed to be a duplicate
- of one of the input files.  */
-  if (d_option.fonly && strcmp (d_option.fonly, main_input_filename) != 0)
+  /* In this mode, the main input file is supposed to be the same as the one
+ given by -fonly=.  */
+  if (d_option.fonly && !endswith (main_input_filename, d_option.fonly))
 error ("%<-fonly=%> argument is different from first input file name");
 
   for (size_t i = 0; i < num_in_fnames; i++)
diff --git a/gcc/d/d-spec.cc b/gcc/d/d-spec.cc
index 7f4a779ab72d..c78804812e3f 100644
--- a/gcc/d/d-spec.cc
+++ b/gcc/d/d-spec.cc
@@ -104,8 +104,8 @@ lang_specific_driver (cl_decoded_option 
**in_decoded_options,
   /* The total number of arguments with the new stuff.  */
   unsigned int num_args = 1;
 
-  /* "-fonly" if it appears on the command line.  */
-  const char *only_source_option = 0;
+  /* "-fonly=" if it appears on the command line.  */
+  const char *only_source_arg = 0;
 
   /* Whether the -o option was used.  */
   bool saw_opt_o = false;
@@ -280,13 +280,13 @@ lang_specific_driver (cl_decoded_option 
**in_decoded_options,
 
case OPT_fonly_:
  args[i] |= SKIPOPT;
- only_source_option = decoded_options[i].orig_option_with_args_text;
+ only_source_arg = arg;
 
  if (arg != NULL)
{
- const char *suffix = strrchr (only_source_option, '.');
+ const char *suffix = strrchr (only_source_arg, '.');
  if (suffix == NULL || strcmp (suffix, ".d") != 0)
-   only_source_option = concat (only_source_option, ".d", NULL);
+   only_source_arg = concat (only_source_arg, ".d", NULL);
}
  break;
 
@@ -335,48 +335,52 @@ lang_specific_driver (cl_decoded_option 
**in_decoded_options,
 + (phobos_library != PHOBOS_NOLINK) * 4 + 2;
   new_decoded_options = XNEWVEC (cl_decoded_option, num_args);
 
-  i = 0;
   j = 0;
 
   /* Copy the 0th argument, i.e., the name of the program itself.  */
-  new_decoded_options[j++] = decoded_options[i++];
+  new_decoded_options[j++] = decoded_options[0];
 
   /* NOTE: We start at 1 now, not 0.  */
-  while (i < argc)
+  for (i = 1; i < argc; i++)
 {
   if (args[i] & SKIPOPT)
-   {
- ++i;
- continue;
-   }
-
-  new_decoded_options[j] = decoded_options[i];
+   continue;
 
   if (!saw_libcxx && (args[i] & WITHLIBCXX))
{
- --j;
  saw_libcxx = &decoded_options[i];
+ continue;
}
 
-  if (args[i] & DSOURCE)
+  if (only_source_arg && (args[i] & DSOURCE))
{
- if (only_source_option)
-   --j;
+ if (!endswith (decoded_options[i].arg, only_source_arg))
+   continue;
}
 
-  i++;
+  new_decoded_options[j] = decoded_options[i];
   j++;
 }
 
-  if (only_source_option)
+  if (only_source_arg)
 {
-  const char *only_source_arg = only_source_option + 7;
+  /* Generate -fonly= option, then copy D input sources that were initially
+ski

[gcc(refs/users/ibuclaw/heads/importc)] d: Implement preprocessor for importC

2025-04-12 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:f60bb700835b8548f6f402297388589462e22f8f

commit f60bb700835b8548f6f402297388589462e22f8f
Author: Iain Buclaw 
Date:   Tue May 24 23:03:23 2022 +0200

d: Implement preprocessor for importC

gcc/ChangeLog:

* config/darwin-d.cc (darwin_register_objc_includes): New function.
(darwin_register_frameworks): New function.

gcc/d/ChangeLog:

* Make-lang.in (D_OBJS): Add d/d-preprocess.o.
* d-builtins.cc (covariant_with_builtin_type_p): Match va_list
parameters converted from array to pointer.
* d-lang.cc (d_init_options): Initialize global.preprocess and 
importC
preprocessor.
(d_handle_option): Call d_cpp_handle_option.
* d-tree.h (struct OutBuffer): Add opaque declaration.
(d_cpp_init_options): Add prototype.
(d_cpp_handle_option): Add prototype.
(d_cpp_preprocess): Add prototype.
* lang-specs.h: Forward -D and -U to compiler proper.
* lang.opt: Add -D, -U, -dirafter, -imacros, -include, and -iquote.
* d-preprocess.cc: New file.

Diff:
---
 gcc/config/darwin-d.cc |  35 +++
 gcc/d/Make-lang.in |   1 +
 gcc/d/d-builtins.cc|  12 +-
 gcc/d/d-lang.cc|  15 +-
 gcc/d/d-preprocess.cc  | 755 +
 gcc/d/d-tree.h |   7 +
 gcc/d/lang-specs.h |   2 +-
 gcc/d/lang.opt |  24 ++
 8 files changed, 848 insertions(+), 3 deletions(-)

diff --git a/gcc/config/darwin-d.cc b/gcc/config/darwin-d.cc
index e23a6cd12708..0afb3d281136 100644
--- a/gcc/config/darwin-d.cc
+++ b/gcc/config/darwin-d.cc
@@ -74,3 +74,38 @@ darwin_d_register_target_info (void)
 #define TARGET_D_MINFO_SECTION_END "*section$end$__DATA$__minfodata"
 
 struct gcc_targetdm targetdm = TARGETDM_INITIALIZER;
+
+/* Provide stubs for the hooks defined by darwin.h
+ TARGET_EXTRA_PRE_INCLUDES, TARGET_EXTRA_INCLUDES
+
+   As both, gcc and gdc link in incpath.o, we cannot conditionally undefine 
said
+   hooks if D is build.  However, we can define do-nothing stubs of said hooks
+   as we are not interested in objc include files in D.
+
+   The hooks original purpose (see also darwin-c.cc):
+* darwin_register_objc_includes
+  Register the GNU objective-C runtime include path if STDINC.
+
+* darwin_register_frameworks
+  Register all the system framework paths if STDINC is true and setup
+  the missing_header callback for subframework searching if any
+  frameworks had been registered.  */
+
+/* Prototypes for functions below to avoid a lengthy list of includes
+   to achieve the same.  */
+void darwin_register_objc_includes (const char *, const char *, int);
+void darwin_register_frameworks (const char *, const char *, int);
+
+void
+darwin_register_objc_includes (const char *sysroot ATTRIBUTE_UNUSED,
+  const char *iprefix ATTRIBUTE_UNUSED,
+  int stdinc ATTRIBUTE_UNUSED)
+{
+}
+
+void
+darwin_register_frameworks (const char *sysroot ATTRIBUTE_UNUSED,
+   const char *iprefix ATTRIBUTE_UNUSED,
+   int stdinc ATTRIBUTE_UNUSED)
+{
+}
diff --git a/gcc/d/Make-lang.in b/gcc/d/Make-lang.in
index 2d444c999530..0292f6e4ccf2 100644
--- a/gcc/d/Make-lang.in
+++ b/gcc/d/Make-lang.in
@@ -225,6 +225,7 @@ D_OBJS = \
d/d-lang.o \
d/d-longdouble.o \
d/d-port.o \
+   d/d-preprocess.o \
d/d-target.o \
d/decl.o \
d/expr.o \
diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index 9c146459d574..1ed0f0577236 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -758,7 +758,17 @@ covariant_with_builtin_type_p (Type *t1, Type *t2)
  || fparam1->isLazy () != fparam2->isLazy ())
return false;
 
-  if (!matches_builtin_type (fparam1->type, fparam2->type))
+  /* va_list array parameters are implicitly converted to pointers.  */
+  Type *fptype1 = fparam1->type;
+  Type *fptype2 = fparam2->type;
+
+  if (valist_array_p (fptype1))
+   fptype1 = dmd::pointerTo (fptype1->nextOf ());
+
+  if (valist_array_p (fptype2))
+   fptype2 = dmd::pointerTo (fptype2->nextOf ());
+
+  if (!matches_builtin_type (fptype1, fptype2))
return false;
 }
 
diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index ec2ea59938c4..b88748d547e6 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -285,7 +285,8 @@ deps_write (Module *module, obstack *buffer)
the option handlers.  */
 
 static void
-d_init_options (unsigned int, cl_decoded_option *decoded_options)
+d_init_options (unsigned int decoded_options_count,
+   cl_decoded_option *decoded_options)
 {
   /* Initialize the D runtime.  */
   rt_init ();
@@ -300,6 +301,8 @@ d_init_options (unsigned int, cl_decoded_option 
*decoded_options)
   /* Default extern(C++) mangling to C++17.  */
   global.params.cp

[gcc] Created branch 'ibuclaw/heads/importc' in namespace 'refs/users'

2025-04-12 Thread Iain Buclaw via Gcc-cvs
The branch 'ibuclaw/heads/importc' was created in namespace 'refs/users' 
pointing to:

 f60bb700835b... d: Implement preprocessor for importC


[gcc(refs/users/ibuclaw/heads/gdcflags)] Makefile.tpl: Implement per-stage GDCFLAGS [PR116975]

2025-04-12 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:714e6e3450715b98a2c35b317f99b20916e7de49

commit 714e6e3450715b98a2c35b317f99b20916e7de49
Author: Iain Buclaw 
Date:   Mon Mar 3 22:38:26 2025 +0100

Makefile.tpl: Implement per-stage GDCFLAGS [PR116975]

Allows the GDCFLAGS for each bootstrap stage of building gdc to be
overriden, as is the case with CXXFLAGS for other front-ends.

PR d/116975

ChangeLog:

* Makefile.in: Regenerate.
* Makefile.tpl (STAGE[+id+]_GDCFLAGS): New.
(STAGE2_GDCFLAGS): Add -fno-checking.
(STAGE3_GDCFLAGS): Add -fchecking=1.
(BASE_FLAGS_TO_PASS): Pass STAGE[+id+]_GDCFLAGS down.
(configure-stage[+id+]-[+prefix+][+module+]): Set GDCFLAGS for all 
gcc
module stages.
(all-stage[+id+]-[+prefix+][+module+]): Likewise.

Diff:
---
 Makefile.in  | 51 +++
 Makefile.tpl | 15 +--
 2 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 87880c62ad20..f2c632c06b38 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -619,6 +619,26 @@ STAGE1_CONFIGURE_FLAGS = $(STAGE1_CHECKING) \
  --disable-build-format-warnings
 
 @if target-libphobos-bootstrap
+# Defaults for each stage if we're bootstrapping D.
+
+STAGE1_GDCFLAGS = $(GDCFLAGS)
+
+STAGE2_GDCFLAGS = $(GDCFLAGS)
+
+STAGE3_GDCFLAGS = $(GDCFLAGS)
+
+STAGE4_GDCFLAGS = $(GDCFLAGS)
+
+STAGEprofile_GDCFLAGS = $(GDCFLAGS)
+
+STAGEtrain_GDCFLAGS = $(GDCFLAGS)
+
+STAGEfeedback_GDCFLAGS = $(GDCFLAGS)
+
+STAGEautoprofile_GDCFLAGS = $(GDCFLAGS)
+
+STAGEautofeedback_GDCFLAGS = $(GDCFLAGS)
+
 STAGE1_CONFIGURE_FLAGS += --with-libphobos-druntime-only
 STAGE2_CONFIGURE_FLAGS += --with-libphobos-druntime-only
 @endif target-libphobos-bootstrap
@@ -632,6 +652,10 @@ STAGE2_CFLAGS += -fno-checking
 STAGE2_TFLAGS += -fno-checking
 STAGE3_CFLAGS += -fchecking=1
 STAGE3_TFLAGS += -fchecking=1
+@if target-libphobos-bootstrap
+STAGE2_GDCFLAGS += -fno-checking
+STAGE3_GDCFLAGS += -fchecking=1
+@endif target-libphobos-bootstrap
 
 STAGEprofile_CFLAGS = $(STAGE2_CFLAGS) -fprofile-generate
 STAGEprofile_TFLAGS = $(STAGE2_TFLAGS)
@@ -921,38 +945,47 @@ BASE_FLAGS_TO_PASS = \
"LEAN=$(LEAN)" \
"STAGE1_CFLAGS=$(STAGE1_CFLAGS)" \
"STAGE1_CXXFLAGS=$(STAGE1_CXXFLAGS)" \
+   "STAGE1_GDCFLAGS=$(STAGE1_GDCFLAGS)" \
"STAGE1_GENERATOR_CFLAGS=$(STAGE1_GENERATOR_CFLAGS)" \
"STAGE1_TFLAGS=$(STAGE1_TFLAGS)" \
"STAGE2_CFLAGS=$(STAGE2_CFLAGS)" \
"STAGE2_CXXFLAGS=$(STAGE2_CXXFLAGS)" \
+   "STAGE2_GDCFLAGS=$(STAGE2_GDCFLAGS)" \
"STAGE2_GENERATOR_CFLAGS=$(STAGE2_GENERATOR_CFLAGS)" \
"STAGE2_TFLAGS=$(STAGE2_TFLAGS)" \
"STAGE3_CFLAGS=$(STAGE3_CFLAGS)" \
"STAGE3_CXXFLAGS=$(STAGE3_CXXFLAGS)" \
+   "STAGE3_GDCFLAGS=$(STAGE3_GDCFLAGS)" \
"STAGE3_GENERATOR_CFLAGS=$(STAGE3_GENERATOR_CFLAGS)" \
"STAGE3_TFLAGS=$(STAGE3_TFLAGS)" \
"STAGE4_CFLAGS=$(STAGE4_CFLAGS)" \
"STAGE4_CXXFLAGS=$(STAGE4_CXXFLAGS)" \
+   "STAGE4_GDCFLAGS=$(STAGE4_GDCFLAGS)" \
"STAGE4_GENERATOR_CFLAGS=$(STAGE4_GENERATOR_CFLAGS)" \
"STAGE4_TFLAGS=$(STAGE4_TFLAGS)" \
"STAGEprofile_CFLAGS=$(STAGEprofile_CFLAGS)" \
"STAGEprofile_CXXFLAGS=$(STAGEprofile_CXXFLAGS)" \
+   "STAGEprofile_GDCFLAGS=$(STAGEprofile_GDCFLAGS)" \
"STAGEprofile_GENERATOR_CFLAGS=$(STAGEprofile_GENERATOR_CFLAGS)" \
"STAGEprofile_TFLAGS=$(STAGEprofile_TFLAGS)" \
"STAGEtrain_CFLAGS=$(STAGEtrain_CFLAGS)" \
"STAGEtrain_CXXFLAGS=$(STAGEtrain_CXXFLAGS)" \
+   "STAGEtrain_GDCFLAGS=$(STAGEtrain_GDCFLAGS)" \
"STAGEtrain_GENERATOR_CFLAGS=$(STAGEtrain_GENERATOR_CFLAGS)" \
"STAGEtrain_TFLAGS=$(STAGEtrain_TFLAGS)" \
"STAGEfeedback_CFLAGS=$(STAGEfeedback_CFLAGS)" \
"STAGEfeedback_CXXFLAGS=$(STAGEfeedback_CXXFLAGS)" \
+   "STAGEfeedback_GDCFLAGS=$(STAGEfeedback_GDCFLAGS)" \
"STAGEfeedback_GENERATOR_CFLAGS=$(STAGEfeedback_GENERATOR_CFLAGS)" \
"STAGEfeedback_TFLAGS=$(STAGEfeedback_TFLAGS)" \
"STAGEautoprofile_CFLAGS=$(STAGEautoprofile_CFLAGS)" \
"STAGEautoprofile_CXXFLAGS=$(STAGEautoprofile_CXXFLAGS)" \
+   "STAGEautoprofile_GDCFLAGS=$(STAGEautoprofile_GDCFLAGS)" \

"STAGEautoprofile_GENERATOR_CFLAGS=$(STAGEautoprofile_GENERATOR_CFLAGS)" \
"STAGEautoprofile_TFLAGS=$(STAGEautoprofile_TFLAGS)" \
"STAGEautofeedback_CFLAGS=$(STAGEautofeedback_CFLAGS)" \
"STAGEautofeedback_CXXFLAGS=$(STAGEautofeedback_CXXFLAGS)" \
+   "STAGEautofeedback_GDCFLAGS=$(STAGEautofeedback_GDCFLAGS)" \

"STAGEautofeedback_GENERATOR_CFLAGS=$(STAGEautofeedback_GENERATOR_CFLAGS)" \
"STAGEautofeedback_TFLAGS=$(STAGEautofeedback_TFLAGS)" \
$(CXX_FOR_TARGET_FLAG_TO_PASS) \
@@ -12133,6 +12166,7 @@ configure-stage1-gcc:
$(HOST_EXPORTS) \
CFLAGS="$(STAGE1_CFLAGS)"; expo

[gcc] Created branch 'ibuclaw/heads/gdcflags' in namespace 'refs/users'

2025-04-12 Thread Iain Buclaw via Gcc-cvs
The branch 'ibuclaw/heads/gdcflags' was created in namespace 'refs/users' 
pointing to:

 714e6e345071... Makefile.tpl: Implement per-stage GDCFLAGS [PR116975]


[gcc(refs/users/ibuclaw/heads/gdc)] d: testsuite: Update documentation about subdirectories of gdc.dg

2025-04-12 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:9b711cfef2270e74fa81aec4b0bce509ded800f6

commit 9b711cfef2270e74fa81aec4b0bce509ded800f6
Author: Iain Buclaw 
Date:   Fri Jan 31 10:16:50 2025 +0100

d: testsuite: Update documentation about subdirectories of gdc.dg

gcc/testsuite/ChangeLog:

* gdc.test/README.gcc: Update.
* gdc.dg/README: New file.

Diff:
---
 gcc/testsuite/gdc.dg/README   | 20 
 gcc/testsuite/gdc.test/README.gcc |  1 +
 2 files changed, 21 insertions(+)

diff --git a/gcc/testsuite/gdc.dg/README b/gcc/testsuite/gdc.dg/README
new file mode 100644
index ..55ccc3efa318
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/README
@@ -0,0 +1,20 @@
+The tests in testsuite/gdc.dg are for checking options, code generation and PRs
+specific to the D front-end.
+
+Subdirectories:
+
+analyzerTests for AddressSanitizer support.
+asanTests for analyzer support.
+debug   Tests for debugging options.
+extern-c++  Tests for ABI compatibility with C++.
+gcovTests for GCOV (code coverage) support.
+lto Tests for Link Time Optimization.
+torture Tests for code generation at all optimization levels.
+ubsan   Tests for UndefinedBehaviorSanitizer support.
+
+
+Copyright (C) 2025 Free Software Foundation, Inc.
+
+Copying and distribution of this file, with or without modification,
+are permitted in any medium without royalty provided the copyright
+notice and this notice are preserved.
diff --git a/gcc/testsuite/gdc.test/README.gcc 
b/gcc/testsuite/gdc.test/README.gcc
index 984da5e3a571..de191f703eb9 100644
--- a/gcc/testsuite/gdc.test/README.gcc
+++ b/gcc/testsuite/gdc.test/README.gcc
@@ -9,6 +9,7 @@ The following directories are part of DMD:
   compilable/
   fail_compilation/
   runnable/
+  runnable_cxx/
 
 All changes to dmd should go through the upstream repository first,
 then merged back to GCC.


[gcc r15-9404] d: Fix importC cannot find input file __importc_builtins.d [PR119761]

2025-04-12 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:424c6c88038ef13364e6e7e74e2389923d95396e

commit r15-9404-g424c6c88038ef13364e6e7e74e2389923d95396e
Author: Iain Buclaw 
Date:   Sun Apr 13 00:48:45 2025 +0200

d: Fix importC cannot find input file __importc_builtins.d [PR119761]

Synchronizes the D runtime library with upstream druntime 09ed02ce56,
and fixes a rename of the importC module missed in the r15-6559 merge.

PR d/119761

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 09ed02ce56.
* libdruntime/Makefile.am (DRUNTIME_DISOURCES): Rename __builtins.di
to __importc_builtins.di.
* libdruntime/Makefile.in: Regenerate.
* libdruntime/__builtins.di: Move to...
* libdruntime/__importc_builtins.di: ...here.

gcc/testsuite/ChangeLog:

* gdc.dg/import-c/import-c.exp: New test.
* gdc.dg/import-c/pr119761.d: New test.
* gdc.dg/import-c/pr119761c.c: New test.

Diff:
---
 gcc/testsuite/gdc.dg/import-c/import-c.exp | 29 ++
 gcc/testsuite/gdc.dg/import-c/pr119761.d   |  2 ++
 gcc/testsuite/gdc.dg/import-c/pr119761c.c  |  4 +++
 libphobos/libdruntime/MERGE|  2 +-
 libphobos/libdruntime/Makefile.am  |  2 +-
 libphobos/libdruntime/Makefile.in  |  2 +-
 .../{__builtins.di => __importc_builtins.di}   | 10 ++--
 7 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gdc.dg/import-c/import-c.exp 
b/gcc/testsuite/gdc.dg/import-c/import-c.exp
new file mode 100644
index ..53d1478d071b
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/import-c/import-c.exp
@@ -0,0 +1,29 @@
+#   Copyright (C) 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# .
+
+# Load support procs.
+load_lib gdc-dg.exp
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+gdc-dg-runtest [lsort \
+   [glob -nocomplain $srcdir/$subdir/*.d ] ] "" \
+   "-I $srcdir/$subdir -finclude-imports"
+
+# All done.
+dg-finish
diff --git a/gcc/testsuite/gdc.dg/import-c/pr119761.d 
b/gcc/testsuite/gdc.dg/import-c/pr119761.d
new file mode 100644
index ..20eff314a83d
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/import-c/pr119761.d
@@ -0,0 +1,2 @@
+// { dg-do compile }
+import pr119761c;
diff --git a/gcc/testsuite/gdc.dg/import-c/pr119761c.c 
b/gcc/testsuite/gdc.dg/import-c/pr119761c.c
new file mode 100644
index ..522f1bf9bf84
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/import-c/pr119761c.c
@@ -0,0 +1,4 @@
+int f119761(const char *, ...)
+{
+  return 0;
+}
diff --git a/libphobos/libdruntime/MERGE b/libphobos/libdruntime/MERGE
index 00c85187b6de..840f8dd4f9d9 100644
--- a/libphobos/libdruntime/MERGE
+++ b/libphobos/libdruntime/MERGE
@@ -1,4 +1,4 @@
-c6863be7206eef3c393726363a480baf0a0c6530
+09ed02ce56ea5bf3e59f21ee0390cd85eb8bfaa7
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
diff --git a/libphobos/libdruntime/Makefile.am 
b/libphobos/libdruntime/Makefile.am
index 9adb5034b088..4098310888fe 100644
--- a/libphobos/libdruntime/Makefile.am
+++ b/libphobos/libdruntime/Makefile.am
@@ -445,4 +445,4 @@ DRUNTIME_DSOURCES_WINDOWS = core/sys/windows/accctrl.d \
core/sys/windows/winuser.d core/sys/windows/winver.d \
core/sys/windows/wtsapi32.d core/sys/windows/wtypes.d
 
-DRUNTIME_DISOURCES = __builtins.di __main.di
+DRUNTIME_DISOURCES = __importc_builtins.di __main.di
diff --git a/libphobos/libdruntime/Makefile.in 
b/libphobos/libdruntime/Makefile.in
index 8f8072c6dc9e..1c0fa546dbbf 100644
--- a/libphobos/libdruntime/Makefile.in
+++ b/libphobos/libdruntime/Makefile.in
@@ -1126,7 +1126,7 @@ DRUNTIME_DSOURCES_WINDOWS = core/sys/windows/accctrl.d \
core/sys/windows/winuser.d core/sys/windows/winver.d \
core/sys/windows/wtsapi32.d core/sys/windows/wtypes.d
 
-DRUNTIME_DISOURCES = __builtins.di __main.di
+DRUNTIME_DISOURCES = __importc_builtins.di __main.di
 all: all-am
 
 .SUFFIXES:
diff --git a/libphobos/libdruntime/__builtins.di 
b/libphobos/libdruntime/__importc_builtins.di
similarity index 93%
rename from libphobos/libdruntime/__builtins.di
rename to libphobos/libdruntime/__importc_builtins.di
index b4fef091b5f4..9493962e4689 100644
--- a/libphobo

[gcc r15-9485] d: Fix internal compiler error: in visit, at d/decl.cc:838 [PR119799]

2025-04-15 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:074b2b0f91f948fe3488ada91ec6a8576c684dea

commit r15-9485-g074b2b0f91f948fe3488ada91ec6a8576c684dea
Author: Iain Buclaw 
Date:   Tue Apr 15 15:19:13 2025 +0200

d: Fix internal compiler error: in visit, at d/decl.cc:838 [PR119799]

This was caused by a check in the D front-end disallowing static
VAR_DECLs with a size `0'.

While empty structs in D are give the size `1', the same symbol coming
from ImportC modules do infact have no size, so allow C variables to
pass the check as well as array objects.

PR d/119799

gcc/d/ChangeLog:

* decl.cc (DeclVisitor::visit (VarDeclaration *)): Check front-end
type size before building the VAR_DECL.  Allow C symbols to have a
size of `0'.

gcc/testsuite/ChangeLog:

* gdc.dg/import-c/pr119799.d: New test.
* gdc.dg/import-c/pr119799c.c: New test.

Diff:
---
 gcc/d/decl.cc | 15 ++-
 gcc/testsuite/gdc.dg/import-c/pr119799.d  |  2 ++
 gcc/testsuite/gdc.dg/import-c/pr119799c.c |  1 +
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 136f78b32ff0..9ddf7cf1540c 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -791,6 +791,12 @@ public:
   }
 else if (d->isDataseg ())
   {
+   /* When the front-end type size is invalid, an error has already been
+  given for the declaration or type.  */
+   dinteger_t size = dmd::size (d->type, d->loc);
+   if (size == SIZE_INVALID)
+ return;
+
tree decl = get_symbol_decl (d);
 
/* Only need to build the VAR_DECL for extern declarations.  */
@@ -804,9 +810,7 @@ public:
  return;
 
/* How big a symbol can be should depend on back-end.  */
-   tree size = build_integer_cst (dmd::size (d->type, d->loc),
-  build_ctype (Type::tsize_t));
-   if (!valid_constant_size_p (size))
+   if (!valid_constant_size_p (build_integer_cst (size, size_type_node)))
  {
error_at (make_location_t (d->loc), "size is too large");
return;
@@ -835,8 +839,9 @@ public:
  }
 
/* Frontend should have already caught this.  */
-   gcc_assert (!integer_zerop (size)
-   || d->type->toBasetype ()->isTypeSArray ());
+   gcc_assert ((size != 0 && size != SIZE_INVALID)
+   || d->type->toBasetype ()->isTypeSArray ()
+   || d->isCsymbol ());
 
d_finish_decl (decl);
 
diff --git a/gcc/testsuite/gdc.dg/import-c/pr119799.d 
b/gcc/testsuite/gdc.dg/import-c/pr119799.d
new file mode 100644
index ..d8b0fa22fe1f
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/import-c/pr119799.d
@@ -0,0 +1,2 @@
+// { dg-do compile }
+import pr119799c;
diff --git a/gcc/testsuite/gdc.dg/import-c/pr119799c.c 
b/gcc/testsuite/gdc.dg/import-c/pr119799c.c
new file mode 100644
index ..b80e856f75f7
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/import-c/pr119799c.c
@@ -0,0 +1 @@
+static struct {} s119799;


[gcc r15-9483] d: Fix ICE in dwarf2out_imported_module_or_decl, at dwarf2out.cc:27676 [PR119817]

2025-04-15 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:f5ed7d19c965de9ccb158d77e929b17459bf65b5

commit r15-9483-gf5ed7d19c965de9ccb158d77e929b17459bf65b5
Author: Iain Buclaw 
Date:   Tue Apr 15 14:49:34 2025 +0200

d: Fix ICE in dwarf2out_imported_module_or_decl, at dwarf2out.cc:27676 
[PR119817]

The ImportVisitor method for handling the importing of overload sets was
pushing NULL_TREE to the array of import decls, which in turn got passed
to `debug_hooks->imported_module_or_decl', triggering the observed
internal compiler error.

NULL_TREE is returned from `build_import_decl' when the symbol was
ignored for being non-trivial to represent in debug, for example,
template or tuple declarations.  So similarly "skip" adding the symbol
when this is the case for overload sets too.

PR d/119817

gcc/d/ChangeLog:

* imports.cc (ImportVisitor::visit (OverloadSet *)): Don't push
NULL_TREE to vector of import symbols.

gcc/testsuite/ChangeLog:

* gdc.dg/debug/imports/m119817/a.d: New test.
* gdc.dg/debug/imports/m119817/b.d: New test.
* gdc.dg/debug/imports/m119817/package.d: New test.
* gdc.dg/debug/pr119817.d: New test.

Diff:
---
 gcc/d/imports.cc | 6 +-
 gcc/testsuite/gdc.dg/debug/imports/m119817/a.d   | 2 ++
 gcc/testsuite/gdc.dg/debug/imports/m119817/b.d   | 2 ++
 gcc/testsuite/gdc.dg/debug/imports/m119817/package.d | 4 
 gcc/testsuite/gdc.dg/debug/pr119817.d| 6 ++
 5 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/gcc/d/imports.cc b/gcc/d/imports.cc
index 776caafd25ca..16e4df69d656 100644
--- a/gcc/d/imports.cc
+++ b/gcc/d/imports.cc
@@ -182,7 +182,11 @@ public:
 vec_alloc (tset, d->a.length);
 
 for (size_t i = 0; i < d->a.length; i++)
-  vec_safe_push (tset, build_import_decl (d->a[i]));
+  {
+   tree overload = build_import_decl (d->a[i]);
+   if (overload != NULL_TREE)
+ vec_safe_push (tset, overload);
+  }
 
 this->result_ = build_tree_list_vec (tset);
 tset->truncate (0);
diff --git a/gcc/testsuite/gdc.dg/debug/imports/m119817/a.d 
b/gcc/testsuite/gdc.dg/debug/imports/m119817/a.d
new file mode 100644
index ..a13747240c43
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/m119817/a.d
@@ -0,0 +1,2 @@
+module imports.m119817.a;
+void f119817()() { }
diff --git a/gcc/testsuite/gdc.dg/debug/imports/m119817/b.d 
b/gcc/testsuite/gdc.dg/debug/imports/m119817/b.d
new file mode 100644
index ..aef0e373ca6e
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/m119817/b.d
@@ -0,0 +1,2 @@
+module imports.m119817.b;
+void f119817() { }
diff --git a/gcc/testsuite/gdc.dg/debug/imports/m119817/package.d 
b/gcc/testsuite/gdc.dg/debug/imports/m119817/package.d
new file mode 100644
index ..188827e669f5
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/m119817/package.d
@@ -0,0 +1,4 @@
+module imports.m119817;
+public import
+imports.m119817.a,
+imports.m119817.b;
diff --git a/gcc/testsuite/gdc.dg/debug/pr119817.d 
b/gcc/testsuite/gdc.dg/debug/pr119817.d
new file mode 100644
index ..3eea6ba9a906
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/pr119817.d
@@ -0,0 +1,6 @@
+// { dg-do compile }
+// { dg-additional-sources "imports/m119817/package.d" }
+// { dg-additional-sources "imports/m119817/a.d" }
+// { dg-additional-sources "imports/m119817/b.d" }
+module pr119817;
+import imports.m119817 : f119817;


[gcc r15-9509] d: Fix ICE: type variant differs by TYPE_MAX_VALUE with -g [PR119826]

2025-04-15 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:c5ffab99a5a962aa955310e74ca0a4be5c1acf30

commit r15-9509-gc5ffab99a5a962aa955310e74ca0a4be5c1acf30
Author: Iain Buclaw 
Date:   Wed Apr 16 01:28:53 2025 +0200

d: Fix ICE: type variant differs by TYPE_MAX_VALUE with -g [PR119826]

Forward referenced enum types were never fixed up after the main
ENUMERAL_TYPE was finished.  All flags set are now propagated to all
variants after its mode, size, and alignment has been calculated.

PR d/119826

gcc/d/ChangeLog:

* types.cc (TypeVisitor::visit (TypeEnum *)): Propagate flags of 
main
enum types to all forward-referenced variants.

gcc/testsuite/ChangeLog:

* gdc.dg/debug/imports/pr119826b.d: New test.
* gdc.dg/debug/pr119826.d: New test.

Diff:
---
 gcc/d/types.cc | 20 
 gcc/testsuite/gdc.dg/debug/imports/pr119826b.d | 14 ++
 gcc/testsuite/gdc.dg/debug/pr119826.d  |  8 
 3 files changed, 42 insertions(+)

diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index e43fa88a5d4c..1c74840605b4 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -1179,6 +1179,26 @@ public:
 
layout_type (t->ctype);
 
+   /* Fix up all forward-referenced variants of this enum type.  */
+   for (tree v = TYPE_MAIN_VARIANT (t->ctype); v;
+v = TYPE_NEXT_VARIANT (v))
+ {
+   if (v == t->ctype)
+ continue;
+
+   TYPE_VALUES (v) = TYPE_VALUES (t->ctype);
+   TYPE_LANG_SPECIFIC (v) = TYPE_LANG_SPECIFIC (t->ctype);
+   TYPE_MIN_VALUE (v) = TYPE_MIN_VALUE (t->ctype);
+   TYPE_MAX_VALUE (v) = TYPE_MAX_VALUE (t->ctype);
+   TYPE_UNSIGNED (v) = TYPE_UNSIGNED (t->ctype);
+   TYPE_SIZE (v) = TYPE_SIZE (t->ctype);
+   TYPE_SIZE_UNIT (v) = TYPE_SIZE_UNIT (t->ctype);
+   SET_TYPE_MODE (v, TYPE_MODE (t->ctype));
+   TYPE_PRECISION (v) = TYPE_PRECISION (t->ctype);
+   SET_TYPE_ALIGN (v, TYPE_ALIGN (t->ctype));
+   TYPE_USER_ALIGN (v) = TYPE_USER_ALIGN (t->ctype);
+ }
+
/* Complete forward-referenced fields of this enum type.  */
finish_incomplete_fields (t->ctype);
   }
diff --git a/gcc/testsuite/gdc.dg/debug/imports/pr119826b.d 
b/gcc/testsuite/gdc.dg/debug/imports/pr119826b.d
new file mode 100644
index ..3c5a6acbb877
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/pr119826b.d
@@ -0,0 +1,14 @@
+module imports.pr119826b;
+
+import pr119826 : t119826;
+
+class C119826
+{
+enum E119826 { Evalue }
+const E119826 em = void;
+}
+
+void f119826(C119826 c)
+{
+t119826(c.em);
+}
diff --git a/gcc/testsuite/gdc.dg/debug/pr119826.d 
b/gcc/testsuite/gdc.dg/debug/pr119826.d
new file mode 100644
index ..2fb98c7ba9df
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/pr119826.d
@@ -0,0 +1,8 @@
+// { dg-do compile }
+// { dg-additional-sources "imports/pr119826b.d" }
+module pr119826;
+
+int t119826(A)(A args)
+{
+assert(false);
+}


[gcc r16-289] d: Use __builtin_clear_padding for zeroing alignment holes after set

2025-04-29 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:692b6470706090a09e30232d7eab74151a509243

commit r16-289-g692b6470706090a09e30232d7eab74151a509243
Author: Iain Buclaw 
Date:   Tue Apr 29 21:43:41 2025 +0200

d: Use __builtin_clear_padding for zeroing alignment holes after set

In an earlier change, a wrapper function was added to set
CONSTRUCTOR_ZERO_PADDING_BITS on all CONSTRUCTOR nodes. This removes all
the old generated calls to built-in memset and memcpy as zero padding is
now taken care of by the middle-end.

The remaining constructors that weren't getting zero padded was
ARRAY_TYPEs, so now `__builtin_clear_padding' is used to fill in all
alignment holes in constructed array literals where required.

PR d/103044

gcc/d/ChangeLog:

* d-tree.h (build_clear_padding_call): New prototype.
* d-codegen.cc (build_clear_padding_call): New function.
(build_memset_call): Remove generated call to __builtin_memcpy.
(build_address): Replace generated call to __builtin_memset with
__builtin_clear_padding.
(build_array_from_exprs): Likewise.
* expr.cc (ExprVisitor::visit (AssignExp *)): Remove generated call 
to
__builtin_memset.
(ExprVisitor::visit (ArrayLiteralExp *)): Likewise.  Insert call to
__builtin_clear_padding after copying array into GC memory.
(ExprVisitor::visit (StructLiteralExp *)): Remove generated call to
__builtin_memset.
* toir.cc (IRVisitor::visit (ReturnStatement *)): Likewise.

Diff:
---
 gcc/d/d-codegen.cc | 41 -
 gcc/d/d-tree.h |  1 +
 gcc/d/expr.cc  | 53 +
 gcc/d/toir.cc  |  5 -
 4 files changed, 30 insertions(+), 70 deletions(-)

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 1a7575aac22c..e35f75af5843 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -717,10 +717,11 @@ build_address (tree exp)
   if (AGGREGATE_TYPE_P (TREE_TYPE (exp))
  && !aggregate_value_p (TREE_TYPE (exp), exp))
{
- tree tmp = build_local_temp (TREE_TYPE (exp));
- init = compound_expr (init, build_memset_call (tmp));
- init = compound_expr (init, modify_expr (tmp, exp));
- exp = tmp;
+ tree target = force_target_expr (exp);
+ tree ptr = build_address (TARGET_EXPR_SLOT (target));
+ init = compound_expr (init, target);
+ init = compound_expr (init, build_clear_padding_call (ptr));
+ exp = TARGET_EXPR_SLOT (target);
}
   else
exp = force_target_expr (exp);
@@ -891,17 +892,13 @@ build_memset_call (tree ptr, tree num)
 }
 
   /* Use a zero constant to fill the destination if setting the entire object.
- For CONSTRUCTORs, the memcpy() is lowered to a ref-all pointer assignment,
- which can then be merged with other stores to the object.  */
+ For CONSTRUCTORs, also set CONSTRUCTOR_ZERO_PADDING_BITS.  */
   tree valtype = TREE_TYPE (TREE_TYPE (ptr));
   if (tree_int_cst_equal (TYPE_SIZE_UNIT (valtype), num))
 {
   tree cst = build_zero_cst (valtype);
   if (TREE_CODE (cst) == CONSTRUCTOR)
-   {
- CONSTRUCTOR_ZERO_PADDING_BITS (cst) = 1;
- return build_memcpy_call (ptr, build_address (cst), num);
-   }
+   CONSTRUCTOR_ZERO_PADDING_BITS (cst) = 1;
 
   return modify_expr (build_deref (ptr), cst);
 }
@@ -910,6 +907,18 @@ build_memset_call (tree ptr, tree num)
  ptr, integer_zero_node, num);
 }
 
+/* Build a call to built-in clear_padding(),  clears padding bits inside of the
+   object representation of object pointed by PTR.  */
+
+tree
+build_clear_padding_call (tree ptr)
+{
+  gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr)));
+
+  return build_call_expr (builtin_decl_explicit (BUILT_IN_CLEAR_PADDING), 1,
+ ptr);
+}
+
 /* Return TRUE if the struct SD is suitable for comparison using memcmp.
This is because we don't guarantee that padding is zero-initialized for
a stack variable, so we can't use memcmp to compare struct values.  */
@@ -1893,15 +1902,13 @@ build_array_from_exprs (Type *type, Expressions *exps, 
bool const_p)
   /* Create a new temporary to store the array.  */
   tree var = build_local_temp (satype);
 
-  /* Fill any alignment holes with zeroes.  */
-  TypeStruct *ts = etype->baseElemOf ()->isTypeStruct ();
-  tree init = NULL;
-  if (ts && (!identity_compare_p (ts->sym) || ts->sym->isUnionDeclaration ()))
-init = build_memset_call (var);
-
   /* Initialize the temporary.  */
   tree assign = modify_expr (var, build_padded_constructor (satype, elms));
-  return compound_expr (compound_expr (init, assign), var);
+
+  /* Fill any alignment holes with zeroes.  */
+  tree clear_padding = build_clear_padding_call (build_address (var));
+
+  return compound_expr (compo

[gcc r14-11370] d: Fix comparing uninitialized memory in dstruct.d [PR116961]

2025-03-02 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:04b5c8b90cd95611d99684282cc321f06a0b49c2

commit r14-11370-g04b5c8b90cd95611d99684282cc321f06a0b49c2
Author: Iain Buclaw 
Date:   Fri Feb 28 19:22:36 2025 +0100

d: Fix comparing uninitialized memory in dstruct.d [PR116961]

Floating-point emulation in the D front-end is done via a type named
`struct longdouble`, which in GDC is a small interface around the
real_value type. Because the D code cannot include gcc/real.h directly,
a big enough buffer is used for the data instead.

On x86_64, this buffer is actually bigger than real_value itself, so
when a new longdouble object is created with

longdouble r;
real_from_string3 (&r.rv (), buffer, mode);
return r;

there is uninitialized padding at the end of `r`.  This was never a
problem when D was implemented in C++ (until GCC 12) as comparing two
longdouble objects with `==' would be forwarded to the relevant
operator== overload that extracted the underlying real_value.

However when the front-end was translated to D, such conditions were
instead rewritten into identity comparisons

return exp.toReal() is CTFloat.zero

The `is` operator gets lowered as a call to `memcmp() == 0', which is
where the read of uninitialized memory occurs, as seen by valgrind.

==26778== Conditional jump or move depends on uninitialised value(s)
==26778==at 0x911F41: 
dmd.dstruct._isZeroInit(dmd.expression.Expression) (dstruct.d:635)
==26778==by 0x9123BE: StructDeclaration::finalizeSize() (dstruct.d:373)
==26778==by 0x86747C: 
dmd.aggregate.AggregateDeclaration.determineSize(ref const(dmd.location.Loc)) 
(aggregate.d:226)
[...]

To avoid accidentally reading uninitialized data, explicitly initialize
all `longdouble` variables with an empty constructor on C++ side of the
implementation before initializing underlying real_value type it holds.

PR d/116961

gcc/d/ChangeLog:

* d-codegen.cc (build_float_cst): Change new_value type from real_t 
to
real_value.
* d-ctfloat.cc (CTFloat::fabs): Default initialize the return value.
(CTFloat::ldexp): Likewise.
(CTFloat::parse): Likewise.
* d-longdouble.cc (longdouble::add): Likewise.
(longdouble::sub): Likewise.
(longdouble::mul): Likewise.
(longdouble::div): Likewise.
(longdouble::mod): Likewise.
(longdouble::neg): Likewise.
* d-port.cc (Port::isFloat32LiteralOutOfRange): Likewise.
(Port::isFloat64LiteralOutOfRange): Likewise.

gcc/testsuite/ChangeLog:

* gdc.dg/pr116961.d: New test.

(cherry picked from commit f7bc17ebc9ef89700672ed7125da719f3558f3b7)

Diff:
---
 gcc/d/d-codegen.cc  |  6 +++---
 gcc/d/d-ctfloat.cc  |  6 +++---
 gcc/d/d-longdouble.cc   | 12 ++--
 gcc/d/d-port.cc |  4 ++--
 gcc/testsuite/gdc.dg/pr116961.d |  7 +++
 5 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 2b3089b5f6dd..3b616930fe01 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -246,15 +246,15 @@ build_integer_cst (dinteger_t value, tree type)
 tree
 build_float_cst (const real_t &value, Type *totype)
 {
-  real_t new_value;
+  real_value new_value;
   TypeBasic *tb = totype->isTypeBasic ();
 
   gcc_assert (tb != NULL);
 
   tree type_node = build_ctype (tb);
-  real_convert (&new_value.rv (), TYPE_MODE (type_node), &value.rv ());
+  real_convert (&new_value, TYPE_MODE (type_node), &value.rv ());
 
-  return build_real (type_node, new_value.rv ());
+  return build_real (type_node, new_value);
 }
 
 /* Returns the .length component from the D dynamic array EXP.  */
diff --git a/gcc/d/d-ctfloat.cc b/gcc/d/d-ctfloat.cc
index e77365ad0484..2393c47bbbf6 100644
--- a/gcc/d/d-ctfloat.cc
+++ b/gcc/d/d-ctfloat.cc
@@ -33,7 +33,7 @@ along with GCC; see the file COPYING3.  If not see
 real_t
 CTFloat::fabs (real_t r)
 {
-  real_t x;
+  real_t x = {};
   real_arithmetic (&x.rv (), ABS_EXPR, &r.rv (), NULL);
   return x.normalize ();
 }
@@ -43,7 +43,7 @@ CTFloat::fabs (real_t r)
 real_t
 CTFloat::ldexp (real_t r, int exp)
 {
-  real_t x;
+  real_t x = {};
   real_ldexp (&x.rv (), &r.rv (), exp);
   return x.normalize ();
 }
@@ -87,7 +87,7 @@ CTFloat::isInfinity (real_t r)
 real_t
 CTFloat::parse (const char *buffer, bool &overflow)
 {
-  real_t r;
+  real_t r = {};
   real_from_string3 (&r.rv (), buffer, TYPE_MODE (long_double_type_node));
 
   /* Front-end checks overflow to see if the value is representable.  */
diff --git a/gcc/d/d-longdouble.cc b/gcc/d/d-longdouble.cc
index e4c8c5e6eb06..212689d1280a 100644
--- a/gcc/d/d-longdouble.cc
+++ b/gcc/d/d-longdouble.cc
@@ -113,7 +113,7 @@ longdouble::to_bool (void) const
 longdouble
 longdouble::add

[gcc r13-9405] d: Fix comparing uninitialized memory in dstruct.d [PR116961]

2025-03-02 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:21b3e23bd972544c1e2f704e8b05dd9252a288ce

commit r13-9405-g21b3e23bd972544c1e2f704e8b05dd9252a288ce
Author: Iain Buclaw 
Date:   Fri Feb 28 19:22:36 2025 +0100

d: Fix comparing uninitialized memory in dstruct.d [PR116961]

Floating-point emulation in the D front-end is done via a type named
`struct longdouble`, which in GDC is a small interface around the
real_value type. Because the D code cannot include gcc/real.h directly,
a big enough buffer is used for the data instead.

On x86_64, this buffer is actually bigger than real_value itself, so
when a new longdouble object is created with

longdouble r;
real_from_string3 (&r.rv (), buffer, mode);
return r;

there is uninitialized padding at the end of `r`.  This was never a
problem when D was implemented in C++ (until GCC 12) as comparing two
longdouble objects with `==' would be forwarded to the relevant
operator== overload that extracted the underlying real_value.

However when the front-end was translated to D, such conditions were
instead rewritten into identity comparisons

return exp.toReal() is CTFloat.zero

The `is` operator gets lowered as a call to `memcmp() == 0', which is
where the read of uninitialized memory occurs, as seen by valgrind.

==26778== Conditional jump or move depends on uninitialised value(s)
==26778==at 0x911F41: 
dmd.dstruct._isZeroInit(dmd.expression.Expression) (dstruct.d:635)
==26778==by 0x9123BE: StructDeclaration::finalizeSize() (dstruct.d:373)
==26778==by 0x86747C: 
dmd.aggregate.AggregateDeclaration.determineSize(ref const(dmd.location.Loc)) 
(aggregate.d:226)
[...]

To avoid accidentally reading uninitialized data, explicitly initialize
all `longdouble` variables with an empty constructor on C++ side of the
implementation before initializing underlying real_value type it holds.

PR d/116961

gcc/d/ChangeLog:

* d-codegen.cc (build_float_cst): Change new_value type from real_t 
to
real_value.
* d-ctfloat.cc (CTFloat::fabs): Default initialize the return value.
(CTFloat::ldexp): Likewise.
(CTFloat::parse): Likewise.
* d-longdouble.cc (longdouble::add): Likewise.
(longdouble::sub): Likewise.
(longdouble::mul): Likewise.
(longdouble::div): Likewise.
(longdouble::mod): Likewise.
(longdouble::neg): Likewise.
* d-port.cc (Port::isFloat32LiteralOutOfRange): Likewise.
(Port::isFloat64LiteralOutOfRange): Likewise.

gcc/testsuite/ChangeLog:

* gdc.dg/pr116961.d: New test.

(cherry picked from commit f7bc17ebc9ef89700672ed7125da719f3558f3b7)

Diff:
---
 gcc/d/d-codegen.cc  |  6 +++---
 gcc/d/d-ctfloat.cc  |  6 +++---
 gcc/d/d-longdouble.cc   | 12 ++--
 gcc/d/d-port.cc |  4 ++--
 gcc/testsuite/gdc.dg/pr116961.d |  7 +++
 5 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 60784928d41f..f6a46fad2b0a 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -246,15 +246,15 @@ build_integer_cst (dinteger_t value, tree type)
 tree
 build_float_cst (const real_t &value, Type *totype)
 {
-  real_t new_value;
+  real_value new_value;
   TypeBasic *tb = totype->isTypeBasic ();
 
   gcc_assert (tb != NULL);
 
   tree type_node = build_ctype (tb);
-  real_convert (&new_value.rv (), TYPE_MODE (type_node), &value.rv ());
+  real_convert (&new_value, TYPE_MODE (type_node), &value.rv ());
 
-  return build_real (type_node, new_value.rv ());
+  return build_real (type_node, new_value);
 }
 
 /* Returns the .length component from the D dynamic array EXP.  */
diff --git a/gcc/d/d-ctfloat.cc b/gcc/d/d-ctfloat.cc
index 15d02b6de760..b716caf96f1c 100644
--- a/gcc/d/d-ctfloat.cc
+++ b/gcc/d/d-ctfloat.cc
@@ -33,7 +33,7 @@ along with GCC; see the file COPYING3.  If not see
 real_t
 CTFloat::fabs (real_t r)
 {
-  real_t x;
+  real_t x = {};
   real_arithmetic (&x.rv (), ABS_EXPR, &r.rv (), NULL);
   return x.normalize ();
 }
@@ -43,7 +43,7 @@ CTFloat::fabs (real_t r)
 real_t
 CTFloat::ldexp (real_t r, int exp)
 {
-  real_t x;
+  real_t x = {};
   real_ldexp (&x.rv (), &r.rv (), exp);
   return x.normalize ();
 }
@@ -87,7 +87,7 @@ CTFloat::isInfinity (real_t r)
 real_t
 CTFloat::parse (const char *buffer, bool &overflow)
 {
-  real_t r;
+  real_t r = {};
   real_from_string3 (&r.rv (), buffer, TYPE_MODE (long_double_type_node));
 
   /* Front-end checks overflow to see if the value is representable.  */
diff --git a/gcc/d/d-longdouble.cc b/gcc/d/d-longdouble.cc
index c00208b47269..5a7afdab4d7a 100644
--- a/gcc/d/d-longdouble.cc
+++ b/gcc/d/d-longdouble.cc
@@ -113,7 +113,7 @@ longdouble::to_bool (void) const
 longdouble
 longdouble::add 

[gcc r12-10972] d: Fix comparing uninitialized memory in dstruct.d [PR116961]

2025-03-02 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:f6be26657c8b974a5caf39350e4965cfb2c4b936

commit r12-10972-gf6be26657c8b974a5caf39350e4965cfb2c4b936
Author: Iain Buclaw 
Date:   Fri Feb 28 19:22:36 2025 +0100

d: Fix comparing uninitialized memory in dstruct.d [PR116961]

Floating-point emulation in the D front-end is done via a type named
`struct longdouble`, which in GDC is a small interface around the
real_value type. Because the D code cannot include gcc/real.h directly,
a big enough buffer is used for the data instead.

On x86_64, this buffer is actually bigger than real_value itself, so
when a new longdouble object is created with

longdouble r;
real_from_string3 (&r.rv (), buffer, mode);
return r;

there is uninitialized padding at the end of `r`.  This was never a
problem when D was implemented in C++ (until GCC 12) as comparing two
longdouble objects with `==' would be forwarded to the relevant
operator== overload that extracted the underlying real_value.

However when the front-end was translated to D, such conditions were
instead rewritten into identity comparisons

return exp.toReal() is CTFloat.zero

The `is` operator gets lowered as a call to `memcmp() == 0', which is
where the read of uninitialized memory occurs, as seen by valgrind.

==26778== Conditional jump or move depends on uninitialised value(s)
==26778==at 0x911F41: 
dmd.dstruct._isZeroInit(dmd.expression.Expression) (dstruct.d:635)
==26778==by 0x9123BE: StructDeclaration::finalizeSize() (dstruct.d:373)
==26778==by 0x86747C: 
dmd.aggregate.AggregateDeclaration.determineSize(ref const(dmd.location.Loc)) 
(aggregate.d:226)
[...]

To avoid accidentally reading uninitialized data, explicitly initialize
all `longdouble` variables with an empty constructor on C++ side of the
implementation before initializing underlying real_value type it holds.

PR d/116961

gcc/d/ChangeLog:

* d-codegen.cc (build_float_cst): Change new_value type from real_t 
to
real_value.
* d-ctfloat.cc (CTFloat::fabs): Default initialize the return value.
(CTFloat::ldexp): Likewise.
(CTFloat::parse): Likewise.
* d-longdouble.cc (longdouble::add): Likewise.
(longdouble::sub): Likewise.
(longdouble::mul): Likewise.
(longdouble::div): Likewise.
(longdouble::mod): Likewise.
(longdouble::neg): Likewise.
* d-port.cc (Port::isFloat32LiteralOutOfRange): Likewise.
(Port::isFloat64LiteralOutOfRange): Likewise.

gcc/testsuite/ChangeLog:

* gdc.dg/pr116961.d: New test.

(cherry picked from commit f7bc17ebc9ef89700672ed7125da719f3558f3b7)

Diff:
---
 gcc/d/d-codegen.cc  |  6 +++---
 gcc/d/d-ctfloat.cc  |  6 +++---
 gcc/d/d-longdouble.cc   | 12 ++--
 gcc/d/d-port.cc |  4 ++--
 gcc/testsuite/gdc.dg/pr116961.d |  7 +++
 5 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 31d593ca7fde..4f20d063c904 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -244,15 +244,15 @@ build_integer_cst (dinteger_t value, tree type)
 tree
 build_float_cst (const real_t &value, Type *totype)
 {
-  real_t new_value;
+  real_value new_value;
   TypeBasic *tb = totype->isTypeBasic ();
 
   gcc_assert (tb != NULL);
 
   tree type_node = build_ctype (tb);
-  real_convert (&new_value.rv (), TYPE_MODE (type_node), &value.rv ());
+  real_convert (&new_value, TYPE_MODE (type_node), &value.rv ());
 
-  return build_real (type_node, new_value.rv ());
+  return build_real (type_node, new_value);
 }
 
 /* Returns the .length component from the D dynamic array EXP.  */
diff --git a/gcc/d/d-ctfloat.cc b/gcc/d/d-ctfloat.cc
index c4d9a44c59ba..3afddc8fe1a6 100644
--- a/gcc/d/d-ctfloat.cc
+++ b/gcc/d/d-ctfloat.cc
@@ -33,7 +33,7 @@ along with GCC; see the file COPYING3.  If not see
 real_t
 CTFloat::fabs (real_t r)
 {
-  real_t x;
+  real_t x = {};
   real_arithmetic (&x.rv (), ABS_EXPR, &r.rv (), NULL);
   return x.normalize ();
 }
@@ -43,7 +43,7 @@ CTFloat::fabs (real_t r)
 real_t
 CTFloat::ldexp (real_t r, int exp)
 {
-  real_t x;
+  real_t x = {};
   real_ldexp (&x.rv (), &r.rv (), exp);
   return x.normalize ();
 }
@@ -87,7 +87,7 @@ CTFloat::isInfinity (real_t r)
 real_t
 CTFloat::parse (const char *buffer, bool *overflow)
 {
-  real_t r;
+  real_t r = {};
   real_from_string3 (&r.rv (), buffer, TYPE_MODE (long_double_type_node));
 
   /* Front-end checks overflow to see if the value is representable.  */
diff --git a/gcc/d/d-longdouble.cc b/gcc/d/d-longdouble.cc
index cf0b68b2f2da..2fb48e2722f2 100644
--- a/gcc/d/d-longdouble.cc
+++ b/gcc/d/d-longdouble.cc
@@ -113,7 +113,7 @@ longdouble::to_bool (void) const
 longdouble
 longdouble::add

[gcc r15-7968] d: Fix regression returning from function with invariants [PR119139]

2025-03-11 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:81582ca6cb692098c1bda7995aec46c6cbfbfcb3

commit r15-7968-g81582ca6cb692098c1bda7995aec46c6cbfbfcb3
Author: Iain Buclaw 
Date:   Tue Mar 11 17:56:18 2025 +0100

d: Fix regression returning from function with invariants [PR119139]

An optimization was added in GDC-12 which sets the TREE_READONLY flag on
all local variables with the storage class `const' assigned.  For some
reason, const is also being added by the front-end to `__result'
variables in non-virtual functions, which ends up getting wrong code by
the gimplify pass promoting the local to static storage.

A bug has been raised upstream, as this looks like an error in the AST.
For now, turn off setting TREE_READONLY on all result variables.

PR d/119139

gcc/d/ChangeLog:

* decl.cc (get_symbol_decl): Don't set TREE_READONLY for __result
declarations.

gcc/testsuite/ChangeLog:

* gdc.dg/pr119139.d: New test.

Diff:
---
 gcc/d/decl.cc   |  2 +-
 gcc/testsuite/gdc.dg/pr119139.d | 24 
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 88dc5251bdaf..1bad1866763f 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -1323,7 +1323,7 @@ get_symbol_decl (Declaration *decl)
   /* `const` applies to data that cannot be changed by the const reference
 to that data. It may, however, be changed by another reference to that
 same data.  */
-  if (vd->isConst () && !vd->isDataseg ())
+  if (vd->isConst () && !vd->isResult () && !vd->isDataseg ())
TREE_READONLY (decl->csym) = 1;
 }
 
diff --git a/gcc/testsuite/gdc.dg/pr119139.d b/gcc/testsuite/gdc.dg/pr119139.d
new file mode 100644
index ..dc42c411e390
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr119139.d
@@ -0,0 +1,24 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119139
+// { dg-do compile }
+// { dg-options "-fdump-tree-gimple" }
+string toString()
+{
+return "1";
+}
+
+struct B
+{
+ulong n;
+
+invariant{}
+
+string str()
+{
+if (n == 0)
+{
+return "0";
+}
+return toString();
+}
+}
+// { dg-final { scan-tree-dump-not "static const struct  __result =" "gimple" 
} }


[gcc r14-11401] d: Fix regression returning from function with invariants [PR119139]

2025-03-11 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:af69315f84778dc1455d2a06d355a67ad8b9241e

commit r14-11401-gaf69315f84778dc1455d2a06d355a67ad8b9241e
Author: Iain Buclaw 
Date:   Tue Mar 11 17:56:18 2025 +0100

d: Fix regression returning from function with invariants [PR119139]

An optimization was added in GDC-12 which sets the TREE_READONLY flag on
all local variables with the storage class `const' assigned.  For some
reason, const is also being added by the front-end to `__result'
variables in non-virtual functions, which ends up getting wrong code by
the gimplify pass promoting the local to static storage.

A bug has been raised upstream, as this looks like an error in the AST.
For now, turn off setting TREE_READONLY on all result variables.

PR d/119139

gcc/d/ChangeLog:

* decl.cc (get_symbol_decl): Don't set TREE_READONLY for __result
declarations.

gcc/testsuite/ChangeLog:

* gdc.dg/pr119139.d: New test.

(cherry picked from commit 81582ca6cb692098c1bda7995aec46c6cbfbfcb3)

Diff:
---
 gcc/d/decl.cc   |  2 +-
 gcc/testsuite/gdc.dg/pr119139.d | 24 
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 0a87c85ae2e5..7cc203ac8429 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -1325,7 +1325,7 @@ get_symbol_decl (Declaration *decl)
   /* `const` applies to data that cannot be changed by the const reference
 to that data. It may, however, be changed by another reference to that
 same data.  */
-  if (vd->isConst () && !vd->isDataseg ())
+  if (vd->isConst () && !vd->isResult () && !vd->isDataseg ())
TREE_READONLY (decl->csym) = 1;
 }
 
diff --git a/gcc/testsuite/gdc.dg/pr119139.d b/gcc/testsuite/gdc.dg/pr119139.d
new file mode 100644
index ..dc42c411e390
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr119139.d
@@ -0,0 +1,24 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119139
+// { dg-do compile }
+// { dg-options "-fdump-tree-gimple" }
+string toString()
+{
+return "1";
+}
+
+struct B
+{
+ulong n;
+
+invariant{}
+
+string str()
+{
+if (n == 0)
+{
+return "0";
+}
+return toString();
+}
+}
+// { dg-final { scan-tree-dump-not "static const struct  __result =" "gimple" 
} }


[gcc r12-10988] d: Fix regression returning from function with invariants [PR119139]

2025-03-11 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:8d8eb5327f44472e8769807a6e632e2e0d445bb9

commit r12-10988-g8d8eb5327f44472e8769807a6e632e2e0d445bb9
Author: Iain Buclaw 
Date:   Tue Mar 11 17:56:18 2025 +0100

d: Fix regression returning from function with invariants [PR119139]

An optimization was added in GDC-12 which sets the TREE_READONLY flag on
all local variables with the storage class `const' assigned.  For some
reason, const is also being added by the front-end to `__result'
variables in non-virtual functions, which ends up getting wrong code by
the gimplify pass promoting the local to static storage.

A bug has been raised upstream, as this looks like an error in the AST.
For now, turn off setting TREE_READONLY on all result variables.

PR d/119139

gcc/d/ChangeLog:

* decl.cc (get_symbol_decl): Don't set TREE_READONLY for __result
declarations.

gcc/testsuite/ChangeLog:

* gdc.dg/pr119139.d: New test.

(cherry picked from commit 81582ca6cb692098c1bda7995aec46c6cbfbfcb3)

Diff:
---
 gcc/d/decl.cc   |  2 +-
 gcc/testsuite/gdc.dg/pr119139.d | 24 
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 6c2705d9864f..00eac62d7a3b 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -1300,7 +1300,7 @@ get_symbol_decl (Declaration *decl)
   /* `const` applies to data that cannot be changed by the const reference
 to that data. It may, however, be changed by another reference to that
 same data.  */
-  if (vd->isConst () && !vd->isDataseg ())
+  if (vd->isConst () && !vd->isResult () && !vd->isDataseg ())
TREE_READONLY (decl->csym) = 1;
 }
 
diff --git a/gcc/testsuite/gdc.dg/pr119139.d b/gcc/testsuite/gdc.dg/pr119139.d
new file mode 100644
index ..dc42c411e390
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr119139.d
@@ -0,0 +1,24 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119139
+// { dg-do compile }
+// { dg-options "-fdump-tree-gimple" }
+string toString()
+{
+return "1";
+}
+
+struct B
+{
+ulong n;
+
+invariant{}
+
+string str()
+{
+if (n == 0)
+{
+return "0";
+}
+return toString();
+}
+}
+// { dg-final { scan-tree-dump-not "static const struct  __result =" "gimple" 
} }


[gcc r15-7742] libphobos: Run unittest tests with dg-runtest.

2025-02-27 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:955de3733a9ef301e2d95009cd59a1eb4ee5273c

commit r15-7742-g955de3733a9ef301e2d95009cd59a1eb4ee5273c
Author: Iain Buclaw 
Date:   Thu Feb 27 23:37:21 2025 +0100

libphobos: Run unittest tests with dg-runtest.

Use `dg-runtest' test driver rather than `dg-test' to run the libphobos
unittest testsuite, same as all other libphobos tests.  This prevents
the tests from being ran multiple times when parallelized.

Set `libphobos_test_name' as well so that all tests get a unique name.

libphobos/ChangeLog:

* testsuite/libphobos.unittest/unittest.exp: Use `dg-runtest' rather
than `dg-test'.  Set `libphobos_test_name'.

Diff:
---
 libphobos/testsuite/libphobos.unittest/unittest.exp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libphobos/testsuite/libphobos.unittest/unittest.exp 
b/libphobos/testsuite/libphobos.unittest/unittest.exp
index 3e2d3b84cdce..0b0e3e3ce09d 100644
--- a/libphobos/testsuite/libphobos.unittest/unittest.exp
+++ b/libphobos/testsuite/libphobos.unittest/unittest.exp
@@ -42,8 +42,10 @@ foreach unit_test $unit_test_list {
 set expected_fail [lindex $unit_test 1]
 
 foreach test $tests {
+set libphobos_test_name "[dg-trim-dirname $srcdir $test] $test_flags"
 set shouldfail $expected_fail
-dg-test $test "" $test_flags
+dg-runtest $test "" $test_flags
+set libphobos_test_name ""
 }
 
 set shouldfail 0


[gcc r15-7763] d: Fix comparing uninitialized memory in dstruct.d [PR116961]

2025-03-01 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:f7bc17ebc9ef89700672ed7125da719f3558f3b7

commit r15-7763-gf7bc17ebc9ef89700672ed7125da719f3558f3b7
Author: Iain Buclaw 
Date:   Fri Feb 28 19:22:36 2025 +0100

d: Fix comparing uninitialized memory in dstruct.d [PR116961]

Floating-point emulation in the D front-end is done via a type named
`struct longdouble`, which in GDC is a small interface around the
real_value type. Because the D code cannot include gcc/real.h directly,
a big enough buffer is used for the data instead.

On x86_64, this buffer is actually bigger than real_value itself, so
when a new longdouble object is created with

longdouble r;
real_from_string3 (&r.rv (), buffer, mode);
return r;

there is uninitialized padding at the end of `r`.  This was never a
problem when D was implemented in C++ (until GCC 12) as comparing two
longdouble objects with `==' would be forwarded to the relevant
operator== overload that extracted the underlying real_value.

However when the front-end was translated to D, such conditions were
instead rewritten into identity comparisons

return exp.toReal() is CTFloat.zero

The `is` operator gets lowered as a call to `memcmp() == 0', which is
where the read of uninitialized memory occurs, as seen by valgrind.

==26778== Conditional jump or move depends on uninitialised value(s)
==26778==at 0x911F41: 
dmd.dstruct._isZeroInit(dmd.expression.Expression) (dstruct.d:635)
==26778==by 0x9123BE: StructDeclaration::finalizeSize() (dstruct.d:373)
==26778==by 0x86747C: 
dmd.aggregate.AggregateDeclaration.determineSize(ref const(dmd.location.Loc)) 
(aggregate.d:226)
[...]

To avoid accidentally reading uninitialized data, explicitly initialize
all `longdouble` variables with an empty constructor on C++ side of the
implementation before initializing underlying real_value type it holds.

PR d/116961

gcc/d/ChangeLog:

* d-codegen.cc (build_float_cst): Change new_value type from real_t 
to
real_value.
* d-ctfloat.cc (CTFloat::fabs): Default initialize the return value.
(CTFloat::ldexp): Likewise.
(CTFloat::parse): Likewise.
* d-longdouble.cc (longdouble::add): Likewise.
(longdouble::sub): Likewise.
(longdouble::mul): Likewise.
(longdouble::div): Likewise.
(longdouble::mod): Likewise.
(longdouble::neg): Likewise.
* d-port.cc (Port::isFloat32LiteralOutOfRange): Likewise.
(Port::isFloat64LiteralOutOfRange): Likewise.

gcc/testsuite/ChangeLog:

* gdc.dg/pr116961.d: New test.

Diff:
---
 gcc/d/d-codegen.cc  |  6 +++---
 gcc/d/d-ctfloat.cc  |  6 +++---
 gcc/d/d-longdouble.cc   | 12 ++--
 gcc/d/d-port.cc |  4 ++--
 gcc/testsuite/gdc.dg/pr116961.d |  7 +++
 5 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 66f06e9086ed..50362e6f8f53 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -246,15 +246,15 @@ build_integer_cst (dinteger_t value, tree type)
 tree
 build_float_cst (const real_t &value, Type *totype)
 {
-  real_t new_value;
+  real_value new_value;
   TypeBasic *tb = totype->isTypeBasic ();
 
   gcc_assert (tb != NULL);
 
   tree type_node = build_ctype (tb);
-  real_convert (&new_value.rv (), TYPE_MODE (type_node), &value.rv ());
+  real_convert (&new_value, TYPE_MODE (type_node), &value.rv ());
 
-  return build_real (type_node, new_value.rv ());
+  return build_real (type_node, new_value);
 }
 
 /* Returns the .length component from the D dynamic array EXP.  */
diff --git a/gcc/d/d-ctfloat.cc b/gcc/d/d-ctfloat.cc
index 271885dcd9b8..659d56161242 100644
--- a/gcc/d/d-ctfloat.cc
+++ b/gcc/d/d-ctfloat.cc
@@ -33,7 +33,7 @@ along with GCC; see the file COPYING3.  If not see
 real_t
 CTFloat::fabs (real_t r)
 {
-  real_t x;
+  real_t x = {};
   real_arithmetic (&x.rv (), ABS_EXPR, &r.rv (), NULL);
   return x.normalize ();
 }
@@ -43,7 +43,7 @@ CTFloat::fabs (real_t r)
 real_t
 CTFloat::ldexp (real_t r, int exp)
 {
-  real_t x;
+  real_t x = {};
   real_ldexp (&x.rv (), &r.rv (), exp);
   return x.normalize ();
 }
@@ -87,7 +87,7 @@ CTFloat::isInfinity (real_t r)
 real_t
 CTFloat::parse (const char *buffer, bool &overflow)
 {
-  real_t r;
+  real_t r = {};
   real_from_string3 (&r.rv (), buffer, TYPE_MODE (long_double_type_node));
 
   /* Front-end checks overflow to see if the value is representable.  */
diff --git a/gcc/d/d-longdouble.cc b/gcc/d/d-longdouble.cc
index 99ce8a19b6c0..193a82838644 100644
--- a/gcc/d/d-longdouble.cc
+++ b/gcc/d/d-longdouble.cc
@@ -113,7 +113,7 @@ longdouble::to_bool (void) const
 longdouble
 longdouble::add (const longdouble &r) const
 {
-  longdouble x;
+  longdouble x = {};
   real_

[gcc r15-7999] libphobos: Merge upstream phobos 0faae92d6

2025-03-12 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:d63b52e059a7d77b98a2ef005920a85feb1e2446

commit r15-7999-gd63b52e059a7d77b98a2ef005920a85feb1e2446
Author: Iain Buclaw 
Date:   Wed Mar 12 12:04:59 2025 +0100

libphobos: Merge upstream phobos 0faae92d6

Phobos changes:

- Import phobos v2.111.0-beta.1.
- Added `bitCast' function to `std.conv'.
- Added `readfln' and `File.readfln' functions to `std.stdio'.
- New procedural API for `std.sumtype'.

libphobos/ChangeLog:

* src/MERGE: Merge upstream phobos 0faae92d6.
* testsuite/libphobos.phobos/std_array.d: Regenerate.
* testsuite/libphobos.phobos/std_conv.d: Regenerate.
* testsuite/libphobos.phobos/std_functional.d: Regenerate.
* testsuite/libphobos.phobos/std_sumtype.d: Regenerate.

Diff:
---
 libphobos/src/MERGE|   2 +-
 libphobos/src/std/algorithm/iteration.d|  34 +-
 libphobos/src/std/array.d  | 387 ++
 libphobos/src/std/bigint.d |  26 +-
 libphobos/src/std/checkedint.d |   2 +-
 libphobos/src/std/container/dlist.d|   2 +-
 libphobos/src/std/conv.d   |  36 ++
 libphobos/src/std/datetime/stopwatch.d |   1 -
 libphobos/src/std/format/internal/floats.d | 193 +++
 libphobos/src/std/format/internal/read.d   |   5 +-
 libphobos/src/std/format/internal/write.d  |  13 +-
 libphobos/src/std/format/read.d|  10 +
 libphobos/src/std/functional.d |  72 ++-
 libphobos/src/std/getopt.d | 111 +++-
 libphobos/src/std/math/operations.d|  95 ++--
 libphobos/src/std/process.d|  60 +--
 libphobos/src/std/random.d | 127 -
 libphobos/src/std/range/interfaces.d   |   2 +-
 libphobos/src/std/range/package.d  |  21 +-
 libphobos/src/std/stdio.d  | 144 ++
 libphobos/src/std/sumtype.d| 560 ++---
 libphobos/src/std/typecons.d   | 109 ++--
 libphobos/testsuite/libphobos.phobos/std_array.d   |  17 +
 libphobos/testsuite/libphobos.phobos/std_conv.d|  12 +
 .../testsuite/libphobos.phobos/std_functional.d|  33 ++
 libphobos/testsuite/libphobos.phobos/std_sumtype.d | 153 ++
 26 files changed, 1787 insertions(+), 440 deletions(-)

diff --git a/libphobos/src/MERGE b/libphobos/src/MERGE
index 9603e65aa423..a5a685de2362 100644
--- a/libphobos/src/MERGE
+++ b/libphobos/src/MERGE
@@ -1,4 +1,4 @@
-1b242048c9db88c52cb0df6cd50c2b7455bedc01
+0faae92d62bdc1cc1982f0e9c65830ece1677289
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/phobos repository.
diff --git a/libphobos/src/std/algorithm/iteration.d 
b/libphobos/src/std/algorithm/iteration.d
index 8a3add3b7333..f8e1c05b658a 100644
--- a/libphobos/src/std/algorithm/iteration.d
+++ b/libphobos/src/std/algorithm/iteration.d
@@ -446,35 +446,21 @@ if (fun.length >= 1)
 auto map(Range)(Range r)
 if (isInputRange!(Unqual!Range))
 {
-import std.meta : AliasSeq, staticMap;
+import std.meta : staticMap;
+import std.functional : adjoin;
 
 alias RE = ElementType!(Range);
-static if (fun.length > 1)
-{
-import std.functional : adjoin;
-import std.meta : staticIndexOf;
 
-alias _funs = staticMap!(unaryFun, fun);
-alias _fun = adjoin!_funs;
+alias _funs = staticMap!(unaryFun, fun);
+alias _fun = adjoin!_funs;
 
-// Once https://issues.dlang.org/show_bug.cgi?id=5710 is fixed
-// accross all compilers (as of 2020-04, it wasn't fixed in LDC 
and GDC),
-// this validation loop can be moved into a template.
-foreach (f; _funs)
-{
-static assert(!is(typeof(f(RE.init)) == void),
-"Mapping function(s) must not return void: " ~ 
_funs.stringof);
-}
-}
-else
+// Once https://issues.dlang.org/show_bug.cgi?id=5710 is fixed
+// accross all compilers (as of 2020-04, it wasn't fixed in LDC and 
GDC),
+// this validation loop can be moved into a template.
+foreach (f; _funs)
 {
-alias _fun = unaryFun!fun;
-alias _funs = AliasSeq!(_fun);
-
-// Do the validation separately for single parameters due to
-// https://issues.dlang.org/show_bug.cgi?id=15777.
-static assert(!is(typeof(_fun(RE.init)) == void),
-"Mapping function(s) must not return void: " ~ _funs.stringof);
+static assert(!is(typeof(f(RE.init)) == void),
+"Mapping function(s) must not return void: " ~ 
_funs.stringof);
 

[gcc r13-9423] d: Fix regression returning from function with invariants [PR119139]

2025-03-11 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:2b37c9973967230b01dc5e38770fb3ec84610555

commit r13-9423-g2b37c9973967230b01dc5e38770fb3ec84610555
Author: Iain Buclaw 
Date:   Tue Mar 11 17:56:18 2025 +0100

d: Fix regression returning from function with invariants [PR119139]

An optimization was added in GDC-12 which sets the TREE_READONLY flag on
all local variables with the storage class `const' assigned.  For some
reason, const is also being added by the front-end to `__result'
variables in non-virtual functions, which ends up getting wrong code by
the gimplify pass promoting the local to static storage.

A bug has been raised upstream, as this looks like an error in the AST.
For now, turn off setting TREE_READONLY on all result variables.

PR d/119139

gcc/d/ChangeLog:

* decl.cc (get_symbol_decl): Don't set TREE_READONLY for __result
declarations.

gcc/testsuite/ChangeLog:

* gdc.dg/pr119139.d: New test.

(cherry picked from commit 81582ca6cb692098c1bda7995aec46c6cbfbfcb3)

Diff:
---
 gcc/d/decl.cc   |  2 +-
 gcc/testsuite/gdc.dg/pr119139.d | 24 
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 84274b3f3c31..deba3335a6a8 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -1313,7 +1313,7 @@ get_symbol_decl (Declaration *decl)
   /* `const` applies to data that cannot be changed by the const reference
 to that data. It may, however, be changed by another reference to that
 same data.  */
-  if (vd->isConst () && !vd->isDataseg ())
+  if (vd->isConst () && !vd->isResult () && !vd->isDataseg ())
TREE_READONLY (decl->csym) = 1;
 }
 
diff --git a/gcc/testsuite/gdc.dg/pr119139.d b/gcc/testsuite/gdc.dg/pr119139.d
new file mode 100644
index ..dc42c411e390
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr119139.d
@@ -0,0 +1,24 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119139
+// { dg-do compile }
+// { dg-options "-fdump-tree-gimple" }
+string toString()
+{
+return "1";
+}
+
+struct B
+{
+ulong n;
+
+invariant{}
+
+string str()
+{
+if (n == 0)
+{
+return "0";
+}
+return toString();
+}
+}
+// { dg-final { scan-tree-dump-not "static const struct  __result =" "gimple" 
} }


[gcc r15-7704] libphobos: Add script for extracting unittests from phobos

2025-02-25 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:df4565eaa9b02906a8fa6bb37845c0b4fdedaa20

commit r15-7704-gdf4565eaa9b02906a8fa6bb37845c0b4fdedaa20
Author: Iain Buclaw 
Date:   Tue Feb 25 19:47:06 2025 +0100

libphobos: Add script for extracting unittests from phobos

This script parses all unittests annotated with three slashes (`///')
and extracts them into a standalone test case.  The intended use is for
generating inexpensive tests to be ran for the phobos testsuite.

libphobos/ChangeLog:

* scripts/.gitignore: Add tests_extractor.
* scripts/README: Document tests_extractor.d.
* scripts/tests_extractor.d: New file.

Diff:
---
 libphobos/scripts/.gitignore|   1 +
 libphobos/scripts/README|  11 ++
 libphobos/scripts/tests_extractor.d | 224 
 3 files changed, 236 insertions(+)

diff --git a/libphobos/scripts/.gitignore b/libphobos/scripts/.gitignore
index a5d300b6f604..ddbaf4164b69 100644
--- a/libphobos/scripts/.gitignore
+++ b/libphobos/scripts/.gitignore
@@ -1,3 +1,4 @@
 # Dub leaves built programs in this directory.
 gen_druntime_sources
 gen_phobos_sources
+tests_extractor
diff --git a/libphobos/scripts/README b/libphobos/scripts/README
index 248324dddac3..5444b71ccba5 100644
--- a/libphobos/scripts/README
+++ b/libphobos/scripts/README
@@ -26,3 +26,14 @@ gen_phobos_sources.d
 Example:
 
cd src && ../scripts/gen_phobos_sources >> Makefile.am
+
+tests_extractor.d
+
+Searches the given input directory recursively for public unittest blocks
+(annotated with three slashes). The tests will be extracted as one file for
+each source file to the output directory.  Used to regenerate all tests
+cases in testsuite/libphobos.phobos.
+
+Example:
+
+   ./tests_extractor -i ../libphobos/src -o ../testsuite/libphobos.phobos
diff --git a/libphobos/scripts/tests_extractor.d 
b/libphobos/scripts/tests_extractor.d
new file mode 100644
index ..bc861f50ff42
--- /dev/null
+++ b/libphobos/scripts/tests_extractor.d
@@ -0,0 +1,224 @@
+#!/usr/bin/env dub
+/++dub.sdl:
+name "tests_extractor"
+dependency "libdparse" version="~>0.24.0"
+dflags "-fall-instantiations" platform="gdc"
++/
+// Written in the D programming language.
+
+import dparse.ast;
+import std.algorithm;
+import std.conv;
+import std.exception;
+import std.experimental.logger;
+import std.file;
+import std.path;
+import std.range;
+import std.stdio;
+
+class TestVisitor : ASTVisitor
+{
+File outFile;
+ubyte[] sourceCode;
+string moduleName;
+
+this(File outFile, ubyte[] sourceCode)
+{
+this.outFile = outFile;
+this.sourceCode = sourceCode;
+}
+
+alias visit = ASTVisitor.visit;
+
+override void visit(const Module m)
+{
+if (m.moduleDeclaration !is null)
+{
+moduleName = m.moduleDeclaration.moduleName.identifiers.map!(i => 
i.text).join(".");
+}
+else
+{
+// Fallback: convert the file path to its module path, e.g. 
std/uni.d -> std.uni
+moduleName = outFile.name.replace(".d", "").replace(dirSeparator, 
".").replace(".package", "");
+}
+m.accept(this);
+}
+
+override void visit(const Declaration decl)
+{
+if (decl.unittest_ !is null && decl.unittest_.comment !is null)
+print(decl.unittest_, decl.attributes);
+
+decl.accept(this);
+}
+
+override void visit(const ConditionalDeclaration decl)
+{
+bool skipTrue;
+
+// Check if it's a version that should be skipped
+if (auto vcd = decl.compileCondition.versionCondition)
+{
+if (vcd.token.text == "StdDdoc")
+skipTrue = true;
+}
+
+// Search if/version block
+if (!skipTrue)
+{
+foreach (d; decl.trueDeclarations)
+visit(d);
+}
+
+// Search else block
+foreach (d; decl.falseDeclarations)
+visit(d);
+}
+
+private:
+
+void print(const Unittest u, const Attribute[] attributes)
+{
+static immutable predefinedAttributes = ["nogc", "system", "nothrow", 
"safe", "trusted", "pure"];
+
+// Write system attributes
+foreach (attr; attributes)
+{
+// pure and nothrow
+if (attr.attribute.type != 0)
+{
+import dparse.lexer : str;
+const attrText = attr.attribute.type.str;
+outFile.write(text(attrText, " "));
+}
+
+const atAttribute = attr.atAttribute;
+if (atAttribute is null)
+continue;
+
+const atText = atAttribute.identifier.text;
+
+// Ignore custom attributes (@myArg)
+if (!predefinedAttributes.canFind(atText))
+continue;
+
+outFile.write(text("@", atText, " "));
+}
+
+// Write the unittes

[gcc r15-7703] libphobos: Organize druntime and phobos tests under common directory

2025-02-25 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:a407eada0173455d267ba403e9e0fe54f0f5dd51

commit r15-7703-ga407eada0173455d267ba403e9e0fe54f0f5dd51
Author: Iain Buclaw 
Date:   Tue Feb 25 20:08:14 2025 +0100

libphobos: Organize druntime and phobos tests under common directory

The druntime and druntime_shared tests are identical, save for one
compiled with `-static-libphobos' and the other `-shared-libphobos'.
Move them to libphobos.druntime/static and libphobos.druntime/shared
respectively.  This has also been done for libphobos.phobos.

libphobos/ChangeLog:

* testsuite/libphobos.druntime_shared/druntime_shared.exp: Move 
to...
* testsuite/libphobos.druntime/shared/druntime-shared.exp: ...here.
* testsuite/libphobos.druntime/druntime.exp: Move to...
* testsuite/libphobos.druntime/static/druntime-static.exp: ...here.
* testsuite/libphobos.phobos_shared/phobos_shared.exp: Move to...
* testsuite/libphobos.phobos/shared/phobos-shared.exp: ...here.
* testsuite/libphobos.phobos/phobos.exp: Move to...
* testsuite/libphobos.phobos/static/phobos-static.exp: ...here.

Diff:
---
 .../shared/druntime-shared.exp} | 0
 .../libphobos.druntime/{druntime.exp => static/druntime-static.exp} | 0
 .../phobos_shared.exp => libphobos.phobos/shared/phobos-shared.exp} | 6 +++---
 .../libphobos.phobos/{phobos.exp => static/phobos-static.exp}   | 6 +++---
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libphobos/testsuite/libphobos.druntime_shared/druntime_shared.exp 
b/libphobos/testsuite/libphobos.druntime/shared/druntime-shared.exp
similarity index 100%
rename from libphobos/testsuite/libphobos.druntime_shared/druntime_shared.exp
rename to libphobos/testsuite/libphobos.druntime/shared/druntime-shared.exp
diff --git a/libphobos/testsuite/libphobos.druntime/druntime.exp 
b/libphobos/testsuite/libphobos.druntime/static/druntime-static.exp
similarity index 100%
rename from libphobos/testsuite/libphobos.druntime/druntime.exp
rename to libphobos/testsuite/libphobos.druntime/static/druntime-static.exp
diff --git a/libphobos/testsuite/libphobos.phobos_shared/phobos_shared.exp 
b/libphobos/testsuite/libphobos.phobos/shared/phobos-shared.exp
similarity index 89%
rename from libphobos/testsuite/libphobos.phobos_shared/phobos_shared.exp
rename to libphobos/testsuite/libphobos.phobos/shared/phobos-shared.exp
index 54acea78a686..31cc13dd9ae2 100644
--- a/libphobos/testsuite/libphobos.phobos_shared/phobos_shared.exp
+++ b/libphobos/testsuite/libphobos.phobos/shared/phobos-shared.exp
@@ -35,10 +35,10 @@ if { [is-effective-target linux_pre_2639] } {
 
 set libphobos_skip_tests {
 # Skip curl tests if library is not available
-{ libphobos.phobos_shared/etc/c/curl.d { ! libcurl_available } }
-{ libphobos.phobos_shared/std/net/curl.d { ! libcurl_available } }
+{ libphobos.phobos/shared/etc/c/curl.d { ! libcurl_available } }
+{ libphobos.phobos/shared/std/net/curl.d { ! libcurl_available } }
 # Skip concurrency.d test: SEGVs or hangs on macOS 13+ (PR d/111628).
-{ libphobos.phobos_shared/std/concurrency.d { x86_64-apple-darwin2[2-9]* } 
}
+{ libphobos.phobos/shared/std/concurrency.d { x86_64-apple-darwin2[2-9]* } 
}
 }
 
 # Initialize dg.
diff --git a/libphobos/testsuite/libphobos.phobos/phobos.exp 
b/libphobos/testsuite/libphobos.phobos/static/phobos-static.exp
similarity index 88%
rename from libphobos/testsuite/libphobos.phobos/phobos.exp
rename to libphobos/testsuite/libphobos.phobos/static/phobos-static.exp
index 3e74078f1366..642019c7f6d7 100644
--- a/libphobos/testsuite/libphobos.phobos/phobos.exp
+++ b/libphobos/testsuite/libphobos.phobos/static/phobos-static.exp
@@ -35,10 +35,10 @@ if { [is-effective-target linux_pre_2639] } {
 
 set libphobos_skip_tests {
 # Skip curl tests if library is not available
-{ libphobos.phobos/etc/c/curl.d { ! libcurl_available } }
-{ libphobos.phobos/std/net/curl.d { ! libcurl_available } }
+{ libphobos.phobos/static/etc/c/curl.d { ! libcurl_available } }
+{ libphobos.phobos/static/std/net/curl.d { ! libcurl_available } }
 # Skip concurrency.d test: SEGVs or hangs on macOS 13+ (PR d/111628).
-{ libphobos.phobos/std/concurrency.d { x86_64-apple-darwin2[2-9]* } }
+{ libphobos.phobos/static/std/concurrency.d { x86_64-apple-darwin2[2-9]* } 
}
 }
 
 # Initialize dg.


[gcc r15-7697] libphobos: Add scripts to update Makefile.am after an upstream merge

2025-02-25 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:fffe14f045df597bf5ab50730eebe0977eea7090

commit r15-7697-gfffe14f045df597bf5ab50730eebe0977eea7090
Author: Iain Buclaw 
Date:   Tue Feb 25 18:58:27 2025 +0100

libphobos: Add scripts to update Makefile.am after an upstream merge

These two scripts have been used for updating Makefile.am whenever
there's been a file added/removed from either Druntime or Phobos since
the start, but never included in the source tree.

libphobos/ChangeLog:

* libdruntime/Makefile.am: Update comment.
* libdruntime/Makefile.in: Regenerate.
* src/Makefile.am: Update comment.
* src/Makefile.in: Regenerate.
* scripts/.gitignore: New file.
* scripts/README: New file.
* scripts/gen_druntime_sources.d: New file.
* scripts/gen_phobos_sources.d: New file.

Diff:
---
 libphobos/libdruntime/Makefile.am|   2 +-
 libphobos/libdruntime/Makefile.in|   2 +-
 libphobos/scripts/.gitignore |   3 +
 libphobos/scripts/README |  28 
 libphobos/scripts/gen_druntime_sources.d |  92 
 libphobos/scripts/gen_phobos_sources.d   | 116 +++
 libphobos/src/Makefile.am|   2 +-
 libphobos/src/Makefile.in|   2 +-
 8 files changed, 243 insertions(+), 4 deletions(-)

diff --git a/libphobos/libdruntime/Makefile.am 
b/libphobos/libdruntime/Makefile.am
index 8df0e1c43b91..efdae4c57861 100644
--- a/libphobos/libdruntime/Makefile.am
+++ b/libphobos/libdruntime/Makefile.am
@@ -167,7 +167,7 @@ install-data-local:
done
 
 # Source file definitions. Boring stuff, auto-generated with
-# https://gist.github.com/jpf91/8ad1dbc9902d6ad876313f134c6527d1
+# libphobos/scripts/gen_druntime_sources.d
 # Can't use wildcards here:
 # https://www.gnu.org/software/automake/manual/html_node/Wildcards.html
 
diff --git a/libphobos/libdruntime/Makefile.in 
b/libphobos/libdruntime/Makefile.in
index 999064e5221c..1227c59b4854 100644
--- a/libphobos/libdruntime/Makefile.in
+++ b/libphobos/libdruntime/Makefile.in
@@ -850,7 +850,7 @@ libgdruntime_convenience_la_DEPENDENCIES = 
$(libgdruntime_la_DEPENDENCIES)
 libgdruntime_convenience_la_LINK = $(libgdruntime_la_LINK)
 
 # Source file definitions. Boring stuff, auto-generated with
-# https://gist.github.com/jpf91/8ad1dbc9902d6ad876313f134c6527d1
+# libphobos/scripts/gen_druntime_sources.d
 # Can't use wildcards here:
 # https://www.gnu.org/software/automake/manual/html_node/Wildcards.html
 DRUNTIME_CSOURCES = core/stdc/errno_.c etc/valgrind/valgrind_.c
diff --git a/libphobos/scripts/.gitignore b/libphobos/scripts/.gitignore
new file mode 100644
index ..a5d300b6f604
--- /dev/null
+++ b/libphobos/scripts/.gitignore
@@ -0,0 +1,3 @@
+# Dub leaves built programs in this directory.
+gen_druntime_sources
+gen_phobos_sources
diff --git a/libphobos/scripts/README b/libphobos/scripts/README
new file mode 100644
index ..248324dddac3
--- /dev/null
+++ b/libphobos/scripts/README
@@ -0,0 +1,28 @@
+The D language scripts in this directory are used during the syncing of
+libphobos with upstream.  They can be built with the command:
+
+dub build --single name-of-script.d
+
+Or when dub isn't available:
+
+gdc -o name-of-script name-of-script.d [any other dependencies].d
+
+Scripts:
+
+gen_druntime_sources.d
+
+Generates source file definitions for libphobos/libdruntime/Makefile.am.
+Ran from the libdruntime directory and append output to Makefile.am.
+
+Example:
+
+   cd libdruntime && ../scripts/gen_druntime_sources >> Makefile.am
+
+gen_phobos_sources.d
+
+Generates source file definitions for libphobos/src/Makefile.am.  Ran from
+the libphobos/src directory and append output to Makefile.am.
+
+Example:
+
+   cd src && ../scripts/gen_phobos_sources >> Makefile.am
diff --git a/libphobos/scripts/gen_druntime_sources.d 
b/libphobos/scripts/gen_druntime_sources.d
new file mode 100644
index ..ee01477a493f
--- /dev/null
+++ b/libphobos/scripts/gen_druntime_sources.d
@@ -0,0 +1,92 @@
+#!/usr/bin/env dub
+/++dub.sdl:
+name "gen_druntime_sources"
++/
+// Written in the D programming language.
+import std.stdio;
+import std.file;
+import std.path;
+import std.range;
+import std.string;
+import std.algorithm;
+
+string[] filterList = [
+"./Makefile.in", "./Makefile.am",
+"./gcc/config.d.in", "./gcc/libbacktrace.d.in", "./gcc/drtstuff.c",
+"./LICENSE.txt", "./MERGE",
+"./rt/dylib_fixes.c"
+];
+
+struct Files
+{
+string[] baseList, cppList;
+string[][string] sysList;
+}
+
+void main(string[] args)
+{
+Files[string] fileMap;
+
+foreach(entry; ".".dirEntries(SpanMode.depth).filter!(a => 
!filterList.canFind(a)))
+{
+if (entry.name.startsWith("./config/"))
+continue;
+
+if(entry.isFile)
+{
+auto ext = entry.extension.empty ? "" :

[gcc r15-7696] d/i386: Add CET TargetInfo key and predefined version [PR118654]

2025-02-25 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:c17044e509824e5ed3de94c85a7a0dd71cfd9cc1

commit r15-7696-gc17044e509824e5ed3de94c85a7a0dd71cfd9cc1
Author: Iain Buclaw 
Date:   Tue Feb 25 18:01:09 2025 +0100

d/i386: Add CET TargetInfo key and predefined version [PR118654]

Adds a new i386 d_target_info_spec entry to handle requests for
`__traits(getTargetInfo, "CET")', and add predefined target version
`GNU_CET' when the option `-fcf-protecton' is used.

Both TargetInfo key and predefined version have been added to the D
front-end documentation.

In the library, `GNU_CET' replaces the existing use of the user-defined
version flag `CET' when building libphobos.

PR d/118654

gcc/ChangeLog:

* config/i386/i386-d.cc (ix86_d_target_versions): Predefine GNU_CET.
(ix86_d_handle_target_cf_protection): New.
(ix86_d_register_target_info): Add 'CET' TargetInfo key.

gcc/d/ChangeLog:

* implement-d.texi: Document CET version and traits key.

libphobos/ChangeLog:

* Makefile.in: Regenerate.
* configure: Regenerate.
* configure.ac: Remove CET_DFLAGS.
* libdruntime/Makefile.am: Replace CET_DFLAGS with CET_FLAGS.
* libdruntime/Makefile.in: Regenerate.
* libdruntime/core/thread/fiber/package.d: Replace CET with GNU_CET.
* src/Makefile.am: Replace CET_DFLAGS with CET_FLAGS.
* src/Makefile.in: Regenerate.
* testsuite/Makefile.in: Regenerate.
* testsuite/testsuite_flags.in: Replace CET_DFLAGS with CET_FLAGS.

gcc/testsuite/ChangeLog:

* gdc.dg/target/i386/i386.exp: New test.
* gdc.dg/target/i386/targetinfo_CET.d: New test.

Diff:
---
 gcc/config/i386/i386-d.cc | 12 ++
 gcc/d/implement-d.texi|  8 
 gcc/testsuite/gdc.dg/target/i386/i386.exp | 48 +++
 gcc/testsuite/gdc.dg/target/i386/targetinfo_CET.d |  3 ++
 libphobos/Makefile.in |  1 -
 libphobos/configure   |  8 +---
 libphobos/configure.ac|  3 --
 libphobos/libdruntime/Makefile.am |  2 +-
 libphobos/libdruntime/Makefile.in |  3 +-
 libphobos/libdruntime/core/thread/fiber/package.d |  4 +-
 libphobos/src/Makefile.am |  2 +-
 libphobos/src/Makefile.in |  3 +-
 libphobos/testsuite/Makefile.in   |  1 -
 libphobos/testsuite/testsuite_flags.in|  2 +-
 14 files changed, 80 insertions(+), 20 deletions(-)

diff --git a/gcc/config/i386/i386-d.cc b/gcc/config/i386/i386-d.cc
index fbe26e012744..f61b5a50b698 100644
--- a/gcc/config/i386/i386-d.cc
+++ b/gcc/config/i386/i386-d.cc
@@ -44,6 +44,9 @@ ix86_d_target_versions (void)
 d_add_builtin_version ("D_HardFloat");
   else
 d_add_builtin_version ("D_SoftFloat");
+
+  if (flag_cf_protection != CF_NONE)
+d_add_builtin_version ("GNU_CET");
 }
 
 /* Handle a call to `__traits(getTargetInfo, "floatAbi")'.  */
@@ -79,6 +82,14 @@ ix86_d_handle_target_object_format (void)
   return build_string_literal (strlen (objfmt) + 1, objfmt);
 }
 
+/* Handle a call to `__traits(getTargetInfo, "CET")'.  */
+
+static tree
+ix86_d_handle_target_cf_protection (void)
+{
+  return build_int_cst_type (uint32_type_node, flag_cf_protection & ~CF_SET);
+}
+
 /* Implement TARGET_D_REGISTER_CPU_TARGET_INFO.  */
 
 void
@@ -87,6 +98,7 @@ ix86_d_register_target_info (void)
   const struct d_target_info_spec handlers[] = {
 { "floatAbi", ix86_d_handle_target_float_abi },
 { "objectFormat", ix86_d_handle_target_object_format },
+{ "CET", ix86_d_handle_target_cf_protection },
 { NULL, NULL },
   };
 
diff --git a/gcc/d/implement-d.texi b/gcc/d/implement-d.texi
index a5534792e66f..a39fd5834763 100644
--- a/gcc/d/implement-d.texi
+++ b/gcc/d/implement-d.texi
@@ -1892,6 +1892,10 @@ This version is defined by the GNU D compiler.  If all 
you need to know is
 whether or not your D program is being compiled by GDC, or a non-GDC compiler,
 you can simply test @code{version(GNU)}.
 
+@item GNU_CET
+This version is defined when @option{-fcf-protection} is used.  The protection
+level is also set in @code{__traits(getTargetInfo, "CET")} (@pxref{Traits}).
+
 @item GNU_DWARF2_Exceptions
 @itemx GNU_SEH_Exceptions
 @itemx GNU_SjLj_Exceptions
@@ -2121,6 +2125,10 @@ recognize.  These are documented by the D language 
specification hosted at
 The following keys are recognized by GNU D.
 
 @table @code
+@item CET
+When @option{-fcf-protection} is used, the first bit is set to 1 for the value
+@code{branch} and the second bit is set to 1 for the value @code{return}.
+
 @item cppRuntimeLibrary
 The C++ runtime library affinity for this toolchain.
 
diff --git a/gcc/testsuite/gdc.dg/target/i386/i386.exp 
b/gcc/testsuite

[gcc r15-7695] d: Increase max parallelism of the D testsuite

2025-02-25 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:2d812eecc36e69b5c39ad49b80ab9965c63fdd09

commit r15-7695-g2d812eecc36e69b5c39ad49b80ab9965c63fdd09
Author: Iain Buclaw 
Date:   Mon Feb 24 19:57:15 2025 +0100

d: Increase max parallelism of the D testsuite

It was noticed that when running the testsuite for gdc and libphobos in
parallel, this was capped at 10 simultaneous jobs each.  Increase this
limit to 128, which enables running for example `make check-d -j48` to
complete in half the time.

gcc/d/ChangeLog:

* Make-lang.in (check_gdc_parallelize): Increase to 128.

libphobos/ChangeLog:

* testsuite/Makefile.am (check_p_subno): Remove variable.
(check_p_subdirs): Increase default parallel slots to 128.
* testsuite/Makefile.in: Regenerate.

Diff:
---
 gcc/d/Make-lang.in  | 2 +-
 libphobos/testsuite/Makefile.am | 3 +--
 libphobos/testsuite/Makefile.in | 3 +--
 3 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/gcc/d/Make-lang.in b/gcc/d/Make-lang.in
index a29531c8b7f6..2d444c999530 100644
--- a/gcc/d/Make-lang.in
+++ b/gcc/d/Make-lang.in
@@ -308,7 +308,7 @@ d.srcman: doc/gdc.1
 check-d: check-gdc
 lang_checks += check-gdc
 lang_checks_parallelized += check-gdc
-check_gdc_parallelize = 10
+check_gdc_parallelize = 128
 
 # No D-specific selftests.
 selftest-d:
diff --git a/libphobos/testsuite/Makefile.am b/libphobos/testsuite/Makefile.am
index 54dc7ba540f7..ecddb80db5df 100644
--- a/libphobos/testsuite/Makefile.am
+++ b/libphobos/testsuite/Makefile.am
@@ -29,7 +29,6 @@ RUNTESTDEFAULTFLAGS = --tool $$tool --srcdir $$srcdir
 
 PWD_COMMAND = $${PWDCMD-pwd}
 
-check_p_subno=$(word 2,$(subst _, ,$*))
 check_p_numbers0:=1 2 3 4 5 6 7 8 9
 check_p_numbers1:=0 $(check_p_numbers0)
 check_p_numbers2:=$(foreach i,$(check_p_numbers0),$(addprefix 
$(i),$(check_p_numbers1)))
@@ -38,7 +37,7 @@ check_p_numbers4:=$(foreach i,$(check_p_numbers0),$(addprefix 
$(i),$(check_p_num
 check_p_numbers5:=$(addprefix 0,$(check_p_numbers3)) $(check_p_numbers4)
 check_p_numbers6:=$(foreach i,$(check_p_numbers0),$(addprefix 
$(i),$(check_p_numbers5)))
 check_p_numbers:=$(check_p_numbers0) $(check_p_numbers2) $(check_p_numbers4) 
$(check_p_numbers6)
-check_p_subdirs=$(wordlist 1,$(if 
$(GCC_TEST_PARALLEL_SLOTS),$(GCC_TEST_PARALLEL_SLOTS),10),$(check_p_numbers))
+check_p_subdirs=$(wordlist 1,$(if 
$(GCC_TEST_PARALLEL_SLOTS),$(GCC_TEST_PARALLEL_SLOTS),128),$(check_p_numbers))
 check_DEJAGNU_libphobos_targets = $(addprefix 
check-DEJAGNUlibphobos,$(check_p_subdirs))
 $(check_DEJAGNU_libphobos_targets): check-DEJAGNUlibphobos%: 
libphobos%/site.exp
 
diff --git a/libphobos/testsuite/Makefile.in b/libphobos/testsuite/Makefile.in
index 885548018bae..3d3a798f35c1 100644
--- a/libphobos/testsuite/Makefile.in
+++ b/libphobos/testsuite/Makefile.in
@@ -301,7 +301,6 @@ _RUNTEST = $(shell if test -f 
$(top_srcdir)/../dejagnu/runtest; then \
 
 RUNTESTDEFAULTFLAGS = --tool $$tool --srcdir $$srcdir
 PWD_COMMAND = $${PWDCMD-pwd}
-check_p_subno = $(word 2,$(subst _, ,$*))
 check_p_numbers0 := 1 2 3 4 5 6 7 8 9
 check_p_numbers1 := 0 $(check_p_numbers0)
 check_p_numbers2 := $(foreach i,$(check_p_numbers0),$(addprefix 
$(i),$(check_p_numbers1)))
@@ -310,7 +309,7 @@ check_p_numbers4 := $(foreach 
i,$(check_p_numbers0),$(addprefix $(i),$(check_p_n
 check_p_numbers5 := $(addprefix 0,$(check_p_numbers3)) $(check_p_numbers4)
 check_p_numbers6 := $(foreach i,$(check_p_numbers0),$(addprefix 
$(i),$(check_p_numbers5)))
 check_p_numbers := $(check_p_numbers0) $(check_p_numbers2) $(check_p_numbers4) 
$(check_p_numbers6)
-check_p_subdirs = $(wordlist 1,$(if 
$(GCC_TEST_PARALLEL_SLOTS),$(GCC_TEST_PARALLEL_SLOTS),10),$(check_p_numbers))
+check_p_subdirs = $(wordlist 1,$(if 
$(GCC_TEST_PARALLEL_SLOTS),$(GCC_TEST_PARALLEL_SLOTS),128),$(check_p_numbers))
 check_DEJAGNU_libphobos_targets = $(addprefix 
check-DEJAGNUlibphobos,$(check_p_subdirs))
 AM_MAKEFLAGS = "EXEEXT=$(EXEEXT)"
 CLEANFILES = *.exe *.log *.o *.sum site.exp


[gcc r15-9073] d: Bump front-end language version to v2.111.0

2025-03-31 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:2d270bdc31414178ed73caee94e14e78b2212217

commit r15-9073-g2d270bdc31414178ed73caee94e14e78b2212217
Author: Iain Buclaw 
Date:   Mon Mar 31 19:37:38 2025 +0200

d: Bump front-end language version to v2.111.0

Merges the front-end language implementation and runtime library with
upstream dmd c6863be720, and the standard library with phobos 60034b56e.

Synchronizing with the upstream release of v2.111.0.

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd c6863be720.
* dmd/VERSION: Bump version to v2.111.0.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime c6863be720.
* src/MERGE: Merge upstream phobos 60034b56e.

Diff:
---
 gcc/d/dmd/MERGE|  2 +-
 gcc/d/dmd/VERSION  |  2 +-
 gcc/d/dmd/access.d |  4 +--
 gcc/d/dmd/aggregate.d  |  4 +--
 gcc/d/dmd/aliasthis.d  |  4 +--
 gcc/d/dmd/arrayop.d|  4 +--
 gcc/d/dmd/arraytypes.d |  4 +--
 gcc/d/dmd/ast_node.d   |  4 +--
 gcc/d/dmd/astenums.d   |  4 +--
 gcc/d/dmd/attrib.d |  4 +--
 gcc/d/dmd/attribsem.d  |  4 +--
 gcc/d/dmd/blockexit.d  |  4 +--
 gcc/d/dmd/builtin.d|  4 +--
 gcc/d/dmd/canthrow.d   |  4 +--
 gcc/d/dmd/chkformat.d  |  4 +--
 gcc/d/dmd/clone.d  |  4 +--
 gcc/d/dmd/common/bitfields.d   |  4 +--
 gcc/d/dmd/common/charactertables.d |  4 +--
 gcc/d/dmd/common/charactertables.h |  2 +-
 gcc/d/dmd/common/file.d|  4 +--
 gcc/d/dmd/common/outbuffer.d   |  4 +--
 gcc/d/dmd/common/smallbuffer.d |  4 +--
 gcc/d/dmd/compiler.d   |  4 +--
 gcc/d/dmd/cond.d   |  4 +--
 gcc/d/dmd/constfold.d  |  4 +--
 gcc/d/dmd/cparse.d |  4 +--
 gcc/d/dmd/ctfeexpr.d   |  4 +--
 gcc/d/dmd/ctorflow.d   |  4 +--
 gcc/d/dmd/cxxfrontend.d|  4 +--
 gcc/d/dmd/dcast.d  |  4 +--
 gcc/d/dmd/dclass.d |  4 +--
 gcc/d/dmd/declaration.d|  4 +--
 gcc/d/dmd/delegatize.d |  4 +--
 gcc/d/dmd/denum.d  |  4 +--
 gcc/d/dmd/deps.d   |  4 +--
 gcc/d/dmd/dimport.d|  4 +--
 gcc/d/dmd/dinterpret.d |  4 +--
 gcc/d/dmd/dmacro.d |  4 +--
 gcc/d/dmd/dmodule.d|  4 +--
 gcc/d/dmd/doc.d|  4 +--
 gcc/d/dmd/dscope.d |  4 +--
 gcc/d/dmd/dstruct.d|  4 +--
 gcc/d/dmd/dsymbol.d|  4 +--
 gcc/d/dmd/dsymbolsem.d |  4 +--
 gcc/d/dmd/dtemplate.d  |  4 +--
 gcc/d/dmd/dtoh.d   |  4 +--
 gcc/d/dmd/dversion.d   |  4 +--
 gcc/d/dmd/entity.d |  4 +--
 gcc/d/dmd/enumsem.d|  4 +--
 gcc/d/dmd/errors.d |  4 +--
 gcc/d/dmd/errorsink.d  |  4 +--
 gcc/d/dmd/escape.d |  4 +--
 gcc/d/dmd/expression.d |  4 +--
 gcc/d/dmd/expressionsem.d  |  4 +--
 gcc/d/dmd/file_manager.d   |  4 +--
 gcc/d/dmd/func.d   |  4 +--
 gcc/d/dmd/funcsem.d|  4 +--
 gcc/d/dmd/globals.d|  4 +--
 gcc/d/dmd/gluelayer.d  |  4 +--
 gcc/d/dmd/hdrgen.d |  4 +--
 gcc/d/dmd/iasm.d   |  4 +--
 gcc/d/dmd/iasmgcc.d|  4 +--
 gcc/d/dmd/id.d |  4 +--
 gcc/d/dmd/identifier.d |  4 +--
 gcc/d/dmd/impcnvtab.d  |  4 +--
 gcc/d/dmd/imphint.d|  4 +--
 gcc/d/dmd/importc.d|  4 +--
 gcc/d/dmd/init.d   |  4 +--
 gcc/d/dmd/initsem.d|  4 +--
 gcc/d/dmd/inline.d 

[gcc r14-11489] d: Fix error with -Warray-bounds and -O2 [PR117002]

2025-03-31 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:a6a2da499ab8b6b9e52cec5bc32bbd48371bb6ba

commit r14-11489-ga6a2da499ab8b6b9e52cec5bc32bbd48371bb6ba
Author: Iain Buclaw 
Date:   Sat Mar 29 23:16:25 2025 +0100

d: Fix error with -Warray-bounds and -O2 [PR117002]

The record layout of class types in D don't get any tail padding, so it
is possible for the `classInstanceSize' to not be a multiple of the
`classInstanceAlignment'.

Rather than setting the instance alignment on the underlying
RECORD_TYPE, instead give the type an alignment of 1, which will mark it
as TYPE_PACKED.  The value of `classInstanceAlignment' is instead
applied to the DECL_ALIGN of both the static `init' symbol, and the
stack allocated variable used when generating `new' for a `scope' class.

PR d/117002

gcc/d/ChangeLog:

* decl.cc (aggregate_initializer_decl): Set explicit decl alignment 
of
class instance.
* expr.cc (ExprVisitor::visit (NewExp *)): Likewise.
* types.cc (TypeVisitor::visit (TypeClass *)): Mark the record type 
of
classes as packed.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/pr117002.d: New test.

(cherry picked from commit 9fadadbbbc2b5352e5e70e0e1a9be9b447176913)

Diff:
---
 gcc/d/decl.cc   |  6 ++
 gcc/d/expr.cc   |  2 ++
 gcc/d/types.cc  |  3 ++-
 gcc/testsuite/gdc.dg/torture/pr117002.d | 28 
 4 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 7cc203ac8429..a29fd230ca77 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -2394,6 +2394,12 @@ aggregate_initializer_decl (AggregateDeclaration *decl)
   SET_DECL_ALIGN (sinit, sd->alignment.get () * BITS_PER_UNIT);
   DECL_USER_ALIGN (sinit) = true;
 }
+  else if (sd == NULL)
+{
+  /* Alignment of class is determined its biggest field alignment.  */
+  SET_DECL_ALIGN (sinit, decl->alignsize * BITS_PER_UNIT);
+  DECL_USER_ALIGN (sinit) = true;
+}
 
   decl->sinit = sinit;
   return sinit;
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 733302f8e2ee..cc76b09751fb 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -2241,6 +2241,8 @@ public:
   storage class, then the instance is allocated on the stack
   rather than the heap or using the class specific allocator.  */
tree var = build_local_temp (TREE_TYPE (type));
+   SET_DECL_ALIGN (var, cd->alignsize * BITS_PER_UNIT);
+   DECL_USER_ALIGN (var) = 1;
new_call = build_nop (type, build_address (var));
setup_exp = modify_expr (var, aggregate_initializer_decl (cd));
  }
diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index 02f69af166d6..6b045bde0a44 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -1278,7 +1278,8 @@ public:
 build_type_decl (basetype, t->sym);
 set_visibility_for_decl (basetype, t->sym);
 apply_user_attributes (t->sym, basetype);
-finish_aggregate_type (t->sym->structsize, t->sym->alignsize, basetype);
+/* The underlying record type of classes are packed.  */
+finish_aggregate_type (t->sym->structsize, 1, basetype);
 
 /* Classes only live in memory, so always set the TREE_ADDRESSABLE bit.  */
 for (tree tv = basetype; tv != NULL_TREE; tv = TYPE_NEXT_VARIANT (tv))
diff --git a/gcc/testsuite/gdc.dg/torture/pr117002.d 
b/gcc/testsuite/gdc.dg/torture/pr117002.d
new file mode 100644
index ..5b8c19e5b12f
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/pr117002.d
@@ -0,0 +1,28 @@
+// { dg-do compile }
+// { dg-additional-options "-Warray-bounds" }
+extern(C++) class C117002
+{
+ubyte[4] not_multiple_of_8;
+}
+
+int pr117002a(void *p)
+{
+auto init = __traits(initSymbol, C117002);
+if (init.ptr + init.length <= p)
+return 1;
+return 0;
+}
+
+void pr117002b(void *p)
+{
+auto init = __traits(initSymbol, C117002);
+p[0 .. init.length] = init[];
+}
+
+void pr117002c()
+{
+scope var = new C117002;
+void *p = cast(void*)var;
+auto init = __traits(initSymbol, C117002);
+p[0 .. __traits(classInstanceSize, C117002)] = init[];
+}


[gcc r15-9070] d: Fix error with -Warray-bounds and -O2 [PR117002]

2025-04-04 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:9fadadbbbc2b5352e5e70e0e1a9be9b447176913

commit r15-9070-g9fadadbbbc2b5352e5e70e0e1a9be9b447176913
Author: Iain Buclaw 
Date:   Sat Mar 29 23:16:25 2025 +0100

d: Fix error with -Warray-bounds and -O2 [PR117002]

The record layout of class types in D don't get any tail padding, so it
is possible for the `classInstanceSize' to not be a multiple of the
`classInstanceAlignment'.

Rather than setting the instance alignment on the underlying
RECORD_TYPE, instead give the type an alignment of 1, which will mark it
as TYPE_PACKED.  The value of `classInstanceAlignment' is instead
applied to the DECL_ALIGN of both the static `init' symbol, and the
stack allocated variable used when generating `new' for a `scope' class.

PR d/117002

gcc/d/ChangeLog:

* decl.cc (aggregate_initializer_decl): Set explicit decl alignment 
of
class instance.
* expr.cc (ExprVisitor::visit (NewExp *)): Likewise.
* types.cc (TypeVisitor::visit (TypeClass *)): Mark the record type 
of
classes as packed.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/pr117002.d: New test.

Diff:
---
 gcc/d/decl.cc   |  6 ++
 gcc/d/expr.cc   |  2 ++
 gcc/d/types.cc  |  3 ++-
 gcc/testsuite/gdc.dg/torture/pr117002.d | 28 
 4 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 9fcfc5681f8c..250d148e56f4 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -2393,6 +2393,12 @@ aggregate_initializer_decl (AggregateDeclaration *decl)
   SET_DECL_ALIGN (sinit, sd->alignment.get () * BITS_PER_UNIT);
   DECL_USER_ALIGN (sinit) = true;
 }
+  else if (sd == NULL)
+{
+  /* Alignment of class is determined its biggest field alignment.  */
+  SET_DECL_ALIGN (sinit, decl->alignsize * BITS_PER_UNIT);
+  DECL_USER_ALIGN (sinit) = true;
+}
 
   decl->sinit = sinit;
   return sinit;
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 0415763b60d1..46e651457911 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -2243,6 +2243,8 @@ public:
   storage class, then the instance is allocated on the stack
   rather than the heap or using the class specific allocator.  */
tree var = build_local_temp (TREE_TYPE (type));
+   SET_DECL_ALIGN (var, cd->alignsize * BITS_PER_UNIT);
+   DECL_USER_ALIGN (var) = 1;
new_call = build_nop (type, build_address (var));
setup_exp = modify_expr (var, aggregate_initializer_decl (cd));
  }
diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index 98074f1fb687..ea62bc9d05e1 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -1278,7 +1278,8 @@ public:
 build_type_decl (basetype, t->sym);
 set_visibility_for_decl (basetype, t->sym);
 apply_user_attributes (t->sym, basetype);
-finish_aggregate_type (t->sym->structsize, t->sym->alignsize, basetype);
+/* The underlying record type of classes are packed.  */
+finish_aggregate_type (t->sym->structsize, 1, basetype);
 
 /* Classes only live in memory, so always set the TREE_ADDRESSABLE bit.  */
 for (tree tv = basetype; tv != NULL_TREE; tv = TYPE_NEXT_VARIANT (tv))
diff --git a/gcc/testsuite/gdc.dg/torture/pr117002.d 
b/gcc/testsuite/gdc.dg/torture/pr117002.d
new file mode 100644
index ..5b8c19e5b12f
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/pr117002.d
@@ -0,0 +1,28 @@
+// { dg-do compile }
+// { dg-additional-options "-Warray-bounds" }
+extern(C++) class C117002
+{
+ubyte[4] not_multiple_of_8;
+}
+
+int pr117002a(void *p)
+{
+auto init = __traits(initSymbol, C117002);
+if (init.ptr + init.length <= p)
+return 1;
+return 0;
+}
+
+void pr117002b(void *p)
+{
+auto init = __traits(initSymbol, C117002);
+p[0 .. init.length] = init[];
+}
+
+void pr117002c()
+{
+scope var = new C117002;
+void *p = cast(void*)var;
+auto init = __traits(initSymbol, C117002);
+p[0 .. __traits(classInstanceSize, C117002)] = init[];
+}


[gcc r15-8477] d: Fix quoted command-line options to match lang.opt [PR118545]

2025-03-25 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:47822ef8f1b03ab7124aba694709825a93897994

commit r15-8477-g47822ef8f1b03ab7124aba694709825a93897994
Author: Iain Buclaw 
Date:   Fri Mar 21 00:28:45 2025 +0100

d: Fix quoted command-line options to match lang.opt [PR118545]

It was noticed that not all D language options get a url in diagnostics.
These have been checked and fixed as necessary.

PR d/118545

gcc/d/ChangeLog:

* d-lang.cc (d_handle_option): Adjust quoted options.

Diff:
---
 gcc/d/d-lang.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index 8e37fed2b608..21f46ffb6aa8 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -460,7 +460,7 @@ d_handle_option (size_t scode, const char *arg, 
HOST_WIDE_INT value,
  break;
}
 
-  error ("bad argument for %<-fdebug%>: %qs", arg);
+  error ("bad argument for %<-fdebug=%>: %qs", arg);
   break;
 
 case OPT_fdoc:
@@ -533,7 +533,7 @@ d_handle_option (size_t scode, const char *arg, 
HOST_WIDE_INT value,
 case OPT_fmodule_file_:
   global.params.modFileAliasStrings.push (arg);
   if (!strchr (arg, '='))
-   error ("bad argument for %<-fmodule-file%>: %qs", arg);
+   error ("bad argument for %<-fmodule-file=%>: %qs", arg);
   break;
 
 case OPT_fmoduleinfo:
@@ -700,7 +700,7 @@ d_handle_option (size_t scode, const char *arg, 
HOST_WIDE_INT value,
  break;
}
 
-  error ("bad argument for %<-fversion%>: %qs", arg);
+  error ("bad argument for %<-fversion=%>: %qs", arg);
   break;
 
 case OPT_H:


[gcc r15-9162] d: Fix error using UFCS in a speculative context

2025-04-02 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:a66de265ab865aacbb6c4957916605c7bac7ff48

commit r15-9162-ga66de265ab865aacbb6c4957916605c7bac7ff48
Author: Iain Buclaw 
Date:   Wed Apr 2 21:21:14 2025 +0200

d: Fix error using UFCS in a speculative context

This reverts a change in the upstream D implementation of the compiler,
as it is no longer necessary since another fix for opDispatch got
applied in the same area (merged in r12-6003-gfd43568cc54e17).

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd ed17b3e95d.

Reviewed-on: https://github.com/dlang/dmd/pull/21132

Diff:
---
 gcc/d/dmd/MERGE|  2 +-
 gcc/d/dmd/expressionsem.d  | 11 +---
 .../gdc.test/compilable/imports/test21098_phobos.d | 77 ++
 .../gdc.test/compilable/imports/test21098b.d   | 12 
 gcc/testsuite/gdc.test/compilable/test21098.d  |  4 ++
 5 files changed, 97 insertions(+), 9 deletions(-)

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index 00c85187b6de..bd297b612c4e 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-c6863be7206eef3c393726363a480baf0a0c6530
+ed17b3e95dc3fc3264a4c91843da824f5541f3e1
 
 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/expressionsem.d b/gcc/d/dmd/expressionsem.d
index 04efa1f86f13..b0278cbaca1b 100644
--- a/gcc/d/dmd/expressionsem.d
+++ b/gcc/d/dmd/expressionsem.d
@@ -1247,6 +1247,9 @@ private Expression resolveUFCS(Scope* sc, CallExp ce)
 }
 else
 {
+if (arrayExpressionSemantic(ce.arguments.peekSlice(), sc))
+return ErrorExp.get();
+
 if (Expression ey = die.dotIdSemanticProp(sc, 1))
 {
 if (ey.op == EXP.error)
@@ -1254,19 +1257,11 @@ private Expression resolveUFCS(Scope* sc, CallExp ce)
 ce.e1 = ey;
 if (isDotOpDispatch(ey))
 {
-// even opDispatch and UFCS must have valid arguments,
-// so now that we've seen indication of a problem,
-// check them for issues.
-Expressions* originalArguments = 
Expression.arraySyntaxCopy(ce.arguments);
-
 const errors = global.startGagging();
 e = ce.expressionSemantic(sc);
 if (!global.endGagging(errors))
 return e;
 
-if (arrayExpressionSemantic(originalArguments.peekSlice(), 
sc))
-return ErrorExp.get();
-
 /* fall down to UFCS */
 }
 else
diff --git a/gcc/testsuite/gdc.test/compilable/imports/test21098_phobos.d 
b/gcc/testsuite/gdc.test/compilable/imports/test21098_phobos.d
new file mode 100644
index ..29c77eb047af
--- /dev/null
+++ b/gcc/testsuite/gdc.test/compilable/imports/test21098_phobos.d
@@ -0,0 +1,77 @@
+struct Nullable(T)
+{
+static struct DontCallDestructorT
+{
+T payload;
+}
+
+DontCallDestructorT _value;
+
+string toString() const
+{
+Appender!string app;
+formatValueImpl(app, _value);
+return null;
+}
+}
+
+
+
+struct Appender(A)
+{
+InPlaceAppender!A impl;
+}
+
+struct InPlaceAppender(T)
+{
+static void toStringImpl(const T[] data)
+{
+string app;
+formatValue(app, data);
+}
+}
+
+
+
+void formatValueImpl(Writer, T)(Writer, const(T)) {}
+
+void formatValueImpl(Writer, T)(Writer w, T obj)
+if (is(T == U[], U))
+{
+formatValue(w, obj[0]);
+}
+
+enum HasToStringResult
+{
+none,
+bla
+}
+
+template hasToString(T)
+{
+static if (is(typeof(
+(T val) {
+val.toString(s);
+})))
+enum hasToString = HasToStringResult.bla;
+else
+enum hasToString = HasToStringResult.none;
+}
+
+void formatValueImpl(Writer, T)(ref Writer w, T val)
+if (is(T == struct) || is(T == union))
+{
+static if (hasToString!T)
+int dummy;
+formatElement(w, val.tupleof);
+}
+
+void formatElement(Writer, T)(Writer w, T val)
+{
+formatValueImpl(w, val);
+}
+
+void formatValue(Writer, T)(Writer w, T val)
+{
+formatValueImpl(w, val);
+}
diff --git a/gcc/testsuite/gdc.test/compilable/imports/test21098b.d 
b/gcc/testsuite/gdc.test/compilable/imports/test21098b.d
new file mode 100644
index ..74c9fa80c87e
--- /dev/null
+++ b/gcc/testsuite/gdc.test/compilable/imports/test21098b.d
@@ -0,0 +1,12 @@
+import imports.test21098_phobos : Appender, Nullable;
+
+struct Type {
+Nullable!(Type[]) templateArgs;
+}
+
+Type[] parseDeclarations() {
+Appender!(Type[]) members;
+return null;
+}
+
+enum ast = parseDeclarations();
diff --git a/gcc/testsuite/gdc.test/compilable/test21098.d 
b/gcc/testsuite/gdc.test/compilable/test21098.d
new file mode 100644
index ..9b02b7b4d6e3
--- /dev/n

[gcc r13-9480] d: Fix error with -Warray-bounds and -O2 [PR117002]

2025-04-04 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:bfc9520eab16379aa47121d336bfd4d38c6d040a

commit r13-9480-gbfc9520eab16379aa47121d336bfd4d38c6d040a
Author: Iain Buclaw 
Date:   Sat Mar 29 23:16:25 2025 +0100

d: Fix error with -Warray-bounds and -O2 [PR117002]

The record layout of class types in D don't get any tail padding, so it
is possible for the `classInstanceSize' to not be a multiple of the
`classInstanceAlignment'.

Rather than setting the instance alignment on the underlying
RECORD_TYPE, instead give the type an alignment of 1, which will mark it
as TYPE_PACKED.  The value of `classInstanceAlignment' is instead
applied to the DECL_ALIGN of both the static `init' symbol, and the
stack allocated variable used when generating `new' for a `scope' class.

PR d/117002

gcc/d/ChangeLog:

* decl.cc (aggregate_initializer_decl): Set explicit decl alignment 
of
class instance.
* expr.cc (ExprVisitor::visit (NewExp *)): Likewise.
* types.cc (TypeVisitor::visit (TypeClass *)): Mark the record type 
of
classes as packed.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/pr117002.d: New test.

(cherry picked from commit 9fadadbbbc2b5352e5e70e0e1a9be9b447176913)

Diff:
---
 gcc/d/decl.cc   |  6 ++
 gcc/d/expr.cc   |  2 ++
 gcc/d/types.cc  |  3 ++-
 gcc/testsuite/gdc.dg/torture/pr117002.d | 28 
 4 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index deba3335a6a8..945f075cd44e 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -2382,6 +2382,12 @@ aggregate_initializer_decl (AggregateDeclaration *decl)
   SET_DECL_ALIGN (sinit, sd->alignment.get () * BITS_PER_UNIT);
   DECL_USER_ALIGN (sinit) = true;
 }
+  else if (sd == NULL)
+{
+  /* Alignment of class is determined its biggest field alignment.  */
+  SET_DECL_ALIGN (sinit, decl->alignsize * BITS_PER_UNIT);
+  DECL_USER_ALIGN (sinit) = true;
+}
 
   decl->sinit = sinit;
   return sinit;
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 5d91349bf5b5..6ed9554af1bf 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -2261,6 +2261,8 @@ public:
   storage class, then the instance is allocated on the stack
   rather than the heap or using the class specific allocator.  */
tree var = build_local_temp (TREE_TYPE (type));
+   SET_DECL_ALIGN (var, cd->alignsize * BITS_PER_UNIT);
+   DECL_USER_ALIGN (var) = 1;
new_call = build_nop (type, build_address (var));
setup_exp = modify_expr (var, aggregate_initializer_decl (cd));
  }
diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index 32b322c87190..0a8679756b0a 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -1278,7 +1278,8 @@ public:
 build_type_decl (basetype, t->sym);
 set_visibility_for_decl (basetype, t->sym);
 apply_user_attributes (t->sym, basetype);
-finish_aggregate_type (t->sym->structsize, t->sym->alignsize, basetype);
+/* The underlying record type of classes are packed.  */
+finish_aggregate_type (t->sym->structsize, 1, basetype);
 
 /* Classes only live in memory, so always set the TREE_ADDRESSABLE bit.  */
 for (tree tv = basetype; tv != NULL_TREE; tv = TYPE_NEXT_VARIANT (tv))
diff --git a/gcc/testsuite/gdc.dg/torture/pr117002.d 
b/gcc/testsuite/gdc.dg/torture/pr117002.d
new file mode 100644
index ..5b8c19e5b12f
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/pr117002.d
@@ -0,0 +1,28 @@
+// { dg-do compile }
+// { dg-additional-options "-Warray-bounds" }
+extern(C++) class C117002
+{
+ubyte[4] not_multiple_of_8;
+}
+
+int pr117002a(void *p)
+{
+auto init = __traits(initSymbol, C117002);
+if (init.ptr + init.length <= p)
+return 1;
+return 0;
+}
+
+void pr117002b(void *p)
+{
+auto init = __traits(initSymbol, C117002);
+p[0 .. init.length] = init[];
+}
+
+void pr117002c()
+{
+scope var = new C117002;
+void *p = cast(void*)var;
+auto init = __traits(initSymbol, C117002);
+p[0 .. __traits(classInstanceSize, C117002)] = init[];
+}