[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



[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", f

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.


[10, committed] d: Fix error: aggregate value used where floating point was expected (PR106139)

2022-07-05 Thread Iain Buclaw via Gcc-patches
Hi,

This is the GCC-10 backport of the fix for PR106139 posted last week.

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

Regards,
Iain.

---
PR d/106139

gcc/d/ChangeLog:

* d-convert.cc (convert_expr): Handle casting from array to vector.
(convert_for_rvalue): Rewrite vector to array casts of the same
element type into a constructor.
(convert_for_assignment): Return calling convert_for_rvalue.
* dmd/expressionsem.c (ExpressionSemanticVisitor::visit): Run semantic
on vector expression after lowering.
* expr.cc (ExprVisitor::visit (VectorExp *)): Handle generating a
vector expression from a static array.

gcc/testsuite/ChangeLog:

* gdc.dg/pr106139a.d: New test.
* gdc.dg/pr106139b.d: New test.
* gdc.dg/pr106139c.d: New test.
* gdc.dg/pr106139d.d: New test.
* gdc.test/fail_compilation/ice20264.d: New test.

(cherry picked from commit 488759b7ea16972c4dfbb62926cd71996b1f77a7)
---
 gcc/d/d-convert.cc| 44 ++-
 gcc/d/dmd/expressionsem.c |  1 +
 gcc/d/expr.cc | 17 ---
 gcc/testsuite/gdc.dg/pr106139a.d  | 36 +++
 gcc/testsuite/gdc.dg/pr106139b.d  | 36 +++
 gcc/testsuite/gdc.dg/pr106139c.d  | 27 
 gcc/testsuite/gdc.dg/pr106139d.d  | 27 
 .../gdc.test/fail_compilation/ice20264.d  | 13 ++
 8 files changed, 195 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/pr106139a.d
 create mode 100644 gcc/testsuite/gdc.dg/pr106139b.d
 create mode 100644 gcc/testsuite/gdc.dg/pr106139c.d
 create mode 100644 gcc/testsuite/gdc.dg/pr106139d.d
 create mode 100644 gcc/testsuite/gdc.test/fail_compilation/ice20264.d

diff --git a/gcc/d/d-convert.cc b/gcc/d/d-convert.cc
index 87062513c33..2cfc2c8cc19 100644
--- a/gcc/d/d-convert.cc
+++ b/gcc/d/d-convert.cc
@@ -502,6 +502,15 @@ convert_expr (tree exp, Type *etype, Type *totype)
  gcc_assert (totype->size () == etype->size ());
  result = build_vconvert (build_ctype (totype), exp);
}
+  else if (tbtype->ty == Tvector && tbtype->size () == ebtype->size ())
+   {
+ /* Allow casting from array to vector as if its an unaligned load.  */
+ tree type = build_ctype (totype);
+ tree unaligned_type = build_variant_type_copy (type);
+ SET_TYPE_ALIGN (unaligned_type, 1 * BITS_PER_UNIT);
+ TYPE_USER_ALIGN (unaligned_type) = 1;
+ result = convert (type, build_vconvert (unaligned_type, exp));
+   }
   else
{
  error ("cannot cast expression of type %qs to type %qs",
@@ -634,6 +643,39 @@ convert_for_rvalue (tree expr, Type *etype, Type *totype)
   break;
 }
 
+  if (tbtype->ty == Tsarray
+  && ebtype->ty == Tsarray
+  && tbtype->nextOf ()->ty == ebtype->nextOf ()->ty
+  && INDIRECT_REF_P (expr)
+  && CONVERT_EXPR_CODE_P (TREE_CODE (TREE_OPERAND (expr, 0)))
+  && TREE_CODE (TREE_OPERAND (TREE_OPERAND (expr, 0), 0)) == ADDR_EXPR)
+{
+  /* If expression is a vector that was casted to an array either by
+explicit type cast or by taking the vector's `.array' value, strip the
+reinterpret cast and build a constructor instead.  */
+  tree ptr = TREE_OPERAND (TREE_OPERAND (expr, 0), 0);
+
+  if (VECTOR_TYPE_P (TREE_TYPE (TREE_TYPE (ptr
+   {
+ /* Rewrite: `*(Array *)&vector'
+   into: `{ vector[0], vector[1], ... }'  */
+ tree array = d_save_expr (TREE_OPERAND (ptr, 0));
+ array = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (expr), array);
+
+ uinteger_t dim = ((TypeSArray *)tbtype)->dim->toUInteger ();
+ vec  *elms = NULL;
+ for (uinteger_t i = 0; i < dim; i++)
+   {
+ tree index = size_int (i);
+ tree value = build4 (ARRAY_REF, TREE_TYPE (TREE_TYPE (array)),
+  array, index, NULL_TREE, NULL_TREE);
+ CONSTRUCTOR_APPEND_ELT (elms, index, value);
+   }
+
+ return build_constructor (build_ctype (totype), elms);
+   }
+}
+
   return result ? result : convert_expr (expr, etype, totype);
 }
 
@@ -694,7 +736,7 @@ convert_for_assignment (tree expr, Type *etype, Type 
*totype)
   return expr;
 }
 
-  return convert_expr (expr, etype, totype);
+  return convert_for_rvalue (expr, etype, totype);
 }
 
 /* Return a TREE representation of EXPR converted to represent
diff --git a/gcc/d/dmd/expressionsem.c b/gcc/d/dmd/expressionsem.c
index 5096754e55f..3c199bf1b57 100644
--- a/gcc/d/dmd/expressionsem.c
+++ b/gcc/d/dmd/expressionsem.c
@@ -4309,6 +4309,7 @@ public:
 if (tob->ty == Tvector && t1b->ty != Tvector)
 {
 result = new VectorExp(exp->loc, exp->e1, exp->to);
+result = 

[11, committed] d: Fix error: aggregate value used where floating point was expected (PR106139)

2022-07-05 Thread Iain Buclaw via Gcc-patches
Hi,

This is the GCC-11 backport of the fix for PR106139 posted last week.

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

Regards,
Iain.

---
PR d/106139

gcc/d/ChangeLog:

* d-convert.cc (convert_expr): Handle casting from array to vector.
(convert_for_rvalue): Rewrite vector to array casts of the same
element type into a constructor.
(convert_for_assignment): Return calling convert_for_rvalue.
* dmd/expressionsem.c (ExpressionSemanticVisitor::visit): Run semantic
on vector expression after lowering.
* expr.cc (ExprVisitor::visit (VectorExp *)): Handle generating a
vector expression from a static array.
* toir.cc (IRVisitor::visit (ReturnStatement *)): Call
convert_for_rvalue on return value.

gcc/testsuite/ChangeLog:

* gdc.dg/pr106139a.d: New test.
* gdc.dg/pr106139b.d: New test.
* gdc.dg/pr106139c.d: New test.
* gdc.dg/pr106139d.d: New test.
* gdc.test/fail_compilation/ice20264.d: New test.

(cherry picked from commit 329bef49da30158d30fed1106002bb71674776bd)
---
 gcc/d/d-convert.cc| 44 ++-
 gcc/d/dmd/expressionsem.c |  1 +
 gcc/d/expr.cc | 10 -
 gcc/d/toir.cc |  1 +
 gcc/testsuite/gdc.dg/pr106139a.d  | 36 +++
 gcc/testsuite/gdc.dg/pr106139b.d  | 36 +++
 gcc/testsuite/gdc.dg/pr106139c.d  | 27 
 gcc/testsuite/gdc.dg/pr106139d.d  | 27 
 .../gdc.test/fail_compilation/ice20264.d  | 13 ++
 9 files changed, 192 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/pr106139a.d
 create mode 100644 gcc/testsuite/gdc.dg/pr106139b.d
 create mode 100644 gcc/testsuite/gdc.dg/pr106139c.d
 create mode 100644 gcc/testsuite/gdc.dg/pr106139d.d
 create mode 100644 gcc/testsuite/gdc.test/fail_compilation/ice20264.d

diff --git a/gcc/d/d-convert.cc b/gcc/d/d-convert.cc
index d43485dca77..cd6551e64f3 100644
--- a/gcc/d/d-convert.cc
+++ b/gcc/d/d-convert.cc
@@ -502,6 +502,15 @@ convert_expr (tree exp, Type *etype, Type *totype)
  gcc_assert (totype->size () == etype->size ());
  result = build_vconvert (build_ctype (totype), exp);
}
+  else if (tbtype->ty == Tvector && tbtype->size () == ebtype->size ())
+   {
+ /* Allow casting from array to vector as if its an unaligned load.  */
+ tree type = build_ctype (totype);
+ tree unaligned_type = build_variant_type_copy (type);
+ SET_TYPE_ALIGN (unaligned_type, 1 * BITS_PER_UNIT);
+ TYPE_USER_ALIGN (unaligned_type) = 1;
+ result = convert (type, build_vconvert (unaligned_type, exp));
+   }
   else
{
  error ("cannot cast expression of type %qs to type %qs",
@@ -636,6 +645,39 @@ convert_for_rvalue (tree expr, Type *etype, Type *totype)
   break;
 }
 
+  if (tbtype->ty == Tsarray
+  && ebtype->ty == Tsarray
+  && tbtype->nextOf ()->ty == ebtype->nextOf ()->ty
+  && INDIRECT_REF_P (expr)
+  && CONVERT_EXPR_CODE_P (TREE_CODE (TREE_OPERAND (expr, 0)))
+  && TREE_CODE (TREE_OPERAND (TREE_OPERAND (expr, 0), 0)) == ADDR_EXPR)
+{
+  /* If expression is a vector that was casted to an array either by
+explicit type cast or by taking the vector's `.array' value, strip the
+reinterpret cast and build a constructor instead.  */
+  tree ptr = TREE_OPERAND (TREE_OPERAND (expr, 0), 0);
+
+  if (VECTOR_TYPE_P (TREE_TYPE (TREE_TYPE (ptr
+   {
+ /* Rewrite: `*(Array *)&vector'
+   into: `{ vector[0], vector[1], ... }'  */
+ tree array = d_save_expr (TREE_OPERAND (ptr, 0));
+ array = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (expr), array);
+
+ uinteger_t dim = tbtype->isTypeSArray ()->dim->toUInteger ();
+ vec  *elms = NULL;
+ for (uinteger_t i = 0; i < dim; i++)
+   {
+ tree index = size_int (i);
+ tree value = build4 (ARRAY_REF, TREE_TYPE (TREE_TYPE (array)),
+  array, index, NULL_TREE, NULL_TREE);
+ CONSTRUCTOR_APPEND_ELT (elms, index, value);
+   }
+
+ return build_constructor (build_ctype (totype), elms);
+   }
+}
+
   return result ? result : convert_expr (expr, etype, totype);
 }
 
@@ -696,7 +738,7 @@ convert_for_assignment (tree expr, Type *etype, Type 
*totype)
   return expr;
 }
 
-  return convert_expr (expr, etype, totype);
+  return convert_for_rvalue (expr, etype, totype);
 }
 
 /* Return a TREE representation of EXPR converted to represent
diff --git a/gcc/d/dmd/expressionsem.c b/gcc/d/dmd/expressionsem.c
index 5ae5fe6a717..fe90039d6f0 100644
--- a/gcc/d/dmd/expressionsem.c
+++ b/gcc/d/dmd/expressionsem.c
@@ -6330,6 +6330,7 @@ p

[committed] d: Build the D sources in the front-end with -fno-exceptions

2022-07-06 Thread Iain Buclaw via Gcc-patches
Hi,

The D front-end does not use exceptions, but it still requires RTTI for
some lowerings of convenience language features.  This patch enforces
that by now building GDC with `-fno-exceptions'.

Bootstrapped with gcc-9, and committed to mainline.

Regards,
Iain.

---
gcc/d/ChangeLog:

* Make-lang.in (NOEXCEPTION_DFLAGS): Define.
(ALL_DFLAGS): Add NO_EXCEPTION_DFLAGS.
---
 gcc/d/Make-lang.in | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/d/Make-lang.in b/gcc/d/Make-lang.in
index 9f134370218..6f9b2e5c26a 100644
--- a/gcc/d/Make-lang.in
+++ b/gcc/d/Make-lang.in
@@ -57,8 +57,12 @@ CHECKING_DFLAGS =
 endif
 WARN_DFLAGS = -Wall -Wdeprecated $(NOCOMMON_FLAG)
 
+# D front-end doesn't use exceptions, but it does require RTTI.
+NOEXCEPTION_DFLAGS = $(filter-out -fno-rtti, $(NOEXCEPTION_FLAGS))
+
 ALL_DFLAGS = $(DFLAGS-$@) $(GDCFLAGS) -fversion=IN_GCC $(CHECKING_DFLAGS) \
-   $(PICFLAG) $(ALIASING_FLAGS) $(COVERAGE_FLAGS) $(WARN_DFLAGS)
+   $(PICFLAG) $(ALIASING_FLAGS) $(NOEXCEPTION_DFLAGS) $(COVERAGE_FLAGS) \
+   $(WARN_DFLAGS)
 
 DCOMPILE.base = $(GDC) $(NO_PIE_CFLAGS) -c $(ALL_DFLAGS) -o $@
 DCOMPILE = $(DCOMPILE.base) -MT $@ -MMD -MP -MF $(@D)/$(DEPDIR)/$(*F).TPo
-- 
2.34.1



[committed] d: Merge upstream dmd 56589f0f4, druntime 651389b5, phobos 1516ecad9.

2022-07-06 Thread Iain Buclaw via Gcc-patches
Hi,

This patch merges the D front-end with upstream dmd 56589f0f4, and
the standard library with druntime 651389b5 and phobos 1516ecad9.

D front-end changes:

- Import latest bug fixes to mainline.

D runtime changes:

- Import latest bug fixes to mainline.

Phobos changes:

- Import latest bug fixes to mainline.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 56589f0f4.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 651389b5.
* src/MERGE: Merge upstream phobos 1516ecad9.
---
 gcc/d/dmd/MERGE   |   2 +-
 gcc/d/dmd/cparse.d| 118 +++-
 gcc/d/dmd/dmodule.d   |   2 +-
 gcc/d/dmd/expressionsem.d |   8 +
 gcc/d/dmd/globals.d   |   2 +-
 gcc/d/dmd/globals.h   |   2 +-
 gcc/d/dmd/hdrgen.d|  17 +-
 gcc/d/dmd/mtype.d |  15 +-
 gcc/d/dmd/tokens.d|   5 +-
 gcc/d/dmd/tokens.h|   1 +
 gcc/d/dmd/typesem.d   |   9 +-
 gcc/testsuite/gdc.test/compilable/test3004.d  |   4 +-
 gcc/testsuite/gdc.test/compilable/vcg-ast.d   |   3 +
 .../gdc.test/fail_compilation/diag_in_array.d |  20 +
 libphobos/libdruntime/MERGE   |   2 +-
 .../libdruntime/core/internal/parseoptions.d  |  17 +
 libphobos/libdruntime/core/thread/osthread.d  |   9 +
 libphobos/libdruntime/rt/aApply.d | 108 ++-
 libphobos/libdruntime/rt/aApplyR.d|  71 +-
 libphobos/libdruntime/rt/aaA.d|  39 +-
 libphobos/libdruntime/rt/arrayassign.d|  83 ++-
 libphobos/libdruntime/rt/lifetime.d   | 378 +++---
 libphobos/src/MERGE   |   2 +-
 libphobos/src/std/complex.d   |   4 +-
 libphobos/src/std/file.d  |  35 +-
 libphobos/src/std/math/exponential.d  | 648 +++---
 26 files changed, 1115 insertions(+), 489 deletions(-)
 create mode 100644 gcc/testsuite/gdc.test/fail_compilation/diag_in_array.d

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index f5c42f0ff00..8324c1cc88c 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-529110f66d7d301d62d943a4e4482edaddeb46ea
+56589f0f4d724c1c8022c57509a243f16a04228a
 
 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/cparse.d b/gcc/d/dmd/cparse.d
index dff76345fa5..a3bebb7365a 100644
--- a/gcc/d/dmd/cparse.d
+++ b/gcc/d/dmd/cparse.d
@@ -1619,6 +1619,12 @@ final class CParser(AST) : Parser!AST
 return;
 }
 
+if (token.value == TOK.__pragma)
+{
+uupragmaDirective(scanloc);
+return;
+}
+
 if (token.value == TOK._import) // import declaration extension
 {
 auto a = parseImport();
@@ -2322,6 +2328,14 @@ final class CParser(AST) : Parser!AST
 break;
 }
 
+case TOK.__declspec:
+{
+/* Microsoft extension
+ */
+cparseDeclspec(specifier);
+break;
+}
+
 case TOK.typeof_:
 {
 nextToken();
@@ -3042,9 +3056,13 @@ final class CParser(AST) : Parser!AST
  * extended-decl-modifier:
  *dllimport
  *dllexport
+ *noreturn
+ * Params:
+ *  specifier = filled in with the attribute(s)
  */
-private void cparseDeclspec()
+private void cparseDeclspec(ref Specifier specifier)
 {
+//printf("cparseDeclspec()\n");
 /* Check for dllexport, dllimport
  * Ignore the rest
  */
@@ -3073,6 +3091,11 @@ final class CParser(AST) : Parser!AST
 dllexport = true;
 nextToken();
 }
+else if (token.ident == Id.noreturn)
+{
+specifier.noreturn = true;
+nextToken();
+}
 else
 {
 nextToken();
@@ -3083,8 +3106,8 @@ final class CParser(AST) : Parser!AST
 else
 {
 error("extended-decl-modifier expected");
+break;
 }
-break;
 }
 }
 
@@ -4789,6 +4812,8 @@ final class CParser(AST) : Parser!AST
 // type function itself.
 if (auto tf = t.isTypeFunction())
 tf.next = tf.next.addSTC(STC.const_);
+else if (auto tt = t.isTypeTag())
+tt.mod |= MODFlags.const_;
 else
 t = t.addSTC(STC.const_);
 return t;
@@ -4961,10 +4986,40 @@ final class CParser(A

[PATCH] d: Move DSO registry support code from compiler to drtstuff in library (PR100062)

2022-07-08 Thread Iain Buclaw via Gcc-patches
Hi,

Currently the DSO support for D runtime is generated by the compiler in
every object, when really it is only required once per shared object.

This patch moves that support logic from the compiler itself to the
library as part of the drtstuff code.  The object files drtbegin.o and
drtend.o are now always linked in.

Bootstrapped and tested on x86_64-linux-gnu/-m32/-mx32, with no
observable regressions.

@Rainer, as you provided the original, would be good to validate this is
fine for Solaris too.

Regards
Iain.

---
PR d/100062

gcc/ChangeLog:

* config/darwin-d.cc (TARGET_D_MINFO_START_NAME): Remove.
(TARGET_D_MINFO_END_NAME): Remove.
* config/elfos.h (TARGET_D_MINFO_START_NAME): Remove.
(TARGET_D_MINFO_END_NAME): Remove.
* config/i386/winnt-d.cc (TARGET_D_MINFO_START_NAME): Remove.
(TARGET_D_MINFO_END_NAME): Remove.
* doc/tm.texi: Regenerate.
* doc/tm.texi.in: Remove hooks for TARGET_D_MINFO_START_NAME and
TARGET_D_MINFO_END_NAME

gcc/d/ChangeLog:

* d-target.def (d_minfo_start_name): Remove hook.
(d_minfo_end_name): Remove hook.
* modules.cc (compiler_dso_type): Remove.
(dso_registry_fn): Remove.
(dso_slot_node): Remove.
(dso_initialized_node): Remove.
(start_minfo_node): Remove.
(stop_minfo_node): Remove.
(get_compiler_dso_type): Remove.
(get_dso_registry_fn): Remove.
(build_dso_cdtor_fn): Remove.
(build_dso_registry_var): Remove.
(register_moduleinfo): Don't generate and emit DSO registry code.

gcc/testsuite/ChangeLog:

* lib/gdc-utils.exp (gdc-convert-args): Handle -nophoboslib.

libphobos/ChangeLog:

* Makefile.in: Regenerate.
* configure: Regenerate.
* configure.ac: Remove substitution of DRTSTUFF_SPEC.
(DRUNTIME_OS_MINFO_BRACKETING): Rename to...
(DRUNTIME_OS_NAMED_SECTIONS): ...this.
* libdruntime/Makefile.am: Always compile $(DRTSTUFF).
(gcc/drtbegin.o): Compile with gdc.
(gcc/drtend.o): Likewise.
* libdruntime/Makefile.in: Regenerate.
* libdruntime/gcc/config.d.in (OS_Have_Named_Sections): Define.
* libdruntime/gcc/sections/common.d (CompilerDSOData): Define.
* libdruntime/gcc/sections/elf.d (CompilerDSOData): Remove.
* libdruntime/gcc/sections/macho.d (CompilerDSOData): Remove.
* libdruntime/gcc/sections/pecoff.d (CompilerDSOData): Remove.
* m4/druntime/os.m4 (DRUNTIME_OS_MINFO_BRACKETING): Remove.
(DRUNTIME_OS_NAMED_SECTIONS): Define.
* src/Makefile.in: Regenerate.
* src/libgphobos.spec.in: Always add drtbegin and drtend to startfile
and endfile spec.
* testsuite/Makefile.in: Regenerate.
* libdruntime/gcc/drtstuff.c: Rename to file to...
* libdruntime/gcc/drtstuff.d: ...this. Convert source to D, add DSO
registry code originally generated by the compiler.
---
 gcc/config/darwin-d.cc  |   6 -
 gcc/config/elfos.h  |   2 -
 gcc/config/i386/winnt-d.cc  |   6 -
 gcc/d/d-target.def  |  17 +-
 gcc/d/modules.cc| 202 +---
 gcc/doc/tm.texi |  12 --
 gcc/doc/tm.texi.in  |   4 -
 gcc/testsuite/lib/gdc-utils.exp |   3 +
 libphobos/Makefile.in   |   2 +-
 libphobos/configure | 119 +++-
 libphobos/configure.ac  |  10 +-
 libphobos/libdruntime/Makefile.am   |  16 +-
 libphobos/libdruntime/Makefile.in   |  16 +-
 libphobos/libdruntime/gcc/config.d.in   |   3 +
 libphobos/libdruntime/gcc/drtstuff.c|  39 
 libphobos/libdruntime/gcc/drtstuff.d| 105 ++
 libphobos/libdruntime/gcc/sections/common.d |  11 ++
 libphobos/libdruntime/gcc/sections/elf.d|  11 --
 libphobos/libdruntime/gcc/sections/macho.d  |  11 --
 libphobos/libdruntime/gcc/sections/pecoff.d |  11 --
 libphobos/m4/druntime/os.m4 |  40 +---
 libphobos/src/Makefile.in   |   2 +-
 libphobos/src/libgphobos.spec.in|   6 +-
 libphobos/testsuite/Makefile.in |   2 +-
 24 files changed, 183 insertions(+), 473 deletions(-)
 delete mode 100644 libphobos/libdruntime/gcc/drtstuff.c
 create mode 100644 libphobos/libdruntime/gcc/drtstuff.d

diff --git a/gcc/config/darwin-d.cc b/gcc/config/darwin-d.cc
index e983883dba6..358a049212b 100644
--- a/gcc/config/darwin-d.cc
+++ b/gcc/config/darwin-d.cc
@@ -66,10 +66,4 @@ darwin_d_register_target_info (void)
 #undef TARGET_D_MINFO_SECTION
 #define TARGET_D_MINFO_SECTION "__DATA,__minfodata"
 
-#undef TARGET_D_MINFO_START_NAME
-#define TARGET_D_MINFO_START_NAME "*section$start$__DATA$__minfodata"
-
-#undef TARGET_D_MINFO_END_NAME
-#define TARGET_D_MINFO_END_NAME "*section$end$__DATA$__min

Re: [PATCH] libphobos: Fix instability in the parallelized testsuite

2022-07-15 Thread Iain Buclaw via Gcc-patches
Excerpts from Lewis Hyatt via Gcc-patches's message of Juli 14, 2022 11:53 pm:
> Hello-
> 
> I get a different number of test results from libphobos.unittest/unittest.exp,
> depending on server load. I believe it's because this testsuite doesn't check
> runtest_file_p:
> 
> $ make -j 1 RUNTESTFLAGS='unittest.exp' check-target-libphobos | grep '^#'
>  # of expected passes   10
> 
> $ make -j 2 RUNTESTFLAGS='unittest.exp' check-target-libphobos | grep '^#'
>  # of expected passes   10
>  # of expected passes   10
> 
> $ make -j 4 RUNTESTFLAGS='unittest.exp' check-target-libphobos | grep '^#'
>  # of expected passes   10
>  # of expected passes   10
>  # of expected passes   10
>  # of expected passes   10
> 
> When running in parallel along with other tests, even at a fixed argument
> for -j, the number of tests that actually execute will depend on how many of 
> the
> parallel sub-makes happened to start prior to the first one finishing, hence
> it changes from run to run.
> 
> The attached patch fixes it for me, if it looks OK? Thanks, this would remove
> some noise from before/after test comparisons.
> 
> -Lewis
> libphobos: Fix instability in the parallelized testsuite
> 
> libphobos.unittest/unittest.exp calls bare dg-test rather than dg-runtest, and
> so it should call runtest_file_p to determine whether to run each test or
> not. Without that call, the tests run too many times in parallel mode (they 
> will
> run as many times, as the argument to make -j).


Hi Lewis,

Thanks! Good spot. I think it should be calling dg-runtest however,
same as what libphobos.cycles/cycles.exp is doing. Could also fix the
test name so each one is unique, just to hit two birds in one -
something like the following would suffice (haven't had time to check).

Kind Regards,
Iain.

---

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



[GCC 12, committed] d: Merge upstream dmd 76e3b41375, druntime 1462ebd1, phobos 5fef0d28f.

2022-07-26 Thread Iain Buclaw via Gcc-patches
Hi,

This patch merges the D front-end with upstream dmd 76e3b41375, and
standard run-time libraries with druntime 1462ebd1, and phobos
5fef0d28f, updating the D language version to v2.100.1.

D front-end changes:

- Fix delegate literal with inferred return value that requires
  following alias-this to not use class cast.
- Fix internal error on variadic template type instantiated with two
  arrays of classes.
- `scope(failure)' blocks that contain `return' statements are now
  deprecated.
- Fix regression where wrong cast was inserted for ternary operator
  and non-int enums.
- Fix internal error in code generation trying to reference
  _d_arraysetctor.
- Fix memory corruption when array literal is passed to map in
  lambda, then returned from nested function.
- Generate invariant id on the basis of location rather than a
  global counter.
- Make `noreturn' conversions work.
- Fix segfault when `.stringof' of template alias overloaded with
  function accessed by trait.
- Empty array literal passed to scope param not 'falsey' anymore.

Phobos changes:

- Avoid copying ranges in std.algorithm.comparison.equal.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 76e3b41375.
* dmd/VERSION: Bump version to v2.100.1.
* decl.cc (DeclVisitor::visit (VarDeclaration *)): Evaluate RHS
  of noreturn declaration expressions first.
* expr.cc (ExprVisitor::visit (AssignExp *)): Don't generate
  assignment for noreturn types.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 1462ebd1.
* src/MERGE: Merge upstream phobos 5fef0d28f.
---
 gcc/d/decl.cc |  7 ++-
 gcc/d/dmd/MERGE   |  2 +-
 gcc/d/dmd/VERSION |  2 +-
 gcc/d/dmd/dcast.d | 14 -
 gcc/d/dmd/dsymbolsem.d|  3 +
 gcc/d/dmd/expressionsem.d | 13 +++--
 gcc/d/dmd/func.d  | 14 -
 gcc/d/dmd/impcnvtab.d | 55 +++
 gcc/d/dmd/mtype.d |  5 ++
 gcc/d/dmd/statementsem.d  | 16 +-
 gcc/d/expr.cc | 11 
 .../gdc.test/compilable/backendfloatoptim.d   | 10 
 gcc/testsuite/gdc.test/compilable/noreturn1.d | 28 ++
 gcc/testsuite/gdc.test/compilable/test23082.d | 17 ++
 gcc/testsuite/gdc.test/compilable/test23166.d | 22 
 gcc/testsuite/gdc.test/compilable/test23172.d | 33 +++
 gcc/testsuite/gdc.test/compilable/test23258.d | 21 +++
 .../gdc.test/fail_compilation/fail23181.d | 16 ++
 .../gdc.test/fail_compilation/fail6889.d  |  2 +-
 .../gdc.test/fail_compilation/fail7848.d  |  8 +--
 .../gdc.test/fail_compilation/test21443.d | 21 +++
 .../gdc.test/fail_compilation/test23170.d | 12 
 gcc/testsuite/gdc.test/runnable/noreturn1.d   | 32 +++
 gcc/testsuite/gdc.test/runnable/test20734.d   |  7 +++
 gcc/testsuite/gdc.test/runnable/test23181.d   | 27 +
 gcc/testsuite/gdc.test/runnable/test23234.d   | 22 
 gcc/testsuite/gdc.test/runnable/warning1.d|  9 ---
 libphobos/libdruntime/MERGE   |  2 +-
 libphobos/src/MERGE   |  2 +-
 libphobos/src/std/algorithm/comparison.d  |  2 +-
 libphobos/src/std/typecons.d  | 10 +++-
 31 files changed, 408 insertions(+), 37 deletions(-)
 create mode 100644 gcc/testsuite/gdc.test/compilable/backendfloatoptim.d
 create mode 100644 gcc/testsuite/gdc.test/compilable/test23082.d
 create mode 100644 gcc/testsuite/gdc.test/compilable/test23166.d
 create mode 100644 gcc/testsuite/gdc.test/compilable/test23172.d
 create mode 100644 gcc/testsuite/gdc.test/compilable/test23258.d
 create mode 100644 gcc/testsuite/gdc.test/fail_compilation/fail23181.d
 create mode 100644 gcc/testsuite/gdc.test/fail_compilation/test21443.d
 create mode 100644 gcc/testsuite/gdc.test/fail_compilation/test23170.d
 create mode 100644 gcc/testsuite/gdc.test/runnable/test23181.d
 create mode 100644 gcc/testsuite/gdc.test/runnable/test23234.d

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index f5c21078aad..43c3d87cdd1 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -645,9 +645,12 @@ public:
if (!d->isDataseg () && !d->isMember ()
&& d->_init && !d->_init->isVoidInitializer ())
  {
+   /* Evaluate RHS for side effects first.  */
+   Expression *ie = initializerToExpression (d->_init);
+   add_stmt (build_expr (ie));
+
Expression *e = d->type->defaultInitLiteral (d->loc);
-   tree exp = build_expr (e);
-   add_stmt (exp);
+   add_stmt (build_expr (e));
  }

[committed] d: Fix ICE in in add_stack_var, at cfgexpand.cc:476 (PR106555)

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

This patch fixes the ICE reported in PR d/106555.

The type that triggers the ICE never got completed by the semantic
analysis pass.  Checking for size forces it to be done, or issue a
compile-time error.

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/106555

gcc/d/ChangeLog:

* d-target.cc (Target::isReturnOnStack): Check for return type size.

gcc/testsuite/ChangeLog:

* gdc.dg/imports/pr106555.d: New test.
* gdc.dg/pr106555.d: New test.
---
 gcc/d/d-target.cc   |  2 ++
 gcc/testsuite/gdc.dg/imports/pr106555.d | 10 ++
 gcc/testsuite/gdc.dg/pr106555.d |  4 
 3 files changed, 16 insertions(+)
 create mode 100644 gcc/testsuite/gdc.dg/imports/pr106555.d
 create mode 100644 gcc/testsuite/gdc.dg/pr106555.d

diff --git a/gcc/d/d-target.cc b/gcc/d/d-target.cc
index 610be74ad48..d4350e593e4 100644
--- a/gcc/d/d-target.cc
+++ b/gcc/d/d-target.cc
@@ -464,6 +464,8 @@ Target::isReturnOnStack (TypeFunction *tf, bool)
 return false;
 
   Type *tn = tf->next->toBasetype ();
+  if (tn->size () == SIZE_INVALID)
+return false;
 
   return (tn->ty == TY::Tstruct || tn->ty == TY::Tsarray);
 }
diff --git a/gcc/testsuite/gdc.dg/imports/pr106555.d 
b/gcc/testsuite/gdc.dg/imports/pr106555.d
new file mode 100644
index 000..0d3ab6bb747
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/imports/pr106555.d
@@ -0,0 +1,10 @@
+module imports.pr106555;
+struct S106555
+{
+int[] f106555;
+int max106555;
+this(int)
+{
+f106555.length = max106555;
+}
+}
diff --git a/gcc/testsuite/gdc.dg/pr106555.d b/gcc/testsuite/gdc.dg/pr106555.d
new file mode 100644
index 000..7b40f3c097b
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr106555.d
@@ -0,0 +1,4 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106555
+// { dg-do compile }
+// { dg-additional-options "-O2" }
+// { dg-additional-sources "imports/pr106555.d" }
-- 
2.34.1



[committed] d: Fix undefined reference to pragma(inline) symbol (PR106563)

2022-08-09 Thread Iain Buclaw via Gcc-patches
Hi,

This patch changes the emission strategy for inline functions so that
they are given codegen in every referencing module, not just the module
that they are defined in.

Functions that are declared `pragma(inline)' should be treated as if
they are defined in every translation unit they are referenced from,
regardless of visibility protection.  Ensure they always get
DECL_ONE_ONLY linkage, and start emitting them into other modules that
import them.

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

Regards,
Iain.

---
PR d/106563

gcc/d/ChangeLog:

* decl.cc (DeclVisitor::visit (FuncDeclaration *)): Set semanticRun
before generating its symbol.
(function_defined_in_root_p): New function.
(function_needs_inline_definition_p): New function.
(maybe_build_decl_tree): New function.
(get_symbol_decl): Call maybe_build_decl_tree before returning symbol.
(start_function): Use function_defined_in_root_p instead of inline
test for locally defined symbols.
(set_linkage_for_decl): Check for inline functions before private or
protected symbols.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/torture.exp (srcdir): New proc.
* gdc.dg/torture/imports/pr106563math.d: New test.
* gdc.dg/torture/imports/pr106563regex.d: New test.
* gdc.dg/torture/imports/pr106563uni.d: New test.
* gdc.dg/torture/pr106563.d: New test.

---
 gcc/d/decl.cc | 121 +++---
 .../gdc.dg/torture/imports/pr106563math.d |  12 ++
 .../gdc.dg/torture/imports/pr106563regex.d|   7 +
 .../gdc.dg/torture/imports/pr106563uni.d  |  15 +++
 gcc/testsuite/gdc.dg/torture/pr106563.d   |  16 +++
 gcc/testsuite/gdc.dg/torture/torture.exp  |   9 ++
 6 files changed, 161 insertions(+), 19 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/torture/imports/pr106563math.d
 create mode 100644 gcc/testsuite/gdc.dg/torture/imports/pr106563regex.d
 create mode 100644 gcc/testsuite/gdc.dg/torture/imports/pr106563uni.d
 create mode 100644 gcc/testsuite/gdc.dg/torture/pr106563.d

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 43c3d87cdd1..9119323175e 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -823,6 +823,10 @@ public:
 if (global.errors)
   return;
 
+/* Start generating code for this function.  */
+gcc_assert (d->semanticRun == PASS::semantic3done);
+d->semanticRun = PASS::obj;
+
 /* Duplicated FuncDeclarations map to the same symbol.  Check if this
is the one declaration which will be emitted.  */
 tree fndecl = get_symbol_decl (d);
@@ -839,10 +843,6 @@ public:
 if (global.params.verbose)
   message ("function  %s", d->toPrettyChars ());
 
-/* Start generating code for this function.  */
-gcc_assert (d->semanticRun == PASS::semantic3done);
-d->semanticRun = PASS::obj;
-
 tree old_context = start_function (d);
 
 tree parm_decl = NULL_TREE;
@@ -1015,13 +1015,103 @@ build_decl_tree (Dsymbol *d)
   input_location = saved_location;
 }
 
+/* Returns true if function 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;
+
+  TemplateInstance *ti = fd->isInstantiated ();
+  if (ti && 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)'.  */
+
+static bool
+function_needs_inline_definition_p (FuncDeclaration *fd)
+{
+  /* Function has already been defined.  */
+  if (!DECL_EXTERNAL (fd->csym))
+return false;
+
+  /* Non-inlineable functions are always external.  */
+  if (DECL_UNINLINABLE (fd->csym))
+return false;
+
+  /* No function body available for inlining.  */
+  if (!fd->fbody)
+return false;
+
+  /* Ignore functions that aren't decorated with `pragma(inline)'.  */
+  if (fd->inlining != PINLINE::always)
+return false;
+
+  /* These functions are tied to the module they are defined in.  */
+  if (fd->isFuncLiteralDeclaration ()
+  || fd->isUnitTestDeclaration ()
+  || fd->isFuncAliasDeclaration ()
+  || fd->isInvariantDeclaration ())
+return false;
+
+  /* Check whether function will be regularly defined later in the current
+ translation unit.  */
+  if (function_defined_in_root_p (fd))
+return false;
+
+  /* Weak functions cannot be inlined.  */
+  if (lookup_attribute ("weak", DECL_ATTRIBUTES (fd->csym)))
+return false;
+
+  /* Naked functions cannot be inlined.  */
+  if (lookup_attribute ("naked", DECL_ATTRIBUTES (fd->csym)))
+return false;
+
+  return true;
+}
+
+/* If the variable or function declaration in DECL needs to be defined, call
+   build_decl_tree on it now before returning its back-end symbol.  

[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(&symbolDg);
 }
 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

[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 +-
 libpho

[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;// 

[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: 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*)&obj_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 *)&expr & 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



[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: 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



[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: 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=   

[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: 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



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: 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



[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: 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
--- a/gcc/

[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(&unwindCB, &stackframe);
 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_c

[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] 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 (&new_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: 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)*)&a[1][0];
+}
-- 
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: 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: 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: 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: 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: 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: 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: Enable private member access for __traits

2021-01-21 Thread Iain Buclaw via Gcc-patches
Hi,

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

The following traits can now access non-public members:
 - hasMember
 - getMember
 - getOverloads
 - getVirtualMethods
 - getVirtualFuntions

This fixes a long-standing issue in D where the allMembers trait would
correctly return non-public members but those non-public members would
be inaccessible to other traits.

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

Regards
Iain.

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 3a7ebef73.
---
 gcc/d/dmd/MERGE   |  2 +-
 gcc/d/dmd/traits.c| 10 --
 gcc/testsuite/gdc.test/compilable/imports/test15371.d |  9 +
 gcc/testsuite/gdc.test/compilable/test15371.d | 10 ++
 4 files changed, 24 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/gdc.test/compilable/imports/test15371.d
 create mode 100644 gcc/testsuite/gdc.test/compilable/test15371.d

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index 4f7f7a8ff3b..1f907b8f19f 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-2d3d137489f030395d06cb664087fd1a35bccabe
+3a7ebef73cc01d4a877a95cf95cd3776c9e3ee66
 
 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/traits.c b/gcc/d/dmd/traits.c
index 5fd4b486a9b..70f7f2cb582 100644
--- a/gcc/d/dmd/traits.c
+++ b/gcc/d/dmd/traits.c
@@ -1103,12 +1103,14 @@ Expression *semanticTraits(TraitsExp *e, Scope *sc)
 return new ErrorExp();
 }
 
+// ignore symbol visibility and disable access checks for these traits
+Scope *scx = sc->push();
+scx->flags |= SCOPEignoresymbolvisibility | SCOPEnoaccesscheck;
+
 if (e->ident == Id::hasMember)
 {
 /* Take any errors as meaning it wasn't found
  */
-Scope *scx = sc->push();
-scx->flags |= SCOPEignoresymbolvisibility;
 ex = trySemantic(ex, scx);
 scx->pop();
 return ex ? True(e) : False(e);
@@ -1118,8 +1120,6 @@ Expression *semanticTraits(TraitsExp *e, Scope *sc)
 if (ex->op == TOKdotid)
 // Prevent semantic() from replacing Symbol with its 
initializer
 ((DotIdExp *)ex)->wantsym = true;
-Scope *scx = sc->push();
-scx->flags |= SCOPEignoresymbolvisibility;
 ex = semantic(ex, scx);
 scx->pop();
 return ex;
@@ -1130,8 +1130,6 @@ Expression *semanticTraits(TraitsExp *e, Scope *sc)
 {
 unsigned errors = global.errors;
 Expression *eorig = ex;
-Scope *scx = sc->push();
-scx->flags |= SCOPEignoresymbolvisibility;
 ex = semantic(ex, scx);
 if (errors < global.errors)
 e->error("%s cannot be resolved", eorig->toChars());
diff --git a/gcc/testsuite/gdc.test/compilable/imports/test15371.d 
b/gcc/testsuite/gdc.test/compilable/imports/test15371.d
new file mode 100644
index 000..49b446a329b
--- /dev/null
+++ b/gcc/testsuite/gdc.test/compilable/imports/test15371.d
@@ -0,0 +1,9 @@
+module imports.test15371;
+
+struct A
+{
+private int a;
+private void fun() {}
+private void fun(int, int) {}
+public void fun(int) {}
+}
diff --git a/gcc/testsuite/gdc.test/compilable/test15371.d 
b/gcc/testsuite/gdc.test/compilable/test15371.d
new file mode 100644
index 000..6e762beeb1e
--- /dev/null
+++ b/gcc/testsuite/gdc.test/compilable/test15371.d
@@ -0,0 +1,10 @@
+// EXTRA_FILES: imports/test15371.d
+import imports.test15371;
+
+void main()
+{
+A a;
+static assert(__traits(hasMember, A, "a"));
+static assert(__traits(getOverloads, A, "fun").length == 3);
+static assert(__traits(compiles, __traits(getMember, a, "a") ));
+}
-- 
2.27.0



[committed] libphobos: Fix executables segfault on mipsel architecture

2021-01-23 Thread Iain Buclaw via Gcc-patches
Hi,

This patch fixes an issue running programs linked to the shared
libphobos library on MIPS.  The dynamic section on MIPS is read-only,
but this was not properly handled in the runtime library.

Bootstrapped and regression tested on mipsel-linux-gnu, and committed to
mainline with backports to the releases/gcc-10 and gcc-9 branches.

Regards
Iain

---
libphobos/ChangeLog:

PR d/98806
* libdruntime/gcc/sections/elf_shared.d (MIPS_Any): Declare version
for MIPS32 and MIPS64.
(getDependencies): Adjust dlpi_addr on MIPS_Any.
---
 libphobos/libdruntime/gcc/sections/elf_shared.d | 4 
 1 file changed, 4 insertions(+)

diff --git a/libphobos/libdruntime/gcc/sections/elf_shared.d 
b/libphobos/libdruntime/gcc/sections/elf_shared.d
index 9050413b261..427759a4f94 100644
--- a/libphobos/libdruntime/gcc/sections/elf_shared.d
+++ b/libphobos/libdruntime/gcc/sections/elf_shared.d
@@ -22,6 +22,8 @@
 
 module gcc.sections.elf_shared;
 
+version (MIPS32)  version = MIPS_Any;
+version (MIPS64)  version = MIPS_Any;
 version (RISCV32) version = RISCV_Any;
 version (RISCV64) version = RISCV_Any;
 version (S390)version = IBMZ_Any;
@@ -763,6 +765,8 @@ version (Shared)
 // in glibc: #define DL_RO_DYN_SECTION 1
 version (RISCV_Any)
 strtab = cast(const(char)*)(info.dlpi_addr + 
dyn.d_un.d_ptr); // relocate
+else version (MIPS_Any)
+strtab = cast(const(char)*)(info.dlpi_addr + 
dyn.d_un.d_ptr); // relocate
 else
 strtab = cast(const(char)*)dyn.d_un.d_ptr;
 }
-- 
2.27.0



[committed] d: Merge upstream dmd 609c3ce2d, phobos 3dd5df686

2021-01-26 Thread Iain Buclaw via Gcc-patches
Hi,

This patch merges the D front-end implementation with upstream dmd
609c3ce2d, and the Phobos standard library with upstream 3dd5df686.

D front-end changes:

 - Contracts for pre- and postconditions are now implicitly "this"
   const, so that state can no longer be altered in these functions.

 - Inside a constructor scope, assigning to aggregate declaration
   members is done by considering the first assignment as initialization
   and subsequent assignments as modifications of the constructed
   object.  For const/immutable fields the initialization is accepted in
   the constructor but subsequent modifications are not.  However this
   rule did not apply when inside a constructor scope there is a call to
   a different constructor.  This been changed so it is now an error
   when there's a double initialization of immutable fields inside a
   constructor.

Phobos changes:

 - Don't run unit-tests for unsupported clocks in std.datetime.  The
   phobos and phobos_shared tests now add -fversion=Linux_Pre_2639 if
   required.

 - Deprecate public extern(C) bindings for getline and getdelim in
   std.stdio.  The correct module for bindings is core.sys.posix.stdio.

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

Regards,
Iain

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 609c3ce2d.
* d-compiler.cc (Compiler::loadModule): Rename to ...
(Compiler::onParseModule): ... this.
(Compiler::onImport): New function.
* d-lang.cc (d_parse_file): Remove call to Compiler::loadModule.

libphobos/ChangeLog:

* src/MERGE: Merge upstream phobos 3dd5df686.
* testsuite/libphobos.phobos/phobos.exp: Add compiler flag
-fversion=Linux_Pre_2639 if target is linux_pre_2639.
* testsuite/libphobos.phobos_shared/phobos_shared.exp: Likewise.
---
 gcc/d/d-compiler.cc   |  12 +-
 gcc/d/d-lang.cc   |   1 -
 gcc/d/dmd/MERGE   |   2 +-
 gcc/d/dmd/compiler.h  |   7 +-
 gcc/d/dmd/declaration.c   |  14 +
 gcc/d/dmd/dmodule.c   |  12 +-
 gcc/d/dmd/expressionsem.c |   7 +
 gcc/d/dmd/func.c  |   2 -
 gcc/d/dmd/root/array.h|   4 +-
 .../gdc.test/fail_compilation/fail18143.d |  43 ++
 .../gdc.test/fail_compilation/fail18719.d |  41 ++
 libphobos/src/MERGE   |   2 +-
 libphobos/src/std/datetime/systime.d  |  32 +-
 libphobos/src/std/file.d  |  23 +-
 libphobos/src/std/stdio.d | 602 +-
 .../testsuite/libphobos.phobos/phobos.exp |   8 +-
 .../libphobos.phobos_shared/phobos_shared.exp |   8 +-
 17 files changed, 496 insertions(+), 324 deletions(-)
 create mode 100644 gcc/testsuite/gdc.test/fail_compilation/fail18143.d
 create mode 100644 gcc/testsuite/gdc.test/fail_compilation/fail18719.d

diff --git a/gcc/d/d-compiler.cc b/gcc/d/d-compiler.cc
index 881d48228c8..3907d010684 100644
--- a/gcc/d/d-compiler.cc
+++ b/gcc/d/d-compiler.cc
@@ -157,7 +157,7 @@ Compiler::paintAsType (UnionExp *, Expression *expr, Type 
*type)
 - core.stdc.*: For all gcc library builtins.  */
 
 void
-Compiler::loadModule (Module *m)
+Compiler::onParseModule (Module *m)
 {
   ModuleDeclaration *md = m->md;
 
@@ -180,3 +180,13 @@ Compiler::loadModule (Module *m)
d_add_builtin_module (m);
 }
 }
