Re: [PATCH 02/52 v2] d: Replace use of LONG_DOUBLE_TYPE_SIZE

2024-06-04 Thread Iain Buclaw
Excerpts from Kewen.Lin's message of Juni 4, 2024 5:17 am:
> Hi Iain,
> 
> on 2024/6/3 22:39, Iain Buclaw wrote:
>> Excerpts from Kewen.Lin's message of Juni 3, 2024 10:57 am:
>>> Hi Iain,
>>>
>>> on 2024/6/3 16:40, Iain Buclaw wrote:
>>>> Excerpts from Kewen Lin's message of Juni 3, 2024 5:00 am:
>>>>> Joseph pointed out "floating types should have their mode,
>>>>> not a poorly defined precision value" in the discussion[1],
>>>>> as he and Richi suggested, the existing macros
>>>>> {FLOAT,{,LONG_}DOUBLE}_TYPE_SIZE will be replaced with a
>>>>> hook mode_for_floating_type.  To be prepared for that, this
>>>>> patch is to replace use of LONG_DOUBLE_TYPE_SIZE in d with
>>>>> TYPE_PRECISION of long_double_type_node.
>>>>>
>>>>> [1] https://gcc.gnu.org/pipermail/gcc-patches/2024-May/651209.html
>>>>>
>>>>
>>>> Thanks, one question though: Is TYPE_PRECISION really equivalent to
>>>> LONG_DOUBLE_TYPE_SIZE?
>>>
>>> Yes, it's guaranteed by the code in build_common_tree_nodes:
>>>
>>>   long_double_type_node = make_node (REAL_TYPE);
>>>   TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
>>>   layout_type (long_double_type_node);
>>>
>>> , the macro LONG_DOUBLE_TYPE_SIZE is assigned to TYPE_PRECISION of
>>> long_double_type_node, layout_type will only pick up one mode as
>>> the given precision and won't change it.
>>>
>>>>
>>>> Unless LONG_DOUBLE_TYPE_SIZE was poorly named to begin with, I'd assume
>>>> the answer to be "no".
>>>
>>> I'm afraid it's poorly named before.
>>>
>> 
>> Thanks for confirming Kewen.
>> 
>> I suspect then that this code is incorrectly using this macro, and it
>> should instead be using:
>> 
>> int_size_in_bytes(long_double_type_node)
>> 
>> as any padding should be considered as part of the overall type size for
>> the purpose that this field serves in the D part of the front-end.
> 
> Got it, thanks for the explanation and suggestion.
> 
>> 
>> Are you able to update the patch this way instead? Otherwise I'm happy
>> to push the change instead.
> 
> Sure, updated as below:
> 

Thanks!

This is OK to apply any time.

Iain.


Re: [PATCH 02/52] d: Replace use of LONG_DOUBLE_TYPE_SIZE

2024-06-03 Thread Iain Buclaw
Excerpts from Kewen.Lin's message of Juni 3, 2024 10:57 am:
> Hi Iain,
> 
> on 2024/6/3 16:40, Iain Buclaw wrote:
>> Excerpts from Kewen Lin's message of Juni 3, 2024 5:00 am:
>>> Joseph pointed out "floating types should have their mode,
>>> not a poorly defined precision value" in the discussion[1],
>>> as he and Richi suggested, the existing macros
>>> {FLOAT,{,LONG_}DOUBLE}_TYPE_SIZE will be replaced with a
>>> hook mode_for_floating_type.  To be prepared for that, this
>>> patch is to replace use of LONG_DOUBLE_TYPE_SIZE in d with
>>> TYPE_PRECISION of long_double_type_node.
>>>
>>> [1] https://gcc.gnu.org/pipermail/gcc-patches/2024-May/651209.html
>>>
>> 
>> Thanks, one question though: Is TYPE_PRECISION really equivalent to
>> LONG_DOUBLE_TYPE_SIZE?
> 
> Yes, it's guaranteed by the code in build_common_tree_nodes:
> 
>   long_double_type_node = make_node (REAL_TYPE);
>   TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
>   layout_type (long_double_type_node);
> 
> , the macro LONG_DOUBLE_TYPE_SIZE is assigned to TYPE_PRECISION of
> long_double_type_node, layout_type will only pick up one mode as
> the given precision and won't change it.
> 
>> 
>> Unless LONG_DOUBLE_TYPE_SIZE was poorly named to begin with, I'd assume
>> the answer to be "no".
> 
> I'm afraid it's poorly named before.
> 

Thanks for confirming Kewen.

I suspect then that this code is incorrectly using this macro, and it
should instead be using:

int_size_in_bytes(long_double_type_node)

as any padding should be considered as part of the overall type size for
the purpose that this field serves in the D part of the front-end.

Are you able to update the patch this way instead? Otherwise I'm happy
to push the change instead.

Thanks again,
Iain.


Re: [PATCH 02/52] d: Replace use of LONG_DOUBLE_TYPE_SIZE

2024-06-03 Thread Iain Buclaw
Excerpts from Kewen Lin's message of Juni 3, 2024 5:00 am:
> Joseph pointed out "floating types should have their mode,
> not a poorly defined precision value" in the discussion[1],
> as he and Richi suggested, the existing macros
> {FLOAT,{,LONG_}DOUBLE}_TYPE_SIZE will be replaced with a
> hook mode_for_floating_type.  To be prepared for that, this
> patch is to replace use of LONG_DOUBLE_TYPE_SIZE in d with
> TYPE_PRECISION of long_double_type_node.
> 
> [1] https://gcc.gnu.org/pipermail/gcc-patches/2024-May/651209.html
> 

Thanks, one question though: Is TYPE_PRECISION really equivalent to
LONG_DOUBLE_TYPE_SIZE?

Unless LONG_DOUBLE_TYPE_SIZE was poorly named to begin with, I'd assume
the answer to be "no".

i.e: TYPE_PRECISION = 80, but LONG_DOUBLE_TYPE_SIZE = 96 or 128.

Iain.


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

2024-04-19 Thread Iain Buclaw
Hi,

This regression in the D front-end was found to be caused by in some
cases the hidden closure parameter type being generated too early for
nested functions.  Better to update the type after the local
closure/frame type has been completed.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-m64,
committed to mainline, and backporting to releases/gcc-13.

Regards,
Iain.

---
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.
---
 gcc/d/decl.cc   | 20 ++--
 gcc/testsuite/gdc.dg/pr111650.d | 21 +
 2 files changed, 31 insertions(+), 10 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/pr111650.d

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()) { }
-- 
2.40.1



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

2024-04-06 Thread Iain Buclaw
Hi,

This patch merges the D front-end and runtime library with upstream dmd
b65767825f, and the standard library with 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.

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

Regards,
Iain.

---
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.
---
 gcc/d/dmd/MERGE   |  2 +-
 gcc/d/dmd/VERSION |  2 +-
 libphobos/libdruntime/MERGE   |  2 +-
 .../core/internal/array/duplication.d | 14 +-
 libphobos/src/MERGE   |  2 +-
 .../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[]*) 
+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
+++ b/libphobos/src/std/net/curl.d
@@ -2422,6 +2422,7 @@ struct HTTP
 import std.algorithm.searching : findSplit, startsWith;
 import 

Re: [PATCH] libphobos, Darwin: Enable libphobos for most Darwin.

2024-04-02 Thread Iain Buclaw
Excerpts from Iain Sandoe's message of April 2, 2024 1:51 pm:
> I have been building and testing D/libphobos for some time and over
> some GCC and OS releases.  As discussed on IRC a while ago, I think
> we're ready to enable this (it also avoids an annoying build fail at
> stage 2 if one forgets to add the enable to the command line).
> 
> Also tested on x86_64 and powerpc64 linux gnu.
> 
> OK for trunk?
> OK for backports?
> thanks,
> Iain
> 

If you're confident, OK, let's enable it.

Iain.


[committed] d: Merge upstream dmd, druntime 855353a1d9

2024-03-17 Thread Iain Buclaw
Hi,

This patch merges the D front-end and runtime library with upstream dmd
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.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

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

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 855353a1d9.
---
 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 +++-
 .../compilable/named_arguments_auto_ref.d | 39 +
 .../compilable/named_arguments_ifti.d | 27 ++
 .../gdc.test/fail_compilation/hexstring.d |  5 +-
 .../fail_compilation/named_arguments_error.d  | 11 ++-
 .../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 +-
 .../core/internal/gc/impl/manual/gc.d |  2 +-
 .../core/internal/gc/impl/proto/gc.d  |  2 +-
 29 files changed, 294 insertions(+), 107 deletions(-)
 create mode 100644 gcc/testsuite/gdc.test/compilable/named_arguments_auto_ref.d
 create mode 100644 gcc/testsuite/gdc.test/compilable/named_arguments_ifti.d
 create mode 100644 
gcc/testsuite/gdc.test/fail_compilation/named_arguments_ifti_error.d

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;
-case Tint8:
-   

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

2024-03-10 Thread Iain Buclaw
Hi,

This patch removes the early lowering of D AST types as GCC trees in
Target::preferPassByRef, fixing both PR12285 and PR12290.

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.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32, committed
to mainline and backported to releases/gcc-13 and releases/gcc-12.

Regards,
Iain.

---
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.
---
 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(-)
 create mode 100644 gcc/testsuite/gdc.dg/pr112285.d
 create mode 100644 gcc/testsuite/gdc.dg/pr112290.d

diff --git a/gcc/d/d-target.cc b/gcc/d/d-target.cc
index b9d124422b7..9b69b0bc873 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;
+}
-- 
2.40.1



Re: Frontend access to target features (was Re: [PATCH] libgccjit: Add ability to get CPU features)

2024-03-10 Thread Iain Buclaw
Excerpts from David Malcolm's message of März 5, 2024 4:09 pm:
> On Thu, 2023-11-09 at 19:33 -0500, Antoni Boucher wrote:
>> Hi.
>> See answers below.
>> 
>> On Thu, 2023-11-09 at 18:04 -0500, David Malcolm wrote:
>> > On Thu, 2023-11-09 at 17:27 -0500, Antoni Boucher wrote:
>> > > Hi.
>> > > This patch adds support for getting the CPU features in libgccjit
>> > > (bug
>> > > 112466)
>> > > 
>> > > There's a TODO in the test:
>> > > I'm not sure how to test that gcc_jit_target_info_arch returns
>> > > the
>> > > correct value since it is dependant on the CPU.
>> > > Any idea on how to improve this?
>> > > 
>> > > Also, I created a CStringHash to be able to have a
>> > > std::unordered_set. Is there any built-in way of
>> > > doing
>> > > this?
>> > 
>> > Thanks for the patch.
>> > 
>> > Some high-level questions:
>> > 
>> > Is this specifically about detecting capabilities of the host that
>> > libgccjit is currently running on? or how the target was configured
>> > when libgccjit was built?
>> 
>> I'm less sure about this part. I'll need to do more tests.
>> 
>> > 
>> > One of the benefits of libgccjit is that, in theory, we support all
>> > of
>> > the targets that GCC already supports.  Does this patch change
>> > that,
>> > or
>> > is this more about giving client code the ability to determine
>> > capabilities of the specific host being compiled for?
>> 
>> This should not change that. If it does, this is a bug.
>> 
>> > 
>> > I'm nervous about having per-target jit code.  Presumably there's a
>> > reason that we can't reuse existing target logic here - can you
>> > please
>> > describe what the problem is.  I see that the ChangeLog has:
>> > 
>> > > * config/i386/i386-jit.cc: New file.
>> > 
>> > where i386-jit.cc has almost 200 lines of nontrivial code.  Where
>> > did
>> > this come from?  Did you base it on existing code in our source
>> > tree,
>> > making modifications to fit the new internal API, or did you write
>> > it
>> > from scratch?  In either case, how onerous would this be for other
>> > targets?
>> 
>> This was mostly copied from the same code done for the Rust and D
>> frontends.
>> See this commit and the following:
>> https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=b1c06fd9723453dd2b2ec306684cb806dc2b4fbb
>> The equivalent to i386-jit.cc is there:
>> https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=22e3557e2d52f129f2bbfdc98688b945dba28dc9
> 
> [CCing Iain and Arthur re those patches; for reference, the patch being
> discussed is attached to :
> https://gcc.gnu.org/pipermail/jit/2024q1/001792.html ]
> 
> One of my concerns about this patch is that we seem to be gaining code
> that's per-(frontend x config) which seems to be copied and pasted with
> a search and replace, which could lead to an M*N explosion.
> 

That's certainly the case with the configure/make rules. Itself I think
is copied originally from the {cpu_type}-protos.h machinery.

It might be worth pointing out that the c-family of front-ends don't
have separate headers because their per-target macros are defined in
{cpu_type}.h directly - for better or worse.

> Is there any real difference between the per-config code for the
> different frontends, or should there be a general "enumerate all
> features of the target" hook that's independent of the frontend? (but
> perhaps calls into it).
> 

As far as I understand, the configure parts should all be identical
between tm_p, tm_d, tm_rust, ..., so would benefit from being templated
to aid any other front-ends adding in their own per target hooks.

> Am I right in thinking that (rustc with default LLVM backend) has some
> set of feature strings that both (rustc with rustc_codegen_gcc) and
> gccrs are trying to emulate?  If so, is it presumably a goal that
> libgccjit gives identical results to gccrs?  If so, would it be crazy
> for libgccjit to consume e.g. config/i386/i386-rust.cc ?

I don't know whether libgccjit can just pull in directly the
implementation of the rust target hooks here.  The per-frontend target
hooks usually also make use of code specific to that front-end -
TARGET_CPU_CPP_BUILTINS and others can't be used by a non-c-family
front-end without adding a plethora of stubs, for example.

Whether or not libgccjit wants to give identical information as as rust
I think is a decision for you as the maintainer of its API.

Iain.


Re: [committed] d: Fix gdc -O2 -mavx generates misaligned vmovdqa instruction [PR114171]

2024-03-03 Thread Iain Buclaw
Excerpts from Andrew Pinski's message of März 3, 2024 11:49 pm:
> On Sat, Mar 2, 2024 at 5:51 PM Iain Buclaw  wrote:
>>
>> Hi,
>>
>> This patch fixes a wrong code issue in the D front-end where lowered
>> struct comparisons would reinterpret fields with a different (usually
>> bigger) alignment than the original.  Use `build_aligned_type' to
>> preserve the alignment when casting away for such comparisons.
>>
>> Bootstrapped and regression tested on x86_64-linux-gnu/-m32, committed
>> to mainline, and backported to releases/gcc-13, releases/gcc-12, and
>> releases/gcc-11.
>>
>> Regards,
>> Iain.
>> ---
>> PR d/114171
>>
>> gcc/d/ChangeLog:
>>
>> * d-codegen.cc (lower_struct_comparison): Keep alignment of original
>> type in reinterpret cast for comparison.
>>
>> gcc/testsuite/ChangeLog:
>>
>> * gdc.dg/torture/pr114171.d: New test.
>> ---
>>  gcc/d/d-codegen.cc  |  1 +
>>  gcc/testsuite/gdc.dg/torture/pr114171.d | 29 +
>>  2 files changed, 30 insertions(+)
>>  create mode 100644 gcc/testsuite/gdc.dg/torture/pr114171.d
>>
>> diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
>> index 5bc233928aa..43d7739f8fc 100644
>> --- a/gcc/d/d-codegen.cc
>> +++ b/gcc/d/d-codegen.cc
>> @@ -1006,6 +1006,7 @@ lower_struct_comparison (tree_code code, 
>> StructDeclaration *sd,
>>   if (tmode == NULL_TREE)
>> tmode = make_unsigned_type (GET_MODE_BITSIZE (mode.require 
>> ()));
>>
>> + tmode = build_aligned_type (tmode, TYPE_ALIGN (stype));
> 
> You might also need to build a may_alias variant too. Or make sure the
> access is using the correct aliasing set.
> I have not checked if the D front-end does anything special for
> aliasing sets so I am not sure if that is needed or not but I suspect
> it is.
> 

There are no alias sets defined in the D front-end - the reference
compiler doesn't enforce it, which has allowed enough code out there
to expect modifying bits (eg: of a float) through a reinterpret cast
(such as an int*) to just work.

Thanks for the reminder though.
Iain.


[committed] d: Merge upstream dmd, druntime f8bae04558, phobos ba2ade9dec

2024-03-03 Thread Iain Buclaw
Hi,

This patch merges the D front-end and runtime library with upstream dmd
f8bae04558, and the standard library with phobos ba2ade9dec

D front-end changes:

- Import dmd v2.108.1-beta-1.

D runtime changes:

- Import druntime v2.108.1-beta-1.

Phobos changes:

- Import phobos v2.108.1-beta-1.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd f8bae04558.
* dmd/VERSION: Bump version to v2.108.0-beta.1.
* d-builtins.cc (build_frontend_type): Update for new front-end
interface.
* d-codegen.cc (build_assert_call): Likewise.
* d-convert.cc (d_array_convert): Likewise.
* decl.cc (get_vtable_decl): Likewise.
* expr.cc (ExprVisitor::visit (EqualExp *)): Likewise.
(ExprVisitor::visit (VarExp *)): Likewise.
(ExprVisitor::visit (ArrayLiteralExp *)): Likewise.
(ExprVisitor::visit (AssocArrayLiteralExp)): Likewise.
* intrinsics.cc (build_shuffle_mask_type): Likewise.
(maybe_warn_intrinsic_mismatch): Likewise.
* runtime.cc (get_libcall_type): Likewise.
* typeinfo.cc (TypeInfoVisitor::layout_string): Likewise.
(TypeInfoVisitor::visit(TypeInfoTupleDeclaration *)): Likewise.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 02d6d07a69.
* src/MERGE: Merge upstream phobos a2ade9dec.
---
 gcc/d/d-builtins.cc   |   6 +-
 gcc/d/d-codegen.cc|   2 +-
 gcc/d/d-convert.cc|   4 +-
 gcc/d/decl.cc |   2 +-
 gcc/d/dmd/MERGE   |   2 +-
 gcc/d/dmd/VERSION |   2 +-
 gcc/d/dmd/constfold.d |   2 +-
 gcc/d/dmd/cparse.d|   8 +-
 gcc/d/dmd/cxxfrontend.d   |  36 ++
 gcc/d/dmd/denum.d |   1 -
 gcc/d/dmd/dinterpret.d|   4 +-
 gcc/d/dmd/dmodule.d   |  16 +-
 gcc/d/dmd/expressionsem.d |  14 +-
 gcc/d/dmd/func.d  | 176 --
 gcc/d/dmd/funcsem.d   | 168 +
 gcc/d/dmd/location.d  |  10 +-
 gcc/d/dmd/mtype.d | 321 +-
 gcc/d/dmd/mtype.h |  14 +-
 gcc/d/dmd/optimize.d  |   2 +-
 gcc/d/dmd/safe.d  |   2 +-
 gcc/d/dmd/typesem.d   | 317 -
 gcc/d/expr.cc |  21 +-
 gcc/d/intrinsics.cc   |   6 +-
 gcc/d/runtime.cc  |  20 +-
 gcc/d/typeinfo.cc |   4 +-
 .../gdc.test/compilable/issue24399.d  |   9 +
 .../gdc.test/compilable/issue24409.d  |  17 +
 gcc/testsuite/gdc.test/runnable/issue24401.d  |   6 +
 gcc/testsuite/gdc.test/runnable/test24371.d   |  15 +
 .../gdc.test/runnable_cxx/test7925.d  |   7 -
 libphobos/libdruntime/MERGE   |   2 +-
 libphobos/libdruntime/core/exception.d|  13 +
 .../libdruntime/core/sys/linux/ifaddrs.d  |  11 +-
 .../libdruntime/core/sys/posix/sys/select.d   |  44 +--
 libphobos/src/MERGE   |   2 +-
 libphobos/src/etc/c/zlib.d|  49 +--
 36 files changed, 717 insertions(+), 618 deletions(-)
 create mode 100644 gcc/testsuite/gdc.test/compilable/issue24399.d
 create mode 100644 gcc/testsuite/gdc.test/compilable/issue24409.d
 create mode 100644 gcc/testsuite/gdc.test/runnable/issue24401.d
 create mode 100644 gcc/testsuite/gdc.test/runnable/test24371.d

diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index dc50df4252c..4546c0e9b56 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -197,8 +197,8 @@ build_frontend_type (tree type)
  length = size_binop (PLUS_EXPR, size_one_node,
   convert (sizetype, length));
 
- dtype =
-   dmd::addMod (dtype->sarrayOf (TREE_INT_CST_LOW (length)), mod);
+ dtype = dmd::sarrayOf (dtype, TREE_INT_CST_LOW (length));
+ dtype = dmd::addMod (dtype, mod);
  builtin_converted_decls.safe_push (builtin_data (dtype, type));
  return dtype;
}
@@ -214,7 +214,7 @@ build_frontend_type (tree type)
   if (!dtype)
break;
 
-  dtype = dmd::addMod (dtype->sarrayOf (nunits), mod);
+  dtype = dmd::addMod (dmd::sarrayOf (dtype, nunits), mod);
   if (target.isVectorTypeSupported (dtype->size (), dtype->nextOf ()))
break;
 
diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 43d7739f8fc..2b3089b5f6d 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -1906,7 +1906,7 @@ build_assert_call (const Loc , libcall_fn libcall, 

Re: [committed] d: Fix gdc -O2 -mavx generates misaligned vmovdqa instruction [PR114171]

2024-03-03 Thread Iain Buclaw
Excerpts from Richard Biener's message of März 3, 2024 11:41 am:
> 
> 
>> Am 03.03.2024 um 02:51 schrieb Iain Buclaw :
>> 
>> Hi,
>> 
>> This patch fixes a wrong code issue in the D front-end where lowered
>> struct comparisons would reinterpret fields with a different (usually
>> bigger) alignment than the original.  Use `build_aligned_type' to
>> preserve the alignment when casting away for such comparisons.
>> 
>> Bootstrapped and regression tested on x86_64-linux-gnu/-m32, committed
>> to mainline, and backported to releases/gcc-13, releases/gcc-12, and
>> releases/gcc-11.
> 
> LGTM.  You might want to experiment with not doing the premature optimization 
> but instead use __builtin_memcmp_eq (assuming that’s a general good fit).  
> The middle-end should better turn that into target optimal code.
> 

Indeed, just looking at the history, it was introduced well over ten
years ago so I can't comment on the original context for it (it doesn't
directly fix any old issues).

Small comparison between this optimization and memcmp_eq
---
  _5 = newitem ();
  # DEBUG bn => _5
  _1 = MEM[(ucent *)_5 + 8B];
  _2 = _1 != 0;
  _6 = (int) _2;
  return _6;
---
call_D8pr1141717newitemFNbNiZPSQz2S2
.LVL29:
vmovdqu 8(%rax), %xmm0
xorl%eax, %eax
.LVL30:
vptest  %xmm0, %xmm0
setne   %al
addq$8, %rsp
ret


---
  _6 = newitem ();
  # DEBUG bn => _6
  D.2335.length = 0;
  D.2335.ptr = 0B;
  _1 = &_6->label.label;
  _2 = __builtin_memcmp_eq (_1, , 16);
  _3 = _2 != 0;
  _9 = (int) _3;
  return _9;
---
call_D8pr1141717newitemFNbNiZPSQz2S2
.LVL29:
movq$0, (%rsp)
movq$0, 8(%rsp)
vmovdqu 8(%rax), %xmm0
xorl%eax, %eax
.LVL30:
vpxor   (%rsp), %xmm0, %xmm0
vptest  %xmm0, %xmm0
setne   %al
addq$24, %rsp
ret


[committed] d: Fix gdc -O2 -mavx generates misaligned vmovdqa instruction [PR114171]

2024-03-02 Thread Iain Buclaw
Hi,

This patch fixes a wrong code issue in the D front-end where lowered
struct comparisons would reinterpret fields with a different (usually
bigger) alignment than the original.  Use `build_aligned_type' to
preserve the alignment when casting away for such comparisons.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32, committed
to mainline, and backported to releases/gcc-13, releases/gcc-12, and
releases/gcc-11.

Regards,
Iain.
---
PR d/114171

gcc/d/ChangeLog:

* d-codegen.cc (lower_struct_comparison): Keep alignment of original
type in reinterpret cast for comparison.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/pr114171.d: New test.
---
 gcc/d/d-codegen.cc  |  1 +
 gcc/testsuite/gdc.dg/torture/pr114171.d | 29 +
 2 files changed, 30 insertions(+)
 create mode 100644 gcc/testsuite/gdc.dg/torture/pr114171.d

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 5bc233928aa..43d7739f8fc 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -1006,6 +1006,7 @@ lower_struct_comparison (tree_code code, 
StructDeclaration *sd,
  if (tmode == NULL_TREE)
tmode = make_unsigned_type (GET_MODE_BITSIZE (mode.require ()));
 
+ tmode = build_aligned_type (tmode, TYPE_ALIGN (stype));
  t1ref = build_vconvert (tmode, t1ref);
  t2ref = build_vconvert (tmode, t2ref);
 
diff --git a/gcc/testsuite/gdc.dg/torture/pr114171.d 
b/gcc/testsuite/gdc.dg/torture/pr114171.d
new file mode 100644
index 000..0f9ffcab916
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/pr114171.d
@@ -0,0 +1,29 @@
+// { dg-do run }
+// { dg-additional-options "-mavx" { target avx_runtime } }
+// { dg-skip-if "needs gcc/config.d" { ! d_runtime } }
+import gcc.builtins;
+
+struct S1
+{
+string label;
+}
+
+struct S2
+{
+ulong pad;
+S1 label;
+}
+
+pragma(inline, false)
+auto newitem()
+{
+void *p = __builtin_malloc(S2.sizeof);
+__builtin_memset(p, 0, S2.sizeof);
+return cast(S2*) p;
+}
+
+int main()
+{
+auto bn = newitem();
+return bn.label is S1.init ? 0 : 1;
+}
-- 
2.40.1



[committed][GCC13] d: Fix callee destructor call invalidates the live object [PR113758]

2024-03-02 Thread Iain Buclaw
Hi,

This patch backports a fix to code generation when passing objects by
invisible reference that have a defined cpctor or dtor.

When generating the argument, check the isCalleeDestroyingArgs hook, and
force a TARGET_EXPR to be created if true, so that a reference to the
live object isn't passed directly to the function that runs dtors.

When instead dealing with caller running destructors, two temporaries
were being generated, one explicit temporary generated by the D
front-end, and another implicitly by the code generator.  This has been
reduced to one by setting DECL_VALUE_EXPR on the explicit temporary to
bind it to the implicit slot created for the TARGET_EXPR, as that has
the shorter lifetime of the two.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32, backported
to releases/gcc-13, releases/gcc-12, and releases/gcc-11.

Regards,
Iain.

---
PR d/113758

gcc/d/ChangeLog:

* d-codegen.cc (d_build_call): Force a TARGET_EXPR when callee
destorys its arguments.
* decl.cc (DeclVisitor::visit (VarDeclaration *)): Set
SET_DECL_VALUE_EXPR on the temporary variable to make it a placeholder
for the TARGET_EXPR_SLOT.

gcc/testsuite/ChangeLog:

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

(cherry picked from commit 3c57b1c12a8e34d50bdf6aaf44146760db6d1b33)
---
 gcc/d/d-codegen.cc  | 15 +++
 gcc/d/decl.cc   | 22 --
 gcc/testsuite/gdc.dg/torture/pr113758.d | 19 +++
 3 files changed, 50 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/torture/pr113758.d

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 8fe659ad527..b8e4b83d2de 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -2213,10 +2213,17 @@ d_build_call (TypeFunction *tf, tree callable, tree 
object,
  Type *t = arg->type->toBasetype ();
  StructDeclaration *sd = t->baseElemOf ()->isTypeStruct ()->sym;
 
- /* Nested structs also have ADDRESSABLE set, but if the type has
-neither a copy constructor nor a destructor available, then we
-need to take care of copying its value before passing it.  */
- if (arg->op == EXP::structLiteral || (!sd->postblit && !sd->dtor))
+ /* Need to take care of copying its value before passing the
+argument in the following scenarios:
+- The argument is a literal expression; a CONSTRUCTOR can't
+have its address taken.
+- The type has neither a copy constructor nor a destructor
+available; nested structs also have ADDRESSABLE set.
+- The ABI of the function expects the callee to destroy its
+arguments; when the caller is handles destruction, then `targ'
+has already been made into a temporary. */
+ if (arg->op == EXP::structLiteral || (!sd->postblit && !sd->dtor)
+ || target.isCalleeDestroyingArgs (tf))
targ = force_target_expr (targ);
 
  targ = convert (build_reference_type (TREE_TYPE (targ)),
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 0375ede082b..2a135b516aa 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -860,10 +860,28 @@ public:
/* Maybe put variable on list of things needing destruction.  */
if (d->needsScopeDtor ())
  {
+   /* Rewrite: `decl = exp' => TARGET_EXPR(decl, exp, dtor).  */
vec_safe_push (d_function_chain->vars_in_scope, decl);
+
/* Force a TARGET_EXPR to add the corresponding cleanup.  */
-   exp = force_target_expr (compound_expr (exp, decl));
-   TARGET_EXPR_CLEANUP (exp) = build_expr (d->edtor);
+   if (TREE_CODE (exp) != TARGET_EXPR)
+ {
+   if (VOID_TYPE_P (TREE_TYPE (exp)))
+ exp = compound_expr (exp, decl);
+
+   exp = force_target_expr (exp);
+ }
+
+   TARGET_EXPR_CLEANUP (exp)
+ = compound_expr (TARGET_EXPR_CLEANUP (exp),
+  build_expr (d->edtor));
+
+   /* The decl is really an alias for the TARGET_EXPR slot.  */
+   SET_DECL_VALUE_EXPR (decl, TARGET_EXPR_SLOT (exp));
+   DECL_HAS_VALUE_EXPR_P (decl) = 1;
+   /* This tells the gimplifier not to emit a clobber for the decl
+  as its lifetime ends when the slot gets cleaned up.  */
+   TREE_ADDRESSABLE (decl) = 0;
  }
 
add_stmt (exp);
diff --git a/gcc/testsuite/gdc.dg/torture/pr113758.d 
b/gcc/testsuite/gdc.dg/torture/pr113758.d
new file mode 100644
index 000..dc53883a8de
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/pr113758.d
@@ -0,0 +1,19 @@
+// { dg-do run }
+// { dg-skip-if "needs gcc/config.d" { ! d_runtime 

[committed][GCC13] d: Fix internal compiler error: in make_import, at d/imports.cc:48 [PR113125]

2024-03-02 Thread Iain Buclaw
Hi,

This patch backports an ICE triggered in the D front-end.

The cause of the ICE was that TYPE_DECLs were only being generated for
structs with members, not opaque structs.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32, backported
to releases/gcc-13, releases/gcc-12, and releases/gcc-11.

Regards,
Iain.

---
PR d/113125

gcc/d/ChangeLog:

* types.cc (TypeVisitor::visit (TypeStruct *)): Generate TYPE_DECL and
apply UDAs to opaque struct declarations.

gcc/testsuite/ChangeLog:

* gdc.dg/imports/pr113125.d: New test.
* gdc.dg/pr113125.d: New test.

(cherry picked from commit b0efb1c35724e3332ee5993976efb98200c1a154)
---
 gcc/d/types.cc  | 5 +
 gcc/testsuite/gdc.dg/imports/pr113125.d | 2 ++
 gcc/testsuite/gdc.dg/pr113125.d | 4 
 3 files changed, 11 insertions(+)
 create mode 100644 gcc/testsuite/gdc.dg/imports/pr113125.d
 create mode 100644 gcc/testsuite/gdc.dg/pr113125.d

diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index f19779fec7d..05050f9edd0 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -1230,6 +1230,11 @@ public:
apply_user_attributes (t->sym, t->ctype);
finish_aggregate_type (structsize, alignsize, t->ctype);
   }
+else
+  {
+   build_type_decl (t->ctype, t->sym);
+   apply_user_attributes (t->sym, t->ctype);
+  }
 
 /* For structs with a user defined postblit, copy constructor, or a
destructor, also set TREE_ADDRESSABLE on the type and all variants.
diff --git a/gcc/testsuite/gdc.dg/imports/pr113125.d 
b/gcc/testsuite/gdc.dg/imports/pr113125.d
new file mode 100644
index 000..761e613b055
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/imports/pr113125.d
@@ -0,0 +1,2 @@
+module imports.pr113125;
+struct S113125;
diff --git a/gcc/testsuite/gdc.dg/pr113125.d b/gcc/testsuite/gdc.dg/pr113125.d
new file mode 100644
index 000..cb7300baa1a
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr113125.d
@@ -0,0 +1,4 @@
+// { dg-do compile }
+// { dg-options "-I $srcdir/gdc.dg" }
+module pr113125;
+import imports.pr113125: S113125;
-- 
2.40.1



[committed] d: Merge dmd, druntime ceff48bf7d, phobos dcbfbd43a

2024-02-25 Thread Iain Buclaw
Hi,

This patch merges the D front-end and runtime library with upstream dmd
ceff48bf7d, and the standard library with phobos dcbfbd43a.

D front-end changes:

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

D runtime changes:

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

Phobos changes:

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

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd ceff48bf7d.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime ceff48bf7d.
* libdruntime/Makefile.am (DRUNTIME_DSOURCES_FREEBSD): Add
core/sys/freebsd/net/if_.d.
* libdruntime/Makefile.in: Regenerate.
* src/MERGE: Merge upstream phobos dcbfbd43a.
---
 gcc/d/dmd/MERGE   |   2 +-
 gcc/d/dmd/arrayop.d   |   2 +-
 gcc/d/dmd/ast_node.h  |   2 +-
 gcc/d/dmd/common/file.d   |  89 ++--
 gcc/d/dmd/common/smallbuffer.d|  30 +-
 gcc/d/dmd/cparse.d| 150 +-
 gcc/d/dmd/dimport.d   | 109 +---
 gcc/d/dmd/dmodule.d   |  32 +-
 gcc/d/dmd/dsymbolsem.d|  97 
 gcc/d/dmd/expression.d|   4 +-
 gcc/d/dmd/expression.h|   2 +-
 gcc/d/dmd/expressionsem.d |  97 
 gcc/d/dmd/func.d  | 394 +-
 gcc/d/dmd/funcsem.d   | 390 ++
 gcc/d/dmd/identifier.h|   2 +-
 gcc/d/dmd/importc.d   |   7 +-
 gcc/d/dmd/mtype.d |   1 -
 gcc/d/dmd/parse.d |  48 +-
 gcc/d/dmd/root/array.h|   3 +-
 gcc/d/dmd/root/bitarray.h |   1 -
 gcc/d/dmd/{root/object.h => rootobject.h} |   6 +-
 gcc/d/dmd/statementsem.d  |   2 +-
 gcc/d/dmd/staticcond.d| 107 
 gcc/d/dmd/template.h  |   2 +-
 .../gdc.test/compilable/imports/defines.c |  25 +
 .../gdc.test/compilable/testdefines.d |  10 +
 .../gdc.test/fail_compilation/warn13679.d |   4 +-
 libphobos/libdruntime/MERGE   |   2 +-
 libphobos/libdruntime/Makefile.am |  22 +-
 libphobos/libdruntime/Makefile.in |  31 +-
 .../libdruntime/core/sys/freebsd/ifaddrs.d|   3 +-
 .../libdruntime/core/sys/freebsd/net/if_.d| 493 ++
 .../libdruntime/core/sys/linux/sys/socket.d   |   1 -
 libphobos/libdruntime/core/thread/fiber.d |   2 +-
 libphobos/src/MERGE   |   2 +-
 libphobos/src/std/typecons.d  |  35 +-
 36 files changed, 1417 insertions(+), 792 deletions(-)
 rename gcc/d/dmd/{root/object.h => rootobject.h} (91%)
 create mode 100644 libphobos/libdruntime/core/sys/freebsd/net/if_.d

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index 021149aabc7..f11c5fbfb0b 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-9471b25db9ed44d71e0e27956430c0c6a09c16db
+ceff48bf7db05503117f54fdc0cefcb89b711136
 
 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/arrayop.d b/gcc/d/dmd/arrayop.d
index afe6054f4aa..af3875ea6c5 100644
--- a/gcc/d/dmd/arrayop.d
+++ b/gcc/d/dmd/arrayop.d
@@ -22,7 +22,7 @@ import dmd.dsymbol;
 import dmd.errors;
 import dmd.expression;
 import dmd.expressionsem;
-import dmd.func;
+import dmd.funcsem;
 import dmd.hdrgen;
 import dmd.id;
 import dmd.identifier;
diff --git a/gcc/d/dmd/ast_node.h b/gcc/d/dmd/ast_node.h
index a24218a86d0..db8608e7cdd 100644
--- a/gcc/d/dmd/ast_node.h
+++ b/gcc/d/dmd/ast_node.h
@@ -10,7 +10,7 @@
 
 #pragma once
 
-#include "root/object.h"
+#include "rootobject.h"
 
 class Visitor;
 
diff --git a/gcc/d/dmd/common/file.d b/gcc/d/dmd/common/file.d
index 8a284241fc2..80677f66ff8 100644
--- a/gcc/d/dmd/common/file.d
+++ b/gcc/d/dmd/common/file.d
@@ -16,24 +16,37 @@ module dmd.common.file;
 
 import core.stdc.errno : errno;
 import core.stdc.stdio : fprintf, remove, rename, stderr;
-import core.stdc.stdlib : exit;
-import core.stdc.string : strerror, strlen;
-import core.sys.windows.winbase;
-import core.sys.windows.winnt;
-import core.sys.posix.fcntl;
-import core.sys.posix.unistd;
+import core.stdc.stdlib;
+import core.stdc.string : strerror, strlen, memcpy;
 
 import dmd.common.smallbuffer;
 
-nothrow:
-
 version (Windows)
 {
+import core.sys.windows.winbase;
 import core.sys.windows.winnls : CP_ACP;
+import core.sys.windows.winnt;
+
+enum CodePage = CP_ACP; // assume filenames encoded in system default 
Windows ANSI code page
+enum invalidHandle = INVALID_HANDLE_VALUE;
+}
+else version (Posix)
+{

Re: [PATCH v10 2/2] Add gcov MC/DC tests for GDC

2024-02-23 Thread Iain Buclaw
Excerpts from Jørgen Kvalsvik's message of Februar 23, 2024 12:18 pm:
> This is a mostly straight port from the gcov-19.c tests from the C test
> suite. The only notable differences from C to D are that D flips the
> true/false outcomes for loop headers, and the D front end ties loop and
> ternary conditions to slightly different locus.
> 
> The test for >64 conditions warning is disabled as it either needs
> support from the testing framework or a something similar to #pragma GCC
> diagnostic push to not cause a test failure from detecting a warning.
> 
> gcc/testsuite/ChangeLog:
> 
>   * gdc.dg/gcov.exp: New test.
>   * gdc.dg/gcov1.d: New test.
> ---
>  gcc/testsuite/gdc.dg/gcov.exp |   44 +
>  gcc/testsuite/gdc.dg/gcov1.d  | 1712 +
>  2 files changed, 1756 insertions(+)
>  create mode 100644 gcc/testsuite/gdc.dg/gcov.exp
>  create mode 100644 gcc/testsuite/gdc.dg/gcov1.d
> 

I think I said this before in the previous series, no objections to
adding more tests to the gdc testsuite.

OK.

Thanks,
Iain.


[committed] d: Add UTF BOM tests to gdc.dg testsuite

2024-02-19 Thread Iain Buclaw
Hi,

This patch checks in a few combinations of UTF BOM/no-BOM tests to the
gdc.dg testsuite.

Some of these are part of the upstream DMD `gdc.test' testsuite, but
they had been omitted because they get mangled by the lib/gdc-utils.exp
helpers when parsing and staging the tests. Translate them over to the
gdc.dg testsuite instead.

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

Regards,
Iain.

---
gcc/testsuite/ChangeLog:

* gdc.dg/bom_UTF16BE.d: New test.
* gdc.dg/bom_UTF16LE.d: New test.
* gdc.dg/bom_UTF32BE.d: New test.
* gdc.dg/bom_UTF32LE.d: New test.
* gdc.dg/bom_UTF8.d: New test.
* gdc.dg/bom_characters.d: New test.
* gdc.dg/bom_error_UTF8.d: New test.
* gdc.dg/bom_infer_UTF16BE.d: New test.
* gdc.dg/bom_infer_UTF16LE.d: New test.
* gdc.dg/bom_infer_UTF32BE.d: New test.
* gdc.dg/bom_infer_UTF32LE.d: New test.
* gdc.dg/bom_infer_UTF8.d: New test.
---
 gcc/testsuite/gdc.dg/bom_UTF16BE.d   | Bin 0 -> 300 bytes
 gcc/testsuite/gdc.dg/bom_UTF16LE.d   | Bin 0 -> 300 bytes
 gcc/testsuite/gdc.dg/bom_UTF32BE.d   | Bin 0 -> 556 bytes
 gcc/testsuite/gdc.dg/bom_UTF32LE.d   | Bin 0 -> 556 bytes
 gcc/testsuite/gdc.dg/bom_UTF8.d  |  11 +++
 gcc/testsuite/gdc.dg/bom_characters.d| Bin 0 -> 780 bytes
 gcc/testsuite/gdc.dg/bom_error_UTF8.d|  11 +++
 gcc/testsuite/gdc.dg/bom_infer_UTF16BE.d | Bin 0 -> 298 bytes
 gcc/testsuite/gdc.dg/bom_infer_UTF16LE.d | Bin 0 -> 298 bytes
 gcc/testsuite/gdc.dg/bom_infer_UTF32BE.d | Bin 0 -> 552 bytes
 gcc/testsuite/gdc.dg/bom_infer_UTF32LE.d | Bin 0 -> 552 bytes
 gcc/testsuite/gdc.dg/bom_infer_UTF8.d|  11 +++
 12 files changed, 33 insertions(+)
 create mode 100644 gcc/testsuite/gdc.dg/bom_UTF16BE.d
 create mode 100644 gcc/testsuite/gdc.dg/bom_UTF16LE.d
 create mode 100644 gcc/testsuite/gdc.dg/bom_UTF32BE.d
 create mode 100644 gcc/testsuite/gdc.dg/bom_UTF32LE.d
 create mode 100644 gcc/testsuite/gdc.dg/bom_UTF8.d
 create mode 100644 gcc/testsuite/gdc.dg/bom_characters.d
 create mode 100644 gcc/testsuite/gdc.dg/bom_error_UTF8.d
 create mode 100644 gcc/testsuite/gdc.dg/bom_infer_UTF16BE.d
 create mode 100644 gcc/testsuite/gdc.dg/bom_infer_UTF16LE.d
 create mode 100644 gcc/testsuite/gdc.dg/bom_infer_UTF32BE.d
 create mode 100644 gcc/testsuite/gdc.dg/bom_infer_UTF32LE.d
 create mode 100644 gcc/testsuite/gdc.dg/bom_infer_UTF8.d

diff --git a/gcc/testsuite/gdc.dg/bom_UTF16BE.d 
b/gcc/testsuite/gdc.dg/bom_UTF16BE.d
new file mode 100644
index 
..f18cec9b1e597b96e27c8650bac552ccb5bde54e
GIT binary patch
literal 300
zcmY+9%?iRm41~Y4;5#fmwc_7dkG_T%-L6{cAGM-Te06np+kz5ynCv8z}60;*=6SPcuE2mmY*
zoRV8mEEf(^4KwD#Wr*a*d-Nz&=Xor5KeG#H)Z^oSLL^tGjq`BVL)eI??A0Hszu$c9
QZB*OpLchIXJ*eUOFJQ(j-2eap

literal 0
HcmV?d1

diff --git a/gcc/testsuite/gdc.dg/bom_UTF16LE.d 
b/gcc/testsuite/gdc.dg/bom_UTF16LE.d
new file mode 100644
index 
..e79a4ddbce1617edc38aa2b8aec61698d200461e
GIT binary patch
literal 300
zcmY+9%?iRm41~Y4;5#fmwW8Lu9{U$vtW9aoV
z%Mu$SJVOU(A{5r$q~yP3U5qaGLk69TzfZCv=f9>P{UW3T=|{ln%{
RZ>!o)7rN~Yn^7IE{{oAqEZqPA

literal 0
HcmV?d1

diff --git a/gcc/testsuite/gdc.dg/bom_UTF32BE.d 
b/gcc/testsuite/gdc.dg/bom_UTF32BE.d
new file mode 100644
index 
..eaf3b04b458fe51bf8b3726af5970ded60f19ad6
GIT binary patch
literal 556
zcmaLUxvD}j5P;#-KE+_A;#O;UU?I!3`G_#8+4UUrr$0!r~*zoS9^jlhW&*QtDNL
z@d3vfmgrRT17lzc=Q|v+#ujq~o~Xg^=DE)mWsdO)Hn7e;FBrmF8Nb80^Aq-H;15j<
zV6Hv*?-}nP0{itgX%cn}0^GF}}hW)&^Q=SMx4o=GkSh)i8#A*_}0JB|!
z?ZI#62JFlHJicIUZR+3rGg6K56~?eO&_cVKcNr7U?+z3BGxE_epWjwZ>k3U|I
uuje|s_U1eIj!OUIR?Y3%xbI!U`^iMzHA1qD)

literal 0
HcmV?d1

diff --git a/gcc/testsuite/gdc.dg/bom_UTF8.d b/gcc/testsuite/gdc.dg/bom_UTF8.d
new file mode 100644
index 000..f3e8af4eb38
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/bom_UTF8.d
@@ -0,0 +1,11 @@
+// { dg-do compile }
+module object;
+
+extern(C):
+int printf(const char *, ...);
+
+int main()
+{
+printf("hello world\n");
+return 0;
+}
diff --git a/gcc/testsuite/gdc.dg/bom_characters.d 
b/gcc/testsuite/gdc.dg/bom_characters.d
new file mode 100644
index 
..4b42b4c611ba7b2746db7df9f3ba19c760952ae9
GIT binary patch
literal 780
zcmbW##v3kP)nCCW)IL=_nmD43E|lBDznNEhmHjQV!*%7S~nKoyZSzRHXYqMsV_nyRa
iM|{5-WY~psx#)gdVZWN$q}}zS{5#*~AAZbl|LhCNt~kg5

literal 0
HcmV?d1

diff --git a/gcc/testsuite/gdc.dg/bom_error_UTF8.d 
b/gcc/testsuite/gdc.dg/bom_error_UTF8.d
new file mode 100644
index 000..0e47e59bda3
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/bom_error_UTF8.d
@@ -0,0 +1,11 @@
+// { dg-do compile }
+module object; // { dg-error "character 0xfeff is not a valid token" }
+
+extern(C):
+int printf(const char *, ...);
+
+int main()
+{
+printf("hello world\n");
+   

Re: [PATCH] testsuite: gdc: Require ucn in gdc.test/runnable/mangle.d etc. [PR104739]

2024-02-14 Thread Iain Buclaw
Excerpts from Rainer Orth's message of Februar 14, 2024 11:51 am:
> gdc.test/runnable/mangle.d and two other tests come out UNRESOLVED on
> Solaris with the native assembler:
> 
> UNRESOLVED: gdc.test/runnable/mangle.d   compilation failed to produce 
> executable
> UNRESOLVED: gdc.test/runnable/mangle.d -shared-libphobos   compilation failed 
> to produce executable
> UNRESOLVED: gdc.test/runnable/testmodule.d   compilation failed to produce 
> executable 
> UNRESOLVED: gdc.test/runnable/testmodule.d -shared-libphobos   compilation 
> failed to produce executable
> UNRESOLVED: gdc.test/runnable/ufcs.d   compilation failed to produce 
> executable
> UNRESOLVED: gdc.test/runnable/ufcs.d -shared-libphobos   compilation failed 
> to produce executable
> 
> Assembler: mangle.d
> "/var/tmp//cci9q2Sc.s", line 115 : Syntax error
> Near line: "movzbl  test_эльфийские_письмена_9, %eax"
> "/var/tmp//cci9q2Sc.s", line 115 : Syntax error
> Near line: "movzbl  test_эльфийские_письмена_9, %eax"
> "/var/tmp//cci9q2Sc.s", line 115 : Syntax error
> Near line: "movzbl  test_эльфийские_письмена_9, %eax"
> "/var/tmp//cci9q2Sc.s", line 115 : Syntax error
> Near line: "movzbl  test_эльфийские_письмена_9, %eax"
> "/var/tmp//cci9q2Sc.s", line 115 : Syntax error
> [...]
> 
> since /bin/as lacks UCN support.
> 
> Iain recently added UNICODE_NAMES: annotations to the affected tests and
> those recently were imported into trunk.
> 
> This patch handles the DejaGnu side of things, adding
> 
>   { dg-require-effective-target ucn }
> 
> to those tests on the fly.
> 
> Tested on i386-pc-solaris2.11, sparc-sun-solaris2.11 (as and gas each),
> and x86_64-pc-linux-gnu.
> 
> Ok for trunk.
> 

OK.

Thanks!
Iain.


[committed] libphobos: Bump soname version to 5 [PR113667]

2024-02-12 Thread Iain Buclaw
Hi,

This patch bumps the soname version of libphobos.

Each major release is not binary compatible with the previous.

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

Regards,
Iain.

---
PR d/113667

libphobos/ChangeLog:

* configure: Regenerate.
* configure.ac (libtool_VERSION): Update to 5:0:0.
---
 libphobos/configure| 2 +-
 libphobos/configure.ac | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libphobos/configure b/libphobos/configure
index 9a59bad34ac..9b6a41879d3 100755
--- a/libphobos/configure
+++ b/libphobos/configure
@@ -15741,7 +15741,7 @@ SPEC_PHOBOS_DEPS="$LIBS"
 
 
 # Libdruntime / phobos soname version
-libtool_VERSION=4:0:0
+libtool_VERSION=5:0:0
 
 
 # Set default flags (after DRUNTIME_WERROR!)
diff --git a/libphobos/configure.ac b/libphobos/configure.ac
index bce85388612..ab82eacc204 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=4:0:0
+libtool_VERSION=5:0:0
 AC_SUBST(libtool_VERSION)
 
 # Set default flags (after DRUNTIME_WERROR!)
-- 
2.40.1



[committed] d: Fix internal compiler error: in make_import, at d/imports.cc:48 [PR113125]

2024-02-12 Thread Iain Buclaw
Hi,

This patch fixes an ICE triggered in the D front-end.

The cause of the ICE was that TYPE_DECLs were only being generated for
structs with members, not opaque structs.

PR d/113125

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

Regards,
Iain.

---

gcc/d/ChangeLog:

* types.cc (TypeVisitor::visit (TypeStruct *)): Generate TYPE_DECL and
apply UDAs to opaque struct declarations.

gcc/testsuite/ChangeLog:

* gdc.dg/imports/pr113125.d: New test.
* gdc.dg/pr113125.d: New test.
---
 gcc/d/types.cc  | 5 +
 gcc/testsuite/gdc.dg/imports/pr113125.d | 2 ++
 gcc/testsuite/gdc.dg/pr113125.d | 4 
 3 files changed, 11 insertions(+)
 create mode 100644 gcc/testsuite/gdc.dg/imports/pr113125.d
 create mode 100644 gcc/testsuite/gdc.dg/pr113125.d

diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index af9aad8a412..ed97aa39cc5 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -1230,6 +1230,11 @@ public:
apply_user_attributes (t->sym, t->ctype);
finish_aggregate_type (structsize, alignsize, t->ctype);
   }
+else
+  {
+   build_type_decl (t->ctype, t->sym);
+   apply_user_attributes (t->sym, t->ctype);
+  }
 
 /* For structs with a user defined postblit, copy constructor, or a
destructor, also set TREE_ADDRESSABLE on the type and all variants.
diff --git a/gcc/testsuite/gdc.dg/imports/pr113125.d 
b/gcc/testsuite/gdc.dg/imports/pr113125.d
new file mode 100644
index 000..761e613b055
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/imports/pr113125.d
@@ -0,0 +1,2 @@
+module imports.pr113125;
+struct S113125;
diff --git a/gcc/testsuite/gdc.dg/pr113125.d b/gcc/testsuite/gdc.dg/pr113125.d
new file mode 100644
index 000..cb7300baa1a
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr113125.d
@@ -0,0 +1,4 @@
+// { dg-do compile }
+// { dg-options "-I $srcdir/gdc.dg" }
+module pr113125;
+import imports.pr113125: S113125;
-- 
2.40.1



[committed] d: Fix callee destructor call invalidates the live object [PR113758]

2024-02-12 Thread Iain Buclaw
Hi,

This patch fixes code generation problem with passing objects by
invisible reference - because of a defined cpctor or dtor.

When generating the argument, check the isCalleeDestroyingArgs hook, and
force a TARGET_EXPR to be created if true, so that a reference to the
live object isn't passed directly to the function that runs dtors.

When instead dealing with caller running destructors, two temporaries
were being generated, one explicit temporary generated by the D
front-end, and another implicitly by the code generator.  This has been
reduced to one by setting DECL_VALUE_EXPR on the explicit temporary to
bind it to the implicit slot created for the TARGET_EXPR, as that has
the shorter lifetime of the two.

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

Regards,
Iain.

---
PR d/113758

gcc/d/ChangeLog:

* d-codegen.cc (d_build_call): Force a TARGET_EXPR when callee
destorys its arguments.
* decl.cc (DeclVisitor::visit (VarDeclaration *)): Set
SET_DECL_VALUE_EXPR on the temporary variable to make it a placeholder
for the TARGET_EXPR_SLOT.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/pr113758.d: New test.
---
 gcc/d/d-codegen.cc  | 15 +++
 gcc/d/decl.cc   | 22 --
 gcc/testsuite/gdc.dg/torture/pr113758.d | 19 +++
 3 files changed, 50 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/torture/pr113758.d

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 95dc8b6327e..dc528164aaf 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -2270,10 +2270,17 @@ d_build_call (TypeFunction *tf, tree callable, tree 
object,
  Type *t = arg->type->toBasetype ();
  StructDeclaration *sd = t->baseElemOf ()->isTypeStruct ()->sym;
 
- /* Nested structs also have ADDRESSABLE set, but if the type has
-neither a copy constructor nor a destructor available, then we
-need to take care of copying its value before passing it.  */
- if (arg->op == EXP::structLiteral || (!sd->postblit && !sd->dtor))
+ /* Need to take care of copying its value before passing the
+argument in the following scenarios:
+- The argument is a literal expression; a CONSTRUCTOR can't
+have its address taken.
+- The type has neither a copy constructor nor a destructor
+available; nested structs also have ADDRESSABLE set.
+- The ABI of the function expects the callee to destroy its
+arguments; when the caller is handles destruction, then `targ'
+has already been made into a temporary. */
+ if (arg->op == EXP::structLiteral || (!sd->postblit && !sd->dtor)
+ || target.isCalleeDestroyingArgs (tf))
targ = force_target_expr (targ);
 
  targ = convert (build_reference_type (TREE_TYPE (targ)),
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index d2e84d3ba61..827495b3e30 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -863,10 +863,28 @@ public:
/* Maybe put variable on list of things needing destruction.  */
if (d->needsScopeDtor ())
  {
+   /* Rewrite: `decl = exp' => TARGET_EXPR(decl, exp, dtor).  */
vec_safe_push (d_function_chain->vars_in_scope, decl);
+
/* Force a TARGET_EXPR to add the corresponding cleanup.  */
-   exp = force_target_expr (compound_expr (exp, decl));
-   TARGET_EXPR_CLEANUP (exp) = build_expr (d->edtor);
+   if (TREE_CODE (exp) != TARGET_EXPR)
+ {
+   if (VOID_TYPE_P (TREE_TYPE (exp)))
+ exp = compound_expr (exp, decl);
+
+   exp = force_target_expr (exp);
+ }
+
+   TARGET_EXPR_CLEANUP (exp)
+ = compound_expr (TARGET_EXPR_CLEANUP (exp),
+  build_expr (d->edtor));
+
+   /* The decl is really an alias for the TARGET_EXPR slot.  */
+   SET_DECL_VALUE_EXPR (decl, TARGET_EXPR_SLOT (exp));
+   DECL_HAS_VALUE_EXPR_P (decl) = 1;
+   /* This tells the gimplifier not to emit a clobber for the decl
+  as its lifetime ends when the slot gets cleaned up.  */
+   TREE_ADDRESSABLE (decl) = 0;
  }
 
add_stmt (exp);
diff --git a/gcc/testsuite/gdc.dg/torture/pr113758.d 
b/gcc/testsuite/gdc.dg/torture/pr113758.d
new file mode 100644
index 000..dc53883a8de
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/pr113758.d
@@ -0,0 +1,19 @@
+// { dg-do run }
+// { dg-skip-if "needs gcc/config.d" { ! d_runtime } }
+struct S113758
+{
+int field;
+~this() { field = 0; }
+}
+
+void main()
+{
+auto var = S113758(1);
+  

[committed] d: Merge dmd, druntime 11240a9663

2024-02-12 Thread Iain Buclaw
Hi,

This patch merges the D front-end and core runtime library with upstream
dmd 11240a9663.

Included in the merge are the fix for PR113772, and new testsuite
directives to enable fixing PR104739.

D front-end changes:

- Import latest fixes from dmd v2.107.0.

D runtime changes:

- Import latest fixes from druntime v2.107.0.

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

Regards,
Iain.

---
PR d/113772

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 11240a9663.
* d-builtins.cc (build_frontend_type): Update for new front-end
interface.
* types.cc (same_type_p): Likewise.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 11240a9663.
---
 gcc/d/d-builtins.cc   |  31 ++--
 gcc/d/dmd/MERGE   |   2 +-
 gcc/d/dmd/aggregate.d |   2 +-
 gcc/d/dmd/aggregate.h |   1 +
 gcc/d/dmd/astcodegen.d|   1 +
 gcc/d/dmd/astenums.d  |   2 +-
 gcc/d/dmd/clone.d |  17 +-
 gcc/d/dmd/constfold.d |   2 +-
 gcc/d/dmd/dcast.d |  87 +-
 gcc/d/dmd/declaration.d   |   4 +-
 gcc/d/dmd/declaration.h   |   2 -
 gcc/d/dmd/dinterpret.d|   2 +-
 gcc/d/dmd/dsymbol.h   |   2 -
 gcc/d/dmd/dsymbolsem.d|   2 +-
 gcc/d/dmd/errors.h|   2 -
 gcc/d/dmd/expression.h|  10 +-
 gcc/d/dmd/expressionsem.d |  34 ++--
 gcc/d/dmd/func.d  |  11 +-
 gcc/d/dmd/hdrgen.h|   8 +
 gcc/d/dmd/init.h  |   1 +
 gcc/d/dmd/mtype.d | 112 +---
 gcc/d/dmd/mtype.h |   6 +-
 gcc/d/dmd/parse.d |   2 +-
 gcc/d/dmd/statement.h |   5 +
 gcc/d/dmd/template.h  |   3 +
 gcc/d/dmd/typesem.d   | 112 +++-
 gcc/d/types.cc|   2 +-
 .../gdc.test/compilable/commontype.d  |  20 +--
 gcc/testsuite/gdc.test/compilable/test3543.d  |  80 +
 gcc/testsuite/gdc.test/runnable/mangle.d  |   1 +
 gcc/testsuite/gdc.test/runnable/testmodule.d  |   2 +
 gcc/testsuite/gdc.test/runnable/ufcs.d|   2 +
 libphobos/libdruntime/MERGE   |   2 +-
 libphobos/libdruntime/core/demangle.d | 160 +-
 libphobos/libdruntime/core/internal/atomic.d  |   2 +-
 .../core/internal/gc/impl/conservative/gc.d   |  39 +++--
 libphobos/libdruntime/core/internal/qsort.d   |   5 +-
 libphobos/libdruntime/core/memory.d   |   1 +
 libphobos/libdruntime/core/thread/osthread.d  |   2 +
 libphobos/libdruntime/core/time.d |   4 +
 libphobos/libdruntime/rt/aaA.d|   1 +
 libphobos/libdruntime/rt/lifetime.d   |   1 +
 42 files changed, 491 insertions(+), 296 deletions(-)
 create mode 100644 gcc/testsuite/gdc.test/compilable/test3543.d

diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index 4ed8751079b..24ac456e23d 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -97,12 +97,15 @@ build_frontend_type (tree type)
{
  /* Check for char * first.  Needs to be done for chars/string.  */
  if (TYPE_MAIN_VARIANT (TREE_TYPE (type)) == char_type_node)
-   return Type::tchar->addMod (dtype->mod)->pointerTo ()->addMod (mod);
+   {
+ dtype = addMod (Type::tchar, dtype->mod);
+ return addMod (dtype->pointerTo (), mod);
+   }
 
  if (dtype->ty == TY::Tfunction)
-   return (TypePointer::create (dtype))->addMod (mod);
+   return addMod (TypePointer::create (dtype), mod);
 
- return dtype->pointerTo ()->addMod (mod);
+ return addMod (dtype->pointerTo (), mod);
}
   break;
 
@@ -113,7 +116,7 @@ build_frontend_type (tree type)
  /* Want to assign ctype directly so that the REFERENCE_TYPE code
 can be turned into as an `inout' argument.  Can't use pointerTo(),
 because the returned Type is shared.  */
- dtype = (TypePointer::create (dtype))->addMod (mod);
+ dtype = addMod (TypePointer::create (dtype), mod);
  dtype->ctype = type;
  builtin_converted_decls.safe_push (builtin_data (dtype, type));
  return dtype;
@@ -122,7 +125,7 @@ build_frontend_type (tree type)
 
 case BOOLEAN_TYPE:
   /* Should be no need for size checking.  */
-  return Type::tbool->addMod (mod);
+  return addMod (Type::tbool, mod);
 
 case INTEGER_TYPE:
 {
@@ -140,7 +143,7 @@ build_frontend_type (tree type)
  || size != 

[committed] d: Merge dmd, druntime a6f1083699, phobos 31dedd7da

2024-02-03 Thread Iain Buclaw
Hi,

This patch merges the D front-end and runtime library with upstream dmd
a6f1083699, and the standard library with phobos 31dedd7da.

D front-end changes:

- Import dmd v2.107.0.
- Character postfixes can now also be used for integers of size
  two or four.

D run-time changes:

- Import druntime v2.107.0.

Phobos changes:

- Import phobos v2.107.0.

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd a6f1083699.
* dmd/VERSION: Bump version to v2.107.0
* Make-lang.in (D_FRONTEND_OBJS): Add d/pragmasem.o.
* d-builtins.cc (strip_type_modifiers): Update for new front-end
interface.
* d-codegen.cc (declaration_type): Likewise.
(parameter_type): Likewise.
* d-target.cc (TargetCPP::parameterType): Likewise.
* expr.cc (ExprVisitor::visit (IndexExp *)): Likewise.
(ExprVisitor::visit (VarExp *)): Likewise.
(ExprVisitor::visit (AssocArrayLiteralExp *)): Likewise.
* runtime.cc (get_libcall_type): Likewise.
* typeinfo.cc (TypeInfoVisitor::visit (TypeInfoConstDeclaration *)):
Likewise.
(TypeInfoVisitor::visit (TypeInfoInvariantDeclaration *)): Likewise.
(TypeInfoVisitor::visit (TypeInfoSharedDeclaration *)): Likewise.
(TypeInfoVisitor::visit (TypeInfoWildDeclaration *)): Likewise.
* types.cc (build_ctype): Likewise.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime a6f1083699.
* src/MERGE: Merge upstream phobos 31dedd7da.

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

Regards,
Iain.

---
 gcc/d/Make-lang.in|1 +
 gcc/d/d-builtins.cc   |2 +-
 gcc/d/d-codegen.cc|4 +-
 gcc/d/d-target.cc |4 +-
 gcc/d/dmd/MERGE   |2 +-
 gcc/d/dmd/README.md   |1 +
 gcc/d/dmd/VERSION |2 +-
 gcc/d/dmd/constfold.d |6 +-
 gcc/d/dmd/cparse.d|2 +-
 gcc/d/dmd/ctfeexpr.d  |2 +-
 gcc/d/dmd/dcast.d |   20 +-
 gcc/d/dmd/dclass.d|1 +
 gcc/d/dmd/declaration.h   |1 -
 gcc/d/dmd/denum.d |7 +-
 gcc/d/dmd/dinterpret.d|   43 +-
 gcc/d/dmd/dmangle.d   |   20 +-
 gcc/d/dmd/dsymbol.h   |2 +-
 gcc/d/dmd/dsymbolsem.d| 1888 ++---
 gcc/d/dmd/dtemplate.d |  759 +--
 gcc/d/dmd/dtoh.d  |1 +
 gcc/d/dmd/enumsem.d   |6 +
 gcc/d/dmd/expression.d|3 +-
 gcc/d/dmd/expression.h|3 +-
 gcc/d/dmd/expressionsem.d |   31 +-
 gcc/d/dmd/func.d  |  172 +-
 gcc/d/dmd/funcsem.d   | 1150 ++
 gcc/d/dmd/hdrgen.d|3 +-
 gcc/d/dmd/initsem.d   |   86 +-
 gcc/d/dmd/mtype.d |  353 +--
 gcc/d/dmd/mtype.h |   26 +-
 gcc/d/dmd/opover.d|1 +
 gcc/d/dmd/optimize.d  |3 +-
 gcc/d/dmd/pragmasem.d |  650 ++
 gcc/d/dmd/scope.h |2 +-
 gcc/d/dmd/semantic2.d |   23 +-
 gcc/d/dmd/sideeffect.d|   10 +
 gcc/d/dmd/statementsem.d  |  181 +-
 gcc/d/dmd/templatesem.d   |  909 +++-
 gcc/d/dmd/typesem.d   |  304 ++-
 gcc/d/dmd/utils.d |   41 +
 gcc/d/expr.cc |9 +-
 gcc/d/runtime.cc  |6 +-
 gcc/d/typeinfo.cc |8 +-
 gcc/d/types.cc|2 +-
 gcc/testsuite/gdc.test/compilable/ddoc4162.d  |2 +-
 gcc/testsuite/gdc.test/compilable/ddoc5446.d  |2 +-
 gcc/testsuite/gdc.test/compilable/ddoc7795.d  |2 +-
 .../compilable/{ddoc12.d => ddoc_bom_UTF8.d}  |0
 gcc/testsuite/gdc.test/compilable/test24338.d |   10 +
 .../gdc.test/fail_compilation/discard_value.d |   34 +
 .../gdc.test/fail_compilation/fail12390.d |   16 -
 .../gdc.test/fail_compilation/gag4269a.d  |2 +-
 .../gdc.test/fail_compilation/gag4269b.d  |2 +-
 .../gdc.test/fail_compilation/gag4269c.d  |2 +-
 .../gdc.test/fail_compilation/gag4269d.d  |2 +-
 .../gdc.test/fail_compilation/gag4269e.d  |2 +-
 .../gdc.test/fail_compilation/gag4269f.d  |2 +-
 .../gdc.test/fail_compilation/gag4269g.d  |2 +-
 

[committed] d: Merge dmd. druntime e770945277, phobos 6d6e0b9b9

2024-02-03 Thread Iain Buclaw
Hi,

This patch merges the D front-end and runtime library with upstream dmd
e770945277, and the standard runtime library with phobos 6d6e0b9b9.

Synchronizing with the upstream release candidate as of 2024-01-27.

D front-end changes:

- Import latest fixes from dmd v2.107.0-beta.1.
- Hex strings can now be cast to integer arrays.
- Add support for Interpolated Expression Sequences.

D runtime changes:

- Import latest fixes from druntime v2.107.0-beta.1.
- New core.interpolation module to provide run-time support for D
  interpolated expression sequence literals.

Phobos changes:

- Import latest fixes from phobos v2.107.0-beta.1.
- `std.range.primitives.isBidirectionalRange', and
  `std.range.primitives.isRandomAccessRange' now take an optional
  element type.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd e770945277.
* Make-lang.in (D_FRONTEND_OBJS): Add d/basicmangle.o, d/enumsem.o,
d/funcsem.o, d/templatesem.o.
* d-builtins.cc (build_frontend_type): Update for new front-end
interface.
* d-codegen.cc (declaration_type): Likewise.
(parameter_type): Likewise.
* d-incpath.cc (add_globalpaths): Likewise.
(add_filepaths): Likewise.
(add_import_paths): Likewise.
* d-lang.cc (d_init_options): Likewise.
(d_handle_option): Likewise.
(d_parse_file): Likewise.
* decl.cc (DeclVisitor::finish_vtable): Likewise.
(DeclVisitor::visit (FuncDeclaration *)): Likewise.
(get_symbol_decl): Likewise.
* expr.cc (ExprVisitor::visit (StringExp *)): Likewise.
Implement support for 8-byte hexadecimal strings.
* typeinfo.cc (create_tinfo_types): Update internal TypeInfo
representation.
(TypeInfoVisitor::visit (TypeInfoConstDeclaration *)): Update for new
front-end interface.
(TypeInfoVisitor::visit (TypeInfoInvariantDeclaration *)): Likewise.
(TypeInfoVisitor::visit (TypeInfoSharedDeclaration *)): Likewise.
(TypeInfoVisitor::visit (TypeInfoWildDeclaration *)): Likewise.
(TypeInfoVisitor::visit (TypeInfoClassDeclaration *)): Move data for
TypeInfo_Class.nameSig to the end of the object.
(create_typeinfo): Update for new front-end interface.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime e770945277.
* libdruntime/Makefile.am (DRUNTIME_SOURCES): Add
core/interpolation.d.
* libdruntime/Makefile.in: Regenerate.
* src/MERGE: Merge upstream phobos 6d6e0b9b9.
---
 gcc/d/Make-lang.in|4 +
 gcc/d/d-builtins.cc   |2 +-
 gcc/d/d-codegen.cc|4 +-
 gcc/d/d-incpath.cc|   41 +-
 gcc/d/d-lang.cc   |   34 +-
 gcc/d/decl.cc |   37 +-
 gcc/d/dmd/MERGE   |2 +-
 gcc/d/dmd/README.md   |4 +
 gcc/d/dmd/aggregate.h |3 +-
 gcc/d/dmd/basicmangle.d   |  109 ++
 gcc/d/dmd/clone.d |9 +-
 gcc/d/dmd/common/outbuffer.d  |   27 +
 gcc/d/dmd/cond.d  |   19 +-
 gcc/d/dmd/constfold.d |6 +-
 gcc/d/dmd/ctfeexpr.d  |   10 +-
 gcc/d/dmd/dclass.d|2 +
 gcc/d/dmd/declaration.h   |7 +-
 gcc/d/dmd/denum.d |   85 -
 gcc/d/dmd/dinterpret.d|   68 +-
 gcc/d/dmd/dmangle.d   |  144 +-
 gcc/d/dmd/dmodule.d   |6 +-
 gcc/d/dmd/doc.d   |3 +-
 gcc/d/dmd/dstruct.d   |2 +-
 gcc/d/dmd/dsymbolsem.d|  574 +-
 gcc/d/dmd/dtemplate.d | 1646 +
 gcc/d/dmd/enum.h  |2 -
 gcc/d/dmd/enumsem.d   |  714 +++
 gcc/d/dmd/expression.d|   44 +-
 gcc/d/dmd/expression.h|   15 +-
 gcc/d/dmd/expressionsem.d |  103 +-
 gcc/d/dmd/func.d  |  199 +-
 gcc/d/dmd/funcsem.d   |  219 +++
 gcc/d/dmd/globals.d   |   12 +-
 gcc/d/dmd/globals.h   |   12 +-
 gcc/d/dmd/hdrgen.d|   84 +
 gcc/d/dmd/id.d|6 +
 gcc/d/dmd/json.d  |   14 +-
 gcc/d/dmd/lexer.d |  166 +-
 gcc/d/dmd/mtype.d |   56 +-
 gcc/d/dmd/mtype.h |

Re: [PATCH] testsuite, GDC: Update link flags [PR112861].

2024-01-28 Thread Iain Buclaw
Excerpts from Iain Sandoe's message of Januar 28, 2024 4:02 pm:
> Tested on i686, x86_64, aarch64 Darwin, x86_64, aarch64 Linux,
> OK for trunk?
> thanks, 
> Iain
> 

OK.

Thanks again!

Iain.


Re: [PATCH] testsuite, libphobos: Update link flags [PR112864].

2024-01-28 Thread Iain Buclaw
Excerpts from Iain Sandoe's message of Januar 28, 2024 4:03 pm:
> Tested on i686, x86_64, aarch64 Darwin, x86_64, aarch64 Linux,
> OK for trunk?
> thanks, 
> Iain
> 

Thanks Iain!

OK. Seems reasonable to me.

Iain.


Re: [PATCH v9 2/2] Add gcov MC/DC tests for GDC

2023-12-31 Thread Iain Buclaw
Excerpts from Jørgen Kvalsvik's message of Dezember 31, 2023 4:51 pm:
> This is a mostly straight port from the gcov-19.c tests from the C test
> suite. The only notable differences from C to D are that D flips the
> true/false outcomes for loop headers, and the D front end ties loop and
> ternary conditions to slightly different locus.
> 
> The test for >64 conditions warning is disabled as it either needs
> support from the testing framework or a something similar to #pragma GCC
> diagnostic push to not cause a test failure from detecting a warning.
> 

Thanks!

No problems with adding this to the gdc testsuite on my end.

Iain.


Re: [committed] d: Merge upstream dmd, druntime 2bbf64907c, phobos b64bfbf91

2023-12-11 Thread Iain Buclaw
Excerpts from Iain Buclaw's message of Dezember 11, 2023 11:07 am:
> Hi,
> 
> This patch merges the D front-end and runtime library with upstream dmd
> 2bbf64907c, and the standard library with phobos b64bfbf91.
> 
> Synchronizing with the upstream release of v2.106.0.
> 

...

> diff --git a/gcc/d/dmd/canthrow.d b/gcc/d/dmd/canthrow.d
> index 67305922df6..5a608a9986d 100644
> --- a/gcc/d/dmd/canthrow.d
> +++ b/gcc/d/dmd/canthrow.d
> @@ -22,7 +22,6 @@ import dmd.declaration;
>  import dmd.dsymbol;
>  import dmd.errorsink;
>  import dmd.expression;
> -import dmd.expressionsem;
>  import dmd.func;
>  import dmd.globals;
>  import dmd.init;
> @@ -81,6 +80,7 @@ CT canThrow(Expression e, FuncDeclaration func, ErrorSink 
> eSink)
>  if (!f.isDtorDeclaration())
>  errorSupplementalInferredAttr(f, 10, false, 
> STC.nothrow_);
>  
> +import dmd.expressionsem : checkOverriddenDtor;
>  f.checkOverriddenDtor(null, e.loc, dd => 
> dd.type.toTypeFunction().isnothrow, "not nothrow");
>  }
>  else if (func)
> 

Hi Rainer,

This specific change that moves an import from toplevel to local should
fix that linker problem when using gdc-9 for bootstrapping.

Iain.


[committed] d: Merge upstream dmd, druntime 2bbf64907c, phobos b64bfbf91

2023-12-11 Thread Iain Buclaw
Hi,

This patch merges the D front-end and runtime library with upstream dmd
2bbf64907c, and the standard library with phobos b64bfbf91.

Synchronizing with the upstream release of v2.106.0.

D front-end changes:

- Import dmd v2.106.0.

D runtime changes:

- Import druntime v2.106.0.

Phobos changes:

- Import phobos v2.106.0.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* Make-lang.in (D_FRONTEND_OBJS): Rename d/common-string.o to
d/common-smallbuffer.o.
* dmd/MERGE: Merge upstream dmd 2bbf64907c.
* dmd/VERSION: Bump version to v2.106.0.
* modules.cc (layout_moduleinfo_fields): Update for new front-end
interface.
(layout_moduleinfo): Likewise.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 2bbf64907c.
* src/MERGE: Merge upstream phobos b64bfbf91.
---
 gcc/d/Make-lang.in|   2 +-
 gcc/d/dmd/MERGE   |   2 +-
 gcc/d/dmd/VERSION |   2 +-
 gcc/d/dmd/aggregate.d |  10 -
 gcc/d/dmd/aggregate.h |   1 -
 gcc/d/dmd/attrib.d|  67 --
 gcc/d/dmd/attrib.h|   9 -
 gcc/d/dmd/canthrow.d  |   2 +-
 gcc/d/dmd/common/README.md|   2 +-
 gcc/d/dmd/common/file.d   |  15 +-
 gcc/d/dmd/common/{string.d => smallbuffer.d}  |  49 ++--
 gcc/d/dmd/cparse.d|   8 +
 gcc/d/dmd/dcast.d |  12 +-
 gcc/d/dmd/denum.d |   7 -
 gcc/d/dmd/dimport.d   |  16 --
 gcc/d/dmd/dmodule.d   |  36 ++-
 gcc/d/dmd/dsymbol.d   | 172 --
 gcc/d/dmd/dsymbol.h   |   5 +-
 gcc/d/dmd/dsymbolsem.d| 214 +
 gcc/d/dmd/dtemplate.d |   7 +-
 gcc/d/dmd/enum.h  |   1 -
 gcc/d/dmd/escape.d|   2 +-
 gcc/d/dmd/expressionsem.d |   2 +-
 gcc/d/dmd/hdrgen.d|  27 +++
 gcc/d/dmd/import.h|   1 -
 gcc/d/dmd/initsem.d   |  20 +-
 gcc/d/dmd/module.h|   1 +
 gcc/d/dmd/nspace.d|  14 --
 gcc/d/dmd/nspace.h|   1 -
 gcc/d/dmd/parse.d |  12 +-
 gcc/d/dmd/root/file.d |   2 +-
 gcc/d/dmd/root/filename.d |   4 +-
 gcc/d/dmd/root/speller.d  |   2 +-
 gcc/d/dmd/root/string.d   |   2 +-
 gcc/d/dmd/typesem.d   |  58 +
 gcc/d/modules.cc  |   4 +-
 .../fail_compilation/misc_parser_err_cov1.d   |   2 +-
 gcc/testsuite/gdc.test/runnable/dbitfields.d  |  34 +++
 libphobos/libdruntime/MERGE   |   2 +-
 libphobos/libdruntime/core/cpuid.d|   7 +-
 libphobos/src/MERGE   |   2 +-
 libphobos/src/std/algorithm/searching.d   | 218 +++---
 libphobos/src/std/conv.d  |   5 +-
 libphobos/src/std/range/package.d |  24 +-
 libphobos/src/std/uni/package.d   |  12 +
 45 files changed, 579 insertions(+), 518 deletions(-)
 rename gcc/d/dmd/common/{string.d => smallbuffer.d} (82%)

diff --git a/gcc/d/Make-lang.in b/gcc/d/Make-lang.in
index b3007a96bd0..a0d4d7cbeb4 100644
--- a/gcc/d/Make-lang.in
+++ b/gcc/d/Make-lang.in
@@ -95,7 +95,7 @@ D_FRONTEND_OBJS = \
d/common-bitfields.o \
d/common-file.o \
d/common-outbuffer.o \
-   d/common-string.o \
+   d/common-smallbuffer.o \
d/compiler.o \
d/cond.o \
d/constfold.o \
diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index aa0062c10eb..5edcee1c84d 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-ff57fec51558013b25cadb7e83da9f4675915d56
+2bbf64907cbbb483d003e0a8fcf8b502e4883799
 
 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 41fdc654b14..8c95cd04f80 100644
--- a/gcc/d/dmd/VERSION
+++ b/gcc/d/dmd/VERSION
@@ -1 +1 @@
-v2.106.0-rc.1
+v2.106.0
diff --git a/gcc/d/dmd/aggregate.d b/gcc/d/dmd/aggregate.d
index 307bb0171c4..352ca88f470 100644
--- a/gcc/d/dmd/aggregate.d
+++ b/gcc/d/dmd/aggregate.d
@@ -178,16 +178,6 @@ extern (C++) abstract class AggregateDeclaration : 
ScopeDsymbol
 return sc2;
 }
 
-override final void setScope(Scope* sc)
-{
-// Might need a scope to resolve forward references. The check for
-// semanticRun prevents unnecessary setting of 

Re: [PATCH v3 2/2] libphobos: Update build scripts for LoongArch64.

2023-12-08 Thread Iain Buclaw
Excerpts from Yang Yujie's message of Dezember 8, 2023 11:09 am:
> libphobos/ChangeLog:
> 
>   * m4/druntime/cpu.m4: Support loongarch* targets.
>   * libdruntime/Makefile.am: Same.
>   * libdruntime/Makefile.in: Regenerate.
>   * configure: Regenerate.
> ---
>  libphobos/configure   | 21 ++-
>  libphobos/libdruntime/Makefile.am |  3 +
>  libphobos/libdruntime/Makefile.in | 98 +++
>  libphobos/m4/druntime/cpu.m4  |  5 ++
>  4 files changed, 87 insertions(+), 40 deletions(-)
> 

Both these patches by themselves are fine.

Thanks again!

Iain.


Re: [PATCH v2 3/3] libphobos: LoongArch hardware support.

2023-12-07 Thread Iain Buclaw
Excerpts from Yang Yujie's message of Dezember 1, 2023 8:46 am:
> libphobos/ChangeLog:
> 
>   * src/std/math/hardware.d: Implement FP control.
> ---
>  libphobos/src/std/math/hardware.d |  53 +++
> 
> diff --git a/libphobos/src/std/math/hardware.d 
> b/libphobos/src/std/math/hardware.d
> index cb6cb87845c..8d11459a8ac 100644
> --- a/libphobos/src/std/math/hardware.d
> +++ b/libphobos/src/std/math/hardware.d
> @@ -177,6 +177,20 @@ private:
>  return result;
>  }
>  }
> +else version (LoongArch_Any)
> +{
> +version (D_SoftFloat)
> +return 0;

Hi,

Changes to this module should go first to github.com/dlang/phobos.

I also notice that theses SoftFloat static conditions in all LoongArch
support code doesn't exist in upstream either.  Can a pull request be
raised to sort out the discrepancy?

Thanks,
Iain.


Re: [PATCH v3 3/3] libruntime: Add fiber context switch code for LoongArch.

2023-12-07 Thread Iain Buclaw
Excerpts from Yang Yujie's message of Dezember 1, 2023 11:08 am:
> libphobos/ChangeLog:
> 
>   * libdruntime/config/loongarch/switchcontext.S: New file.
> ---

OK.

Thanks,
Iain.


Re: [PATCH v3 2/3] libphobos: Update build scripts for LoongArch64.

2023-12-07 Thread Iain Buclaw
Excerpts from Yang Yujie's message of Dezember 1, 2023 11:08 am:
> libphobos/ChangeLog:
> 
>   * m4/druntime/cpu.m4: Support loongarch* targets.
>   * libdruntime/Makefile.am: Same.
>   * libdruntime/Makefile.in: Regenerate.
>   * configure: Regenerate.
> ---
>  libphobos/configure   | 21 ++-
>  libphobos/libdruntime/Makefile.am |  3 +
>  libphobos/libdruntime/Makefile.in | 98 +++
>  libphobos/m4/druntime/cpu.m4  |  5 ++
>  4 files changed, 87 insertions(+), 40 deletions(-)
> 
> diff --git a/libphobos/libdruntime/Makefile.am 
> b/libphobos/libdruntime/Makefile.am
> index 23205fd3301..ca43a0753c4 100644
> --- a/libphobos/libdruntime/Makefile.am
> +++ b/libphobos/libdruntime/Makefile.am
> @@ -83,6 +83,9 @@ endif
>  if DRUNTIME_CPU_ARM
>  DRUNTIME_SOURCES_CONFIGURED += config/arm/switchcontext.S
>  endif
> +if DRUNTIME_CPU_LOONGARCH
> +DRUNTIME_SOURCES_CONFIGURED += config/loongarch/switchcontext.S
> +endif
>  if DRUNTIME_CPU_MIPS
>  DRUNTIME_SOURCES_CONFIGURED += config/mips/switchcontext.S
>  endif

Just a nitpick, I'd thought the committing of switchcontext.S should
come before this. I have no strong opinion either way.

OK to commit.

Iain.


Re: [PATCH v3 1/3] LoongArch: Adjust D version strings.

2023-12-07 Thread Iain Buclaw
Hi,

Thanks for this.

Excerpts from Yang Yujie's message of Dezember 1, 2023 11:08 am:
> diff --git a/gcc/d/dmd/cond.d b/gcc/d/dmd/cond.d
> index 568b639e0b6..02af0cc9e29 100644
> --- a/gcc/d/dmd/cond.d
> +++ b/gcc/d/dmd/cond.d
> @@ -693,10 +693,10 @@ extern (C++) final class VersionCondition : DVCondition
>  case "LDC":
>  case "linux":
>  case "LittleEndian":
> -case "LoongArch32":
>  case "LoongArch64":
> -case "LoongArch_HardFloat":
> -case "LoongArch_SoftFloat":
> +case "LoongArch_F64":
> +case "LoongArch_F32":
> +case "LoongArch_SF":
>  case "MinGW":
>  case "MIPS32":
>  case "MIPS64":

Changes to this module should be submitted to github.com/dlang/dmd,
otherwise it'll get overwritten on the next "merge" with upstream.

What's the rationale for F64 and SF abbreviations?

Otherwise, looks reasonable.

Iain.


Re: [committed] d: Merge upstream dmd ff57fec515, druntime ff57fec515, phobos 17bafda79.

2023-11-22 Thread Iain Buclaw
Excerpts from Rainer Orth's message of November 21, 2023 5:03 pm:
> Rainer Orth  writes:
> 
>> either this patch or the previous one broke D bootstrap with GCC 9.  On
>> both i386-pc-solaris2.11 with gdc 9.4.0 and sparc-sun-solaris2.11 with
>> gdc 9.3.0, stage 1 d21 fails to link with
>>
>> Undefined   first referenced
>>  symbol in file
>> _D3dmd4root11stringtable34__T11StringValueTC3dmd5mtype4TypeZ11StringValue7lstringMFNaNbNiNjZPa
>>  d/func.o
>> _D3dmd4root11stringtable34__T11StringValueTC3dmd5mtype4TypeZ11StringValue8toDcharsMxFNaNbNiNjZPxa
>>  d/func.o
>> _D3dmd4root11stringtable34__T11StringValueTC3dmd5mtype4TypeZ11StringValue8toStringMxFNaNbNiNjZAxa
>>  d/func.o
>> ld: fatal: symbol referencing errors
>> collect2: error: ld returned 1 exit status
>> make[3]: *** [/vol/gcc/src/hg/master/local/gcc/d/Make-lang.in:236: d21] 
>> Error 1
> 
> Same on i686-pc-linux-gnu, btw.
> 

Thanks, I've found the culprit.  There's been quite a few changes in the
import graph upstream.  This looks to have exposed some unfortunate
template emission bugs in older versions of the compiler that as you've
pointed out, work just fine with gdc-11.

I'm err'ing on the side of reverting the individual patches, though if I
get time later, maybe try a partial revert by restoring the old import
statements only.

Iain.


Re: [committed] d: Merge upstream dmd ff57fec515, druntime ff57fec515, phobos 17bafda79.

2023-11-22 Thread Iain Buclaw
Excerpts from Rainer Orth's message of November 21, 2023 4:59 pm:
> Hi Iain,
> 
>> This patch merges the D front-end and runtime library with upstream dmd
>> ff57fec515, and the standard library with phobos 17bafda79.
>>
>> Synchronizing with the upstream release candidate of v2.106.0.
>>
>> D front-end changes:
>>
>> - Import dmd v2.106.0-rc.1.
>> - New'ing multi-dimensional arrays are now are converted to a single
>>   template call `_d_newarraymTX'.
>>
>> D runtime changes:
>>
>> - Import druntime v2.106.0-rc.1.
>>
>> Phobos changes:
>>
>> - Import phobos v2.106.0-rc.1.
>>
>> Bootstrapped and regression tested on x86_64-linux-gnu/-m32, committed
>> to mainline.
> 
> either this patch or the previous one broke D bootstrap with GCC 9.  On
> both i386-pc-solaris2.11 with gdc 9.4.0 and sparc-sun-solaris2.11 with
> gdc 9.3.0, stage 1 d21 fails to link with
> 
> Undefined   first referenced
>  symbol in file
> _D3dmd4root11stringtable34__T11StringValueTC3dmd5mtype4TypeZ11StringValue7lstringMFNaNbNiNjZPa
>  d/func.o
> _D3dmd4root11stringtable34__T11StringValueTC3dmd5mtype4TypeZ11StringValue8toDcharsMxFNaNbNiNjZPxa
>  d/func.o
> _D3dmd4root11stringtable34__T11StringValueTC3dmd5mtype4TypeZ11StringValue8toStringMxFNaNbNiNjZAxa
>  d/func.o
> ld: fatal: symbol referencing errors
> collect2: error: ld returned 1 exit status
> make[3]: *** [/vol/gcc/src/hg/master/local/gcc/d/Make-lang.in:236: d21] Error 
> 1
> 
> I'm now running bootstraps with gdc 11.1.0 instead, which seems to work:
> in both cases, stage 1 d21 did link.
> 
> If this is intentional, install.texi should be updated accordingly.
> 

Thanks Rainer,

I don't think this should happen if we can help it just yet.  I'll have
a look to see which specific upstream change might have caused it.

Iain.


Re: [PATCH 2/3] Add generated .opt.urls files

2023-11-12 Thread Iain Buclaw
Excerpts from David Malcolm's message of November 10, 2023 10:42 pm:
> gcc/d/ChangeLog:
>   * lang.opt.urls: New file, autogenerated by
>   regenerate-opt-urls.py.
> ---
>  gcc/d/lang.opt.urls  |   95 +
>  create mode 100644 gcc/d/lang.opt.urls
> 

[abridged view of patch]

> diff --git a/gcc/d/lang.opt.urls b/gcc/d/lang.opt.urls
> new file mode 100644
> index ..57c14ecc459a
> --- /dev/null
> +++ b/gcc/d/lang.opt.urls
> @@ -0,0 +1,95 @@
> +; Autogenerated by regenerate-opt-urls.py from gcc/d/lang.opt and generated 
> HTML
> +
> +H
> +UrlSuffix(gcc/Preprocessor-Options.html#index-H)
> +
> +I
> +UrlSuffix(gcc/Directory-Options.html#index-I)
> +
> +M
> +UrlSuffix(gcc/Preprocessor-Options.html#index-M)
> +
> +MD
> +UrlSuffix(gcc/Preprocessor-Options.html#index-MD)
> +
> +MF
> +UrlSuffix(gcc/Preprocessor-Options.html#index-MF)
> +
> +MG
> +UrlSuffix(gcc/Preprocessor-Options.html#index-MG)
> +
> +MM
> +UrlSuffix(gcc/Preprocessor-Options.html#index-MM)
> +
> +MMD
> +UrlSuffix(gcc/Preprocessor-Options.html#index-MMD)
> +
> +MP
> +UrlSuffix(gcc/Preprocessor-Options.html#index-MP)
> +
> +MT
> +UrlSuffix(gcc/Preprocessor-Options.html#index-MT)
> +
> +MQ
> +UrlSuffix(gcc/Preprocessor-Options.html#index-MQ)
> +
> +Waddress
> +UrlSuffix(gcc/Warning-Options.html#index-Waddress)
> +
> +; skipping 'Wall' due to multiple URLs:
> +;   duplicate: 'gcc/Standard-Libraries.html#index-Wall-1'
> +;   duplicate: 'gcc/Warning-Options.html#index-Wall'
> +
> +Walloca
> +UrlSuffix(gcc/Warning-Options.html#index-Walloca)
> +
> +Walloca-larger-than=
> +UrlSuffix(gcc/Warning-Options.html#index-Walloca-larger-than_003d)
> +
> +Wbuiltin-declaration-mismatch
> +UrlSuffix(gcc/Warning-Options.html#index-Wbuiltin-declaration-mismatch)
> +
> +Wdeprecated
> +UrlSuffix(gcc/Warning-Options.html#index-Wdeprecated)
> +
> +Werror
> +UrlSuffix(gcc/Warning-Options.html#index-Werror)
> +
> +Wextra
> +UrlSuffix(gcc/Warning-Options.html#index-Wextra)
> +
> +Wunknown-pragmas
> +UrlSuffix(gcc/Warning-Options.html#index-Wno-unknown-pragmas)
> +
> +Wvarargs
> +UrlSuffix(gcc/Warning-Options.html#index-Wno-varargs)
> +
> +; skipping 'fbuiltin' due to multiple URLs:
> +;   duplicate: 'gcc/C-Dialect-Options.html#index-fbuiltin'
> +;   duplicate: 'gcc/Other-Builtins.html#index-fno-builtin-3'
> +;   duplicate: 'gcc/Warning-Options.html#index-fno-builtin-1'
> +
> +fexceptions
> +UrlSuffix(gcc/Code-Gen-Options.html#index-fexceptions)
> +
> +frtti
> +UrlSuffix(gcc/C_002b_002b-Dialect-Options.html#index-fno-rtti)
> +
> +imultilib
> +UrlSuffix(gcc/Directory-Options.html#index-imultilib)
> +
> +iprefix
> +UrlSuffix(gcc/Directory-Options.html#index-iprefix)
> +
> +isysroot
> +UrlSuffix(gcc/Directory-Options.html#index-isysroot)
> +
> +isystem
> +UrlSuffix(gcc/Directory-Options.html#index-isystem)
> +
> +nostdinc
> +UrlSuffix(gcc/Directory-Options.html#index-nostdinc)
> +
> +v
> +UrlSuffix(gcc/Overall-Options.html#index-v)
> +
> -- 
> 2.26.3
> 
> 

So I see this focuses on only adding URLs for common options, or options
that relate to C/C++ family, but may be handled by other front-ends too?

To pick out one, you have:

frtti
UrlSuffix(gcc/C_002b_002b-Dialect-Options.html#index-fno-rtti)

It looks like it could could alternatively be

frtti
UrlSuffix(gdc/Runtime-Options.html#index-frtti)

Or are other front-ends having URLs to their language-specific
documentation pages not supported for the same reason as why they can't
add self-documentation to their own options if another front-end
(typically C/C++) also makes claim to the option?

frtti
D 
; Documented in C


I'm OK with the D parts regardless of this observation.

Thanks,
Iain.


[committed] d: Merge upstream dmd, druntime 643b1261bb, phobos 1c98326e7

2023-11-02 Thread Iain Buclaw
Hi,

This patch merges the D front-end and runtime library with upstream dmd
643b1261bb, and standard library with phobos 1c98326e7.

Synchronizing with the v2.106.0-beta.1 release.

This is being done a little earlier than usual as there's a lot of
internal moving code around within upstream at the moment to reduce both
the extern(C++) surface area, and cyclic dependencies between all D
modules that implement the compiler. So it is done now to keep the diff
below the 400kb threshold enforced on the mailing list.

D front-end changes:

- Suggested preview switches now give gdc flags (PR109681).
- `new S[10]' is now lowered to `_d_newarrayT!S(10)'.

D runtime changes:

- Runtime compiler library functions `_d_newarrayU', `_d_newarrayT',
  `_d_newarrayiT' have been converted to templates.

Phobos changes:

- Add new `std.traits.Unshared' template.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 643b1261bb.
* d-attribs.cc (build_attributes): Update for new front-end interface.
* d-lang.cc (d_post_options): Likewise.
* decl.cc (layout_class_initializer): Likewise.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 643b1261bb.
* libdruntime/Makefile.am (DRUNTIME_DSOURCES_FREEBSD): Add
core/sys/freebsd/ifaddrs.d, core/sys/freebsd/net/if_dl.d,
core/sys/freebsd/sys/socket.d, core/sys/freebsd/sys/types.d.
(DRUNTIME_DSOURCES_LINUX): Add core/sys/linux/linux/if_arp.d,
core/sys/linux/linux/if_packet.d.
* libdruntime/Makefile.in: Regenerate.
* src/MERGE: Merge upstream phobos 1c98326e7.
---
 gcc/d/d-attribs.cc|   2 +-
 gcc/d/d-lang.cc   |   1 -
 gcc/d/decl.cc |   2 +-
 gcc/d/dmd/MERGE   |   2 +-
 gcc/d/dmd/aggregate.d | 184 +++---
 gcc/d/dmd/attrib.d|   6 +-
 gcc/d/dmd/cond.d  |   1 +
 gcc/d/dmd/constfold.d |  24 +-
 gcc/d/dmd/cparse.d|   1 +
 gcc/d/dmd/dcast.d |   3 +-
 gcc/d/dmd/dclass.d|   2 +-
 gcc/d/dmd/declaration.d   |  50 +-
 gcc/d/dmd/dinterpret.d|   3 +-
 gcc/d/dmd/dmangle.d   |   1 +
 gcc/d/dmd/doc.d   |   2 +-
 gcc/d/dmd/dstruct.d   |   2 +-
 gcc/d/dmd/dsymbol.d   |  74 ++-
 gcc/d/dmd/dsymbolsem.d|  11 +-
 gcc/d/dmd/dtemplate.d |  15 +-
 gcc/d/dmd/expression.d| 546 +-
 gcc/d/dmd/expression.h|  20 +-
 gcc/d/dmd/expressionsem.d | 511 +++-
 gcc/d/dmd/func.d  |   1 +
 gcc/d/dmd/globals.h   |   1 -
 gcc/d/dmd/gluelayer.d |   5 -
 gcc/d/dmd/initsem.d   |   1 +
 gcc/d/dmd/lexer.d |   1 -
 gcc/d/dmd/mtype.d |  25 +-
 gcc/d/dmd/mtype.h |   2 +-
 gcc/d/dmd/optimize.d  |   1 +
 gcc/d/dmd/parse.d |  22 +-
 gcc/d/dmd/semantic3.d |   7 +-
 gcc/d/dmd/statementsem.d  |   5 +-
 gcc/d/dmd/staticcond.d|   1 +
 gcc/d/dmd/templateparamsem.d  |   1 +
 gcc/d/dmd/traits.d|   1 +
 gcc/d/dmd/typesem.d   |   2 +
 gcc/d/dmd/typinf.d|  30 +-
 gcc/d/dmd/typinf.h|  22 +
 gcc/testsuite/gdc.test/compilable/dbitfield.d |  13 +
 .../gdc.test/compilable/deprecate14283.d  |   8 +-
 .../gdc.test/compilable/named_arguments.d |  18 +-
 gcc/testsuite/gdc.test/compilable/test20039.d |   2 +-
 .../gdc.test/fail_compilation/b23686.d|  42 ++
 .../gdc.test/fail_compilation/diag4596.d  |   4 +-
 .../gdc.test/fail_compilation/fail13116.d |   2 +-
 .../gdc.test/fail_compilation/fail24208.d |  20 +
 .../gdc.test/fail_compilation/fail24212.d |  30 +
 .../gdc.test/fail_compilation/fail24213.d |  17 +
 .../gdc.test/fail_compilation/ice23865.d  |  32 +
 .../gdc.test/fail_compilation/ice24188.d  |  14 +
 .../fail_compilation/ice24188_a/ice24188_c.d  |   0
 .../gdc.test/fail_compilation/test18480.d |   1 +
 .../gdc.test/fail_compilation/test24157.d |  28 +
 libphobos/libdruntime/MERGE   |   2 +-
 libphobos/libdruntime/Makefile.am |   7 +-
 libphobos/libdruntime/Makefile.in |  34 +-
 .../libdruntime/core/sys/linux/linux/if_arp.d | 136 

[committed] d: Clean-up unused variable assignments after interface change

2023-10-31 Thread Iain Buclaw
Hi,

The lowering done for invoking `new' on a single dimension array was
moved from the code generator to the front-end semantic pass in 
r14-4996.  This removes the detritus left behind in the code generator
from that deletion.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* expr.cc (ExprVisitor::visit (NewExp *)): Remove unused assignments.
---
 gcc/d/expr.cc | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index ef4ea60ffed..17801a3bd1e 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -2357,9 +2357,6 @@ public:
 else if (tb->ty == TY::Tarray)
   {
/* Allocating memory for a new D array.  */
-   tb = e->newtype->toBasetype ();
-   TypeDArray *tarray = tb->isTypeDArray ();
-
gcc_assert (e->arguments && e->arguments->length >= 1);
 
if (e->arguments->length == 1)
@@ -2403,7 +2400,8 @@ public:
   size_int (e->arguments->length),
   build_address (var));
 
-   result = build_libcall (libcall, tb, 2, tinfo, dims);
+   result = build_libcall (libcall, e->newtype->toBasetype (), 2,
+   tinfo, dims);
  }
 
if (e->argprefix)
-- 
2.39.2



Re: [committed] d: Merge upstream dmd, druntime e48bc0987d, phobos 2458e8f82.

2023-10-30 Thread Iain Buclaw
Excerpts from Rainer Orth's message of Oktober 30, 2023 5:37 pm:
> Hi Iain,
> 
>> This patch merges the D front-end and runtime library with upstream dmd
>> e48bc0987d, and standard library with phobos 2458e8f82.
>>
>> Synchronizing with the v2.106.0-beta.1 release.
>>
>> D front-end changes:
>>
>> - Import dmd v2.106.0-beta.1.
> 
> this patch broke D bootstrap, it seems:
> 
> /vol/gcc/src/hg/master/local/gcc/d/expr.cc: In member function 'virtual void 
> ExprVisitor::visit(NewExp*)':
> /vol/gcc/src/hg/master/local/gcc/d/expr.cc:2361:21: error: unused variable 
> 'tarray' [-Werror=unused-variable]
>  2361 | TypeDArray *tarray = tb->isTypeDArray ();
>   | ^~
> 
> It removed the uses of tarray, but kept the initialization.
> 

Hi Rainer,

Thanks for spotting, I'll fix it up.

Iain.


[committed] d: Fix ICE: verify_gimple_failed (conversion of register to a different size in 'view_convert_expr') [PR110712]

2023-10-29 Thread Iain Buclaw
Hi,

This patch fixes an ICE cause by the way the D front-end generates its
codegen around va_list types.

Static arrays in D are passed around by value, rather than decaying to a
pointer.  On x86_64 __builtin_va_list is an exception to this rule, but
semantically it's still treated as a static array.

This makes certain assignment operations fail due a mismatch in types.
As all examples in the test program are rejected by C/C++ front-ends,
these are now errors in D too to be consistent.

Bootstrapped and regression tested on x86-64-linux-gnu/-m32, committed
to mainline and backported to releases/gcc-12 and releases/gcc-13.

Regards,
Iain.

---
PR d/110712

gcc/d/ChangeLog:

* d-codegen.cc (d_build_call): Update call to convert_for_argument.
* d-convert.cc (is_valist_parameter_type): New function.
(check_valist_conversion): New function.
(convert_for_assignment): Update signature.  Add check whether
assigning va_list is permissible.
(convert_for_argument): Likewise.
* d-tree.h (convert_for_assignment): Update signature.
(convert_for_argument): Likewise.
* expr.cc (ExprVisitor::visit (AssignExp *)): Update call to
convert_for_assignment.

gcc/testsuite/ChangeLog:

* gdc.dg/pr110712.d: New test.
---
 gcc/d/d-codegen.cc  |   6 +-
 gcc/d/d-convert.cc  | 127 ++--
 gcc/d/d-tree.h  |   4 +-
 gcc/d/expr.cc   |  12 +--
 gcc/testsuite/gdc.dg/pr110712.d |  23 ++
 5 files changed, 139 insertions(+), 33 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/pr110712.d

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 270cb5e2be6..5c53cf78577 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -2245,14 +2245,16 @@ d_build_call (TypeFunction *tf, tree callable, tree 
object,
   for (size_t i = 0; i < arguments->length; ++i)
{
  Expression *arg = (*arguments)[i];
- tree targ = build_expr (arg);
+ tree targ;
 
  if (i - varargs < nparams && i >= varargs)
{
  /* Actual arguments for declared formal arguments.  */
  Parameter *parg = tf->parameterList[i - varargs];
- targ = convert_for_argument (targ, parg);
+ targ = convert_for_argument (arg, parg);
}
+ else
+   targ = build_expr (arg);
 
  /* Don't pass empty aggregates by value.  */
  if (empty_aggregate_p (TREE_TYPE (targ)) && !TREE_ADDRESSABLE (targ)
diff --git a/gcc/d/d-convert.cc b/gcc/d/d-convert.cc
index 71d7a41374e..4c5375cba9a 100644
--- a/gcc/d/d-convert.cc
+++ b/gcc/d/d-convert.cc
@@ -694,16 +694,86 @@ convert_for_rvalue (tree expr, Type *etype, Type *totype)
   return result ? result : convert_expr (expr, etype, totype);
 }
 
+/* Helper for convert_for_assigment and convert_for_argument.
+   Returns true if EXPR is a va_list static array parameter.  */
+
+static bool
+is_valist_parameter_type (Expression *expr)
+{
+  Declaration *decl = NULL;
+
+  if (VarExp *ve = expr->isVarExp ())
+decl = ve->var;
+  else if (SymOffExp *se = expr->isSymOffExp ())
+decl = se->var;
+
+  if (decl != NULL && decl->isParameter () && valist_array_p (decl->type))
+return true;
+
+  return false;
+}
+
+/* Helper for convert_for_assigment and convert_for_argument.
+   Report erroneous uses of assigning or passing a va_list parameter.  */
+
+static void
+check_valist_conversion (Expression *expr, Type *totype, bool in_assignment)
+{
+  /* Parameter symbol and its converted type.  */
+  Declaration *decl = NULL;
+  /* Type of parameter when evaluated in the expression.  */
+  Type *type = NULL;
+
+  if (VarExp *ve = expr->isVarExp ())
+{
+  decl = ve->var;
+  type = ve->var->type->nextOf ()->pointerTo ();
+}
+  else if (SymOffExp *se = expr->isSymOffExp ())
+{
+  decl = se->var;
+  type = se->var->type->nextOf ()->pointerTo ()->pointerTo ();
+}
+
+  /* Should not be called unless is_valist_parameter_type also matched.  */
+  gcc_assert (decl != NULL && decl->isParameter ()
+ && valist_array_p (decl->type));
+
+  /* OK if conversion between types is allowed.  */
+  if (type->implicitConvTo (totype) != MATCH::nomatch)
+return;
+
+  if (in_assignment)
+{
+  error_at (make_location_t (expr->loc), "cannot convert parameter %qs "
+   "from type %qs to type %qs in assignment",
+   expr->toChars(), type->toChars (), totype->toChars ());
+}
+  else
+{
+  error_at (make_location_t (expr->loc), "cannot convert parameter %qs "
+   "from type %qs to type %qs in argument passing",
+   expr->toChars(), type->toChars (), totype->toChars ());
+}
+
+  inform (make_location_t (decl->loc), "parameters of type % "
+ "{aka %qs} are decayed to pointer types, and require % "
+ "to be converted back into a static array 

[committed] d: Merge upstream dmd, druntime e48bc0987d, phobos 2458e8f82.

2023-10-29 Thread Iain Buclaw
Hi,

This patch merges the D front-end and runtime library with upstream dmd
e48bc0987d, and standard library with phobos 2458e8f82.

Synchronizing with the v2.106.0-beta.1 release.

D front-end changes:

- Import dmd v2.106.0-beta.1.

D runtime changes:

- Import druntime v2.106.0-beta.1.

Phobos changes:

- Import phobos v2.106.0-beta.1.


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

Regards,
Iain.

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd e48bc0987d.
* expr.cc (ExprVisitor::visit (NewExp *)): Update for new front-end
interface.
* runtime.def (NEWARRAYT): Remove.
(NEWARRAYIT): Remove.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime e48bc0987d.
* src/MERGE: Merge upstream phobos 2458e8f82.
---
 gcc/d/dmd/MERGE   |   2 +-
 gcc/d/dmd/VERSION |   2 +-
 gcc/d/dmd/aggregate.d |   8 +-
 gcc/d/dmd/aggregate.h |   8 -
 gcc/d/dmd/aliasthis.h |   2 +-
 gcc/d/dmd/attrib.h|   1 -
 gcc/d/dmd/canthrow.d  |   2 +-
 gcc/d/dmd/cond.d  |   2 +-
 gcc/d/dmd/cond.h  |   2 -
 gcc/d/dmd/cparse.d|  17 +-
 gcc/d/dmd/dcast.d |   2 +-
 gcc/d/dmd/dclass.d|   8 +-
 gcc/d/dmd/declaration.d   |   1 +
 gcc/d/dmd/declaration.h   |  12 -
 gcc/d/dmd/denum.d |   2 +-
 gcc/d/dmd/dimport.d   |   2 +-
 gcc/d/dmd/dinterpret.d|   3 +
 gcc/d/dmd/dmodule.d   |   2 +-
 gcc/d/dmd/dscope.d|   2 +-
 gcc/d/dmd/dstruct.d   |   2 +-
 gcc/d/dmd/dsymbol.d   |   7 +-
 gcc/d/dmd/dsymbolsem.d|  15 +-
 gcc/d/dmd/dtemplate.d |   8 +-
 gcc/d/dmd/expression.d|  90 ++-
 gcc/d/dmd/expression.h|  88 +--
 gcc/d/dmd/expressionsem.d |  53 
 gcc/d/dmd/func.d  |  20 +-
 gcc/d/dmd/globals.h   |   6 +-
 gcc/d/dmd/hdrgen.d|  38 ++-
 gcc/d/dmd/id.d|   2 +
 gcc/d/dmd/import.h|   1 -
 gcc/d/dmd/init.h  |   1 -
 gcc/d/dmd/location.d  |   2 +-
 gcc/d/dmd/module.h|   1 -
 gcc/d/dmd/mtype.d |  16 +-
 gcc/d/dmd/mtype.h |  12 -
 gcc/d/dmd/objc.h  |   2 -
 gcc/d/dmd/scope.h |   2 -
 gcc/d/dmd/sideeffect.d|   4 +-
 gcc/d/dmd/statement.d |   6 +-
 gcc/d/dmd/statement.h |   4 +-
 gcc/d/dmd/template.h  |   5 -
 gcc/d/dmd/tokens.d|   2 +-
 gcc/d/dmd/tokens.h|   3 -
 gcc/d/expr.cc |  20 +-
 gcc/d/runtime.def |   9 +-
 .../gdc.test/fail_compilation/ice10727a.d |   2 +
 .../gdc.test/fail_compilation/ice10727b.d |   2 +
 libphobos/libdruntime/MERGE   |   2 +-
 .../core/internal/array/construction.d| 167 +
 .../libdruntime/core/internal/array/utils.d   | 236 ++
 libphobos/libdruntime/core/lifetime.d |  13 +-
 .../libdruntime/core/sys/freebsd/ifaddrs.d|  41 +++
 .../libdruntime/core/sys/freebsd/net/if_dl.d  |  42 
 .../libdruntime/core/sys/freebsd/sys/socket.d | 131 ++
 .../libdruntime/core/sys/freebsd/sys/types.d  |  58 +
 .../libdruntime/core/sys/posix/sys/types.d|   4 +-
 libphobos/libdruntime/object.d|   2 +
 libphobos/libdruntime/rt/lifetime.d   |  26 +-
 libphobos/src/MERGE   |   2 +-
 libphobos/src/std/parallelism.d   |   2 +-
 libphobos/src/std/range/primitives.d  |  10 +-
 libphobos/src/std/traits.d|  57 +
 63 files changed, 962 insertions(+), 334 deletions(-)
 create mode 100644 libphobos/libdruntime/core/sys/freebsd/ifaddrs.d
 create mode 100644 libphobos/libdruntime/core/sys/freebsd/net/if_dl.d
 create mode 100644 libphobos/libdruntime/core/sys/freebsd/sys/socket.d
 create mode 100644 libphobos/libdruntime/core/sys/freebsd/sys/types.d

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index bfadeaa0c68..2a0baf09a4b 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-f4be7f6f7bae75f1613b862940cdd533b5ae99b2
+e48bc0987dfec35bc76a3015ee3e85906ce86dfd
 
 The first 

[committed] d: Fix ICE: in verify_gimple_in_seq on powerpc-darwin9 [PR112270]

2023-10-28 Thread Iain Buclaw
Hi,

This patch fixes an ICE seen during stage2 on powerpc-darwin9 only.
There were still some uses of GCC's boolean_type_node in the D
front-end, which caused a type mismatch to trigger as D bool size is
fixed to 1 byte on all targets.

So two new nodes have been introduced - d_bool_false_node and
d_bool_true_node - which have replaced all remaining uses of
boolean_false_node and boolean_true_node respectively.

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

Regards,
Iain.

---
PR d/112270

gcc/d/ChangeLog:

* d-builtins.cc (d_build_d_type_nodes): Initialize d_bool_false_node,
d_bool_true_node.
* d-codegen.cc (build_array_struct_comparison): Use d_bool_false_node
instead of boolean_false_node.
* d-convert.cc (d_truthvalue_conversion): Use d_bool_false_node and
d_bool_true_node instead of boolean_false_node and boolean_true_node.
* d-tree.h (enum d_tree_index): Add DTI_BOOL_FALSE and DTI_BOOL_TRUE.
(d_bool_false_node): New macro.
(d_bool_true_node): New macro.
* modules.cc (build_dso_cdtor_fn): Use d_bool_false_node and
d_bool_true_node instead of boolean_false_node and boolean_true_node.
(register_moduleinfo): Use d_bool_type instead of boolean_type_node.

gcc/testsuite/ChangeLog:

* gdc.dg/pr112270.d: New test.
---
 gcc/d/d-builtins.cc |  3 +++
 gcc/d/d-codegen.cc  |  2 +-
 gcc/d/d-convert.cc  | 10 +-
 gcc/d/d-tree.h  |  6 ++
 gcc/d/modules.cc|  4 ++--
 gcc/testsuite/gdc.dg/pr112270.d |  7 +++
 6 files changed, 24 insertions(+), 8 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/pr112270.d

diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index cf998d22721..f6ea026bdcf 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -956,6 +956,9 @@ d_build_d_type_nodes (void)
   d_bool_type = make_unsigned_type (1);
   TREE_SET_CODE (d_bool_type, BOOLEAN_TYPE);
 
+  d_bool_false_node = TYPE_MIN_VALUE (d_bool_type);
+  d_bool_true_node = TYPE_MAX_VALUE (d_bool_type);
+
   char8_type_node = make_unsigned_type (8);
   TYPE_STRING_FLAG (char8_type_node) = 1;
 
diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 91ddb1b657e..270cb5e2be6 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -1115,7 +1115,7 @@ build_array_struct_comparison (tree_code code, 
StructDeclaration *sd,
if (length == 0 || result OP 0) break;  */
   t = build_boolop (EQ_EXPR, length, d_convert (lentype, integer_zero_node));
   t = build_boolop (TRUTH_ORIF_EXPR, t, build_boolop (code, result,
- boolean_false_node));
+ d_bool_false_node));
   t = build1 (EXIT_EXPR, void_type_node, t);
   add_stmt (t);
 
diff --git a/gcc/d/d-convert.cc b/gcc/d/d-convert.cc
index 2b9d8e78fb6..71d7a41374e 100644
--- a/gcc/d/d-convert.cc
+++ b/gcc/d/d-convert.cc
@@ -132,13 +132,13 @@ d_truthvalue_conversion (tree expr)
   return expr;
 
 case INTEGER_CST:
-  return integer_zerop (expr) ? boolean_false_node
- : boolean_true_node;
+  return integer_zerop (expr) ? d_bool_false_node
+ : d_bool_true_node;
 
 case REAL_CST:
   return real_compare (NE_EXPR, _REAL_CST (expr), )
-? boolean_true_node
-: boolean_false_node;
+? d_bool_true_node
+: d_bool_false_node;
 
 case ADDR_EXPR:
   /* If we are taking the address of a decl that can never be null,
@@ -148,7 +148,7 @@ d_truthvalue_conversion (tree expr)
  warning (OPT_Waddress,
   "the address of %qD will always evaluate as %",
   TREE_OPERAND (expr, 0));
- return boolean_true_node;
+ return d_bool_true_node;
}
   break;
 
diff --git a/gcc/d/d-tree.h b/gcc/d/d-tree.h
index ed26533feb4..7763695a106 100644
--- a/gcc/d/d-tree.h
+++ b/gcc/d/d-tree.h
@@ -444,6 +444,9 @@ enum d_tree_index
   DTI_NULL_ARRAY,
   DTI_BOTTOM_TYPE,
 
+  DTI_BOOL_FALSE,
+  DTI_BOOL_TRUE,
+
   DTI_MAX
 };
 
@@ -480,6 +483,9 @@ extern GTY(()) tree d_global_trees[DTI_MAX];
 #define null_array_noded_global_trees[DTI_NULL_ARRAY]
 /* The bottom type, referred to as `noreturn` in code.  */
 #define noreturn_type_node d_global_trees[DTI_BOTTOM_TYPE]
+/* D boolean values are always byte-sized, unlike boolean_type_node.  */
+#define d_bool_false_node  d_global_trees[DTI_BOOL_FALSE]
+#define d_bool_true_node   d_global_trees[DTI_BOOL_TRUE]
 
 /* A prefix for internal variables, which are not user-visible.  */
 #if !defined (NO_DOT_IN_LABEL)
diff --git a/gcc/d/modules.cc b/gcc/d/modules.cc
index 8d6c8f0f9ad..e3c1ef9f82e 100644
--- a/gcc/d/modules.cc
+++ b/gcc/d/modules.cc
@@ -330,7 +330,7 @@ 

[committed] d: Add warning for call expression without side effects

2023-10-28 Thread Iain Buclaw
Hi,

In the last merge of the dmd front-end with upstream (r14-4830), this
warning got removed from the semantic passes.  Reimplement the warning
for the code generation pass instead, where it cannot have an effect on
conditional compilation.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* d-codegen.cc (call_side_effect_free_p): New function.
* d-tree.h (CALL_EXPR_WARN_IF_UNUSED): New macro.
(call_side_effect_free_p): New prototype.
* expr.cc (ExprVisitor::visit (CallExp *)): Set
CALL_EXPR_WARN_IF_UNUSED on matched call expressions.
(ExprVisitor::visit (NewExp *)): Don't dereference the result of an
allocation call here.
* toir.cc (add_stmt): Emit warning when call expression added to
statement list without being used.

gcc/testsuite/ChangeLog:

* gdc.dg/Wunused_value.d: New test.
---
 gcc/d/d-codegen.cc   | 54 
 gcc/d/d-tree.h   |  7 
 gcc/d/expr.cc| 13 ++-
 gcc/d/toir.cc| 32 +
 gcc/testsuite/gdc.dg/Wunused_value.d | 29 +++
 5 files changed, 134 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gdc.dg/Wunused_value.d

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 155f5d0d618..8c2e6c70ed4 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -2102,6 +2102,60 @@ get_function_type (Type *t)
   return tf;
 }
 
+/* Returns TRUE if calling the function FUNC, or the function or delegate type
+   TYPE is free of side effects.  */
+
+bool
+call_side_effect_free_p (FuncDeclaration *func, Type *type)
+{
+  gcc_assert (func != NULL || type != NULL);
+
+  if (func != NULL)
+{
+  /* Constructor and invariant calls can't be `pure'.  */
+  if (func->isCtorDeclaration () || func->isInvariantDeclaration ())
+   return false;
+
+  /* Must be a `nothrow' function.  */
+  TypeFunction *tf = func->type->toTypeFunction ();
+  if (!tf->isnothrow ())
+   return false;
+
+  /* Return type can't be `void' or `noreturn', as that implies all work is
+done via side effects.  */
+  if (tf->next->ty == TY::Tvoid || tf->next->ty == TY::Tnoreturn)
+   return false;
+
+  /* Only consider it as `pure' if it can't modify its arguments.  */
+  if (func->isPure () == PURE::const_)
+   return true;
+}
+
+  if (type != NULL)
+{
+  TypeFunction *tf = get_function_type (type);
+
+  /* Must be a `nothrow` function type.  */
+  if (tf == NULL || !tf->isnothrow ())
+   return false;
+
+  /* Return type can't be `void' or `noreturn', as that implies all work is
+done via side effects.  */
+  if (tf->next->ty == TY::Tvoid || tf->next->ty == TY::Tnoreturn)
+   return false;
+
+  /* Delegates that can modify its context can't be `pure'.  */
+  if (type->isTypeDelegate () && tf->isMutable ())
+   return false;
+
+  /* Only consider it as `pure' if it can't modify its arguments.  */
+  if (tf->purity == PURE::const_)
+   return true;
+}
+
+  return false;
+}
+
 /* Returns TRUE if CALLEE is a plain nested function outside the scope of
CALLER.  In which case, CALLEE is being called through an alias that was
passed to CALLER.  */
diff --git a/gcc/d/d-tree.h b/gcc/d/d-tree.h
index 66c2f2465c8..ed26533feb4 100644
--- a/gcc/d/d-tree.h
+++ b/gcc/d/d-tree.h
@@ -47,6 +47,7 @@ typedef Array  Expressions;
 
 /* Usage of TREE_LANG_FLAG_?:
0: METHOD_CALL_EXPR
+   1: CALL_EXPR_WARN_IF_UNUSED (in CALL_EXPR).
 
Usage of TYPE_LANG_FLAG_?:
0: TYPE_SHARED
@@ -357,6 +358,11 @@ lang_tree_node
 #define METHOD_CALL_EXPR(NODE) \
   (TREE_LANG_FLAG_0 (NODE))
 
+/* True if the CALL_EXPR is free of side effects, and its return value
+   should not be discarded.  */
+#define CALL_EXPR_WARN_IF_UNUSED(NODE) \
+  (TREE_LANG_FLAG_1 (CALL_EXPR_CHECK (NODE)))
+
 /* True if the type was declared 'shared'.  */
 #define TYPE_SHARED(NODE) \
   (TYPE_LANG_FLAG_0 (NODE))
@@ -594,6 +600,7 @@ extern tree build_bounds_slice_condition (SliceExp *, tree, 
tree, tree);
 extern bool array_bounds_check (void);
 extern bool checkaction_trap_p (void);
 extern TypeFunction *get_function_type (Type *);
+extern bool call_side_effect_free_p (FuncDeclaration *, Type *);
 extern bool call_by_alias_p (FuncDeclaration *, FuncDeclaration *);
 extern tree d_build_call_expr (FuncDeclaration *, tree, Expressions *);
 extern tree d_build_call (TypeFunction *, tree, tree, Expressions *);
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 52243e61899..72180b100af 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -1714,6 +1714,12 @@ public:
build the call expression.  */
 tree exp = d_build_call (tf, callee, object, e->arguments);
 
+/* Record whether the call expression has no side effects, so we can check
+   for an 

[committed] d: Merge upstream dmd f4be7f6f7b.

2023-10-22 Thread Iain Buclaw
Hi,

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

Synchronizing with the upstream development branch as of 2023-10-22.

D front-end changes:

- Fix bootstrap failure with i686-darwin9.
  ```
  Undefined symbols for architecture i386:
  "gendocfile", referenced from:
  __ZL20d_generate_ddoc_fileP6ModuleR9OutBuffer in d-lang.o
  ld: symbol(s) not found for architecture i386
  ```

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd f4be7f6f7b.
* Make-lang.in (D_FRONTEND_OBJS): Rename d/root-rootobject.o to
d/rootobject.o.
---
 gcc/d/Make-lang.in|   2 +-
 gcc/d/dmd/MERGE   |   2 +-
 gcc/d/dmd/README.md   |   1 +
 gcc/d/dmd/arraytypes.d|   2 +-
 gcc/d/dmd/ast_node.d  |   2 +-
 gcc/d/dmd/blockexit.d |  20 +-
 gcc/d/dmd/cond.d  |   2 +-
 gcc/d/dmd/cppmangle.d |   2 +-
 gcc/d/dmd/declaration.d   |   2 +-
 gcc/d/dmd/dinterpret.d|  18 +-
 gcc/d/dmd/dmodule.d   |   2 +-
 gcc/d/dmd/doc.h   |   4 +-
 gcc/d/dmd/dscope.d|   6 -
 gcc/d/dmd/dsymbol.d   |   2 +-
 gcc/d/dmd/dsymbolsem.d|   8 +-
 gcc/d/dmd/dtemplate.d |   2 +-
 gcc/d/dmd/dtoh.d  |   2 +-
 gcc/d/dmd/escape.d|   2 +-
 gcc/d/dmd/expression.d| 284 +
 gcc/d/dmd/expression.h|   1 -
 gcc/d/dmd/expressionsem.d | 300 --
 gcc/d/dmd/foreachvar.d|   2 +-
 gcc/d/dmd/func.d  |  12 +-
 gcc/d/dmd/hdrgen.d|   2 +-
 gcc/d/dmd/identifier.d|   2 +-
 gcc/d/dmd/init.d  |   2 +-
 gcc/d/dmd/json.d  |   2 +-
 gcc/d/dmd/mtype.d |   2 +-
 gcc/d/dmd/mustuse.d   |  23 +-
 gcc/d/dmd/nogc.d  |   2 +-
 gcc/d/dmd/ob.d|   2 +-
 gcc/d/dmd/parse.d |   2 +-
 gcc/d/dmd/{root => }/rootobject.d |   8 +-
 gcc/d/dmd/semantic2.d |   2 +-
 gcc/d/dmd/semantic3.d |   2 +-
 gcc/d/dmd/sideeffect.d|  35 --
 gcc/d/dmd/statement.d |   2 +-
 gcc/d/dmd/statement.h |   3 -
 gcc/d/dmd/templateparamsem.d  |   2 +-
 gcc/d/dmd/traits.d|   2 +-
 gcc/d/dmd/transitivevisitor.d |   2 +-
 gcc/d/dmd/typesem.d   |   2 +-
 gcc/d/dmd/visitor.d   |   2 +-
 .../gdc.test/fail_compilation/fail3882.d  |  31 +-
 gcc/testsuite/gdc.test/runnable/issue24168.d  |  31 ++
 45 files changed, 375 insertions(+), 468 deletions(-)
 rename gcc/d/dmd/{root => }/rootobject.d (88%)
 create mode 100644 gcc/testsuite/gdc.test/runnable/issue24168.d

diff --git a/gcc/d/Make-lang.in b/gcc/d/Make-lang.in
index 264ae03a89e..b3007a96bd0 100644
--- a/gcc/d/Make-lang.in
+++ b/gcc/d/Make-lang.in
@@ -174,11 +174,11 @@ D_FRONTEND_OBJS = \
d/root-port.o \
d/root-region.o \
d/root-rmem.o \
-   d/root-rootobject.o \
d/root-speller.o \
d/root-string.o \
d/root-stringtable.o \
d/root-utf.o \
+   d/rootobject.o \
d/safe.o \
d/sapply.o \
d/semantic2.o \
diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index 794600274a3..bfadeaa0c68 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-4c18eed9674e04c1ca89fbc8bd5c4e483eb5477c
+f4be7f6f7bae75f1613b862940cdd533b5ae99b2
 
 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/README.md b/gcc/d/dmd/README.md
index d0c75a5b14a..f8ac00117eb 100644
--- a/gcc/d/dmd/README.md
+++ b/gcc/d/dmd/README.md
@@ -84,6 +84,7 @@
 | 
[astcodegen.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/astcodegen.d)
 | Namespace of AST nodes of a AST ready for code generation   |
 | 
[astenums.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/astenums.d)
 | Enums common to DMD and AST |
 | 
[expression.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/expression.d)
 | Define expression AST nodes |
+| 
[rootobject.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/rootobject.d)
 | 

[committed] d: Forbid taking the address of an intrinsic with no implementation

2023-10-16 Thread Iain Buclaw
Hi,

This code fails to link:

import core.math;
real function(real) fn = 

However, when called directly, the D intrinsic `sin()' is expanded by
the front-end into the GCC built-in `__builtin_sin()'.  This has been
fixed to now also expand the function when a reference is taken.

As there are D intrinsics and GCC built-ins that don't have a fallback
implementation, raise an error if taking the address is not possible.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* d-tree.h (intrinsic_code): Update define for DEF_D_INTRINSIC.
(maybe_reject_intrinsic): New prototype.
* expr.cc (ExprVisitor::visit (SymOffExp *)): Call
maybe_reject_intrinsic.
* intrinsics.cc (intrinsic_decl): Add fallback field.
(intrinsic_decls): Update define for DEF_D_INTRINSIC.
(maybe_reject_intrinsic): New function.
* intrinsics.def (DEF_D_LIB_BUILTIN): Update.
(DEF_CTFE_BUILTIN): Update.
(INTRINSIC_BSF): Declare as library builtin.
(INTRINSIC_BSR): Likewise.
(INTRINSIC_BT): Likewise.
(INTRINSIC_BSF64): Likewise.
(INTRINSIC_BSR64): Likewise.
(INTRINSIC_BT64): Likewise.
(INTRINSIC_POPCNT32): Likewise.
(INTRINSIC_POPCNT64): Likewise.
(INTRINSIC_ROL): Likewise.
(INTRINSIC_ROL_TIARG): Likewise.
(INTRINSIC_ROR): Likewise.
(INTRINSIC_ROR_TIARG): Likewise.
(INTRINSIC_ADDS): Likewise.
(INTRINSIC_ADDSL): Likewise.
(INTRINSIC_ADDU): Likewise.
(INTRINSIC_ADDUL): Likewise.
(INTRINSIC_SUBS): Likewise.
(INTRINSIC_SUBSL): Likewise.
(INTRINSIC_SUBU): Likewise.
(INTRINSIC_SUBUL): Likewise.
(INTRINSIC_MULS): Likewise.
(INTRINSIC_MULSL): Likewise.
(INTRINSIC_MULU): Likewise.
(INTRINSIC_MULUI): Likewise.
(INTRINSIC_MULUL): Likewise.
(INTRINSIC_NEGS): Likewise.
(INTRINSIC_NEGSL): Likewise.
(INTRINSIC_TOPRECF): Likewise.
(INTRINSIC_TOPREC): Likewise.
(INTRINSIC_TOPRECL): Likewise.

gcc/testsuite/ChangeLog:

* gdc.dg/builtins_reject.d: New test.
* gdc.dg/intrinsics_reject.d: New test.
---
 gcc/d/d-tree.h   |   3 +-
 gcc/d/expr.cc|   3 +
 gcc/d/intrinsics.cc  |  47 -
 gcc/d/intrinsics.def | 128 ---
 gcc/testsuite/gdc.dg/builtins_reject.d   |  17 +++
 gcc/testsuite/gdc.dg/intrinsics_reject.d |  87 +++
 6 files changed, 222 insertions(+), 63 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/builtins_reject.d
 create mode 100644 gcc/testsuite/gdc.dg/intrinsics_reject.d

diff --git a/gcc/d/d-tree.h b/gcc/d/d-tree.h
index b64a6fb46f9..66c2f2465c8 100644
--- a/gcc/d/d-tree.h
+++ b/gcc/d/d-tree.h
@@ -94,7 +94,7 @@ enum level_kind
 
 enum intrinsic_code
 {
-#define DEF_D_INTRINSIC(CODE, B, N, M, D, C) CODE,
+#define DEF_D_INTRINSIC(CODE, B, N, M, D, C, F) CODE,
 
 #include "intrinsics.def"
 
@@ -668,6 +668,7 @@ extern tree build_import_decl (Dsymbol *);
 /* In intrinsics.cc.  */
 extern void maybe_set_intrinsic (FuncDeclaration *);
 extern tree maybe_expand_intrinsic (tree);
+extern tree maybe_reject_intrinsic (tree);
 
 /* In modules.cc.  */
 extern void build_module_tree (Module *);
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index cc4aa03dfb9..52243e61899 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -2050,6 +2050,9 @@ public:
 tree result = get_decl_tree (e->var);
 TREE_USED (result) = 1;
 
+if (e->var->isFuncDeclaration ())
+  result = maybe_reject_intrinsic (result);
+
 if (declaration_reference_p (e->var))
   gcc_assert (POINTER_TYPE_P (TREE_TYPE (result)));
 else
diff --git a/gcc/d/intrinsics.cc b/gcc/d/intrinsics.cc
index 583d5a9dea6..1b03e9edbdb 100644
--- a/gcc/d/intrinsics.cc
+++ b/gcc/d/intrinsics.cc
@@ -60,12 +60,15 @@ struct intrinsic_decl
 
   /* True if the intrinsic is only handled in CTFE.  */
   bool ctfeonly;
+
+  /* True if the intrinsic has a library implementation.  */
+  bool fallback;
 };
 
 static const intrinsic_decl intrinsic_decls[] =
 {
-#define DEF_D_INTRINSIC(CODE, BUILTIN, NAME, MODULE, DECO, CTFE) \
-{ CODE, BUILTIN, NAME, MODULE, DECO, CTFE },
+#define DEF_D_INTRINSIC(CODE, BUILTIN, NAME, MODULE, DECO, CTFE, FALLBACK) \
+{ CODE, BUILTIN, NAME, MODULE, DECO, CTFE, FALLBACK },
 
 #include "intrinsics.def"
 
@@ -1436,3 +1439,43 @@ maybe_expand_intrinsic (tree callexp)
   gcc_unreachable ();
 }
 }
+
+/* If FNDECL is an intrinsic, return the FUNCTION_DECL that has a library
+   fallback implementation of it, otherwise raise an error.  */
+
+tree
+maybe_reject_intrinsic (tree fndecl)
+{
+  gcc_assert (TREE_CODE (fndecl) == FUNCTION_DECL);
+
+  intrinsic_code intrinsic = DECL_INTRINSIC_CODE (fndecl);
+
+  if (intrinsic == INTRINSIC_NONE)
+{
+

[committed] d: Merge upstream dmd, druntime 4c18eed967, phobos d945686a4.

2023-10-16 Thread Iain Buclaw
Hi,

This patch merges the D front-end and run-time library with upstream dmd
4c18eed967, and standard library with phobos d945686a4.

Synchronizing with the upstream development branch as of 2023-10-16.

D front-end changes:

- Import latest fixes to mainline.

D runtime changes:

- Import latest fixes to mainline.

Phobos changes:

- Import latest fixes to mainline.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 4c18eed967.
* d-diagnostic.cc (verrorReport): Update for new front-end interface.
(verrorReportSupplemental): Likewise.
* d-lang.cc (d_init_options): Likewise.
(d_handle_option): Likewise.
(d_post_options): Likewise.
(d_parse_file): Likewise.
* decl.cc (get_symbol_decl): Likewise.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 4c18eed967.
* src/MERGE: Merge upstream phobos d945686a4.
---
 gcc/d/d-diagnostic.cc |   4 +-
 gcc/d/d-lang.cc   |  86 +-
 gcc/d/decl.cc |   4 +-
 gcc/d/dmd/MERGE   |   2 +-
 gcc/d/dmd/access.d|   3 +-
 gcc/d/dmd/aggregate.d |  11 +-
 gcc/d/dmd/aggregate.h |   1 +
 gcc/d/dmd/arrayop.d   |  11 +-
 gcc/d/dmd/attrib.d|   7 +-
 gcc/d/dmd/blockexit.d |  19 +-
 gcc/d/dmd/canthrow.d  |  43 +-
 gcc/d/dmd/clone.d |   2 +-
 gcc/d/dmd/compiler.d  |   1 -
 gcc/d/dmd/cond.d  |   4 +
 gcc/d/dmd/constfold.d |  18 +-
 gcc/d/dmd/cparse.d|   5 +-
 gcc/d/dmd/cppmangle.d |  10 +-
 gcc/d/dmd/ctfe.h  |   1 -
 gcc/d/dmd/ctfeexpr.d  |   8 +-
 gcc/d/dmd/dcast.d |  53 +-
 gcc/d/dmd/dclass.d|  58 +-
 gcc/d/dmd/declaration.d   |  16 +-
 gcc/d/dmd/denum.d |   5 +-
 gcc/d/dmd/dimport.d   |   2 +-
 gcc/d/dmd/dinterpret.d| 296 +++
 gcc/d/dmd/dmangle.d   |  20 +-
 gcc/d/dmd/dmodule.d   |  44 +-
 gcc/d/dmd/doc.d   |   2 +-
 gcc/d/dmd/dstruct.d   |   2 +-
 gcc/d/dmd/dsymbol.d   |  87 +-
 gcc/d/dmd/dsymbol.h   |   4 -
 gcc/d/dmd/dsymbolsem.d| 306 +++
 gcc/d/dmd/dtemplate.d |  69 +-
 gcc/d/dmd/dtoh.d  |  20 +
 gcc/d/dmd/dversion.d  |  13 +-
 gcc/d/dmd/expression.d| 336 +++-
 gcc/d/dmd/expression.h|   6 +-
 gcc/d/dmd/expressionsem.d | 439 +-
 gcc/d/dmd/func.d  |  36 +-
 gcc/d/dmd/globals.d   |  57 +-
 gcc/d/dmd/globals.h   |  48 +-
 gcc/d/dmd/hdrgen.d| 760 ++
 gcc/d/dmd/iasm.d  |   1 +
 gcc/d/dmd/id.d|   2 +
 gcc/d/dmd/importc.d   |   5 +-
 gcc/d/dmd/init.d  |   8 -
 gcc/d/dmd/init.h  |   2 -
 gcc/d/dmd/initsem.d   |  31 +-
 gcc/d/dmd/json.d  |   4 +-
 gcc/d/dmd/lexer.d |  75 +-
 gcc/d/dmd/mtype.d |   6 +-
 gcc/d/dmd/mustuse.d   |   3 +-
 gcc/d/dmd/nogc.d  |   4 +-
 gcc/d/dmd/nspace.d|   3 +-
 gcc/d/dmd/ob.d|  20 +-
 gcc/d/dmd/objc.d  |  32 +-
 gcc/d/dmd/opover.d|  32 +-
 gcc/d/dmd/optimize.d  |  53 +-
 gcc/d/dmd/parse.d |  15 +-
 gcc/d/dmd/root/filename.d |   7 +-
 gcc/d/dmd/root/rootobject.d   |   6 +-
 gcc/d/dmd/semantic2.d |  34 +-
 gcc/d/dmd/semantic3.d |  48 +-
 gcc/d/dmd/sideeffect.d|   9 +-
 gcc/d/dmd/statement.d | 167 +---
 gcc/d/dmd/statement.h |   8 +-
 gcc/d/dmd/statementsem.d  | 192 -
 gcc/d/dmd/staticcond.d|   3 +-
 gcc/d/dmd/traits.d| 104 +--
 gcc/d/dmd/typesem.d   |  42 +-

[committed] d: Merge upstream dmd, druntime f9efc98fd7, phobos a3f22129d.

2023-10-15 Thread Iain Buclaw
Hi,

This patch merges the D front-end and run-time library with upstream dmd
f9efc98fd7, and standard library with phobos a3f22129d.

Synchronizing with the latest bug fixes in the v2.105.2 release.

D front-end changes:

- Import dmd v2.105.2.
- A function with enum storage class is now deprecated.
- Global variables can now be initialized with Associative
  Arrays.
- Improvements for the C++ header generation of static variables
  used in a default argument context.

D runtime changes:

- Import druntime v2.105.2.
- The `core.memory.GC' functions `GC.enable', `GC.disable',
  `GC.collect', and `GC.minimize' `have been marked `@safe'.

Phobos changes:

- Import phobos v2.105.2.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd f9efc98fd7.
* dmd/VERSION: Bump version to v2.105.2.
* d-builtins.cc (build_frontend_type): Update for new front-end
interface.
* d-diagnostic.cc (verrorReport): Don't emit tips when error gagging
is turned on.
* d-lang.cc (d_handle_option): Remove obsolete parameter.
(d_post_options): Likewise.
(d_read_ddoc_files): New function.
(d_generate_ddoc_file): New function.
(d_parse_file): Update for new front-end interface.
* expr.cc (ExprVisitor::visit (AssocArrayLiteralExp *)): Check for new
front-end lowering of static associative arrays.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime f9efc98fd7.
* libdruntime/Makefile.am (DRUNTIME_DSOURCES): Add
core/internal/newaa.d.
* libdruntime/Makefile.in: Regenerate.
* src/MERGE: Merge upstream phobos a3f22129d.
* testsuite/libphobos.hash/test_hash.d: Update test.
* testsuite/libphobos.phobos/phobos.exp: Add compiler flags
-Wno-deprecated.
* testsuite/libphobos.phobos_shared/phobos_shared.exp: Likewise.

gcc/testsuite/ChangeLog:

* lib/gdc-utils.exp (gdc-convert-args): Handle new compiler options.
---
 gcc/d/d-builtins.cc   |   3 +-
 gcc/d/d-diagnostic.cc |   5 +-
 gcc/d/d-lang.cc   |  78 +++-
 gcc/d/dmd/MERGE   |   2 +-
 gcc/d/dmd/VERSION |   2 +-
 gcc/d/dmd/attrib.d|   2 +-
 gcc/d/dmd/blockexit.d | 107 +++--
 gcc/d/dmd/canthrow.d  |   2 +-
 gcc/d/dmd/chkformat.d |  32 +-
 gcc/d/dmd/clone.d |  20 +-
 gcc/d/dmd/cond.d  |   2 +-
 gcc/d/dmd/cparse.d|  11 +-
 gcc/d/dmd/cppmangle.d |   2 -
 gcc/d/dmd/ctfeexpr.d  |   6 +-
 gcc/d/dmd/dcast.d |  13 +-
 gcc/d/dmd/dclass.d|   6 +-
 gcc/d/dmd/declaration.d   |   7 +-
 gcc/d/dmd/delegatize.d|   1 -
 gcc/d/dmd/denum.d |   2 -
 gcc/d/dmd/dinterpret.d|  14 +-
 gcc/d/dmd/dmacro.d|  56 ++-
 gcc/d/dmd/dmodule.d   |   4 +-
 gcc/d/dmd/doc.d   | 353 -
 gcc/d/dmd/doc.h   |   3 +-
 gcc/d/dmd/dscope.d|   1 +
 gcc/d/dmd/dstruct.d   |   1 +
 gcc/d/dmd/dsymbol.d   |   1 +
 gcc/d/dmd/dsymbolsem.d|  58 ++-
 gcc/d/dmd/dtemplate.d |  24 +-
 gcc/d/dmd/dtoh.d  |  10 +-
 gcc/d/dmd/errors.h|   3 +-
 gcc/d/dmd/errorsink.d |   1 +
 gcc/d/dmd/escape.d|  40 +-
 gcc/d/dmd/expression.d|  47 ++-
 gcc/d/dmd/expression.h|   3 +-
 gcc/d/dmd/expressionsem.d | 109 ++---
 gcc/d/dmd/func.d  |  21 +-
 gcc/d/dmd/globals.d   |  33 +-
 gcc/d/dmd/globals.h   |  35 +-
 gcc/d/dmd/hdrgen.d| 375 +-
 gcc/d/dmd/hdrgen.h|   4 +-
 gcc/d/dmd/iasmgcc.d   |   2 +-
 gcc/d/dmd/id.d|   2 +
 gcc/d/dmd/init.d  |   2 +-
 gcc/d/dmd/initsem.d   |  31 +-
 gcc/d/dmd/json.d  |  23 +-
 gcc/d/dmd/json.h  |   2 +-
 gcc/d/dmd/lexer.d |  88 +++-
 gcc/d/dmd/location.d  |  20 +-
 gcc/d/dmd/module.h

[committed] Fix ICE in set_cell_span, at text-art/table.cc:148 with D front-end and -fanalyzer

2023-10-14 Thread Iain Buclaw
Hi,

The internal error in analyzer turned out to be caused by a subtly
invalid tree representation of STRING_CSTs in the D front-end, fixed by
including the terminating NULL as part of the TREE_STRING_POINTER.

When adding a first analyzer test for D, it flagged up another subtle
mismatch in one assignment in the module support routines as well, fixed
by generating the correct field type for the compiler-generated struct.

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

Regards,
Iain.

---
PR d/111537

gcc/d/ChangeLog:

* expr.cc (ExprVisitor::visit (StringExp *)): Include null terminator
in STRING_CST string.
* modules.cc (get_compiler_dso_type): Generate ModuleInfo** type for
the minfo fields.

gcc/testsuite/ChangeLog:

* gdc.dg/analyzer/analyzer.exp: New test.
* gdc.dg/analyzer/pr111537.d: New test.
---
 gcc/d/expr.cc  |  6 +--
 gcc/d/modules.cc   |  9 ++--
 gcc/testsuite/gdc.dg/analyzer/analyzer.exp | 51 ++
 gcc/testsuite/gdc.dg/analyzer/pr111537.d   |  7 +++
 4 files changed, 66 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/analyzer/analyzer.exp
 create mode 100644 gcc/testsuite/gdc.dg/analyzer/pr111537.d

diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 7038655bc94..551d004c241 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -2535,13 +2535,13 @@ public:
   {
/* Copy the string contents to a null terminated string.  */
dinteger_t length = (e->len * e->sz);
-   char *string = XALLOCAVEC (char, length + 1);
+   char *string = XALLOCAVEC (char, length + e->sz);
+   memset (string, 0, length + e->sz);
if (length > 0)
  memcpy (string, e->string, length);
-   string[length] = '\0';
 
/* String value and type includes the null terminator.  */
-   tree value = build_string (length, string);
+   tree value = build_string (length + e->sz, string);
TREE_TYPE (value) = make_array_type (tb->nextOf (), length + 1);
value = build_address (value);
 
diff --git a/gcc/d/modules.cc b/gcc/d/modules.cc
index f2180d30546..8d6c8f0f9ad 100644
--- a/gcc/d/modules.cc
+++ b/gcc/d/modules.cc
@@ -277,12 +277,13 @@ get_compiler_dso_type (void)
   DECL_CHAIN (field) = fields;
   fields = field;
 
-  field = create_field_decl (build_pointer_type (get_moduleinfo_type ()),
-NULL, 1, 1);
+  tree moduleinfo_ptr_ptr_type =
+build_pointer_type (build_pointer_type (get_moduleinfo_type ()));
+
+  field = create_field_decl (moduleinfo_ptr_ptr_type, NULL, 1, 1);
   DECL_CHAIN (field) = fields;
   fields = field;
-  field = create_field_decl (build_pointer_type (get_moduleinfo_type ()),
-NULL, 1, 1);
+  field = create_field_decl (moduleinfo_ptr_ptr_type, NULL, 1, 1);
   DECL_CHAIN (field) = fields;
   fields = field;
 
diff --git a/gcc/testsuite/gdc.dg/analyzer/analyzer.exp 
b/gcc/testsuite/gdc.dg/analyzer/analyzer.exp
new file mode 100644
index 000..7b82b8e0cd1
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/analyzer/analyzer.exp
@@ -0,0 +1,51 @@
+#  Copyright (C) 2023 Free Software Foundation, Inc.
+
+#  This file is part of GCC.
+#
+#  GCC 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, or (at your option) any later
+#  version.
+#
+#  GCC 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
+#  .
+
+# GCC testsuite that uses the `dg.exp' driver.
+
+# Load support procs.
+load_lib gdc-dg.exp
+
+# If the analyzer has not been enabled, bail.
+if { ![check_effective_target_analyzer] } {
+return
+}
+
+global DEFAULT_DFLAGS
+if [info exists DEFAULT_DFLAGS] then {
+  set save_default_dflags $DEFAULT_DFLAGS
+}
+
+# If a testcase doesn't have special options, use these.
+set DEFAULT_DFLAGS "-fanalyzer -Wanalyzer-too-complex 
-fanalyzer-call-summaries"
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+gdc-dg-runtest [lsort \
+   [glob -nocomplain $srcdir/$subdir/*.d ] ] "" $DEFAULT_DFLAGS
+
+# All done.
+dg-finish
+
+if [info exists save_default_dflags] {
+  set DEFAULT_DFLAGS $save_default_dflags
+} else {
+  unset DEFAULT_DFLAGS
+}
diff --git a/gcc/testsuite/gdc.dg/analyzer/pr111537.d 
b/gcc/testsuite/gdc.dg/analyzer/pr111537.d
new file mode 100644
index 000..e50b05a3f79
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/analyzer/pr111537.d
@@ -0,0 +1,7 @@
+// { dg-do compile }
+import core.stdc.string;
+void main()
+{
+char[5] arr;
+

[committed] d: Reduce code duplication of writing generated files.

2023-10-14 Thread Iain Buclaw
Hi,

This is a small refactoring ahead of the next merge from upstream, where
a few more front-end routines will stop doing the file handling
themselves.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* d-lang.cc (d_write_file): New function.
(d_parse_file): Reduce code duplication.
---
 gcc/d/d-lang.cc | 91 -
 1 file changed, 29 insertions(+), 62 deletions(-)

diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index 7dddcf5ac91..f290acf494b 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -978,6 +978,30 @@ d_add_builtin_module (Module *m)
   builtin_modules.push (m);
 }
 
+/* Writes to FILENAME.  DATA is the full content of the file to be written.  */
+
+static void
+d_write_file (const char *filename, const char *data)
+{
+  FILE *stream;
+
+  if (filename && (filename[0] != '-' || filename[1] != '\0'))
+stream = fopen (filename, "w");
+  else
+stream = stdout;
+
+  if (!stream)
+{
+  error ("unable to open %s for writing: %m", filename);
+  return;
+}
+
+  fprintf (stream, "%s", data);
+
+  if (stream != stdout && (ferror (stream) || fclose (stream)))
+error ("writing output file %s: %m", filename);
+}
+
 /* Implements the lang_hooks.parse_file routine for language D.  */
 
 static void
@@ -1264,8 +1288,6 @@ d_parse_file (void)
   if (d_option.deps)
 {
   obstack buffer;
-  FILE *deps_stream;
-
   gcc_obstack_init ();
 
   for (size_t i = 0; i < modules.length; i++)
@@ -1275,27 +1297,8 @@ d_parse_file (void)
   if (d_option.deps_filename_user)
d_option.deps_filename = d_option.deps_filename_user;
 
-  if (d_option.deps_filename)
-   {
- deps_stream = fopen (d_option.deps_filename, "w");
- if (!deps_stream)
-   {
- fatal_error (input_location, "opening dependency file %s: %m",
-  d_option.deps_filename);
- goto had_errors;
-   }
-   }
-  else
-   deps_stream = stdout;
-
-  fprintf (deps_stream, "%s", (char *) obstack_finish ());
-
-  if (deps_stream != stdout
- && (ferror (deps_stream) || fclose (deps_stream)))
-   {
- fatal_error (input_location, "closing dependency file %s: %m",
-  d_option.deps_filename);
-   }
+  d_write_file (d_option.deps_filename,
+   (char *) obstack_finish ());
 }
 
   if (global.params.vtemplates)
@@ -1306,29 +1309,7 @@ d_parse_file (void)
 {
   OutBuffer buf;
   json_generate (, );
-
-  const char *name = global.params.json.name.ptr;
-  FILE *json_stream;
-
-  if (name && (name[0] != '-' || name[1] != '\0'))
-   {
- const char *nameext
-   = FileName::defaultExt (name, json_ext.ptr);
- json_stream = fopen (nameext, "w");
- if (!json_stream)
-   {
- fatal_error (input_location, "opening json file %s: %m", nameext);
- goto had_errors;
-   }
-   }
-  else
-   json_stream = stdout;
-
-  fprintf (json_stream, "%s", buf.peekChars ());
-
-  if (json_stream != stdout
- && (ferror (json_stream) || fclose (json_stream)))
-   fatal_error (input_location, "closing json file %s: %m", name);
+  d_write_file (global.params.json.name.ptr, buf.peekChars ());
 }
 
   /* Generate Ddoc files.  */
@@ -1391,22 +1372,8 @@ d_parse_file (void)
   /* We want to write the mixin expansion file also on error.  */
   if (global.params.mixinOut.doOutput)
 {
-  FILE *mixin_stream = fopen (global.params.mixinOut.name.ptr, "w");
-
-  if (mixin_stream)
-   {
- OutBuffer *buf = global.params.mixinOut.buffer;
- fprintf (mixin_stream, "%s", buf->peekChars ());
-
- if (ferror (mixin_stream) || fclose (mixin_stream))
-   fatal_error (input_location, "closing mixin file %s: %m",
-global.params.mixinOut.name.ptr);
-   }
-  else
-   {
- fatal_error (input_location, "opening mixin file %s: %m",
-  global.params.mixinOut.name.ptr);
-   }
+  d_write_file (global.params.mixinOut.name.ptr,
+   global.params.mixinOut.buffer->peekChars ());
 }
 
   /* Remove generated .di files on error.  */
-- 
2.39.2



Re: [PATCH 1/1] gcc/d: add LoongArch64 support for D frontend

2023-09-24 Thread Iain Buclaw
Excerpts from liushuyu's message of September 24, 2023 1:21 am:
> 
> gcc/ChangeLog:
> 
>   * config.gcc: add loongarch-d.o to d_target_objs for LoongArch
>   architecture.
> 
> gcc/config/ChangeLog:
> 
>   * loongarch/loongarch-d.cc
>   (loongarch_d_target_versions): add interface function to define builtin
>   D versions for LoongArch architecture.
>   (loongarch_d_handle_target_float_abi): add interface function to define
>   builtin D traits for LoongArch architecture.
>   (loongarch_d_register_target_info): add interface function to register
>   loongarch_d_handle_target_float_abi function.
>   * loongarch/loongarch-d.h:
>   (loongarch_d_target_versions): add function prototype.
>   (loongarch_d_register_target_info): Likewise.
>   * loongarch/t-loongarch: add object target for loongarch-d.cc.
> 
> gcc/testsuite/ChangeLog:
> 
>   * gdc.test/fail_compilation/reserved_version.d: add reserved version
>   tests for LoongArch architecture and also updated expected output.
>   * gdc.test/fail_compilation/reserved_version_switch.d: Likewise.
> 
> libphobos/ChangeLog:
> 
>   * configure.tgt: enable libphobos for LoongArch architecture.
>   * configure: Regenerate.
>   * libdruntime/gcc/sections/elf.d: add TLS_DTV_OFFSET constant for
>   LoongArch64.
>   * libdruntime/gcc/unwind/generic.d: add __aligned__ constant for
>   LoongArch64.
>   * libdruntime/Makefile.in: Regenerate.
> 
> Signed-off-by: Zixing Liu 

Thanks, some comments below.

> diff --git a/gcc/config/loongarch/loongarch-d.cc 
> b/gcc/config/loongarch/loongarch-d.cc
> new file mode 100644
> index 000..d7875079212
> --- /dev/null
> +++ b/gcc/config/loongarch/loongarch-d.cc
> @@ -0,0 +1,82 @@
> +/* Subroutines for the D front end on the LoongArch architecture.
> +   Copyright (C) 2017-2023 Free Software Foundation, Inc.

Copyright years start from the year the source file was introduced.

> +
> +GCC 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, or (at your option)
> +any later version.
> +
> +GCC 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
> +.  */
> +
> +#define IN_TARGET_CODE 1
> +
> +#include "config.h"
> +#include "system.h"
> +#include "coretypes.h"
> +#include "tm_d.h"
> +#include "d/d-target.h"
> +#include "d/d-target-def.h"
> +
> +/* Implement TARGET_D_CPU_VERSIONS for LoongArch targets.  */
> +
> +void
> +loongarch_d_target_versions (void)
> +{
> +  if (TARGET_64BIT)
> +d_add_builtin_version ("LoongArch64");
> +  else
> +d_add_builtin_version ("LoongArch32");
> +
> +  if (TARGET_ABI_LP64)
> +d_add_builtin_version ("D_LP64");

D_LP64 is already predefined by d/d-builtins.cc if POINTER_SIZE == 64,
and it should not be confused with any LP64 ABI model.  I haven't
checked what happens if you predefine the same version twice.

> +  else
> +d_add_builtin_version ("D_LP32");

D_LP32 is not a standardized predefined version condition as far as I'm
aware. Maybe these should be LoongArch_LP64 and LoongArch_LP32 instead.

> +
> +  if (TARGET_HARD_FLOAT_ABI)
> +{
> +  d_add_builtin_version ("LoongArch_HardFloat");
> +  d_add_builtin_version ("D_HardFloat");
> +}
> +  else if (TARGET_SOFT_FLOAT_ABI)
> +{
> +  d_add_builtin_version ("LoongArch_SoftFloat");
> +  d_add_builtin_version ("D_SoftFloat");
> +}
> +}
> +
> diff --git a/gcc/testsuite/gdc.test/fail_compilation/reserved_version.d 
> b/gcc/testsuite/gdc.test/fail_compilation/reserved_version.d
> index f7a554ce729..b00b3453d85 100644
> --- a/gcc/testsuite/gdc.test/fail_compilation/reserved_version.d
> +++ b/gcc/testsuite/gdc.test/fail_compilation/reserved_version.d

These tests would be added anyway as part of merging the upstream DMD
mainline, but otherwise I wouldn't object to update them here.

Regards,
Iain.


[committed] d: Merge upstream dmd, druntime 4574d1728d, phobos d7e79f024.

2023-09-23 Thread Iain Buclaw
Hi,

This patch merges the D front-end and run-time library with upstream dmd
4574d1728d, and standard library with phobos d7e79f024.

Updating the latest changes from the v2.105.0 release.

D front-end changes:

- Import dmd v2.105.0.
- Catch clause must take only `const' or mutable exceptions.
- Creating a `scope' class instance with a non-scope constructor
  is now `@system' only with `-fpreview=dip1000'.
- Global `const' variables can no longer be initialized from a
  non-shared static constructor

D runtime changes:

- Import druntime v2.105.0.

Phobos changes:

- Import phobos v2.105.0.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 4574d1728d.
* dmd/VERSION: Bump version to v2.105.0.
* d-diagnostic.cc (verror): Remove.
(verrorSupplemental): Remove.
(vwarning): Remove.
(vwarningSupplemental): Remove.
(vdeprecation): Remove.
(vdeprecationSupplemental): Remove.
(vmessage): Remove.
(vtip): Remove.
(verrorReport): New function.
(verrorReportSupplemental): New function.
* d-lang.cc (d_parse_file): Update for new front-end interface.
* decl.cc (d_mangle_decl): Update for new front-end interface.
* intrinsics.cc (maybe_set_intrinsic): Update for new front-end
interface.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 4574d1728d.
* src/MERGE: Merge upstream phobos d7e79f024.
---
 gcc/d/d-diagnostic.cc | 199 +---
 gcc/d/d-lang.cc   |   6 +-
 gcc/d/decl.cc |   2 +-
 gcc/d/dmd/MERGE   |   2 +-
 gcc/d/dmd/README.md   |   3 +-
 gcc/d/dmd/VERSION |   2 +-
 gcc/d/dmd/access.d|   1 -
 gcc/d/dmd/aggregate.d |   2 +-
 gcc/d/dmd/aliasthis.d |   3 +-
 gcc/d/dmd/arrayop.d   |  10 +-
 gcc/d/dmd/attrib.d|  47 ++-
 gcc/d/dmd/blockexit.d |   1 -
 gcc/d/dmd/canthrow.d  |   3 +-
 gcc/d/dmd/common/file.d   |   8 +
 gcc/d/dmd/common/outbuffer.d  |  12 +-
 gcc/d/dmd/common/string.d |   5 +-
 gcc/d/dmd/cond.d  |  16 +-
 gcc/d/dmd/constfold.d |   4 +-
 gcc/d/dmd/cppmangle.d |  18 +-
 gcc/d/dmd/ctfeexpr.d  |  24 +-
 gcc/d/dmd/ctorflow.d  |   8 +-
 gcc/d/dmd/dclass.d|   2 +-
 gcc/d/dmd/declaration.d   |  30 +-
 gcc/d/dmd/declaration.h   |   4 +-
 gcc/d/dmd/delegatize.d|   4 +-
 gcc/d/dmd/dinterpret.d|  17 +-
 gcc/d/dmd/dmangle.d   |  66 ++--
 gcc/d/dmd/dmodule.d   |   6 +-
 gcc/d/dmd/doc.d   |  99 +++---
 gcc/d/dmd/doc.h   |   3 +-
 gcc/d/dmd/dscope.d|  15 +-
 gcc/d/dmd/dsymbol.d   |  52 +--
 gcc/d/dmd/dsymbolsem.d|  30 +-
 gcc/d/dmd/dtemplate.d |  22 +-
 gcc/d/dmd/dtoh.d  |  23 +-
 gcc/d/dmd/dversion.d  |   8 +-
 gcc/d/dmd/errors.d| 180 ---
 gcc/d/dmd/errors.h|  20 +-
 gcc/d/dmd/errorsink.d |   6 +
 gcc/d/dmd/escape.d|   2 +-
 gcc/d/dmd/expression.d| 303 +-
 gcc/d/dmd/expression.h|   1 +
 gcc/d/dmd/expressionsem.d |  49 ++-
 gcc/d/dmd/foreachvar.d|   2 +-
 gcc/d/dmd/func.d  |  17 +-
 gcc/d/dmd/globals.d   |  18 +-
 gcc/d/dmd/globals.h   |   2 +-
 gcc/d/dmd/hdrgen.d|  16 +-
 gcc/d/dmd/id.d|   8 +-
 gcc/d/dmd/identifier.d|   6 +-
 gcc/d/dmd/imphint.d   |   2 +-
 gcc/d/dmd/init.d  |  14 +-
 gcc/d/dmd/intrange.d  |  50 +--
 gcc/d/dmd/json.d  |   2 +-
 gcc/d/dmd/lambdacomp.d|   2 +-
 gcc/d/dmd/lexer.d |   2 +-
 gcc/d/dmd/location.d  |   6 +-
 gcc/d/dmd/mangle.h|   8 +-
 gcc/d/dmd/mtype.d |  76 ++---
 

Re: [PATCHSET] Reintroduce targetrustm hooks

2023-09-13 Thread Iain Buclaw via Gcc-patches
Excerpts from Arthur Cohen's message of September 7, 2023 3:41 pm:
> Alright, was not expecting to mess up this patchset so bad so here we go:
> 
> This patchset reintroduces proper targetrustm hooks without the old
> problematic mess of macros we had, which had been removed for the first
> merge of gccrs upstream.
> 
> Tested on x86-64 GNU Linux, and has also been present in our development
> repository for a long time - added by this pull-request from Iain [1]
> which was merged in October 2022.
> 
> Ok for trunk?
> 
> [PATCH 01/14] rust: Add skeleton support and documentation for
> [PATCH 02/14] rust: Reintroduce TARGET_RUST_CPU_INFO hook
> [PATCH 03/14] rust: Reintroduce TARGET_RUST_OS_INFO hook
> [PATCH 04/14] rust: Implement TARGET_RUST_CPU_INFO for i[34567]86-*-*
> [PATCH 05/14] rust: Implement TARGET_RUST_OS_INFO for *-*-darwin*
> [PATCH 06/14] rust: Implement TARGET_RUST_OS_INFO for *-*-freebsd*
> [PATCH 07/14] rust: Implement TARGET_RUST_OS_INFO for *-*-netbsd*
> [PATCH 08/14] rust: Implement TARGET_RUST_OS_INFO for *-*-openbsd*
> [PATCH 09/14] rust: Implement TARGET_RUST_OS_INFO for *-*-solaris2*.
> [PATCH 10/14] rust: Implement TARGET_RUST_OS_INFO for *-*-dragonfly*
> [PATCH 11/14] rust: Implement TARGET_RUST_OS_INFO for *-*-vxworks*
> [PATCH 12/14] rust: Implement TARGET_RUST_OS_INFO for *-*-fuchsia*.
> [PATCH 13/14] rust: Implement TARGET_RUST_OS_INFO for
> [PATCH 14/14] rust: Implement TARGET_RUST_OS_INFO for *-*-*linux*.
> 

Thanks for eventually getting round to this.

As the co-author of this patch series, I'm not going to look at it.

FWIW, these being Rust-specific target changes isolated to just
Rust-specific files, you should have the automony to commit without
needing any request for review - at least this is my understanding when
have made D-specific target changes in the past that have not touched
common back-end headers.

I'll let someone else confirm and check over the shared parts touched by
the patch however.

For reviewers, this is pretty much a mirror of the D front-end's CPU and
OS-specific target hooks (D has built-in version identifiers, not
built-in attributes, but both Rust and D are otherwise the same in the
kind of information exposed by them).

> [1]: https://github.com/Rust-GCC/gccrs/pull/1543
> 

The other GitHub pull request that added these is here.

https://github.com/Rust-GCC/gccrs/pull/1596

Regards,
Iain.


Re: [PATCH] Allow target attributes in non-gnu namespaces

2023-09-13 Thread Iain Buclaw via Gcc-patches
Excerpts from Richard Sandiford via Gcc-patches's message of September 8, 2023 
6:29 pm:
> Currently there are four static sources of attributes:
> 
> - LANG_HOOKS_ATTRIBUTE_TABLE
> - LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
> - LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE
> - TARGET_ATTRIBUTE_TABLE
> 
> All of the attributes in these tables go in the "gnu" namespace.
> This means that they can use the traditional GNU __attribute__((...))
> syntax and the standard [[gnu::...]] syntax.
> 
> Standard attributes are registered dynamically with a null namespace.
> There are no supported attributes in other namespaces (clang, vendor
> namespaces, etc.).
> 
> This patch tries to generalise things by making the namespace
> part of the attribute specification.
> 
> It's usual for multiple attributes to be defined in the same namespace,
> so rather than adding the namespace to each individual definition,
> it seemed better to group attributes in the same namespace together.
> This would also allow us to reuse the same table for clang attributes
> that are written with the GNU syntax, or other similar situations
> where the attribute can be accessed via multiple "spellings".
> 
> The patch therefore adds a scoped_attribute_specs that contains
> a namespace and a list of attributes in that namespace.
> 

Changes to the D front-end in this patch look reasonable to me.

Regards,
Iain.

> 
> 
> gcc/d/
>   * d-tree.h (d_langhook_attribute_table): Replace with...
>   (d_langhook_gnu_attribute_table): ...this.
>   (d_langhook_common_attribute_table): Change type to
>   scoped_attribute_specs.
>   * d-attribs.cc (d_langhook_common_attribute_table): Change type to
>   scoped_attribute_specs, using...
>   (d_langhook_common_attributes): ...this as the underlying array.
>   (d_langhook_attribute_table): Replace with...
>   (d_langhook_gnu_attributes, d_langhook_gnu_attribute_table): ...these
>   new globals.
>   (uda_attribute_p): Update accordingly, and update for new
>   targetm.attribute_table type.
>   * d-lang.cc (d_langhook_attribute_table): New global.
>   (LANG_HOOKS_COMMON_ATTRIBUTE_TABLE): Delete.
> 
> ---
>  gcc/d/d-attribs.cc  |  35 ++---
>  gcc/d/d-lang.cc |   8 +-
>  gcc/d/d-tree.h  |   4 +-
> 
> diff --git a/gcc/d/d-attribs.cc b/gcc/d/d-attribs.cc
> index cc46220ddc2..78215bc88bc 100644
> --- a/gcc/d/d-attribs.cc
> +++ b/gcc/d/d-attribs.cc
> @@ -162,7 +162,7 @@ extern const struct attribute_spec::exclusions 
> attr_cold_hot_exclusions[] =
>  
>  /* Table of machine-independent attributes.
> For internal use (marking of built-ins) only.  */
> -const attribute_spec d_langhook_common_attribute_table[] =
> +static const attribute_spec d_langhook_common_attributes[] =
>  {
>ATTR_SPEC ("noreturn", 0, 0, true, false, false, false,
>handle_noreturn_attribute, attr_noreturn_exclusions),
> @@ -190,11 +190,15 @@ const attribute_spec 
> d_langhook_common_attribute_table[] =
>handle_fnspec_attribute, NULL),
>ATTR_SPEC ("omp declare simd", 0, -1, true,  false, false, false,
>handle_omp_declare_simd_attribute, NULL),
> -  ATTR_SPEC (NULL, 0, 0, false, false, false, false, NULL, NULL),
> +};
> +
> +const scoped_attribute_specs d_langhook_common_attribute_table =
> +{
> +  "gnu", d_langhook_common_attributes
>  };
>  
>  /* Table of D language attributes exposed by `gcc.attribute' UDAs.  */
> -const attribute_spec d_langhook_attribute_table[] =
> +static const attribute_spec d_langhook_gnu_attributes[] =
>  {
>ATTR_SPEC ("noinline", 0, 0, true, false, false, false,
>d_handle_noinline_attribute, attr_noinline_exclusions),
> @@ -238,9 +242,12 @@ const attribute_spec d_langhook_attribute_table[] =
>d_handle_used_attribute, NULL),
>ATTR_SPEC ("visibility", 1, 1, false, false, false, false,
>d_handle_visibility_attribute, NULL),
> -  ATTR_SPEC (NULL, 0, 0, false, false, false, false, NULL, NULL),
>  };
>  
> +const scoped_attribute_specs d_langhook_gnu_attribute_table =
> +{
> +  "gnu", d_langhook_gnu_attributes
> +};
>  
>  /* Insert the type attribute ATTRNAME with value VALUE into TYPE.
> Returns a new variant of the original type declaration.  */
> @@ -283,20 +290,14 @@ uda_attribute_p (const char *name)
>  
>/* Search both our language, and target attribute tables.
>   Common and format attributes are kept internal.  */
> -  for (const attribute_spec *p = d_langhook_attribute_table; p->name; p++)
> -{
> -  if (get_identifier (p->name) == ident)
> - return true;
> -}
> +  for (const attribute_spec  : d_langhook_gnu_attributes)
> +if (get_identifier (p.name) == ident)
> +  return true;
>  
> -  if (targetm.attribute_table)
> -{
> -  for (const attribute_spec *p = targetm.attribute_table; p->name; p++)
> - {
> -   if (get_identifier (p->name) == ident)
> - return true;
> - }
> -}
> 

[committed] d: Merge upstream dmd, druntime 26f049fb26, phobos 330d6a4fd.

2023-08-20 Thread Iain Buclaw via Gcc-patches
Hi,

This patch merges the D front-end and run-time library with upstream dmd
26f049fb26, and standard library with phobos 330d6a4fd.

Synchronizing with the latest bug fixes in the v2.105.0-beta.1 release.

D front-end changes:

- Import dmd v2.105.0-beta.1.
- Added predefined version identifier VisionOS (ignored by GDC).
- Functions can no longer have `enum` storage class.
- The deprecation of the `body` keyword has been reverted, it is
  now an obsolete feature.
- The error for `scope class` has been reverted, it is now an
  obsolete feature.

D runtime changes:

- Import druntime v2.105.0-beta.1.

Phobos changes:

- Import phobos v2.105.0-beta.1.
- AliasSeq has been removed from std.math.
- extern(C) getdelim and getline have been removed from
  std.stdio.

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 26f049fb26.
* dmd/VERSION: Bump version to v2.105.0-beta.1.
* d-codegen.cc (get_frameinfo): Check useGC in condition.
* d-lang.cc (d_handle_option): Set obsolete parameter when compiling
with -Wall.
(d_post_options): Set useGC to false when compiling with
-fno-druntime.  Propagate obsolete flag to compileEnv.
* expr.cc (ExprVisitor::visit (CatExp *)): Check useGC in condition.

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

Regards,
Iain.

---
libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 26f049fb26.
* src/MERGE: Merge upstream phobos 330d6a4fd.
---
 gcc/d/d-codegen.cc|   2 +-
 gcc/d/d-lang.cc   |   3 +
 gcc/d/dmd/MERGE   |   2 +-
 gcc/d/dmd/VERSION |   2 +-
 gcc/d/dmd/clone.d |   2 +-
 gcc/d/dmd/common/string.d |   2 +-
 gcc/d/dmd/cond.d  |   1 +
 gcc/d/dmd/cparse.d|  10 +-
 gcc/d/dmd/dsymbolsem.d| 194 ++
 gcc/d/dmd/errors.d|  34 +--
 gcc/d/dmd/expression.d|  24 ++-
 gcc/d/dmd/expression.h|   6 +-
 gcc/d/dmd/expressionsem.d |   4 +-
 gcc/d/dmd/func.d  |  18 +-
 gcc/d/dmd/globals.d   |  10 +-
 gcc/d/dmd/globals.h   |  11 +-
 gcc/d/dmd/initsem.d   |  25 ++-
 gcc/d/dmd/lexer.d |   1 +
 gcc/d/dmd/nogc.d  |   2 +-
 gcc/d/dmd/parse.d |  86 +---
 gcc/d/dmd/semantic3.d |   3 +-
 gcc/d/dmd/target.d|   4 +-
 gcc/d/dmd/target.h|   2 +-
 gcc/d/dmd/traits.d|  23 ++-
 gcc/d/expr.cc |   2 +-
 gcc/testsuite/gdc.test/compilable/cppmangle.d |   1 -
 .../gdc.test/compilable/deprecate14283.d  |   8 +-
 .../gdc.test/compilable/emptystatement.d  |  19 ++
 .../gdc.test/compilable/imports/imp24022.c|   5 +
 .../gdc.test/compilable/parens_inc.d  |  23 +++
 gcc/testsuite/gdc.test/compilable/test23951.d |  10 +
 gcc/testsuite/gdc.test/compilable/test23966.d |  19 ++
 gcc/testsuite/gdc.test/compilable/test24022.d |  30 +++
 gcc/testsuite/gdc.test/compilable/test7172.d  |   6 +-
 .../gdc.test/fail_compilation/biterrors3.d|   2 +-
 .../gdc.test/fail_compilation/body.d  |  11 +
 .../gdc.test/fail_compilation/ccast.d |  21 +-
 .../gdc.test/fail_compilation/diag4596.d  |   4 +-
 .../gdc.test/fail_compilation/enum_function.d |  13 ++
 .../gdc.test/fail_compilation/fail10285.d |  12 +-
 .../gdc.test/fail_compilation/fail13116.d |   2 +-
 .../gdc.test/fail_compilation/fail15896.d |   1 +
 .../gdc.test/fail_compilation/fail22729.d |   2 +-
 .../gdc.test/fail_compilation/fail22780.d |   2 +-
 .../gdc.test/fail_compilation/fail4559.d  |  22 --
 .../gdc.test/fail_compilation/format.d|  21 +-
 .../fail_compilation/reserved_version.d   |   2 +
 .../gdc.test/fail_compilation/scope_class.d   |   2 +-
 .../gdc.test/fail_compilation/scope_type.d|  16 --
 .../gdc.test/fail_compilation/test23279.d |  14 ++
 .../gdc.test/fail_compilation/typeerrors.d|   2 +-
 gcc/testsuite/gdc.test/runnable/betterc.d |  11 +
 gcc/testsuite/gdc.test/runnable/sctor2.d  |   5 -
 gcc/testsuite/gdc.test/runnable/test24029.c   |  23 +++
 .../gdc.test/runnable/testcontracts.d |  16 --
 libphobos/libdruntime/MERGE   |   2 +-
 libphobos/libdruntime/core/int128.d   |   8 +-
 .../core/internal/array/comparison.d  |  25 ++-
 libphobos/libdruntime/core/lifetime.d |   6 +-
 libphobos/src/MERGE   |   2 +-
 

[committed][GCC 12] d: Fix internal compiler error: in layout_aggregate_type, at d/types.cc:574

2023-08-15 Thread Iain Buclaw via Gcc-patches
Hi,

This patch fixes an ICE that is specific to the D front-end language
version in GDC 12.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32, committed
to releases/gcc-12.

The pr110959.d test case has also been committed to mainline to catch
the unlikely event of a regression.

Regards,
Iain.

---
PR d/110959

gcc/d/ChangeLog:

* dmd/canthrow.d (Dsymbol_canThrow): Use foreachVar.
* dmd/declaration.d (TupleDeclaration::needThis): Likewise.
(TupleDeclaration::foreachVar): New function.
(VarDeclaration::setFieldOffset): Use foreachVar.
* dmd/dinterpret.d (Interpreter::visit (DeclarationExp)): Likewise.
* dmd/dsymbolsem.d (DsymbolSemanticVisitor::visit (VarDeclaration)):
Don't push tuple field members to the scope symbol table.
(determineFields): Handle pushing tuple field members here instead.
* dmd/dtoh.d (ToCppBuffer::visit (VarDeclaration)): Visit all tuple
fields.
(ToCppBuffer::visit (TupleDeclaration)): New function.
* dmd/expression.d (expandAliasThisTuples): Use foreachVar.
* dmd/foreachvar.d (VarWalker::visit (DeclarationExp)): Likewise.
* dmd/ob.d (genKill): Likewise.
(checkObErrors): Likewise.
* dmd/semantic2.d (Semantic2Visitor::visit (TupleDeclaration)): Visit
all tuple fields.

gcc/testsuite/ChangeLog:

* gdc.dg/pr110959.d: New test.
* gdc.test/runnable/test23010.d: New test.
---
 gcc/d/dmd/canthrow.d| 13 +
 gcc/d/dmd/declaration.d | 63 +
 gcc/d/dmd/dinterpret.d  | 17 +++---
 gcc/d/dmd/dsymbolsem.d  | 17 +++---
 gcc/d/dmd/dtoh.d| 11 
 gcc/d/dmd/expression.d  |  8 ++-
 gcc/d/dmd/foreachvar.d  | 14 +
 gcc/d/dmd/ob.d  | 22 +--
 gcc/d/dmd/semantic2.d   |  5 ++
 gcc/testsuite/gdc.dg/pr110959.d | 32 +++
 gcc/testsuite/gdc.test/runnable/test23010.d | 43 ++
 11 files changed, 153 insertions(+), 92 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/pr110959.d
 create mode 100644 gcc/testsuite/gdc.test/runnable/test23010.d

diff --git a/gcc/d/dmd/canthrow.d b/gcc/d/dmd/canthrow.d
index a38cbb1610b..fe6e1e344b9 100644
--- a/gcc/d/dmd/canthrow.d
+++ b/gcc/d/dmd/canthrow.d
@@ -270,18 +270,7 @@ private CT Dsymbol_canThrow(Dsymbol s, FuncDeclaration 
func, bool mustNotThrow)
 }
 else if (auto td = s.isTupleDeclaration())
 {
-for (size_t i = 0; i < td.objects.dim; i++)
-{
-RootObject o = (*td.objects)[i];
-if (o.dyncast() == DYNCAST.expression)
-{
-Expression eo = cast(Expression)o;
-if (auto se = eo.isDsymbolExp())
-{
-result |= Dsymbol_canThrow(se.s, func, mustNotThrow);
-}
-}
-}
+td.foreachVar();
 }
 return result;
 }
diff --git a/gcc/d/dmd/declaration.d b/gcc/d/dmd/declaration.d
index 7b50c050487..6c83c196f72 100644
--- a/gcc/d/dmd/declaration.d
+++ b/gcc/d/dmd/declaration.d
@@ -656,23 +656,46 @@ extern (C++) final class TupleDeclaration : Declaration
 override bool needThis()
 {
 //printf("TupleDeclaration::needThis(%s)\n", toChars());
-for (size_t i = 0; i < objects.dim; i++)
+return isexp ? foreachVar((s) { return s.needThis(); }) != 0 : false;
+}
+
+/***
+ * Calls dg(Dsymbol) for each Dsymbol, which should be a VarDeclaration
+ * inside DsymbolExp (isexp == true).
+ * Params:
+ *dg = delegate to call for each Dsymbol
+ */
+extern (D) void foreachVar(scope void delegate(Dsymbol) dg)
+{
+assert(isexp);
+foreach (o; *objects)
 {
-RootObject o = (*objects)[i];
-if (o.dyncast() == DYNCAST.expression)
-{
-Expression e = cast(Expression)o;
-if (DsymbolExp ve = e.isDsymbolExp())
-{
-Declaration d = ve.s.isDeclaration();
-if (d && d.needThis())
-{
-return true;
-}
-}
-}
+if (auto e = o.isExpression())
+if (auto se = e.isDsymbolExp())
+dg(se.s);
 }
-return false;
+}
+
+/***
+ * Calls dg(Dsymbol) for each Dsymbol, which should be a VarDeclaration
+ * inside DsymbolExp (isexp == true).
+ * If dg returns !=0, stops and returns that value else returns 0.
+ * Params:
+ *dg = delegate to call for each Dsymbol
+ * Returns:
+ *last value returned by dg()
+ */
+extern (D) int 

Re: [PATCH] Use substituted GDCFLAGS

2023-07-27 Thread Iain Buclaw via Gcc-patches
Excerpts from Andreas Schwab via Gcc-patches's message of Juli 24, 2023 11:15 
am:
> Ping?
> 

OK from me.

Thanks,
Iain.


[committed] d: Fix PR 108842: Cannot use enum array with -fno-druntime

2023-07-07 Thread Iain Buclaw via Gcc-patches
Hi,

This patch restricts generating of CONST_DECLs for D manifest constants
to just scalars without pointers.  It shouldn't happen that a reference
to a manifest constant has not been expanded within a function body
during codegen, but it has been found to occur in older versions of the
D front-end (PR98277), so if the decl of a non-scalar constant is
requested, just return its initializer as an expression.

Bootstrapped and regresson tested on x86_64-linux-gnu/-m32, committed to
mainline, and backported to the gcc-11, gcc-12, and gcc-13 release
branches.

Regards,
Iain.

---
PR d/108842

gcc/d/ChangeLog:

* decl.cc (DeclVisitor::visit (VarDeclaration *)): Only emit scalar
manifest constants.
(get_symbol_decl): Don't generate CONST_DECL for non-scalar manifest
constants.
* imports.cc (ImportVisitor::visit (VarDeclaration *)): New method.

gcc/testsuite/ChangeLog:

* gdc.dg/pr98277.d: Add more tests.
* gdc.dg/pr108842.d: New test.
---
 gcc/d/decl.cc   | 36 +++--
 gcc/d/imports.cc|  9 +
 gcc/testsuite/gdc.dg/pr108842.d |  4 
 gcc/testsuite/gdc.dg/pr98277.d  | 11 ++
 4 files changed, 45 insertions(+), 15 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/pr108842.d

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 3f980851259..0375ede082b 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -782,7 +782,7 @@ public:
   {
/* Do not store variables we cannot take the address of,
   but keep the values for purposes of debugging.  */
-   if (!d->type->isscalar ())
+   if (d->type->isscalar () && !d->type->hasPointers ())
  {
tree decl = get_symbol_decl (d);
d_pushdecl (decl);
@@ -1212,6 +1212,20 @@ get_symbol_decl (Declaration *decl)
   return decl->csym;
 }
 
+  if (VarDeclaration *vd = decl->isVarDeclaration ())
+{
+  /* CONST_DECL was initially intended for enumerals and may be used for
+scalars in general, but not for aggregates.  Here a non-constant
+value is generated anyway so as its value can be used.  */
+  if (!vd->canTakeAddressOf () && !vd->type->isscalar ())
+   {
+ gcc_assert (vd->_init && !vd->_init->isVoidInitializer ());
+ Expression *ie = initializerToExpression (vd->_init);
+ decl->csym = build_expr (ie, false);
+ return decl->csym;
+   }
+}
+
   /* Build the tree for the symbol.  */
   FuncDeclaration *fd = decl->isFuncDeclaration ();
   if (fd)
@@ -1259,23 +1273,15 @@ get_symbol_decl (Declaration *decl)
   if (vd->storage_class & STCextern)
DECL_EXTERNAL (decl->csym) = 1;
 
-  /* CONST_DECL was initially intended for enumerals and may be used for
-scalars in general, but not for aggregates.  Here a non-constant
-value is generated anyway so as the CONST_DECL only serves as a
-placeholder for the value, however the DECL itself should never be
-referenced in any generated code, or passed to the back-end.  */
-  if (vd->storage_class & STCmanifest)
+  if (!vd->canTakeAddressOf ())
{
  /* Cannot make an expression out of a void initializer.  */
- if (vd->_init && !vd->_init->isVoidInitializer ())
-   {
- Expression *ie = initializerToExpression (vd->_init);
+ gcc_assert (vd->_init && !vd->_init->isVoidInitializer ());
+ /* Non-scalar manifest constants have already been dealt with.  */
+ gcc_assert (vd->type->isscalar ());
 
- if (!vd->type->isscalar ())
-   DECL_INITIAL (decl->csym) = build_expr (ie, false);
- else
-   DECL_INITIAL (decl->csym) = build_expr (ie, true);
-   }
+ Expression *ie = initializerToExpression (vd->_init);
+ DECL_INITIAL (decl->csym) = build_expr (ie, true);
}
 
   /* [type-qualifiers/const-and-immutable]
diff --git a/gcc/d/imports.cc b/gcc/d/imports.cc
index 2efef4ed54f..3172b799cb0 100644
--- a/gcc/d/imports.cc
+++ b/gcc/d/imports.cc
@@ -127,6 +127,15 @@ public:
 this->result_ = this->make_import (TYPE_STUB_DECL (type));
   }
 
+  void visit (VarDeclaration *d) final override
+  {
+/* Not all kinds of manifest constants create a CONST_DECL.  */
+if (!d->canTakeAddressOf () && !d->type->isscalar ())
+  return;
+
+visit ((Declaration *) d);
+  }
+
   /* For now, ignore importing other kinds of dsymbols.  */
   void visit (ScopeDsymbol *) final override
   {
diff --git a/gcc/testsuite/gdc.dg/pr108842.d b/gcc/testsuite/gdc.dg/pr108842.d
new file mode 100644
index 000..5aae9e5000d
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr108842.d
@@ -0,0 +1,4 @@
+// { dg-do compile }
+// { dg-options "-fno-rtti" }
+module object;
+enum int[] x = [0, 1, 2];
diff --git a/gcc/testsuite/gdc.dg/pr98277.d b/gcc/testsuite/gdc.dg/pr98277.d
index 0dff142a6ef..c88c735dec8 100644
--- 

[committed] d: Fix testcase failure of gdc.dg/Wbuiltin_declaration_mismatch2.d.

2023-07-02 Thread Iain Buclaw via Gcc-patches
Hi,

Seen at least on aarch64-*-darwin, the parameters used to instantiate
the shufflevector intrinsic meant the return type was __vector(int[1]),
which resulted in the error:

vector type '__vector(int[1])' is not supported on this platform.

All instantiations have now been fixed so the expected warning/error is
now given by the compiler.

Regression tested on x86_64-linux-gnu/-m32, committed to mainline, and
backported to releases/gcc-13.

Regards,
Iain.

---
gcc/testsuite/ChangeLog:

* gdc.dg/Wbuiltin_declaration_mismatch2.d: Fix failed tests.
---
 .../gdc.dg/Wbuiltin_declaration_mismatch2.d   | 44 +--
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/gcc/testsuite/gdc.dg/Wbuiltin_declaration_mismatch2.d 
b/gcc/testsuite/gdc.dg/Wbuiltin_declaration_mismatch2.d
index 7b83fffae58..0d12bcb8b07 100644
--- a/gcc/testsuite/gdc.dg/Wbuiltin_declaration_mismatch2.d
+++ b/gcc/testsuite/gdc.dg/Wbuiltin_declaration_mismatch2.d
@@ -77,32 +77,32 @@ void test_shuffle()
 
 void test_shufflevector()
 {
-shufflevector!(int, int4, int)(0, 0, 0); // { dg-warning "mismatch in 
argument 1" }
-shufflevector!(double, int4, int)(0, 0, 0); // { dg-warning "mismatch in 
argument 1" }
-shufflevector!(fake4, int4, int)(f, 0, 0); // { dg-warning "mismatch in 
argument 1" }
-
-shufflevector!(int4, int, int)(0, 0, 0); // { dg-warning "mismatch in 
argument 2" }
-shufflevector!(int4, double, int)(0, 0, 0); // { dg-warning "mismatch in 
argument 2" }
-shufflevector!(int4, int4, int)(0, 0, 0);
-shufflevector!(int4, short8, int)(0, 0, 0); // { dg-error "mismatch in 
argument 2" }
-shufflevector!(int4, float4, int)(0, 0, 0); // { dg-error "mismatch in 
argument 2" }
-shufflevector!(int4, byte16, int)(0, 0, 0); // { dg-error "mismatch in 
argument 2" }
-shufflevector!(int4, fake4, int)(0, f, 0); // { dg-warning "mismatch in 
argument 2" }
-
-shufflevector!(int4, int4, double)(0, 0, 0); // { dg-warning "mismatch in 
argument 3" }
-shufflevector!(int4, int4, int4)(0, 0, 0); // { dg-warning "mismatch in 
argument 3" }
-shufflevector!(int4, int4, short8)(0, 0, 0); // { dg-warning "mismatch in 
argument 3" }
-shufflevector!(int4, int4, float4)(0, 0, 0); // { dg-warning "mismatch in 
argument 3" }
-shufflevector!(int4, int4, byte16)(0, 0, 0); // { dg-warning "mismatch in 
argument 3" }
-
-shufflevector!(int4, int4, int, double)(0, 0, 0, 0); // { dg-warning 
"mismatch in argument 4" }
+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, 0, 0, 0, 0); // { 
dg-warning "mismatch in argument 2" }
+shufflevector!(int4, double, int, int, int, int)(0, 0, 0, 0, 0, 0); // { 
dg-warning "mismatch in argument 2" }
+shufflevector!(int4, int4, int, int, int, int)(0, 0, 0, 0, 0, 0);
+shufflevector!(int4, short8, int, int, int, int)(0, 0, 0, 0, 0, 0); // { 
dg-error "mismatch in argument 2" }
+shufflevector!(int4, float4, int, int, int, int)(0, 0, 0, 0, 0, 0); // { 
dg-error "mismatch in argument 2" }
+shufflevector!(int4, byte16, int, int, int, int)(0, 0, 0, 0, 0, 0); // { 
dg-error "mismatch in argument 2" }
+shufflevector!(int4, fake4, int, int, int, int)(0, f, 0, 0, 0, 0); // { 
dg-warning "mismatch in argument 2" }
+
+shufflevector!(int4, int4, double, int, int, int)(0, 0, 0, 0, 0, 0); // { 
dg-warning "mismatch in argument 3" }
+shufflevector!(int4, int4, int4, int, int, int)(0, 0, 0, 0, 0, 0); // { 
dg-warning "mismatch in argument 3" }
+shufflevector!(int4, int4, short8, int, int, int)(0, 0, 0, 0, 0, 0); // { 
dg-warning "mismatch in argument 3" }
+shufflevector!(int4, int4, float4, int, int, int)(0, 0, 0, 0, 0, 0); // { 
dg-warning "mismatch in argument 3" }
+shufflevector!(int4, int4, byte16, int, int, int)(0, 0, 0, 0, 0, 0); // { 
dg-warning "mismatch in argument 3" }
+
+shufflevector!(int4, int4, int, double, int, int)(0, 0, 0, 0, 0, 0); // { 
dg-warning "mismatch in argument 4" }
 shufflevector!(int4, int4, int, int, double, int)(0, 0, 0, 0, 0, 0); // { 
dg-warning "mismatch in argument 5" }
 shufflevector!(int4, int4, int, int, int, double)(0, 0, 0, 0, 0, 0); // { 
dg-warning "mismatch in argument 6" }
 
 int i;
-shufflevector!(int4, int4, int)(0, 0, i); // { dg-error "argument .i. 
cannot be read at compile time" }
-shufflevector!(int4, int4, int)(0, 0, -1u); // { dg-error "element index 
.-1. is out of bounds" }
-shufflevector!(int4, int4, int)(0, 0, 8); // { dg-error "element index .8. 
is out of bounds" }
+shufflevector!(int4, int4, int, int, int, int)(0, 0, i, 0, 0, 0); // { 
dg-error "argument .i. cannot be read at 

[committed] d: Add testcase from PR108962

2023-07-02 Thread Iain Buclaw via Gcc-patches
Hi,

This adds testcase from PR108962 into the gdc testsuite.

The issue was fixed in r14-2232 and backported to gcc-13.

Regtested, committed to mainline and gcc-13 branches.

Regards,
Iain.

---
PR d/108962

gcc/testsuite/ChangeLog:

* gdc.dg/pr108962.d: New test.
---
 gcc/testsuite/gdc.dg/pr108962.d | 13 +
 1 file changed, 13 insertions(+)
 create mode 100644 gcc/testsuite/gdc.dg/pr108962.d

diff --git a/gcc/testsuite/gdc.dg/pr108962.d b/gcc/testsuite/gdc.dg/pr108962.d
new file mode 100644
index 000..0fefa126b54
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr108962.d
@@ -0,0 +1,13 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108962
+// { dg-do compile }
+// { dg-options "-fno-exceptions -fdump-tree-original" }
+extern(C) void main()
+{
+final switch (0)
+{
+case 1:
+return;
+}
+}
+// { dg-final { scan-tree-dump-times "_d_assert_msg" 1 "original" } }
+// { dg-final { scan-tree-dump-not "_d_throw" "original" } }
-- 
2.39.2



Re: [PATCH] libphobos: Handle Darwin Arm and AArch64 in fibre context asm.

2023-07-02 Thread Iain Buclaw via Gcc-patches
Excerpts from Iain Sandoe's message of Juli 2, 2023 12:22 pm:
> Tested on AArch64 (Arm64) Darwin on 11.x, 13.x and master,
> OK for trunk?
> and backports?
> thanks
> Iain
> 
> --- 8< ---
> 
> This code currently fails to build because it contains ELF-
> specific directives.  This patch excludes those directives when
> the platform is Darwin.
> 
> We do not expect switching fibres between threads to be safe here
> either owing to the possible caching of TLS pointers.
> 
> Signed-off-by: Iain Sandoe 
> 

OK.

Thanks!
Iain.


[committed] d: Fix core.volatile.volatileLoad discarded if result is unused

2023-07-01 Thread Iain Buclaw via Gcc-patches
Hi,

The first pass of code generation in the D front-end splits up all
compound expressions and discards expressions that have no side effects.
This included calls to the `volatileLoad' intrinsic if its result was
not used, causing such calls to be eliminated from the program.

We already set TREE_THIS_VOLATILE on the expression, however the
tree documentation says if this bit is set in an expression, so is
TREE_SIDE_EFFECTS.  So set TREE_SIDE_EFFECTS on the expression too.
This prevents any early discarding from occuring.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32, committed
to mainline, and backported to releases/gcc-13, gcc-12, and gcc-11.

Regards,
Iain.

---
PR d/110516

gcc/d/ChangeLog:

* intrinsics.cc (expand_volatile_load): Set TREE_SIDE_EFFECTS on the
expanded expression.
(expand_volatile_store): Likewise.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/pr110516a.d: New test.
* gdc.dg/torture/pr110516b.d: New test.
---
 gcc/d/intrinsics.cc  |  2 ++
 gcc/testsuite/gdc.dg/torture/pr110516a.d | 12 
 gcc/testsuite/gdc.dg/torture/pr110516b.d | 12 
 3 files changed, 26 insertions(+)
 create mode 100644 gcc/testsuite/gdc.dg/torture/pr110516a.d
 create mode 100644 gcc/testsuite/gdc.dg/torture/pr110516b.d

diff --git a/gcc/d/intrinsics.cc b/gcc/d/intrinsics.cc
index 0121d81eb14..aaf04e50baa 100644
--- a/gcc/d/intrinsics.cc
+++ b/gcc/d/intrinsics.cc
@@ -1007,6 +1007,7 @@ expand_volatile_load (tree callexp)
   tree type = build_qualified_type (TREE_TYPE (ptrtype), TYPE_QUAL_VOLATILE);
   tree result = indirect_ref (type, ptr);
   TREE_THIS_VOLATILE (result) = 1;
+  TREE_SIDE_EFFECTS (result) = 1;
 
   return result;
 }
@@ -1034,6 +1035,7 @@ expand_volatile_store (tree callexp)
   tree type = build_qualified_type (TREE_TYPE (ptrtype), TYPE_QUAL_VOLATILE);
   tree result = indirect_ref (type, ptr);
   TREE_THIS_VOLATILE (result) = 1;
+  TREE_SIDE_EFFECTS (result) = 1;
 
   /* (*(volatile T *) ptr) = value;  */
   tree value = CALL_EXPR_ARG (callexp, 1);
diff --git a/gcc/testsuite/gdc.dg/torture/pr110516a.d 
b/gcc/testsuite/gdc.dg/torture/pr110516a.d
new file mode 100644
index 000..276455ae408
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/pr110516a.d
@@ -0,0 +1,12 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110516
+// { dg-do compile }
+// { dg-options "-fno-moduleinfo -fdump-tree-optimized" }
+void fn110516(ubyte* ptr)
+{
+import core.volatile : volatileLoad;
+volatileLoad(ptr);
+volatileLoad(ptr);
+volatileLoad(ptr);
+volatileLoad(ptr);
+}
+// { dg-final { scan-tree-dump-times " ={v} " 4 "optimized" } }
diff --git a/gcc/testsuite/gdc.dg/torture/pr110516b.d 
b/gcc/testsuite/gdc.dg/torture/pr110516b.d
new file mode 100644
index 000..b7a67e716a5
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/pr110516b.d
@@ -0,0 +1,12 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110516
+// { dg-do compile }
+// { dg-options "-fno-moduleinfo -fdump-tree-optimized" }
+void fn110516(ubyte* ptr)
+{
+import core.volatile : volatileStore;
+volatileStore(ptr, 0);
+volatileStore(ptr, 0);
+volatileStore(ptr, 0);
+volatileStore(ptr, 0);
+}
+// { dg-final { scan-tree-dump-times " ={v} " 4 "optimized" } }
-- 
2.39.2



[committed] d: Fix accesses of immutable arrays using constant index still bounds checked

2023-07-01 Thread Iain Buclaw via Gcc-patches
Hi,

This patch sets TREE_READONLY on all non-static const and immutable
variables in D, as well as all static immutable variables that aren't
initialized by a module constructor.  This allows more aggressive
constant folding of D code which makes use of `immutable' or `const'.

Bootstrapped and regression tested on x86_64-linux-gnu, committed to
mainline, and backported to releases/gcc-13 and releases/gcc-12.

Regards,
Iain.

---
PR d/110514

gcc/d/ChangeLog:

* decl.cc (get_symbol_decl): Set TREE_READONLY on certain kinds of
const and immutable variables.
* expr.cc (ExprVisitor::visit (ArrayLiteralExp *)): Set TREE_READONLY
on immutable dynamic array literals.

gcc/testsuite/ChangeLog:

* gdc.dg/pr110514a.d: New test.
* gdc.dg/pr110514b.d: New test.
* gdc.dg/pr110514c.d: New test.
* gdc.dg/pr110514d.d: New test.
---
 gcc/d/decl.cc| 14 ++
 gcc/d/expr.cc|  4 
 gcc/testsuite/gdc.dg/pr110514a.d |  9 +
 gcc/testsuite/gdc.dg/pr110514b.d |  8 
 gcc/testsuite/gdc.dg/pr110514c.d |  8 
 gcc/testsuite/gdc.dg/pr110514d.d |  8 
 6 files changed, 51 insertions(+)
 create mode 100644 gcc/testsuite/gdc.dg/pr110514a.d
 create mode 100644 gcc/testsuite/gdc.dg/pr110514b.d
 create mode 100644 gcc/testsuite/gdc.dg/pr110514c.d
 create mode 100644 gcc/testsuite/gdc.dg/pr110514d.d

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 78c4ab554dc..3f980851259 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -1277,6 +1277,20 @@ get_symbol_decl (Declaration *decl)
DECL_INITIAL (decl->csym) = build_expr (ie, true);
}
}
+
+  /* [type-qualifiers/const-and-immutable]
+
+`immutable` applies to data that cannot change. Immutable data values,
+once constructed, remain the same for the duration of the program's
+execution.  */
+  if (vd->isImmutable () && !vd->setInCtorOnly ())
+   TREE_READONLY (decl->csym) = 1;
+
+  /* `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 ())
+   TREE_READONLY (decl->csym) = 1;
 }
 
   /* Set the declaration mangled identifier if static.  */
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index c6245ff5fc1..b7cec1327fd 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -2701,6 +2701,10 @@ public:
if (tb->ty == TY::Tarray)
  ctor = d_array_value (type, size_int (e->elements->length), ctor);
 
+   /* Immutable data can be placed in rodata.  */
+   if (tb->isImmutable ())
+ TREE_READONLY (decl) = 1;
+
d_pushdecl (decl);
rest_of_decl_compilation (decl, 1, 0);
  }
diff --git a/gcc/testsuite/gdc.dg/pr110514a.d b/gcc/testsuite/gdc.dg/pr110514a.d
new file mode 100644
index 000..46e370527d3
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr110514a.d
@@ -0,0 +1,9 @@
+// { dg-do "compile" }
+// { dg-options "-O -fdump-tree-optimized" }
+immutable uint[] imm_arr = [1,2,3];
+int test_imm(immutable uint[] ptr)
+{
+return imm_arr[2] == 3 ? 123 : 456;
+}
+// { dg-final { scan-assembler-not "_d_arraybounds_indexp" } }
+// { dg-final { scan-tree-dump "return 123;" optimized } }
diff --git a/gcc/testsuite/gdc.dg/pr110514b.d b/gcc/testsuite/gdc.dg/pr110514b.d
new file mode 100644
index 000..86aeb485c34
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr110514b.d
@@ -0,0 +1,8 @@
+// { dg-do "compile" }
+// { dg-options "-O" }
+immutable uint[] imm_ctor_arr;
+int test_imm_ctor(immutable uint[] ptr)
+{
+return imm_ctor_arr[2] == 3;
+}
+// { dg-final { scan-assembler "_d_arraybounds_indexp" } }
diff --git a/gcc/testsuite/gdc.dg/pr110514c.d b/gcc/testsuite/gdc.dg/pr110514c.d
new file mode 100644
index 000..94779e123a4
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr110514c.d
@@ -0,0 +1,8 @@
+// { dg-do "compile" }
+// { dg-options "-O" }
+const uint[] cst_arr = [1,2,3];
+int test_cst(const uint[] ptr)
+{
+return cst_arr[2] == 3;
+}
+// { dg-final { scan-assembler "_d_arraybounds_indexp" } }
diff --git a/gcc/testsuite/gdc.dg/pr110514d.d b/gcc/testsuite/gdc.dg/pr110514d.d
new file mode 100644
index 000..56e9a3139ea
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr110514d.d
@@ -0,0 +1,8 @@
+// { dg-do "compile" }
+// { dg-options "-O" }
+const uint[] cst_ctor_arr;
+int test_cst_ctor(const uint[] ptr)
+{
+return cst_ctor_arr[2] == 3;
+}
+// { dg-final { scan-assembler "_d_arraybounds_indexp" } }
-- 
2.39.2



[committed] d: Don't generate code that throws exceptions when compiling with `-fno-exceptions'

2023-07-01 Thread Iain Buclaw via Gcc-patches
Hi,

The version flags for RTMI, RTTI, and exceptions was unconditionally
predefined.  These are now only predefined if the feature flag is
enabled.  It was noticed that there was no `-fexceptions' definition
inside d/lang.opt, so the detection of the exceptions option flag was
only partially working.  Once that was fixed, a few places in the
front-end implementation were found to fall fowl of `nothrow' rules,
these have been fixed upstream and backported here as well.

Bootstrapped and regression tested on x86_64-linux-gnu{-m64,-m32},
committed to mainline, and backported to releases/gcc-13.

Regards,
Iain.

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

PR d/110471

gcc/d/ChangeLog:

* d-builtins.cc (d_init_versions): Predefine D_ModuleInfo,
D_Exceptions, and D_TypeInfo only if feature is enabled.
* lang.opt: Add -fexceptions.

gcc/testsuite/ChangeLog:

* gdc.dg/pr110471a.d: New test.
* gdc.dg/pr110471b.d: New test.
* gdc.dg/pr110471c.d: New test.

(cherry picked from commit da108c75ad386b3f1f47abb2265296e4b61d578a)
---
 gcc/d/d-builtins.cc  | 9 ++---
 gcc/d/dmd/root/array.d   | 2 +-
 gcc/d/dmd/semantic2.d| 3 +--
 gcc/d/dmd/semantic3.d| 2 +-
 gcc/d/lang.opt   | 4 
 gcc/testsuite/gdc.dg/pr110471a.d | 5 +
 gcc/testsuite/gdc.dg/pr110471b.d | 5 +
 gcc/testsuite/gdc.dg/pr110471c.d | 5 +
 8 files changed, 28 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/pr110471a.d
 create mode 100644 gcc/testsuite/gdc.dg/pr110471b.d
 create mode 100644 gcc/testsuite/gdc.dg/pr110471c.d

diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index f40888019ce..60f76fc694c 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -500,9 +500,12 @@ d_init_versions (void)
 VersionCondition::addPredefinedGlobalIdent ("D_BetterC");
   else
 {
-  VersionCondition::addPredefinedGlobalIdent ("D_ModuleInfo");
-  VersionCondition::addPredefinedGlobalIdent ("D_Exceptions");
-  VersionCondition::addPredefinedGlobalIdent ("D_TypeInfo");
+  if (global.params.useModuleInfo)
+   VersionCondition::addPredefinedGlobalIdent ("D_ModuleInfo");
+  if (global.params.useExceptions)
+   VersionCondition::addPredefinedGlobalIdent ("D_Exceptions");
+  if (global.params.useTypeInfo)
+   VersionCondition::addPredefinedGlobalIdent ("D_TypeInfo");
 }
 
   if (optimize)
diff --git a/gcc/d/dmd/root/array.d b/gcc/d/dmd/root/array.d
index 541a12d9e1d..d1c61be7344 100644
--- a/gcc/d/dmd/root/array.d
+++ b/gcc/d/dmd/root/array.d
@@ -574,7 +574,7 @@ unittest
 private template arraySortWrapper(T, alias fn)
 {
 pragma(mangle, "arraySortWrapper_" ~ T.mangleof ~ "_" ~ fn.mangleof)
-extern(C) int arraySortWrapper(scope const void* e1, scope const void* e2) 
nothrow
+extern(C) int arraySortWrapper(scope const void* e1, scope const void* e2)
 {
 return fn(cast(const(T*))e1, cast(const(T*))e2);
 }
diff --git a/gcc/d/dmd/semantic2.d b/gcc/d/dmd/semantic2.d
index 440e4cbc8e7..ee268d95251 100644
--- a/gcc/d/dmd/semantic2.d
+++ b/gcc/d/dmd/semantic2.d
@@ -807,9 +807,8 @@ private void doGNUABITagSemantic(ref Expression e, ref 
Expression* lastTag)
 // but it's a concession to practicality.
 // Casts are unfortunately necessary as `implicitConvTo` is not
 // `const` (and nor is `StringExp`, by extension).
-static int predicate(const scope Expression* e1, const scope Expression* 
e2) nothrow
+static int predicate(const scope Expression* e1, const scope Expression* 
e2)
 {
-scope(failure) assert(0, "An exception was thrown");
 return 
(cast(Expression*)e1).toStringExp().compare((cast(Expression*)e2).toStringExp());
 }
 ale.elements.sort!predicate;
diff --git a/gcc/d/dmd/semantic3.d b/gcc/d/dmd/semantic3.d
index 33a43187fa8..a912e768f0c 100644
--- a/gcc/d/dmd/semantic3.d
+++ b/gcc/d/dmd/semantic3.d
@@ -1420,7 +1420,7 @@ private extern(C++) final class Semantic3Visitor : Visitor
  * https://issues.dlang.org/show_bug.cgi?id=14246
  */
 AggregateDeclaration ad = ctor.isMemberDecl();
-if (!ctor.fbody || !ad || !ad.fieldDtor || !global.params.dtorFields 
|| global.params.betterC || ctor.type.toTypeFunction.isnothrow)
+if (!ctor.fbody || !ad || !ad.fieldDtor || !global.params.dtorFields 
|| !global.params.useExceptions || ctor.type.toTypeFunction.isnothrow)
 return visit(cast(FuncDeclaration)ctor);
 
 /* Generate:
diff --git a/gcc/d/lang.opt b/gcc/d/lang.opt
index 26ca92c4c17..98a95c1dc38 100644
--- a/gcc/d/lang.opt
+++ b/gcc/d/lang.opt
@@ -291,6 +291,10 @@ fdump-d-original
 D
 Display the frontend AST after parsing and semantic passes.
 
+fexceptions
+D
+; Documented in common.opt
+
 fextern-std=
 D Joined RejectNegative Enum(extern_stdcpp) Var(flag_extern_stdcpp)
 -fextern-std=   

[GCC 11][committed] d: Fix ICE in setValue, at d/dmd/dinterpret.c:7013

2023-07-01 Thread Iain Buclaw via Gcc-patches
Hi,

This patch backports ICE fix from upstream which is already part of
GCC-12 and later.  When casting null to integer or real, instead of
painting the type on the NullExp, we emplace an IntegerExp/RealExp with
the value zero.  Same as when casting from NullExp to bool.

Bootstrapped and regression tested on x86_64-linux-gnu, committed to
releases/gcc-11, and backported to releases/gcc-10.

Regards,
Iain.

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

PR d/110511

gcc/d/ChangeLog:

* dmd/dinterpret.c (Interpreter::visit (CastExp *)): Handle casting
null to int or float.

gcc/testsuite/ChangeLog:

* gdc.test/compilable/test21794.d: New test.
---
 gcc/d/dmd/dinterpret.c| 12 -
 gcc/testsuite/gdc.test/compilable/test21794.d | 52 +++
 2 files changed, 63 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gdc.test/compilable/test21794.d

diff --git a/gcc/d/dmd/dinterpret.c b/gcc/d/dmd/dinterpret.c
index ab9d88c660c..d4cfb0caacb 100644
--- a/gcc/d/dmd/dinterpret.c
+++ b/gcc/d/dmd/dinterpret.c
@@ -5792,12 +5792,22 @@ public:
 }
 if (e->to->ty == Tsarray)
 e1 = resolveSlice(e1);
-if (e->to->toBasetype()->ty == Tbool && e1->type->ty == Tpointer)
+Type *tobt = e->to->toBasetype();
+if (tobt->ty == Tbool && e1->type->ty == Tpointer)
 {
 new(pue) IntegerExp(e->loc, e1->op != TOKnull, e->to);
 result = pue->exp();
 return;
 }
+else if (tobt->isTypeBasic() && e1->op == TOKnull)
+{
+if (tobt->isintegral())
+new(pue) IntegerExp(e->loc, 0, e->to);
+else if (tobt->isreal())
+new(pue) RealExp(e->loc, CTFloat::zero, e->to);
+result = pue->exp();
+return;
+}
 result = ctfeCast(pue, e->loc, e->type, e->to, e1);
 }
 
diff --git a/gcc/testsuite/gdc.test/compilable/test21794.d 
b/gcc/testsuite/gdc.test/compilable/test21794.d
new file mode 100644
index 000..68e504bce56
--- /dev/null
+++ b/gcc/testsuite/gdc.test/compilable/test21794.d
@@ -0,0 +1,52 @@
+// https://issues.dlang.org/show_bug.cgi?id=21794
+/*
+TEST_OUTPUT:
+---
+0
+0u
+0L
+0LU
+0.0F
+0.0
+0.0L
+---
+*/
+
+bool fun(void* p) {
+const x = cast(ulong)p;
+return 1;
+}
+
+static assert(fun(null));
+
+T fun2(T)(void* p) {
+const x = cast(T)p;
+return x;
+}
+
+// These were an error before, they were returning a NullExp instead of 
IntegerExp/RealExp
+
+static assert(fun2!int(null)== 0);
+static assert(fun2!uint(null)   == 0);
+static assert(fun2!long(null)   == 0);
+static assert(fun2!ulong(null)  == 0);
+static assert(fun2!float(null)  == 0);
+static assert(fun2!double(null) == 0);
+static assert(fun2!real(null)   == 0);
+
+// These were printing 'null' instead of the corresponding number
+
+const i = cast(int)null;
+const ui = cast(uint)null;
+const l = cast(long)null;
+const ul = cast(ulong)null;
+const f = cast(float)null;
+const d = cast(double)null;
+const r = cast(real)null;
+pragma(msg, i);
+pragma(msg, ui);
+pragma(msg, l);
+pragma(msg, ul);
+pragma(msg, f);
+pragma(msg, d);
+pragma(msg, r);
-- 
2.39.2



[committed] d: Fix wrong code-gen when returning structs by value.

2023-06-28 Thread Iain Buclaw via Gcc-patches
Hi,

Since r13-1104, structs in the D have had compute_record_mode called too
early on them, causing them to return differently depending on the order
that types are generated in, and whether there are forward references.

This patch moves the call to compute_record_mode into its own function,
and calls it after all fields have been given a size.

Bootstrapped on i686-apple-darwin17 - previously it failed at stage2 -
as well as bootstrapped and regression tested on x86_64-linux-gnu/-m32.
Committed to mainline, and backported to releases/gcc-13.

Regards,
Iain.

---
PR d/106977
PR target/110406

gcc/d/ChangeLog:

* types.cc (finish_aggregate_mode): New function.
(finish_incomplete_fields): Call finish_aggregate_mode.
(finish_aggregate_type): Replace call to compute_record_mode with
finish_aggregate_mode.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/pr110406.d: New test.
---
 gcc/d/types.cc  | 39 ++---
 gcc/testsuite/gdc.dg/torture/pr110406.d | 25 
 2 files changed, 60 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/torture/pr110406.d

diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index bdf07f83d4b..ef2d80e5bd4 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -573,6 +573,35 @@ layout_aggregate_type (AggregateDeclaration *decl, tree 
type,
 }
 }
 
+/* Given a record type TYPE compute the finalized record mode if all fields 
have
+   had their types resolved and sizes determined.  */
+
+void
+finish_aggregate_mode (tree type)
+{
+  for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
+{
+  /* Fields of type `typeof(*null)' have no size, so let them force the
+record type mode to be computed as BLKmode.  */
+  if (TYPE_MAIN_VARIANT (TREE_TYPE (field)) == noreturn_type_node)
+   break;
+
+  if (DECL_SIZE (field) == NULL_TREE)
+   return;
+}
+
+  compute_record_mode (type);
+
+  /* Propagate computed mode to all variants of this aggregate type.  */
+  for (tree t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
+{
+  if (t == type)
+   continue;
+
+  SET_TYPE_MODE (t, TYPE_MODE (type));
+}
+}
+
 /* If the aggregate type TYPE completes the type of any previous field
declarations, lay them out now.  */
 
@@ -596,6 +625,9 @@ finish_incomplete_fields (tree type)
}
 
   relayout_decl (field);
+
+  /* Relayout of field may change the mode of its RECORD_TYPE.  */
+  finish_aggregate_mode (DECL_FIELD_CONTEXT (field));
 }
 
   /* No more forward references to process.  */
@@ -615,9 +647,6 @@ finish_aggregate_type (unsigned structsize, unsigned 
alignsize, tree type)
   SET_TYPE_ALIGN (type, alignsize * BITS_PER_UNIT);
   TYPE_PACKED (type) = (alignsize == 1);
 
-  /* Set the back-end type mode.  */
-  compute_record_mode (type);
-
   /* Layout all fields now the type is complete.  */
   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
 {
@@ -662,6 +691,9 @@ finish_aggregate_type (unsigned structsize, unsigned 
alignsize, tree type)
}
 }
 
+  /* Set the back-end type mode after all fields have had their size set.  */
+  finish_aggregate_mode (type);
+
   /* Fix up all forward-referenced variants of this aggregate type.  */
   for (tree t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
 {
@@ -673,7 +705,6 @@ finish_aggregate_type (unsigned structsize, unsigned 
alignsize, tree type)
   TYPE_SIZE (t) = TYPE_SIZE (type);
   TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (type);
   TYPE_PACKED (type) = TYPE_PACKED (type);
-  SET_TYPE_MODE (t, TYPE_MODE (type));
   SET_TYPE_ALIGN (t, TYPE_ALIGN (type));
   TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (type);
 }
diff --git a/gcc/testsuite/gdc.dg/torture/pr110406.d 
b/gcc/testsuite/gdc.dg/torture/pr110406.d
new file mode 100644
index 000..c380e4bdec8
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/pr110406.d
@@ -0,0 +1,25 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110406
+// { dg-do compile { target i?86-*-* x86_64-*-* } }
+// { dg-options "-fdump-tree-optimized" }
+struct cpuid_abcd_t
+{
+uint eax;
+uint ebx;
+uint ecx;
+uint edx;
+};
+
+cpuid_abcd_t cpuid_insn(const uint in_eax)
+{
+cpuid_abcd_t ret = void;
+asm { "cpuid"
+: "=a" (ret.eax),
+  "=b" (ret.ebx),
+  "=c" (ret.ecx),
+  "=d" (ret.edx)
+: "a"  (in_eax)
+:;
+}
+return ret;
+}
+// { dg-final { scan-tree-dump-not "MEM " "optimized" } }
-- 
2.39.2



[committed] d: Fix d_signed_or_unsigned_type is invoked for vector types (PR110193)

2023-06-28 Thread Iain Buclaw via Gcc-patches
Hi,

The function being changed in this patch can be invoked on VECTOR_TYPE,
but the implementation assumes it works on integer types only.

To fix, added a check whether the type passed is any `__vector(T)' or
non-integral type, and return early by calling
`signed_or_unsigned_type_for()' instead.

Problem was found by instrumenting TYPE_PRECISION and ICEing when
applied on VECTOR_TYPEs.

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

Regards,
Iain.

---
PR d/110193

gcc/d/ChangeLog:

* types.cc (d_signed_or_unsigned_type): Handle being called with any
vector or non-integral type.
---
 gcc/d/types.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index a4c05bfb75f..bdf07f83d4b 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -49,8 +49,8 @@ along with GCC; see the file COPYING3.  If not see
 static tree
 d_signed_or_unsigned_type (int unsignedp, tree type)
 {
-  if (TYPE_UNSIGNED (type) == (unsigned) unsignedp)
-return type;
+  if (VECTOR_TYPE_P (type) || !ANY_INTEGRAL_TYPE_P (type))
+return signed_or_unsigned_type_for (unsignedp, type);
 
   if (TYPE_PRECISION (type) == TYPE_PRECISION (d_cent_type))
 return unsignedp ? d_ucent_type : d_cent_type;
-- 
2.39.2



[committed] d: Suboptimal codegen for __builtin_expect(cond, false)

2023-06-25 Thread Iain Buclaw via Gcc-patches
Hi,

Since PR96435, both boolean objects and expressions have been evaluated
in the following way by the D front-end.

(*(ubyte*)_or_expr) & 1

It has been noted that sometimes this can cause the back-end to optimize
in non-obvious ways - in particular with __builtin_expect.

This @safe feature is now restricted to just when reading the value of a
bool field that comes from a union.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32, committed
to mainline, and backported to releases/gcc-13 through to gcc-10.

Regards,
Iain.

---
PR d/110359

gcc/d/ChangeLog:

* d-convert.cc (convert_for_rvalue): Only apply the @safe boolean
conversion to boolean fields of a union.
(convert_for_condition): Call convert_for_rvalue in the default case.

gcc/testsuite/ChangeLog:

* gdc.dg/pr110359.d: New test.
---
 gcc/d/d-convert.cc  | 31 +++
 gcc/testsuite/gdc.dg/pr110359.d | 22 ++
 2 files changed, 41 insertions(+), 12 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/pr110359.d

diff --git a/gcc/d/d-convert.cc b/gcc/d/d-convert.cc
index cdbd69cf012..2b9d8e78fb6 100644
--- a/gcc/d/d-convert.cc
+++ b/gcc/d/d-convert.cc
@@ -619,7 +619,7 @@ convert_expr (tree exp, Type *etype, Type *totype)
   return result ? result : convert (build_ctype (totype), exp);
 }
 
-/* Return a TREE represenwation of EXPR, whose type has been converted from
+/* Return a TREE representation of EXPR, whose type has been converted from
  * ETYPE to TOTYPE, and is being used in an rvalue context.  */
 
 tree
@@ -634,20 +634,27 @@ convert_for_rvalue (tree expr, Type *etype, Type *totype)
 {
   /* If casting from bool, the result is either 0 or 1, any other value
 violates @safe code, so enforce that it is never invalid.  */
-  if (CONSTANT_CLASS_P (expr))
-   result = d_truthvalue_conversion (expr);
-  else
+  for (tree ref = expr; TREE_CODE (ref) == COMPONENT_REF;
+  ref = TREE_OPERAND (ref, 0))
{
- /* Reinterpret the boolean as an integer and test the first bit.
-The generated code should end up being equivalent to:
+ /* If the expression is a field that's part of a union, reinterpret
+the boolean as an integer and test the first bit.  The generated
+code should end up being equivalent to:
*cast(ubyte *) & 1;  */
- machine_mode bool_mode = TYPE_MODE (TREE_TYPE (expr));
- tree mtype = lang_hooks.types.type_for_mode (bool_mode, 1);
- result = fold_build2 (BIT_AND_EXPR, mtype,
-   build_vconvert (mtype, expr),
-   build_one_cst (mtype));
+ if (TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0))) == UNION_TYPE)
+   {
+ machine_mode bool_mode = TYPE_MODE (TREE_TYPE (expr));
+ tree mtype = lang_hooks.types.type_for_mode (bool_mode, 1);
+ result = fold_build2 (BIT_AND_EXPR, mtype,
+   build_vconvert (mtype, expr),
+   build_one_cst (mtype));
+ break;
+   }
}
 
+  if (result == NULL_TREE)
+   result = d_truthvalue_conversion (expr);
+
   result = convert (build_ctype (tbtype), result);
 }
 
@@ -844,7 +851,7 @@ convert_for_condition (tree expr, Type *type)
   break;
 
 default:
-  result = expr;
+  result = convert_for_rvalue (expr, type, type);
   break;
 }
 
diff --git a/gcc/testsuite/gdc.dg/pr110359.d b/gcc/testsuite/gdc.dg/pr110359.d
new file mode 100644
index 000..bf69201d9a5
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr110359.d
@@ -0,0 +1,22 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110359
+// { dg-do compile }
+// { dg-options "-fdump-tree-original" }
+double pow(in double x, in ulong p)
+{
+import gcc.builtins : __builtin_expect;
+if (__builtin_expect(p == 0, false))
+return 1;
+if (__builtin_expect(p == 1, false))
+return x;
+
+double s = x;
+double v = 1;
+for (ulong i = p; i > 1; i >>= 1)
+{
+v = (i & 0x1) ? s * v : v;
+s = s * s;
+}
+return v * s;
+}
+// { dg-final { scan-tree-dump "if \\(__builtin_expect \\(p == 0, 0\\) != 
0\\)" "original" } }
+// { dg-final { scan-tree-dump "if \\(__builtin_expect \\(p == 1, 0\\) != 
0\\)" "original" } }
-- 
2.39.2



[GCC13][committed] d: Fix crash in d/dmd/root/aav.d:127 dmd_aaGetRvalue from DsymbolTable::lookup (PR110113)

2023-06-25 Thread Iain Buclaw via Gcc-patches
Hi,

This backports patch from upstream dmd mainline for fixing PR110113.

The data being Mem.xrealloc'd contains many Array(T) fields, some of
which have self references in their data.ptr field thanks to the
smallarray optimization used by Array.

Naturally then, the memcpy from old GC data to new retains those self
referenced addresses, and the GC marks the old data as "free". Some time
later GC.malloc will return a pointer to said "free" data. So now we
have two GC references to the same memory. One that is treating the data
as an Array(VarDeclaration) in dmd.escape.escapeByStorage, and the other
as an AA in the symtab of a dmd.dsymbol.ScopeDsymbol.

Fix this memory corruption by not storing the data in a global variable
for reuse.  If there are no more live references, the GC will free it.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32, committed
to releases/gcc-13, and backported to releases/gcc-12.

Regards,
Iain.

---
PR d/110113

gcc/d/ChangeLog:

* dmd/escape.d (checkMutableArguments): Always allocate new buffer for
computing escapeBy.

gcc/testsuite/ChangeLog:

* gdc.test/compilable/test23978.d: New test.

Reviewed-on: https://github.com/dlang/dmd/pull/15302
---
 gcc/d/dmd/escape.d| 24 +--
 gcc/testsuite/gdc.test/compilable/test23978.d | 30 +++
 2 files changed, 31 insertions(+), 23 deletions(-)
 create mode 100644 gcc/testsuite/gdc.test/compilable/test23978.d

diff --git a/gcc/d/dmd/escape.d b/gcc/d/dmd/escape.d
index 420fa7f80bb..7586e5c7184 100644
--- a/gcc/d/dmd/escape.d
+++ b/gcc/d/dmd/escape.d
@@ -93,22 +93,7 @@ bool checkMutableArguments(Scope* sc, FuncDeclaration fd, 
TypeFunction tf,
 bool isMutable; // true if reference to mutable
 }
 
-/* Store escapeBy as static data escapeByStorage so we can keep reusing 
the same
- * arrays rather than reallocating them.
- */
-__gshared EscapeBy[] escapeByStorage;
-auto escapeBy = escapeByStorage;
-if (escapeBy.length < len)
-{
-auto newPtr = cast(EscapeBy*)mem.xrealloc(escapeBy.ptr, len * 
EscapeBy.sizeof);
-// Clear the new section
-memset(newPtr + escapeBy.length, 0, (len - escapeBy.length) * 
EscapeBy.sizeof);
-escapeBy = newPtr[0 .. len];
-escapeByStorage = escapeBy;
-}
-else
-escapeBy = escapeBy[0 .. len];
-
+auto escapeBy = new EscapeBy[len];
 const paramLength = tf.parameterList.length;
 
 // Fill in escapeBy[] with arguments[], ethis, and outerVars[]
@@ -228,13 +213,6 @@ bool checkMutableArguments(Scope* sc, FuncDeclaration fd, 
TypeFunction tf,
 escape(i, eb, false);
 }
 
-/* Reset the arrays in escapeBy[] so we can reuse them next time through
- */
-foreach (ref eb; escapeBy)
-{
-eb.er.reset();
-}
-
 return errors;
 }
 
diff --git a/gcc/testsuite/gdc.test/compilable/test23978.d 
b/gcc/testsuite/gdc.test/compilable/test23978.d
new file mode 100644
index 000..cc30f728dee
--- /dev/null
+++ b/gcc/testsuite/gdc.test/compilable/test23978.d
@@ -0,0 +1,30 @@
+// REQUIRED_ARGS: -preview=dip1021 -lowmem
+// https://issues.dlang.org/show_bug.cgi?id=23978
+
+// Note: this is a memory corruption bug.
+// Memory returned by `GC.realloc` retains references to old memory in it,
+// mostly because of the smallarray optimization for `Array(T)`.
+// If this fails again, it might not be consistent, so try running it multiple 
times.
+
+class LUBench { }
+void lup(ulong , ulong , int , int = 1)
+{
+new LUBench;
+}
+void lup_3200(ulong iters, ulong flops)
+{
+lup(iters, flops, 3200);
+}
+void raytrace()
+{
+struct V
+{
+float x, y, z;
+auto normalize() { }
+struct Tid { }
+auto spawnLinked() { }
+string[] namesByTid;
+class MessageBox { }
+auto cross() { }
+}
+}
-- 
2.39.2



[committed] d: Merge upstream dmd, druntime a45f4e9f43, phobos 106038f2e.

2023-06-25 Thread Iain Buclaw via Gcc-patches
Hi,

This patch merges the D front-end and run-time library with upstream dmd
5f7552bb28, and standard library with phobos 106038f2e.

Synchronizing with the latest bug fixes in the v2.103.1 release.

D front-end changes:

- Import dmd v2.103.1.
- Deprecated invalid special token sequences inside token strings.

D runtime changes:

- Import druntime v2.103.1.

Phobos changes:

- Import phobos v2.103.1.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32,
committed to mainline, and backported to releases/gcc-13.

Regards,
Iain.

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd a45f4e9f43.
* dmd/VERSION: Bump version to v2.103.1.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime a45f4e9f43.
* src/MERGE: Merge upstream phobos 106038f2e.
---
 gcc/d/dmd/MERGE   |   2 +-
 gcc/d/dmd/VERSION |   2 +-
 gcc/d/dmd/aggregate.h |  10 +-
 gcc/d/dmd/attrib.h|  12 +-
 gcc/d/dmd/common/outbuffer.h  |   6 +-
 gcc/d/dmd/cond.d  |   3 -
 gcc/d/dmd/cond.h  |   2 +-
 gcc/d/dmd/cppmangle.d |  11 +-
 gcc/d/dmd/declaration.h   |  12 +-
 gcc/d/dmd/dsymbol.h   |   4 +-
 gcc/d/dmd/dsymbolsem.d|  13 +-
 gcc/d/dmd/expression.h|  50 
 gcc/d/dmd/expressionsem.d |  22 +++-
 gcc/d/dmd/globals.h   | 112 +-
 gcc/d/dmd/hdrgen.d|   5 +-
 gcc/d/dmd/identifier.h|   2 +-
 gcc/d/dmd/init.h  |   8 +-
 gcc/d/dmd/lexer.d |  26 +++-
 gcc/d/dmd/module.h|   8 +-
 gcc/d/dmd/mtype.h |   4 +-
 gcc/d/dmd/objc.h  |   6 +-
 gcc/d/dmd/root/dcompat.h  |  10 +-
 gcc/d/dmd/root/optional.h |   4 +-
 gcc/d/dmd/scope.h |   4 +-
 gcc/d/dmd/statement.h |  24 ++--
 gcc/d/dmd/statementsem.d  |   8 +-
 gcc/d/dmd/target.h|  20 ++--
 gcc/d/dmd/template.h  |  14 +--
 gcc/d/dmd/visitor.h   |   3 +-
 gcc/testsuite/gdc.test/compilable/shared.d|  66 +++
 gcc/testsuite/gdc.test/compilable/test22739.d |  10 ++
 gcc/testsuite/gdc.test/compilable/test23799.d |  37 ++
 .../gdc.test/fail_compilation/bug9631.d   |   2 +-
 .../gdc.test/fail_compilation/cerrors.d   |  16 ++-
 .../gdc.test/fail_compilation/fail17646.d |   2 +-
 .../gdc.test/fail_compilation/fail19948.d |   2 +-
 .../gdc.test/fail_compilation/fail22857.d |  18 +++
 .../gdc.test/fail_compilation/fail23816.d |  16 +++
 .../fail_compilation/imports/import22857.d|   4 +
 .../gdc.test/fail_compilation/shared.d|  19 +++
 .../gdc.test/fail_compilation/test21164.d |   3 +-
 gcc/testsuite/gdc.test/runnable/complex3.d|  31 +
 libphobos/libdruntime/MERGE   |   2 +-
 .../libdruntime/core/sys/windows/stacktrace.d |   2 +
 libphobos/src/MERGE   |   2 +-
 libphobos/src/std/functional.d|   3 +
 46 files changed, 435 insertions(+), 207 deletions(-)
 create mode 100644 gcc/testsuite/gdc.test/compilable/test22739.d
 create mode 100644 gcc/testsuite/gdc.test/compilable/test23799.d
 create mode 100644 gcc/testsuite/gdc.test/fail_compilation/fail22857.d
 create mode 100644 gcc/testsuite/gdc.test/fail_compilation/fail23816.d
 create mode 100644 
gcc/testsuite/gdc.test/fail_compilation/imports/import22857.d
 create mode 100644 gcc/testsuite/gdc.test/runnable/complex3.d

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index 986925e8bdc..1205cd941b7 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-5f7552bb2829b75d5e36cc767a476e1ab35147b7
+a45f4e9f43e9fdbf0b666175e5e66b1ce4f561f6
 
 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 da496a2ceeb..8316aafdaca 100644
--- a/gcc/d/dmd/VERSION
+++ b/gcc/d/dmd/VERSION
@@ -1 +1 @@
-v2.103.0-rc.1
+v2.103.1
diff --git a/gcc/d/dmd/aggregate.h b/gcc/d/dmd/aggregate.h
index 04e5eb2f0d9..03fe478685c 100644
--- a/gcc/d/dmd/aggregate.h
+++ b/gcc/d/dmd/aggregate.h
@@ -108,8 +108,8 @@ public:
 Expression *getRTInfo;  // pointer to GC info generated by 
object.RTInfo(this)
 
 Visibility visibility;
-bool noDefaultCtor; // no default construction
-bool disableNew;// disallow allocations using `new`
+d_bool noDefaultCtor; // no default construction
+d_bool disableNew;// 

[GCC 12, committed] d: Merge upstream dmd 316b89f1e3, phobos 8e8aaae50.

2023-06-06 Thread Iain Buclaw via Gcc-patches
Hi,

This patch merges the D front-end with upstream dmd 316b89f1e3, and
standard library with phobos 8e8aaae50.

Updates the D language version to v2.100.2 in the GCC 12 release branch.

Phobos changes:

- Fix instantiating std.container.array.Array!T where T is a
  shared class.
- Fix calling toString on a const std.typecons.Nullable type.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32, committed
to releases/gcc-12.

Regards,
Iain.

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 316b89f1e3.
* dmd/VERSION: Bump version to v2.100.2.

libphobos/ChangeLog:

* src/MERGE: Merge upstream phobos 8e8aaae50.
---
 gcc/d/dmd/MERGE |  2 +-
 gcc/d/dmd/VERSION   |  2 +-
 libphobos/src/MERGE |  2 +-
 libphobos/src/std/container/array.d | 31 --
 libphobos/src/std/typecons.d| 40 +
 5 files changed, 66 insertions(+), 11 deletions(-)

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index d79ebfae806..51736565a57 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-76e3b41375e3e1cb4dbca692b587d8e916c0b49f
+316b89f1e3dffcad488c26f56f58c8adfcb84b26
 
 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 83a14f57e16..868f8007d2f 100644
--- a/gcc/d/dmd/VERSION
+++ b/gcc/d/dmd/VERSION
@@ -1 +1 @@
-v2.100.1
+v2.100.2
diff --git a/libphobos/src/MERGE b/libphobos/src/MERGE
index f2678185f39..8c570369602 100644
--- a/libphobos/src/MERGE
+++ b/libphobos/src/MERGE
@@ -1,4 +1,4 @@
-5fef0d28fc873fb5a0dbfb9149759d76a7b9f1b7
+8e8aaae5080ccc2e0a2202cbe9778dca96496a95
 
 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/container/array.d 
b/libphobos/src/std/container/array.d
index 08f9ead196e..ecc45996925 100644
--- a/libphobos/src/std/container/array.d
+++ b/libphobos/src/std/container/array.d
@@ -412,9 +412,9 @@ if (!is(immutable T == immutable bool))
 .destroy(e);
 
 static if (hasIndirections!T)
-GC.removeRange(_payload.ptr);
+GC.removeRange(cast(void*) _payload.ptr);
 
-free(_payload.ptr);
+free(cast(void*) _payload.ptr);
 }
 
 this(this) @disable;
@@ -489,14 +489,14 @@ if (!is(immutable T == immutable bool))
 auto newPayload = newPayloadPtr[0 .. oldLength];
 
 // copy old data over to new array
-memcpy(newPayload.ptr, _payload.ptr, T.sizeof * oldLength);
+memcpy(cast(void*) newPayload.ptr, cast(void*) _payload.ptr, 
T.sizeof * oldLength);
 // Zero out unused capacity to prevent gc from seeing false 
pointers
-memset(newPayload.ptr + oldLength,
+memset( cast(void*) (newPayload.ptr + oldLength),
 0,
 (elements - oldLength) * T.sizeof);
-GC.addRange(newPayload.ptr, sz);
-GC.removeRange(_payload.ptr);
-free(_payload.ptr);
+GC.addRange(cast(void*) newPayload.ptr, sz);
+GC.removeRange(cast(void*) _payload.ptr);
+free(cast(void*) _payload.ptr);
 _payload = newPayload;
 }
 else
@@ -611,12 +611,17 @@ if (!is(immutable T == immutable bool))
 return opEquals(rhs);
 }
 
+// fix https://issues.dlang.org/show_bug.cgi?23140
+private alias Unshared(T) = T;
+private alias Unshared(T: shared U, U) = U;
+
 /// ditto
 bool opEquals(ref const Array rhs) const
 {
 if (empty) return rhs.empty;
 if (rhs.empty) return false;
-return _data._payload == rhs._data._payload;
+
+return cast(Unshared!(T)[]) _data._payload ==  cast(Unshared!(T)[]) 
rhs._data._payload;
 }
 
 /**
@@ -1740,6 +1745,16 @@ if (!is(immutable T == immutable bool))
 assertThrown!AssertError(array.length = 5);
 }
 
+// https://issues.dlang.org/show_bug.cgi?id=23140
+@system unittest
+{
+shared class C
+{
+}
+
+Array!C ac;
+ac = Array!C([new C]);
+}
 

 // Array!bool
 

diff --git a/libphobos/src/std/typecons.d b/libphobos/src/std/typecons.d
index fb15001233a..34e884cac8a 100644
--- a/libphobos/src/std/typecons.d
+++ b/libphobos/src/std/typecons.d
@@ -3793,8 +3793,28 @@ Params:
 sink.formatValue(_value, fmt);
 }
 }
+
+void toString()(scope void delegate(const(char)[]) sink, scope const 
ref FormatSpec!char fmt) const
+{
+if (isNull)
+{
+sink.formatValue("Nullable.null", 

[committed] d: Warn when declared size of a special enum does not match its intrinsic type.

2023-06-05 Thread Iain Buclaw via Gcc-patches
Hi,

All special enums have declarations in the D runtime library, but the
compiler will recognize and treat them specially if declared in any
module.  When the underlying base type of a special enum is a different
size to its matched intrinsic, then this can cause undefined behavior at
runtime.  Detect and warn about when such a mismatch occurs.

This was found when merging the D front-end with the v2.103.1 release,
splitting this out of the merge patch into its own standalone change.

Bootstrapped and regression tested on x86_64-linux-gnu, committed to
mainline and backported to the releases/gcc-13 branch.

Regards,
Iain.

---
gcc/d/ChangeLog:

* gdc.texi (Warnings): Document -Wextra and -Wmismatched-special-enum.
* implement-d.texi (Special Enums): Add reference to warning option
-Wmismatched-special-enum.
* lang.opt: Add -Wextra and -Wmismatched-special-enum.
* types.cc (TypeVisitor::visit (TypeEnum *)): Warn when declared
special enum size mismatches its intrinsic type.

gcc/testsuite/ChangeLog:

* gdc.dg/Wmismatched_enum.d: New test.
---
 gcc/d/gdc.texi  | 17 +
 gcc/d/implement-d.texi  |  5 +
 gcc/d/lang.opt  |  8 
 gcc/d/types.cc  | 15 +++
 gcc/testsuite/gdc.dg/Wmismatched_enum.d |  4 
 5 files changed, 49 insertions(+)
 create mode 100644 gcc/testsuite/gdc.dg/Wmismatched_enum.d

diff --git a/gcc/d/gdc.texi b/gcc/d/gdc.texi
index 24b6ee00478..6f81967a83d 100644
--- a/gcc/d/gdc.texi
+++ b/gcc/d/gdc.texi
@@ -699,6 +699,23 @@ Do not warn about usage of deprecated features and symbols 
with
 @item -Werror
 Turns all warnings into errors.
 
+@opindex Wextra
+@opindex Wno-extra
+@item -Wextra
+This enables some extra warning flags that are not enabled by
+@option{-Wall}.
+
+@gccoptlist{-Waddress
+-Wcast-result
+-Wmismatched-special-enum
+-Wunknown-pragmas}
+
+@opindex Wmismatched-special-enum
+@opindex Wno-mismatched-special-enum
+@item -Wmismatched-special-enum
+Warn when an enum the compiler recognizes as special is declared with a
+different size to the built-in type it is representing.
+
 @opindex Wspeculative
 @opindex Wno-speculative
 @item -Wspeculative
diff --git a/gcc/d/implement-d.texi b/gcc/d/implement-d.texi
index 039e5fbd24e..6f33bc192fe 100644
--- a/gcc/d/implement-d.texi
+++ b/gcc/d/implement-d.texi
@@ -2085,6 +2085,11 @@ for convenience: @code{c_complex_double}, 
@code{c_complex_float},
 @code{c_complex_real}, @code{cpp_long}, @code{cpp_longlong},
 @code{c_long_double}, @code{cpp_ulong}, @code{cpp_ulonglong}.
 
+It may cause undefined behavior at runtime if a special enum is declared with a
+base type that has a different size to the target C/C++ type it is
+representing.  The GNU D compiler will catch such declarations and emit a
+warning when the @option{-Wmismatched-special-enum} option is seen on the
+command-line.
 
 @c 
 
diff --git a/gcc/d/lang.opt b/gcc/d/lang.opt
index bb0a3dcc911..26ca92c4c17 100644
--- a/gcc/d/lang.opt
+++ b/gcc/d/lang.opt
@@ -134,6 +134,14 @@ Werror
 D
 ; Documented in common.opt
 
+Wextra
+D Warning
+; Documented in common.opt
+
+Wmismatched-special-enum
+D Warning Var(warn_mismatched_special_enum) LangEnabledBy(D, Wextra)
+Warn when a special enum is declared with the wrong base type.
+
 Wpsabi
 D
 ; Documented in C
diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index beaf2a61af9..a4c05bfb75f 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -1067,6 +1067,21 @@ public:
gcc_assert (underlying != NULL);
 
t->ctype = build_variant_type_copy (build_ctype (underlying));
+
+   /* When the size of the declared enum base type doesn't match the target
+  C type that this enum is being used as a placeholder for, we can't
+  use the generated underlying type as it'll conflict with all sizes
+  the front-end has computed during semantic.  */
+   if (TYPE_SIZE (t->ctype) != TYPE_SIZE (basetype))
+ {
+   warning_at (make_location_t (t->sym->loc),
+   OPT_Wmismatched_special_enum,
+   "size of %qs (%wd) differ from its declared size (%wd)",
+   t->sym->ident->toChars (), int_size_in_bytes (t->ctype),
+   int_size_in_bytes (basetype));
+   t->ctype = basetype;
+ }
+
build_type_decl (t->ctype, t->sym);
   }
 else if (t->sym->ident == NULL
diff --git a/gcc/testsuite/gdc.dg/Wmismatched_enum.d 
b/gcc/testsuite/gdc.dg/Wmismatched_enum.d
new file mode 100644
index 000..54f47988c2b
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/Wmismatched_enum.d
@@ -0,0 +1,4 @@
+// { dg-do compile }
+// { dg-options "-Wmismatched-special-enum" }
+
+enum __c_longlong : byte; // { dg-warning "differ from its declared size" }
-- 
2.39.2



[committed] d: Merge upstream dmd, druntime 5f7552bb28, phobos 67a47cf39.

2023-03-16 Thread Iain Buclaw via Gcc-patches
Hi,

This patch merges the D front-end and run-time library with upstream dmd
5f7552bb28, and standard library with phobos 67a47cf39.

Synchronizing the latest bug fixes in the upcoming v2.103.0 release.

D front-end changes:

- Import dmd v2.103.0-rc.1.

D runtime changes:

- Import druntime v2.103.0-rc.1.

Phobos changes:

- Import phobos v2.103.0-rc.1.

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 5f7552bb28.
* dmd/VERSION: Bump version to v2.103.0-rc.1.

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

Regards,
Iain.

---
libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 5f7552bb28.
* src/MERGE: Merge upstream phobos 67a47cf39.
---
 gcc/d/dmd/MERGE   |   2 +-
 gcc/d/dmd/VERSION |   2 +-
 gcc/d/dmd/dinterpret.d|  12 ++-
 gcc/d/dmd/dsymbol.d   |  21 +++-
 gcc/d/dmd/expressionsem.d | 102 +-
 gcc/d/dmd/typesem.d   |   1 +
 gcc/d/dmd/typinf.d|   5 +-
 gcc/testsuite/gdc.test/compilable/test16213.d |   8 ++
 gcc/testsuite/gdc.test/compilable/test17351.d |   9 ++
 gcc/testsuite/gdc.test/compilable/test19295.d |  10 ++
 .../gdc.test/compilable/testcorrectthis.d |  37 +++
 .../gdc.test/fail_compilation/fail23760.d |  27 +
 .../gdc.test/fail_compilation/fail61.d|   2 +-
 .../gdc.test/fail_compilation/fail_circular.d |  15 +--
 .../gdc.test/fail_compilation/ice19295.d  |  18 
 .../gdc.test/fail_compilation/ice23781.d  |  10 ++
 .../gdc.test/fail_compilation/ice9439.d   |   4 +-
 libphobos/libdruntime/MERGE   |   2 +-
 libphobos/src/MERGE   |   2 +-
 libphobos/src/std/math/exponential.d  |  30 --
 libphobos/src/std/traits.d|  27 -
 21 files changed, 295 insertions(+), 51 deletions(-)
 create mode 100644 gcc/testsuite/gdc.test/compilable/test16213.d
 create mode 100644 gcc/testsuite/gdc.test/compilable/test19295.d
 create mode 100644 gcc/testsuite/gdc.test/compilable/testcorrectthis.d
 create mode 100644 gcc/testsuite/gdc.test/fail_compilation/fail23760.d
 delete mode 100644 gcc/testsuite/gdc.test/fail_compilation/ice19295.d
 create mode 100644 gcc/testsuite/gdc.test/fail_compilation/ice23781.d

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index 269eebfc483..986925e8bdc 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-4ca4140e584c055a8a9bc727e56a97ebcecd61e0
+5f7552bb2829b75d5e36cc767a476e1ab35147b7
 
 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 8b24f92dab7..da496a2ceeb 100644
--- a/gcc/d/dmd/VERSION
+++ b/gcc/d/dmd/VERSION
@@ -1 +1 @@
-v2.103.0-beta.1
+v2.103.0-rc.1
diff --git a/gcc/d/dmd/dinterpret.d b/gcc/d/dmd/dinterpret.d
index 9073b0db2f8..e6ef704be86 100644
--- a/gcc/d/dmd/dinterpret.d
+++ b/gcc/d/dmd/dinterpret.d
@@ -2036,7 +2036,7 @@ public:
 }
 auto er = interpret(e.e1, istate, CTFEGoal.LValue);
 if (auto ve = er.isVarExp())
-if (ve.var == istate.fd.vthis)
+if (istate && ve.var == istate.fd.vthis)
 er = interpret(er, istate);
 
 if (exceptionOrCant(er))
@@ -2117,6 +2117,16 @@ public:
 return CTFEExp.cantexp;
 assert(e.type);
 
+// There's a terrible hack in `dmd.dsymbolsem` that special 
case
+// a struct with all zeros to an 
`ExpInitializer(BlitExp(IntegerExp(0)))`
+// There's matching code for it in e2ir (toElem's 
visitAssignExp),
+// so we need the same hack here.
+// This does not trigger for global as they get a normal 
initializer.
+if (auto ts = e.type.isTypeStruct())
+if (auto ae = e.isBlitExp())
+if (ae.e2.op == EXP.int64)
+e = ts.defaultInitLiteral(loc);
+
 if (e.op == EXP.construct || e.op == EXP.blit)
 {
 AssignExp ae = cast(AssignExp)e;
diff --git a/gcc/d/dmd/dsymbol.d b/gcc/d/dmd/dsymbol.d
index aa478f2fea2..e7ce93ee067 100644
--- a/gcc/d/dmd/dsymbol.d
+++ b/gcc/d/dmd/dsymbol.d
@@ -2162,10 +2162,23 @@ extern (C++) final class ArrayScopeSymbol : ScopeDsymbol
  * or a variable (in which case an expression is created in
  * toir.c).
  */
-auto e = new VoidInitializer(Loc.initial);
-e.type = Type.tsize_t;
-v = new VarDeclaration(loc, Type.tsize_t, Id.dollar, e);
-v.storage_class |= STC.temp | STC.ctfe; // it's never a true 
static variable
+
+// 

[committed] d: Fix closure fields don't get same alignment as local variable [PR109144]

2023-03-16 Thread Iain Buclaw via Gcc-patches
Hi,

Local variables with both non-local references and explicit alignment
did not propagate their alignment to either the closure field or closure
frame type, resulting in the closure being misaligned. This is now
correctly set-up when building the frame type.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32,
committed to mainline and backported to releases/gcc-12.

I did have a look at backporting to gcc-11 too, however the D front-end
does not correctly set the alignment of local variables, so although the
code generation pass is doing the right thing, the alignment for the
local variable is never set in the first place.

Regards,
Iain.

---
PR d/109144

gcc/d/ChangeLog:

* d-codegen.cc (build_frame_type): Set frame field and type alignment.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/pr109144.d: New test.
---
 gcc/d/d-codegen.cc  | 5 +
 gcc/testsuite/gdc.dg/torture/pr109144.d | 9 +
 2 files changed, 14 insertions(+)
 create mode 100644 gcc/testsuite/gdc.dg/torture/pr109144.d

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 5a041927ec9..5c6c300ecec 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -2706,6 +2706,11 @@ build_frame_type (tree ffi, FuncDeclaration *fd)
   TREE_ADDRESSABLE (field) = TREE_ADDRESSABLE (vsym);
   DECL_NONADDRESSABLE_P (field) = !TREE_ADDRESSABLE (vsym);
   TREE_THIS_VOLATILE (field) = TREE_THIS_VOLATILE (vsym);
+  SET_DECL_ALIGN (field, DECL_ALIGN (vsym));
+
+  /* Update alignment for frame record type.  */
+  if (TYPE_ALIGN (frame_rec_type) < DECL_ALIGN (field))
+   SET_TYPE_ALIGN (frame_rec_type, DECL_ALIGN (field));
 
   if (DECL_LANG_NRVO (vsym))
{
diff --git a/gcc/testsuite/gdc.dg/torture/pr109144.d 
b/gcc/testsuite/gdc.dg/torture/pr109144.d
new file mode 100644
index 000..32d3af7cd45
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/pr109144.d
@@ -0,0 +1,9 @@
+// { dg-do run }
+// { dg-skip-if "needs gcc/config.d" { ! d_runtime } }
+void main()
+{
+align(128) byte var;
+assert((cast(size_t) ) % 128 == 0);
+var = 73;
+assert((() => var)() == 73);
+}
-- 
2.37.2



[committed] d: Fix undefined reference to lambda defined in private enum [PR109108]

2023-03-14 Thread Iain Buclaw via Gcc-patches
Hi,

This patch fixes linker error as described in PR d/109108.

Previously lambdas were connected to the module they were defined in.
Now they are emitted into every referencing compilation unit, and are
given one-only linkage.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32,
committed to mainline, and backported to releases/gcc-11 and gcc-12.

Regards,
Iain.

---
PR d/109108

gcc/d/ChangeLog:

* decl.cc (function_defined_in_root_p): Remove.
(get_symbol_decl): Set DECL_LAMBDA_FUNCTION_P on function literals.
(start_function): Unconditionally unset DECL_EXTERNAL
(set_linkage_for_decl): Give lambda functions one-only linkage.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/imports/pr109108.d: New test.
* gdc.dg/torture/pr109108.d: New test.
---
 gcc/d/decl.cc | 41 ++-
 .../gdc.dg/torture/imports/pr109108.d | 11 +
 gcc/testsuite/gdc.dg/torture/pr109108.d   | 10 +
 3 files changed, 34 insertions(+), 28 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/torture/imports/pr109108.d
 create mode 100644 gcc/testsuite/gdc.dg/torture/pr109108.d

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index c451805639d..4fbabd59998 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -1090,25 +1090,6 @@ build_decl_tree (Dsymbol *d)
   input_location = saved_location;
 }
 
-/* Returns true if function FD, or any lexically enclosing scope function of FD
-   is defined or instantiated in a root module.  */
-
-static bool
-function_defined_in_root_p (FuncDeclaration *fd)
-{
-  Module *md = fd->getModule ();
-  if (md && md->isRoot ())
-return true;
-
-  for (TemplateInstance *ti = fd->isInstantiated (); ti != NULL; ti = 
ti->tinst)
-{
-  if (ti->minst && ti->minst->isRoot ())
-   return true;
-}
-
-  return false;
-}
-
 /* Returns true if function FD always needs to be implicitly defined, such as
it was declared `pragma(inline)'.  */
 
@@ -1474,6 +1455,12 @@ get_symbol_decl (Declaration *decl)
  DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl->csym) = 1;
}
 
+  /* In [expression/function_literals], function literals (aka lambdas)
+enable embedding anonymous functions and anonymous delegates directly
+into expressions.  They are defined in each referencing module.  */
+  if (fd->isFuncLiteralDeclaration ())
+   DECL_SET_LAMBDA_FUNCTION (decl->csym, true);
+
   /* Mark compiler generated functions as artificial.  */
   if (fd->isGenerated ())
DECL_ARTIFICIAL (decl->csym) = 1;
@@ -2029,12 +2016,9 @@ start_function (FuncDeclaration *fd)
 {
   tree fndecl = get_symbol_decl (fd);
 
-  /* Function has been defined, check now whether we intend to send it to
- object file, or it really is extern.  Such as inlinable functions from
- modules not in this compilation, or thunk aliases.  */
-  if (function_defined_in_root_p (fd))
-DECL_EXTERNAL (fndecl) = 0;
-
+  /* Function has been defined. Whether we intend to send it to object file, or
+ discard it has already been determined by set_linkage_for_decl.  */
+  DECL_EXTERNAL (fndecl) = 0;
   DECL_INITIAL (fndecl) = error_mark_node;
 
   /* Add this decl to the current binding level.  */
@@ -2550,9 +2534,10 @@ set_linkage_for_decl (tree decl)
   if (!TREE_PUBLIC (decl))
 return;
 
-  /* Functions declared as `pragma(inline, true)' can appear in multiple
- translation units.  */
-  if (TREE_CODE (decl) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (decl))
+  /* Function literals and functions declared as `pragma(inline, true)' can
+ appear in multiple translation units.  */
+  if (TREE_CODE (decl) == FUNCTION_DECL
+  && (DECL_DECLARED_INLINE_P (decl) || DECL_LAMBDA_FUNCTION_P (decl)))
 return d_comdat_linkage (decl);
 
   /* Don't need to give private or protected symbols a special linkage.  */
diff --git a/gcc/testsuite/gdc.dg/torture/imports/pr109108.d 
b/gcc/testsuite/gdc.dg/torture/imports/pr109108.d
new file mode 100644
index 000..cec5274098c
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/imports/pr109108.d
@@ -0,0 +1,11 @@
+module imports.pr109108;
+private enum int function(ref int)[] funs =
+[
+0: (ref idx) => 0,
+1: (ref idx) => 1,
+];
+
+int test109108(I)(I idx)
+{
+return funs[idx](idx);
+}
diff --git a/gcc/testsuite/gdc.dg/torture/pr109108.d 
b/gcc/testsuite/gdc.dg/torture/pr109108.d
new file mode 100644
index 000..4a428bf85a6
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/pr109108.d
@@ -0,0 +1,10 @@
+// { dg-additional-files "imports/pr109108.d" }
+// { dg-additional-options "-I[srcdir] -fno-moduleinfo" }
+// { dg-do link }
+// { dg-skip-if "needs gcc/config.d" { ! d_runtime } }
+import imports.pr109108;
+
+extern(C) int main()
+{
+return test109108(0);
+}
-- 
2.37.2



[committed] d: Delay removing DECL_EXTERNAL from thunks until funcion has finished

2023-03-13 Thread Iain Buclaw via Gcc-patches
Hi,

This is the second part to fixing PR109108, don't blindly generate the
associated function definition of all referenced thunks in the
compilation. Just delay finishing a thunk until the function gets
codegen itself.  If the function never gets a definition, then the thunk
is left as "extern".

Bootstrapped and regression tested on x86_64-linux/-m32/-mx32, committed
to mainline and backported to the releases/gcc-11 and gcc-12 branches.

Regards,
Iain.

---
gcc/d/ChangeLog:

* decl.cc (finish_thunk): Unset DECL_EXTERNAL on thunk.
(make_thunk): Set DECL_EXTERNAL on thunk, don't call build_decl_tree.
(finish_function): Call finish_thunk on forward referenced thunks.
---
 gcc/d/decl.cc | 37 ++---
 1 file changed, 18 insertions(+), 19 deletions(-)

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index d4e936d0f83..c451805639d 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -1858,6 +1858,7 @@ finish_thunk (tree thunk, tree function)
 
   TREE_ADDRESSABLE (function) = 1;
   TREE_USED (function) = 1;
+  DECL_EXTERNAL (thunk) = 0;
 
   if (flag_syntax_only)
 {
@@ -1929,21 +1930,14 @@ make_thunk (FuncDeclaration *decl, int offset)
 
   if (!DECL_ARGUMENTS (function) || !DECL_RESULT (function))
 {
-  /* Compile the function body before generating the thunk, this is done
-even if the decl is external to the current module.  */
-  if (decl->fbody)
-   build_decl_tree (decl);
-  else
-   {
- /* Build parameters for functions that are not being compiled,
-so that they can be correctly cloned in finish_thunk.  */
- tree function = get_symbol_decl (decl);
- DECL_ARGUMENTS (function) = get_fndecl_arguments (decl);
-
- /* Also build the result decl, which is needed when force creating
-the thunk in gimple inside cgraph_node::expand_thunk.  */
- DECL_RESULT (function) = get_fndecl_result (decl);
-   }
+  /* Build parameters for functions that are not being compiled,
+so that they can be correctly cloned in finish_thunk.  */
+  tree function = get_symbol_decl (decl);
+  DECL_ARGUMENTS (function) = get_fndecl_arguments (decl);
+
+  /* Also build the result decl, which is needed when force creating
+the thunk in gimple inside cgraph_node::expand_thunk.  */
+  DECL_RESULT (function) = get_fndecl_result (decl);
 }
 
   /* Don't build the thunk if the compilation step failed.  */
@@ -1969,11 +1963,10 @@ make_thunk (FuncDeclaration *decl, int offset)
 
   DECL_CONTEXT (thunk) = d_decl_context (decl);
 
-  /* Thunks inherit the public access of the function they are targeting.
- Thunks are connected to the definitions of the functions, so thunks are
- not produced for external functions.  */
+  /* Thunks inherit the public access of the function they are targeting.  */
   TREE_PUBLIC (thunk) = TREE_PUBLIC (function);
-  DECL_EXTERNAL (thunk) = DECL_EXTERNAL (function);
+  /* The thunk has not been defined -- yet.  */
+  DECL_EXTERNAL (thunk) = 1;
 
   /* Thunks are always addressable.  */
   TREE_ADDRESSABLE (thunk) = 1;
@@ -2013,6 +2006,8 @@ make_thunk (FuncDeclaration *decl, int offset)
   if (decl->resolvedLinkage () != LINK::cpp)
 free (CONST_CAST (char *, ident));
 
+  /* Thunks are connected to the definitions of the functions, so thunks are
+ not produced for external functions.  */
   if (!DECL_EXTERNAL (function))
 finish_thunk (thunk, function);
 
@@ -2122,6 +2117,10 @@ finish_function (tree old_context)
 
   DECL_SAVED_TREE (fndecl) = bind;
 
+  /* Finish any forward referenced thunks for the function.  */
+  for (tree t = DECL_LANG_THUNKS (fndecl); t; t = DECL_CHAIN (t))
+finish_thunk (t, fndecl);
+
   if (!errorcount && !global.errors)
 {
   /* Dump the D-specific tree IR.  */
-- 
2.37.2



[committed] d: Refactor DECL_ARGUMENT and DECL_RESULT generation to own function

2023-03-13 Thread Iain Buclaw via Gcc-patches
Hi,

When looking into PR109108, the reason why things go awry is because
of the logic around functions with thunks - they have their definitions
generated even when they are external.  This subsequently then relied on
the detection of whether a function receiving codegen really is extern
or not, and this check ultimately prunes too much.

This is a first step to both removing the call to `build_decl_tree' from
`make_thunk' and the pruning of symbols within the `build_decl_tree'
visitor method for functions.  Move the generation of DECL_ARGUMENT and
DECL_RESULT out of `build_decl_tree' and into their own functions.

Bootstrapped and regression tested on x86_64-linux/-m32/-mx32, committed
to mainline and backported to the releases/gcc-11 and gcc-12 branches.

Regards,
Iain.

---
gcc/d/ChangeLog:

* decl.cc (get_fndecl_result): New function.
(get_fndecl_arguments): New function.
(DeclVisitor::visit (FuncDeclaration *)): Adjust to call
get_fndecl_arguments.
(make_thunk): Adjust to call get_fndecl_arguments and
get_fndecl_result.
(start_function): Adjust to call get_fndecl_result.
---
 gcc/d/decl.cc | 206 +-
 1 file changed, 118 insertions(+), 88 deletions(-)

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 990ac4016b8..d4e936d0f83 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -117,6 +117,113 @@ gcc_attribute_p (Dsymbol *decl)
   return false;
 }
 
+/* Return the DECL_RESULT for the function declaration DECL, create it if it
+   doesn't already exist.  */
+
+static tree
+get_fndecl_result (FuncDeclaration *decl)
+{
+  tree fndecl = get_symbol_decl (decl);
+  tree resdecl = DECL_RESULT (fndecl);
+
+  if (resdecl != NULL_TREE)
+return resdecl;
+
+  resdecl = build_decl (make_location_t (decl->loc), RESULT_DECL,
+   NULL_TREE, TREE_TYPE (TREE_TYPE (fndecl)));
+
+  DECL_ARTIFICIAL (resdecl) = 1;
+  DECL_IGNORED_P (resdecl) = 1;
+  DECL_CONTEXT (resdecl) = fndecl;
+  DECL_RESULT (fndecl) = resdecl;
+  return resdecl;
+}
+
+/* Return the list of PARAM_DECLs for the function declaration DECL, create it
+   if it doesn't already exist.  */
+
+static tree
+get_fndecl_arguments (FuncDeclaration *decl)
+{
+  tree fndecl = get_symbol_decl (decl);
+  tree param_list = DECL_ARGUMENTS (fndecl);
+
+  if (param_list != NULL_TREE)
+return param_list;
+
+  if (decl->fbody)
+{
+  /* Handle special arguments first.  */
+
+  /* `this' parameter:
+For nested functions, D still generates a vthis, but it
+should not be referenced in any expression.  */
+  if (decl->vthis)
+   {
+ 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);
+   }
+
+  /* `_arguments' parameter.  */
+  if (decl->v_arguments)
+   {
+ tree parm_decl = get_symbol_decl (decl->v_arguments);
+ param_list = chainon (param_list, parm_decl);
+   }
+
+  /* Now add on formal function parameters.  */
+  size_t n_parameters = decl->parameters ? decl->parameters->length : 0;
+
+  for (size_t i = 0; i < n_parameters; i++)
+   {
+ VarDeclaration *param = (*decl->parameters)[i];
+ tree parm_decl = get_symbol_decl (param);
+
+ /* Type `noreturn` is a terminator, as no other arguments can possibly
+be evaluated after it.  */
+ if (TREE_TYPE (parm_decl) == noreturn_type_node)
+   break;
+
+ /* Chain them in the correct order.  */
+ param_list = chainon (param_list, parm_decl);
+   }
+}
+  else
+{
+  /* Build parameters from the function type.  */
+  tree fntype = TREE_TYPE (fndecl);
+
+  for (tree t = TYPE_ARG_TYPES (fntype); t; t = TREE_CHAIN (t))
+   {
+ if (t == void_list_node)
+   break;
+
+ tree param = build_decl (DECL_SOURCE_LOCATION (fndecl),
+  PARM_DECL, NULL_TREE, TREE_VALUE (t));
+ DECL_ARG_TYPE (param) = TREE_TYPE (param);
+ DECL_ARTIFICIAL (param) = 1;
+ DECL_IGNORED_P (param) = 1;
+ DECL_CONTEXT (param) = fndecl;
+ param_list = chainon (param_list, param);
+   }
+}
+
+  DECL_ARGUMENTS (fndecl) = param_list;
+  return param_list;
+}
+
 /* Implements the visitor interface to lower all Declaration AST classes
emitted from the D Front-end to GCC trees.
All visit methods accept one parameter D, which holds the frontend AST
@@ 

[committed] d: Document that TypeInfo-based va_arg is not implemented [PR108763]

2023-03-03 Thread Iain Buclaw via Gcc-patches
Hi,

GDC's run-time library doesn't implement the RTTI-based overload of
va_arg, document it on the missing features page.

Bootstrapped and regression tested, committed to mainline.

Regards,
Iain.

---
PR d/108763

gcc/d/ChangeLog:

* implement-d.texi (Missing Features): Document that TypeInfo-based
va_arg is not implemented.
---
 gcc/d/implement-d.texi | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/gcc/d/implement-d.texi b/gcc/d/implement-d.texi
index 89a17916a83..039e5fbd24e 100644
--- a/gcc/d/implement-d.texi
+++ b/gcc/d/implement-d.texi
@@ -2511,4 +2511,10 @@ version (GNU)
 @}
 @end smallexample
 
+@item TypeInfo-based va_arg
+The Digital Mars D compiler implements a version of @code{core.vararg.va_arg}
+that accepts a run-time @code{TypeInfo} argument for use when the static type
+is not known.  This function is not implemented by GNU D.  It is more portable
+to use variadic template functions instead.
+
 @end table
-- 
2.37.2



[committed] d: vector float comparison doesn't result in 0 or -1 [PR108945]

2023-03-02 Thread Iain Buclaw via Gcc-patches
Hi,

When comparing two vectors, the type of vector was used as the result of
the condition result.  This meant that for floating point comparisons,
each value would either be `0.0' or `-1.0' reinterpreted as an integer,
not the expected integral bitmask values `0' and `-1'.

Instead, use the comparison type determined by truth_type_for as the
result of the comparison.  If a reinterpret is later required by the
final conversion for generating CmpExp, it is still only going to
reinterpret one integer kind as another.

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

Regards,
Iain.

---
PR d/108945

gcc/d/ChangeLog:

* d-codegen.cc (build_boolop): Evaluate vector comparison as
the truth_type_for vector type.

gcc/testsuite/ChangeLog:

* gdc.dg/pr108945.d: New test.
---
 gcc/d/d-codegen.cc  |  9 -
 gcc/testsuite/gdc.dg/pr108945.d | 12 
 2 files changed, 16 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/pr108945.d

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 0e8e07366ee..5a041927ec9 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -1453,13 +1453,12 @@ build_boolop (tree_code code, tree arg0, tree arg1)
 {
   /* Build a vector comparison.
 VEC_COND_EXPR ; */
-  tree type = TREE_TYPE (arg0);
-  tree cmptype = truth_type_for (type);
+  tree cmptype = truth_type_for (TREE_TYPE (arg0));
   tree cmp = fold_build2_loc (input_location, code, cmptype, arg0, arg1);
 
-  return fold_build3_loc (input_location, VEC_COND_EXPR, type, cmp,
- build_minus_one_cst (type),
- build_zero_cst (type));
+  return fold_build3_loc (input_location, VEC_COND_EXPR, cmptype, cmp,
+ build_minus_one_cst (cmptype),
+ build_zero_cst (cmptype));
 }
 
   if (code == EQ_EXPR || code == NE_EXPR)
diff --git a/gcc/testsuite/gdc.dg/pr108945.d b/gcc/testsuite/gdc.dg/pr108945.d
new file mode 100644
index 000..03b9de8e758
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr108945.d
@@ -0,0 +1,12 @@
+// { dg-options "-fdump-tree-gimple" }
+// { dg-additional-options "-mavx" { target avx_runtime } }
+// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } }
+
+alias f4 = __vector(float[4]);
+
+auto pr108945(f4 a, f4 b)
+{
+return a < b;
+}
+
+// { dg-final { scan-tree-dump-not "VEC_COND_EXPR" "gimple" } }
-- 
2.37.2



[committed] d: Fix ICE on explicit immutable struct import [PR10887]

2023-03-02 Thread Iain Buclaw via Gcc-patches
Hi,

This patch fixes an ICE in the D front-end when importing an immutable
struct.  Const and immutable types are built as variants of the type
they are derived from, and TYPE_STUB_DECL is not set for these variants.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32, committed
to mainline, and backported to the release branches for gcc-10, gcc-11,
and gcc-12.

Regards,
Iain.

---
PR d/108877

gcc/d/ChangeLog:

* imports.cc (ImportVisitor::visit (EnumDeclaration *)): Call
make_import on TYPE_MAIN_VARIANT.
(ImportVisitor::visit (AggregateDeclaration *)): Likewise.
(ImportVisitor::visit (ClassDeclaration *)): Likewise.

gcc/testsuite/ChangeLog:

* gdc.dg/imports/pr108877a.d: New test.
* gdc.dg/pr108877.d: New test.
---
 gcc/d/imports.cc | 7 ++-
 gcc/testsuite/gdc.dg/imports/pr108877a.d | 6 ++
 gcc/testsuite/gdc.dg/pr108877.d  | 9 +
 3 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gdc.dg/imports/pr108877a.d
 create mode 100644 gcc/testsuite/gdc.dg/pr108877.d

diff --git a/gcc/d/imports.cc b/gcc/d/imports.cc
index 3b46d1b7560..2efef4ed54f 100644
--- a/gcc/d/imports.cc
+++ b/gcc/d/imports.cc
@@ -106,12 +106,16 @@ public:
 tree type = build_ctype (d->type);
 /* Not all kinds of D enums create a TYPE_DECL.  */
 if (TREE_CODE (type) == ENUMERAL_TYPE)
-  this->result_ = this->make_import (TYPE_STUB_DECL (type));
+  {
+   type = TYPE_MAIN_VARIANT (type);
+   this->result_ = this->make_import (TYPE_STUB_DECL (type));
+  }
   }
 
   void visit (AggregateDeclaration *d) final override
   {
 tree type = build_ctype (d->type);
+type = TYPE_MAIN_VARIANT (type);
 this->result_ = this->make_import (TYPE_STUB_DECL (type));
   }
 
@@ -119,6 +123,7 @@ public:
   {
 /* Want the RECORD_TYPE, not POINTER_TYPE.  */
 tree type = TREE_TYPE (build_ctype (d->type));
+type = TYPE_MAIN_VARIANT (type);
 this->result_ = this->make_import (TYPE_STUB_DECL (type));
   }
 
diff --git a/gcc/testsuite/gdc.dg/imports/pr108877a.d 
b/gcc/testsuite/gdc.dg/imports/pr108877a.d
new file mode 100644
index 000..a23c78ddf84
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/imports/pr108877a.d
@@ -0,0 +1,6 @@
+immutable struct ImmutableS { }
+const struct ConstS { }
+immutable class ImmutableC { }
+const class ConstC { }
+immutable enum ImmutableE { _ }
+const enum ConstE { _ }
diff --git a/gcc/testsuite/gdc.dg/pr108877.d b/gcc/testsuite/gdc.dg/pr108877.d
new file mode 100644
index 000..710551f3f9a
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr108877.d
@@ -0,0 +1,9 @@
+// { dg-options "-I $srcdir/gdc.dg" }
+// { dg-do compile }
+import imports.pr108877a :
+ImmutableS,
+ConstS,
+ImmutableC,
+ConstC,
+ImmutableE,
+ConstE;
-- 
2.37.2



[committed] d: Allow vectors to be compared for identity (PR108946)

2023-03-02 Thread Iain Buclaw via Gcc-patches
Hi,

Vector equality and comparisons are now accepted by the language
implementation, but identity wasn't.  This patch implements it as an
extra integer comparison of the bit-casted bitmask.

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

Regards,
Iain.

---
PR d/108946

gcc/d/ChangeLog:

* d-target.cc (Target::isVectorOpSupported): Allow identity ops.
* expr.cc (ExprVisitor::visit (IdentityExp *)): Handle vector identity
comparisons.

gcc/testsuite/ChangeLog:

* gdc.dg/simd2a.d: Update test.
* gdc.dg/simd2b.d: Likewise.
* gdc.dg/simd2c.d: Likewise.
* gdc.dg/simd2d.d: Likewise.
* gdc.dg/simd2e.d: Likewise.
* gdc.dg/simd2f.d: Likewise.
* gdc.dg/simd2g.d: Likewise.
* gdc.dg/simd2h.d: Likewise.
* gdc.dg/simd2i.d: Likewise.
* gdc.dg/simd2j.d: Likewise.
---
 gcc/d/d-target.cc |  5 -
 gcc/d/expr.cc | 25 +
 gcc/testsuite/gdc.dg/simd2a.d |  5 +++--
 gcc/testsuite/gdc.dg/simd2b.d |  5 +++--
 gcc/testsuite/gdc.dg/simd2c.d |  5 +++--
 gcc/testsuite/gdc.dg/simd2d.d |  5 +++--
 gcc/testsuite/gdc.dg/simd2e.d |  5 +++--
 gcc/testsuite/gdc.dg/simd2f.d |  5 +++--
 gcc/testsuite/gdc.dg/simd2g.d |  5 +++--
 gcc/testsuite/gdc.dg/simd2h.d |  5 +++--
 gcc/testsuite/gdc.dg/simd2i.d |  5 +++--
 gcc/testsuite/gdc.dg/simd2j.d |  5 +++--
 12 files changed, 55 insertions(+), 25 deletions(-)

diff --git a/gcc/d/d-target.cc b/gcc/d/d-target.cc
index 5eab5706ead..4c7a212703e 100644
--- a/gcc/d/d-target.cc
+++ b/gcc/d/d-target.cc
@@ -323,11 +323,6 @@ Target::isVectorOpSupported (Type *type, EXP op, Type *)
   /* Logical operators must have a result type of bool.  */
   return false;
 
-case EXP::identity:
-case EXP::notIdentity:
-  /* Comparison operators must have a result type of bool.  */
-  return false;
-
 default:
   break;
 }
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index c8ec37d7103..4311edcc2d6 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -313,6 +313,31 @@ public:
 
this->result_ = build_struct_comparison (code, ts->sym, t1, t2);
   }
+else if (tb1->ty == TY::Tvector && tb2->ty == TY::Tvector)
+  {
+   /* For vectors, identity is defined as all values being equal.  */
+   tree t1 = build_expr (e->e1);
+   tree t2 = build_expr (e->e2);
+   tree mask = build_boolop (code, t1, t2);
+
+   /* To reinterpret the vector comparison as a boolean expression, bitcast
+  the bitmask result and generate an additional integer comparison.  */
+   opt_scalar_int_mode mode =
+ int_mode_for_mode (TYPE_MODE (TREE_TYPE (mask)));
+   gcc_assert (mode.exists ());
+
+   tree type = lang_hooks.types.type_for_mode (mode.require (), 1);
+   if (type == NULL_TREE)
+ type = make_unsigned_type (GET_MODE_BITSIZE (mode.require ()));
+
+   /* In `t1 is t2', all mask bits must be set for vectors to be equal.
+  Otherwise any bit set is enough for vectors to be not-equal.  */
+   tree mask_eq = (code == EQ_EXPR)
+ ? build_all_ones_cst (type) : build_zero_cst (type);
+
+   this->result_ = build_boolop (code, mask_eq,
+ build_vconvert (type, mask));
+  }
 else
   {
/* For operands of other types, identity is defined as being the
diff --git a/gcc/testsuite/gdc.dg/simd2a.d b/gcc/testsuite/gdc.dg/simd2a.d
index 373d5d1e229..d47175fd38b 100644
--- a/gcc/testsuite/gdc.dg/simd2a.d
+++ b/gcc/testsuite/gdc.dg/simd2a.d
@@ -5,6 +5,7 @@ import core.simd;
 void test2a()
 {
 byte16 v1, v2 = 1, v3 = 1;
+bool b1;
 v1 = v2;
 v1 = v2 + v3;
 v1 = v2 - v3;
@@ -16,8 +17,8 @@ void test2a()
 v1 = v2 ^ v3;
 static assert(!__traits(compiles, v1 ~ v2));
 static assert(!__traits(compiles, v1 ^^ v2));
-static assert(!__traits(compiles, v1 is v2));
-static assert(!__traits(compiles, v1 !is v2));
+b1 = v1 is v2;
+b1 = v1 !is v2;
 static assert( __traits(compiles, v1 == v2));
 static assert( __traits(compiles, v1 != v2));
 static assert( __traits(compiles, v1 < v2));
diff --git a/gcc/testsuite/gdc.dg/simd2b.d b/gcc/testsuite/gdc.dg/simd2b.d
index e72da0d9b77..a1b2a10caaf 100644
--- a/gcc/testsuite/gdc.dg/simd2b.d
+++ b/gcc/testsuite/gdc.dg/simd2b.d
@@ -5,6 +5,7 @@ import core.simd;
 void test2b()
 {
 ubyte16 v1, v2 = 1, v3 = 1;
+bool b1;
 v1 = v2;
 v1 = v2 + v3;
 v1 = v2 - v3;
@@ -16,8 +17,8 @@ void test2b()
 v1 = v2 ^ v3;
 static assert(!__traits(compiles, v1 ~ v2));
 static assert(!__traits(compiles, v1 ^^ v2));
-static assert(!__traits(compiles, v1 is v2));
-static assert(!__traits(compiles, v1 !is v2));
+b1 = v1 is v2;
+b1 = v1 !is v2;
 static assert( __traits(compiles, v1 == v2));
 static assert( __traits(compiles, v1 != v2));
 static assert( __traits(compiles, 

[committed] d: Add test for PR d/108167 to the testsuite [PR108167]

2023-03-02 Thread Iain Buclaw via Gcc-patches
Hi,

This patch adds the test for checking PR108167.  The D front-end
implementation got fixed in upstream, add test to the gdc testsuite to
check we don't regress on it.

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

Regards,
Iain.

---
PR d/108167

gcc/testsuite/ChangeLog:

* gdc.dg/pr108167.d: New test.
---
 gcc/testsuite/gdc.dg/pr108167.d | 5 +
 1 file changed, 5 insertions(+)
 create mode 100644 gcc/testsuite/gdc.dg/pr108167.d

diff --git a/gcc/testsuite/gdc.dg/pr108167.d b/gcc/testsuite/gdc.dg/pr108167.d
new file mode 100644
index 000..1337a494171
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr108167.d
@@ -0,0 +1,5 @@
+// { dg-do compile }
+auto pr108167(const(ubyte[32])[] a)
+{
+return cast(const(ubyte)*)[1][0];
+}
-- 
2.37.2



[committed] d: Only handle the left-to-right evaluation of a call expression during gimplify

2023-02-21 Thread Iain Buclaw via Gcc-patches
This patch removes an unnecessary rewriting of the front-end AST during
lowering. As all functions regardless of their linkage are evaluated
strictly left-to-right now, there's no point trying to handle all temp
saving during the code generation pass.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* d-codegen.cc (d_build_call): Remove front-end expansion of
side-effects in a call expression.
* d-gimplify.cc (d_gimplify_call_expr): Gimplify the callee before its
arguments.
---
 gcc/d/d-codegen.cc  | 29 +++--
 gcc/d/d-gimplify.cc |  9 +
 2 files changed, 12 insertions(+), 26 deletions(-)

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 920b45d0480..0e8e07366ee 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -2172,7 +2172,6 @@ d_build_call (TypeFunction *tf, tree callable, tree 
object,
 
   /* Build the argument list for the call.  */
   vec  *args = NULL;
-  tree saved_args = NULL_TREE;
   bool noreturn_call = false;
 
   /* If this is a delegate call or a nested function being called as
@@ -2182,23 +2181,6 @@ d_build_call (TypeFunction *tf, tree callable, tree 
object,
 
   if (arguments)
 {
-  /* First pass, evaluated expanded tuples in function arguments.  */
-  for (size_t i = 0; i < arguments->length; ++i)
-   {
-   Lagain:
- Expression *arg = (*arguments)[i];
- gcc_assert (arg->op != EXP::tuple);
-
- if (arg->op == EXP::comma)
-   {
- CommaExp *ce = arg->isCommaExp ();
- tree tce = build_expr (ce->e1);
- saved_args = compound_expr (saved_args, tce);
- (*arguments)[i] = ce->e2;
- goto Lagain;
-   }
-   }
-
   const size_t nparams = tf->parameterList.length ();
   /* if _arguments[] is the first argument.  */
   const size_t varargs = tf->isDstyleVariadic ();
@@ -2257,17 +2239,12 @@ d_build_call (TypeFunction *tf, tree callable, tree 
object,
}
 }
 
-  /* Evaluate the callee before calling it.  */
-  if (TREE_SIDE_EFFECTS (callee))
-{
-  callee = d_save_expr (callee);
-  saved_args = compound_expr (callee, saved_args);
-}
-
   /* If we saw a `noreturn` parameter, any unreachable argument evaluations
  after it are discarded, as well as the function call itself.  */
   if (noreturn_call)
 {
+  tree saved_args = NULL_TREE;
+
   if (TREE_SIDE_EFFECTS (callee))
saved_args = compound_expr (callee, saved_args);
 
@@ -2297,7 +2274,7 @@ d_build_call (TypeFunction *tf, tree callable, tree 
object,
   result = force_target_expr (result);
 }
 
-  return compound_expr (saved_args, result);
+  return result;
 }
 
 /* Build and return the correct call to fmod depending on TYPE.
diff --git a/gcc/d/d-gimplify.cc b/gcc/d/d-gimplify.cc
index 4072a3d92cf..04cb631244c 100644
--- a/gcc/d/d-gimplify.cc
+++ b/gcc/d/d-gimplify.cc
@@ -162,6 +162,15 @@ d_gimplify_call_expr (tree *expr_p, gimple_seq *pre_p)
   if (!has_side_effects)
 return GS_UNHANDLED;
 
+  /* Evaluate the callee before calling it.  */
+  tree new_call_fn = CALL_EXPR_FN (*expr_p);
+
+  if (gimplify_expr (_call_fn, pre_p, NULL,
+is_gimple_call_addr, fb_rvalue) == GS_ERROR)
+return GS_ERROR;
+
+  CALL_EXPR_FN (*expr_p) = new_call_fn;
+
   /* Leave the last argument for gimplify_call_expr.  */
   for (int i = 0; i < nargs - 1; i++)
 {
-- 
2.37.2



[committed] d: Set doing_semantic_analysis_p before calling functionSemantic3

2023-02-21 Thread Iain Buclaw via Gcc-patches
Hi,

This patch fixes a problem seen where functions which have semantic
analysis ran late may still require the use of CTFE built-ins to be
evaluated.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* decl.cc (DeclVisitor::visit (FuncDeclaration *)): Set
doing_semantic_analysis_p before calling functionSemantic3.

gcc/testsuite/ChangeLog:

* gdc.dg/ctfeintrinsics.d: New test.
---
 gcc/d/decl.cc |  4 ++
 gcc/testsuite/gdc.dg/ctfeintrinsics.d | 53 +++
 2 files changed, 57 insertions(+)
 create mode 100644 gcc/testsuite/gdc.dg/ctfeintrinsics.d

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 2bece96f26e..990ac4016b8 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -829,8 +829,12 @@ public:
 /* Ensure all semantic passes have run.  */
 if (d->semanticRun < PASS::semantic3)
   {
+   gcc_assert (!doing_semantic_analysis_p);
+
+   doing_semantic_analysis_p = true;
d->functionSemantic3 ();
Module::runDeferredSemantic3 ();
+   doing_semantic_analysis_p = false;
   }
 
 if (global.errors)
diff --git a/gcc/testsuite/gdc.dg/ctfeintrinsics.d 
b/gcc/testsuite/gdc.dg/ctfeintrinsics.d
new file mode 100644
index 000..0e5592b9b1a
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/ctfeintrinsics.d
@@ -0,0 +1,53 @@
+// { dg-do compile { target d_runtime_has_std_library } }
+
+//
+// std.math.exponential
+import std.math.exponential;
+
+enum test_exp = exp(1.0L);
+enum test_expm1 = expm1(1.0L);
+enum test_exp2 = exp2(1.0L);
+enum test_log = log(1.0L);
+enum test_log2 = log2(1.0L);
+enum test_log10 = log10(1.0L);
+enum test_pow = pow(1.0L, 1L);
+enum test_powi = pow(1L, 1L);
+enum test_powf = pow(1L, 1.0L);
+enum test_powl = pow(1.0L, 1.0L);
+
+//
+// std.math.operations
+import std.math.operations;
+
+enum test_fmin = fmin(1.0L, 2.0L);
+enum test_fmax = fmax(1.0L, 2.0L);
+enum test_fma = fma(1.0L, 2.0L, 3.0L);
+
+//
+// std.math.rounding
+import std.math.rounding;
+
+enum test_round = round(12.34L);
+enum test_floorf = floor(12.34f);
+enum test_floor = floor(12.34);
+enum test_floorl = floor(12.34L);
+enum test_ceilf = ceil(12.34f);
+enum test_ceil = ceil(12.34);
+enum test_ceill = ceil(12.34L);
+enum test_trunc = trunc(12.34L);
+
+//
+// std.math.traits
+import std.math.traits;
+
+enum test_isNaN = isNaN(real.nan);
+enum test_isInfinity = isInfinity(real.infinity);
+enum test_isFinite = isFinite(1.0L);
+enum test_copysign = copysign(1.0L, -1.0L);
+enum test_copysigni = copysign(1L, -1.0L);
+
+//
+// std.math.trigonometry
+import std.math.trigonometry;
+
+enum test_tan = tan(1.0L);
-- 
2.37.2



[committed] libphobos: Add @nogc to gcc.backtrace and gcc.libbacktrace modules.

2023-02-21 Thread Iain Buclaw via Gcc-patches
Hi,

This patch annotated the LibBacktrace class and the libbacktrace C
bindings it uses with `@nogc' in preparation for a `Throwable.TraceInfo'
becoming `@nogc' itself.

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

Regards,
Iain.

---
libphobos/ChangeLog:

* libdruntime/gcc/backtrace.d (simpleErrorCallback): Add @nogc.
(LibBacktrace.initLibBacktrace): Likewise.
(LibBacktrace.this): Likewise.
(UnwindBacktrace.this): Likewise.
(getBacktrace): Likewise.
(getBacktraceSymbols): Likewise.
* libdruntime/gcc/libbacktrace.d.in (backtrace_create_state):
Likewise.
(backtrace_full): Likewise.
(backtrace_simple): Likewise.
(backtrace_print): Likewise.
(backtrace_pcinfo): Likewise.
(backtrace_syminfo): Likewise.
---
 libphobos/libdruntime/gcc/backtrace.d   | 12 ++--
 libphobos/libdruntime/gcc/libbacktrace.d.in | 12 ++--
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/libphobos/libdruntime/gcc/backtrace.d 
b/libphobos/libdruntime/gcc/backtrace.d
index eeaf0783e96..2b4a339e721 100644
--- a/libphobos/libdruntime/gcc/backtrace.d
+++ b/libphobos/libdruntime/gcc/backtrace.d
@@ -46,7 +46,7 @@ static if (BACKTRACE_SUPPORTED && !BACKTRACE_USES_MALLOC)
 /*
  * Used for backtrace_create_state and backtrace_simple
  */
-extern(C) void simpleErrorCallback(void* data, const(char)* msg, int 
errnum)
+extern(C) void simpleErrorCallback(void* data, const(char)* msg, int 
errnum) @nogc
 {
 if (data) // context is not available in backtrace_create_state
 {
@@ -187,7 +187,7 @@ static if (BACKTRACE_SUPPORTED && !BACKTRACE_USES_MALLOC)
 // FIXME: state is never freed as libbacktrace doesn't provide a free 
function...
 public class LibBacktrace : Throwable.TraceInfo
 {
-static void initLibBacktrace()
+static void initLibBacktrace() @nogc
 {
 if (!initialized)
 {
@@ -196,7 +196,7 @@ static if (BACKTRACE_SUPPORTED && !BACKTRACE_USES_MALLOC)
 }
 }
 
-this(int firstFrame)
+this(int firstFrame) @nogc
 {
 _firstFrame = firstFrame;
 
@@ -345,7 +345,7 @@ else
  */
 public class UnwindBacktrace : Throwable.TraceInfo
 {
-this(int firstFrame)
+this(int firstFrame) @nogc
 {
 _firstFrame = firstFrame;
 _callstack = getBacktrace();
@@ -436,14 +436,14 @@ private:
 return _URC_NO_REASON;
 }
 
-UnwindBacktraceData getBacktrace()
+UnwindBacktraceData getBacktrace() @nogc
 {
 UnwindBacktraceData stackframe;
 _Unwind_Backtrace(, );
 return stackframe;
 }
 
-BTSymbolData getBacktraceSymbols(UnwindBacktraceData data)
+BTSymbolData getBacktraceSymbols(UnwindBacktraceData data) @nogc
 {
 BTSymbolData symData;
 
diff --git a/libphobos/libdruntime/gcc/libbacktrace.d.in 
b/libphobos/libdruntime/gcc/libbacktrace.d.in
index 96382e1f7f3..def017d155b 100644
--- a/libphobos/libdruntime/gcc/libbacktrace.d.in
+++ b/libphobos/libdruntime/gcc/libbacktrace.d.in
@@ -46,28 +46,28 @@ extern(C):
 backtrace_error_callback;
 
 backtrace_state* backtrace_create_state(const(char)* filename, int 
threaded,
-backtrace_error_callback 
error_callback, void* data) nothrow;
+backtrace_error_callback 
error_callback, void* data) @nogc nothrow;
 
 alias extern(C) int function(void* data, uintptr_t pc, const(char)* 
filename, int lineno, const(char)* func)
 backtrace_full_callback;
 
 int backtrace_full(backtrace_state* state, int skip, 
backtrace_full_callback callback,
-   backtrace_error_callback error_callback, void* data) 
nothrow;
+   backtrace_error_callback error_callback, void* data) 
@nogc nothrow;
 
 alias extern(C) int function(void* data, uintptr_t pc)
 backtrace_simple_callback;
 
 int backtrace_simple(backtrace_state* state, int skip, 
backtrace_simple_callback callback,
- backtrace_error_callback error_callback, void* data) 
nothrow;
+ backtrace_error_callback error_callback, void* data) 
@nogc nothrow;
 
-void backtrace_print(backtrace_state* state, int skip, FILE* file) nothrow;
+void backtrace_print(backtrace_state* state, int skip, FILE* file) @nogc 
nothrow;
 
 int backtrace_pcinfo(backtrace_state* state, uintptr_t pc, 
backtrace_full_callback callback,
- backtrace_error_callback error_callback,void* 
data) nothrow;
+ backtrace_error_callback error_callback,void* 
data) @nogc nothrow;
 
 alias extern(C) void function(void* data, uintptr_t pc, const(char)* 
symname, uintptr_t symval)
 backtrace_syminfo_callback;
 
 int 

Re: [PATCH 3/7] **/*.texi: Reorder index entries

2023-01-27 Thread Iain Buclaw via Gcc-patches
Excerpts from Arsen Arsenović via Gcc-patches's message of Januar 27, 2023 1:18 
am:
> 
> gcc/d/ChangeLog:
> 
>   * implement-d.texi: Reorder index entries around @items.
> 
> ---
>  gcc/d/implement-d.texi  |  66 ++---
> 
> diff --git a/gcc/d/implement-d.texi b/gcc/d/implement-d.texi
> index 6d0c1ec3661..89a17916a83 100644
> --- a/gcc/d/implement-d.texi
> +++ b/gcc/d/implement-d.texi
> @@ -126,11 +126,11 @@ The following attributes are supported on most targets.
> 

Don't have much to comment on the D-specific documentation changes,
other than seems reasonable to me.

OK.

Iain.


Re: [PATCH v2] IBM zSystems: Fix TARGET_D_CPU_VERSIONS

2023-01-24 Thread Iain Buclaw via Gcc-patches
Excerpts from Stefan Schulze Frielinghaus's message of Januar 24, 2023 9:47 am:
> In the context of D the interpretation of S390, S390X, and SystemZ is a
> bit fuzzy.  The wording S390X was wrongly deprecated in favour of
> SystemZ by commit
> https://github.com/dlang/dlang.org/commit/3b50a4c3faf01c32234d0ef8be5f82915a61c23f
> Thus, SystemZ is used for 64-bit targets, now, and S390 for 31-bit
> targets.  However, in TARGET_D_CPU_VERSIONS depending on TARGET_ZARCH we
> set the CPU version to SystemZ.  This is also the case if compiled for
> 31-bit targets leading to the following error:
> 
> libphobos/libdruntime/core/sys/posix/sys/stat.d:967:13: error: static assert: 
>  '96u == 144u' is false
>   967 | static assert(stat_t.sizeof == 144);
>   | ^
> 
> Thus in order to keep this patch simple I went for keeping SystemZ for
> 64-bit targets and S390, as usual, for 31-bit targets and dropped the
> distinction between ESA and z/Architecture.
> 
> Bootstrapped and regtested on IBM zSystems.  Ok for mainline?
> 

OK.


Re: Ping^3: [PATCH] d: Update __FreeBSD_version values [PR107469]

2023-01-23 Thread Iain Buclaw via Gcc-patches
Excerpts from Lorenzo Salvadore's message of Januar 10, 2023 5:10 pm:
> Hello,
> 
> Ping https://gcc.gnu.org/pipermail/gcc-patches/2022-November/605685.html
> 
> I would like to remind that Gerald Pfeifer already volunteered to commit this 
> patch
> when it is approved. However the patch has not been approved yet.
> 

Hi, sorry for belated reply.

Yes is fine for now, I'm concerned that it'll just be the same again
come FreeBSD 15, 16, 17...

There needs to be a better mechanism to determine which FreeBSD version
is being compiled for, but that shouldn't block this going in.

OK.



Re: [PATCH] IBM zSystems: Fix TARGET_D_CPU_VERSIONS

2023-01-23 Thread Iain Buclaw via Gcc-patches
Excerpts from Stefan Schulze Frielinghaus via Gcc-patches's message of Januar 
13, 2023 6:54 pm:
> In the context of D the interpretation of S390, S390X, and SystemZ is a
> bit fuzzy.  The wording S390X was wrongly deprecated in favour of
> SystemZ by commit
> https://github.com/dlang/dlang.org/commit/3b50a4c3faf01c32234d0ef8be5f82915a61c23f
> Thus, SystemZ is used for 64-bit targets, now, and S390 for 31-bit
> targets.  However, in TARGET_D_CPU_VERSIONS depending on TARGET_ZARCH we
> set the CPU version to SystemZ.  This is also the case if compiled for
> 31-bit targets leading to the following error:
> 
> libphobos/libdruntime/core/sys/posix/sys/stat.d:967:13: error: static assert: 
>  '96u == 144u' is false
>   967 | static assert(stat_t.sizeof == 144);
>   | ^
> 

So that I follow, there are three possible combinations?

ESA 31-bit (S390)
ESA 64-bit (what was S390X)
z/Arch 64-bit (SystemZ)

> Thus in order to keep this patch simple I went for keeping SystemZ for
> 64-bit targets and S390, as usual, for 31-bit targets and dropped the
> distinction between ESA and z/Architecture.
> 
> Bootstrapped and regtested on IBM zSystems.  Ok for mainline?
> 

OK by me.  Maybe keep both S390X and SystemZ for TARGET_64BIT? There's
only ever been a binary distinction as far as I'm aware.

Iain.


Re: Add '-Wno-complain-wrong-lang', and use it in 'gcc/testsuite/lib/target-supports.exp:check_compile' and elsewhere (was: Make '-frust-incomplete-and-experimental-compiler-do-not-use' a 'Common' opt

2022-12-16 Thread Iain Buclaw via Gcc-patches
Excerpts from Thomas Schwinge's message of Dezember 16, 2022 3:10 pm:
> 
> In the test suites, a number of existing test cases explicitly match the
> "command-line option [...] is valid for [...] but not for [...]"
> diagnostic with 'dg-warning'; I've left those alone.  On the other hand,
> I've changed 'dg-prune-output' of this diagnostic into
> '-Wno-complain-wrong-lang' usage.  I'm happy to adjust that in either way
> anyone may prefer.  I've not looked for test cases that just to silence
> this diagnostic use more general 'dg-prune-output', 'dg-excess-errors',
> '-w', etc.
> 
> In the GCC/D test suite, I see a number of:
> 
> cc1plus: warning: command-line option '-fpreview=in' is valid for D but 
> not for C++
> 
> cc1plus: warning: command-line option '-fextern-std=c++11' is valid for D 
> but not for C++
> 
> It's not clear to me how they, despite this, do achieve
> 'PASS: [...] (test for excess errors)'?  Maybe I haven't found where that
> gets pruned/ignored?
> 

There's an implicit dg-prune-output inserted by the gdc-convert-test
proc. As the only tests that mix C++ and D sources is the runnable_cxx
part of the testsuite, I can add the flag to the D2 testsuite scripts
later just for those tests.

Iain.


Re: Make '-frust-incomplete-and-experimental-compiler-do-not-use' a 'Common' option (was: Rust front-end patches v4)

2022-12-15 Thread Iain Buclaw via Gcc-patches
Excerpts from Jakub Jelinek via Gcc-patches's message of Dezember 15, 2022 
12:16 pm:
> We seem to have a problem in other testsuites too:
> grep ' valid for .*but not for' */*.log | sort -u
> gcc/gcc.log:/home/jakub/src/gcc/gcc/testsuite/gcc.dg/pragma-diag-6.c:2:30: 
> warning: option '-Wnoexcept' is valid for C++/ObjC++ but not for C [-Wpragmas]
> gdc/gdc.log:cc1plus: warning: command-line option '-fextern-std=c++11' is 
> valid for D but not for C++
> gdc/gdc.log:cc1plus: warning: command-line option '-fpreview=in' is valid for 
> D but not for C++
> gfortran/gfortran.log:cc1: warning: command-line option '-fcheck=all' is 
> valid for Fortran but not for C
> g++/g++.log:cc1: warning: command-line option '-nostdinc++' is valid for 
> C++/ObjC++ but not for C
> g++/g++.log:cc1: warning: command-line option '-std=gnu++11' is valid for 
> C++/ObjC++ but not for C
> g++/g++.log:cc1: warning: command-line option '-std=gnu++14' is valid for 
> C++/ObjC++ but not for C
> g++/g++.log:cc1: warning: command-line option '-std=gnu++17' is valid for 
> C++/ObjC++ but not for C
> g++/g++.log:cc1: warning: command-line option '-std=gnu++20' is valid for 
> C++/ObjC++ but not for C
> g++/g++.log:cc1: warning: command-line option '-std=gnu++23' is valid for 
> C++/ObjC++ but not for C
> g++/g++.log:cc1: warning: command-line option '-std=gnu++98' is valid for 
> C++/ObjC++ but not for C
> rust/rust.log:cc1plus: warning: command-line option 
> '-frust-incomplete-and-experimental-compiler-do-not-use' is valid for Rust 
> but not for C++
> rust/rust.log:cc1: warning: command-line option 
> '-frust-incomplete-and-experimental-compiler-do-not-use' is valid for Rust 
> but not for C
> (of course, some of them could be from tests that this valid for but not for
> messages work right, that is clearly the case of pragma-diag-6.c).
> 
> In gcc/testsuite/lib/target-supports.exp (check_compile) we already
> determine extension for the check_compile snippet based on magic comments
> with default to .c (Rust nor Modula 2 don't have any, should that be
> changed?), shouldn't we at that point based on the language filter out
> known options that will not work?
> 
> So, given the above, at least when in gdc testsuite and language is
> not D filter out -fextern-std=* and -fpreview=in, for gfortran testsuite
> and language not Fortran filter out -fcheck=all, when in g++ testsuite and
> language is not C++ filter out -nostdinc++, -std=gnu++* and when
> in rust testsuite and language is not Rust filter out
> -frust-incomplete-and-experimental-compiler-do-not-use ?
> 

For the gdc testsuite, those warnings arise because both language files
are compiled in the same invocation (dg-additional-sources "cpp11.cpp"),
so it ends up looking something like:

gdc -fextern-std=c++11 testcpp11.d cpp11.cpp -o testcpp11.exe

So ruling out some sort of filtering done by the gdc driver when
delegating calls to the C/C++/D language compilers, is there a way to
get dejagnu to compile dg-additional-sources one-at-a-time?

Iain.


[GCC-10][committed] libphobos: Fix std.path.expandTilde raising onOutOfMemory

2022-12-13 Thread Iain Buclaw via Gcc-patches
Hi,

This patch backports from mainline a fix for std.path.expandTilde
erroneously raising onOutOfMemory after failed call to `getpwnam_r()'.

Regression tested on x86_64-linux-gnu/-m32/-mx32, committed to
releases/gcc-10 branch.

Regards,
Iain.

---
libphobos/ChangeLog:

* src/std/path.d (expandTilde): Handle more errno codes that could be
left set by getpwnam_r.
---
 libphobos/src/std/path.d | 23 ++-
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/libphobos/src/std/path.d b/libphobos/src/std/path.d
index 4a435efba6c..d250953ee1c 100644
--- a/libphobos/src/std/path.d
+++ b/libphobos/src/std/path.d
@@ -3850,7 +3850,7 @@ string expandTilde(string inputPath) nothrow
 version (Posix)
 {
 import core.exception : onOutOfMemoryError;
-import core.stdc.errno : errno, ERANGE;
+import core.stdc.errno : errno, EBADF, ENOENT, EPERM, ERANGE, ESRCH;
 import core.stdc.stdlib : malloc, free, realloc;
 
 /*  Joins a path from a C string to the remainder of path.
@@ -3950,7 +3950,7 @@ string expandTilde(string inputPath) nothrow
 scope(exit) free(extra_memory);
 
 passwd result;
-while (1)
+loop: while (1)
 {
 extra_memory = cast(char*) realloc(extra_memory, 
extra_memory_size * char.sizeof);
 if (extra_memory == null)
@@ -3969,10 +3969,23 @@ string expandTilde(string inputPath) nothrow
 break;
 }
 
-if (errno != ERANGE &&
+switch (errno)
+{
+case ERANGE:
 // On BSD and OSX, errno can be left at 0 instead of 
set to ERANGE
-errno != 0)
-onOutOfMemoryError();
+case 0:
+break;
+
+case ENOENT:
+case ESRCH:
+case EBADF:
+case EPERM:
+// The given name or uid was not found.
+break loop;
+
+default:
+onOutOfMemoryError();
+}
 
 // extra_memory isn't large enough
 import core.checkedint : mulu;
-- 
2.37.2



[GCC-11][committed] libphobos: Backport library and bindings fixes from mainline

2022-12-13 Thread Iain Buclaw via Gcc-patches
Hi,

This patch backports some fixes for the libphobos library from mainline
that fix build and testsuite failures.

Regression tested on x86_64-linux-gnu/-m32/-mx32, committed to
releases/gcc-11 branch.

D Runtime changes:

- Fix MIPS64 bindings for CRuntime_UClibc.

Phobos changes:

- Fix std.path.expandTilde erroneously raising onOutOfMemory
  after failed call to getpwnam_r().
- Use GENERIC_IO on CRuntime_UClibc port of std.stdio.

libphobos/ChangeLog:

* libdruntime/core/stdc/fenv.d: Compile in MIPS uClibc bindings on
MIPS_Any targets.
* libdruntime/core/stdc/math.d: Likewise.
* libdruntime/core/sys/posix/dlfcn.d: Likewise.
* libdruntime/core/sys/posix/setjmp.d: Add MIPS64 definitions for
CRuntime_UClibc.
* libdruntime/core/sys/posix/sys/types.d: Likewise.
* src/std/path.d (expandTilde): Handle more errno codes that could be
left set by getpwnam_r.
* src/std/stdio.d: Set CRuntime_UClibc as GENERIC_IO target.
---
 libphobos/libdruntime/core/stdc/fenv.d|  2 +-
 libphobos/libdruntime/core/stdc/math.d|  2 +-
 libphobos/libdruntime/core/sys/posix/dlfcn.d  |  2 +-
 libphobos/libdruntime/core/sys/posix/setjmp.d | 16 +
 .../libdruntime/core/sys/posix/sys/types.d| 12 ++
 libphobos/src/std/path.d  | 23 +++
 libphobos/src/std/stdio.d |  3 +--
 7 files changed, 50 insertions(+), 10 deletions(-)

diff --git a/libphobos/libdruntime/core/stdc/fenv.d 
b/libphobos/libdruntime/core/stdc/fenv.d
index 3002c022613..665f383167d 100644
--- a/libphobos/libdruntime/core/stdc/fenv.d
+++ b/libphobos/libdruntime/core/stdc/fenv.d
@@ -481,7 +481,7 @@ else version (CRuntime_UClibc)
 
 alias fexcept_t = ushort;
 }
-else version (MIPS32)
+else version (MIPS_Any)
 {
 struct fenv_t
 {
diff --git a/libphobos/libdruntime/core/stdc/math.d 
b/libphobos/libdruntime/core/stdc/math.d
index 2de6e579575..2a965444f2c 100644
--- a/libphobos/libdruntime/core/stdc/math.d
+++ b/libphobos/libdruntime/core/stdc/math.d
@@ -113,7 +113,7 @@ else version (CRuntime_UClibc)
 ///
 enum int FP_ILOGBNAN  = int.min;
 }
-else version (MIPS32)
+else version (MIPS_Any)
 {
 ///
 enum int FP_ILOGB0= -int.max;
diff --git a/libphobos/libdruntime/core/sys/posix/dlfcn.d 
b/libphobos/libdruntime/core/sys/posix/dlfcn.d
index f6476ec3106..ff24896cdb6 100644
--- a/libphobos/libdruntime/core/sys/posix/dlfcn.d
+++ b/libphobos/libdruntime/core/sys/posix/dlfcn.d
@@ -316,7 +316,7 @@ else version (CRuntime_UClibc)
 enum RTLD_LOCAL = 0;
 enum RTLD_NODELETE  = 0x01000;
 }
-else version (MIPS32)
+else version (MIPS_Any)
 {
 enum RTLD_LAZY  = 0x0001;
 enum RTLD_NOW   = 0x0002;
diff --git a/libphobos/libdruntime/core/sys/posix/setjmp.d 
b/libphobos/libdruntime/core/sys/posix/setjmp.d
index b98d321a883..547e52e8edc 100644
--- a/libphobos/libdruntime/core/sys/posix/setjmp.d
+++ b/libphobos/libdruntime/core/sys/posix/setjmp.d
@@ -366,6 +366,22 @@ else version (CRuntime_UClibc)
 double[6] __fpregs;
 }
 }
+else version (MIPS64)
+{
+struct __jmp_buf
+{
+long __pc;
+long __sp;
+long[8] __regs;
+long __fp;
+long __gp;
+int __fpc_csr;
+version (MIPS_N64)
+double[8] __fpregs;
+else
+double[6] __fpregs;
+}
+}
 else
 static assert(0, "unimplemented");
 
diff --git a/libphobos/libdruntime/core/sys/posix/sys/types.d 
b/libphobos/libdruntime/core/sys/posix/sys/types.d
index abcea99019f..529df1bae82 100644
--- a/libphobos/libdruntime/core/sys/posix/sys/types.d
+++ b/libphobos/libdruntime/core/sys/posix/sys/types.d
@@ -1277,6 +1277,18 @@ else version (CRuntime_UClibc)
 enum __SIZEOF_PTHREAD_BARRIER_T = 20;
 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4;
  }
+ else version (MIPS64)
+ {
+enum __SIZEOF_PTHREAD_ATTR_T= 56;
+enum __SIZEOF_PTHREAD_MUTEX_T   = 40;
+enum __SIZEOF_PTHREAD_MUTEXATTR_T   = 4;
+enum __SIZEOF_PTHREAD_COND_T= 48;
+enum __SIZEOF_PTHREAD_CONDATTR_T= 4;
+enum __SIZEOF_PTHREAD_RWLOCK_T  = 56;
+enum __SIZEOF_PTHREAD_RWLOCKATTR_T  = 8;
+enum __SIZEOF_PTHREAD_BARRIER_T = 32;
+enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4;
+ }
  else version (ARM)
  {
 enum __SIZEOF_PTHREAD_ATTR_T = 36;
diff --git a/libphobos/src/std/path.d b/libphobos/src/std/path.d
index 4a435efba6c..d250953ee1c 100644
--- a/libphobos/src/std/path.d
+++ b/libphobos/src/std/path.d
@@ -3850,7 +3850,7 @@ string expandTilde(string inputPath) nothrow
 version (Posix)
 {
 

[GCC-12][committed] libphobos: Backport library and bindings fixes from mainline

2022-12-13 Thread Iain Buclaw via Gcc-patches
Hi,

This patch backports some fixes for the libphobos library from mainline
that fix build and testsuite failures.

Regression tested on x86_64-linux-gnu/-m32/-mx32, committed to
releases/gcc-12 branch.

D Runtime changes:

- Fix MIPS64 bindings for CRuntime_UClibc.

Phobos changes:

- Fix std.path.expandTilde erroneously raising onOutOfMemory
  after failed call to getpwnam_r().
- Fix std.random unittest failures on ILP32 targets.
- Use GENERIC_IO on CRuntime_UClibc port of std.stdio.

libphobos/ChangeLog:

* libdruntime/core/stdc/fenv.d: Compile in MIPS uClibc bindings on
MIPS_Any targets.
* libdruntime/core/stdc/math.d: Likewise.
* libdruntime/core/sys/posix/dlfcn.d: Likewise.
* libdruntime/core/sys/posix/setjmp.d: Add MIPS64 definitions for
CRuntime_UClibc.
* libdruntime/core/sys/posix/sys/types.d: Likewise.
* src/std/path.d (expandTilde): Handle more errno codes that could be
left set by getpwnam_r.
* src/std/random.d: Use D_LP64 in unittests.
* src/std/stdio.d: Set CRuntime_UClibc as GENERIC_IO target.
---
 libphobos/libdruntime/core/stdc/fenv.d|  2 +-
 libphobos/libdruntime/core/stdc/math.d|  2 +-
 libphobos/libdruntime/core/sys/posix/dlfcn.d  |  2 +-
 libphobos/libdruntime/core/sys/posix/setjmp.d | 16 +
 .../libdruntime/core/sys/posix/sys/types.d| 12 ++
 libphobos/src/std/path.d  | 23 +++
 libphobos/src/std/random.d| 14 +--
 libphobos/src/std/stdio.d |  3 +--
 8 files changed, 57 insertions(+), 17 deletions(-)

diff --git a/libphobos/libdruntime/core/stdc/fenv.d 
b/libphobos/libdruntime/core/stdc/fenv.d
index 88123fb16a6..5242ba9d4e2 100644
--- a/libphobos/libdruntime/core/stdc/fenv.d
+++ b/libphobos/libdruntime/core/stdc/fenv.d
@@ -483,7 +483,7 @@ else version (CRuntime_UClibc)
 
 alias fexcept_t = ushort;
 }
-else version (MIPS32)
+else version (MIPS_Any)
 {
 struct fenv_t
 {
diff --git a/libphobos/libdruntime/core/stdc/math.d 
b/libphobos/libdruntime/core/stdc/math.d
index 0393ea52c07..51fd68f9fc3 100644
--- a/libphobos/libdruntime/core/stdc/math.d
+++ b/libphobos/libdruntime/core/stdc/math.d
@@ -120,7 +120,7 @@ else version (CRuntime_UClibc)
 ///
 enum int FP_ILOGBNAN  = int.min;
 }
-else version (MIPS32)
+else version (MIPS_Any)
 {
 ///
 enum int FP_ILOGB0= -int.max;
diff --git a/libphobos/libdruntime/core/sys/posix/dlfcn.d 
b/libphobos/libdruntime/core/sys/posix/dlfcn.d
index a9519ca234a..24fa3787ec4 100644
--- a/libphobos/libdruntime/core/sys/posix/dlfcn.d
+++ b/libphobos/libdruntime/core/sys/posix/dlfcn.d
@@ -387,7 +387,7 @@ else version (CRuntime_UClibc)
 enum RTLD_LOCAL = 0;
 enum RTLD_NODELETE  = 0x01000;
 }
-else version (MIPS32)
+else version (MIPS_Any)
 {
 enum RTLD_LAZY  = 0x0001;
 enum RTLD_NOW   = 0x0002;
diff --git a/libphobos/libdruntime/core/sys/posix/setjmp.d 
b/libphobos/libdruntime/core/sys/posix/setjmp.d
index 91e3a19d081..5a15d82d2ee 100644
--- a/libphobos/libdruntime/core/sys/posix/setjmp.d
+++ b/libphobos/libdruntime/core/sys/posix/setjmp.d
@@ -370,6 +370,22 @@ else version (CRuntime_UClibc)
 double[6] __fpregs;
 }
 }
+else version (MIPS64)
+{
+struct __jmp_buf
+{
+long __pc;
+long __sp;
+long[8] __regs;
+long __fp;
+long __gp;
+int __fpc_csr;
+version (MIPS_N64)
+double[8] __fpregs;
+else
+double[6] __fpregs;
+}
+}
 else
 static assert(0, "unimplemented");
 
diff --git a/libphobos/libdruntime/core/sys/posix/sys/types.d 
b/libphobos/libdruntime/core/sys/posix/sys/types.d
index ec229dd3b2b..3e515c4c68e 100644
--- a/libphobos/libdruntime/core/sys/posix/sys/types.d
+++ b/libphobos/libdruntime/core/sys/posix/sys/types.d
@@ -1140,6 +1140,18 @@ else version (CRuntime_UClibc)
 enum __SIZEOF_PTHREAD_BARRIER_T = 20;
 enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4;
  }
+ else version (MIPS64)
+ {
+enum __SIZEOF_PTHREAD_ATTR_T= 56;
+enum __SIZEOF_PTHREAD_MUTEX_T   = 40;
+enum __SIZEOF_PTHREAD_MUTEXATTR_T   = 4;
+enum __SIZEOF_PTHREAD_COND_T= 48;
+enum __SIZEOF_PTHREAD_CONDATTR_T= 4;
+enum __SIZEOF_PTHREAD_RWLOCK_T  = 56;
+enum __SIZEOF_PTHREAD_RWLOCKATTR_T  = 8;
+enum __SIZEOF_PTHREAD_BARRIER_T = 32;
+enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4;
+ }
  else version (ARM)
  {
 enum __SIZEOF_PTHREAD_ATTR_T = 36;
diff --git a/libphobos/src/std/path.d b/libphobos/src/std/path.d
index de180fcc548..777d8b924dd 

[committed] d: Fix undefined reference to nested lambda in template (PR108055)

2022-12-12 Thread Iain Buclaw via Gcc-patches
Hi,

This patch fixes a linker error caused by gdc not emitting all symbols.

Sometimes, nested lambdas of templated functions get no code generation
due to them being marked as instantianted outside of all modules being
compiled in the current compilation unit.  This despite enclosing
template instances being marked as instantiated inside the current
compilation unit.  To fix, all enclosing templates are now checked in
`function_defined_in_root_p'.

Because of this change, `function_needs_inline_definition_p' has also
been fixed up to only check whether the regular function definition
itself is to be emitted in the current compilation unit.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32,
committed to mainline and backported to the releases/gcc-12 branch.

Regards,
Iain.

---

PR d/108055

gcc/d/ChangeLog:

* decl.cc (function_defined_in_root_p): Check all enclosing template
instances for definition in a root module.
(function_needs_inline_definition_p): Replace call to
function_defined_in_root_p with test for outer module `isRoot'.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/imports/pr108055conv.d: New.
* gdc.dg/torture/imports/pr108055spec.d: New.
* gdc.dg/torture/imports/pr108055write.d: New.
* gdc.dg/torture/pr108055.d: New test.
---
 gcc/d/decl.cc | 14 ++
 .../gdc.dg/torture/imports/pr108055conv.d | 26 +++
 .../gdc.dg/torture/imports/pr108055spec.d | 18 +
 .../gdc.dg/torture/imports/pr108055write.d| 19 ++
 gcc/testsuite/gdc.dg/torture/pr108055.d   | 12 +
 5 files changed, 84 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/torture/imports/pr108055conv.d
 create mode 100644 gcc/testsuite/gdc.dg/torture/imports/pr108055spec.d
 create mode 100644 gcc/testsuite/gdc.dg/torture/imports/pr108055write.d
 create mode 100644 gcc/testsuite/gdc.dg/torture/pr108055.d

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index bed16323fec..35081083cd6 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -1028,7 +1028,8 @@ build_decl_tree (Dsymbol *d)
   input_location = saved_location;
 }
 
-/* Returns true if function FD is defined or instantiated in a root module.  */
+/* Returns true if function FD, or any lexically enclosing scope function of FD
+   is defined or instantiated in a root module.  */
 
 static bool
 function_defined_in_root_p (FuncDeclaration *fd)
@@ -1037,9 +1038,11 @@ function_defined_in_root_p (FuncDeclaration *fd)
   if (md && md->isRoot ())
 return true;
 
-  TemplateInstance *ti = fd->isInstantiated ();
-  if (ti && ti->minst && ti->minst->isRoot ())
-return true;
+  for (TemplateInstance *ti = fd->isInstantiated (); ti != NULL; ti = 
ti->tinst)
+{
+  if (ti->minst && ti->minst->isRoot ())
+   return true;
+}
 
   return false;
 }
@@ -1067,7 +1070,8 @@ function_needs_inline_definition_p (FuncDeclaration *fd)
 
   /* Check whether function will be regularly defined later in the current
  translation unit.  */
-  if (function_defined_in_root_p (fd))
+  Module *md = fd->getModule ();
+  if (md && md->isRoot ())
 return false;
 
   /* Non-inlineable functions are always external.  */
diff --git a/gcc/testsuite/gdc.dg/torture/imports/pr108055conv.d 
b/gcc/testsuite/gdc.dg/torture/imports/pr108055conv.d
new file mode 100644
index 000..93ebba747b1
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/imports/pr108055conv.d
@@ -0,0 +1,26 @@
+module imports.pr108055conv;
+
+T toStr(T, S)(S src)
+{
+static if (is(typeof(T.init[0]) E))
+{
+struct Appender
+{
+inout(E)[] data;
+}
+
+import imports.pr108055spec;
+import imports.pr108055write;
+
+auto w = Appender();
+FormatSpec!E f;
+formatValue(w, src, f);
+return w.data;
+}
+}
+
+T to(T, A)(A args)
+{
+return toStr!T(args);
+}
+
diff --git a/gcc/testsuite/gdc.dg/torture/imports/pr108055spec.d 
b/gcc/testsuite/gdc.dg/torture/imports/pr108055spec.d
new file mode 100644
index 000..801c5810516
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/imports/pr108055spec.d
@@ -0,0 +1,18 @@
+module imports.pr108055spec;
+
+template Unqual(T : const U, U)
+{
+alias Unqual = U;
+}
+
+template FormatSpec(Char)
+if (!is(Unqual!Char == Char))
+{
+alias FormatSpec = FormatSpec!(Unqual!Char);
+}
+
+struct FormatSpec(Char)
+if (is(Unqual!Char == Char))
+{
+const(Char)[] nested;
+}
diff --git a/gcc/testsuite/gdc.dg/torture/imports/pr108055write.d 
b/gcc/testsuite/gdc.dg/torture/imports/pr108055write.d
new file mode 100644
index 000..fe41d7baa7c
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/imports/pr108055write.d
@@ -0,0 +1,19 @@
+module imports.pr108055write;
+import imports.pr108055spec;
+
+void formatValueImpl(Writer, T, Char)(ref Writer , const(T) ,
+  scope const ref 

[GCC-12][committed] d: Remove "final" and "override" from visitor method.

2022-12-11 Thread Iain Buclaw via Gcc-patches
Hi,

This patch removes "final" and "override" from the OverloadSet visitor
method.  This was added by the backport of an ICE in r12-8969.  While
harmless, it was not until r13-758 that "final" and "override" were
introduced to all visitor methods in the D front-end.  Removing it from
the release branch just for consistency with the rest of the file.

Committed to releases/gcc-12.

Regards,
Iain.

---
gcc/d/ChangeLog:

* imports.cc (ImportVisitor::visit (OverloadSet *)): Remove "final"
and "override" from visitor method.
---
 gcc/d/imports.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/d/imports.cc b/gcc/d/imports.cc
index 4ce6f026b29..dfda2401ee8 100644
--- a/gcc/d/imports.cc
+++ b/gcc/d/imports.cc
@@ -161,7 +161,7 @@ public:
   }
 
   /* Build IMPORTED_DECLs for all overloads in a set.  */
-  void visit (OverloadSet *d) final override
+  void visit (OverloadSet *d)
   {
 vec *tset = NULL;
 
-- 
2.37.2



[committed] d: Fix internal compiler error: in visit, at d/imports.cc:72 (PR108050)

2022-12-11 Thread Iain Buclaw via Gcc-patches
Hi,

This patch fixes an ICE in the D front-end when importing symbols that
have multiple overloads.

The visitor for lowering IMPORTED_DECLs did not have an override for
dealing with importing OverloadSet symbols.  This has now been
implemented in the code generator.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32,
committed to mainline, and backported to the release branches for
gcc-10, gcc-11, and gcc-12.

Regards,
Iain.

---
PR d/108050

gcc/d/ChangeLog:

* decl.cc (DeclVisitor::visit (Import *)): Handle build_import_decl
returning a TREE_LIST.
* imports.cc (ImportVisitor::visit (OverloadSet *)): New override.

gcc/testsuite/ChangeLog:

* gdc.dg/imports/pr108050/mod1.d: New.
* gdc.dg/imports/pr108050/mod2.d: New.
* gdc.dg/imports/pr108050/package.d: New.
* gdc.dg/pr108050.d: New test.
---
 gcc/d/decl.cc   | 12 ++--
 gcc/d/imports.cc| 14 ++
 gcc/testsuite/gdc.dg/imports/pr108050/mod1.d|  2 ++
 gcc/testsuite/gdc.dg/imports/pr108050/mod2.d|  2 ++
 gcc/testsuite/gdc.dg/imports/pr108050/package.d |  2 ++
 gcc/testsuite/gdc.dg/pr108050.d |  4 
 6 files changed, 34 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/imports/pr108050/mod1.d
 create mode 100644 gcc/testsuite/gdc.dg/imports/pr108050/mod2.d
 create mode 100644 gcc/testsuite/gdc.dg/imports/pr108050/package.d
 create mode 100644 gcc/testsuite/gdc.dg/pr108050.d

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index dcfca648e44..bed16323fec 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -198,8 +198,16 @@ public:
tree name = (alias != NULL)
  ? get_identifier (alias->toChars ()) : NULL_TREE;
 
-   debug_hooks->imported_module_or_decl (decl, name, context,
- false, false);
+   if (TREE_CODE (decl) != TREE_LIST)
+ debug_hooks->imported_module_or_decl (decl, name, context,
+   false, false);
+   else
+ {
+   /* Overload sets return a list of imported decls.  */
+   for (; decl != NULL_TREE; decl = TREE_CHAIN (decl))
+ debug_hooks->imported_module_or_decl (TREE_VALUE (decl), name,
+   context, false, false);
+ }
  }
   }
 else
diff --git a/gcc/d/imports.cc b/gcc/d/imports.cc
index 133d93d4961..2d331f46c35 100644
--- a/gcc/d/imports.cc
+++ b/gcc/d/imports.cc
@@ -160,6 +160,20 @@ public:
   d->aliassym->accept (this);
   }
 
+  /* Build IMPORTED_DECLs for all overloads in a set.  */
+  void visit (OverloadSet *d) final override
+  {
+vec *tset = NULL;
+
+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]));
+
+this->result_ = build_tree_list_vec (tset);
+tset->truncate (0);
+  }
+
   /* Function aliases are the same as alias symbols.  */
   void visit (FuncAliasDeclaration *d) final override
   {
diff --git a/gcc/testsuite/gdc.dg/imports/pr108050/mod1.d 
b/gcc/testsuite/gdc.dg/imports/pr108050/mod1.d
new file mode 100644
index 000..f27a13dc051
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/imports/pr108050/mod1.d
@@ -0,0 +1,2 @@
+module imports.pr108050.mod1;
+string[] split() { return null; }
diff --git a/gcc/testsuite/gdc.dg/imports/pr108050/mod2.d 
b/gcc/testsuite/gdc.dg/imports/pr108050/mod2.d
new file mode 100644
index 000..29d8aa8f53e
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/imports/pr108050/mod2.d
@@ -0,0 +1,2 @@
+module imports.pr108050.mod2;
+string[] split() { return null; }
diff --git a/gcc/testsuite/gdc.dg/imports/pr108050/package.d 
b/gcc/testsuite/gdc.dg/imports/pr108050/package.d
new file mode 100644
index 000..b8b03b832af
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/imports/pr108050/package.d
@@ -0,0 +1,2 @@
+module imports.pr108050;
+public import imports.pr108050.mod1, imports.pr108050.mod2;
diff --git a/gcc/testsuite/gdc.dg/pr108050.d b/gcc/testsuite/gdc.dg/pr108050.d
new file mode 100644
index 000..69134e73137
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr108050.d
@@ -0,0 +1,4 @@
+// { dg-do compile }
+// { dg-additional-sources "imports/pr108050/package.d imports/pr108050/mod1.d 
imports/pr108050/mod2.d" }
+// { dg-options "-g" }
+import imports.pr108050 : split;
-- 
2.37.2



[committed] d: Expand bsr intrinsic as `clz(arg) ^ (argsize - 1)'

2022-12-11 Thread Iain Buclaw via Gcc-patches
Hi,

This patch tweaks the code expansion of the D intrinsic bsr() function.

As well as removing unnecessary casts, this results in less temporaries
being generated during the initial gimple lowering pass.  Otherwise the
code generated is identical to the former intrinsic expansion.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32.

Committed to mainline.

Regards,
Iain.

---
gcc/d/ChangeLog:

* intrinsics.cc (expand_intrinsic_bsf): Fix comment.
(expand_intrinsic_bsr): Use BIT_XOR_EXPR instead of MINUS_EXPR.
---
 gcc/d/intrinsics.cc | 17 ++---
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/gcc/d/intrinsics.cc b/gcc/d/intrinsics.cc
index 6d9f74a6d7a..46380e512c4 100644
--- a/gcc/d/intrinsics.cc
+++ b/gcc/d/intrinsics.cc
@@ -525,7 +525,7 @@ call_builtin_fn (tree callexp, built_in_function code, int 
n, ...)
 static tree
 expand_intrinsic_bsf (tree callexp)
 {
-  /* The bsr() intrinsic gets turned into __builtin_ctz(arg).
+  /* The bsf() intrinsic gets turned into __builtin_ctz(arg).
  The return value is supposed to be undefined if arg is zero.  */
   tree arg = CALL_EXPR_ARG (callexp, 0);
   int argsize = TYPE_PRECISION (TREE_TYPE (arg));
@@ -554,11 +554,11 @@ expand_intrinsic_bsf (tree callexp)
 static tree
 expand_intrinsic_bsr (tree callexp)
 {
-  /* The bsr() intrinsic gets turned into (size - 1) - __builtin_clz(arg).
+  /* The bsr() intrinsic gets turned into __builtin_clz(arg) ^ (size - 1).
  The return value is supposed to be undefined if arg is zero.  */
   tree arg = CALL_EXPR_ARG (callexp, 0);
-  tree type = TREE_TYPE (arg);
-  int argsize = TYPE_PRECISION (type);
+  tree type = TREE_TYPE (callexp);
+  int argsize = TYPE_PRECISION (TREE_TYPE (arg));
 
   /* Which variant of __builtin_clz* should we call?  */
   built_in_function code = (argsize <= INT_TYPE_SIZE) ? BUILT_IN_CLZ
@@ -570,13 +570,8 @@ expand_intrinsic_bsr (tree callexp)
 
   tree result = call_builtin_fn (callexp, code, 1, arg);
 
-  /* Handle int -> long conversions.  */
-  if (TREE_TYPE (result) != type)
-result = fold_convert (type, result);
-
-  result = fold_build2 (MINUS_EXPR, type,
-   build_integer_cst (argsize - 1, type), result);
-  return fold_convert (TREE_TYPE (callexp), result);
+  return fold_build2 (BIT_XOR_EXPR, type, result,
+ build_integer_cst (argsize - 1, type));
 }
 
 /* Expand a front-end intrinsic call to INTRINSIC, which is either a call to
-- 
2.37.2



Re: [committed] onlinedocs: Add documentation links to gdc

2022-12-07 Thread Iain Buclaw via Gcc-patches
Hi Gerald,

Excerpts from Gerald Pfeifer's message of Dezember 6, 2022 2:13 pm:
> On Tue, 6 Dec 2022, Iain Buclaw wrote:
>> Now that the D front-end documentation has been generated and pushed to
>> the site after r13-4421, this can be added to the main index page.
>> 
>> This is a simple copy from other entries, so have gone ahead and
>> committed it.
> 
> Cool, thank you. And sorry, I applied the change on the gcc.gnu.org 
> system and then missed droping you a note once it successfully ran 
> the first time.
> 
> With your web page patch, are we complete now? Or is anything missing?
> 

Looks like it's all there to me. Just need myself to write up more content.

Iain.


  1   2   3   4   5   6   7   8   9   10   >