+
+/* A callback function that is called once an imported module is parsed.
+   If the callback returns true, then it tells the front-end that the
+   driver intends on compiling the import.  */
+
+bool
+Compiler::onImport (Module *)
+{
+  return false;
+}
diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index 72dcb716987..0fd207da7f3 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -980,7 +980,6 @@ d_parse_file (void)
 
   m->importedFrom = m;
   m->parse ();
-  Compiler::loadModule (m);
 
   if (m->isDocFile)
{
diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index 1f907b8f19f..228eed838b2 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-3a7ebef73cc01d4a877a95cf95cd3776c9e3ee66
+609c3ce2d5d5d8a3dc4ba12c5e6e1100873f9ed1
 
 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/compiler.h b/gcc/d/dmd/compiler.h
index 124829b297d..7f9006ce851 100644
--- a/gcc/d/dmd/compiler.h
+++ b/gcc/d/dmd/compiler.h
@@ -27,12 +27,17 @@ extern Module *entrypoint;
 // Module in which the D main is
 extern Module *rootHasMain;
 
+extern bool includeImports;
+// array of module patterns used to include/exclude imported modules
+extern Array includeModulePatterns;
+extern Array compiledImports;
+
 struct Compiler
 {
 // CTFE support for cross-compilation.
 static Expression *paintAsType(UnionExp *, Expression *, Type *);
 

[committed] d: Fix junk in generated symbol on powerpc64-*-* (PR98921)

2021-02-01 Thread Iain Buclaw via Gcc-patches
Hi,

This patch merges the D front-end implementation with upstream dmd
5e2a81d9c, fixing PR98921.  This adds a special formatter to OutBuffer
to handle formatted printing of integers, a common case.  The
replacement is faster and safer.

In dmangle.c, it also gets rid of a number of problematic casts, as seen
on powerpc64 targets.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32, and
on powerpc64le-linux-gnu.  Committed to mainline, and backported to the
releases/gcc-10 and gcc-9 branches.

Regards,
Iain.

---
gcc/d/ChangeLog:

PR d/98921
* dmd/MERGE: Merge upstream dmd 5e2a81d9c.
---
 gcc/d/dmd/MERGE|  2 +-
 gcc/d/dmd/dmangle.c| 29 -
 gcc/d/dmd/root/outbuffer.c | 31 +++
 gcc/d/dmd/root/outbuffer.h |  1 +
 4 files changed, 53 insertions(+), 10 deletions(-)

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index 228eed838b2..342871f9a1a 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-609c3ce2d5d5d8a3dc4ba12c5e6e1100873f9ed1
+5e2a81d9cbcd653d9eed52344d664e72ba1355bc
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
diff --git a/gcc/d/dmd/dmangle.c b/gcc/d/dmd/dmangle.c
index f6eee52afbf..4a9a118ebba 100644
--- a/gcc/d/dmd/dmangle.c
+++ b/gcc/d/dmd/dmangle.c
@@ -279,7 +279,7 @@ public:
 {
 visit((Type *)t);
 if (t->dim)
-buf->printf("%llu", t->dim->toInteger());
+buf->print(t->dim->toInteger());
 if (t->next)
 visitWithMask(t->next, t->mod);
 }
@@ -377,7 +377,8 @@ public:
 visit((Type *)t);
 const char *name = t->ident->toChars();
 size_t len = strlen(name);
-buf->printf("%u%s", (unsigned)len, name);
+buf->print(len);
+buf->writestring(name);
 }
 
 void visit(TypeEnum *t)
@@ -493,7 +494,7 @@ public:
 s->error("excessive length %llu for symbol, possible recursive 
expansion?", buf->length() + len);
 else
 {
-buf->printf("%llu", (ulonglong)len);
+buf->print(len);
 buf->write(id, len);
 }
 }
@@ -822,9 +823,15 @@ public:
 void visit(IntegerExp *e)
 {
 if ((sinteger_t)e->value < 0)
-buf->printf("N%lld", -e->value);
+{
+buf->writeByte('N');
+buf->print(-e->value);
+}
 else
-buf->printf("i%lld",  e->value);
+{
+buf->writeByte('i');
+buf->print(e->value);
+}
 }
 
 void visit(RealExp *e)
@@ -946,7 +953,8 @@ public:
 }
 buf->reserve(1 + 11 + 2 * qlen);
 buf->writeByte(m);
-buf->printf("%d_", (int)qlen); // nbytes <= 11
+buf->print(qlen);
+buf->writeByte('_');// nbytes <= 11
 
 for (utf8_t *p = (utf8_t *)buf->slice().ptr + buf->length(), *pend = p 
+ 2 * qlen;
  p < pend; p += 2, ++q)
@@ -962,7 +970,8 @@ public:
 void visit(ArrayLiteralExp *e)
 {
 size_t dim = e->elements ? e->elements->length : 0;
-buf->printf("A%u", dim);
+buf->writeByte('A');
+buf->print(dim);
 for (size_t i = 0; i < dim; i++)
 {
 e->getElement(i)->accept(this);
@@ -972,7 +981,8 @@ public:
 void visit(AssocArrayLiteralExp *e)
 {
 size_t dim = e->keys->length;
-buf->printf("A%u", dim);
+buf->writeByte('A');
+buf->print(dim);
 for (size_t i = 0; i < dim; i++)
 {
 (*e->keys)[i]->accept(this);
@@ -983,7 +993,8 @@ public:
 void visit(StructLiteralExp *e)
 {
 size_t dim = e->elements ? e->elements->length : 0;
-buf->printf("S%u", dim);
+buf->writeByte('S');
+buf->print(dim);
 for (size_t i = 0; i < dim; i++)
 {
 Expression *ex = (*e->elements)[i];
diff --git a/gcc/d/dmd/root/outbuffer.c b/gcc/d/dmd/root/outbuffer.c
index 8544697a3d5..81c2e901805 100644
--- a/gcc/d/dmd/root/outbuffer.c
+++ b/gcc/d/dmd/root/outbuffer.c
@@ -319,6 +319,37 @@ void OutBuffer::printf(const char *format, ...)
 va_end(ap);
 }
 
+/**
+ * Convert `u` to a string and append it to the buffer.
+ * Params:
+ *  u = integral value to append
+ */
+void OutBuffer::print(unsigned long long u)
+{
+unsigned long long value = u;
+char buf[20];
+const unsigned radix = 10;
+
+size_t i = sizeof(buf);
+do
+{
+if (value < radix)
+{
+unsigned char x = (unsigned char)value;
+buf[--i] = (char)(x + '0');
+break;
+}
+else
+{
+unsigned char x = (unsigned char)(value % radix);
+value = value / radix;
+buf[--i] = (char)(x + '0');
+}
+} while (value);
+
+write(buf + i, sizeof(buf) - i);
+}
+
 void OutBuffer::bracket(char left, c

[committed] libphobos: Merge upstream druntime 9d0c8364, phobos 9d575282e.

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

This patch merges the D runtime library with upstream druntime 9d0c8364,
and the standard library with upstream phobos 9d575282e.

Adds bindings to libdruntime to replace extern(C) declarations found in
the phobos part of the library, and fixes an issue with the locale
bindings being incomplete (PR98910).

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

Regards,
Iain.

---
libphobos/ChangeLog:

PR d/98910
* libdruntime/MERGE: Merge upstream druntime 9d0c8364.
* libdruntime/Makefile.am (DRUNTIME_DSOURCES): Add
  core/internal/attributes.d
(DRUNTIME_DSOURCES_BIONIC): Add core/sys/bionic/stdlib.d.
(DRUNTIME_DSOURCES_DARWIN): Add core/sys/darwin/stdlib.d, and
core/sys/darwin/sys/sysctl.d.
(DRUNTIME_DSOURCES_DRAGONFLYBSD): Add
core/sys/dragonflybsd/stdlib.d, and
core/sys/dragonflybsd/sys/sysctl.d.
(DRUNTIME_DSOURCES_FREEBSD): Add core/sys/freebsd/stdlib.d, and
core/sys/freebsd/sys/sysctl.d.
(DRUNTIME_DSOURCES_NETBSD): Add core/sys/netbsd/stdlib.d, and
core/sys/netbsd/sys/sysctl.d.
(DRUNTIME_DSOURCES_OPENBSD): Add core/sys/openbsd/stdlib.d, and
core/sys/openbsd/sys/sysctl.d.
(DRUNTIME_DSOURCES_SOLARIS): Add core/sys/solaris/stdlib.d.
* libdruntime/Makefile.in: Regenerate.
* src/MERGE: Merge upstream phobos 9d575282e.
---
 libphobos/libdruntime/MERGE   |   2 +-
 libphobos/libdruntime/Makefile.am |  69 ++--
 libphobos/libdruntime/Makefile.in | 174 +
 .../libdruntime/core/internal/attributes.d|  11 +
 .../libdruntime/core/sys/bionic/stdlib.d  |  17 +
 .../libdruntime/core/sys/darwin/mach/dyld.d   |   5 +-
 .../libdruntime/core/sys/darwin/stdlib.d  |  26 ++
 .../libdruntime/core/sys/darwin/sys/sysctl.d  | 253 +
 .../core/sys/dragonflybsd/stdlib.d|  17 +
 .../core/sys/dragonflybsd/sys/sysctl.d| 199 +++
 .../libdruntime/core/sys/freebsd/stdlib.d |  17 +
 .../libdruntime/core/sys/freebsd/sys/sysctl.d | 211 +++
 .../libdruntime/core/sys/netbsd/stdlib.d  |  17 +
 .../libdruntime/core/sys/netbsd/sys/sysctl.d  | 254 +
 .../libdruntime/core/sys/openbsd/stdlib.d |  17 +
 .../libdruntime/core/sys/openbsd/sys/sysctl.d | 254 +
 libphobos/libdruntime/core/sys/posix/locale.d | 335 +++---
 libphobos/libdruntime/core/sys/posix/mqueue.d |   6 +-
 .../libdruntime/core/sys/posix/pthread.d  |   3 +-
 .../libdruntime/core/sys/posix/sys/statvfs.d  | 101 --
 .../libdruntime/core/sys/posix/sys/types.d|   9 +-
 .../libdruntime/core/sys/solaris/stdlib.d |  17 +
 libphobos/src/MERGE   |   2 +-
 libphobos/src/std/conv.d  |   2 -
 libphobos/src/std/datetime/systime.d  | 110 --
 libphobos/src/std/datetime/timezone.d |  17 +-
 libphobos/src/std/exception.d |   5 +-
 .../allocator/building_blocks/region.d|  44 ++-
 .../experimental/allocator/mmap_allocator.d   |  17 +
 libphobos/src/std/file.d  |  88 -
 libphobos/src/std/math.d  |  33 +-
 libphobos/src/std/parallelism.d   | 233 +++-
 libphobos/src/std/socket.d|   4 +-
 libphobos/src/std/stdio.d |   9 +-
 libphobos/src/std/system.d|   6 +
 35 files changed, 2172 insertions(+), 412 deletions(-)
 create mode 100644 libphobos/libdruntime/core/internal/attributes.d
 create mode 100644 libphobos/libdruntime/core/sys/bionic/stdlib.d
 create mode 100644 libphobos/libdruntime/core/sys/darwin/stdlib.d
 create mode 100644 libphobos/libdruntime/core/sys/darwin/sys/sysctl.d
 create mode 100644 libphobos/libdruntime/core/sys/dragonflybsd/stdlib.d
 create mode 100644 libphobos/libdruntime/core/sys/dragonflybsd/sys/sysctl.d
 create mode 100644 libphobos/libdruntime/core/sys/freebsd/stdlib.d
 create mode 100644 libphobos/libdruntime/core/sys/freebsd/sys/sysctl.d
 create mode 100644 libphobos/libdruntime/core/sys/netbsd/stdlib.d
 create mode 100644 libphobos/libdruntime/core/sys/netbsd/sys/sysctl.d
 create mode 100644 libphobos/libdruntime/core/sys/openbsd/stdlib.d
 create mode 100644 libphobos/libdruntime/core/sys/openbsd/sys/sysctl.d
 create mode 100644 libphobos/libdruntime/core/sys/solaris/stdlib.d

diff --git a/libphobos/libdruntime/MERGE b/libphobos/libdruntime/MERGE
index 4654e58e2d9..3485bde1200 100644
--- a/libphobos/libdruntime/MERGE
+++ b/libphobos/libdruntime/MERGE
@@ -1,4 +1,4 @@
-e4aae28e36c118f13e346a61af6c413aadd8e838
+9d0c8364450064d0b6e68da4384f8acd19eb454f
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/druntime repository.
diff --git a/libphobos/libdruntime/Makefile.am 
b/libphobos/libdruntime/Makefile.am
index 57de872862b..df2c06c3dab 100644
--- a/libphobos/libdrunti

[committed] d: Merge upstream dmd 46133f761, druntime 0fd4364c

2021-02-04 Thread Iain Buclaw via Gcc-patches
Hi,

This patch merges the D front-end implementation with upstream dmd
46133f761, and the D runtime library with upstream druntime 0fd4364c.

Backports built-in function handling from upstream, adding a new
intrinsic `byteswap(ushort)`.

Intrinsic modules have been updated accordingly in the runtime library,
and a few more platform-specific fixes have been downstreamed as well.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 46133f761.
* d-builtins.cc (d_build_builtins_module): Set builtins as BUILTINgcc.
(maybe_set_builtin_1): Likewise.
* d-frontend.cc (eval_builtin): Adjust condition for early return.
* intrinsics.cc (maybe_set_intrinsic): Set intrinsics as BUILTINgcc.
(maybe_expand_intrinsic): Add case for INTRINSIC_BSWAP16.
* intrinsics.def (INTRINSIC_BT): Update signature.
(INTRINSIC_BT64): Likewise.
(INTRINSIC_BSWAP16): New intrinsic.
(INTRINSIC_VLOAD8): Update module.
(INTRINSIC_VLOAD16): Likewise.
(INTRINSIC_VLOAD32): Likewise.
(INTRINSIC_VLOAD64): Likewise.
(INTRINSIC_VSTORE8): Likewise.
(INTRINSIC_VSTORE16): Likewise.
(INTRINSIC_VSTORE32): Likewise.
(INTRINSIC_VSTORE64): Likewise.
(INTRINSIC_ADDS): Update signature.
(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.


libphobos/ChangeLog:

PR d/98910
* libdruntime/MERGE: Merge upstream druntime 0fd4364c.
* libdruntime/Makefile.am (DRUNTIME_DSOURCES): Add core/volatile.d.
* libdruntime/Makefile.in: Regenerate.
* testsuite/libphobos.allocations/tls_gc_integration.d: Update test.

gcc/testsuite/ChangeLog:

* gdc.dg/intrinsics.d: Update test.
---
 gcc/d/d-builtins.cc   |4 +-
 gcc/d/d-frontend.cc   |2 +-
 gcc/d/dmd/MERGE   |2 +-
 gcc/d/dmd/declaration.h   |   40 +-
 gcc/d/dmd/dinterpret.c|2 +-
 gcc/d/dmd/idgen.c |   38 +
 gcc/d/dmd/root/ctfloat.h  |   18 +
 gcc/d/intrinsics.cc   |7 +-
 gcc/d/intrinsics.def  |   53 +-
 gcc/testsuite/gdc.dg/intrinsics.d |3 +
 libphobos/libdruntime/MERGE   |2 +-
 libphobos/libdruntime/Makefile.am |   31 +-
 libphobos/libdruntime/Makefile.in |   48 +-
 libphobos/libdruntime/core/bitop.d|  145 ++-
 libphobos/libdruntime/core/checkedint.d   |   48 +-
 libphobos/libdruntime/core/cpuid.d|   69 +-
 libphobos/libdruntime/core/internal/traits.d  |  152 ++-
 libphobos/libdruntime/core/simd.d | 1096 ++---
 libphobos/libdruntime/core/stdc/stdio.d   |2 +-
 libphobos/libdruntime/core/sys/posix/locale.d |   28 +
 libphobos/libdruntime/core/thread/osthread.d  |8 -
 libphobos/libdruntime/core/vararg.d   |  122 ++
 libphobos/libdruntime/core/volatile.d |   67 +
 libphobos/libdruntime/rt/lifetime.d   |  109 +-
 .../tls_gc_integration.d  |2 +-
 25 files changed, 1329 insertions(+), 769 deletions(-)
 create mode 100644 libphobos/libdruntime/core/volatile.d

diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index 3f1533b592f..c45edc2fa3f 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -566,7 +566,7 @@ d_build_builtins_module (Module *m)
   STCextern, tf);
   DECL_LANG_SPECIFIC (decl) = build_lang_decl (func);
   func->csym = decl;
-  func->builtin = BUILTINyes;
+  func->builtin = BUILTINgcc;
 
   members->push (func);
 }
@@ -706,7 +706,7 @@ maybe_set_builtin_1 (Dsymbol *d)
  /* Found a match, tell the frontend this is a builtin.  */
  DECL_LANG_SPECIFIC (t) = build_lang_decl (fd);
  fd->csym = t;
- fd->builtin = BUILTINyes;
+ fd->builtin = BUILTINgcc;
  return;
}
 }
diff --git a/gcc/d/d-frontend.cc b/gcc/d/d-frontend.cc
index 32550ecfd64..84c70f8ee6a 100644
--- a/gcc/d/d-frontend.cc
+++ b/gcc/d/d-frontend.cc
@@ -158,7 +158,7 @@ isBuiltin (FuncDeclaration *fd)
 Expression *
 eval_builtin (Loc loc, FuncDeclaration *fd, Expressions *arguments)
 {
-  if (fd->builtin != BUILTINyes)
+  if (fd->builtin == BUILTINunimp)
 return NULL;
 
   tree decl = get_s

[committed] d: Remove the expansion of intrinsic and built-in codes from the DEF_D_INTRINSIC macro

2021-02-05 Thread Iain Buclaw via Gcc-patches
Hi,

This patch is a small tidy-up of the intrinsics.def file to make it
clear that the parameters refer to INTRINSIC and BUILT_IN codes.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* d-tree.h (DEF_D_INTRINSIC): Don't insert INTRINSIC_ into the
intrinsic code name.
* intrinsics.cc (DEF_D_INTRINSIC): Don't insert INTRISIC_ and
BUILT_IN_ into the intrinsic and built-in code names.
* intrinsics.def:  Explicitly use full intrinsic and built-in
codes in all definitions.
---
 gcc/d/d-tree.h   |   2 +-
 gcc/d/intrinsics.cc  |   2 +-
 gcc/d/intrinsics.def | 298 ---
 3 files changed, 195 insertions(+), 107 deletions(-)

diff --git a/gcc/d/d-tree.h b/gcc/d/d-tree.h
index c41969e36b1..724a0bfd87b 100644
--- a/gcc/d/d-tree.h
+++ b/gcc/d/d-tree.h
@@ -80,7 +80,7 @@ enum level_kind
 
 enum intrinsic_code
 {
-#define DEF_D_INTRINSIC(CODE, B, N, M, D, C) INTRINSIC_ ## CODE,
+#define DEF_D_INTRINSIC(CODE, B, N, M, D, C) CODE,
 
 #include "intrinsics.def"
 
diff --git a/gcc/d/intrinsics.cc b/gcc/d/intrinsics.cc
index 7f97c1d1fa8..539dc0c1f37 100644
--- a/gcc/d/intrinsics.cc
+++ b/gcc/d/intrinsics.cc
@@ -62,7 +62,7 @@ struct intrinsic_decl
 static const intrinsic_decl intrinsic_decls[] =
 {
 #define DEF_D_INTRINSIC(CODE, BUILTIN, NAME, MODULE, DECO, CTFE) \
-{ INTRINSIC_ ## CODE, BUILT_IN_ ## BUILTIN, NAME, MODULE, DECO, CTFE },
+{ CODE, BUILTIN, NAME, MODULE, DECO, CTFE },
 
 #include "intrinsics.def"
 
diff --git a/gcc/d/intrinsics.def b/gcc/d/intrinsics.def
index dc6b104f6d5..f5af2a5fe5c 100644
--- a/gcc/d/intrinsics.def
+++ b/gcc/d/intrinsics.def
@@ -36,133 +36,221 @@ along with GCC; see the file COPYING3.  If not see
 #define DEF_CTFE_BUILTIN(C, B, N, M, D) \
   DEF_D_INTRINSIC (C, B, N, M, D, true)
 
-DEF_D_BUILTIN (NONE, NONE, 0, 0, 0)
+DEF_D_BUILTIN (INTRINSIC_NONE, BUILT_IN_NONE, 0, 0, 0)
 
 /* core.bitop intrinsics.  */
 
-DEF_D_BUILTIN (BSF, NONE, "bsf", "core.bitop", "FNaNbNiNfkZi")
-DEF_D_BUILTIN (BSR, NONE, "bsr", "core.bitop", "FNaNbNiNfkZi")
-DEF_D_BUILTIN (BT, NONE, "bt", "core.bitop", "FNaNbNiMxPkkZi")
-DEF_D_BUILTIN (BTC, NONE, "btc", "core.bitop", "FNaNbNiPkkZi")
-DEF_D_BUILTIN (BTR, NONE, "btr", "core.bitop", "FNaNbNiPkkZi")
-DEF_D_BUILTIN (BTS, NONE, "bts", "core.bitop", "FNaNbNiPkkZi")
-DEF_D_BUILTIN (BSF64, NONE, "bsf", "core.bitop", "FNaNbNiNfmZi")
-DEF_D_BUILTIN (BSR64, NONE, "bsr", "core.bitop", "FNaNbNiNfmZi")
-DEF_D_BUILTIN (BT64, NONE, "bt", "core.bitop", "FNaNbNiMxPmmZi")
-DEF_D_BUILTIN (BTC64, NONE, "btc", "core.bitop", "FNaNbNiPmmZi")
-DEF_D_BUILTIN (BTR64, NONE, "btr", "core.bitop", "FNaNbNiPmmZi")
-DEF_D_BUILTIN (BTS64, NONE, "bts", "core.bitop", "FNaNbNiPmmZi")
-
-DEF_D_BUILTIN (BSWAP16, BSWAP16, "byteswap", "core.bitop", "FNaNbNiNftZt")
-DEF_D_BUILTIN (BSWAP32, BSWAP32, "bswap", "core.bitop", "FNaNbNiNfkZk")
-DEF_D_BUILTIN (BSWAP64, BSWAP64, "bswap", "core.bitop", "FNaNbNiNfmZm")
-
-DEF_D_BUILTIN (POPCNT32, NONE, "popcnt", "core.bitop", "FNaNbNiNfkZi")
-DEF_D_BUILTIN (POPCNT64, NONE, "popcnt", "core.bitop", "FNaNbNiNfmZi")
-
-DEF_D_BUILTIN (ROL, NONE, "rol", "core.bitop", "FNaI1TkZI1T")
-DEF_D_BUILTIN (ROL_TIARG, NONE, "rol", "core.bitop", "FNaI1TZI1T")
-DEF_D_BUILTIN (ROR, NONE, "ror", "core.bitop", "FNaI1TkZI1T")
-DEF_D_BUILTIN (ROR_TIARG, NONE, "ror", "core.bitop", "FNaI1TZI1T")
+DEF_D_BUILTIN (INTRINSIC_BSF, BUILT_IN_NONE, "bsf", "core.bitop",
+  "FNaNbNiNfkZi")
+DEF_D_BUILTIN (INTRINSIC_BSR, BUILT_IN_NONE, "bsr", "core.bitop",
+  "FNaNbNiNfkZi")
+DEF_D_BUILTIN (INTRINSIC_BT, BUILT_IN_NONE, "bt", "core.bitop",
+  "FNaNbNiMxPkkZi")
+DEF_D_BUILTIN (INTRINSIC_BTC, BUILT_IN_NONE, "btc", "core.bitop",
+  "FNaNbNiPkkZi")
+DEF_D_BUILTIN (INTRINSIC_BTR, BUILT_IN_NONE, "btr", "core.bitop",
+  "FNaNbNiPkkZi")
+DEF_D_BUILTIN (INTRINSIC_BTS, BUILT_IN_NONE, "bts", "core.bitop",
+  "FNaNbNiPkkZi")
+DEF_D_BUILTIN (INTRINSIC_BSF64, BUILT_IN_NONE, "bsf", "core.bitop",
+  "FNaNbNiNfmZi")
+DEF_D_BUILTIN (INTRINSIC_BSR64, BUILT_IN_NONE, "bsr", "core.bitop",
+  "FNaNbNiNfmZi")
+DEF_D_BUILTIN (INTRINSIC_BT64, BUILT_IN_NONE, "bt", "core.bitop",
+  "FNaNbNiMxPmmZi")
+DEF_D_BUILTIN (INTRINSIC_BTC64, BUILT_IN_NONE, "btc", "core.bitop",
+  "FNaNbNiPmmZi")
+DEF_D_BUILTIN (INTRINSIC_BTR64, BUILT_IN_NONE, "btr", "core.bitop",
+  "FNaNbNiPmmZi")
+DEF_D_BUILTIN (INTRINSIC_BTS64, BUILT_IN_NONE, "bts", "core.bitop",
+  "FNaNbNiPmmZi")
+
+DEF_D_BUILTIN (INTRINSIC_BSWAP16, BUILT_IN_BSWAP16, "byteswap", "core.bitop",
+  "FNaNbNiNftZt")
+DEF_D_BUILTIN (INTRINSIC_BSWAP32, BUILT_IN_BSWAP32, "bswap", "core.bitop",
+  "FNaNbNiNfkZk")
+DEF_D_BUILTIN (INTRINSIC_BSWAP64, BUILT_IN_BSWAP64, "bswap", "core.bitop",
+  "FNaNbNiNfmZm")
+
+DEF_D_BUILTIN (INTRINSIC_POPCNT32, BUILT_IN_N

[committed] d: Fix heap-buffer-overflow in checkModFileAlias [PR 99337]

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

This patch merges the D front-end implementation with upstream dmd,
fixing a heap-buffer-overflow in checkModFileAlias.  The code wrongly
assumed memcmp did not read past the mismatch.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

PR d/99337
* dmd/MERGE: Merge upstream dmd a3c9bf422.
---
 gcc/d/dmd/MERGE | 2 +-
 gcc/d/dmd/dmodule.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index 690fe407278..78b454c1c64 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-7132b3537dc27cb353da75798082ffe7ea3d69a6
+a3c9bf422e7ff54d45846b8c577ee82da4234db1
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
diff --git a/gcc/d/dmd/dmodule.c b/gcc/d/dmd/dmodule.c
index a2b01f534eb..ed01858f06b 100644
--- a/gcc/d/dmd/dmodule.c
+++ b/gcc/d/dmd/dmodule.c
@@ -195,7 +195,7 @@ static void checkModFileAlias(OutBuffer *buf, OutBuffer 
*dotmods,
 const char *m = (*ms)[j];
 const char *q = strchr(m, '=');
 assert(q);
-if (dotmods->length() <= (size_t)(q - m) && 
memcmp(dotmods->peekChars(), m, q - m) == 0)
+if (dotmods->length() == (size_t)(q - m) && 
memcmp(dotmods->peekChars(), m, q - m) == 0)
 {
 buf->reset();
 size_t qlen = strlen(q + 1);
-- 
2.27.0



[committed] d: Don't set default flag_complex_method.

2021-03-06 Thread Iain Buclaw via Gcc-patches
Hi,

This patch removes the default initializing of flag_complex_method in
the D front-end.  D doesn't need C99-like requirements for complex
multiply and divide, the default set by common.opt is sufficient enough.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* d-lang.cc (d_init_options_struct): Don't set default
flag_complex_method.
---
 gcc/d/d-lang.cc | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index 1a51c5e4b7c..0720cba1340 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -342,9 +342,6 @@ d_init_options_struct (gcc_options *opts)
   /* GCC options.  */
   opts->x_flag_exceptions = 1;
 
-  /* Avoid range issues for complex multiply and divide.  */
-  opts->x_flag_complex_method = 2;
-
   /* Unlike C, there is no global `errno' variable.  */
   opts->x_flag_errno_math = 0;
   opts->frontend_set_flag_errno_math = true;
-- 
2.27.0



[committed] d: ICE in gimple_register_canonical_type_1, at lto/lto-common.c:430 (PR102094)

2021-08-29 Thread Iain Buclaw via Gcc-patches
Hi,

User defined types have the TYPE_CXX_ODR_P flag set, but closure frames
did not.  This mismatch led to an ICE in the conflict detection for ODR
and interoperable non-ODR types.  As a given closure frame is tied
explicitly to a function, it already conforms to ODR.

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

Regards,
Iain

---
gcc/d/ChangeLog:

PR d/102094
* d-codegen.cc (build_frame_type): Set TYPE_CXX_ODR_P.

gcc/testsuite/ChangeLog:

PR d/102094
* gdc.dg/lto/pr102094_0.d: New test.
---
 gcc/d/d-codegen.cc|  1 +
 gcc/testsuite/gdc.dg/lto/pr102094_0.d | 18 ++
 2 files changed, 19 insertions(+)
 create mode 100644 gcc/testsuite/gdc.dg/lto/pr102094_0.d

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index fe2ad98e60a..ad20bd15403 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -2563,6 +2563,7 @@ build_frame_type (tree ffi, FuncDeclaration *fd)
 
   TYPE_FIELDS (frame_rec_type) = fields;
   TYPE_READONLY (frame_rec_type) = 1;
+  TYPE_CXX_ODR_P (frame_rec_type) = 1;
   layout_type (frame_rec_type);
   d_keep (frame_rec_type);
 
diff --git a/gcc/testsuite/gdc.dg/lto/pr102094_0.d 
b/gcc/testsuite/gdc.dg/lto/pr102094_0.d
new file mode 100644
index 000..f83631a1158
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/lto/pr102094_0.d
@@ -0,0 +1,18 @@
+// { dg-lto-do link }
+module pr102094_0;
+
+extern(C) int printf(char* s, ...);
+
+struct S102094
+{
+int a;
+}
+
+void main()
+{
+S102094 x;
+void nested()
+{
+printf(cast(char*)0, x);
+}
+}
-- 
2.30.2



[committed] d: Use POINTER_SIZE for testing whether to predefine D_LP64

2021-08-29 Thread Iain Buclaw via Gcc-patches
Hi,

This patch removes uses of global.params to get information about the
target.  Using POINTER_SIZE is assumed to be reliably set at the point
where predefined version conditions are inserted into the compilation.

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

Regards,
Iain

---
gcc/d/ChangeLog:

* d-builtins.cc (d_init_versions): Use POINTER_SIZE for testing
whether to predefine D_LP64.
---
 gcc/d/d-builtins.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index 328711fc745..ab39d69c294 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -462,7 +462,7 @@ d_init_versions (void)
   VersionCondition::addPredefinedGlobalIdent ("GNU_InlineAsm");
 
   /* LP64 only means 64bit pointers in D.  */
-  if (global.params.isLP64)
+  if (POINTER_SIZE == 64)
 VersionCondition::addPredefinedGlobalIdent ("D_LP64");
 
   /* Setting `global.params.cov' forces module info generation which is
-- 
2.30.2



[committed] d: Convert convert_for_rvalue switch statement into if condition

2021-08-29 Thread Iain Buclaw via Gcc-patches
Hi,

This patch replaces the switch statement in convert_for_rvalue with an
if condition.  In the D implementation of the D front-end, the condition
value has been changed to an `enum class` type.

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

Regards,
Iain

---
gcc/d/ChangeLog:

* d-convert.cc (convert_for_rvalue): Convert switch statement into if
condition.
---
 gcc/d/d-convert.cc | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/gcc/d/d-convert.cc b/gcc/d/d-convert.cc
index d43485dca77..3b4790298a5 100644
--- a/gcc/d/d-convert.cc
+++ b/gcc/d/d-convert.cc
@@ -613,9 +613,8 @@ convert_for_rvalue (tree expr, Type *etype, Type *totype)
   Type *ebtype = etype->toBasetype ();
   Type *tbtype = totype->toBasetype ();
 
-  switch (ebtype->ty)
+  if (ebtype->ty == Tbool)
 {
-case Tbool:
   /* 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))
@@ -633,7 +632,6 @@ convert_for_rvalue (tree expr, Type *etype, Type *totype)
}
 
   result = convert (build_ctype (tbtype), result);
-  break;
 }
 
   return result ? result : convert_expr (expr, etype, totype);
-- 
2.30.2



[committed] d: Get __c_wchar_t type from build_frontend_type

2021-08-29 Thread Iain Buclaw via Gcc-patches
Hi

This patch uses build_frontend_type to get the underlying type for
__c_wchar_t.  The previous field has been removed from the upstream D
implementation of the D front-end.

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

Regards,
Iain

---
gcc/d/ChangeLog:

* types.cc (TypeVisitor::visit(TypeEnum*)): Get wchar_t type from
build_frontend_type.
---
 gcc/d/types.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index 8e674618004..fc8a1330696 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -886,7 +886,8 @@ public:
else if (strcmp (ident, "ulong") == 0)
  underlying = build_frontend_type (long_unsigned_type_node);
else if (strcmp (ident, "wchar_t") == 0)
- underlying = target.c.twchar_t;
+ underlying =
+   build_frontend_type (make_unsigned_type (WCHAR_TYPE_SIZE));
else if (strcmp (ident, "longlong") == 0)
  underlying = build_frontend_type (long_long_integer_type_node);
else if (strcmp (ident, "ulonglong") == 0)
-- 
2.30.2



[committed] d: Use `int` to store class and struct flags

2021-08-29 Thread Iain Buclaw via Gcc-patches
Hi,

This patch replaces ClassFlags and StructFlags with an int.  In the D
implementation of the D front-end, this type has been changed to an
`enum class`.

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

Regards,
Iain

---
gcc/d/ChangeLog:

* typeinfo.cc (TypeInfoVisitor::visit(TypeInfoClassDeclaration *)):
Use int to store type flags.
(TypeInfoVisitor::visit(TypeInfoStructDeclaration *)): Likewise.
---
 gcc/d/typeinfo.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/d/typeinfo.cc b/gcc/d/typeinfo.cc
index 978c73e65f6..04e228abf7c 100644
--- a/gcc/d/typeinfo.cc
+++ b/gcc/d/typeinfo.cc
@@ -868,7 +868,7 @@ public:
this->layout_field (inv);
 
/* ClassFlags m_flags;  */
-   ClassFlags::Type flags = ClassFlags::hasOffTi;
+   int flags = ClassFlags::hasOffTi;
if (cd->isCOMclass ())
  flags |= ClassFlags::isCOMclass;
 
@@ -962,7 +962,7 @@ public:
this->layout_field (null_pointer_node);
 
/* ClassFlags m_flags;  */
-   ClassFlags::Type flags = ClassFlags::hasOffTi;
+   int flags = ClassFlags::hasOffTi;
flags |= ClassFlags::hasTypeInfo;
if (cd->isCOMinterface ())
  flags |= ClassFlags::isCOMclass;
@@ -1091,7 +1091,7 @@ public:
   this->layout_field (null_pointer_node);
 
 /* StructFlags m_flags;  */
-StructFlags::Type m_flags = 0;
+int m_flags = StructFlags::none;
 if (ti->hasPointers ())
   m_flags |= StructFlags::hasPointers;
 this->layout_field (build_integer_cst (m_flags, d_uint_type));
-- 
2.30.2



[committed] d: Update comment for TypeInfoVisitor::layout_base

2021-08-29 Thread Iain Buclaw via Gcc-patches
Hi,

This patch updates the comment for TypeInfoVisitor::layout_base to
reflect a recent change that made the emission of a __monitor optional.

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

Regards,
Iain

---
gcc/d/ChangeLog:

* typeinfo.cc (class TypeInfoVisitor::layout_base): Update comment.
---
 gcc/d/typeinfo.cc | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/gcc/d/typeinfo.cc b/gcc/d/typeinfo.cc
index 04e228abf7c..fd8c746a307 100644
--- a/gcc/d/typeinfo.cc
+++ b/gcc/d/typeinfo.cc
@@ -411,8 +411,7 @@ class TypeInfoVisitor : public Visitor
 this->layout_field (value);
   }
 
-
-  /* Write out the __vptr and __monitor fields of class CD.  */
+  /* Write out the __vptr and optionally __monitor fields of class CD.  */
 
   void layout_base (ClassDeclaration *cd)
   {
-- 
2.30.2



[committed] d: Call the assertp and boundsp variants for assert and array contract failures.

2021-08-29 Thread Iain Buclaw via Gcc-patches
Hi,

This patch updates the code generator to call _d_assertp or
_d_arrayboundsp when an assert or array bounds check fails respectively.
These functions accept an `immutable(char)*` instead of an
`immutable(char)[]`.  The subtle difference being that the length of the
string no longer has to be included in the generated code.

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

Regards,
Iain

---
gcc/d/ChangeLog:

* d-codegen.cc: Include dmd/module.h.
(build_filename_from_loc): New function.
(d_assert_call): Rename to...
(build_assert_call): ...this.
(build_array_bounds_call): Call arrayboundsp variant of the array
bounds failure callback.
(build_bounds_condition): Rename to...
(build_bounds_index_condition): ...this.  Update signature.
(build_bounds_slice_condition): New function.
(checkaction_trap_p): New function.
(d_assert_call): Call assertp variant of assert failure callback.
* d-tree.h (class IndexExp): Declare.
(class SliceExp): Declare.
(build_bounds_condition): Remove.
(build_assert_call): Declare.
(build_bounds_index_condition): Declare.
(build_bounds_slice_condition): Declare.
(checkaction_trap_p): Declare.
(d_assert_call): Remove.
* expr.cc (ExprVisitor::visit(IndexExp *)): Call
build_bounds_index_condition.
(ExprVisitor::visit(SliceExp *)): Call build_bounds_slice_condition.
(ExprVisitor::visit(AssertExp *)): Update setting of libcall.
* runtime.cc (enum d_libcall_type): Add LCT_IMMUTABLE_CHARPTR.
(get_libcall_type): Handle LCT_IMMUTABLE_CHARPTR.
* runtime.def (ASSERT): Rename to...
(ASSERTP): ...this.  Update signature.
(UNITTEST): Rename to...
(UNITTESTP): ...this.  Update signature.
(ARRAY_BOUNDS): Rename to...
(ARRAYBOUNDSP): ...this.  Updates signature.
* toir.cc (IRVisitor::visit(SwitchErrorStatement *)): Update call.
---
 gcc/d/d-codegen.cc | 185 ++---
 gcc/d/d-tree.h |   8 +-
 gcc/d/expr.cc  |  58 ++
 gcc/d/runtime.cc   |   5 ++
 gcc/d/runtime.def  |  24 +++---
 gcc/d/toir.cc  |   2 +-
 6 files changed, 173 insertions(+), 109 deletions(-)

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index ad20bd15403..e63365055d3 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "dmd/ctfe.h"
 #include "dmd/declaration.h"
 #include "dmd/identifier.h"
+#include "dmd/module.h"
 #include "dmd/target.h"
 #include "dmd/template.h"
 
@@ -1831,50 +1832,149 @@ void_okay_p (tree t)
   return t;
 }
 
-/* Builds a CALL_EXPR at location LOC in the source file to execute when an
-   array bounds check fails.  */
+/* Builds a STRING_CST representing the filename of location LOC.  When the
+   location is not valid, the name of the source module is used instead.  */
+
+static tree
+build_filename_from_loc (const Loc &loc)
+{
+  const char *filename = loc.filename
+? loc.filename : d_function_chain->module->srcfile->toChars ();
+
+  unsigned length = strlen (filename);
+  tree str = build_string (length, filename);
+  TREE_TYPE (str) = make_array_type (Type::tchar, length + 1);
+
+  return build_address (str);
+}
+
+/* Builds a CALL_EXPR at location LOC in the source file to call LIBCALL when
+   an assert check fails.  When calling the msg variant functions, MSG is the
+   error message supplied by the user.  */
 
 tree
-build_array_bounds_call (const Loc &loc)
+build_assert_call (const Loc &loc, libcall_fn libcall, tree msg)
 {
-  switch (global.params.checkAction)
+  tree file;
+  tree line = size_int (loc.linnum);
+
+  switch (libcall)
 {
-case CHECKACTION_D:
-  return d_assert_call (loc, LIBCALL_ARRAY_BOUNDS);
+case LIBCALL_ASSERT_MSG:
+case LIBCALL_UNITTEST_MSG:
+case LIBCALL_SWITCH_ERROR:
+  /* File location is passed as a D string.  */
+  if (loc.filename)
+   {
+ unsigned len = strlen (loc.filename);
+ tree str = build_string (len, loc.filename);
+ TREE_TYPE (str) = make_array_type (Type::tchar, len);
 
-case CHECKACTION_C:
-case CHECKACTION_halt:
-  return build_call_expr (builtin_decl_explicit (BUILT_IN_TRAP), 0);
+ file = d_array_value (build_ctype (Type::tchar->arrayOf ()),
+   size_int (len), build_address (str));
+   }
+  else
+   file = null_array_node;
+  break;
+
+case LIBCALL_ASSERTP:
+case LIBCALL_UNITTESTP:
+  file = build_filename_from_loc (loc);
+  break;
 
 default:
   gcc_unreachable ();
 }
+
+
+  if (msg != NULL_TREE)
+return build_libcall (libcall, Type::tvoid, 3, msg, file, line);
+  else
+return build_libcall (libcall, Type::tvoid, 2, file, line);
 }
 
-/* Builds a bounds condition 

[PATCH 1/3] libiberty: Add support for D `typeof(*null)' types

2021-08-29 Thread Iain Buclaw via Gcc-patches
Hi,

The D language has a new bottom type `typeof(*null)'.  Null types were
also incorrectly being demangled as `none', this has been fixed to be
`typeof(null)'.

Bootstrapped and regression tested on x86_64-linux-gnu.

OK for mainline?

Regards,
Iain.

---
libiberty/ChangeLog:

* d-demangle.c (dlang_attributes): Handle typeof(*null).
(dlang_type): Likewise.  Demangle 'n' as typeof(null).
* testsuite/d-demangle-expected: Update tests.
---
 libiberty/d-demangle.c  | 12 ++--
 libiberty/testsuite/d-demangle-expected |  6 +-
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c
index 822c7580782..c34f91843de 100644
--- a/libiberty/d-demangle.c
+++ b/libiberty/d-demangle.c
@@ -573,9 +573,11 @@ dlang_attributes (string *decl, const char *mangled)
case 'g':
case 'h':
case 'k':
+   case 'n':
  /* inout parameter is represented as 'Ng'.
 vector parameter is represented as 'Nh'.
-return paramenter is represented as 'Nk'.
+return parameter is represented as 'Nk'.
+typeof(*null) parameter is represented as 'Nn'.
 If we see this, then we know we're really in the
 parameter list.  Rewind and break.  */
  mangled--;
@@ -787,6 +789,12 @@ dlang_type (string *decl, const char *mangled, struct 
dlang_info *info)
  string_append (decl, ")");
  return mangled;
}
+  else if (*mangled == 'n') /* typeof(*null) */
+   {
+ mangled++;
+ string_append (decl, "typeof(*null)");
+ return mangled;
+   }
   else
return NULL;
 case 'A': /* dynamic array (T[]) */
@@ -884,7 +892,7 @@ dlang_type (string *decl, const char *mangled, struct 
dlang_info *info)
 /* Basic types */
 case 'n':
   mangled++;
-  string_append (decl, "none");
+  string_append (decl, "typeof(null)");
   return mangled;
 case 'v':
   mangled++;
diff --git a/libiberty/testsuite/d-demangle-expected 
b/libiberty/testsuite/d-demangle-expected
index ba0ffed5c8d..00036e7810a 100644
--- a/libiberty/testsuite/d-demangle-expected
+++ b/libiberty/testsuite/d-demangle-expected
@@ -83,7 +83,11 @@ demangle.test(ulong)
 #
 --format=dlang
 _D8demangle4testFnZv
-demangle.test(none)
+demangle.test(typeof(null))
+#
+--format=dlang
+_D8demangle4testFNnZv
+demangle.test(typeof(*null))
 #
 --format=dlang
 _D8demangle4testFoZv
-- 
2.30.2



[PATCH 2/3] libiberty: Add support for demangling D function literals as template value parameters

2021-08-29 Thread Iain Buclaw via Gcc-patches
Hi,

The D language now allows instantiating templates using struct literals
that have function literal fields as a value argument.

Bootstrapped and regression tested on x86_64-linux-gnu.

OK for mainline?

Regards,
Iain.

---
libiberty/ChangeLog:

* d-demangle.c (dlang_parse_arrayliteral): Add 'info' parameter.
(dlang_parse_assocarray): Likewise.
(dlang_parse_structlit): Likewise.
(dlang_value): Likewise.  Handle function literal symbols.
(dlang_template_args): Pass 'info' to dlang_value.
* testsuite/d-demangle-expected: Add new test.
---
 libiberty/d-demangle.c  | 40 +
 libiberty/testsuite/d-demangle-expected |  4 +++
 2 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c
index c34f91843de..d74cf47b1a9 100644
--- a/libiberty/d-demangle.c
+++ b/libiberty/d-demangle.c
@@ -191,7 +191,8 @@ static const char *dlang_function_args (string *, const 
char *,
 
 static const char *dlang_type (string *, const char *, struct dlang_info *);
 
-static const char *dlang_value (string *, const char *, const char *, char);
+static const char *dlang_value (string *, const char *, const char *, char,
+   struct dlang_info *);
 
 static const char *dlang_parse_qualified (string *, const char *,
  struct dlang_info *, int);
@@ -1386,7 +1387,8 @@ dlang_parse_string (string *decl, const char *mangled)
 /* Extract the static array value from MANGLED and append it to DECL.
Return the remaining string on success or NULL on failure.  */
 static const char *
-dlang_parse_arrayliteral (string *decl, const char *mangled)
+dlang_parse_arrayliteral (string *decl, const char *mangled,
+ struct dlang_info *info)
 {
   unsigned long elements;
 
@@ -1397,7 +1399,7 @@ dlang_parse_arrayliteral (string *decl, const char 
*mangled)
   string_append (decl, "[");
   while (elements--)
 {
-  mangled = dlang_value (decl, mangled, NULL, '\0');
+  mangled = dlang_value (decl, mangled, NULL, '\0', info);
   if (mangled == NULL)
return NULL;
 
@@ -1412,7 +1414,8 @@ dlang_parse_arrayliteral (string *decl, const char 
*mangled)
 /* Extract the associative array value from MANGLED and append it to DECL.
Return the remaining string on success or NULL on failure.  */
 static const char *
-dlang_parse_assocarray (string *decl, const char *mangled)
+dlang_parse_assocarray (string *decl, const char *mangled,
+   struct dlang_info *info)
 {
   unsigned long elements;
 
@@ -1423,12 +1426,12 @@ dlang_parse_assocarray (string *decl, const char 
*mangled)
   string_append (decl, "[");
   while (elements--)
 {
-  mangled = dlang_value (decl, mangled, NULL, '\0');
+  mangled = dlang_value (decl, mangled, NULL, '\0', info);
   if (mangled == NULL)
return NULL;
 
   string_append (decl, ":");
-  mangled = dlang_value (decl, mangled, NULL, '\0');
+  mangled = dlang_value (decl, mangled, NULL, '\0', info);
   if (mangled == NULL)
return NULL;
 
@@ -1443,7 +1446,8 @@ dlang_parse_assocarray (string *decl, const char *mangled)
 /* Extract the struct literal value for NAME from MANGLED and append it to 
DECL.
Return the remaining string on success or NULL on failure.  */
 static const char *
-dlang_parse_structlit (string *decl, const char *mangled, const char *name)
+dlang_parse_structlit (string *decl, const char *mangled, const char *name,
+  struct dlang_info *info)
 {
   unsigned long args;
 
@@ -1457,7 +1461,7 @@ dlang_parse_structlit (string *decl, const char *mangled, 
const char *name)
   string_append (decl, "(");
   while (args--)
 {
-  mangled = dlang_value (decl, mangled, NULL, '\0');
+  mangled = dlang_value (decl, mangled, NULL, '\0', info);
   if (mangled == NULL)
return NULL;
 
@@ -1472,7 +1476,8 @@ dlang_parse_structlit (string *decl, const char *mangled, 
const char *name)
 /* Extract the value from MANGLED and append it to DECL.
Return the remaining string on success or NULL on failure.  */
 static const char *
-dlang_value (string *decl, const char *mangled, const char *name, char type)
+dlang_value (string *decl, const char *mangled, const char *name, char type,
+struct dlang_info *info)
 {
   if (mangled == NULL || *mangled == '\0')
 return NULL;
@@ -1533,15 +1538,24 @@ dlang_value (string *decl, const char *mangled, const 
char *name, char type)
 case 'A':
   mangled++;
   if (type == 'H')
-   mangled = dlang_parse_assocarray (decl, mangled);
+   mangled = dlang_parse_assocarray (decl, mangled, info);
   else
-   mangled = dlang_parse_arrayliteral (decl, mangled);
+   mangled = dlang_parse_arrayliteral (decl, mangled, info);
   break;
 
   /* Struct values.  */
 case 'S':
   mangled++;
-  mangled = 

[PATCH 3/3] libiberty: Add support for demangling local D template declarations

2021-08-29 Thread Iain Buclaw via Gcc-patches
Hi,

The D language now allows multiple different template declarations in
the same function that have the same mangled name.  To make the mangled
names unique, a fake parent in the form `__Sddd' is added to the symbol.
This information is not important for the user, so the demangler now
handles and ignores it.

Bootstrapped and regression tested on x86_64-linux-gnu.

OK for mainline?

Regards,
Iain.

---
libiberty/ChangeLog:

* d-demangle.c (dlang_identifier): Skip over fake parent manglings.
* testsuite/d-demangle-expected: Add tests.
---
 libiberty/d-demangle.c  | 19 +++
 libiberty/testsuite/d-demangle-expected | 24 
 2 files changed, 43 insertions(+)

diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c
index d74cf47b1a9..a2152cc6551 100644
--- a/libiberty/d-demangle.c
+++ b/libiberty/d-demangle.c
@@ -1044,6 +1044,25 @@ dlang_identifier (string *decl, const char *mangled, 
struct dlang_info *info)
   && (mangled[2] == 'T' || mangled[2] == 'U'))
 return dlang_parse_template (decl, mangled, info, len);
 
+  /* There can be multiple different declarations in the same function that 
have
+ the same mangled name.  To make the mangled names unique, a fake parent in
+ the form `__Sddd' is added to the symbol.  */
+  if (len >= 4 && mangled[0] == '_' && mangled[1] == '_' && mangled[2] == 'S')
+{
+  const char *numptr = mangled + 3;
+  while (numptr < (mangled + len) && ISDIGIT (*numptr))
+   numptr++;
+
+  if (mangled + len == numptr)
+   {
+ /* Skip over the fake parent.  */
+ mangled += len;
+ return dlang_identifier (decl, mangled, info);
+   }
+
+  /* else demangle it as a plain identifier.  */
+}
+
   return dlang_lname (decl, mangled, len);
 }
 
diff --git a/libiberty/testsuite/d-demangle-expected 
b/libiberty/testsuite/d-demangle-expected
index 87ed8d330a8..c35185c3e1e 100644
--- a/libiberty/testsuite/d-demangle-expected
+++ b/libiberty/testsuite/d-demangle-expected
@@ -1420,5 +1420,29 @@ 
_D3std3uni__T6toCaseS_DQvQt12toLowerIndexFNaNbNiNewZtVii1043S_DQCjQCi10toLowerTa
 std.uni.toCase!(std.uni.toLowerIndex(dchar), 1043, std.uni.toLowerTab(ulong), 
std.ascii.toLower, 
immutable(char)[]).toCase(immutable(char)[]).__foreachbody2(ref ulong, ref 
dchar).__foreachbody3(ref dchar)
 #
 --format=dlang
+_D8demangle4mainFZ1xi
+demangle.main().x
+#
+--format=dlang
+_D8demangle4mainFZ4__S11xi
+demangle.main().x
+#
+--format=dlang
+_D8demangle4mainFZ1fMFNaNbNiNfZv
+demangle.main().f()
+#
+--format=dlang
+_D8demangle4mainFZ4__S11fMFNaNbNiNfZv
+demangle.main().f()
+#
+--format=dlang
+_D3mod4funcFZ__T6nestedTiZQkMFNaNbNiNfZi
+mod.func().nested!(int).nested()
+#
+--format=dlang
+_D3mod4funcFZ__T6nestedTiZ4__S1QpMFNaNbNiNfZi
+mod.func().nested!(int).nested()
+#
+--format=dlang
 _D6mangle__T8fun21753VSQv6S21753S1f_DQBj10__lambda71MFNaNbNiNfZvZQCbQp
 mangle.fun21753!(mangle.S21753(mangle.__lambda71())).fun21753
-- 
2.30.2



Re: [PATCH 1/3] libiberty: Add support for D `typeof(*null)' types

2021-08-29 Thread Iain Buclaw via Gcc-patches
Excerpts from Jeff Law's message of August 29, 2021 10:55 pm:
> 
> 
> On 8/29/2021 12:46 PM, Iain Buclaw via Gcc-patches wrote:
>> Hi,
>>
>> The D language has a new bottom type `typeof(*null)'.  Null types were
>> also incorrectly being demangled as `none', this has been fixed to be
>> `typeof(null)'.
>>
>> Bootstrapped and regression tested on x86_64-linux-gnu.
>>
>> OK for mainline?
>>
>> Regards,
>> Iain.
>>
>> ---
>> libiberty/ChangeLog:
>>
>>  * d-demangle.c (dlang_attributes): Handle typeof(*null).
>>  (dlang_type): Likewise.  Demangle 'n' as typeof(null).
>>  * testsuite/d-demangle-expected: Update tests.
> I'd argue anything in d-demangle would fall under your maintainership 
> for D.  So, OK and similarly for the other two D demangling patches.
> 
> jeff
> 

OK, I'll keep that in mind for future ABI updates.

Thanks,
Iain.


[committed] libphobos: Compile configure tests with -fno-druntime

2021-08-30 Thread Iain Buclaw via Gcc-patches
Hi,

This patch changes WITH_LOCAL_DRUNTIME to build with `-fno-druntime'.
The D tests done at configure-time for libphobos don't require a
functional D run-time, so don't enable any run-time features.

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

Regards,
Iain.

---
libphobos/ChangeLog:

* configure: Regenerate.
* m4/autoconf.m4 (AC_LANG_PROGRAM): Declare module name 'object'.
* m4/gcc_support.m4 (WITH_LOCAL_DRUNTIME): Compile tests with
-fno-druntime.
---
 libphobos/configure | 28 ++--
 libphobos/m4/autoconf.m4|  2 +-
 libphobos/m4/gcc_support.m4 |  2 +-
 3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/libphobos/configure b/libphobos/configure
index b1c8ecb5673..14298a0dc4f 100755
--- a/libphobos/configure
+++ b/libphobos/configure
@@ -5382,7 +5382,7 @@ fi
 
 
   gdc_save_DFLAGS=$GDCFLAGS
-  GDCFLAGS="-fno-moduleinfo -nostdinc -I $phobos_cv_abs_srcdir/libdruntime  
$GDCFLAGS"
+  GDCFLAGS="-fno-druntime -nostdinc -I $phobos_cv_abs_srcdir/libdruntime  
$GDCFLAGS"
 
   ac_ext=d
 ac_compile='$GDC -c $GDCFLAGS conftest.$ac_ext >&5'
@@ -5392,7 +5392,7 @@ ac_compiler_gnu=yes
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking If $GDC can compile D 
sources" >&5
 $as_echo_n "checking If $GDC can compile D sources... " >&6; }
 cat > conftest.$ac_ext <<_ACEOF
-module mod;
+module object;
 
 
 extern(C) int main() {
@@ -12097,7 +12097,7 @@ CC="$lt_save_CC"
 
 
   gdc_save_DFLAGS=$GDCFLAGS
-  GDCFLAGS="-fno-moduleinfo -nostdinc -I $phobos_cv_abs_srcdir/libdruntime  
$GDCFLAGS"
+  GDCFLAGS="-fno-druntime -nostdinc -I $phobos_cv_abs_srcdir/libdruntime  
$GDCFLAGS"
 
 
 # Source file extension for D test sources.
@@ -14089,7 +14089,7 @@ fi
 
 
   gdc_save_DFLAGS=$GDCFLAGS
-  GDCFLAGS="-fno-moduleinfo -nostdinc -I $phobos_cv_abs_srcdir/libdruntime 
-nophoboslib $GDCFLAGS"
+  GDCFLAGS="-fno-druntime -nostdinc -I $phobos_cv_abs_srcdir/libdruntime 
-nophoboslib $GDCFLAGS"
 
 ac_ext=d
 ac_compile='$GDC -c $GDCFLAGS conftest.$ac_ext >&5'
@@ -14098,7 +14098,7 @@ ac_compiler_gnu=yes
 
 GDCFLAGS="$GDCFLAGS -g -Werror -ffunction-sections -fdata-sections"
 cat > conftest.$ac_ext <<_ACEOF
-module mod;
+module object;
 int foo; void bar() { }
 
 extern(C) int main() {
@@ -14562,7 +14562,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 
   gdc_save_DFLAGS=$GDCFLAGS
-  GDCFLAGS="-fno-moduleinfo -nostdinc -I $phobos_cv_abs_srcdir/libdruntime 
-nophoboslib $GDCFLAGS"
+  GDCFLAGS="-fno-druntime -nostdinc -I $phobos_cv_abs_srcdir/libdruntime 
-nophoboslib $GDCFLAGS"
 
   ac_ext=d
 ac_compile='$GDC -c $GDCFLAGS conftest.$ac_ext >&5'
@@ -14576,7 +14576,7 @@ if ${ac_cv_search_malloc+:} false; then :
 else
   ac_func_search_save_LIBS=$LIBS
 cat > conftest.$ac_ext <<_ACEOF
-module mod;
+module object;
  extern(C) int malloc();
 
 extern(C) int main() {
@@ -14622,7 +14622,7 @@ if ${ac_cv_search_pthread_create+:} false; then :
 else
   ac_func_search_save_LIBS=$LIBS
 cat > conftest.$ac_ext <<_ACEOF
-module mod;
+module object;
  extern(C) int pthread_create();
 
 extern(C) int main() {
@@ -14668,7 +14668,7 @@ if ${ac_cv_search_cosf+:} false; then :
 else
   ac_func_search_save_LIBS=$LIBS
 cat > conftest.$ac_ext <<_ACEOF
-module mod;
+module object;
  extern(C) int cosf();
 
 extern(C) int main() {
@@ -14714,7 +14714,7 @@ if ${ac_cv_search_clock_gettime+:} false; then :
 else
   ac_func_search_save_LIBS=$LIBS
 cat > conftest.$ac_ext <<_ACEOF
-module mod;
+module object;
  extern(C) int clock_gettime();
 
 extern(C) int main() {
@@ -14765,7 +14765,7 @@ $as_echo_n "checking for atomic builtins for byte... " 
>&6; }
 else
 
 cat > conftest.$ac_ext <<_ACEOF
-module mod;
+module object;
 import gcc.builtins;
 
 extern(C) int main() {
@@ -14799,7 +14799,7 @@ $as_echo_n "checking for atomic builtins for short... " 
>&6; }
 else
 
 cat > conftest.$ac_ext <<_ACEOF
-module mod;
+module object;
 import gcc.builtins;
 
 extern(C) int main() {
@@ -14833,7 +14833,7 @@ $as_echo_n "checking for atomic builtins for int... " 
>&6; }
 else
 
 cat > conftest.$ac_ext <<_ACEOF
-module mod;
+module object;
 import gcc.builtins;
 
 extern(C) int main() {
@@ -14867,7 +14867,7 @@ $as_echo_n "checking for atomic builtins for long... " 
>&6; }
 else
 
 cat > conftest.$ac_ext <<_ACEOF
-module mod;
+module object;
 import gcc.builtins;
 
 extern(C) int main() {
diff --git a/libphobos/m4/autoconf.m4 b/libphobos/m4/autoconf.m4
index f46a7809f43..f0ca947478c 100644
--- a/libphobos/m4/autoconf.m4
+++ b/libphobos/m4/autoconf.m4
@@ -27,7 +27,7 @@ AU_DEFUN([AC_LANG_D], [AC_LANG(D)])
 # AC_LANG_PROGRAM(D)([PROLOGUE], [BODY])
 # ---
 m4_define([AC_LANG_PROGRAM(D)],
-[module mod;
+[module object;
 $1
 
 extern(C) int main() {
diff --git a/libphobos/m4/gcc_support.m4 b/libphobos/m4/gcc_support.m4
index 0903ed4b45f..cc1acb4a230 100644
--- a/libphobos/m4/gcc_support.m4
+++ b/libphobos/m4/

[committed] d: Build TYPE_DECLs for non-numeric enum types.

2020-09-12 Thread Iain Buclaw via Gcc-patches
Hi,

This patch alters TYPE_DECL generation to also build one for enums whose
member type is non-numeric.

This is done so that the DWARF pass will emit a DW_TAG_typedef where the
member type of an enum can't be represented in an ENUMERAL_TYPE.

Bootstrapped and regression tested on x86_64-linux-gnu/0m32/-mx32.
Committed to mainline.

Regards
Iain

---
gcc/d/ChangeLog:

* d-builtins.cc (d_build_d_type_nodes): Call build_ctype() on all
basic front-end types.
* decl.cc (DeclVisitor::visit (EnumDeclaration *)): Always add decl to
current binding level.
(build_type_decl): Build TYPE_DECL as a typedef if not for an enum or
record type.
* types.cc (TypeVisitor::visit (TypeEnum *)): Set underlying type for
ENUMERAL_TYPEs.  Build TYPE_DECL for non-numeric enums.
---
 gcc/d/d-builtins.cc |  8 
 gcc/d/decl.cc   | 22 --
 gcc/d/types.cc  |  5 -
 3 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index e3d7adc2deb..72e2d3a7168 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -848,6 +848,14 @@ d_build_d_type_nodes (void)
   ireal_type_node = build_distinct_type_copy (long_double_type_node);
   TYPE_IMAGINARY_FLOAT (ireal_type_node) = 1;
 
+  /* Calling build_ctype() links the front-end Type to the GCC node,
+ and sets the TYPE_NAME to the D language type.  */
+  for (unsigned ty = 0; ty < TMAX; ty++)
+{
+  if (Type::basic[ty] != NULL)
+   build_ctype (Type::basic[ty]);
+}
+
   /* Used for ModuleInfo, ClassInfo, and Interface decls.  */
   unknown_type_node = make_node (RECORD_TYPE);
 
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 59844bc8633..161a85a842b 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -618,13 +618,13 @@ public:
  d_linkonce_linkage (d->sinit);
 
d_finish_decl (d->sinit);
-
-   /* Add this decl to the current binding level.  */
-   tree ctype = build_ctype (d->type);
-   if (TREE_CODE (ctype) == ENUMERAL_TYPE && TYPE_NAME (ctype))
- d_pushdecl (TYPE_NAME (ctype));
   }
 
+/* Add this decl to the current binding level.  */
+tree ctype = build_ctype (d->type);
+if (TYPE_NAME (ctype))
+  d_pushdecl (TYPE_NAME (ctype));
+
 d->semanticRun = PASSobj;
   }
 
@@ -2270,8 +2270,6 @@ build_type_decl (tree type, Dsymbol *dsym)
   if (TYPE_STUB_DECL (type))
 return;
 
-  gcc_assert (!POINTER_TYPE_P (type));
-
   /* If a templated type, use the template instance name, as that includes all
  template parameters.  */
   const char *name = dsym->parent->isTemplateInstance ()
@@ -2281,7 +2279,6 @@ build_type_decl (tree type, Dsymbol *dsym)
  get_identifier (name), type);
   SET_DECL_ASSEMBLER_NAME (decl, get_identifier (d_mangle_decl (dsym)));
   TREE_PUBLIC (decl) = 1;
-  DECL_ARTIFICIAL (decl) = 1;
   DECL_CONTEXT (decl) = d_decl_context (dsym);
 
   TYPE_CONTEXT (type) = DECL_CONTEXT (decl);
@@ -2290,9 +2287,14 @@ build_type_decl (tree type, Dsymbol *dsym)
   /* Not sure if there is a need for separate TYPE_DECLs in
  TYPE_NAME and TYPE_STUB_DECL.  */
   if (TREE_CODE (type) == ENUMERAL_TYPE || RECORD_OR_UNION_TYPE_P (type))
-TYPE_STUB_DECL (type) = decl;
+{
+  DECL_ARTIFICIAL (decl) = 1;
+  TYPE_STUB_DECL (type) = decl;
+}
+  else if (type != TYPE_MAIN_VARIANT (type))
+DECL_ORIGINAL_TYPE (decl) = TYPE_MAIN_VARIANT (type);
 
-  rest_of_decl_compilation (decl, SCOPE_FILE_SCOPE_P (decl), 0);
+  rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0);
 }
 
 /* Create a declaration for field NAME of a given TYPE, setting the flags
diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index 994d0b9195b..6df1e78c074 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -859,14 +859,17 @@ public:
   For these, we simplify this a little by using the base type directly
   instead of building an ENUMERAL_TYPE.  */
t->ctype = build_variant_type_copy (basetype);
+   build_type_decl (t->ctype, t->sym);
   }
 else
   {
t->ctype = make_node (ENUMERAL_TYPE);
-   ENUM_IS_SCOPED (t->ctype) = 1;
TYPE_LANG_SPECIFIC (t->ctype) = build_lang_type (t);
d_keep (t->ctype);
 
+   ENUM_IS_SCOPED (t->ctype) = 1;
+   TREE_TYPE (t->ctype) = basetype;
+
if (flag_short_enums)
  TYPE_PACKED (t->ctype) = 1;
 
-- 
2.25.1



[committed] d: Return promoted types in d_type_promotes_to when linkage is not D

2020-09-12 Thread Iain Buclaw via Gcc-patches
Hi,

This enables warnings to be shown when a wrong type is passed to va_arg
inside an extern(C) or extern(C++) function.

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

Regards
Iain

---
gcc/d/ChangeLog:

PR d/97002
* d-codegen.cc (d_build_call): Set input_location on CALL_EXPR.
* d-lang.cc: Include function.h.
(d_type_promotes_to): Do default conversions for C and C++ functions.
* intrinsics.cc (expand_intrinsic_vaarg): Use build1_loc to build
VA_ARG_EXPR.

gcc/testsuite/ChangeLog:

PR d/97002
* gdc.dg/pr97002.d: New test.
---
 gcc/d/d-codegen.cc |  1 +
 gcc/d/d-lang.cc| 58 --
 gcc/d/intrinsics.cc|  2 +-
 gcc/testsuite/gdc.dg/pr97002.d | 55 
 4 files changed, 113 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/pr97002.d

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 4050b85af28..1f2d65c4ae2 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -2042,6 +2042,7 @@ d_build_call (TypeFunction *tf, tree callable, tree 
object,
 }
 
   tree result = build_call_vec (TREE_TYPE (ctype), callee, args);
+  SET_EXPR_LOCATION (result, input_location);
 
   /* Enforce left to right evaluation.  */
   if (tf->linkage == LINKd)
diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index c5254a02446..fb95716f918 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -43,6 +43,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "langhooks.h"
 #include "langhooks-def.h"
 #include "target.h"
+#include "function.h"
 #include "stringpool.h"
 #include "stor-layout.h"
 #include "varasm.h"
@@ -1358,12 +1359,65 @@ d_type_for_size (unsigned bits, int unsignedp)
   return 0;
 }
 
-/* Implements the lang_hooks.types.type_promotes_to routine for language D.
-   All promotions for variable arguments are handled by the D frontend.  */
+/* Implements the lang_hooks.types.type_promotes_to routine for language D.  */
 
 static tree
 d_type_promotes_to (tree type)
 {
+  /* Promotions are only applied on unnamed function arguments for declarations
+ with `extern(C)' or `extern(C++)' linkage.  */
+  if (cfun && DECL_LANG_FRONTEND (cfun->decl)
+  && DECL_LANG_FRONTEND (cfun->decl)->linkage != LINKd)
+{
+  /* In [type/integer-promotions], integer promotions are conversions of 
the
+following types:
+
+   boolint
+   byteint
+   ubyte   int
+   short   int
+   ushort  int
+   charint
+   wchar   int
+   dchar   uint
+
+If an enum has as a base type one of the types in the left column, it
+is converted to the type in the right column.  */
+  if (TREE_CODE (type) == ENUMERAL_TYPE && ENUM_IS_SCOPED (type))
+   type = TREE_TYPE (type);
+
+  type = TYPE_MAIN_VARIANT (type);
+
+  /* Check for promotions of target-defined types first.  */
+  tree promoted_type = targetm.promoted_type (type);
+  if (promoted_type)
+   return promoted_type;
+
+  if (TREE_CODE (type) == BOOLEAN_TYPE)
+   return d_int_type;
+
+  if (INTEGRAL_TYPE_P (type))
+   {
+ if (type == d_byte_type || type == d_ubyte_type
+ || type == d_short_type || type == d_ushort_type
+ || type == char8_type_node || type == char16_type_node)
+   return d_int_type;
+
+ if (type == char32_type_node)
+   return d_uint_type;
+
+ if (TYPE_PRECISION (type) < TYPE_PRECISION (d_int_type))
+   return d_int_type;
+   }
+
+  /* Float arguments are converted to doubles.  */
+  if (type == float_type_node)
+   return double_type_node;
+
+  if (type == ifloat_type_node)
+   return idouble_type_node;
+}
+
   return type;
 }
 
diff --git a/gcc/d/intrinsics.cc b/gcc/d/intrinsics.cc
index 1b12a3ec6fb..a629472c6c5 100644
--- a/gcc/d/intrinsics.cc
+++ b/gcc/d/intrinsics.cc
@@ -562,7 +562,7 @@ expand_intrinsic_vaarg (tree callexp)
 }
 
   /* (T) VA_ARG_EXP;  */
-  tree exp = build1 (VA_ARG_EXPR, type, ap);
+  tree exp = build1_loc (EXPR_LOCATION (callexp), VA_ARG_EXPR, type, ap);
 
   /* parmn = (T) VA_ARG_EXP;  */
   if (parmn != NULL_TREE)
diff --git a/gcc/testsuite/gdc.dg/pr97002.d b/gcc/testsuite/gdc.dg/pr97002.d
new file mode 100644
index 000..5c537db3a0b
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr97002.d
@@ -0,0 +1,55 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97002
+// { dg-do compile }
+
+import core.stdc.stdarg;
+
+enum E1 : bool { one, two }
+enum E2 : short { one, two }
+enum E3 : dchar { one, two }
+enum E4 : float { one, two }
+
+extern(C) void fun(void *p1, ...)
+{
+va_arg!bool(_argptr);   // { dg-warning "'bool' is promoted to 'int' when 
passed through '...'" "promoted" }
+// { dg-message "note: .so you should pass .int. not .

Re: [PATCH] MIPS/libphobos: Fix switchcontext.S assembly for MIPS I ISA

2020-10-08 Thread Iain Buclaw via Gcc-patches
Excerpts from Maciej W. Rozycki's message of October 7, 2020 9:45 pm:
> Correct MIPS I assembly build errors in switchcontext.S:
> 
> .../libphobos/libdruntime/config/mips/switchcontext.S: Assembler messages:
> .../libphobos/libdruntime/config/mips/switchcontext.S:50: Error: opcode not 
> supported on this processor: mips1 (mips1) `sdc1 
> $f20,(0*8-((6*8+4+(-6*8+4&7($sp)'
> 
> etc., due to the use of the MIPS II LDC1 and SDC1 hardware instructions 
> for FP register load and store operations.  Instead use the L.D and S.D 
> generic assembly instructions, which are strict aliases for the LDC1 and 
> SDC1 instructions respectively and produce identical machine code where 
> the assembly for the MIPS II or a higher ISA has been requested, however 
> they become assembly macros and expand to compatible sequences of LWC1 
> and SWC1 hardware instructions where the assembly for the MIPS I ISA is 
> in effect.
> 
>   libphobos/
>   * libdruntime/config/mips/switchcontext.S [__mips_hard_float]: 
>   Use L.D and S.D generic assembly instructions rather than LDC1 
>   and SDC1 MIPS II hardware instructions.
> ---
> Hi,
> 
>  Noticed in a build of a MIPS I toolchain.  I have no way to run MIPS 
> regression-testing right now, however in `libopcodes' the L.D and S.D 
> instructions are strict aliases valid for the MIPS II and higher ISAs, and 
> just to double-check that I have built MIPS32r2 GCC with and without the 
> change applied and verified with `objdump' that the respective target 
> objects produced are identical.
> 
>  OK to apply to trunk, and -- as a fatal compilation error -- to backport 
> to active release branches?
> 

Fine with me, thanks.

Iain.



[committed] libphobos: Fix misspelling of msvcUsesUCRT (PR104659)

2022-03-01 Thread Iain Buclaw via Gcc-patches
Hi,

This patch fixes a compilation error on x86_64-w64-mingw32.

Committed to mainline, and backported to releases/gcc-11.

Regards
Iain

---
libphobos/ChangeLog:

PR d/104659
* libdruntime/config/mingw/msvc.c (init_msvc): Fix misspelling of
msvcUsesUCRT.
---
 libphobos/libdruntime/config/mingw/msvc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libphobos/libdruntime/config/mingw/msvc.c 
b/libphobos/libdruntime/config/mingw/msvc.c
index b00d90d7061..348b2237ed5 100644
--- a/libphobos/libdruntime/config/mingw/msvc.c
+++ b/libphobos/libdruntime/config/mingw/msvc.c
@@ -50,7 +50,7 @@ init_msvc (void)
   core_stdc_stderr = stderr;
 
 #if __MSVCRT_VERSION__ >= 0xE00
-  msvcUsedUCRT = 1;
+  msvcUsesUCRT = 1;
 #endif
 }
 
-- 
2.32.0



[committed] d: Remove gdc.test/dhry.d from the testsuite (PR104736)

2022-03-01 Thread Iain Buclaw via Gcc-patches
Hi,

This patch removes gdc.test/dhry.d from the testsuite, that was merged
in from the sync with upstream 2.098.0.

This test is not well ported, and doesn't check anything useful.

Committed to mainline.

gcc/testsuite/ChangeLog:

PR d/104736
* gdc.test/runnable/dhry.d: Removed.
---
 gcc/testsuite/gdc.test/runnable/dhry.d | 947 -
 1 file changed, 947 deletions(-)
 delete mode 100644 gcc/testsuite/gdc.test/runnable/dhry.d

diff --git a/gcc/testsuite/gdc.test/runnable/dhry.d 
b/gcc/testsuite/gdc.test/runnable/dhry.d
deleted file mode 100644
index 1eb463ce8cc..000
--- a/gcc/testsuite/gdc.test/runnable/dhry.d
+++ /dev/null
@@ -1,947 +0,0 @@
-/*
-PERMUTE_ARGS:
-REQUIRED_ARGS: -release -O -g -inline
-DISABLED: freebsd dragonflybsd
-
-Deprecation caused by https://issues.dlang.org/show_bug.cgi?id=20645
-*/
-
-/*
- *
- *
- *   "DHRYSTONE" Benchmark Program
- *   -
- *
- *  Version:C, Version 2.1
- *
- *  File:   dhry.h (part 1 of 3)
- *
- *  Date:   May 25, 1988
- *
- *  Author: Reinhold P. Weicker
- *  Siemens Nixdorf Inf. Syst.
- *  STM OS 32
- *  Otto-Hahn-Ring 6
- *  W-8000 Muenchen 83
- *  Germany
- *  Phone:[+49]-89-636-42436
- *(8-17 Central European Time)
- *  UUCP: weic...@ztivax.uucp@unido.uucp
- *  Internet: weic...@ztivax.siemens.com
- *
- *  Original Version (in Ada) published in
- *  "Communications of the ACM" vol. 27., no. 10 (Oct. 1984),
- *  pp. 1013 - 1030, together with the statistics
- *  on which the distribution of statements etc. is based.
- *
- *  In this C version, the following C library functions are
- *  used:
- *  - strcpy, strcmp (inside the measurement loop)
- *  - printf, scanf (outside the measurement loop)
- *
- *  Collection of Results:
- *  Reinhold Weicker (address see above) and
- *
- *  Rick Richardson
- *  PC Research. Inc.
- *  94 Apple Orchard Drive
- *  Tinton Falls, NJ 07724
- *  Phone:  (201) 834-1378 (9-17 EST)
- *  UUCP:   ...!uunet!pcrat!rick
- *
- *  Please send results to Rick Richardson and/or Reinhold Weicker.
- *  Complete information should be given on hardware and software
- *  used. Hardware information includes: Machine type, CPU, type and
- *  size of caches; for microprocessors: clock frequency, memory speed
- *  (number of wait states). Software information includes: Compiler
- *  (and runtime library) manufacturer and version, compilation
- *  switches, OS version. The Operating System version may give an
- *  indication about the compiler; Dhrystone itself performs no OS
- *  calls in the measurement loop.
- *
- *  The complete output generated by the program should be mailed
- *  such that at least some checks for correctness can be made.
- *
- *
- *
- *  History:This version C/2.1 has been made for two reasons:
- *
- *  1) There is an obvious need for a common C version of
- *  Dhrystone, since C is at present the most popular system
- *  programming language for the class of processors
- *  (microcomputers, minicomputers) where Dhrystone is used
- *  most. There should be, as far as possible, only one C
- *  version of Dhrystone such that results can be compared
- *  without restrictions. In the past, the C versions
- *  distributed by Rick Richardson (Version 1.1) and by
- *  Reinhold Weicker had small (though not significant)
- *  differences.
- *
- *  2) As far as it is possible without changes to the
- *  Dhrystone statistics, optimizing compilers should be
- *  prevented from removing significant statements.
- *
- *  This C version has been developed in cooperation with
- *  Rick Richardson (Tinton Falls, NJ), it incorporates many
- *  ideas from the "Version 1.1" distributed previously by
- *  him over the UNIX network Usenet.
- *  I also thank Chaim Benedelac (National Semiconductor),
- *  David Ditzel (SUN), Earl Killian and John Mashey (MIPS),
- *  Alan Smith and Rafael Saavedra-Barrera (UC at Berkeley)
- *  for their help with comments on earlier versions of the
- *  benchmark.
- *
- *  Changes:In the initialization part, this version follows mostly
- *  Rick Richardson's version distributed via Usenet, 

[committed] d: Merge upstream dmd 423f19b41, druntime 100a608c, phobos a1f8c4c07.

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

This patch merges the D front-end implementation with upstream dmd
423f19b41, as well as the D runtime libraries with druntime 100a608c,
and phobos a1f8c4c07.

D Runtime changes:

- Fix stdc.stdio bindings to not depend on druntime (PR104729).
- Implement stdc.math for Solaris (PR104735).

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 423f19b41.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 100a608c.
* src/MERGE: Merge upstream phobos a1f8c4c07.
---
 gcc/d/dmd/MERGE   |   2 +-
 gcc/d/dmd/dtemplate.d |   9 +-
 gcc/d/dmd/expression.d| 161 +-
 gcc/d/dmd/lexer.d |  71 +++-
 gcc/d/dmd/optimize.d  |  21 ++-
 gcc/d/dmd/statementsem.d  |   2 +
 gcc/d/dmd/tokens.d|   2 +
 gcc/d/dmd/tokens.h|   1 +
 gcc/testsuite/gdc.test/compilable/test21975.d |  15 ++
 .../runnable_cxx/extra-files/cppb.cpp |  47 ++---
 libphobos/libdruntime/MERGE   |   2 +-
 libphobos/libdruntime/core/memory.d   |   9 +-
 libphobos/libdruntime/core/stdc/math.d| 133 ++-
 libphobos/libdruntime/core/stdc/stdio.d   |  16 +-
 libphobos/libdruntime/core/stdcpp/exception.d |  10 +-
 libphobos/libdruntime/core/stdcpp/typeinfo.d  |  40 +++--
 libphobos/libdruntime/core/sys/posix/locale.d |   2 +-
 libphobos/libdruntime/object.d|  18 +-
 libphobos/src/MERGE   |   2 +-
 libphobos/src/std/datetime/systime.d  |  35 ++--
 libphobos/src/std/sumtype.d   |  41 +
 21 files changed, 503 insertions(+), 136 deletions(-)
 create mode 100644 gcc/testsuite/gdc.test/compilable/test21975.d

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index f08d53aa3cd..71dc2b0a155 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-cf63dd8e5a77ecb68cf5e7c43bf7b6c4c1154bbe
+423f19b41089f627808bf16ff21c60c0791712ba
 
 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/dtemplate.d b/gcc/d/dmd/dtemplate.d
index 457c5d12892..6abe69a9c4f 100644
--- a/gcc/d/dmd/dtemplate.d
+++ b/gcc/d/dmd/dtemplate.d
@@ -4295,8 +4295,13 @@ MATCH deduceType(RootObject o, Scope* sc, Type tparam, 
TemplateParameters* param
 if (ti && ti.toAlias() == t.sym)
 {
 auto tx = new TypeInstance(Loc.initial, ti);
-result = deduceType(tx, sc, tparam, parameters, dedtypes, 
wm);
-return;
+auto m = deduceType(tx, sc, tparam, parameters, dedtypes, 
wm);
+// if we have a no match we still need to check alias this
+if (m != MATCH.nomatch)
+{
+result = m;
+return;
+}
 }
 
 /* Match things like:
diff --git a/gcc/d/dmd/expression.d b/gcc/d/dmd/expression.d
index b3aa0b268b4..2b41219846a 100644
--- a/gcc/d/dmd/expression.d
+++ b/gcc/d/dmd/expression.d
@@ -83,7 +83,7 @@ void emplaceExp(T : UnionExp)(T* p, Expression e)
 memcpy(p, cast(void*)e, e.size);
 }
 
-// Return value for `checkModifiable`
+/// Return value for `checkModifiable`
 enum Modifiable
 {
 /// Not modifiable
@@ -1766,6 +1766,7 @@ extern (C++) abstract class Expression : ASTNode
 }
 
 /***
+ * A compile-time known integer value
  */
 extern (C++) final class IntegerExp : Expression
 {
@@ -1982,6 +1983,7 @@ extern (C++) final class IntegerExp : Expression
 
 /***
  * Use this expression for error recovery.
+ *
  * It should behave as a 'sink' to prevent further cascaded error messages.
  */
 extern (C++) final class ErrorExp : Expression
@@ -2026,6 +2028,8 @@ extern (C++) final class ErrorExp : Expression
 /***
  * An uninitialized value,
  * generated from void initializers.
+ *
+ * https://dlang.org/spec/declaration.html#void_init
  */
 extern (C++) final class VoidInitExp : Expression
 {
@@ -2052,6 +2056,7 @@ extern (C++) final class VoidInitExp : Expression
 
 
 /***
+ * A compile-time known floating point number
  */
 extern (C++) final class RealExp : Expression
 {
@@ -2127,6 +2132,7 @@ extern (C++) final class RealExp : Expression
 }
 
 /***
+ * A compile-time complex number (deprecated)
  */
 extern (C++) final class ComplexExp : Expression
 {
@@ -2202,6 +2208,12 @@ extern (C++) final class ComplexExp

Re: [PATCH] libphobos: Enable on Solaris/SPARC or with /bin/as [PR 103528]

2022-03-10 Thread Iain Buclaw via Gcc-patches
Excerpts from Rainer Orth's message of März 10, 2022 11:19 am:
> libphobos is currently only enabled on Solaris/x86 with gas.  As
> discovered when gdc was switched to the dmd frontend, this initially
> broke bootstrap for the other Solaris configurations.
> 
> However, it's now well possible to enable it both for Solaris/x86 with
> as and Solaris/SPARC (both as and gas) since the original problems (x86
> as linelength limit among others) are long gone.
> 
> The following patch does just that.
> 
> Tested on i386-pc-solaris2.11 and sparc-sun-solaris2.11 (both as and
> gas) with gdc 9.3.0 (x86) resp. 9.4.0 (sparc, configured with
> --enable-libphobos) as bootstrap compilers.
> 
> Ok for trunk?

OK.

Thanks,
Iain.


[committed] d: Cache generated import declarations in a hash_map

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

This patch refactors the ImportVisitor to cache the generated result
decl in a hash_map.  Originally, these were cached in the front-end AST
node field `isym'.  However, this field is soon to be removed.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* imports.cc (imported_decls): Define.
(class ImportVisitor): Add result_ field.
(ImportVisitor::result): New method.
(ImportVisitor::visit (Module *)): Store decl to result_.
(ImportVisitor::visit (Import *)): Likewise.
(ImportVisitor::visit (AliasDeclaration *)): Don't cache decl in
front-end AST node.
(ImportVisitor::visit (OverDeclaration *)): Likewise.
(ImportVisitor::visit (FuncDeclaration *)): Likewise.
(ImportVisitor::visit (Declaration *)): Likewise.
(build_import_decl): Use imported_decls to cache and lookup built
declarations.
---
 gcc/d/imports.cc | 77 ++--
 1 file changed, 41 insertions(+), 36 deletions(-)

diff --git a/gcc/d/imports.cc b/gcc/d/imports.cc
index d3a3099ce76..29c0fbfe6d2 100644
--- a/gcc/d/imports.cc
+++ b/gcc/d/imports.cc
@@ -31,14 +31,17 @@ along with GCC; see the file COPYING3.  If not see
 
 #include "d-tree.h"
 
+static hash_map *imported_decls;
 
 /* Implements the visitor interface to build debug trees for all
-   module and import declarations, where ISYM holds the cached
-   back-end representation to be returned.  */
+   module and import declarations, where RESULT_ holds the back-end
+   representation to be cached and returned from the caller.  */
 class ImportVisitor : public Visitor
 {
   using Visitor::visit;
 
+  tree result_;
+
   /* Build the declaration DECL as an imported symbol.  */
   tree make_import (tree decl)
   {
@@ -55,6 +58,12 @@ class ImportVisitor : public Visitor
 public:
   ImportVisitor (void)
   {
+this->result_ = NULL_TREE;
+  }
+
+  tree result (void)
+  {
+return this->result_;
   }
 
   /* This should be overridden by each symbol class.  */
@@ -70,16 +79,16 @@ public:
 Loc loc = (m->md != NULL) ? m->md->loc
   : Loc (m->srcfile.toChars (), 1, 0);
 
-m->isym = build_decl (make_location_t (loc), NAMESPACE_DECL,
- get_identifier (m->toPrettyChars ()),
- void_type_node);
-d_keep (m->isym);
+this->result_ = build_decl (make_location_t (loc), NAMESPACE_DECL,
+   get_identifier (m->toPrettyChars ()),
+   void_type_node);
+d_keep (this->result_);
 
 if (!m->isRoot ())
-  DECL_EXTERNAL (m->isym) = 1;
+  DECL_EXTERNAL (this->result_) = 1;
 
-TREE_PUBLIC (m->isym) = 1;
-DECL_CONTEXT (m->isym) = NULL_TREE;
+TREE_PUBLIC (this->result_) = 1;
+DECL_CONTEXT (this->result_) = NULL_TREE;
   }
 
   /* Build an import of another module symbol.  */
@@ -87,7 +96,7 @@ public:
   void visit (Import *m)
   {
 tree module = build_import_decl (m->mod);
-m->isym = this->make_import (module);
+this->result_ = this->make_import (module);
   }
 
   /* Build an import for any kind of user defined type.
@@ -141,20 +150,14 @@ public:
 
 /* This symbol is really an alias for another, visit the other.  */
 if (dsym != d)
-  {
-   dsym->accept (this);
-   d->isym = dsym->isym;
-  }
+  dsym->accept (this);
   }
 
   /* Visit the underlying alias symbol of overloadable aliases.  */
   void visit (OverDeclaration *d)
   {
 if (d->aliassym != NULL)
-  {
-   d->aliassym->accept (this);
-   d->isym = d->aliassym->isym;
-  }
+  d->aliassym->accept (this);
   }
 
   /* Function aliases are the same as alias symbols.  */
@@ -163,10 +166,7 @@ public:
 FuncDeclaration *fd = d->toAliasFunc ();
 
 if (fd != NULL)
-  {
-   fd->accept (this);
-   d->isym = fd->isym;
-  }
+  fd->accept (this);
   }
 
   /* Skip over importing templates and tuples.  */
@@ -182,7 +182,7 @@ public:
  symbol generation routines, the compiler will throw an error.  */
   void visit (Declaration *d)
   {
-d->isym = this->make_import (get_symbol_decl (d));
+this->result_ = this->make_import (get_symbol_decl (d));
   }
 };
 
@@ -192,17 +192,22 @@ public:
 tree
 build_import_decl (Dsymbol *d)
 {
-  if (!d->isym)
-{
-  location_t saved_location = input_location;
-  ImportVisitor v;
-
-  input_location = make_location_t (d->loc);
-  d->accept (&v);
-  input_location = saved_location;
-}
-
-  /* Not all visitors set `isym'.  */
-  return d->isym ? d->isym : NULL_TREE;
-}
+  hash_map_maybe_create (imported_decls);
+
+  if (tree *decl = imported_decls->get (d))
+return *decl;
 
+  location_t saved_location = input_location;
+  ImportVisitor v = ImportVisitor ();
+
+  input_location = make_location_t (d->loc);
+  d->accept (&v);
+  input_location = saved_loca

[committed] d: Fix mistakes in strings to be translated [PR104552]

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

This patch addresses comments made in PR104552 about documented D
language options.

Bootstrapped and committed to mainline.

Regards,
Iain.

---
gcc/d/ChangeLog:

PR translation/104552
* lang.opt (fdump-cxx-spec=): Fix typo in argument handle.
(fpreview=fixaliasthis): Quote `alias this' as code.
---
 gcc/d/lang.opt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/d/lang.opt b/gcc/d/lang.opt
index 491797a1b6b..7859e1583c8 100644
--- a/gcc/d/lang.opt
+++ b/gcc/d/lang.opt
@@ -277,7 +277,7 @@ Add comments for ignored declarations in the generated C++ 
header.
 
 fdump-c++-spec=
 D RejectNegative Joined
--fdump-cxx-spec= Write all declarations as C++ code to .
+-fdump-cxx-spec= Write all declarations as C++ code to 
.
 
 fdump-d-original
 D
@@ -370,7 +370,7 @@ Use field-wise comparisons for struct equality.
 
 fpreview=fixaliasthis
 D RejectNegative
-When a symbol is resolved, check alias this scope before going to upper scopes.
+When a symbol is resolved, check `alias this' scope before going to upper 
scopes.
 
 fpreview=in
 D RejectNegative
-- 
2.32.0



[committed] d: Fix internal compiler error: in build_complex, at tree.c:2358

2022-03-21 Thread Iain Buclaw via Gcc-patches
Hi,

This patch fixes an ICE in the D front-end when constructing a complex
object from a struct literal typed as enum __c_complex_float.

The conversion from the special _Complex enum to native complex used
build_complex, however the input value isn't necessarily a literal.

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

Regards,
Iain.

---
PR d/105004

gcc/d/ChangeLog:

* d-codegen.cc (build_struct_literal): Use complex_expr to build
complex expressions from __c_complex types.

gcc/testsuite/ChangeLog:

* gdc.dg/pr105004.d: New test.
---
 gcc/d/d-codegen.cc  |  2 +-
 gcc/testsuite/gdc.dg/pr105004.d | 14 ++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gdc.dg/pr105004.d

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 3e54d3bffd0..3206edd17e8 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -1161,7 +1161,7 @@ build_struct_literal (tree type, vec  *init)
   if (COMPLEX_FLOAT_TYPE_P (type))
 {
   gcc_assert (vec_safe_length (init) == 2);
-  return build_complex (type, (*init)[0].value, (*init)[1].value);
+  return complex_expr (type, (*init)[0].value, (*init)[1].value);
 }
 
   vec  *ve = NULL;
diff --git a/gcc/testsuite/gdc.dg/pr105004.d b/gcc/testsuite/gdc.dg/pr105004.d
new file mode 100644
index 000..60b3c3f635e
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr105004.d
@@ -0,0 +1,14 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105004
+// { dg-do compile }
+
+private struct _Complex(T)
+{
+T re;
+T im;
+}
+enum __c_complex_float  : _Complex!float;
+
+__c_complex_float pr105004(float re, float im)
+{
+return typeof(return)(re, im);
+}
-- 
2.32.0



[committed] d: Remove Wtemplates warnings from the code generation pass

2022-04-03 Thread Iain Buclaw via Gcc-patches
Hi,

This patch removes the `-Wtemplate' warnings from the code generation
pass of the D front-end.

These have been superceded by the upstream front-end's own internal
tracking of instantiations, exposed by `-ftransition=templates'.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* d-lang.cc: Include dmd/template.h.
(d_parse_file): Call printTemplateStats when vtemplates is set.
* decl.cc (start_function): Remove OPT_Wtemplates warning.
* lang.opt (Wtemplates): Remove.
---
 gcc/d/d-lang.cc |  4 
 gcc/d/decl.cc   | 11 +--
 gcc/d/lang.opt  |  4 
 3 files changed, 5 insertions(+), 14 deletions(-)

diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index 4a7aa8983b7..69571628336 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -33,6 +33,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "dmd/module.h"
 #include "dmd/mtype.h"
 #include "dmd/target.h"
+#include "dmd/template.h"
 
 #include "opts.h"
 #include "alias.h"
@@ -1306,6 +1307,9 @@ d_parse_file (void)
}
 }
 
+  if (global.params.vtemplates)
+printTemplateStats ();
+
   /* Generate JSON files.  */
   if (global.params.doJsonGeneration)
 {
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index ea8baef588c..86ea1761f4f 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -1891,16 +1891,7 @@ start_function (FuncDeclaration *fd)
  modules not in this compilation, or thunk aliases.  */
   TemplateInstance *ti = fd->isInstantiated ();
   if (ti && ti->needsCodegen ())
-{
-  /* Warn about templates instantiated in this compilation.  */
-  if (ti == fd->parent)
-   {
- warning (OPT_Wtemplates, "%s %qs instantiated",
-  ti->kind (), ti->toPrettyChars (false));
-   }
-
-  DECL_EXTERNAL (fndecl) = 0;
-}
+DECL_EXTERNAL (fndecl) = 0;
   else
 {
   Module *md = fd->getModule ();
diff --git a/gcc/d/lang.opt b/gcc/d/lang.opt
index 7859e1583c8..51e8e5c7e00 100644
--- a/gcc/d/lang.opt
+++ b/gcc/d/lang.opt
@@ -138,10 +138,6 @@ Wspeculative
 D
 Warn from speculative compiles such as __traits(compiles).
 
-Wtemplates
-D
-; Documented in C
-
 Wunknown-pragmas
 D Var(warn_unknown_pragmas) LangEnabledBy(D, Wextra)
 ; Documented in C
-- 
2.32.0



[committed] d: Compile simd_ctfe.d only on avx_runtime or vect_sizes_16B_8B targets

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

This test makes use of the `__vector(int[4])' type, which is not
supported on all targets, so guard the test with target avx_runtime ||
vect_sizes_16B_8B, fixing PR104740.

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

Regards,
Iain.

---

PR d/104740

gcc/testsuite/ChangeLog:

* gdc.dg/simd_ctfe.d: Compile with target avx_runtime or
vect_sizes_16B_8B.
---
 gcc/testsuite/gdc.dg/simd_ctfe.d | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gdc.dg/simd_ctfe.d b/gcc/testsuite/gdc.dg/simd_ctfe.d
index b254cf312cb..507de17baa2 100644
--- a/gcc/testsuite/gdc.dg/simd_ctfe.d
+++ b/gcc/testsuite/gdc.dg/simd_ctfe.d
@@ -1,4 +1,5 @@
-// { dg-do compile }
+// { dg-additional-options "-mavx" { target avx_runtime } }
+// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } }
 import core.simd;
 
 // https://issues.dlang.org/show_bug.cgi?id=19627
-- 
2.32.0



[committed] d: Merge upstream dmd eb7bee331, druntime 27834edb, phobos ac296f80c.

2022-04-21 Thread Iain Buclaw via Gcc-patches
Hi,

This patch merges the D front-end with upstream dmd eb7bee331, and
the standard library with druntime 27834edb and phobos ac296f80c.

D front-end changes:

- Import dmd v2.100.0-beta.1.
- Print deprecation messages for scope violations unless
  `-frevert=dip1000' is used.
- Fixed a missed case of switch case fallthrough not being caught by
  the compiler.

D runtime changes:

- Import druntime v2.100.0-beta.1.

Phobos changes:

- Import phobos v2.100.0-beta.1.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd eb7bee331.
* dmd/VERSION: Update version to v2.100.0-beta.1.
* d-lang.cc (d_handle_option): Handle OPT_frevert_dip1000.
* lang.opt (frevert=dip1000): New option.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 27834edb.
* src/MERGE: Merge upstream phobos ac296f80c.
* src/Makefile.am (PHOBOS_DSOURCES): Add std/int128.d.
* src/Makefile.in: Regenerate.
---
 gcc/d/d-lang.cc   |   5 +
 gcc/d/dmd/MERGE   |   2 +-
 gcc/d/dmd/VERSION |   2 +-
 gcc/d/dmd/aggregate.d |  22 ++
 gcc/d/dmd/astenums.d  |   1 +
 gcc/d/dmd/blockexit.d |  15 +-
 gcc/d/dmd/clone.d |   6 +-
 gcc/d/dmd/cparse.d|  22 +-
 gcc/d/dmd/declaration.d   |  18 +-
 gcc/d/dmd/dmodule.d   |   6 +-
 gcc/d/dmd/dsymbol.d   |   4 +-
 gcc/d/dmd/dsymbolsem.d|   9 +-
 gcc/d/dmd/errors.d|  16 +-
 gcc/d/dmd/escape.d|  61 ++-
 gcc/d/dmd/expression.d|  11 +-
 gcc/d/dmd/expression.h|   2 -
 gcc/d/dmd/expressionsem.d |  29 +-
 gcc/d/dmd/initsem.d   |   8 +-
 gcc/d/dmd/lexer.d |  55 ++-
 gcc/d/dmd/mtype.d |  92 ++---
 gcc/d/dmd/mtype.h |   2 +-
 gcc/d/dmd/optimize.d  |  13 +-
 gcc/d/dmd/parse.d |  98 +++--
 gcc/d/dmd/statement.d |   8 +
 gcc/d/dmd/transitivevisitor.d |   4 +-
 gcc/d/dmd/typesem.d   |  11 +-
 gcc/d/dmd/utils.d |   2 +-
 gcc/d/lang.opt|   4 +
 .../gdc.test/compilable/betterCarray.d|   7 +
 gcc/testsuite/gdc.test/compilable/test18216.d |  40 ++
 gcc/testsuite/gdc.test/compilable/test22635.d |  13 +
 .../gdc.test/fail_compilation/diag11198.d |  12 +-
 .../gdc.test/fail_compilation/fail22202.d |  22 ++
 .../gdc.test/fail_compilation/fail23036.d |  22 ++
 .../gdc.test/fail_compilation/fail_scope.d|  30 +-
 .../gdc.test/fail_compilation/retscope6.d |  48 ++-
 .../gdc.test/fail_compilation/test22999.d |  27 ++
 .../gdc.test/fail_compilation/test23017.d |  20 +
 gcc/testsuite/gdc.test/runnable/testscope.d   |  16 -
 libphobos/libdruntime/MERGE   |   2 +-
 libphobos/libdruntime/core/exception.d|  84 ++--
 libphobos/libdruntime/object.d|   4 +-
 libphobos/libdruntime/rt/aaA.d|   4 +-
 libphobos/src/MERGE   |   2 +-
 libphobos/src/Makefile.am |   2 +-
 libphobos/src/Makefile.in |   4 +-
 libphobos/src/std/base64.d|  20 +-
 libphobos/src/std/int128.d| 374 ++
 libphobos/src/std/path.d  |   2 +-
 libphobos/src/std/traits.d|  21 +-
 50 files changed, 1002 insertions(+), 302 deletions(-)
 create mode 100644 gcc/testsuite/gdc.test/compilable/test18216.d
 create mode 100644 gcc/testsuite/gdc.test/compilable/test22635.d
 create mode 100644 gcc/testsuite/gdc.test/fail_compilation/fail22202.d
 create mode 100644 gcc/testsuite/gdc.test/fail_compilation/fail23036.d
 create mode 100644 gcc/testsuite/gdc.test/fail_compilation/test22999.d
 create mode 100644 gcc/testsuite/gdc.test/fail_compilation/test23017.d
 create mode 100644 libphobos/src/std/int128.d

diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index 69571628336..9adcabdf7cf 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -637,12 +637,17 @@ d_handle_option (size_t scode, const char *arg, 
HOST_WIDE_INT value,
   break;
 
 case OPT_frevert_all:
+  global.params.useDIP1000 = FeatureState::disabled;
   global.params.useDIP25 = FeatureState::disabled;
   global.params.dtorFields = FeatureState::disabled;
   global.params.fix16997 = !value;
   global.params.markdown = !value;
   break;
 
+case OPT_frevert

Re: [PATCH] internal_error - do not use leading capital letter

2022-01-27 Thread Iain Buclaw via Gcc-patches
Excerpts from Martin Liška's message of Januar 27, 2022 1:40 pm:
> That's follow up patch based on the discussion with Jakub.
> 
> Ready to be installed?
> Thanks,
> Martin
> 
> gcc/ChangeLog:
> 
>   * config/rs6000/host-darwin.cc (segv_crash_handler):
>   Do not use leading capital letter.
>   (segv_handler): Likewise.
>   * ipa-sra.cc (verify_splitting_accesses): Likewise.
>   * varasm.cc (get_section): Likewise.
> 
> gcc/d/ChangeLog:
> 
>   * decl.cc (d_finish_decl): Do not use leading capital letter.
> ---
>   gcc/config/rs6000/host-darwin.cc | 4 ++--
>   gcc/d/decl.cc| 2 +-
>   gcc/ipa-sra.cc   | 4 ++--
>   gcc/varasm.cc| 2 +-
>   4 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
> index c7a1e4652f8..5ecc6269780 100644
> --- a/gcc/d/decl.cc
> +++ b/gcc/d/decl.cc
> @@ -1597,7 +1597,7 @@ d_finish_decl (tree decl)
>   {
> tree name = DECL_ASSEMBLER_NAME (decl);
>   
> -   internal_error ("Mismatch between declaration %qE size (%wd) and "
> +   internal_error ("mismatch between declaration %qE size (%wd) and "
> "its initializer size (%wd).",
> IDENTIFIER_PRETTY_NAME (name)
> ? IDENTIFIER_PRETTY_NAME (name) : name,


This part is OK for me.

Iain.


Re: [PATCH][pushed] d: Fix -Werror=format-diag error.

2022-02-01 Thread Iain Buclaw via Gcc-patches
Excerpts from Martin Liška's message of Januar 31, 2022 9:50 am:
> Pushed as obvious.
> 

Thanks,
Iain.



Re: [committed] d: Merge upstream dmd 52844d4b1, druntime dbd0c874, phobos 896b1d0e1.

2022-02-18 Thread Iain Buclaw via Gcc-patches
Excerpts from Rainer Orth's message of Februar 16, 2022 11:45 pm:
> Hi Iain,
> 
>> This patch merges the D front-end implementation with upstream dmd
>> 52844d4b1, as well as the D runtime libraries with druntime dbd0c874,
>> and phobos 896b1d0e1, including the latest features and bug-fixes ahead of 
>> the 2.099.0-beta1 release.
> 
> this patch broke Solaris bootstrap:
> 
> /vol/gcc/src/hg/master/local/libphobos/libdruntime/core/sys/posix/sys/ipc.d:193:5:
>  error: static assert:  "Unsupported platform"
>   193 | static assert(false, "Unsupported platform");
>   | ^
> 
> The attached patch fixes this.  Tested on i386-pc-solaris2.11 and
> sparc-sun-solaris2.11.
> 

Thanks Rainer!

I've committed it upstream, and will merge it down in the next sync-up.

Iain.


[committed] d: Merge upstream dmd cb49e99f8, druntime 55528bd1, phobos 1a3e80ec2.

2022-02-20 Thread Iain Buclaw via Gcc-patches
Hi,

This patch merges the D front-end implementation with upstream dmd
cb49e99f8, as well as the D runtime libraries with druntime 55528bd1,
and phobos 1a3e80ec2, synchronizing with the release of 2.099.0-beta1.

D front-end changes:

- Import dmd v2.099.0-beta.1.
- It's now an error to use `alias this' for partial assignment.
- The `delete' keyword has been removed from the language.
- Using `this' and `super' as types has been removed from the
  language, the parser no longer specially handles this wrong code
  with an informative error.

D Runtime changes:

- Import druntime v2.099.0-beta.1.

Phobos changes:

- Import phobos v2.099.0-beta.1.


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

Regards,
Iain.

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd cb49e99f8.
* dmd/VERSION: Update version to v2.099.0-beta.1.
* decl.cc (layout_class_initializer): Update call to NewExp::create.
* expr.cc (ExprVisitor::visit (DeleteExp *)): Remove handling of
deleting arrays and pointers.
(ExprVisitor::visit (DotVarExp *)): Convert complex types to the
front-end library type representing them.
(ExprVisitor::visit (StringExp *)): Use getCodeUnit instead of charAt
to get the value of each index in a string expression.
* runtime.def (DELMEMORY): Remove.
(DELARRAYT): Remove.
* types.cc (TypeVisitor::visit (TypeEnum *)): Handle anonymous enums.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 55528bd1.
* src/MERGE: Merge upstream phobos 1a3e80ec2.
* testsuite/libphobos.hash/test_hash.d: Update.
* testsuite/libphobos.betterc/test19933.d: New test.
---
 gcc/d/decl.cc |2 +-
 gcc/d/dmd/MERGE   |2 +-
 gcc/d/dmd/VERSION |2 +-
 gcc/d/dmd/apply.d |4 +-
 gcc/d/dmd/canthrow.d  |   12 +-
 gcc/d/dmd/clone.d |   37 +-
 gcc/d/dmd/constfold.d |6 +-
 gcc/d/dmd/cparse.d|   27 +-
 gcc/d/dmd/ctfeexpr.d  |2 +-
 gcc/d/dmd/dcast.d | 4267 -
 gcc/d/dmd/declaration.d   |5 +-
 gcc/d/dmd/declaration.h   |1 -
 gcc/d/dmd/dinterpret.d|  106 +-
 gcc/d/dmd/dmangle.d   |3 +-
 gcc/d/dmd/dmodule.d   |   78 +-
 gcc/d/dmd/dscope.d|2 +-
 gcc/d/dmd/dsymbol.d   |   11 +-
 gcc/d/dmd/dsymbol.h   |2 +
 gcc/d/dmd/dsymbolsem.d|  184 +-
 gcc/d/dmd/dtemplate.d |   52 +-
 gcc/d/dmd/dtoh.d  |   24 +-
 gcc/d/dmd/escape.d|2 +-
 gcc/d/dmd/expression.d|  115 +-
 gcc/d/dmd/expression.h|   17 +-
 gcc/d/dmd/expressionsem.d |  304 +-
 gcc/d/dmd/func.d  |3 +-
 gcc/d/dmd/hdrgen.d|   70 +-
 gcc/d/dmd/iasmgcc.d   |2 +-
 gcc/d/dmd/id.d|4 -
 gcc/d/dmd/importc.d   |   47 +
 gcc/d/dmd/initsem.d   |4 +
 gcc/d/dmd/lexer.d |  444 +-
 gcc/d/dmd/mtype.d |   45 +-
 gcc/d/dmd/nogc.d  |   42 +-
 gcc/d/dmd/opover.d|  342 +-
 gcc/d/dmd/optimize.d  |7 -
 gcc/d/dmd/parse.d |  794 +--
 gcc/d/dmd/printast.d  |   10 +
 gcc/d/dmd/semantic2.d |2 +-
 gcc/d/dmd/semantic3.d |   22 +-
 gcc/d/dmd/statementsem.d  |  206 +-
 gcc/d/dmd/staticassert.d  |5 +
 gcc/d/dmd/staticassert.h  |1 +
 gcc/d/dmd/tokens.d|  120 +-
 gcc/d/dmd/tokens.h|   13 +-
 gcc/d/dmd/transitivevisitor.d |4 -
 gcc/d/dmd/typesem.d   |   80 +-
 gcc/d/expr.cc |   46 +-
 gcc/d/runtime.def |7 -
 gcc/d/types.cc|   14 +-
 gcc/testsuite/gdc.dg/special1.d   |   12 +
 gcc/testsuite/gdc.test/compilable/99bottles.d |  212 +-
 gcc/testsuite/gdc.test/compilable/b18242.d|6 +-
 gcc/testsuite/gdc.test/compilable/b19294.d|   10 +-
 gcc/testsuite/gdc.test/compilable/b20938.d|6 +-
 gcc/testsuite/gdc.test/compilable/b21285.d|   10 +-
 .../gdc.t

[committed] d: Remove handling of deleting GC allocated classes.

2022-02-20 Thread Iain Buclaw via Gcc-patches
Hi,

Now that the `delete' keyword has been removed from the front-end, only
compiler-generated uses of DeleteExp reach the code generator via the
auto-destruction of `scope class' variables.

The run-time library helpers that previously were used to delete GC
class objects can now be removed from the compiler.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* expr.cc (ExprVisitor::visit (DeleteExp *)): Remove handling of
deleting GC allocated classes.
* runtime.def (DELCLASS): Remove.
(DELINTERFACE): Remove.
---
 gcc/d/expr.cc | 24 ++--
 gcc/d/runtime.def |  6 +-
 2 files changed, 7 insertions(+), 23 deletions(-)

diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index d5e4df7f563..2a7fb690862 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -1438,28 +1438,16 @@ public:
   {
/* For class object references, if there is a destructor for that class,
   the destructor is called for the object instance.  */
-   libcall_fn libcall;
+   gcc_assert (e->e1->op == EXP::variable);
 
-   if (e->e1->op == EXP::variable)
- {
-   VarDeclaration *v = e->e1->isVarExp ()->var->isVarDeclaration ();
-   if (v && v->onstack)
- {
-   libcall = tb1->isClassHandle ()->isInterfaceDeclaration ()
- ? LIBCALL_CALLINTERFACEFINALIZER : LIBCALL_CALLFINALIZER;
+   VarDeclaration *v = e->e1->isVarExp ()->var->isVarDeclaration ();
+   gcc_assert (v && v->onstack);
 
-   this->result_ = build_libcall (libcall, Type::tvoid, 1, t1);
-   return;
- }
- }
+   libcall_fn libcall = tb1->isClassHandle ()->isInterfaceDeclaration ()
+ ? LIBCALL_CALLINTERFACEFINALIZER : LIBCALL_CALLFINALIZER;
 
-   /* Otherwise, the garbage collector is called to immediately free the
-  memory allocated for the class instance.  */
-   libcall = tb1->isClassHandle ()->isInterfaceDeclaration ()
- ? LIBCALL_DELINTERFACE : LIBCALL_DELCLASS;
-
-   t1 = build_address (t1);
this->result_ = build_libcall (libcall, Type::tvoid, 1, t1);
+   return;
   }
 else
   {
diff --git a/gcc/d/runtime.def b/gcc/d/runtime.def
index acb610f71f0..534f8661b3e 100644
--- a/gcc/d/runtime.def
+++ b/gcc/d/runtime.def
@@ -63,11 +63,7 @@ DEF_D_RUNTIME (ARRAYBOUNDS_INDEXP, "_d_arraybounds_indexp", 
RT(VOID),
 DEF_D_RUNTIME (NEWCLASS, "_d_newclass", RT(OBJECT), P1(CONST_CLASSINFO), 0)
 DEF_D_RUNTIME (NEWTHROW, "_d_newThrowable", RT(OBJECT), P1(CONST_CLASSINFO), 0)
 
-/* Used when calling delete on a class or interface.  */
-DEF_D_RUNTIME (DELCLASS, "_d_delclass", RT(VOID), P1(VOIDPTR), 0)
-DEF_D_RUNTIME (DELINTERFACE, "_d_delinterface", RT(VOID), P1(VOIDPTR), 0)
-
-/* Same as deleting a class, but used for stack-allocated classes.  */
+/* Used when calling delete on a stack-allocated class or interface.  */
 DEF_D_RUNTIME (CALLFINALIZER, "_d_callfinalizer", RT(VOID), P1(VOIDPTR), 0)
 DEF_D_RUNTIME (CALLINTERFACEFINALIZER, "_d_callinterfacefinalizer", RT(VOID),
   P1(VOIDPTR), 0)
-- 
2.32.0



[committed] d: Merge upstream dmd cf63dd8e5, druntime caf14b0f, phobos 41aaf8c26.

2022-02-28 Thread Iain Buclaw via Gcc-patches
Hi,

This patch merges the D front-end implementation with upstream dmd
cf63dd8e5, as well as the D runtime libraries with druntime caf14b0f,
and phobos 41aaf8c26, synchronizing with the release of 2.099.0-rc1.

D front-end changes:

- Import dmd v2.099.0-rc.1.
- The `main' can now return type `noreturn' and supports return
  inference.

D Runtime changes:

- Import druntime v2.099.0-rc.1.
- C bindings for stat_t on powerpc-linux has been fixed.

Phobos changes:

- Import phobos v2.099.0-rc.1.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* d-target.cc (Target::_init): Initialize C type size fields.
* dmd/MERGE: Merge upstream dmd cf63dd8e5.
* dmd/VERSION: Update version to v2.099.0-rc.1.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime caf14b0f.
* src/MERGE: Merge upstream phobos 41aaf8c26.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/simd7413a.d: Update.
* gdc.dg/ubsan/pr88957.d: Update.
* gdc.dg/simd18489.d: New test.
* gdc.dg/torture/simd21727.d: New test.
---
 gcc/d/d-target.cc |   9 +-
 gcc/d/dmd/MERGE   |   2 +-
 gcc/d/dmd/VERSION |   2 +-
 gcc/d/dmd/common/outbuffer.d  |  32 +-
 gcc/d/dmd/cparse.d|  66 +-
 gcc/d/dmd/cppmangle.d |  44 +-
 gcc/d/dmd/dmangle.d   | 626 +-
 gcc/d/dmd/dmodule.d   |   8 +
 gcc/d/dmd/dsymbolsem.d|   3 +-
 gcc/d/dmd/expressionsem.d |   6 +-
 gcc/d/dmd/file_manager.d  |   6 +-
 gcc/d/dmd/func.d  |  19 +-
 gcc/d/dmd/lexer.d |  12 +-
 gcc/d/dmd/mtype.d |   8 +
 gcc/d/dmd/root/file.d |  40 +-
 gcc/d/dmd/root/speller.d  |  23 +-
 gcc/d/dmd/root/string.d   |  11 +-
 gcc/d/dmd/semantic3.d |  22 +-
 gcc/d/dmd/target.d|   4 +
 gcc/d/dmd/target.h|   4 +
 gcc/d/dmd/tokens.h|  20 +-
 gcc/d/dmd/traits.d|   7 +-
 gcc/d/dmd/typesem.d   |  13 +-
 gcc/testsuite/gdc.dg/simd18489.d  |   8 +
 .../ice21727.d => gdc.dg/torture/simd21727.d} |  11 +-
 gcc/testsuite/gdc.dg/torture/simd7413a.d  |   1 -
 gcc/testsuite/gdc.dg/ubsan/pr88957.d  |   3 +-
 gcc/testsuite/gdc.test/compilable/b18489.d|   8 -
 .../gdc.test/compilable/issue21390.d  |   3 +
 .../gdc.test/fail_compilation/fail17927.d |   2 +-
 .../gdc.test/fail_compilation/fix17751.d  |  22 -
 .../gdc.test/fail_compilation/issue22826.d|   7 +
 .../gdc.test/fail_compilation/test21546.d |  59 ++
 .../gdc.test/fail_compilation/test22023.d |  26 +
 .../gdc.test/fail_compilation/test22818.d |  21 +
 gcc/testsuite/gdc.test/runnable/nan.d |  17 +-
 gcc/testsuite/gdc.test/runnable/previewin.d   |   6 +-
 gcc/testsuite/gdc.test/runnable/sroa13220.d   | 103 ---
 gcc/testsuite/gdc.test/runnable/test15.d  |   2 +-
 gcc/testsuite/gdc.test/runnable/testconst.d   |  16 +-
 gcc/testsuite/gdc.test/runnable/testscope2.d  |   2 +-
 .../runnable/traits_getPointerBitmap.d|   2 +-
 libphobos/libdruntime/MERGE   |   2 +-
 libphobos/libdruntime/core/gc/gcinterface.d   |   4 +-
 libphobos/libdruntime/core/internal/gc/bits.d |  12 +-
 .../core/internal/gc/impl/conservative/gc.d   | 257 ---
 .../libdruntime/core/internal/gc/pooltable.d  |  29 +-
 .../libdruntime/core/internal/gc/proxy.d  |   4 +-
 libphobos/libdruntime/core/memory.d   |   4 +-
 libphobos/libdruntime/core/stdcpp/string.d|   8 +-
 .../libdruntime/core/sys/posix/sys/stat.d |  85 ++-
 libphobos/libdruntime/core/time.d | 158 +++--
 libphobos/libdruntime/object.d|  13 +-
 libphobos/src/MERGE   |   2 +-
 libphobos/src/std/file.d  |   4 +-
 libphobos/src/std/getopt.d|   8 +-
 libphobos/src/std/range/primitives.d  |  11 +-
 libphobos/src/std/sumtype.d   | 108 ++-
 58 files changed, 1164 insertions(+), 851 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/simd18489.d
 rename gcc/testsuite/{gdc.test/runnable/ice21727.d => 
gdc.dg/torture/simd21727.d} (71%)
 delete mode 100644 gcc/testsuite/gdc.test/compilable/b18489.d
 create mode 100644 gcc/testsuite/gdc.test/compilable/issue21390.d
 delete mode 100644 gcc/testsuite/gdc.test/fail_compilation/fix17751.d
 create mode 100644 gcc/testsuite/gdc.test/fail_compilation/issue22826.d
 create mode 100644 gcc/testsuite/gdc.test/fail_compilation/te

[PATCH] doc, d: Add note that D front end now requires GDC installed in order to bootstrap.

2021-11-17 Thread Iain Buclaw via Gcc-patches
Hi,

As asked for, this adds the documentation note in install.texi about the
upcoming bootstrap requirements.

Obviously this will be applied alongside the patch posted previously:

https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582917.html

Final batch of testing before proceeding has taking a bit longer than I
expected.  Currently bootstrapping on sparcv9-sun-solaris2.11, and will
push forward once have confirmed that it works as well as the current
C++ implementation of the D front end.

OK for mainline?  Any improvements on wording?

Thanks,
Iain.

---
gcc/ChangeLog:

* doc/install.texi (Prerequisites): Add note that D front end now
requires GDC installed in order to bootstrap.
(Building): Add D compiler section, referencing prerequisites.
---
 gcc/doc/install.texi | 28 
 1 file changed, 28 insertions(+)

diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 094469b9a4e..6f999a2fd5a 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -289,6 +289,25 @@ Ada runtime libraries. You can check that your build 
environment is clean
 by verifying that @samp{gnatls -v} lists only one explicit path in each
 section.
 
+@item @anchor{GDC-prerequisite}GDC
+
+In order to build GDC, the D compiler, you need a working GDC
+compiler (GCC version 9.1 or later), as the D front end is written in D.
+
+Versions of GDC prior to 12 can be built with an ISO C++11 compiler, which can
+then be installed and used to bootstrap newer versions of the D front end.
+
+It is strongly recommended to use an older version of GDC to build GDC. More
+recent versions of GDC than the version built are not guaranteed to work and
+will often fail during the build with compilation errors relating to
+deprecations or removed features.
+
+Note that @command{configure} does not test whether the GDC installation works
+and has a sufficiently recent version.  Though the implementation of the D
+front end does not make use of any GDC-specific extensions, or novel features
+of the D language, if too old a GDC version is installed and
+@option{--enable-languages=d} is used, the build will fail.
+
 @item A ``working'' POSIX compatible shell, or GNU bash
 
 Necessary when running @command{configure} because some
@@ -2977,6 +2996,15 @@ and network filesystems.
 @uref{prerequisites.html#GNAT-prerequisite,,GNAT prerequisites}.
 @end ifhtml
 
+@section Building the D compiler
+
+@ifnothtml
+@ref{GDC-prerequisite}.
+@end ifnothtml
+@ifhtml
+@uref{prerequisites.html#GDC-prerequisite,,GDC prerequisites}.
+@end ifhtml
+
 @section Building with profile feedback
 
 It is possible to use profile feedback to optimize the compiler itself.  This
-- 
2.30.2



[committed] d: Use HOST_WIDE_INT for type size temporaries.

2021-11-18 Thread Iain Buclaw via Gcc-patches
Hi,

This patch fixes an issue with bootstrap on x86_64-darwin when building
with --enable-werror.

These couple variables are later used as the value for the format
specifier `%wd`, to which the expected type may not match dinteger_t,
causing unnecessary -Wformat warnings.

Bootstrapped and regression tested on x86_64-linux-gnu, committed to
mainline and backported to the releases/gcc-9, gcc-10, and gcc-11
branches as it's obvious what this is doing.

Regards
Iain

---
gcc/d/ChangeLog:

* decl.cc (d_finish_decl): Use HOST_WIDE_INT for type size
temporaries.
---
 gcc/d/decl.cc | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 0d46ee180e7..9c9205fa349 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -1544,8 +1544,9 @@ d_finish_decl (tree decl)
   if (flag_checking && DECL_INITIAL (decl))
 {
   /* Initializer must never be bigger than symbol size.  */
-  dinteger_t tsize = int_size_in_bytes (TREE_TYPE (decl));
-  dinteger_t dtsize = int_size_in_bytes (TREE_TYPE (DECL_INITIAL (decl)));
+  HOST_WIDE_INT tsize = int_size_in_bytes (TREE_TYPE (decl));
+  HOST_WIDE_INT dtsize =
+   int_size_in_bytes (TREE_TYPE (DECL_INITIAL (decl)));
 
   if (tsize < dtsize)
{
-- 
2.30.2



[PATCH] darwin, d: Support outfile substitution for liphobos

2021-11-19 Thread Iain Buclaw via Gcc-patches
Hi,

This patch fixes a stage2 bootstrap failure in the D front-end on
darwin due to libgphobos being dynamically linked despite
-static-libphobos being on the command line.

In the gdc driver, this takes the previous fix for the Darwin D
bootstrap, and extends it to the -static-libphobos option as well.
Rather than pushing the -static-libphobos option back onto the command
line, the setting of SKIPOPT is instead conditionally removed.  The same
change has been repeated for -static-libstdc++ so there is now no need
to call generate_option to re-add it.

In the gcc driver, -static-libphobos has been added as a common option,
validated, and a new outfile substition added to config/darwin.h to
correctly replace -lgphobos with libgphobos.a.

Bootstrapped and regression tested on x86_64-linux-gnu and
x86_64-apple-darwin20.

OK for mainline?  This would also be fine for gcc-11 release branch too,
as well as earlier releases with D support.

Regards,
Iain.

---
gcc/ChangeLog:

* common.opt (static-libphobos): Add option.
* config/darwin.h (LINK_SPEC): Substitute -lgphobos with libgphobos.a
when linking statically.
* gcc.c (driver_handle_option): Set -static-libphobos as always valid.

gcc/d/ChangeLog:

* d-spec.cc (lang_specific_driver): Set SKIPOPT on -static-libstdc++
and -static-libphobos only when target supports LD_STATIC_DYNAMIC.
Remove generate_option to re-add -static-libstdc++.
---
 gcc/common.opt  |  4 
 gcc/config/darwin.h |  1 +
 gcc/d/d-spec.cc | 18 +++---
 gcc/gcc.c   |  6 --
 4 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/gcc/common.opt b/gcc/common.opt
index db6010e4e20..73c12d933f3 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -3527,6 +3527,10 @@ static-libgfortran
 Driver
 ; Documented for Fortran, but always accepted by driver.
 
+static-libphobos
+Driver
+; Documented for D, but always accepted by driver.
+
 static-libstdc++
 Driver
 
diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
index 7ed01efa694..c4ddd623e8b 100644
--- a/gcc/config/darwin.h
+++ b/gcc/config/darwin.h
@@ -443,6 +443,7 @@ extern GTY(()) int darwin_ms_struct;
  %:replace-outfile(-lobjc libobjc-gnu.a%s); \
 :%:replace-outfile(-lobjc -lobjc-gnu )}}\
%{static|static-libgcc|static-libgfortran:%:replace-outfile(-lgfortran 
libgfortran.a%s)}\
+   %{static|static-libgcc|static-libphobos:%:replace-outfile(-lgphobos 
libgphobos.a%s)}\

%{static|static-libgcc|static-libstdc++|static-libgfortran:%:replace-outfile(-lgomp
 libgomp.a%s)}\
%{static|static-libgcc|static-libstdc++:%:replace-outfile(-lstdc++ 
libstdc++.a%s)}\
%{force_cpusubtype_ALL:-arch %(darwin_arch)} \
diff --git a/gcc/d/d-spec.cc b/gcc/d/d-spec.cc
index b12d28f1047..73ecac3bbf1 100644
--- a/gcc/d/d-spec.cc
+++ b/gcc/d/d-spec.cc
@@ -253,13 +253,23 @@ lang_specific_driver (cl_decoded_option 
**in_decoded_options,
 
case OPT_static_libstdc__:
  saw_static_libcxx = true;
+#ifndef HAVE_LD_STATIC_DYNAMIC
+ /* Remove -static-libstdc++ from the command only if target supports
+LD_STATIC_DYNAMIC.  When not supported, it is left in so that a
+back-end target can use outfile substitution.  */
  args[i] |= SKIPOPT;
+#endif
  break;
 
case OPT_static_libphobos:
  if (phobos_library != PHOBOS_NOLINK)
phobos_library = PHOBOS_STATIC;
+#ifndef HAVE_LD_STATIC_DYNAMIC
+ /* Remove -static-libphobos from the command only if target supports
+LD_STATIC_DYNAMIC.  When not supported, it is left in so that a
+back-end target can use outfile substitution.  */
  args[i] |= SKIPOPT;
+#endif
  break;
 
case OPT_shared_libphobos:
@@ -460,7 +470,7 @@ lang_specific_driver (cl_decoded_option 
**in_decoded_options,
 #endif
 }
 
-  if (saw_libcxx || need_stdcxx)
+  if (saw_libcxx || saw_static_libcxx || need_stdcxx)
 {
 #ifdef HAVE_LD_STATIC_DYNAMIC
   if (saw_static_libcxx && !static_link)
@@ -468,12 +478,6 @@ lang_specific_driver (cl_decoded_option 
**in_decoded_options,
  generate_option (OPT_Wl_, LD_STATIC_OPTION, 1, CL_DRIVER,
   &new_decoded_options[j++]);
}
-#else
-  /* Push the -static-libstdc++ option back onto the command so that
-a target without LD_STATIC_DYNAMIC can use outfile substitution.  */
-  if (saw_static_libcxx && !static_link)
-   generate_option (OPT_static_libstdc__, NULL, 1, CL_DRIVER,
-&new_decoded_options[j++]);
 #endif
   if (saw_libcxx)
new_decoded_options[j++] = *saw_libcxx;
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 506c2acc282..fea6d049183 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -4576,10 +4576,12 @@ driver_handle_option (struct gcc_options *opts,
 case OPT_static_libgcc:
 case OPT_shared_libgcc:
 case OPT_static_libgfortran:
+case OPT_

Re: [PATCH] darwin, d: Support outfile substitution for liphobos

2021-11-19 Thread Iain Buclaw via Gcc-patches
Excerpts from Iain Sandoe's message of November 19, 2021 10:21 am:
> Hi Iain
> 
>> On 19 Nov 2021, at 08:32, Iain Buclaw  wrote:
> 
>> This patch fixes a stage2 bootstrap failure in the D front-end on
>> darwin due to libgphobos being dynamically linked despite
>> -static-libphobos being on the command line.
>> 
>> In the gdc driver, this takes the previous fix for the Darwin D
>> bootstrap, and extends it to the -static-libphobos option as well.
>> Rather than pushing the -static-libphobos option back onto the command
>> line, the setting of SKIPOPT is instead conditionally removed.  The same
>> change has been repeated for -static-libstdc++ so there is now no need
>> to call generate_option to re-add it.
>> 
>> In the gcc driver, -static-libphobos has been added as a common option,
>> validated, and a new outfile substition added to config/darwin.h to
>> correctly replace -lgphobos with libgphobos.a.
>> 
>> Bootstrapped and regression tested on x86_64-linux-gnu and
>> x86_64-apple-darwin20.
>> 
>> OK for mainline?  This would also be fine for gcc-11 release branch too,
>> as well as earlier releases with D support.
> 
> the Darwin parts are fine, thanks 
> 
> The SKIPOPT in d-spec, presumably means “skip removing this opt”?
> otherwise the #ifndef looks odd (because of the 
> static-libgcc|static-libphobos,
> darwin.h would do the substitution for -static-libgcc as well, so it’s not a 
> 100%
> test).
> 

The inverse. SKIPOPT means "skip this option", so previously it was
being removed by the driver when constructing the new_decoded_options,
hence why your generate_option addition was necessary before.

Iain.

> Iain
> 
>> 
>> Regards,
>> Iain.
>> 
>> ---
>> gcc/ChangeLog:
>> 
>>  * common.opt (static-libphobos): Add option.
>>  * config/darwin.h (LINK_SPEC): Substitute -lgphobos with libgphobos.a
>>  when linking statically.
>>  * gcc.c (driver_handle_option): Set -static-libphobos as always valid.
>> 
>> gcc/d/ChangeLog:
>> 
>>  * d-spec.cc (lang_specific_driver): Set SKIPOPT on -static-libstdc++
>>  and -static-libphobos only when target supports LD_STATIC_DYNAMIC.
>>  Remove generate_option to re-add -static-libstdc++.
>> ---
>> gcc/common.opt  |  4 
>> gcc/config/darwin.h |  1 +
>> gcc/d/d-spec.cc | 18 +++---
>> gcc/gcc.c   |  6 --
>> 4 files changed, 20 insertions(+), 9 deletions(-)
>> 
>> diff --git a/gcc/common.opt b/gcc/common.opt
>> index db6010e4e20..73c12d933f3 100644
>> --- a/gcc/common.opt
>> +++ b/gcc/common.opt
>> @@ -3527,6 +3527,10 @@ static-libgfortran
>> Driver
>> ; Documented for Fortran, but always accepted by driver.
>> 
>> +static-libphobos
>> +Driver
>> +; Documented for D, but always accepted by driver.
>> +
>> static-libstdc++
>> Driver
>> 
>> diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
>> index 7ed01efa694..c4ddd623e8b 100644
>> --- a/gcc/config/darwin.h
>> +++ b/gcc/config/darwin.h
>> @@ -443,6 +443,7 @@ extern GTY(()) int darwin_ms_struct;
>>  %:replace-outfile(-lobjc libobjc-gnu.a%s); \
>> :%:replace-outfile(-lobjc -lobjc-gnu )}}\
>>%{static|static-libgcc|static-libgfortran:%:replace-outfile(-lgfortran 
>> libgfortran.a%s)}\
>> +   %{static|static-libgcc|static-libphobos:%:replace-outfile(-lgphobos 
>> libgphobos.a%s)}\
>>
>> %{static|static-libgcc|static-libstdc++|static-libgfortran:%:replace-outfile(-lgomp
>>  libgomp.a%s)}\
>>%{static|static-libgcc|static-libstdc++:%:replace-outfile(-lstdc++ 
>> libstdc++.a%s)}\
>>%{force_cpusubtype_ALL:-arch %(darwin_arch)} \
>> diff --git a/gcc/d/d-spec.cc b/gcc/d/d-spec.cc
>> index b12d28f1047..73ecac3bbf1 100644
>> --- a/gcc/d/d-spec.cc
>> +++ b/gcc/d/d-spec.cc
>> @@ -253,13 +253,23 @@ lang_specific_driver (cl_decoded_option 
>> **in_decoded_options,
>> 
>>  case OPT_static_libstdc__:
>>saw_static_libcxx = true;
>> +#ifndef HAVE_LD_STATIC_DYNAMIC
>> +  /* Remove -static-libstdc++ from the command only if target supports
>> + LD_STATIC_DYNAMIC.  When not supported, it is left in so that a
>> + back-end target can use outfile substitution.  */
>>args[i] |= SKIPOPT;
>> +#endif
>>break;
>> 
>>  case OPT_static_libphobos:
>>if (phobos_library != PHOBOS_NOLINK)
>>  phobos_library = PHOBOS_STATIC;
>> +#ifndef HAVE_LD_STATIC_DYNAMIC
>> +  /* Remove -static-libphobos from the command only if target supports
>> + LD_STATIC_DYNAMIC.  When not supported, it is left in so that a
>> + back-end target can use outfile substitution.  */
>>args[i] |= SKIPOPT;
>> +#endif
>>break;
>> 
>>  case OPT_shared_libphobos:
>> @@ -460,7 +470,7 @@ lang_specific_driver (cl_decoded_option 
>> **in_decoded_options,
>> #endif
>> }
>> 
>> -  if (saw_libcxx || need_stdcxx)
>> +  if (saw_libcxx || saw_static_libcxx || need_stdcxx)
>> {
>> #ifdef HAVE_LD_STATIC_DYNAMIC
>>   if (saw_static_libcxx && !static_link)
>> @@ -468,1

[committed] libphobos: Don't call __gthread_key_delete in the emutls destroy function.

2021-11-19 Thread Iain Buclaw via Gcc-patches
Hi,

This patch fixes a EXC_BAD_ACCESS issue seen on Darwin when the
libphobos DSO gets unloaded.  Based on reading libgcc's emutls
implementation, as it doesn't call __gthread_key_delete directly,
neither should libphobos.

Bootstrapped and regression tested on x86_64-linux-gnu and
x86_64-apple-darwin20, committed to mainline, and backported to the
release branches.

Regards,
Iain

---
libphobos/ChangeLog:

* libdruntime/gcc/emutls.d (emutlsDestroyThread): Don't remove entry
from global array.
(_d_emutls_destroy): Don't call __gthread_key_delete.
---
 libphobos/libdruntime/gcc/emutls.d | 6 --
 1 file changed, 6 deletions(-)

diff --git a/libphobos/libdruntime/gcc/emutls.d 
b/libphobos/libdruntime/gcc/emutls.d
index 4237dc7a3df..462230508ab 100644
--- a/libphobos/libdruntime/gcc/emutls.d
+++ b/libphobos/libdruntime/gcc/emutls.d
@@ -229,9 +229,6 @@ void** emutlsAlloc(shared __emutls_object* obj) nothrow 
@nogc
 extern (C) void emutlsDestroyThread(void* ptr) nothrow @nogc
 {
 auto arr = cast(TlsArray*) ptr;
-emutlsMutex.lock_nothrow();
-emutlsArrays.remove(arr);
-emutlsMutex.unlock_nothrow();
 
 foreach (entry; *arr)
 {
@@ -308,9 +305,6 @@ void _d_emutls_scan(scope void delegate(void* pbeg, void* 
pend) nothrow cb) noth
 // Call this after druntime has been unloaded
 void _d_emutls_destroy() nothrow @nogc
 {
-if (__gthread_key_delete(emutlsKey) != 0)
-abort();
-
 (cast(Mutex) _emutlsMutex.ptr).__dtor();
 destroy(emutlsArrays);
 }
-- 
2.30.2



[committed] libphobos: Increase size of defaultStackPages on OSX X86_64 targets.

2021-11-19 Thread Iain Buclaw via Gcc-patches
Hi,

As of macOS 11, libunwind now requires more stack space than 16k, so
default to a larger stack size. This is only applied to X86 as the
PAGESIZE is still 4k, however on AArch64 it is 16k.

Regression tested on x86_64-linux-gnu and x86_64-apple-darwin20,
committed to mainline and backported to the release branches.

Regards,
Iain.

---
libphobos/ChangeLog:

* libdruntime/core/thread/fiber.d (defaultStackPages): Increase size
on OSX X86_64 targets.
---
 libphobos/libdruntime/core/thread/fiber.d | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/libphobos/libdruntime/core/thread/fiber.d 
b/libphobos/libdruntime/core/thread/fiber.d
index f4c04ce7358..2f90f179edb 100644
--- a/libphobos/libdruntime/core/thread/fiber.d
+++ b/libphobos/libdruntime/core/thread/fiber.d
@@ -595,6 +595,16 @@ class Fiber
 // the existence of debug symbols and other conditions. Avoid causing
 // stack overflows by defaulting to a larger stack size
 enum defaultStackPages = 8;
+else version (OSX)
+{
+version (X86_64)
+// libunwind on macOS 11 now requires more stack space than 16k, so
+// default to a larger stack size. This is only applied to X86 as
+// the PAGESIZE is still 4k, however on AArch64 it is 16k.
+enum defaultStackPages = 8;
+else
+enum defaultStackPages = 4;
+}
 else
 enum defaultStackPages = 4;
 
-- 
2.30.2



Re: [PATCH] libphobos, testsuite: Add prune clauses for two Darwin cases.

2021-11-19 Thread Iain Buclaw via Gcc-patches
Excerpts from Iain Sandoe's message of November 19, 2021 4:59 pm:
> Depending on the permutation of CPU, OS version and shared/non-
> shared library inclusion, we get can get two warnings from the
> external tools (ld64, dsymutil) which are not actually GCC issues
> but relate to the external tools.  These are already pruned in
> the main testsuite, this adds them to the library.
> 
> tested on x86_64,i686-darwin17 where the problem shows up.
> OK for master / backports?
> thanks
> Iain
> 

OK from me.
Iain.


> Signed-off-by: Iain Sandoe 
> 
> libphobos/ChangeLog:
> 
>   * testsuite/lib/libphobos.exp: Prune warnings from external
>   tool bugs.
> ---
>  libphobos/testsuite/lib/libphobos.exp | 7 +++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/libphobos/testsuite/lib/libphobos.exp 
> b/libphobos/testsuite/lib/libphobos.exp
> index 3be2092b12e..2af430a0e45 100644
> --- a/libphobos/testsuite/lib/libphobos.exp
> +++ b/libphobos/testsuite/lib/libphobos.exp
> @@ -90,6 +90,13 @@ proc libphobos-dg-test { prog do_what extra_tool_flags } {
>  }
>  
>  proc libphobos-dg-prune { system text } {
> +
> +# Ignore harmless warnings from Xcode.
> +regsub -all "(^|\n)\[^\n\]*ld: warning: could not create compact unwind 
> for\[^\n\]*" $text "" text
> +
> +# Ignore dsymutil warning (tool bug is actually linker)
> +regsub -all "(^|\n)\[^\n\]*could not find object file symbol for 
> symbol\[^\n\]*" $text "" text
> +
>  return $text
>  }
>  
> -- 
> 2.24.3 (Apple Git-128)
> 
> 


Re: [PATCH] d: fix ASAN in option processing

2021-11-26 Thread Iain Buclaw via Gcc-patches
Excerpts from Martin Liška's message of November 25, 2021 2:59 pm:
> Fixes:
> 
> ==129444==ERROR: AddressSanitizer: global-buffer-overflow on address 
> 0x0666ca5c at pc 0x00ef094b bp 0x7fff8180 sp 0x7fff8178
> READ of size 4 at 0x0666ca5c thread T0
>  #0 0xef094a in parse_optimize_options ../../gcc/d/d-attribs.cc:855
>  #1 0xef0d36 in d_handle_optimize_attribute ../../gcc/d/d-attribs.cc:916
>  #2 0xef107e in d_handle_optimize_attribute ../../gcc/d/d-attribs.cc:887
>  #3 0xff85b1 in decl_attributes(tree_node**, tree_node*, int, tree_node*) 
> ../../gcc/attribs.c:829
>  #4 0xef2a91 in apply_user_attributes(Dsymbol*, tree_node*) 
> ../../gcc/d/d-attribs.cc:427
>  #5 0xf7b7f3 in get_symbol_decl(Declaration*) ../../gcc/d/decl.cc:1346
>  #6 0xf87bc7 in get_symbol_decl(Declaration*) ../../gcc/d/decl.cc:967
>  #7 0xf87bc7 in DeclVisitor::visit(FuncDeclaration*) 
> ../../gcc/d/decl.cc:808
>  #8 0xf83db5 in DeclVisitor::build_dsymbol(Dsymbol*) 
> ../../gcc/d/decl.cc:146
> 
> for the following test-case: gcc/testsuite/gdc.dg/attr_optimize1.d.
> 
> Ready for master?

Thanks, looks OK to me, does it need backporting as well?

Iain.



> Thanks,
> Martin
> 
> gcc/d/ChangeLog:
> 
>   * d-attribs.cc (parse_optimize_options): Check index before
>   accessing cl_options.
> ---
>   gcc/d/d-attribs.cc | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/gcc/d/d-attribs.cc b/gcc/d/d-attribs.cc
> index d81b7d122f7..1ec800526f7 100644
> --- a/gcc/d/d-attribs.cc
> +++ b/gcc/d/d-attribs.cc
> @@ -852,7 +852,9 @@ parse_optimize_options (tree args)
> unsigned j = 1;
> for (unsigned i = 1; i < decoded_options_count; ++i)
>   {
> -  if (! (cl_options[decoded_options[i].opt_index].flags & 
> CL_OPTIMIZATION))
> +  unsigned opt_index = decoded_options[i].opt_index;
> +  if (opt_index >= cl_options_count
> +   && ! (cl_options[opt_index].flags & CL_OPTIMIZATION))
>   {
> ret = false;
> warning (OPT_Wattributes,
> -- 
> 2.34.0
> 
> 


Re: [committed 03/12] d: Insert null terminator in obstack buffers

2021-11-26 Thread Iain Buclaw via Gcc-patches
Excerpts from Martin Liška's message of November 25, 2021 3:09 pm:
> On 7/30/21 13:01, Iain Buclaw via Gcc-patches wrote:
>> |Covers cases where functions that handle the extracted strings ignore the 
>> explicit length. This isn't something that's known to happen in the current 
>> front-end, but the self-hosted front-end has been observed to do this in its 
>> conversions between D and C-style strings.|
> 
> Can you please cherry pick this for gcc-11 branch as I see nasty output when 
> using --verbose:
> 
> $ gcc /home/marxin/Programming/gcc/gcc/testsuite/gdc.dg/attr_optimize4.d -c 
> --verbose
> ...
> predefs   GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions 
> GNU_StackGrowsDown GNU_InlineAsm D_LP64 assert D_ModuleInfo D_Exceptions 
> D_TypeInfo all X86_64 D_HardFloat Posix linux CRuntime_Glibc 
> CppRuntime_Gcc��...
> 
> 

Ouch, I'll have a look at gcc-9 and 10 too to see if they are the same.

Iain.


Re: [PATCH] darwin, d: Support outfile substitution for liphobos

2021-11-26 Thread Iain Buclaw via Gcc-patches
Excerpts from Iain Sandoe's message of November 19, 2021 10:21 am:
> Hi Iain
> 
>> On 19 Nov 2021, at 08:32, Iain Buclaw  wrote:
> 
>> This patch fixes a stage2 bootstrap failure in the D front-end on
>> darwin due to libgphobos being dynamically linked despite
>> -static-libphobos being on the command line.
>> 
>> In the gdc driver, this takes the previous fix for the Darwin D
>> bootstrap, and extends it to the -static-libphobos option as well.
>> Rather than pushing the -static-libphobos option back onto the command
>> line, the setting of SKIPOPT is instead conditionally removed.  The same
>> change has been repeated for -static-libstdc++ so there is now no need
>> to call generate_option to re-add it.
>> 
>> In the gcc driver, -static-libphobos has been added as a common option,
>> validated, and a new outfile substition added to config/darwin.h to
>> correctly replace -lgphobos with libgphobos.a.
>> 
>> Bootstrapped and regression tested on x86_64-linux-gnu and
>> x86_64-apple-darwin20.
>> 
>> OK for mainline?  This would also be fine for gcc-11 release branch too,
>> as well as earlier releases with D support.
> 
> the Darwin parts are fine, thanks 
> 
> The SKIPOPT in d-spec, presumably means “skip removing this opt”?
> otherwise the #ifndef looks odd (because of the 
> static-libgcc|static-libphobos,
> darwin.h would do the substitution for -static-libgcc as well, so it’s not a 
> 100%
> test).
> 

I've only just realised what you meant.  Yes you are of course right,
and it should have been #ifdef, attaching a fixed-up patch.

Iain.

---
gcc/ChangeLog:

* common.opt (static-libphobos): Add option.
* config/darwin.h (LINK_SPEC): Substitute -lgphobos with 
libgphobos.a
when linking statically.
* gcc.c (driver_handle_option): Set -static-libphobos as always 
valid.

gcc/d/ChangeLog:

* d-spec.cc (lang_specific_driver): Set SKIPOPT on -static-libstdc++
and -static-libphobos only when target supports LD_STATIC_DYNAMIC.
Remove generate_option to re-add -static-libstdc++.

libphobos/ChangeLog:

* testsuite/testsuite_flags.in: Add libphobos library directory as
search path to --gdcldflags.

diff --git a/gcc/common.opt b/gcc/common.opt
index db6010e4e20..73c12d933f3 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -3527,6 +3527,10 @@ static-libgfortran
 Driver
 ; Documented for Fortran, but always accepted by driver.
 
+static-libphobos
+Driver
+; Documented for D, but always accepted by driver.
+
 static-libstdc++
 Driver
 
diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
index 7ed01efa694..c4ddd623e8b 100644
--- a/gcc/config/darwin.h
+++ b/gcc/config/darwin.h
@@ -443,6 +443,7 @@ extern GTY(()) int darwin_ms_struct;
  %:replace-outfile(-lobjc libobjc-gnu.a%s); \
 :%:replace-outfile(-lobjc -lobjc-gnu )}}\
%{static|static-libgcc|static-libgfortran:%:replace-outfile(-lgfortran 
libgfortran.a%s)}\
+   %{static|static-libgcc|static-libphobos:%:replace-outfile(-lgphobos 
libgphobos.a%s)}\

%{static|static-libgcc|static-libstdc++|static-libgfortran:%:replace-outfile(-lgomp
 libgomp.a%s)}\
%{static|static-libgcc|static-libstdc++:%:replace-outfile(-lstdc++ 
libstdc++.a%s)}\
%{force_cpusubtype_ALL:-arch %(darwin_arch)} \
diff --git a/gcc/d/d-spec.cc b/gcc/d/d-spec.cc
index b12d28f1047..1304126a675 100644
--- a/gcc/d/d-spec.cc
+++ b/gcc/d/d-spec.cc
@@ -253,13 +253,23 @@ lang_specific_driver (cl_decoded_option 
**in_decoded_options,
 
case OPT_static_libstdc__:
  saw_static_libcxx = true;
+#ifdef HAVE_LD_STATIC_DYNAMIC
+ /* Remove -static-libstdc++ from the command only if target supports
+LD_STATIC_DYNAMIC.  When not supported, it is left in so that a
+back-end target can use outfile substitution.  */
  args[i] |= SKIPOPT;
+#endif
  break;
 
case OPT_static_libphobos:
  if (phobos_library != PHOBOS_NOLINK)
phobos_library = PHOBOS_STATIC;
+#ifdef HAVE_LD_STATIC_DYNAMIC
+ /* Remove -static-libphobos from the command only if target supports
+LD_STATIC_DYNAMIC.  When not supported, it is left in so that a
+back-end target can use outfile substitution.  */
  args[i] |= SKIPOPT;
+#endif
  break;
 
case OPT_shared_libphobos:
@@ -460,7 +470,7 @@ lang_specific_driver (cl_decoded_option 
**in_decoded_options,
 #endif
 }
 
-  if (saw_libcxx || need_stdcxx)
+  if (saw_libcxx || saw_static_libcxx || need_stdcxx)
 {
 #ifdef HAVE_LD_STATIC_DYNAMIC
   if (saw_static_libcxx && !static_link)
@@ -468,12 +478,6 @@ lang_specific_driver (cl_decoded_option 
**in_decoded_options,
  generate_option (OPT_Wl_, LD_STATIC_OPTION, 1, CL_DRIVER,
   &new_decoded_options[j++]);
}
-#else
-  /* Push the -static-libstdc++ option back onto the command

Re: [committed 03/12] d: Insert null terminator in obstack buffers

2021-11-28 Thread Iain Buclaw via Gcc-patches
Excerpts from Iain Buclaw's message of November 26, 2021 1:35 pm:
> Excerpts from Martin Liška's message of November 25, 2021 3:09 pm:
>> On 7/30/21 13:01, Iain Buclaw via Gcc-patches wrote:
>>> |Covers cases where functions that handle the extracted strings ignore the 
>>> explicit length. This isn't something that's known to happen in the current 
>>> front-end, but the self-hosted front-end has been observed to do this in 
>>> its conversions between D and C-style strings.|
>> 
>> Can you please cherry pick this for gcc-11 branch as I see nasty output when 
>> using --verbose:
>> 
>> $ gcc /home/marxin/Programming/gcc/gcc/testsuite/gdc.dg/attr_optimize4.d -c 
>> --verbose
>> ...
>> predefs   GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions 
>> GNU_StackGrowsDown GNU_InlineAsm D_LP64 assert D_ModuleInfo D_Exceptions 
>> D_TypeInfo all X86_64 D_HardFloat Posix linux CRuntime_Glibc 
>> CppRuntime_Gcc��...
>> 
>> 
> 
> Ouch, I'll have a look at gcc-9 and 10 too to see if they are the same.
> 

FYI, patch applied cleanly to gcc-11 branch and has been committed.
Saw no regressions on x86_64-linux-gnu in both bootstrap and tests.

Checked other branches, however earlier releases used the dmd
front-end's OutBuffer, so are unaffected.

Iain.


[committed 10/19] libphobos: Update libgdruntime to build with latest version

2021-11-30 Thread Iain Buclaw via Gcc-patches
Updates the make files, and the gdc-specific modules of druntime.

Bootstrapped, regression tested, and committed to mainline.

Regards,
Iain.

---
libphobos/ChangeLog:

* libdruntime/Makefile.am (D_EXTRA_FLAGS): Build libdruntime with
-fpreview=dip1000, -fpreview=fieldwise, and -fpreview=dtorfields.
(ALL_DRUNTIME_SOURCES): Add DRUNTIME_DSOURCES_STDCXX.
(DRUNTIME_DSOURCES): Update list of C binding modules.
(DRUNTIME_DSOURCES_STDCXX): Likewise.
(DRUNTIME_DSOURCES_LINUX): Likewise.
(DRUNTIME_DSOURCES_OPENBSD): Likewise.
(DRUNTIME_DISOURCES): Remove __entrypoint.di.
* libdruntime/Makefile.in: Regenerated.
* libdruntime/__entrypoint.di: Removed.
* libdruntime/gcc/backtrace.d (FIRSTFRAME): Remove.
(LibBacktrace.MaxAlignment): Remove.
(LibBacktrace.this): Remove default initialization of firstFrame.
(UnwindBacktrace.this): Likewise.
* libdruntime/gcc/deh.d (_d_isbaseof): Update signature.
(_d_createTrace): Likewise.
(__gdc_begin_catch): Remove reference to the exception.
(_d_throw): Increment reference count of thrown object before unwind.
(__gdc_personality): Chain exceptions with  Throwable.chainTogether.
* libdruntime/gcc/emutls.d: Update imports.
* libdruntime/gcc/sections/elf.d: Update imports.
(DSO.moduleGroup): Update signature.
* libdruntime/gcc/sections/macho.d: Update imports.
(DSO.moduleGroup): Update signature.
* libdruntime/gcc/sections/pecoff.d: Update imports.
(DSO.moduleGroup): Update signature.
* libdruntime/gcc/unwind/generic.d (__aligned__): Define.
---
 libphobos/libdruntime/Makefile.am   |   6 +-
 libphobos/libdruntime/Makefile.in   | 148 
 libphobos/libdruntime/__entrypoint.di   |  56 
 libphobos/libdruntime/gcc/deh.d |  22 +--
 libphobos/libdruntime/gcc/emutls.d  |   3 +-
 libphobos/libdruntime/gcc/sections/elf.d|   6 +-
 libphobos/libdruntime/gcc/sections/macho.d  |   6 +-
 libphobos/libdruntime/gcc/sections/pecoff.d |   6 +-
 8 files changed, 116 insertions(+), 137 deletions(-)
 delete mode 100644 libphobos/libdruntime/__entrypoint.di

diff --git a/libphobos/libdruntime/Makefile.am 
b/libphobos/libdruntime/Makefile.am
index 80fc0badcff..80c7567079a 100644
--- a/libphobos/libdruntime/Makefile.am
+++ b/libphobos/libdruntime/Makefile.am
@@ -19,7 +19,8 @@
 include $(top_srcdir)/d_rules.am
 
 # Make sure GDC can find libdruntime include files
-D_EXTRA_DFLAGS=-nostdinc -I $(srcdir) -I .
+D_EXTRA_DFLAGS=-fpreview=dip1000 -fpreview=fieldwise -fpreview=dtorfields \
+  -nostdinc -I $(srcdir) -I .
 
 # D flags for compilation
 AM_DFLAGS= \
@@ -119,6 +120,7 @@ endif
 DRUNTIME_DSOURCES_GENERATED = gcc/config.d gcc/libbacktrace.d
 
 ALL_DRUNTIME_SOURCES = $(DRUNTIME_DSOURCES) $(DRUNTIME_CSOURCES) \
+   $(DRUNTIME_DSOURCES_STDCXX) \
$(DRUNTIME_SOURCES_CONFIGURED) $(DRUNTIME_DSOURCES_GENERATED)
 
 # Need this library to both be part of libgphobos.a, and installed separately.
@@ -422,4 +424,4 @@ DRUNTIME_DSOURCES_WINDOWS = core/sys/windows/accctrl.d \
core/sys/windows/winuser.d core/sys/windows/winver.d \
core/sys/windows/wtsapi32.d core/sys/windows/wtypes.d
 
-DRUNTIME_DISOURCES = __entrypoint.di __main.di
+DRUNTIME_DISOURCES = __main.di
diff --git a/libphobos/libdruntime/Makefile.in 
b/libphobos/libdruntime/Makefile.in
index cdb1fe3cc18..b5f29da8540 100644
--- a/libphobos/libdruntime/Makefile.in
+++ b/libphobos/libdruntime/Makefile.in
@@ -245,7 +245,13 @@ am__objects_1 = core/atomic.lo core/attribute.lo 
core/bitop.lo \
rt/monitor_.lo rt/profilegc.lo rt/sections.lo rt/tlsgc.lo \
rt/util/typeinfo.lo rt/util/utility.lo
 am__objects_2 = core/stdc/libgdruntime_la-errno_.lo
-am__objects_3 = core/sys/posix/aio.lo core/sys/posix/arpa/inet.lo \
+am__objects_3 = core/stdcpp/allocator.lo core/stdcpp/array.lo \
+   core/stdcpp/exception.lo core/stdcpp/memory.lo \
+   core/stdcpp/new_.lo core/stdcpp/string.lo \
+   core/stdcpp/string_view.lo core/stdcpp/type_traits.lo \
+   core/stdcpp/typeinfo.lo core/stdcpp/utility.lo \
+   core/stdcpp/vector.lo core/stdcpp/xutility.lo
+am__objects_4 = core/sys/posix/aio.lo core/sys/posix/arpa/inet.lo \
core/sys/posix/config.lo core/sys/posix/dirent.lo \
core/sys/posix/dlfcn.lo core/sys/posix/fcntl.lo \
core/sys/posix/grp.lo core/sys/posix/iconv.lo \
@@ -272,8 +278,8 @@ am__objects_3 = core/sys/posix/aio.lo 
core/sys/posix/arpa/inet.lo \
core/sys/posix/syslog.lo core/sys/posix/termios.lo \
core/sys/posix/time.lo core/sys/posix/ucontext.lo \
core/sys/posix/unistd.lo core/sys/posix/utime.lo
-@DRUNTIME_OS_POSIX_TRUE@am__objects_4 = $(am__objects_3)
-am__objects_5 = core/sys/darwin/config.lo \
+@DRUNTIME_OS_POSIX_TRUE@am__objects_5 = $(am__objects_4)
+am__objects_6 = core/sys/d

[committed 14/19] libphobos: Update libphobos to build latest version

2021-11-30 Thread Iain Buclaw via Gcc-patches
Updates the make files that build phobos.

Bootstrapped, regression tested, and committed to mainline.

Regards,
Iain.

---
libphobos/ChangeLog:

* src/Makefile.am (D_EXTRA_DFLAGS): Add -fpreview=dip1000 and
-fpreview=dtorfields flags.
(PHOBOS_DSOURCES): Update list of std modules.
* src/Makefile.in: Regenerate.
---
 libphobos/src/Makefile.am |  47 +++-
 libphobos/src/Makefile.in | 145 ++
 2 files changed, 142 insertions(+), 50 deletions(-)

diff --git a/libphobos/src/Makefile.am b/libphobos/src/Makefile.am
index 9f6251009f6..ba1579da8d7 100644
--- a/libphobos/src/Makefile.am
+++ b/libphobos/src/Makefile.am
@@ -19,7 +19,7 @@
 include $(top_srcdir)/d_rules.am
 
 # Make sure GDC can find libdruntime and libphobos include files
-D_EXTRA_DFLAGS=-nostdinc -I $(srcdir) \
+D_EXTRA_DFLAGS=-fpreview=dip1000 -fpreview=dtorfields -nostdinc -I $(srcdir) \
-I $(top_srcdir)/libdruntime -I ../libdruntime -I .
 
 # D flags for compilation
@@ -83,12 +83,12 @@ PHOBOS_DSOURCES =
 
 else
 
-PHOBOS_DSOURCES = etc/c/curl.d etc/c/sqlite3.d etc/c/zlib.d \
-   std/algorithm/comparison.d std/algorithm/internal.d \
-   std/algorithm/iteration.d std/algorithm/mutation.d \
-   std/algorithm/package.d std/algorithm/searching.d \
-   std/algorithm/setops.d std/algorithm/sorting.d std/array.d std/ascii.d \
-   std/base64.d std/bigint.d std/bitmanip.d std/compiler.d std/complex.d \
+PHOBOS_DSOURCES = etc/c/curl.d etc/c/zlib.d std/algorithm/comparison.d \
+   std/algorithm/internal.d std/algorithm/iteration.d \
+   std/algorithm/mutation.d std/algorithm/package.d \
+   std/algorithm/searching.d std/algorithm/setops.d \
+   std/algorithm/sorting.d std/array.d std/ascii.d std/base64.d \
+   std/bigint.d std/bitmanip.d std/compiler.d std/complex.d \
std/concurrency.d std/container/array.d std/container/binaryheap.d \
std/container/dlist.d std/container/package.d std/container/rbtree.d \
std/container/slist.d std/container/util.d std/conv.d std/csv.d \
@@ -99,7 +99,9 @@ PHOBOS_DSOURCES = etc/c/curl.d etc/c/sqlite3.d etc/c/zlib.d \
std/digest/murmurhash.d std/digest/package.d std/digest/ripemd.d \
std/digest/sha.d std/encoding.d std/exception.d \
std/experimental/allocator/building_blocks/affix_allocator.d \
+   std/experimental/allocator/building_blocks/aligned_block_list.d \
std/experimental/allocator/building_blocks/allocator_list.d \
+   std/experimental/allocator/building_blocks/ascending_page_allocator.d \
std/experimental/allocator/building_blocks/bitmapped_block.d \
std/experimental/allocator/building_blocks/bucketizer.d \
std/experimental/allocator/building_blocks/fallback_allocator.d \
@@ -123,27 +125,34 @@ PHOBOS_DSOURCES = etc/c/curl.d etc/c/sqlite3.d 
etc/c/zlib.d \
std/experimental/logger/core.d std/experimental/logger/filelogger.d \
std/experimental/logger/multilogger.d \
std/experimental/logger/nulllogger.d std/experimental/logger/package.d \
-   std/experimental/typecons.d std/file.d std/format.d std/functional.d \
-   std/getopt.d std/internal/cstring.d std/internal/math/biguintcore.d \
-   std/internal/math/biguintnoasm.d std/internal/math/errorfunction.d \
-   std/internal/math/gammafunction.d std/internal/scopebuffer.d \
+   std/experimental/typecons.d std/file.d std/format/internal/floats.d \
+   std/format/internal/read.d std/format/internal/write.d \
+   std/format/package.d std/format/read.d std/format/spec.d \
+   std/format/write.d std/functional.d std/getopt.d \
+   std/internal/attributes.d std/internal/cstring.d \
+   std/internal/math/biguintcore.d std/internal/math/biguintnoasm.d \
+   std/internal/math/errorfunction.d std/internal/math/gammafunction.d \
+   std/internal/memory.d std/internal/scopebuffer.d \
std/internal/test/dummyrange.d std/internal/test/range.d \
std/internal/test/uda.d std/internal/unicode_comp.d \
std/internal/unicode_decomp.d std/internal/unicode_grapheme.d \
std/internal/unicode_norm.d std/internal/unicode_tables.d \
-   std/internal/windows/advapi32.d std/json.d std/math.d \
+   std/internal/windows/advapi32.d std/json.d std/math/algebraic.d \
+   std/math/constants.d std/math/exponential.d std/math/hardware.d \
+   std/math/operations.d std/math/package.d std/math/remainder.d \
+   std/math/rounding.d std/math/traits.d std/math/trigonometry.d \
std/mathspecial.d std/meta.d std/mmfile.d std/net/curl.d \
-   std/net/isemail.d std/numeric.d std/outbuffer.d std/parallelism.d \
-   std/path.d std/process.d std/random.d std/range/interfaces.d \
-   std/range/package.d std/range/primitives.d \
+   std/net/isemail.d std/numeric.d std/outbuffer.d std/package.d \
+   std/parallelism.d std/path.d std/process.d std/random.d \
+   std/rang

[committed 17/19] libphobos: Import druntime testsuite v2.098.0-beta.1 (e6caaab9)

2021-11-30 Thread Iain Buclaw via Gcc-patches
This is the updated D runtime library testsuite.

Bootstrapped, regression tested, and committed to mainline.

Regards,
Iain.

---
libphobos/ChangeLog:

* testsuite/libphobos.aa/test_aa.d: Update test.
* testsuite/libphobos.exceptions/unknown_gc.d: Likewise.
* testsuite/libphobos.hash/test_hash.d: Likewise.
* testsuite/libphobos.shared/host.c: Likewise.
* testsuite/libphobos.shared/load.d: Likewise.
* testsuite/libphobos.shared/load_13414.d: Likewise.
* testsuite/libphobos.thread/fiber_guard_page.d: Likewise.
* testsuite/libphobos.thread/tlsgc_sections.d: Likewise.
* testsuite/libphobos.shared/link_mod_collision.d: Removed.
* testsuite/libphobos.shared/load_mod_collision.d: Removed.
* testsuite/libphobos.allocations/alloc_from_assert.d: New test.
* testsuite/libphobos.betterc/test18828.d: New test.
* testsuite/libphobos.betterc/test19416.d: New test.
* testsuite/libphobos.betterc/test19421.d: New test.
* testsuite/libphobos.betterc/test19561.d: New test.
* testsuite/libphobos.betterc/test19924.d: New test.
* testsuite/libphobos.betterc/test20088.d: New test.
* testsuite/libphobos.betterc/test20613.d: New test.
* testsuite/libphobos.config/test19433.d: New test.
* testsuite/libphobos.config/test20459.d: New test.
* testsuite/libphobos.exceptions/assert_fail.d: New test.
* testsuite/libphobos.exceptions/catch_in_finally.d: New test.
* testsuite/libphobos.exceptions/future_message.d: New test.
* testsuite/libphobos.exceptions/long_backtrace_trunc.d: New test.
* testsuite/libphobos.exceptions/refcounted.d: New test.
* testsuite/libphobos.exceptions/rt_trap_exceptions.d: New test.
* testsuite/libphobos.exceptions/rt_trap_exceptions_drt.d: New test.
* testsuite/libphobos.gc/attributes.d: New test.
* testsuite/libphobos.gc/forkgc.d: New test.
* testsuite/libphobos.gc/forkgc2.d: New test.
* testsuite/libphobos.gc/nocollect.d: New test.
* testsuite/libphobos.gc/precisegc.d: New test.
* testsuite/libphobos.gc/recoverfree.d: New test.
* testsuite/libphobos.gc/sigmaskgc.d: New test.
* testsuite/libphobos.gc/startbackgc.d: New test.
* testsuite/libphobos.imports/bug18193.d: New test.
* testsuite/libphobos.init_fini/custom_gc.d: New test.
* testsuite/libphobos.init_fini/test18996.d: New test.
* testsuite/libphobos.lifetime/large_aggregate_destroy_21097.d: New 
test.
* testsuite/libphobos.thread/external_threads.d: New test.
* testsuite/libphobos.thread/join_detach.d: New test.
* testsuite/libphobos.thread/test_import.d: New test.
* testsuite/libphobos.thread/tlsstack.d: New test.
* testsuite/libphobos.typeinfo/enum_.d: New test.
* testsuite/libphobos.typeinfo/isbaseof.d: New test.
* testsuite/libphobos.unittest/customhandler.d: New test.
---
 libphobos/testsuite/libphobos.aa/test_aa.d|  79 ++-
 .../libphobos.allocations/alloc_from_assert.d |  25 +
 .../testsuite/libphobos.betterc/test18828.d   |  10 +
 .../testsuite/libphobos.betterc/test19416.d   |  14 +
 .../testsuite/libphobos.betterc/test19421.d   |  13 +
 .../testsuite/libphobos.betterc/test19561.d   |  16 +
 .../testsuite/libphobos.betterc/test19924.d   |  15 +
 .../testsuite/libphobos.betterc/test20088.d   |  14 +
 .../testsuite/libphobos.betterc/test20613.d   |  18 +
 .../testsuite/libphobos.config/test19433.d|   7 +
 .../testsuite/libphobos.config/test20459.d|   5 +
 .../libphobos.exceptions/assert_fail.d| 564 ++
 .../libphobos.exceptions/catch_in_finally.d   | 191 ++
 .../libphobos.exceptions/future_message.d |  71 +++
 .../long_backtrace_trunc.d|  37 ++
 .../libphobos.exceptions/refcounted.d |  96 +++
 .../libphobos.exceptions/rt_trap_exceptions.d |  15 +
 .../rt_trap_exceptions_drt.d  |  11 +
 .../libphobos.exceptions/unknown_gc.d |   4 +
 libphobos/testsuite/libphobos.gc/attributes.d |  30 +
 libphobos/testsuite/libphobos.gc/forkgc.d |  36 ++
 libphobos/testsuite/libphobos.gc/forkgc2.d|  22 +
 libphobos/testsuite/libphobos.gc/nocollect.d  |  15 +
 libphobos/testsuite/libphobos.gc/precisegc.d  | 126 
 .../testsuite/libphobos.gc/recoverfree.d  |  13 +
 libphobos/testsuite/libphobos.gc/sigmaskgc.d  |  42 ++
 .../testsuite/libphobos.gc/startbackgc.d  |  22 +
 .../testsuite/libphobos.hash/test_hash.d  | 140 -
 .../testsuite/libphobos.imports/bug18193.d|   4 +
 .../testsuite/libphobos.init_fini/custom_gc.d | 203 +++
 .../testsuite/libphobos.init_fini/test18996.d |  13 +
 .../large_aggregate_destroy_21097.d   |  78 +++
 libphobos/testsuite/libphobos.shared/host.c   |   8 +
 .../libphobos.shared/link_mod_collision.d |   5 -
 libphobos/testsuite/libphobos.shared/l

[committed 18/19] testsuite: Update gdc testsuite to pass on latest version

2021-11-30 Thread Iain Buclaw via Gcc-patches
This updates the GDC testsuite parts to be compatible with the current
language features/deprecations.  The dejagnu gdc-utils helper has also
been updated to handle the new options and directives added to the D2
testsuite tests.

Bootstrapped, regression tested, and committed to mainline.

Regards,
Iain.

---
gcc/testsuite/ChangeLog:

* gdc.dg/Wcastresult2.d: Update test.
* gdc.dg/asm1.d: Likewise.
* gdc.dg/asm2.d: Likewise.
* gdc.dg/asm3.d: Likewise.
* gdc.dg/gdc282.d: Likewise.
* gdc.dg/imports/gdc170.d: Likewise.
* gdc.dg/intrinsics.d: Likewise.
* gdc.dg/pr101672.d: Likewise.
* gdc.dg/pr90650a.d: Likewise.
* gdc.dg/pr90650b.d: Likewise.
* gdc.dg/pr94777a.d: Likewise.
* gdc.dg/pr95250.d: Likewise.
* gdc.dg/pr96869.d: Likewise.
* gdc.dg/pr98277.d: Likewise.
* gdc.dg/pr98457.d: Likewise.
* gdc.dg/simd1.d: Likewise.
* gdc.dg/simd2a.d: Likewise.
* 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.
* gdc.dg/simd7951.d: Likewise.
* gdc.dg/torture/gdc309.d: Likewise.
* gdc.dg/torture/pr94424.d: Likewise.
* gdc.dg/torture/pr94777b.d: Likewise.
* lib/gdc-utils.exp (gdc-convert-args): Handle new compiler options.
(gdc-convert-test): Handle CXXFLAGS, EXTRA_OBJC_SOURCES, and ARG_SETS
test directives.
(gdc-do-test): Only import modules in the test run directory.
* gdc.dg/pr94777c.d: New test.
* gdc.dg/pr96156b.d: New test.
* gdc.dg/pr96157c.d: New test.
* gdc.dg/simd_ctfe.d: New test.
* gdc.dg/torture/simd17344.d: New test.
* gdc.dg/torture/simd20052.d: New test.
* gdc.dg/torture/simd6.d: New test.
* gdc.dg/torture/simd7.d: New test.
---
 gcc/testsuite/gdc.dg/Wcastresult2.d  |   2 +-
 gcc/testsuite/gdc.dg/asm1.d  |  18 +--
 gcc/testsuite/gdc.dg/asm2.d  |   2 +-
 gcc/testsuite/gdc.dg/asm3.d  |  10 +-
 gcc/testsuite/gdc.dg/gdc282.d|   6 +-
 gcc/testsuite/gdc.dg/imports/gdc170.d|   8 +-
 gcc/testsuite/gdc.dg/intrinsics.d|  36 +++---
 gcc/testsuite/gdc.dg/pr101672.d  |   2 +-
 gcc/testsuite/gdc.dg/pr90650a.d  |   2 +-
 gcc/testsuite/gdc.dg/pr90650b.d  |   2 +-
 gcc/testsuite/gdc.dg/pr94777a.d  |   2 +-
 gcc/testsuite/gdc.dg/pr94777c.d  |  62 +++
 gcc/testsuite/gdc.dg/pr95250.d   |   2 +-
 gcc/testsuite/gdc.dg/pr96156b.d  |  17 +++
 gcc/testsuite/gdc.dg/pr96157c.d  |  40 +++
 gcc/testsuite/gdc.dg/pr96869.d   |  26 ++---
 gcc/testsuite/gdc.dg/pr98277.d   |   2 +-
 gcc/testsuite/gdc.dg/pr98457.d   |   6 +-
 gcc/testsuite/gdc.dg/simd1.d |   8 --
 gcc/testsuite/gdc.dg/simd2a.d|   8 --
 gcc/testsuite/gdc.dg/simd2b.d|   8 --
 gcc/testsuite/gdc.dg/simd2c.d|   8 --
 gcc/testsuite/gdc.dg/simd2d.d|   8 --
 gcc/testsuite/gdc.dg/simd2e.d|   8 --
 gcc/testsuite/gdc.dg/simd2f.d|   8 --
 gcc/testsuite/gdc.dg/simd2g.d|   8 --
 gcc/testsuite/gdc.dg/simd2h.d|   8 --
 gcc/testsuite/gdc.dg/simd2i.d|   8 --
 gcc/testsuite/gdc.dg/simd2j.d|   8 --
 gcc/testsuite/gdc.dg/simd7951.d  |   1 +
 gcc/testsuite/gdc.dg/simd_ctfe.d |  87 +++
 gcc/testsuite/gdc.dg/torture/gdc309.d|   1 +
 gcc/testsuite/gdc.dg/torture/pr94424.d   |  16 +++
 gcc/testsuite/gdc.dg/torture/pr94777b.d  | 135 ---
 gcc/testsuite/gdc.dg/torture/simd17344.d |  11 ++
 gcc/testsuite/gdc.dg/torture/simd20052.d |  17 +++
 gcc/testsuite/gdc.dg/torture/simd6.d |  26 +
 gcc/testsuite/gdc.dg/torture/simd7.d |  18 +++
 gcc/testsuite/lib/gdc-utils.exp  |  81 --
 39 files changed, 435 insertions(+), 291 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/pr94777c.d
 create mode 100644 gcc/testsuite/gdc.dg/pr96156b.d
 create mode 100644 gcc/testsuite/gdc.dg/pr96157c.d
 create mode 100644 gcc/testsuite/gdc.dg/simd_ctfe.d
 create mode 100644 gcc/testsuite/gdc.dg/torture/simd17344.d
 create mode 100644 gcc/testsuite/gdc.dg/torture/simd20052.d
 create mode 100644 gcc/testsuite/gdc.dg/torture/simd6.d
 create mode 100644 gcc/testsuite/gdc.dg/torture/simd7.d

diff --git a/gcc/testsuite/gdc.dg/Wcastresult2.d 
b/gcc/testsuite/gdc.dg/Wcastresult2.d
index 56d2dd20e82..83d189a6adf 100644
--- a/gcc/testsuite/gdc.dg/Wcastresult2.d
+++ b/gcc/testsuite/gdc.dg/Wcastresult2.d
@@ -1,5 +1,5 @@
 // { dg-do compile }
-// { dg-options "-Wcast-result" }
+// { dg-options "-Wcast-result -Wno-deprecated" }
 
 vo

[committed 19/19] libphobos: Update libphobos testsuite to pass on latest version

2021-11-30 Thread Iain Buclaw via Gcc-patches
This adds new, or updates the dejagu testing scripts for the suite of
libphobos tests.

Bootstrapped, regression tested, and committed to mainline.

Regards,
Iain.

---
libphobos/ChangeLog:

* testsuite/lib/libphobos.exp (libphobos-dg-test): Handle assembly
compile types.
(dg-test): Override.
(additional_prunes): Define.
(libphobos-dg-prune): Filter any additional_prunes set by tests.
* testsuite/libphobos.druntime/druntime.exp (version_flags): Add
-fversion=CoreUnittest.
* testsuite/libphobos.druntime_shared/druntime_shared.exp
(version_flags): Add -fversion=CoreUnittest -fversion=Shared.
* testsuite/libphobos.phobos/phobos.exp (version_flags): Add
-fversion=StdUnittest
* testsuite/libphobos.phobos_shared/phobos_shared.exp (version_flags):
Likewise.
* testsuite/testsuite_flags.in: Add -fpreview=dip1000 to --gdcflags.
* testsuite/libphobos.betterc/betterc.exp: New test.
* testsuite/libphobos.config/config.exp: New test.
* testsuite/libphobos.gc/gc.exp: New test.
* testsuite/libphobos.imports/imports.exp: New test.
* testsuite/libphobos.lifetime/lifetime.exp: New test.
* testsuite/libphobos.unittest/unittest.exp: New test.
---
 libphobos/testsuite/lib/libphobos.exp | 60 +++
 .../testsuite/libphobos.betterc/betterc.exp   | 27 +
 .../testsuite/libphobos.config/config.exp | 46 ++
 .../testsuite/libphobos.druntime/druntime.exp |  2 +-
 .../druntime_shared.exp   |  2 +-
 libphobos/testsuite/libphobos.gc/gc.exp   | 27 +
 .../testsuite/libphobos.imports/imports.exp   | 29 +
 .../testsuite/libphobos.lifetime/lifetime.exp | 27 +
 .../testsuite/libphobos.phobos/phobos.exp |  2 +-
 .../libphobos.phobos_shared/phobos_shared.exp |  2 +-
 .../testsuite/libphobos.unittest/unittest.exp | 53 
 libphobos/testsuite/testsuite_flags.in|  2 +-
 12 files changed, 274 insertions(+), 5 deletions(-)
 create mode 100644 libphobos/testsuite/libphobos.betterc/betterc.exp
 create mode 100644 libphobos/testsuite/libphobos.config/config.exp
 create mode 100644 libphobos/testsuite/libphobos.gc/gc.exp
 create mode 100644 libphobos/testsuite/libphobos.imports/imports.exp
 create mode 100644 libphobos/testsuite/libphobos.lifetime/lifetime.exp
 create mode 100644 libphobos/testsuite/libphobos.unittest/unittest.exp

diff --git a/libphobos/testsuite/lib/libphobos.exp 
b/libphobos/testsuite/lib/libphobos.exp
index 2af430a0e45..66e3e80105f 100644
--- a/libphobos/testsuite/lib/libphobos.exp
+++ b/libphobos/testsuite/lib/libphobos.exp
@@ -54,6 +54,10 @@ proc libphobos-dg-test { prog do_what extra_tool_flags } {
 
 # Set up the compiler flags, based on what we're going to do.
 switch $do_what {
+   "compile" {
+   set compile_type "assembly"
+   set output_file "[file rootname [file tail $prog]].s"
+   }
"run" {
set compile_type "executable"
# FIXME: "./" is to cope with "." not being in $PATH.
@@ -89,8 +93,52 @@ proc libphobos-dg-test { prog do_what extra_tool_flags } {
 return [list $comp_output $output_file]
 }
 
+# Override the DejaGnu dg-test in order to clear flags after a test, as
+# is done for compiler tests in gcc-dg.exp.
+
+if { [info procs saved-dg-test] == [list] } {
+rename dg-test saved-dg-test
+
+proc dg-test { args } {
+   global additional_prunes
+   global errorInfo
+   global testname_with_flags
+   global shouldfail
+
+   if { [ catch { eval saved-dg-test $args } errmsg ] } {
+   set saved_info $errorInfo
+   set additional_prunes ""
+   set shouldfail 0
+   if [info exists testname_with_flags] {
+   unset testname_with_flags
+   }
+   unset_timeout_vars
+   error $errmsg $saved_info
+   }
+   set additional_prunes ""
+   set shouldfail 0
+   unset_timeout_vars
+   if [info exists testname_with_flags] {
+   unset testname_with_flags
+   }
+}
+}
+
+# Prune messages from gdc that aren't useful.
+
+set additional_prunes ""
+
 proc libphobos-dg-prune { system text } {
 
+global additional_prunes
+
+foreach p $additional_prunes {
+   if { [string length $p] > 0 } {
+   # Following regexp matches a complete line containing $p.
+   regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
+   }
+}
+
 # Ignore harmless warnings from Xcode.
 regsub -all "(^|\n)\[^\n\]*ld: warning: could not create compact unwind 
for\[^\n\]*" $text "" text
 
@@ -281,6 +329,18 @@ proc libphobos_skipped_test_p { test } {
 return "skipped test"
 }
 
+# Prune any messages matching ARGS[1] (a regexp) from test output.
+proc dg-prune-output { args } {
+global additional_prunes
+
+if { [llength $args] != 2 } {
+   error "[lindex $arg

[PING, PATCH] doc, d: Add note that D front end now requires GDC installed in order to bootstrap.

2021-11-30 Thread Iain Buclaw via Gcc-patches
Ping.

Excerpts from Iain Buclaw's message of November 18, 2021 2:06 am:
> Hi,
> 
> As asked for, this adds the documentation note in install.texi about the
> upcoming bootstrap requirements.
> 
> Obviously this will be applied alongside the patch posted previously:
> 
> https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582917.html
> 
> Final batch of testing before proceeding has taking a bit longer than I
> expected.  Currently bootstrapping on sparcv9-sun-solaris2.11, and will
> push forward once have confirmed that it works as well as the current
> C++ implementation of the D front end.
> 
> OK for mainline?  Any improvements on wording?
> 
> Thanks,
> Iain.
> 
> ---
> gcc/ChangeLog:
> 
>   * doc/install.texi (Prerequisites): Add note that D front end now
>   requires GDC installed in order to bootstrap.
>   (Building): Add D compiler section, referencing prerequisites.
> ---
>  gcc/doc/install.texi | 28 
>  1 file changed, 28 insertions(+)
> 
> diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
> index 094469b9a4e..6f999a2fd5a 100644
> --- a/gcc/doc/install.texi
> +++ b/gcc/doc/install.texi
> @@ -289,6 +289,25 @@ Ada runtime libraries. You can check that your build 
> environment is clean
>  by verifying that @samp{gnatls -v} lists only one explicit path in each
>  section.
>  
> +@item @anchor{GDC-prerequisite}GDC
> +
> +In order to build GDC, the D compiler, you need a working GDC
> +compiler (GCC version 9.1 or later), as the D front end is written in D.
> +
> +Versions of GDC prior to 12 can be built with an ISO C++11 compiler, which 
> can
> +then be installed and used to bootstrap newer versions of the D front end.
> +
> +It is strongly recommended to use an older version of GDC to build GDC. More
> +recent versions of GDC than the version built are not guaranteed to work and
> +will often fail during the build with compilation errors relating to
> +deprecations or removed features.
> +
> +Note that @command{configure} does not test whether the GDC installation 
> works
> +and has a sufficiently recent version.  Though the implementation of the D
> +front end does not make use of any GDC-specific extensions, or novel features
> +of the D language, if too old a GDC version is installed and
> +@option{--enable-languages=d} is used, the build will fail.
> +
>  @item A ``working'' POSIX compatible shell, or GNU bash
>  
>  Necessary when running @command{configure} because some
> @@ -2977,6 +2996,15 @@ and network filesystems.
>  @uref{prerequisites.html#GNAT-prerequisite,,GNAT prerequisites}.
>  @end ifhtml
>  
> +@section Building the D compiler
> +
> +@ifnothtml
> +@ref{GDC-prerequisite}.
> +@end ifnothtml
> +@ifhtml
> +@uref{prerequisites.html#GDC-prerequisite,,GDC prerequisites}.
> +@end ifhtml
> +
>  @section Building with profile feedback
>  
>  It is possible to use profile feedback to optimize the compiler itself.  This
> -- 
> 2.30.2
> 
> 


[PING, PATCH] darwin, d: Support outfile substitution for liphobos

2021-11-30 Thread Iain Buclaw via Gcc-patches
Ping.

Are the common gcc parts OK (also for backporting)?

Iain.

Excerpts from Iain Buclaw's message of November 26, 2021 1:51 pm:
> Excerpts from Iain Sandoe's message of November 19, 2021 10:21 am:
>> Hi Iain
>> 
>>> On 19 Nov 2021, at 08:32, Iain Buclaw  wrote:
>> 
>>> This patch fixes a stage2 bootstrap failure in the D front-end on
>>> darwin due to libgphobos being dynamically linked despite
>>> -static-libphobos being on the command line.
>>> 
>>> In the gdc driver, this takes the previous fix for the Darwin D
>>> bootstrap, and extends it to the -static-libphobos option as well.
>>> Rather than pushing the -static-libphobos option back onto the command
>>> line, the setting of SKIPOPT is instead conditionally removed.  The same
>>> change has been repeated for -static-libstdc++ so there is now no need
>>> to call generate_option to re-add it.
>>> 
>>> In the gcc driver, -static-libphobos has been added as a common option,
>>> validated, and a new outfile substition added to config/darwin.h to
>>> correctly replace -lgphobos with libgphobos.a.
>>> 
>>> Bootstrapped and regression tested on x86_64-linux-gnu and
>>> x86_64-apple-darwin20.
>>> 
>>> OK for mainline?  This would also be fine for gcc-11 release branch too,
>>> as well as earlier releases with D support.
>> 
>> the Darwin parts are fine, thanks 
>> 
>> The SKIPOPT in d-spec, presumably means “skip removing this opt”?
>> otherwise the #ifndef looks odd (because of the 
>> static-libgcc|static-libphobos,
>> darwin.h would do the substitution for -static-libgcc as well, so it’s not a 
>> 100%
>> test).
>> 
> 
> I've only just realised what you meant.  Yes you are of course right,
> and it should have been #ifdef, attaching a fixed-up patch.
> 
> Iain.
> 
> ---
> gcc/ChangeLog:
> 
> * common.opt (static-libphobos): Add option.
> * config/darwin.h (LINK_SPEC): Substitute -lgphobos with 
> libgphobos.a
> when linking statically.
> * gcc.c (driver_handle_option): Set -static-libphobos as always 
> valid.
> 
> gcc/d/ChangeLog:
> 
> * d-spec.cc (lang_specific_driver): Set SKIPOPT on 
> -static-libstdc++
> and -static-libphobos only when target supports LD_STATIC_DYNAMIC.
> Remove generate_option to re-add -static-libstdc++.
> 
> libphobos/ChangeLog:
> 
> * testsuite/testsuite_flags.in: Add libphobos library directory as
> search path to --gdcldflags.
> 
> diff --git a/gcc/common.opt b/gcc/common.opt
> index db6010e4e20..73c12d933f3 100644
> --- a/gcc/common.opt
> +++ b/gcc/common.opt
> @@ -3527,6 +3527,10 @@ static-libgfortran
>  Driver
>  ; Documented for Fortran, but always accepted by driver.
>  
> +static-libphobos
> +Driver
> +; Documented for D, but always accepted by driver.
> +
>  static-libstdc++
>  Driver
>  
> diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
> index 7ed01efa694..c4ddd623e8b 100644
> --- a/gcc/config/darwin.h
> +++ b/gcc/config/darwin.h
> @@ -443,6 +443,7 @@ extern GTY(()) int darwin_ms_struct;
>   %:replace-outfile(-lobjc libobjc-gnu.a%s); \
>  :%:replace-outfile(-lobjc -lobjc-gnu )}}\
> %{static|static-libgcc|static-libgfortran:%:replace-outfile(-lgfortran 
> libgfortran.a%s)}\
> +   %{static|static-libgcc|static-libphobos:%:replace-outfile(-lgphobos 
> libgphobos.a%s)}\
> 
> %{static|static-libgcc|static-libstdc++|static-libgfortran:%:replace-outfile(-lgomp
>  libgomp.a%s)}\
> %{static|static-libgcc|static-libstdc++:%:replace-outfile(-lstdc++ 
> libstdc++.a%s)}\
> %{force_cpusubtype_ALL:-arch %(darwin_arch)} \
> diff --git a/gcc/d/d-spec.cc b/gcc/d/d-spec.cc
> index b12d28f1047..1304126a675 100644
> --- a/gcc/d/d-spec.cc
> +++ b/gcc/d/d-spec.cc
> @@ -253,13 +253,23 @@ lang_specific_driver (cl_decoded_option 
> **in_decoded_options,
>  
>   case OPT_static_libstdc__:
> saw_static_libcxx = true;
> +#ifdef HAVE_LD_STATIC_DYNAMIC
> +   /* Remove -static-libstdc++ from the command only if target supports
> +  LD_STATIC_DYNAMIC.  When not supported, it is left in so that a
> +  back-end target can use outfile substitution.  */
> args[i] |= SKIPOPT;
> +#endif
> break;
>  
>   case OPT_static_libphobos:
> if (phobos_library != PHOBOS_NOLINK)
>   phobos_library = PHOBOS_STATIC;
> +#ifdef HAVE_LD_STATIC_DYNAMIC
> +   /* Remove -static-libphobos from the command only if target supports
> +  LD_STATIC_DYNAMIC.  When not supported, it is left in so that a
> +  back-end target can use outfile substitution.  */
> args[i] |= SKIPOPT;
> +#endif
> break;
>  
>   case OPT_shared_libphobos:
> @@ -460,7 +470,7 @@ lang_specific_driver (cl_decoded_option 
> **in_decoded_options,
>  #endif
>  }
>  
> -  if (saw_libcxx || need_stdcxx)
> +  if (saw_libcxx || saw_static_libcxx || need_stdcxx)
>  {
>  #ifdef HAVE_LD_STATIC_DYNAMIC
>

[committed] d: Update documentation of new D language options.

2021-12-01 Thread Iain Buclaw via Gcc-patches
Hi,

This patch adds documentation for the following new D options:

- New switch that controls what code is generated on a contract
  failure (throw or abort).
- New switch that controls mangling of D types in `extern(C++)`
  code, as well as setting the compile-time value of
  `__traits(getTargetInfo "cppStd")`
- New switches that generate C++ headers from D source files.
- New switch to save expanded mixins to a file.
- New switches that now distinguish between D language changes that
  are either (a) an experimental feature or an upcoming breaking
  change, (b) a warning or help on an upcoming change, or (c) revert
  of a change for users who don't want to deal with the breaking
  change for now.

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

Regards,
Iain

---
gcc/d/ChangeLog:

* gdc.texi (Runtime Options): Document -fcheckaction=, -fextern-std=,
-fpreview=, -frevert=.
(Code Generation): Document -fdump-c++-spec=, -fdump-c++-spec-verbose,
-fsave-mixins=.
(Warnings): Update list of supported -ftransitions=.
---
 gcc/d/gdc.texi | 114 ++---
 1 file changed, 109 insertions(+), 5 deletions(-)

diff --git a/gcc/d/gdc.texi b/gcc/d/gdc.texi
index 095f7ecca41..c98eb1f45d9 100644
--- a/gcc/d/gdc.texi
+++ b/gcc/d/gdc.texi
@@ -216,6 +216,20 @@ Don't recognize built-in functions unless they begin with 
the prefix
 @samp{__builtin_}.  By default, the compiler will recognize when a
 function in the @code{core.stdc} package is a built-in function.
 
+@item -fcheckaction=@var{value}
+@cindex @option{-fcheckaction}
+This option controls what code is generated on an assertion, bounds check, or
+final switch failure.  The following values are supported:
+
+@table @samp
+@item context
+Throw an @code{AssertError} with extra context information.
+@item halt
+Halt the program execution.
+@item throw
+Throw an @code{AssertError} (the default).
+@end table
+
 @item -fdebug
 @item -fdebug=@var{value}
 @cindex @option{-fdebug}
@@ -245,6 +259,25 @@ This is equivalent to compiling with the following options:
 gdc -nophoboslib -fno-exceptions -fno-moduleinfo -fno-rtti
 @end example
 
+@item -fextern-std=@var{standard}
+@cindex @option{-fextern-std}
+Sets the C++ name mangling compatibility to the version identified by
+@var{standard}.  The following values are supported:
+
+@table @samp
+@item c++98
+@item c++03
+Sets @code{__traits(getTargetInfo "cppStd")} to @code{199711}.
+@item c++11
+Sets @code{__traits(getTargetInfo "cppStd")} to @code{201103}.
+@item c++14
+Sets @code{__traits(getTargetInfo "cppStd")} to @code{201402}.
+@item c++17
+Sets @code{__traits(getTargetInfo "cppStd")} to @code{201703}.
+@item c++20
+Sets @code{__traits(getTargetInfo "cppStd")} to @code{202002}.
+@end table
+
 @item -fno-invariants
 @cindex @option{-finvariants}
 @cindex @option{-fno-invariants}
@@ -276,6 +309,48 @@ Turns off code generation for postcondition @code{out} 
contracts.
 @cindex @option{-fno-preconditions}
 Turns off code generation for precondition @code{in} contracts.
 
+@item -fpreview=@var{id}
+@cindex @option{-fpreview}
+Turns on an upcoming D language change identified by @var{id}.  The following
+values are supported:
+
+@table @samp
+@item all
+Turns on all upcoming D language features.
+@item dip1000
+Implements @uref{http://wiki.dlang.org/DIP1000} (Scoped pointers).
+@item dip1008
+Implements @uref{http://wiki.dlang.org/DIP1008} (Allow exceptions in
+@code{@@nogc} code).
+@item dip1021
+Implements @uref{http://wiki.dlang.org/DIP1021} (Mutable function arguments).
+@item dip25
+Implements @uref{http://wiki.dlang.org/DIP25} (Sealed references).
+@item dtorfields
+Turns on generation for destructing fields of partially constructed objects.
+@item fieldwise
+Turns on generation of struct equality to use field-wise comparisons.
+@item fixaliasthis
+Implements new lookup rules that check the current scope for @code{alias this}
+before searching in upper scopes.
+@item in
+Implements @code{in} parameters to mean @code{scope const [ref]} and accepts
+rvalues.
+@item inclusiveincontracts
+Implements @code{in} contracts of overridden methods to be a superset of parent
+contract.
+@item intpromote
+Implements C-style integral promotion for unary @code{+}, @code{-} and @code{~}
+expressions.
+@item nosharedaccess
+Turns off and disallows all access to shared memory objects.
+@item rvaluerefparam
+Implements rvalue arguments to @code{ref} parameters.
+@item shortenedmethods
+Implements use of @code{=>} for methods and top-level functions in addition to
+lambdas.
+@end table
+
 @item -frelease
 @cindex @option{-frelease}
 @cindex @option{-fno-release}
@@ -291,6 +366,22 @@ gdc -fno-assert -fbounds-check=safe -fno-invariants \
 -fno-postconditions -fno-preconditions -fno-switch-errors
 @end example
 
+@item -frevert=
+@cindex @option{-frevert}
+Turns off a D language feature identified by @var{

[committed] d: Prefix object files from the root package with 'root-'

2021-12-01 Thread Iain Buclaw via Gcc-patches
Hi,

This patch prefixes D object files from the root package with 'root-'.

None of the front-end module names in either the dmd or root package
collide just yet, but that does not mean they won't in the future.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* Make-lang.in (D_FRONTEND_OBJS): Prefix object files from the root
package with root-.
(d/root-%.o): New recipe.
---
 gcc/d/Make-lang.in | 34 +-
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/gcc/d/Make-lang.in b/gcc/d/Make-lang.in
index 4c0a0321eba..4ce11e3cada 100644
--- a/gcc/d/Make-lang.in
+++ b/gcc/d/Make-lang.in
@@ -74,19 +74,16 @@ endif
 
 # D Frontend object files.
 D_FRONTEND_OBJS = \
-   d/aav.o \
d/access.o \
d/aggregate.o \
d/aliasthis.o \
d/apply.o \
-   d/array.o \
d/arrayop.o \
d/arraytypes.o \
d/attrib.o \
d/ast_node.o \
d/astcodegen.o \
d/astenums.o \
-   d/bitarray.o \
d/blockexit.o \
d/builtin.o \
d/canthrow.o \
@@ -99,7 +96,6 @@ D_FRONTEND_OBJS = \
d/cparse.o \
d/cppmangle.o \
d/ctfeexpr.o \
-   d/ctfloat.o \
d/ctorflow.o \
d/dcast.o \
d/dclass.o \
@@ -124,13 +120,10 @@ D_FRONTEND_OBJS = \
d/escape.o \
d/expression.o \
d/expressionsem.o \
-   d/file.o \
-   d/filename.o \
d/foreachvar.o \
d/func.o \
d/globals.o \
d/gluelayer.o \
-   d/hash.o \
d/hdrgen.o \
d/iasm.o \
d/iasmgcc.o \
@@ -145,7 +138,6 @@ D_FRONTEND_OBJS = \
d/json.o \
d/lambdacomp.o \
d/lexer.o \
-   d/longdouble.o \
d/mtype.o \
d/nogc.o \
d/nspace.o \
@@ -153,29 +145,37 @@ D_FRONTEND_OBJS = \
d/objc.o \
d/opover.o \
d/optimize.o \
-   d/outbuffer.o \
d/parse.o \
d/parsetimevisitor.o \
d/permissivevisitor.o \
-   d/port.o \
d/printast.o \
-   d/region.o \
-   d/rmem.o \
-   d/rootobject.o \
+   d/root-aav.o \
+   d/root-array.o \
+   d/root-bitarray.o \
+   d/root-ctfloat.o \
+   d/root-file.o \
+   d/root-filename.o \
+   d/root-hash.o \
+   d/root-longdouble.o \
+   d/root-outbuffer.o \
+   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/safe.o \
d/sapply.o \
d/semantic2.o \
d/semantic3.o \
d/sideeffect.o \
-   d/speller.o \
d/statement.o \
d/statement_rewrite_walker.o \
d/statementsem.o \
d/staticassert.o \
d/staticcond.o \
d/stmtstate.o \
-   d/string.o \
-   d/stringtable.o \
d/target.o \
d/templateparamsem.o \
d/tokens.o \
@@ -393,6 +393,6 @@ d/%.o: d/dmd/%.d
$(DCOMPILE) $(D_INCLUDES) $<
$(DPOSTCOMPILE)
 
-d/%.o: d/dmd/root/%.d
+d/root-%.o: d/dmd/root/%.d
$(DCOMPILE) $(D_INCLUDES) $<
$(DPOSTCOMPILE)
-- 
2.30.2



[committed] d: Disable the D runtime garbage collector after initializing (PR103520)

2021-12-01 Thread Iain Buclaw via Gcc-patches
Hi,

This patch disables the D runtime garbage collector after initializing.

Not all targets that support building libdruntime have a stable garbage
collector, so to avoid running into problems where live memory allocated
by the D GC is freed, disable all in-flight collections until a time
when scanning is more reliably implemented everywhere.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

PR d/103520
* d-frontend.h (gc_disable): Declare.
* d-lang.cc (d_init_options): Disable the D runtime garbage collector
after initializing.
---
 gcc/d/d-frontend.h | 2 +-
 gcc/d/d-lang.cc| 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/d/d-frontend.h b/gcc/d/d-frontend.h
index 3edf812212a..e7695d5718b 100644
--- a/gcc/d/d-frontend.h
+++ b/gcc/d/d-frontend.h
@@ -21,7 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 /* These functions are defined in D runtime.  */
 extern "C" int rt_init (void);
 extern "C" int rt_term (void);
-//extern "C" void gc_disable (void);
+extern "C" void gc_disable (void);
 extern "C" void *gc_malloc (size_t sz, unsigned ba = 0, const void *ti = NULL);
 extern "C" void gc_free (void *);
 extern "C" void gc_collect (void);
diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index d20370e5d8a..dbf7a8b60b9 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -288,7 +288,7 @@ d_init_options (unsigned int, cl_decoded_option 
*decoded_options)
 {
   /* Initialize the D runtime.  */
   rt_init ();
-//  gc_disable ();
+  gc_disable ();
 
   /* Set default values.  */
   global._init ();
-- 
2.30.2



[committed] libphobos: Add missing ControlState variable for AArch64

2021-12-01 Thread Iain Buclaw via Gcc-patches
Hi,

This patch fixes a typo that occurred during the splitting of the
std.math module into a package.

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

Regards,
Iain.

---
libphobos/ChangeLog:

* src/std/math/hardware.d (FloatingPointControl.getControlState): Add
missing ControlState variable for AArch64.
---
 libphobos/src/std/math/hardware.d | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libphobos/src/std/math/hardware.d 
b/libphobos/src/std/math/hardware.d
index 90bc96df148..b768969d4cf 100644
--- a/libphobos/src/std/math/hardware.d
+++ b/libphobos/src/std/math/hardware.d
@@ -912,6 +912,7 @@ private:
 }
 else version (AArch64)
 {
+ControlState cont;
 asm pure nothrow @nogc
 {
 "mrs %0, FPCR;" : "=r" (cont);
-- 
2.30.2



  1   2   3   4   5   6   >