Re: [PATCHSET] Reintroduce targetrustm hooks

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

Thanks for eventually getting round to this.

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

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

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

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

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

The other GitHub pull request that added these is here.

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

Regards,
Iain.


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

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

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

Regards,
Iain.

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

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

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

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

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

D front-end changes:

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

D runtime changes:

- Import druntime v2.105.0-beta.1.

Phobos changes:

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

gcc/d/ChangeLog:

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

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

Regards,
Iain.

---
libphobos/ChangeLog:

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

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

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

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

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

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

Regards,
Iain.

---
PR d/110959

gcc/d/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

Re: [PATCH] Use substituted GDCFLAGS

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

OK from me.

Thanks,
Iain.


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

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

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

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

Regards,
Iain.

---
PR d/108842

gcc/d/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

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

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

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

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

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

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

Regards,
Iain.

---
gcc/testsuite/ChangeLog:

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

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

[committed] d: Add testcase from PR108962

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

This adds testcase from PR108962 into the gdc testsuite.

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

Regtested, committed to mainline and gcc-13 branches.

Regards,
Iain.

---
PR d/108962

gcc/testsuite/ChangeLog:

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

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



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

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

OK.

Thanks!
Iain.


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

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

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

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

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

Regards,
Iain.

---
PR d/110516

gcc/d/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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



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

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

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

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

Regards,
Iain.

---
PR d/110514

gcc/d/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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



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

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

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

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

Regards,
Iain.

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

PR d/110471

gcc/d/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

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

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

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

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

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

Regards,
Iain.

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

PR d/110511

gcc/d/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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



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

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

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

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

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

Regards,
Iain.

---
PR d/106977
PR target/110406

gcc/d/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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



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

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

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

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

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

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

Regards,
Iain.

---
PR d/110193

gcc/d/ChangeLog:

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

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



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

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

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

(*(ubyte*)_or_expr) & 1

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

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

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

Regards,
Iain.

---
PR d/110359

gcc/d/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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



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

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

This backports patch from upstream dmd mainline for fixing PR110113.

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

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

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

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

Regards,
Iain.

---
PR d/110113

gcc/d/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

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



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

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

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

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

D front-end changes:

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

D runtime changes:

- Import druntime v2.103.1.

Phobos changes:

- Import phobos v2.103.1.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

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

libphobos/ChangeLog:

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

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index 986925e8bdc..1205cd941b7 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-5f7552bb2829b75d5e36cc767a476e1ab35147b7
+a45f4e9f43e9fdbf0b666175e5e66b1ce4f561f6
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
diff --git a/gcc/d/dmd/VERSION b/gcc/d/dmd/VERSION
index da496a2ceeb..8316aafdaca 100644
--- a/gcc/d/dmd/VERSION
+++ b/gcc/d/dmd/VERSION
@@ -1 +1 @@
-v2.103.0-rc.1
+v2.103.1
diff --git a/gcc/d/dmd/aggregate.h b/gcc/d/dmd/aggregate.h
index 04e5eb2f0d9..03fe478685c 100644
--- a/gcc/d/dmd/aggregate.h
+++ b/gcc/d/dmd/aggregate.h
@@ -108,8 +108,8 @@ public:
 Expression *getRTInfo;  // pointer to GC info generated by 
object.RTInfo(this)
 
 Visibility visibility;
-bool noDefaultCtor; // no default construction
-bool disableNew;// disallow allocations using `new`
+d_bool noDefaultCtor; // no default construction
+d_bool disableNew;// 

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

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

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

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

Phobos changes:

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

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

Regards,
Iain.

---
gcc/d/ChangeLog:

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

libphobos/ChangeLog:

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

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

 // Array!bool
 

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

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

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

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

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

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

Regards,
Iain.

---
gcc/d/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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



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

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

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

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

D front-end changes:

- Import dmd v2.103.0-rc.1.

D runtime changes:

- Import druntime v2.103.0-rc.1.

Phobos changes:

- Import phobos v2.103.0-rc.1.

gcc/d/ChangeLog:

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

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

Regards,
Iain.

---
libphobos/ChangeLog:

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

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

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

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

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

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

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

Regards,
Iain.

---
PR d/109144

gcc/d/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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



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

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

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

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

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

Regards,
Iain.

---
PR d/109108

gcc/d/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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



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

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

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

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

Regards,
Iain.

---
gcc/d/ChangeLog:

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

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



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

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

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

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

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

Regards,
Iain.

---
gcc/d/ChangeLog:

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

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

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

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

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

Bootstrapped and regression tested, committed to mainline.

Regards,
Iain.

---
PR d/108763

gcc/d/ChangeLog:

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

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



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

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

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

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

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

Regards,
Iain.

---
PR d/108945

gcc/d/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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



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

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

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

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

Regards,
Iain.

---
PR d/108877

gcc/d/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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



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

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

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

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

Regards,
Iain.

---
PR d/108946

gcc/d/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

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

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

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

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

Regards,
Iain.

---
PR d/108167

gcc/testsuite/ChangeLog:

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

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



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

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

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

Regards,
Iain.

---
gcc/d/ChangeLog:

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

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



[committed] d: Set doing_semantic_analysis_p before calling functionSemantic3

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

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

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

Regards,
Iain.

---
gcc/d/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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



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

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

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

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

Regards,
Iain.

---
libphobos/ChangeLog:

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

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

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

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

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

OK.

Iain.


Re: [PATCH v2] IBM zSystems: Fix TARGET_D_CPU_VERSIONS

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

OK.


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

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

Hi, sorry for belated reply.

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

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

OK.



Re: [PATCH] IBM zSystems: Fix TARGET_D_CPU_VERSIONS

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

So that I follow, there are three possible combinations?

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

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

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

Iain.


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

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

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

Iain.


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

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

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

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

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

Iain.


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

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

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

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

Regards,
Iain.

---
libphobos/ChangeLog:

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

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



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

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

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

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

D Runtime changes:

- Fix MIPS64 bindings for CRuntime_UClibc.

Phobos changes:

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

libphobos/ChangeLog:

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

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

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

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

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

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

D Runtime changes:

- Fix MIPS64 bindings for CRuntime_UClibc.

Phobos changes:

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

libphobos/ChangeLog:

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

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

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

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

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

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

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

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

Regards,
Iain.

---

PR d/108055

gcc/d/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

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

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

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

Committed to releases/gcc-12.

Regards,
Iain.

---
gcc/d/ChangeLog:

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

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



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

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

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

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

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

Regards,
Iain.

---
PR d/108050

gcc/d/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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



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

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

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

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

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

Committed to mainline.

Regards,
Iain.

---
gcc/d/ChangeLog:

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

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



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

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

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

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

Iain.


[committed] onlinedocs: Add documentation links to gdc

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

Now that the D front-end documentation has been generated and pushed to
the site after r13-4421, this can be added to the main index page.

This is a simple copy from other entries, so have gone ahead and
committed it.

Regards,
Iain.

---
 htdocs/onlinedocs/index.html | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/htdocs/onlinedocs/index.html b/htdocs/onlinedocs/index.html
index c5787f32..343ff9f5 100644
--- a/htdocs/onlinedocs/index.html
+++ b/htdocs/onlinedocs/index.html
@@ -1641,6 +1641,12 @@ existing release.
href="https://gcc.gnu.org/onlinedocs/gccgo.ps.gz;>PostScript or 
https://gcc.gnu.org/onlinedocs/gccgo-html.tar.gz;>an
HTML tarball)
+https://gcc.gnu.org/onlinedocs/gdc/;>GNU D Manual (https://gcc.gnu.org/onlinedocs/gdc.pdf;>also in
+   PDF or https://gcc.gnu.org/onlinedocs/gdc.ps.gz;>PostScript or https://gcc.gnu.org/onlinedocs/gdc-html.tar.gz;>an
+   HTML tarball)
 https://gcc.gnu.org/onlinedocs/libgomp/;>GNU Offloading and
Multi Processing Runtime Library Manual (https://gcc.gnu.org/onlinedocs/libgomp.pdf;>also in
-- 
2.37.2



Re: Rust front-end patches v4

2022-12-06 Thread Iain Buclaw via Gcc-patches
Excerpts from Richard Biener via Gcc-patches's message of Dezember 6, 2022 
12:03 pm:
> On Tue, Dec 6, 2022 at 11:11 AM  wrote:
>>
>> This patchset contains the fixed version of our most recent patchset. We
>> have fixed most of the issues noted in the previous round of reviews, and are
>> keeping some for later as they would otherwise create too many conflicts with
>> our updated development branch.
>>
>> Similarly to the previous round of patches, this patchset does not contain 
>> any
>> new features - only fixes for the reviews of the v3. New features will follow
>> shortly once that first patchset is merged.
>>
>> Once again, thank you to all the contributors who made this possible and
>> especially to Philip Herron for his dedication to the project.
> 
> Thanks a lot - this is OK to merge now, thanks for your patience and I'm
> looking forward for the future improvements.
> 
> Thanks,
> Richard.
> 

Finally! Some competition. :-)

Don't feel any pressure, and reach out if you ever need any guidance.

All the best.

Iain.


Re: Ping: [PATCH] maintainer-scripts: Add gdc to update_web_docs_git

2022-11-30 Thread Iain Buclaw via Gcc-patches
Hi Gerald,

Excerpts from Gerald Pfeifer's message of November 29, 2022 9:21 pm:
> Hi Iain,
> 
> On Tue, 29 Nov 2022, Iain Buclaw via Gcc-patches wrote:
>> This looks obvious, however I don't know how things are generated for
>> the online documentation site in order to say this won't cause any
>> problems for whatever process is building these pages.
> 
>>> maintainer-scripts/ChangeLog:
>>> 
>>> * update_web_docs_git: Add gdc to MANUALS.
> 
> please go ahead and let me know when done. I'll see how I can help.
> 

Thanks, I've committed it - along with a bit of content I've been
working on since the temporary switch to Sphinx (the gdc pages of seem
to still be up https://gcc.gnu.org/onlinedocs/gdc/).

As far as I understand, there's also a corresponding wwwdocs change to
be done so that there's  a reference from the main onlinedocs page.
Will wait until docs have been confirmed rebuilt before submitting that.

Iain.



[committed] d: Add language reference section to documentation files.

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

This adds an initial body of documentation for the D front-end - other
than the existing documentation for command-line usage/the man page.

Documentation covers code generation choices specific to GNU D - what
attributes are supported, intrinsics, pragmas, predefined versions,
language extensions, missing features and deviations from spec.

More could be added or elaborated upon, such as what linkage do
different symbols get, mixed language programming with C and C++, the
anatomy of a TypeInfo and ModuleInfo object, and so on.  This is enough
as a first wave just to get it off the ground.

Tested with `make html', and committed to mainline.

Regards,
Iain

---
gcc/d/ChangeLog:

* Make-lang.in (D_TEXI_FILES): Add d/implement-d.texi.
* gdc.texi: Adjust introduction, include implement-d.texi.
* implement-d.texi: New file.
---
 gcc/d/Make-lang.in |1 +
 gcc/d/gdc.texi |   12 +-
 gcc/d/implement-d.texi | 2514 
 3 files changed, 2523 insertions(+), 4 deletions(-)
 create mode 100644 gcc/d/implement-d.texi

diff --git a/gcc/d/Make-lang.in b/gcc/d/Make-lang.in
index 144d5b88483..b5264613db0 100644
--- a/gcc/d/Make-lang.in
+++ b/gcc/d/Make-lang.in
@@ -239,6 +239,7 @@ d21$(exeext): $(D_ALL_OBJS) attribs.o $(BACKEND) $(LIBDEPS) 
$(d.prev)
 
 D_TEXI_FILES = \
d/gdc.texi \
+   d/implement-d.texi \
$(gcc_docdir)/include/fdl.texi \
$(gcc_docdir)/include/gpl_v3.texi \
$(gcc_docdir)/include/gcc-common.texi \
diff --git a/gcc/d/gdc.texi b/gcc/d/gdc.texi
index 45dc544e83f..c99c36558a9 100644
--- a/gcc/d/gdc.texi
+++ b/gcc/d/gdc.texi
@@ -65,13 +65,15 @@ Boston, MA 02110-1301, USA@*
 @top Introduction
 
 This manual describes how to use @command{gdc}, the GNU compiler for
-the D programming language.  This manual is specifically about
-@command{gdc}.  For more information about the D programming
-language in general, including language specifications and standard
-package documentation, see @uref{https://dlang.org/}.
+the D programming language.  This manual is specifically about how to
+invoke @command{gdc}, as well as its features and incompatibilities.
+For more information about the D programming language in general,
+including language specifications and standard package documentation,
+see @uref{https://dlang.org/}.
 
 @menu
 * Invoking gdc::How to run gdc.
+* D Implementation::User-visible implementation details.
 * Copying:: The GNU General Public License.
 * GNU Free Documentation License::
 How you can share and copy this manual.
@@ -838,6 +840,8 @@ and all @code{function} bodies that are being compiled.
 
 @c man end
 
+@include implement-d.texi
+
 @include gpl_v3.texi
 @include fdl.texi
 
diff --git a/gcc/d/implement-d.texi b/gcc/d/implement-d.texi
new file mode 100644
index 000..8f3f825e797
--- /dev/null
+++ b/gcc/d/implement-d.texi
@@ -0,0 +1,2514 @@
+@ignore
+Copyright (C) 2022 Free Software Foundation, Inc.
+This is part of the GNU D manual.
+For copying conditions, see the file gdc.texi.
+@end ignore
+
+@node D Implementation
+@chapter Language Reference
+@cindex language reference, D language
+
+The implementation of the D programming language used by the GNU D compiler is
+shared with parts of the front-end for the Digital Mars D compiler, hosted at
+@uref{https://github.com/dlang/dmd/}.  This common front-end covers lexical
+analysis, parsing, and semantic analysis of the D programming language defined
+in the documents at @uref{https://dlang.org/}.
+
+The implementation details described in this manual are GNU D extensions to the
+D programming language.  If you want to write code that checks whether these
+features are available, you can test for the predefined version @code{GNU}, or
+you can check whether a specific feature is compilable using
+@code{__traits(compiles)}.
+
+@smallexample
+version (GNU)
+@{
+import gcc.builtins;
+return __builtin_atan2(x, y);
+@}
+
+static if (__traits(compiles, @{ asm @{"";@} @}))
+@{
+asm @{ "magic instruction"; @}
+@}
+@end smallexample
+
+@menu
+* Attributes::  Implementation-defined attributes.
+* Builtin Functions::   GCC built-ins module.
+* ImportC:: Importing C sources into D.
+* Inline Assembly:: Interfacing D with assembler.
+* Intrinsics::  Intrinsic functions supported by GDC.
+* Predefined Pragmas::  Pragmas accepted by GDC.
+* Predefined Versions:: List of versions for conditional compilation.
+* Special Enums::   Intrinsic type interoperability with C and C++.
+* Traits::  Compile-time reflection extensions.
+* Vector Extensions::   Using vector types and supported operations.
+* Vector Intrinsics::   Vector instructions through intrinsics.
+* Missing Features::Deviations from the D2 specification in GDC.
+@end menu
+
+
+@c 
+

[committed] d: Update recipes for building html and pdf documentation

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

This patch sorts out the include directories for building the gdc docs -
we don't need to include anything from the toplevel docs directory.

The html output directory has also been renamed from /d/ to /gdc/ to
make it clearer that this is vendor-specific documentation.

Tested by building and checking pdf/info/man/html pages, and committed
to mainline.

Regards,
Iain.

---
gcc/d/ChangeLog:

* Make-lang.in: Only include doc/include when building documentation.
(d.html): Rename html directory to $(build_htmldir)/gdc.
---
 gcc/d/Make-lang.in | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/gcc/d/Make-lang.in b/gcc/d/Make-lang.in
index 28313208ec9..b5264613db0 100644
--- a/gcc/d/Make-lang.in
+++ b/gcc/d/Make-lang.in
@@ -253,16 +253,15 @@ doc/gdc.info: $(D_TEXI_FILES)
else true; fi
 
 doc/gdc.dvi: $(D_TEXI_FILES)
-   $(TEXI2DVI) -I $(abs_docdir) -I $(abs_docdir)/include -o $@ $<
+   $(TEXI2DVI) -I $(abs_docdir)/include -o $@ $<
 
 doc/gdc.pdf: $(D_TEXI_FILES)
-   $(TEXI2PDF) -I $(abs_docdir) -I $(abs_docdir)/include -o $@ $<
+   $(TEXI2PDF) -I $(abs_docdir)/include -o $@ $<
 
-$(build_htmldir)/d/index.html: $(D_TEXI_FILES)
+$(build_htmldir)/gdc/index.html: $(D_TEXI_FILES)
$(mkinstalldirs) $(@D)
rm -f $(@D)/*
-   $(TEXI2HTML) -I $(gcc_docdir) -I $(gcc_docdir)/include \
-   -I $(srcdir)/d -o $(@D) $<
+   $(TEXI2HTML) -I $(gcc_docdir)/include -I $(srcdir)/d -o $(@D) $<
 
 .INTERMEDIATE: gdc.pod
 
@@ -277,7 +276,7 @@ d.rest.encap:
 d.info: doc/gdc.info
 d.dvi: doc/gdc.dvi
 d.pdf: doc/gdc.pdf
-d.html: $(build_htmldir)/d/index.html
+d.html: $(build_htmldir)/gdc/index.html
 d.srcinfo: doc/gdc.info
-cp -p $^ $(srcdir)/doc
 d.srcextra:
@@ -341,10 +340,10 @@ d.install-dvi: doc/gdc.dvi
  $(INSTALL_DATA) "$$d$$p" "$(DESTDIR)$(dvidir)/gcc/$$f"; \
done
 
-d.install-html: $(build_htmldir)/d
+d.install-html: $(build_htmldir)/gdc
@$(NORMAL_INSTALL)
test -z "$(htmldir)" || $(mkinstalldirs) "$(DESTDIR)$(htmldir)"
-   @for p in $(build_htmldir)/d; do \
+   @for p in $(build_htmldir)/gdc; do \
  if test -f "$$p" || test -d "$$p"; then d=""; else d="$(srcdir)/"; 
fi; \
  f=$(html__strip_dir) \
  if test -d "$$d$$p"; then \
-- 
2.37.2



[committed] d: Separate documentation indices into options and keywords.

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

This patch separates indexes at the end of the gdc documentation into an
Options index and Keyword index, as per documentation manuals in other
front-ends.

Tested by building and checking pdf/info/man/html pages, and committed
to mainline.

Regards,
Iain.

---
gcc/d/ChangeLog:

* gdc.texi: Separate indices into options and keywords.
---
 gcc/d/gdc.texi | 225 ++---
 1 file changed, 118 insertions(+), 107 deletions(-)

diff --git a/gcc/d/gdc.texi b/gcc/d/gdc.texi
index 6ceb2cc67aa..45dc544e83f 100644
--- a/gcc/d/gdc.texi
+++ b/gcc/d/gdc.texi
@@ -2,6 +2,8 @@
 @setfilename gdc.info
 @settitle The GNU D Compiler
 
+@c Create a separate index for command line options
+@defcodeindex op
 @c Merge the standard indexes into a single one.
 @syncodeindex fn cp
 @syncodeindex vr cp
@@ -69,19 +71,14 @@ language in general, including language specifications and 
standard
 package documentation, see @uref{https://dlang.org/}.
 
 @menu
+* Invoking gdc::How to run gdc.
 * Copying:: The GNU General Public License.
 * GNU Free Documentation License::
 How you can share and copy this manual.
-* Invoking gdc::How to run gdc.
-* Index::   Index.
+* Option Index::Index of command line options.
+* Keyword Index::   Index of concepts.
 @end menu
 
-
-@include gpl_v3.texi
-
-@include fdl.texi
-
-
 @node Invoking gdc
 @chapter Invoking gdc
 
@@ -173,21 +170,21 @@ These options affect the runtime behavior of programs 
compiled with
 @table @gcctabopt
 
 @item -fall-instantiations
-@cindex @option{-fall-instantiations}
-@cindex @option{-fno-all-instantiations}
+@opindex fall-instantiations
+@opindex fno-all-instantiations
 Generate code for all template instantiations.  The default template emission
 strategy is to not generate code for declarations that were either
 instantiated speculatively, such as from @code{__traits(compiles, ...)}, or
 that come from an imported module not being compiled.
 
 @item -fno-assert
-@cindex @option{-fassert}
-@cindex @option{-fno-assert}
+@opindex fassert
+@opindex fno-assert
 Turn off code generation for @code{assert} contracts.
 
 @item -fno-bounds-check
-@cindex @option{-fbounds-check}
-@cindex @option{-fno-bounds-check}
+@opindex fbounds-check
+@opindex fno-bounds-check
 Turns off array bounds checking for all functions, which can improve
 performance for code that uses arrays extensively.  Note that this
 can result in unpredictable behavior if the code in question actually
@@ -195,7 +192,7 @@ does violate array bounds constraints.  It is safe to use 
this option
 if you are sure that your code never throws a @code{RangeError}.
 
 @item -fbounds-check=@var{value}
-@cindex @option{-fbounds-check=}
+@opindex fbounds-check=
 An alternative to @option{-fbounds-check} that allows more control
 as to where bounds checking is turned on or off.  The following values
 are supported:
@@ -210,14 +207,14 @@ Turns off array bounds checking completely.
 @end table
 
 @item -fno-builtin
-@cindex @option{-fbuiltin}
-@cindex @option{-fno-builtin}
+@opindex fbuiltin
+@opindex fno-builtin
 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}
+@opindex fcheckaction
 This option controls what code is generated on an assertion, bounds check, or
 final switch failure.  The following values are supported:
 
@@ -232,8 +229,8 @@ Throw an @code{AssertError} (the default).
 
 @item -fdebug
 @item -fdebug=@var{value}
-@cindex @option{-fdebug}
-@cindex @option{-fno-debug}
+@opindex fdebug
+@opindex fno-debug
 Turn on compilation of conditional @code{debug} code into the program.
 The @option{-fdebug} option itself sets the debug level to @code{1},
 while @option{-fdebug=} enables @code{debug} code that are identified
@@ -245,8 +242,8 @@ Turns on compilation of any @code{debug} code identified by 
@var{ident}.
 @end table
 
 @item -fno-druntime
-@cindex @option{-fdruntime}
-@cindex @option{-fno-druntime}
+@opindex fdruntime
+@opindex fno-druntime
 Implements @uref{https://dlang.org/spec/betterc.html}.  Assumes that
 compilation targets an environment without a D runtime library.
 
@@ -257,7 +254,7 @@ gdc -nophoboslib -fno-exceptions -fno-moduleinfo -fno-rtti
 @end example
 
 @item -fextern-std=@var{standard}
-@cindex @option{-fextern-std}
+@opindex fextern-std
 Sets the C++ name mangling compatibility to the version identified by
 @var{standard}.  The following values are supported:
 
@@ -277,20 +274,20 @@ Sets @code{__traits(getTargetInfo, "cppStd")} to 
@code{202002}.
 @end table
 
 @item -fno-invariants
-@cindex @option{-finvariants}
-@cindex @option{-fno-invariants}
+@opindex finvariants
+@opindex fno-invariants
 Turns off 

[committed] d: Synchronize gdc documentation with options in d/lang.opt

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

This patch synchronizes the documentation between lang.opt and gdc.texi.

Tested by building and checking pdf/info/man/html pages, and committed
to mainline.

Regards,
Iain.

---
gcc/d/ChangeLog:

* gdc.texi: Update gdc option documentation.
* lang.opt (frevert=intpromote): Correct documentation.
---
 gcc/d/gdc.texi | 38 +-
 gcc/d/lang.opt |  2 +-
 2 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/gcc/d/gdc.texi b/gcc/d/gdc.texi
index d3bf75ccfa9..6ceb2cc67aa 100644
--- a/gcc/d/gdc.texi
+++ b/gcc/d/gdc.texi
@@ -240,9 +240,6 @@ while @option{-fdebug=} enables @code{debug} code that are 
identified
 by any of the following values:
 
 @table @samp
-@item level
-Sets the debug level to @var{level}, any @code{debug} code <= @var{level}
-is compiled into the program.
 @item ident
 Turns on compilation of any @code{debug} code identified by @var{ident}.
 @end table
@@ -325,6 +322,8 @@ values are supported:
 @table @samp
 @item all
 Turns on all upcoming D language features.
+@item bitfields
+Implements bit-fields in D.
 @item dip1000
 Implements 
@uref{https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md}
 (Scoped pointers).
@@ -353,9 +352,6 @@ 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
@@ -387,13 +383,17 @@ are supported:
 @table @samp
 @item all
 Turns off all revertable D language features.
+@item dip1000
+Reverts @uref{https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md}
+(Scoped pointers).
 @item dip25
 Reverts @uref{https://github.com/dlang/DIPs/blob/master/DIPs/archive/DIP25.md}
 (Sealed references).
 @item dtorfields
 Turns off generation for destructing fields of partially constructed objects.
-@item markdown
-Turns off Markdown replacements in Ddoc comments.
+@item intpromote
+Turns off C-style integral promotion for unary @code{+}, @code{-} and @code{~}
+expressions.
 @end table
 
 @item -fno-rtti
@@ -423,9 +423,6 @@ Turns on compilation of conditional @code{version} code 
into the program
 identified by any of the following values:
 
 @table @samp
-@item level
-Sets the version level to @var{level}, any @code{version} code >= @var{level}
-is compiled into the program.
 @item ident
 Turns on compilation of @code{version} code identified by @var{ident}.
 @end table
@@ -646,8 +643,10 @@ and provides source for debuggers to show when requested.
 
 @node Warnings
 @section Warnings
-@cindex options to control warnings
-@cindex warning messages
+@cindex options, warnings
+@cindex options, errors
+@cindex warnings, suppressing
+@cindex messages, error
 @cindex messages, warning
 @cindex suppressing warnings
 
@@ -678,6 +677,11 @@ whose bound can be larger than @var{n} bytes.
 @option{-Walloca-larger-than} warning and is equivalent to
 @option{-Walloca-larger-than=@var{SIZE_MAX}} or larger.
 
+@item -Wno-builtin-declaration-mismatch
+@cindex @option{-Wno-builtin-declaration-mismatch}
+@cindex @option{-Wbuiltin-declaration-mismatch}
+Warn if a built-in function is declared with an incompatible signature.
+
 @item -Wcast-result
 @cindex @option{-Wcast-result}
 @cindex @option{-Wno-cast-result}
@@ -704,12 +708,6 @@ List all error messages from speculative compiles, such as
 messages as warnings, and these messages therefore never become
 errors when the @option{-Werror} option is also used.
 
-@item -Wtemplates
-@cindex @option{-Wtemplates}
-@cindex @option{-Wno-templates}
-Warn when a template instantiation is encountered.  Some coding
-rules disallow templates, and this may be used to enforce that rule.
-
 @item -Wunknown-pragmas
 @cindex @option{-Wunknown-pragmas}
 @cindex @option{-Wno-unknown-pragmas}
@@ -764,8 +762,6 @@ List all hidden GC allocations.
 List statistics on template instantiations.
 @item tls
 List all variables going into thread local storage.
-@item vmarkdown
-List instances of Markdown replacements in Ddoc.
 @end table
 
 @end table
diff --git a/gcc/d/lang.opt b/gcc/d/lang.opt
index 15ab725a2dd..b039c766aa9 100644
--- a/gcc/d/lang.opt
+++ b/gcc/d/lang.opt
@@ -422,7 +422,7 @@ Don't destruct fields of partially constructed objects.
 
 frevert=intpromote
 D RejectNegative
-Use C-style integral promotion for unary '+', '-' and '~'.
+Don't use C-style integral promotion for unary '+', '-' and '~'.
 
 frtti
 D
-- 
2.37.2



[GCC-12][committed] d: Fix #error You must define PREFERRED_DEBUGGING_TYPE if DWARF is not supported

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

This patch was applied to mainline back in August, but was held back
from backporting until after 12.2 release to allow some more time for
testing.  There are no further regressions been found, so have
backported to the releases/gcc-12 branch.

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

Regards,
Iain.

---
PR d/105659

gcc/ChangeLog:

* config.gcc: Set tm_d_file to ${cpu_type}/${cpu_type}-d.h.
* config/aarch64/aarch64-d.cc: Include tm_d.h.
* config/aarch64/aarch64-protos.h (aarch64_d_target_versions): Move to
config/aarch64/aarch64-d.h.
(aarch64_d_register_target_info): Likewise.
* config/aarch64/aarch64.h (TARGET_D_CPU_VERSIONS): Likewise.
(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
* config/arm/arm-d.cc: Include tm_d.h and arm-protos.h instead of
tm_p.h.
* config/arm/arm-protos.h (arm_d_target_versions): Move to
config/arm/arm-d.h.
(arm_d_register_target_info): Likewise.
* config/arm/arm.h (TARGET_D_CPU_VERSIONS): Likewise.
(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
* config/default-d.cc: Remove memmodel.h include.
* config/freebsd-d.cc: Include tm_d.h instead of tm_p.h.
* config/glibc-d.cc: Likewise.
* config/i386/i386-d.cc: Include tm_d.h.
* config/i386/i386-protos.h (ix86_d_target_versions): Move to
config/i386/i386-d.h.
(ix86_d_register_target_info): Likewise.
(ix86_d_has_stdcall_convention): Likewise.
* config/i386/i386.h (TARGET_D_CPU_VERSIONS): Likewise.
(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
(TARGET_D_HAS_STDCALL_CONVENTION): Likewise.
* config/i386/winnt-d.cc: Include tm_d.h instead of tm_p.h.
* config/mips/mips-d.cc: Include tm_d.h.
* config/mips/mips-protos.h (mips_d_target_versions): Move to
config/mips/mips-d.h.
(mips_d_register_target_info): Likewise.
* config/mips/mips.h (TARGET_D_CPU_VERSIONS): Likewise.
(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
* config/netbsd-d.cc: Include tm_d.h instead of tm.h and memmodel.h.
* config/openbsd-d.cc: Likewise.
* config/pa/pa-d.cc: Include tm_d.h.
* config/pa/pa-protos.h (pa_d_target_versions): Move to
config/pa/pa-d.h.
(pa_d_register_target_info): Likewise.
* config/pa/pa.h (TARGET_D_CPU_VERSIONS): Likewise.
(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
* config/riscv/riscv-d.cc: Include tm_d.h.
* config/riscv/riscv-protos.h (riscv_d_target_versions): Move to
config/riscv/riscv-d.h.
(riscv_d_register_target_info): Likewise.
* config/riscv/riscv.h (TARGET_D_CPU_VERSIONS): Likewise.
(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
* config/rs6000/rs6000-d.cc: Include tm_d.h.
* config/rs6000/rs6000-protos.h (rs6000_d_target_versions): Move to
config/rs6000/rs6000-d.h.
(rs6000_d_register_target_info): Likewise.
* config/rs6000/rs6000.h (TARGET_D_CPU_VERSIONS) Likewise.:
(TARGET_D_REGISTER_CPU_TARGET_INFO) Likewise.:
* config/s390/s390-d.cc: Include tm_d.h.
* config/s390/s390-protos.h (s390_d_target_versions): Move to
config/s390/s390-d.h.
(s390_d_register_target_info): Likewise.
* config/s390/s390.h (TARGET_D_CPU_VERSIONS): Likewise.
(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
* config/sol2-d.cc: Include tm_d.h instead of tm.h and memmodel.h.
* config/sparc/sparc-d.cc: Include tm_d.h.
* config/sparc/sparc-protos.h (sparc_d_target_versions): Move to
config/sparc/sparc-d.h.
(sparc_d_register_target_info): Likewise.
* config/sparc/sparc.h (TARGET_D_CPU_VERSIONS): Likewise.
(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
* configure: Regenerate.
* configure.ac (tm_d_file): Remove defaults.h.
(tm_d_include_list): Remove options.h and insn-constants.h.
* config/aarch64/aarch64-d.h: New file.
* config/arm/arm-d.h: New file.
* config/i386/i386-d.h: New file.
* config/mips/mips-d.h: New file.
* config/pa/pa-d.h: New file.
* config/riscv/riscv-d.h: New file.
* config/rs6000/rs6000-d.h: New file.
* config/s390/s390-d.h: New file.
* config/sparc/sparc-d.h: New file.

(cherry picked from commit d5ad6f8415171798adaff5787400505ce9882144)
---
 gcc/config.gcc  | 10 ++
 gcc/config/aarch64/aarch64-d.cc |  1 +
 gcc/config/aarch64/aarch64-d.h  | 24 
 gcc/config/aarch64/aarch64-protos.h |  4 
 gcc/config/aarch64/aarch64.h|  4 
 gcc/config/arm/arm-d.cc |  3 ++-
 gcc/config/arm/arm-d.h  | 24 
 gcc/config/arm/arm-protos.h |  4 
 gcc/config/arm/arm.h|  4 

[committed] d: Fix ICE on named continue label in an unrolled loop [PR107592]

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

This patch fixes an ICE with using `continue' on a named label in an
unrolled loop statement.

Continue labels in an unrolled loop require a unique label per
iteration.  Previously this used the Statement body node for each
unrolled iteration to generate a new entry in the label hash table.
This does not work when the continue label has an identifier, as said
named label is pointing to the outer UnrolledLoopStatement node.

What would happen is that during the lowering of `continue label', an
automatic label associated with the unrolled loop would be generated,
and a jump to that label inserted, but because it was never pushed by
the visitor for the loop itself, it subsequently never gets emitted.

To fix, correctly use the UnrolledLoopStatement as the key to look up
and store the break/continue label pair, but remove the continue label
from the value entry after every loop to force a new label to be
generated by the next call to `push_continue_label'

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

Regards
Iain.

---
PR d/107592

gcc/d/ChangeLog:

* toir.cc (IRVisitor::push_unrolled_continue_label): New method.
(IRVisitor::pop_unrolled_continue_label): New method.
(IRVisitor::visit (UnrolledLoopStatement *)): Use them instead of
push_continue_label and pop_continue_label.

gcc/testsuite/ChangeLog:

* gdc.dg/pr107592.d: New test.
---
 gcc/d/toir.cc   | 26 --
 gcc/testsuite/gdc.dg/pr107592.d | 13 +
 2 files changed, 37 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/pr107592.d

diff --git a/gcc/d/toir.cc b/gcc/d/toir.cc
index e5f5751f6db..e387f27760d 100644
--- a/gcc/d/toir.cc
+++ b/gcc/d/toir.cc
@@ -529,6 +529,28 @@ public:
 this->do_label (label);
   }
 
+  /* Generate and set a new continue label for the current unrolled loop.  */
+
+  void push_unrolled_continue_label (UnrolledLoopStatement *s)
+  {
+this->push_continue_label (s);
+  }
+
+  /* Finish with the continue label for the unrolled loop.  */
+
+  void pop_unrolled_continue_label (UnrolledLoopStatement *s)
+  {
+Statement *stmt = s->getRelatedLabeled ();
+d_label_entry *ent = d_function_chain->labels->get (stmt);
+gcc_assert (ent != NULL && ent->bc_label == true);
+
+this->pop_continue_label (TREE_VEC_ELT (ent->label, bc_continue));
+
+/* Remove the continue label from the label htab, as a new one must be
+   inserted at the end of every unrolled loop.  */
+ent->label = TREE_VEC_ELT (ent->label, bc_break);
+  }
+
   /* Visitor interfaces.  */
 
 
@@ -1089,9 +,9 @@ public:
 
if (statement != NULL)
  {
-   tree lcontinue = this->push_continue_label (statement);
+   this->push_unrolled_continue_label (s);
this->build_stmt (statement);
-   this->pop_continue_label (lcontinue);
+   this->pop_unrolled_continue_label (s);
  }
   }
 
diff --git a/gcc/testsuite/gdc.dg/pr107592.d b/gcc/testsuite/gdc.dg/pr107592.d
new file mode 100644
index 000..59f34477356
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr107592.d
@@ -0,0 +1,13 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107592
+// { dg-do compile }
+
+void test107592(Things...)(Things things)
+{
+label:
+foreach (thing; things)
+{
+continue label;
+}
+}
+
+alias a107592 = test107592!(string);
-- 
2.37.2



Re: [PATCH] range-op: Implement floating point division fold_range [PR107569]

2022-11-30 Thread Iain Buclaw via Gcc-patches
Excerpts from Jakub Jelinek via Gcc-patches's message of November 11, 2022 
10:09 am:
> Hi!
> 
> Here is the floating point division fold_range implementation,
> as I wrote in the last mail, we could outline some of the common parts
> into static methods with descriptive names and share them between
> foperator_div and foperator_mult.
> 
> Bootstrapped/regtested on top of the earlier version of the multiplication
> fold_range on x86_64-linux and i686-linux, regressions are
> +FAIL: gcc.dg/pr95115.c execution test
> +FAIL: libphobos.phobos/std/math/hardware.d execution test
> +FAIL: libphobos.phobos_shared/std/math/hardware.d execution test

I've had some time to look at the Phobos failures, and seems to me that
it's a poorly written test.

pragma(inline, false) static void blockopt(ref real x) {}
real a = 3.5;
// Set all the flags to zero
resetIeeeFlags();
assert(!ieeeFlags.divByZero);
blockopt(a); // avoid constant propagation by the optimizer
// Perform a division by zero.
a /= 0.0L;
assert(a == real.infinity);
assert(ieeeFlags.divByZero);
blockopt(a); // avoid constant propagation by the optimizer


1. Since this patch, that `a /= 0.0L` operation no longer appears in the
final assembly - so no divide-by-zero flags are raised.

2. Whoever introduced blockopt() perhaps did not understand that
`a /= 0.0L` is not safe from constant propagation just because it is
surrounded by some uninlinable call.

I'll fix the test in upstream, it should really be something like:

pragma(inline, false)
static real forceDiv(real x, real y) { return x / y; }
a = forceDiv(a, 0.0L);
assert(a == real.infinity);
assert(ieeeFlags.divByZero);


Regards,
Iain.


Ping: [PATCH] maintainer-scripts: Add gdc to update_web_docs_git

2022-11-29 Thread Iain Buclaw via Gcc-patches
Ping.

This looks obvious, however I don't know how things are generated for
the online documentation site in order to say this won't cause any
problems for whatever process is building these pages.

Excerpts from Iain Buclaw's message of November 21, 2022 11:29 am:
> Hi,
> 
> This patch adds gdc to maintainer-scripts/update_web_docs_git so that
> it's built and uploaded to gcc.gnu.org/onlinedocs.
> 
> One half of re-adding the gdc docs that were taken down after the revert
> to the Sphinx conversion.
> 
> OK?
> 
> Regards,
> Iain.
> 
> ---
>   PR web/107749
> 
> maintainer-scripts/ChangeLog:
> 
>   * update_web_docs_git: Add gdc to MANUALS.
> ---
>  maintainer-scripts/update_web_docs_git | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/maintainer-scripts/update_web_docs_git 
> b/maintainer-scripts/update_web_docs_git
> index 6c38e213562..dee9b1d3b5e 100755
> --- a/maintainer-scripts/update_web_docs_git
> +++ b/maintainer-scripts/update_web_docs_git
> @@ -21,6 +21,7 @@ MANUALS="cpp
>gccgo
>gccint
>gcj
> +  gdc
>gfortran
>gfc-internals
>gnat_ugn
> -- 
> 2.37.2
> 
> 


Re: [PATCH] d: respect --enable-link-mutex configure option

2022-11-22 Thread Iain Buclaw via Gcc-patches
Excerpts from Martin Liška's message of November 22, 2022 10:41 am:
> I noticed the option is ignored because @DO_LINK_MUTEX@
> is not defined in d/Make-lang.in.
> 
> Tested locally before and after the patch.
> 
> Ready to be installed?
> Thanks,
> Martin
> 

Fine on my end.  Thanks!

Iain.


[PATCH] maintainer-scripts: Add gdc to update_web_docs_git

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

This patch adds gdc to maintainer-scripts/update_web_docs_git so that
it's built and uploaded to gcc.gnu.org/onlinedocs.

One half of re-adding the gdc docs that were taken down after the revert
to the Sphinx conversion.

OK?

Regards,
Iain.

---
PR web/107749

maintainer-scripts/ChangeLog:

* update_web_docs_git: Add gdc to MANUALS.
---
 maintainer-scripts/update_web_docs_git | 1 +
 1 file changed, 1 insertion(+)

diff --git a/maintainer-scripts/update_web_docs_git 
b/maintainer-scripts/update_web_docs_git
index 6c38e213562..dee9b1d3b5e 100755
--- a/maintainer-scripts/update_web_docs_git
+++ b/maintainer-scripts/update_web_docs_git
@@ -21,6 +21,7 @@ MANUALS="cpp
   gccgo
   gccint
   gcj
+  gdc
   gfortran
   gfc-internals
   gnat_ugn
-- 
2.37.2



[committed] d: Adjust attr_register2.d to pass when compiling with -m32

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

Noticed when running on x86_64-linux-gnu with `-m32', this test
triggered a different kind of error.  Adjusted the test to use a
different register that is common between x86 and x86_64.

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

Regards,
Iain.

---
gcc/testsuite/ChangeLog:

* gdc.dg/attr_register2.d: Adjust test.
---
 gcc/testsuite/gdc.dg/attr_register2.d | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gdc.dg/attr_register2.d 
b/gcc/testsuite/gdc.dg/attr_register2.d
index 9061a643f31..22c518f9033 100644
--- a/gcc/testsuite/gdc.dg/attr_register2.d
+++ b/gcc/testsuite/gdc.dg/attr_register2.d
@@ -6,6 +6,6 @@ import gcc.attributes;
 
 @register("ebx") extern int var2; // { dg-error "explicit register variable 
.var2. declared .extern." }
 
-@register("r12") __gshared int var3 = 0x2a; // { dg-error "global register 
variable has initial value" }
+@register("ebp") __gshared int var3 = 0x2a; // { dg-error "global register 
variable has initial value" }
 
-@register("r12") __gshared int[256] var4 = void; // { dg-error "data type of 
.var4. isn.t suitable for a register" }
+@register("ebp") __gshared int[256] var4 = void; // { dg-error "data type of 
.var4. isn.t suitable for a register" }
-- 
2.34.1



[committed] d: Add support for vector comparison operators

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

The front-end added semantic support to permit comparing two vector
expressions.  This removes the restriction in the code generator, as
well as the intrisics that previously exposed the same operation.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* d-target.cc (Target::isVectorOpSupported): Remove cases for
comparison operators.
* intrinsics.cc (maybe_set_intrinsic): Remove cases for vector
comparison intrinsics.
(maybe_warn_intrinsic_mismatch): Likewise.
(expand_intrinsic_vec_cond): Remove.
(maybe_expand_intrinsic): Remove cases for vector comparison
intrinsics.
* intrinsics.def (INTRINSIC_EQUALMASK): Remove.
(INTRINSIC_NOTEQUALMASK): Remove.
(INTRINSIC_GREATERMASK): Remove.
(INTRINSIC_GREATEREQUALMASK): Remove.

libphobos/ChangeLog:

* libdruntime/gcc/simd.d (equalMask): Implement using generics.
(notEqualMask): Likewise.
(greaterMask): Likewise.
(greaterOrEqualMask): Likewise.
(notMask): Likewise.
(andAndMask): Likewise.
(orOrMask): Likewise.

gcc/testsuite/ChangeLog:

* gdc.dg/Wbuiltin_declaration_mismatch2.d: Remove comparision tests.
* gdc.dg/simd2a.d: Update comparison tests.
* 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 |  6 --
 gcc/d/intrinsics.cc   | 65 ---
 gcc/d/intrinsics.def  |  8 ---
 .../gdc.dg/Wbuiltin_declaration_mismatch2.d   | 40 
 gcc/testsuite/gdc.dg/simd2a.d | 12 ++--
 gcc/testsuite/gdc.dg/simd2b.d | 12 ++--
 gcc/testsuite/gdc.dg/simd2c.d | 12 ++--
 gcc/testsuite/gdc.dg/simd2d.d | 12 ++--
 gcc/testsuite/gdc.dg/simd2e.d | 12 ++--
 gcc/testsuite/gdc.dg/simd2f.d | 12 ++--
 gcc/testsuite/gdc.dg/simd2g.d | 12 ++--
 gcc/testsuite/gdc.dg/simd2h.d | 12 ++--
 gcc/testsuite/gdc.dg/simd2i.d | 12 ++--
 gcc/testsuite/gdc.dg/simd2j.d | 12 ++--
 libphobos/libdruntime/gcc/simd.d  | 26 ++--
 15 files changed, 79 insertions(+), 186 deletions(-)

diff --git a/gcc/d/d-target.cc b/gcc/d/d-target.cc
index d4350e593e4..d3244673f62 100644
--- a/gcc/d/d-target.cc
+++ b/gcc/d/d-target.cc
@@ -323,12 +323,6 @@ Target::isVectorOpSupported (Type *type, EXP op, Type *)
   /* Logical operators must have a result type of bool.  */
   return false;
 
-case EXP::lessOrEqual:
-case EXP::lessThan:
-case EXP::greaterOrEqual:
-case EXP::greaterThan:
-case EXP::equal:
-case EXP::notEqual:
 case EXP::identity:
 case EXP::notIdentity:
   /* Comparison operators must have a result type of bool.  */
diff --git a/gcc/d/intrinsics.cc b/gcc/d/intrinsics.cc
index 75d43186909..6d9f74a6d7a 100644
--- a/gcc/d/intrinsics.cc
+++ b/gcc/d/intrinsics.cc
@@ -170,10 +170,6 @@ maybe_set_intrinsic (FuncDeclaration *decl)
case INTRINSIC_SHUFFLEVECTOR:
case INTRINSIC_CONVERTVECTOR:
case INTRINSIC_BLENDVECTOR:
-   case INTRINSIC_EQUALMASK:
-   case INTRINSIC_NOTEQUALMASK:
-   case INTRINSIC_GREATERMASK:
-   case INTRINSIC_GREATEREQUALMASK:
case INTRINSIC_VLOAD8:
case INTRINSIC_VLOAD16:
case INTRINSIC_VLOAD32:
@@ -487,29 +483,6 @@ maybe_warn_intrinsic_mismatch (tree function, tree callexp)
 
return false;
   }
-
-case INTRINSIC_EQUALMASK:
-case INTRINSIC_NOTEQUALMASK:
-case INTRINSIC_GREATERMASK:
-case INTRINSIC_GREATEREQUALMASK:
-  {
-   /* Expects the signature:
-  vector(T) equalMask(vector(T), vector(T));
-  vector(T) notEqualMask(vector(T), vector(T));
-  vector(T) greaterMask(vector(T), vector(T));
-  vector(T) greateOrEqualMask(vector(T), vector(T));  */
-   gcc_assert (call_expr_nargs (callexp) == 2);
-
-   tree vec0 = TREE_TYPE (CALL_EXPR_ARG (callexp, 0));
-   tree vec1 = TREE_TYPE (CALL_EXPR_ARG (callexp, 1));
-   if (!VECTOR_TYPE_P (TREE_TYPE (callexp))
-   || !VECTOR_TYPE_P (vec0)
-   || !VECTOR_TYPE_P (vec1)
-   || TYPE_MAIN_VARIANT (vec0) != TYPE_MAIN_VARIANT (vec1))
- return warn_mismatched_return_type (callexp, "__vector(T)");
-
-   return false;
-  }
 }
 
   /* Generic mismatch warning if it hasn't already been handled.  */
@@ -1072,32 +1045,6 @@ expand_volatile_store (tree callexp)
   return modify_expr (result, value);
 }
 

[committed] d: Make TARGET_D_MINFO_SECTION hooks in elfos.h the language default.

2022-10-29 Thread Iain Buclaw via Gcc-patches
Hi,

This patch makes the TARGET_D_MINFO_SECTION hooks defined in elfos.h the
langauge default, removing the last of all TARGET_D_* macro definitions
in common target headers.  Now everything is either defined in the D
language front-end, or D-specific target headers.

The target macros TARGET_D_MINFO_START_NAME and TARGET_D_MINFO_END_NAME
have also been renamed to TARGET_D_MINFO_SECTION_START and
TARGET_D_MINFO_SECTION_END respectively to reflect their relation to the
hook TARGET_D_MINFO_SECTION - the documentation of which has been
revised to clarify these changes.

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

Regards,
Iain.

---
gcc/ChangeLog:

* config/darwin-d.cc (TARGET_D_MINFO_START_NAME): Rename to ...
(TARGET_D_MINFO_SECTION_START): ...this.
(TARGET_D_MINFO_END_NAME): Rename to ...
(TARGET_D_MINFO_SECTION_END): ... this.
* config/elfos.h (TARGET_D_MINFO_SECTION): Remove.
(TARGET_D_MINFO_START_NAME): Remove.
(TARGET_D_MINFO_END_NAME): Remove.
* config/i386/cygwin-d.cc (TARGET_D_MINFO_SECTION): Remove.
(TARGET_D_MINFO_START_NAME): Remove.
(TARGET_D_MINFO_END_NAME): Remove.
* config/i386/winnt-d.cc (TARGET_D_MINFO_SECTION): Remove.
(TARGET_D_MINFO_START_NAME): Remove.
(TARGET_D_MINFO_END_NAME): Remove.
* doc/tm.texi: Regenerate.
* doc/tm.texi.in (TARGET_D_MINFO_START_NAME): Rename to ...
(TARGET_D_MINFO_SECTION_START): ...this.
(TARGET_D_MINFO_END_NAME): Rename to ...
(TARGET_D_MINFO_SECTION_END): ...this.

gcc/d/ChangeLog:

* d-target.def (d_minfo_section): Expand documentation of hook.
Default initialize to "minfo".
(d_minfo_start_name): Rename to ...
(d_minfo_section_start): ... this.  Default initialize to
"__start_minfo".
(d_minfo_end_name): Rename to ...
(d_minfo_section_end): ... this. Default initialize to "__stop_minfo".
* modules.cc (register_moduleinfo): Use new targetdm hook names.
---
 gcc/config/darwin-d.cc  |  8 
 gcc/config/elfos.h  |  6 --
 gcc/config/i386/cygwin-d.cc | 11 ---
 gcc/config/i386/winnt-d.cc  | 11 ---
 gcc/d/d-target.def  | 23 +--
 gcc/d/modules.cc|  4 ++--
 gcc/doc/tm.texi | 16 ++--
 gcc/doc/tm.texi.in  |  4 ++--
 8 files changed, 31 insertions(+), 52 deletions(-)

diff --git a/gcc/config/darwin-d.cc b/gcc/config/darwin-d.cc
index 2ceebc49851..97304947c0a 100644
--- a/gcc/config/darwin-d.cc
+++ b/gcc/config/darwin-d.cc
@@ -67,10 +67,10 @@ 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_SECTION_START
+#define TARGET_D_MINFO_SECTION_START "*section$start$__DATA$__minfodata"
 
-#undef TARGET_D_MINFO_END_NAME
-#define TARGET_D_MINFO_END_NAME "*section$end$__DATA$__minfodata"
+#undef TARGET_D_MINFO_SECTION_END
+#define TARGET_D_MINFO_SECTION_END "*section$end$__DATA$__minfodata"
 
 struct gcc_targetdm targetdm = TARGETDM_INITIALIZER;
diff --git a/gcc/config/elfos.h b/gcc/config/elfos.h
index acb376283cf..f8b3be4358a 100644
--- a/gcc/config/elfos.h
+++ b/gcc/config/elfos.h
@@ -482,9 +482,3 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
 
 #undef TARGET_LIBC_HAS_FUNCTION
 #define TARGET_LIBC_HAS_FUNCTION no_c99_libc_has_function
-
-/* ELF support needed only by D front-end.  */
-
-#define TARGET_D_MINFO_SECTION "minfo"
-#define TARGET_D_MINFO_START_NAME "__start_minfo"
-#define TARGET_D_MINFO_END_NAME "__stop_minfo"
diff --git a/gcc/config/i386/cygwin-d.cc b/gcc/config/i386/cygwin-d.cc
index 619930b4ff4..6d70d499eef 100644
--- a/gcc/config/i386/cygwin-d.cc
+++ b/gcc/config/i386/cygwin-d.cc
@@ -64,17 +64,6 @@ cygwin_d_register_target_info (void)
 #undef TARGET_D_REGISTER_OS_TARGET_INFO
 #define TARGET_D_REGISTER_OS_TARGET_INFO cygwin_d_register_target_info
 
-/* Define TARGET_D_MINFO_SECTION for Cygwin targets.  */
-
-#undef TARGET_D_MINFO_SECTION
-#define TARGET_D_MINFO_SECTION "minfo"
-
-#undef TARGET_D_MINFO_START_NAME
-#define TARGET_D_MINFO_START_NAME "__start_minfo"
-
-#undef TARGET_D_MINFO_END_NAME
-#define TARGET_D_MINFO_END_NAME "__stop_minfo"
-
 /* Define TARGET_D_TEMPLATES_ALWAYS_COMDAT for Cygwin targets.  */
 
 #undef TARGET_D_TEMPLATES_ALWAYS_COMDAT
diff --git a/gcc/config/i386/winnt-d.cc b/gcc/config/i386/winnt-d.cc
index a1fd3fa1fbe..843c7139cb2 100644
--- a/gcc/config/i386/winnt-d.cc
+++ b/gcc/config/i386/winnt-d.cc
@@ -69,17 +69,6 @@ winnt_d_register_target_info (void)
 #undef TARGET_D_REGISTER_OS_TARGET_INFO
 #define TARGET_D_REGISTER_OS_TARGET_INFO winnt_d_register_target_info
 
-/* Define TARGET_D_MINFO_SECTION for Windows targets.  */
-
-#undef TARGET_D_MINFO_SECTION
-#define 

[PATCH] d: Remove D-specific version definitions from target headers

2022-10-17 Thread Iain Buclaw via Gcc-patches
Hi,

This splits up the targetdm sources so that each file only handles one
target platform.

Having all logic kept in the headers means that they could become out of
sync when a new target is added (loongarch*-*-linux*) or accidentally
broken if some headers in tm_file are omitted or changed about.

There might be an open bikeshed question as to appropriate names for
some of the platform sources (kfreebsd-d.cc or kfreebsd-gnu-d.cc).

Bootstrapped and regression tested on x86_64-linux-gnu, and also built
i686-cygwin, i686-gnu, i686-kfreebsd-gnu, i686-kopensolaris-gnu,
x86_64-cygwin, x86_64-w64-mingw32 cross compilers, the dumps of all
predefined version identifiers remain correct in all configurations.

OK?

Regards,
Iain.

---
gcc/ChangeLog:

* config.gcc: Split out glibc-d.o into linux-d.o, kfreebsd-d.o,
kopensolaris-d.o, and gnu-d.o.  Split out cygwin-d.o from winnt-d.o.
* config/arm/linux-eabi.h (EXTRA_TARGET_D_OS_VERSIONS): Remove.
* config/gnu.h (GNU_USER_TARGET_D_OS_VERSIONS): Remove.
* config/i386/cygwin.h (EXTRA_TARGET_D_OS_VERSIONS): Remove.
* config/i386/linux-common.h (EXTRA_TARGET_D_OS_VERSIONS): Remove.
* config/i386/mingw32.h (EXTRA_TARGET_D_OS_VERSIONS): Remove.
* config/i386/t-cygming: Add cygwin-d.o.
* config/i386/winnt-d.cc (winnt_d_os_builtins): Only add
MinGW-specific version condition.
* config/kfreebsd-gnu.h (GNU_USER_TARGET_D_OS_VERSIONS): Remove.
* config/kopensolaris-gnu.h (GNU_USER_TARGET_D_OS_VERSIONS): Remove.
* config/linux-android.h (ANDROID_TARGET_D_OS_VERSIONS): Remove.
* config/linux.h (GNU_USER_TARGET_D_OS_VERSIONS): Remove.
* config/mips/linux-common.h (EXTRA_TARGET_D_OS_VERSIONS): Remove.
* config/t-glibc: Remove glibc-d.o, add gnu-d.o, kfreebsd-d.o,
kopensolaris-d.o.
* config/t-linux: Add linux-d.o.
* config/glibc-d.cc: Remove file.
* config/gnu-d.cc: New file.
* config/i386/cygwin-d.cc: New file.
* config/kfreebsd-d.cc: New file.
* config/kopensolaris-d.cc: New file.
* config/linux-d.cc: New file.
---
 gcc/config.gcc  | 24 +++--
 gcc/config/arm/linux-eabi.h |  3 --
 gcc/config/{glibc-d.cc => gnu-d.cc} | 30 ---
 gcc/config/gnu.h|  6 ---
 gcc/config/i386/cygwin-d.cc | 83 +
 gcc/config/i386/cygwin.h|  9 
 gcc/config/i386/linux-common.h  |  3 --
 gcc/config/i386/mingw32.h   | 12 -
 gcc/config/i386/t-cygming   |  4 ++
 gcc/config/i386/winnt-d.cc  | 10 ++--
 gcc/config/kfreebsd-d.cc| 65 ++
 gcc/config/kfreebsd-gnu.h   |  6 ---
 gcc/config/kopensolaris-d.cc| 65 ++
 gcc/config/kopensolaris-gnu.h   |  6 ---
 gcc/config/linux-android.h  |  6 ---
 gcc/config/linux-d.cc   | 78 +++
 gcc/config/linux.h  | 13 -
 gcc/config/mips/linux-common.h  |  3 --
 gcc/config/t-glibc  | 10 +++-
 gcc/config/t-linux  |  4 ++
 20 files changed, 345 insertions(+), 95 deletions(-)
 rename gcc/config/{glibc-d.cc => gnu-d.cc} (65%)
 create mode 100644 gcc/config/i386/cygwin-d.cc
 create mode 100644 gcc/config/kfreebsd-d.cc
 create mode 100644 gcc/config/kopensolaris-d.cc
 create mode 100644 gcc/config/linux-d.cc

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 2af30b4a6ec..2c9b9a06564 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -879,10 +879,8 @@ case ${target} in
   esac
   c_target_objs="${c_target_objs} glibc-c.o"
   cxx_target_objs="${cxx_target_objs} glibc-c.o"
-  d_target_objs="${d_target_objs} glibc-d.o"
   tmake_file="${tmake_file} t-glibc"
   target_has_targetcm=yes
-  target_has_targetdm=yes
   case $target in
 *-*-*uclibc* | *-*-uclinuxfdpiceabi)
   ;;
@@ -891,6 +889,24 @@ case ${target} in
   gcc_cv_initfini_array=yes
   ;;
   esac
+  case $target in
+*-*-*linux*)
+  d_target_objs="${d_target_objs} linux-d.o"
+  target_has_targetdm=yes
+  ;;
+*-*-kfreebsd*-gnu)
+  d_target_objs="${d_target_objs} kfreebsd-d.o"
+  target_has_targetdm=yes
+  ;;
+*-*-kopensolaris*-gnu)
+  d_target_objs="${d_target_objs} kopensolaris-d.o"
+  target_has_targetdm=yes
+  ;;
+*-*-gnu*)
+  d_target_objs="${d_target_objs} gnu-d.o"
+  target_has_targetdm=yes
+  ;;
+  esac
   ;;
 *-*-netbsd*)
   tm_p_file="${tm_p_file} netbsd-protos.h"
@@ -2051,7 +2067,7 @@ i[34567]86-*-cygwin*)
extra_objs="${extra_objs} winnt.o winnt-stubs.o"
c_target_objs="${c_target_objs} msformat-c.o"
cxx_target_objs="${cxx_target_objs} winnt-cxx.o msformat-c.o"
-   d_target_objs="${d_target_objs} winnt-d.o"
+   d_target_objs="${d_target_objs} cygwin-d.o"
target_has_targetdm="yes"
if test x$enable_threads = xyes; 

Re: [PATCH Rust front-end v2 33/37] gccrs: add lang-spec.h

2022-10-14 Thread Iain Buclaw via Gcc-patches
Excerpts from herron.phi...@googlemail.com's message of August 24, 2022 1:59 pm:
> From: Philip Herron 
> 
> This specifies the extensions of the Rust language.
> ---
>  gcc/rust/lang-specs.h | 26 ++
>  1 file changed, 26 insertions(+)
>  create mode 100644 gcc/rust/lang-specs.h
> 
> diff --git a/gcc/rust/lang-specs.h b/gcc/rust/lang-specs.h
> new file mode 100644
> index 000..9b14a559dd6
> --- /dev/null
> +++ b/gcc/rust/lang-specs.h
> @@ -0,0 +1,26 @@
> +/* lang-specs.h -- gcc driver specs for Rust frontend.
> +   Copyright (C) 2009-2022 Free Software Foundation, Inc.
> +
> +   This file is part of GCC.
> +
> +   GCC is free software; you can redistribute it and/or modify it under
> +   the terms of the GNU General Public License as published by the Free
> +   Software Foundation; either version 3, or (at your option) any later
> +   version.
> +
> +   GCC is distributed in the hope that it will be useful, but WITHOUT ANY
> +   WARRANTY; without even the implied warranty of MERCHANTABILITY or
> +   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
> +   for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with GCC; see the file COPYING3.  If not see
> +   .  */
> +
> +/* This is the contribution to the `default_compilers' array in gcc.cc
> +   for the Rust language.  */
> +
> +{".rs", "@rs", 0, 1, 0},
> +  {"@rs",

I've just noticed that you named the spec language "rs", I think you
mean to name it "@rust" instead.

Regards,
Iain.


[committed] d: Include tm.h in all D target platform sources, remove memmodel.h

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

This patch re-adds tm.h to all D-specific target platform sources,
previously removed by an earlier change that fixed up tm_d.h generation.

The tm.h header would pull in config/elfos.h, which defines
TARGET_D_MINFO_SECTION needed for the D module support in the front-end
to emit data to the correct section for the run-time library to pick up.

The removal of it in r13-2385 caused a stage2 bootstrap failure on all
Solaris targets, and others would have been affected as well.

The memmodel header has also been removed as it is no longer required
now tm_p.h is no longer used by these sources.

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

Regards,
Iain

---
gcc/ChangeLog:

* config/darwin-d.cc: Include tm.h.
* config/dragonfly-d.cc: Likewise.
* config/freebsd-d.cc: Remove memmodel.h.
* config/glibc-d.cc: Likewise.
* config/netbsd-d.cc: Include tm.h.
* config/openbsd-d.cc: Likewise.
* config/sol2-d.cc: Likewise.
---
 gcc/config/darwin-d.cc| 1 +
 gcc/config/dragonfly-d.cc | 1 +
 gcc/config/freebsd-d.cc   | 1 -
 gcc/config/glibc-d.cc | 1 -
 gcc/config/netbsd-d.cc| 1 +
 gcc/config/openbsd-d.cc   | 1 +
 gcc/config/sol2-d.cc  | 1 +
 7 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/gcc/config/darwin-d.cc b/gcc/config/darwin-d.cc
index e983883dba6..2ceebc49851 100644
--- a/gcc/config/darwin-d.cc
+++ b/gcc/config/darwin-d.cc
@@ -18,6 +18,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
+#include "tm.h"
 #include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
diff --git a/gcc/config/dragonfly-d.cc b/gcc/config/dragonfly-d.cc
index d431638f7da..881c5e60b9a 100644
--- a/gcc/config/dragonfly-d.cc
+++ b/gcc/config/dragonfly-d.cc
@@ -18,6 +18,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
+#include "tm.h"
 #include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
diff --git a/gcc/config/freebsd-d.cc b/gcc/config/freebsd-d.cc
index 189e4a69e78..c795ca2978c 100644
--- a/gcc/config/freebsd-d.cc
+++ b/gcc/config/freebsd-d.cc
@@ -18,7 +18,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "memmodel.h"
 #include "tm.h"
 #include "tm_d.h"
 #include "d/d-target.h"
diff --git a/gcc/config/glibc-d.cc b/gcc/config/glibc-d.cc
index 80ef27d19c6..1411f1973e5 100644
--- a/gcc/config/glibc-d.cc
+++ b/gcc/config/glibc-d.cc
@@ -19,7 +19,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
-#include "memmodel.h"
 #include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
diff --git a/gcc/config/netbsd-d.cc b/gcc/config/netbsd-d.cc
index cd0c95568a1..dbabae7ab71 100644
--- a/gcc/config/netbsd-d.cc
+++ b/gcc/config/netbsd-d.cc
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
+#include "tm.h"
 #include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
diff --git a/gcc/config/openbsd-d.cc b/gcc/config/openbsd-d.cc
index 33c7e41ab62..bb3a3f28f6d 100644
--- a/gcc/config/openbsd-d.cc
+++ b/gcc/config/openbsd-d.cc
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
+#include "tm.h"
 #include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
diff --git a/gcc/config/sol2-d.cc b/gcc/config/sol2-d.cc
index 0ace79d5aae..cecb49cc826 100644
--- a/gcc/config/sol2-d.cc
+++ b/gcc/config/sol2-d.cc
@@ -18,6 +18,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
+#include "tm.h"
 #include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
-- 
2.34.1



Re: [PATCH] d: Fix #error You must define PREFERRED_DEBUGGING_TYPE if DWARF is not supported (PR105659)

2022-09-07 Thread Iain Buclaw via Gcc-patches
Excerpts from Rainer Orth's message of September 7, 2022 2:40 pm:
> Hi Iain,
> 
>>> Yes, this is data related. The DSO registry picks up nothing in the
>>> miscompiled stage2 compiler, leaving all data uninitialized.  The stage1
>>> compiler works, and runs all module constructors ahead of compilation.
>>> 
>>
>> Ohh, backtrack on that, analysis is correct, but it is a compiler regression.
>>
>> The TARGET_D_MINFO_SECTION macros are in elfos.h, which of course no
>> longer get pulled in to sol2-d.cc after I removed the tm.h include.
>>
>> Re-adding these two ought to fix the bootstrap for you.
>>
>> #include "tm.h"
>> #include "memmodel.h"
> 
> it does indeed: with that patch, i386-pc-solaris2.11 and
> sparc-sun-solaris2.11 bootstraps completed successfully and test results
> are back to normal.
> 
> Thanks a lot.
> 

I'm just running through various target configurations with memmodel.h
removed, I know it was used to be required for one of the targets
(probably SPARC), though that may have been because of the previously
included tm_p.h header.

Will have a think about a likely follow-up though.

Firstly fixing the outstanding issues with
https://gcc.gnu.org/pipermail/gcc-patches/2022-July/598078.html

Secondly possibly using a different method to coax out the object format
to the D target hooks, or front-end.

Iain.


Re: [PATCH] d: Fix #error You must define PREFERRED_DEBUGGING_TYPE if DWARF is not supported (PR105659)

2022-09-07 Thread Iain Buclaw via Gcc-patches
Excerpts from Iain Buclaw's message of September 6, 2022 11:41 pm:
> Excerpts from Iain Buclaw's message of September 6, 2022 7:02 pm:
>> Excerpts from Rainer Orth's message of September 6, 2022 4:25 pm:
>>> Hi Iain,
>>> 
> there is indeed ;-)  The previous d21 emits
> 
> binary./266566/gcc/d21
> version   v2.100.1
> 
> predefs GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions
> GNU_StackGrowsDown GNU_InlineAsm assert D_PreConditions D_PostConditions
> D_Invariants D_ModuleInfo D_Exceptions D_TypeInfo all X86 D_HardFloat
> Posix Solaris CppRuntime_Gcc
> 
> while the patched one gives
> 
> core.exception.ArrayIndexError@/var/gcc/reghunt/master/gcc/d/dmd/root/stringtable.d(291):
> index [3530971477] is out of bounds for array of length 0
> gcc.deh(505): uncaught exception
> : internal compiler error: Abort
> 0x96d5b6c crash_signal
>   /var/gcc/reghunt/master/gcc/toplev.cc:314
> 

 Excellent, and the stage1 compiler?
>>> 
>>> binary./prev-gcc/d21
>>> version   v2.100.1
>>> 
>>> predefs   GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions 
>>> GNU_StackGrowsDown GNU_InlineAsm assert D_PreConditions D_PostConditions 
>>> D_Invariants D_ModuleInfo D_Exceptions D_TypeInfo all X86 D_HardFloat Posix 
>>> Solaris CppRuntime_Gcc
>>> 
>>> So identical to the pre-patch one.
>>> 
>>> Just in case, here's the stacktrace of the crashing d21, filtered
>>> through c++filt -s dlang:
>>> 
>>> Thread 2 received signal SIGABRT, Aborted.
>>> [Switching to Thread 1 (LWP 1)]
>>> 0xfe1be2e5 in __lwp_sigqueue () from /lib/libc.so.1
>>> (gdb) bt
>>> #0  0xfe1be2e5 in __lwp_sigqueue () from /lib/libc.so.1
>>> #1  0xfe1b62cf in thr_kill () from /lib/libc.so.1
>>> #2  0xfe0ed662 in raise () from /lib/libc.so.1
>>> #3  0xfe0bae74 in abort () from /lib/libc.so.1
>>> #4  0x0a8e786d in gcc.deh.terminate(immutable(char)[], uint) (msg=..., 
>>> line=) at 
>>> /var/gcc/reghunt/master/libphobos/libdruntime/gcc/deh.d:414
>>> #5  0x0a8e7ab3 in _d_throw (object=) at 
>>> /var/gcc/reghunt/master/libphobos/libdruntime/gcc/deh.d:505
>>> #6  0x0a8edf02 in onArrayIndexError (index=, 
>>> length=, file=..., line=) at 
>>> /var/gcc/reghunt/master/libphobos/libdruntime/core/exception.d:650
>>> #7  0x0a8edf3d in _d_arraybounds_indexp (file=, 
>>> line=, index=, length=) at 
>>> /var/gcc/reghunt/master/libphobos/libdruntime/core/exception.d:848
>>> #8  0x08ffc17a in 
>>> dmd.root.stringtable.StringTable!(dmd.identifier.Identifier).StringTable.findSlot(uint,
>>>  scope const(char)[]) const (this=..., hash=, str=...) at 
>>> /var/gcc/reghunt/master/gcc/d/dmd/root/stringtable.d:291
>> 
>> Yeah, I don't see how that could trigger, as the value of `i` is always
>> adjusted to `i &= (table.length - 1)` (it uses quadratic probing to search
>> the hash table).
>> 
>> The logic of the compiler doesn't appear to have changed, but the data
>> layout may have, so I'm suspecting an issue that was always there has
>> now surfaced to the fore.
>> 
> 
> Yes, this is data related. The DSO registry picks up nothing in the
> miscompiled stage2 compiler, leaving all data uninitialized.  The stage1
> compiler works, and runs all module constructors ahead of compilation.
> 

Ohh, backtrack on that, analysis is correct, but it is a compiler regression.

The TARGET_D_MINFO_SECTION macros are in elfos.h, which of course no
longer get pulled in to sol2-d.cc after I removed the tm.h include.

Re-adding these two ought to fix the bootstrap for you.

#include "tm.h"
#include "memmodel.h"

Iain


Re: [PATCH] d: Fix #error You must define PREFERRED_DEBUGGING_TYPE if DWARF is not supported (PR105659)

2022-09-06 Thread Iain Buclaw via Gcc-patches
Excerpts from Iain Buclaw's message of September 6, 2022 7:02 pm:
> Excerpts from Rainer Orth's message of September 6, 2022 4:25 pm:
>> Hi Iain,
>> 
 there is indeed ;-)  The previous d21 emits
 
 binary./266566/gcc/d21
 version   v2.100.1
 
 predefs GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions
 GNU_StackGrowsDown GNU_InlineAsm assert D_PreConditions D_PostConditions
 D_Invariants D_ModuleInfo D_Exceptions D_TypeInfo all X86 D_HardFloat
 Posix Solaris CppRuntime_Gcc
 
 while the patched one gives
 
 core.exception.ArrayIndexError@/var/gcc/reghunt/master/gcc/d/dmd/root/stringtable.d(291):
 index [3530971477] is out of bounds for array of length 0
 gcc.deh(505): uncaught exception
 : internal compiler error: Abort
 0x96d5b6c crash_signal
/var/gcc/reghunt/master/gcc/toplev.cc:314
 
>>>
>>> Excellent, and the stage1 compiler?
>> 
>> binary./prev-gcc/d21
>> version   v2.100.1
>> 
>> predefs   GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions 
>> GNU_StackGrowsDown GNU_InlineAsm assert D_PreConditions D_PostConditions 
>> D_Invariants D_ModuleInfo D_Exceptions D_TypeInfo all X86 D_HardFloat Posix 
>> Solaris CppRuntime_Gcc
>> 
>> So identical to the pre-patch one.
>> 
>> Just in case, here's the stacktrace of the crashing d21, filtered
>> through c++filt -s dlang:
>> 
>> Thread 2 received signal SIGABRT, Aborted.
>> [Switching to Thread 1 (LWP 1)]
>> 0xfe1be2e5 in __lwp_sigqueue () from /lib/libc.so.1
>> (gdb) bt
>> #0  0xfe1be2e5 in __lwp_sigqueue () from /lib/libc.so.1
>> #1  0xfe1b62cf in thr_kill () from /lib/libc.so.1
>> #2  0xfe0ed662 in raise () from /lib/libc.so.1
>> #3  0xfe0bae74 in abort () from /lib/libc.so.1
>> #4  0x0a8e786d in gcc.deh.terminate(immutable(char)[], uint) (msg=..., 
>> line=) at 
>> /var/gcc/reghunt/master/libphobos/libdruntime/gcc/deh.d:414
>> #5  0x0a8e7ab3 in _d_throw (object=) at 
>> /var/gcc/reghunt/master/libphobos/libdruntime/gcc/deh.d:505
>> #6  0x0a8edf02 in onArrayIndexError (index=, 
>> length=, file=..., line=) at 
>> /var/gcc/reghunt/master/libphobos/libdruntime/core/exception.d:650
>> #7  0x0a8edf3d in _d_arraybounds_indexp (file=, 
>> line=, index=, length=) at 
>> /var/gcc/reghunt/master/libphobos/libdruntime/core/exception.d:848
>> #8  0x08ffc17a in 
>> dmd.root.stringtable.StringTable!(dmd.identifier.Identifier).StringTable.findSlot(uint,
>>  scope const(char)[]) const (this=..., hash=, str=...) at 
>> /var/gcc/reghunt/master/gcc/d/dmd/root/stringtable.d:291
> 
> Yeah, I don't see how that could trigger, as the value of `i` is always
> adjusted to `i &= (table.length - 1)` (it uses quadratic probing to search
> the hash table).
> 
> The logic of the compiler doesn't appear to have changed, but the data
> layout may have, so I'm suspecting an issue that was always there has
> now surfaced to the fore.
> 

Yes, this is data related. The DSO registry picks up nothing in the
miscompiled stage2 compiler, leaving all data uninitialized.  The stage1
compiler works, and runs all module constructors ahead of compilation.

Iain.


Re: [PATCH] d: Fix #error You must define PREFERRED_DEBUGGING_TYPE if DWARF is not supported (PR105659)

2022-09-06 Thread Iain Buclaw via Gcc-patches
Excerpts from Rainer Orth's message of September 6, 2022 4:25 pm:
> Hi Iain,
> 
>>> there is indeed ;-)  The previous d21 emits
>>> 
>>> binary./266566/gcc/d21
>>> version   v2.100.1
>>> 
>>> predefs GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions
>>> GNU_StackGrowsDown GNU_InlineAsm assert D_PreConditions D_PostConditions
>>> D_Invariants D_ModuleInfo D_Exceptions D_TypeInfo all X86 D_HardFloat
>>> Posix Solaris CppRuntime_Gcc
>>> 
>>> while the patched one gives
>>> 
>>> core.exception.ArrayIndexError@/var/gcc/reghunt/master/gcc/d/dmd/root/stringtable.d(291):
>>> index [3530971477] is out of bounds for array of length 0
>>> gcc.deh(505): uncaught exception
>>> : internal compiler error: Abort
>>> 0x96d5b6c crash_signal
>>> /var/gcc/reghunt/master/gcc/toplev.cc:314
>>> 
>>
>> Excellent, and the stage1 compiler?
> 
> binary./prev-gcc/d21
> version   v2.100.1
> 
> predefs   GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions 
> GNU_StackGrowsDown GNU_InlineAsm assert D_PreConditions D_PostConditions 
> D_Invariants D_ModuleInfo D_Exceptions D_TypeInfo all X86 D_HardFloat Posix 
> Solaris CppRuntime_Gcc
> 
> So identical to the pre-patch one.
> 
> Just in case, here's the stacktrace of the crashing d21, filtered
> through c++filt -s dlang:
> 
> Thread 2 received signal SIGABRT, Aborted.
> [Switching to Thread 1 (LWP 1)]
> 0xfe1be2e5 in __lwp_sigqueue () from /lib/libc.so.1
> (gdb) bt
> #0  0xfe1be2e5 in __lwp_sigqueue () from /lib/libc.so.1
> #1  0xfe1b62cf in thr_kill () from /lib/libc.so.1
> #2  0xfe0ed662 in raise () from /lib/libc.so.1
> #3  0xfe0bae74 in abort () from /lib/libc.so.1
> #4  0x0a8e786d in gcc.deh.terminate(immutable(char)[], uint) (msg=..., 
> line=) at 
> /var/gcc/reghunt/master/libphobos/libdruntime/gcc/deh.d:414
> #5  0x0a8e7ab3 in _d_throw (object=) at 
> /var/gcc/reghunt/master/libphobos/libdruntime/gcc/deh.d:505
> #6  0x0a8edf02 in onArrayIndexError (index=, length= out>, file=..., line=) at 
> /var/gcc/reghunt/master/libphobos/libdruntime/core/exception.d:650
> #7  0x0a8edf3d in _d_arraybounds_indexp (file=, 
> line=, index=, length=) at 
> /var/gcc/reghunt/master/libphobos/libdruntime/core/exception.d:848
> #8  0x08ffc17a in 
> dmd.root.stringtable.StringTable!(dmd.identifier.Identifier).StringTable.findSlot(uint,
>  scope const(char)[]) const (this=..., hash=, str=...) at 
> /var/gcc/reghunt/master/gcc/d/dmd/root/stringtable.d:291

Yeah, I don't see how that could trigger, as the value of `i` is always
adjusted to `i &= (table.length - 1)` (it uses quadratic probing to search
the hash table).

The logic of the compiler doesn't appear to have changed, but the data
layout may have, so I'm suspecting an issue that was always there has
now surfaced to the fore.

Iain.


Re: [PATCH] d: Fix #error You must define PREFERRED_DEBUGGING_TYPE if DWARF is not supported (PR105659)

2022-09-06 Thread Iain Buclaw via Gcc-patches
Excerpts from Rainer Orth's message of September 6, 2022 2:04 pm:
> Hi Iain,
> 
>> Is there a difference in output from `./gcc/d21 -quiet -v` ?
>>
>> Pay attention to any predefs that have suddenly appeared or disappeared.
> 
> there is indeed ;-)  The previous d21 emits
> 
> binary./266566/gcc/d21
> version   v2.100.1
> 
> predefs   GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions 
> GNU_StackGrowsDown GNU_InlineAsm assert D_PreConditions D_PostConditions 
> D_Invariants D_ModuleInfo D_Exceptions D_TypeInfo all X86 D_HardFloat Posix 
> Solaris CppRuntime_Gcc
> 
> while the patched one gives
> 
> core.exception.ArrayIndexError@/var/gcc/reghunt/master/gcc/d/dmd/root/stringtable.d(291):
>  index [3530971477] is out of bounds for array of length 0
> gcc.deh(505): uncaught exception
> : internal compiler error: Abort
> 0x96d5b6c crash_signal
>   /var/gcc/reghunt/master/gcc/toplev.cc:314
> 

Excellent, and the stage1 compiler?

Iain.


Re: [PATCH] d: Fix #error You must define PREFERRED_DEBUGGING_TYPE if DWARF is not supported (PR105659)

2022-09-06 Thread Iain Buclaw via Gcc-patches
Excerpts from Rainer Orth's message of September 6, 2022 9:42 am:
> Hi Iain,
> 
>> Excerpts from Richard Biener's message of September 1, 2022 8:28 am:
>>> On Wed, Aug 31, 2022 at 9:21 PM Iain Buclaw  wrote:
>>> 
>>> Ah yes - I think, even if a bit verbose, this is exactly how it was supposed
>>> to be?
>>> 
>>> OK from my side.
>>> 
>>
>> To access the TARGET macros from arm-d.cc, arm-protos.h had to be
>> included (after tm_p.h was removed).
>>
>> All ~200 configurations in contrib/config-list.mk now build again with
>> the D front-end enabled.
> 
> unfortunately, this patch broke all Solaris configs
> (i386-pc-solaris2.11, sparc-sun-solaris2.11, sparcv9-sun-solaris2.11).
> libphobos configure in stage2 fails with
> 
> can compile D sources
> configure:5402: /var/gcc/regression/master/11.4-gcc/build/./gcc/gdc 
> -B/var/gcc/regression/master/11.4-gcc/build/./gcc/ 
> -B/vol/gcc/i386-pc-solaris2.11/bin/ -B/vol/gcc/i386-pc-solaris2.11/lib/ 
> -isystem /vol/gcc/i386-pc-solaris2.11/include -isystem 
> /vol/gcc/i386-pc-solaris2.11/sys-include   -fno-checking -c -fno-druntime 
> -nostdinc -I /vol/gcc/src/hg/master/local/libphobos/libdruntime  -g -O2   
> conftest.d >&5
> core.exception.ArrayIndexError@/vol/gcc/src/hg/master/local/gcc/d/dmd/root/stringtable.d(291):
>  index [3530971477] is out of bounds for array of length 0
> gcc.deh(505): uncaught exception
> 
> I don't yet see why, though.

Hi Rainer,

Is there a difference in output from `./gcc/d21 -quiet -v` ?

Pay attention to any predefs that have suddenly appeared or disappeared.

Regards,
Iain.


Re: [PATCH] d: Fix #error You must define PREFERRED_DEBUGGING_TYPE if DWARF is not supported (PR105659)

2022-09-02 Thread Iain Buclaw via Gcc-patches
Excerpts from Richard Biener's message of September 1, 2022 8:28 am:
> On Wed, Aug 31, 2022 at 9:21 PM Iain Buclaw  wrote:
>>
>> Excerpts from Joseph Myers's message of August 31, 2022 7:16 pm:
>> > On Wed, 31 Aug 2022, Iain Buclaw via Gcc-patches wrote:
>> >
>> >> Excerpts from Joseph Myers's message of August 30, 2022 11:53 pm:
>> >> > On Fri, 26 Aug 2022, Richard Biener via Gcc-patches wrote:
>> >> >
>> >> >> I was hoping Joseph would chime in here - I recollect debugging this 
>> >> >> kind
>> >> >> of thing and a thread about this a while back but unfortunately I do 
>> >> >> not
>> >> >> remember the details here (IIRC some things get included where they
>> >> >> better should not be).
>> >> >
>> >> > See 
>> >> > <https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582563.html>.
>> >> > Is there some reason it's problematic to avoid having defaults.h or
>> >> > ${cpu_type}/${cpu_type}.h included in tm_d.h, and instead have tm_d.h 
>> >> > only
>> >> > include D-specific headers?
>> >> >
>> >>
>> >> In targets such as arm-elf, we still need to pull in definitions from
>> >> ${cpu_type}/${cpu_type}-d.cc into default-d.cc.
>> >>
>> >> All I can think that might suffice is having D-specific prototype
>> >> headers in all targets as ${cpu_type}/${cpu_type}-d.h.
>> >
>> > As long as those prototypes don't involve any types that depend on an
>> > inclusion of tm.h, that should be fine.
>> >
>>
>> Updated patch that does what I described.
> 
> Ah yes - I think, even if a bit verbose, this is exactly how it was supposed
> to be?
> 
> OK from my side.
> 

To access the TARGET macros from arm-d.cc, arm-protos.h had to be
included (after tm_p.h was removed).

All ~200 configurations in contrib/config-list.mk now build again with
the D front-end enabled.

Regards,
Iain.

---

gcc/ChangeLog:

* config.gcc: Set tm_d_file to ${cpu_type}/${cpu_type}-d.h.
* config/aarch64/aarch64-d.cc: Include tm_d.h.
* config/aarch64/aarch64-protos.h (aarch64_d_target_versions): Move to
config/aarch64/aarch64-d.h.
(aarch64_d_register_target_info): Likewise.
* config/aarch64/aarch64.h (TARGET_D_CPU_VERSIONS): Likewise.
(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
* config/arm/arm-d.cc: Include tm_d.h and arm-protos.h instead of
tm_p.h.
* config/arm/arm-protos.h (arm_d_target_versions): Move to
config/arm/arm-d.h.
(arm_d_register_target_info): Likewise.
* config/arm/arm.h (TARGET_D_CPU_VERSIONS): Likewise.
(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
* config/default-d.cc: Remove memmodel.h include.
* config/freebsd-d.cc: Include tm_d.h instead of tm_p.h.
* config/glibc-d.cc: Likewise.
* config/i386/i386-d.cc: Include tm_d.h.
* config/i386/i386-protos.h (ix86_d_target_versions): Move to
config/i386/i386-d.h.
(ix86_d_register_target_info): Likewise.
(ix86_d_has_stdcall_convention): Likewise.
* config/i386/i386.h (TARGET_D_CPU_VERSIONS): Likewise.
(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
(TARGET_D_HAS_STDCALL_CONVENTION): Likewise.
* config/i386/winnt-d.cc: Include tm_d.h instead of tm_p.h.
* config/mips/mips-d.cc: Include tm_d.h.
* config/mips/mips-protos.h (mips_d_target_versions): Move to
config/mips/mips-d.h.
(mips_d_register_target_info): Likewise.
* config/mips/mips.h (TARGET_D_CPU_VERSIONS): Likewise.
(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
* config/netbsd-d.cc: Include tm_d.h instead of tm.h and memmodel.h.
* config/openbsd-d.cc: Likewise.
* config/pa/pa-d.cc: Include tm_d.h.
* config/pa/pa-protos.h (pa_d_target_versions): Move to
config/pa/pa-d.h.
(pa_d_register_target_info): Likewise.
* config/pa/pa.h (TARGET_D_CPU_VERSIONS): Likewise.
(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
* config/riscv/riscv-d.cc: Include tm_d.h.
* config/riscv/riscv-protos.h (riscv_d_target_versions): Move to
config/riscv/riscv-d.h.
(riscv_d_register_target_info): Likewise.
* config/riscv/riscv.h (TARGET_D_CPU_VERSIONS): Likewise.
(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
* config/rs6000/rs6000-d.cc: Include tm_d.h.
* config/rs6000/rs6000-protos.h (rs6000_d_target_versions): Move to
config/rs6000/rs6000-d.h.
(rs6000_d_register_target_info): Likewise.
* config/rs6000/rs6000.h (T

Re: [PATCH] d: Fix #error You must define PREFERRED_DEBUGGING_TYPE if DWARF is not supported (PR105659)

2022-08-31 Thread Iain Buclaw via Gcc-patches
Excerpts from Joseph Myers's message of August 31, 2022 7:16 pm:
> On Wed, 31 Aug 2022, Iain Buclaw via Gcc-patches wrote:
> 
>> Excerpts from Joseph Myers's message of August 30, 2022 11:53 pm:
>> > On Fri, 26 Aug 2022, Richard Biener via Gcc-patches wrote:
>> > 
>> >> I was hoping Joseph would chime in here - I recollect debugging this kind
>> >> of thing and a thread about this a while back but unfortunately I do not
>> >> remember the details here (IIRC some things get included where they
>> >> better should not be).
>> > 
>> > See <https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582563.html>.  
>> > Is there some reason it's problematic to avoid having defaults.h or 
>> > ${cpu_type}/${cpu_type}.h included in tm_d.h, and instead have tm_d.h only 
>> > include D-specific headers?
>> > 
>> 
>> In targets such as arm-elf, we still need to pull in definitions from
>> ${cpu_type}/${cpu_type}-d.cc into default-d.cc.
>> 
>> All I can think that might suffice is having D-specific prototype
>> headers in all targets as ${cpu_type}/${cpu_type}-d.h.
> 
> As long as those prototypes don't involve any types that depend on an 
> inclusion of tm.h, that should be fine.
> 

Updated patch that does what I described.

Bootstrapped on x86_64-linux-gnu and built an aarch64-rtems
cross-compiler without any errors, will kick off config-list.mk as well for
sanity checking a big list of targets in a while.

Iain.
---
PR d/105659

gcc/ChangeLog:

* config.gcc: Set tm_d_file to ${cpu_type}/${cpu_type}-d.h.
* config/aarch64/aarch64-d.cc: Include tm_d.h.
* config/aarch64/aarch64-protos.h (aarch64_d_target_versions): Move to
config/aarch64/aarch64-d.h.
(aarch64_d_register_target_info): Likewise.
* config/aarch64/aarch64.h (TARGET_D_CPU_VERSIONS): Likewise.
(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
* config/arm/arm-d.cc: Include tm_d.h instead of tm_p.h.
* config/arm/arm-protos.h (arm_d_target_versions): Move to
config/arm/arm-d.h.
(arm_d_register_target_info): Likewise.
* config/arm/arm.h (TARGET_D_CPU_VERSIONS): Likewise.
(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
* config/default-d.cc: Remove memmodel.h include.
* config/freebsd-d.cc: Include tm_d.h instead of tm_p.h.
* config/glibc-d.cc: Likewise.
* config/i386/i386-d.cc: Include tm_d.h.
* config/i386/i386-protos.h (ix86_d_target_versions): Move to
config/i386/i386-d.h.
(ix86_d_register_target_info): Likewise.
(ix86_d_has_stdcall_convention): Likewise.
* config/i386/i386.h (TARGET_D_CPU_VERSIONS): Likewise.
(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
(TARGET_D_HAS_STDCALL_CONVENTION): Likewise.
* config/i386/winnt-d.cc: Include tm_d.h instead of tm_p.h.
* config/mips/mips-d.cc: Include tm_d.h.
* config/mips/mips-protos.h (mips_d_target_versions): Move to
config/mips/mips-d.h.
(mips_d_register_target_info): Likewise.
* config/mips/mips.h (TARGET_D_CPU_VERSIONS): Likewise.
(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
* config/netbsd-d.cc: Include tm_d.h instead of tm.h and memmodel.h.
* config/openbsd-d.cc: Likewise.
* config/pa/pa-d.cc: Include tm_d.h.
* config/pa/pa-protos.h (pa_d_target_versions): Move to
config/pa/pa-d.h.
(pa_d_register_target_info): Likewise.
* config/pa/pa.h (TARGET_D_CPU_VERSIONS): Likewise.
(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
* config/riscv/riscv-d.cc: Include tm_d.h.
* config/riscv/riscv-protos.h (riscv_d_target_versions): Move to
config/riscv/riscv-d.h.
(riscv_d_register_target_info): Likewise.
* config/riscv/riscv.h (TARGET_D_CPU_VERSIONS): Likewise.
(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
* config/rs6000/rs6000-d.cc: Include tm_d.h.
* config/rs6000/rs6000-protos.h (rs6000_d_target_versions): Move to
config/rs6000/rs6000-d.h.
(rs6000_d_register_target_info): Likewise.
* config/rs6000/rs6000.h (TARGET_D_CPU_VERSIONS) Likewise.:
(TARGET_D_REGISTER_CPU_TARGET_INFO) Likewise.:
* config/s390/s390-d.cc: Include tm_d.h.
* config/s390/s390-protos.h (s390_d_target_versions): Move to
config/s390/s390-d.h.
(s390_d_register_target_info): Likewise.
* config/s390/s390.h (TARGET_D_CPU_VERSIONS): Likewise.
(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
* config/sol2-d.cc: Include tm_d.h instead of tm.h and memmodel.h.
* config/sparc/sparc-d.cc: Include tm_d.h.
* config/sparc/sparc-protos.h (sparc_d_target_versions): Move to
config/sparc/sparc-d.h.

Re: [PATCH] d: Fix #error You must define PREFERRED_DEBUGGING_TYPE if DWARF is not supported (PR105659)

2022-08-31 Thread Iain Buclaw via Gcc-patches
Excerpts from Joseph Myers's message of August 30, 2022 11:53 pm:
> On Fri, 26 Aug 2022, Richard Biener via Gcc-patches wrote:
> 
>> I was hoping Joseph would chime in here - I recollect debugging this kind
>> of thing and a thread about this a while back but unfortunately I do not
>> remember the details here (IIRC some things get included where they
>> better should not be).
> 
> See .  
> Is there some reason it's problematic to avoid having defaults.h or 
> ${cpu_type}/${cpu_type}.h included in tm_d.h, and instead have tm_d.h only 
> include D-specific headers?
> 

In targets such as arm-elf, we still need to pull in definitions from
${cpu_type}/${cpu_type}-d.cc into default-d.cc.

All I can think that might suffice is having D-specific prototype
headers in all targets as ${cpu_type}/${cpu_type}-d.h.

At this location:
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config.gcc;h=1104508488818ff589dbc0890cf3fc475ae5977a;hb=refs/heads/master#l560

if test -f ${srcdir}/config/${cpu_type}/${cpu_type}-d.h
then
tm_d_file=${cpu_type}/${cpu_type}-d.h
fi


Looks like RustFE ripped out their target support for now.

https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=1c8ebf66965509008329b6e0425ffda407265263
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=3cd9342634e38100a9fa6a4bec4d958ca3a4ab60
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=a15ee6c3e5d710556d145e6af499b09993c4ee64

Iain.


[PATCH] wwwdocs: Add D language changes and caveats to gcc-12/changes.html

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

This patch belatedly adds the new features and changes to the D
front-end during the GCC 12 development cycle, as well as a bullet in
the caveat section for D's new bootstrapping requirements.

If nothing stands out being really wrong, I'll go ahead and commit it by
end of week.

OK?

Regards,
Iain.

---
 htdocs/gcc-12/changes.html | 78 +-
 1 file changed, 77 insertions(+), 1 deletion(-)

diff --git a/htdocs/gcc-12/changes.html b/htdocs/gcc-12/changes.html
index ef957204..5bbad9bf 100644
--- a/htdocs/gcc-12/changes.html
+++ b/htdocs/gcc-12/changes.html
@@ -72,6 +72,17 @@ You may also want to check out our
 pool arguments. Those configurations had been broken for
 some time.
   
+  
+D:
+Building and bootstrapping GDC, the D compiler, now requires a working GDC
+compiler (GCC version 9.1 or later) and D runtime library, libphobos, as
+the D front end is written in D. On some targets, libphobos isn't enabled
+by default, but compiles and works if --enable-libphobos is
+used. Other targets may require a more recent minimum version of GCC to
+bootstrap. Specifics are documented for affected targets in the
+https://gcc.gnu.org/install/specific.html;>manual for
+installing GCC.
+  
   
 Fortran:
 OpenMP code using the omp_lib.h include file can no longer be
@@ -509,7 +520,72 @@ function Multiply (S1, S2 : Sign) return Sign is
 
 
 
-
+D
+
+  New features:
+
+  Support for the D programming language has been updated to version
+   2.100.1 of the language and run-time library. Full changelog for this
+   release and previous releases can be found on the
+   https://dlang.org/changelog/2.100.1.html;>dlang.org
+   website.
+  
+  On supported targets, the __traits(compiles) expression
+   can now be used to determine whether a target-specific built-in is
+   available without error during CTFE
+   (https://gcc.gnu.org/PR101127;>PR101127).
+  
+  Partial support for directly importing C99 sources into a D
+   compilation (https://dlang.org/spec/importc.html;>ImportC)
+   has been added to the language. A notable missing feature is support
+   for preprocessing C imports, which can be worked around by
+   preprocessing all C sources used for importing ahead of time.
+  
+
+  
+  New language options:
+
+  -fcheck=, enables or disables the code generation of
+   specific run-time contract checks.
+  
+  -fcheckaction=, controls the run-time behaviour on an
+   assert, array bounds check, or final switch contract failure. The
+   default is -fcheckaction=throw.
+  
+  -fdump-c++-spec=, dumps all compiled
+   extern(C++) declarations as C++ code to a file.
+   The supplimentary option -fdump-c++-spec-verbose turns on
+   emission of comments for ignored declaration in the generated C++ spec.
+  
+  -fextern-std=, controls which C++ standard
+   extern(C++) declarations are compiled to be compatible
+   with. The default is -fextern-std=c++17.
+  
+  -fpreview=, added to enable upcoming D language features
+   in the compiler.
+  
+  -frevert=, added to revert D language changes to support
+   older D codebases that need more time to transition.
+  
+  -fsave-mixins=, saves mixins expanded at compile-time to
+   a file.
+  
+
+  
+  Deprecated and removed features:
+
+  The -Wtemplates compiler switch has been removed, as it
+   had been superceded by -ftransition=templates, which more
+   accurately reports on which templates have been instantiated.
+  
+  The -ftransition=dip25 and
+   -ftransition=dip1000 compiler switches have been renamed
+   to -fpreview=dip25 and -fprefix=dip1000.
+  
+
+  
+
+
 
 Fortran
 
-- 
2.34.1



[PATCH] d: Fix #error You must define PREFERRED_DEBUGGING_TYPE if DWARF is not supported (PR105659)

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

Because targetdm contains hooks pertaining to both the target platform
and cpu, it tries to pull in both platform and cpu headers via tm_d.h in
the source file where TARGETDM_INITIALIZER is used.

Since 12.0, this has caused problems when there is no platform (*-elf),
resulting in default-d.cc failing to build due to triggering a
PREFERRED_DEBUGGING_TYPE #error.

This patch removes the CPU-specific hooks from targetdm, documenting
them instead as target macros.  Also removing the generation of tm_d.h
as its role is redundant.

I also notice that Rust maintainers initially copied what I did in
devel/rust/master, but ended up reverting back to using macros to get at
target OS and CPU information as well, possibly because they ran into
the same problems as reported in PR105659.

I'm not sure whether calling these hooks via function-like macros is
really desirable, I do recall early on during the review process of the
D front-end that putting target-specific language features behind a
targetdm hook was the preferred/encouraged way to expose these things.

One alternative perhaps would be to break out CPU-specific hooks in
targetdm into a separate targetdm_cpu hook vector.  This would mean
there would be no need to include tm_p.h anywhere in D-specific target
sources (only tm.h where needed), and all D-specific prototypes in
$cpu_type-protos.h can be removed.  Though tm_d.h would still be
redundant, so either way it gets the chop.

OK? Thoughts?  I don't expect this to go in for 12.2, but backporting
some time before 12.3 would be nice.

Bootstrapped and regression tested on x86_64-linux-gnu, and checked that
it indeed fixes the referenced PR by building an aarch64-rtems cross.

Regards,
Iain.

---
PR d/105659

gcc/ChangeLog:

* Makefile.in (tm_d_file_list): Remove.
(tm_d_include_list): Remove.
(TM_D_H): Remove.
(tm_d.h): Remove.
(cs-tm_d.h): Remove.
(generated_files): Remove TM_D_H.
* config.gcc (tm_d_file): Remove.
* config/darwin-d.cc: Include memmodel.h and tm_p.h instead of tm_d.h.
* config/default-d.cc: Remove includes of memmodel.h and tm_d.h.
* config/dragonfly-d.cc: Include tm_p.h instead of tm_d.h.
* configure: Regenerate.
* configure.ac (tm_d_file): Remove.
(tm_d_file_list): Remove substitution.
(tm_d_include_list): Remove substitution.
* doc/tm.texi: Regenerate.
* doc/tm.texi.in (TARGET_D_CPU_VERSIONS): Document hook as being a
function-like macro.
(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.

gcc/d/ChangeLog:

* d-builtins.cc: Include memmodel.h and tm_p.h.
(d_init_versions): Call TARGET_D_CPU_VERSIONS via macro.
* d-target.cc (Target::_init): Call TARGET_D_REGISTER_CPU_TARGET_INFO
via macro.
* d-target.def (d_cpu_versions): Remove hook.
(d_register_cpu_target_info): Remove hook.
---
 gcc/Makefile.in   | 11 +--
 gcc/config.gcc|  7 ---
 gcc/config/darwin-d.cc|  3 ++-
 gcc/config/default-d.cc   |  9 +++--
 gcc/config/dragonfly-d.cc |  2 +-
 gcc/configure | 32 
 gcc/configure.ac  | 18 --
 gcc/d/d-builtins.cc   |  6 +-
 gcc/d/d-target.cc |  4 +++-
 gcc/d/d-target.def| 22 --
 gcc/doc/tm.texi   | 22 --
 gcc/doc/tm.texi.in| 18 --
 12 files changed, 55 insertions(+), 99 deletions(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 203f0a15187..12d9b5a3be4 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -571,8 +571,6 @@ tm_include_list=@tm_include_list@
 tm_defines=@tm_defines@
 tm_p_file_list=@tm_p_file_list@
 tm_p_include_list=@tm_p_include_list@
-tm_d_file_list=@tm_d_file_list@
-tm_d_include_list=@tm_d_include_list@
 build_xm_file_list=@build_xm_file_list@
 build_xm_include_list=@build_xm_include_list@
 build_xm_defines=@build_xm_defines@
@@ -865,7 +863,6 @@ BCONFIG_H = bconfig.h $(build_xm_file_list)
 CONFIG_H  = config.h  $(host_xm_file_list)
 TCONFIG_H = tconfig.h $(xm_file_list)
 TM_P_H= tm_p.h$(tm_p_file_list)
-TM_D_H= tm_d.h$(tm_d_file_list)
 GTM_H = tm.h  $(tm_file_list) insn-constants.h
 TM_H  = $(GTM_H) insn-flags.h $(OPTIONS_H)
 
@@ -1937,7 +1934,6 @@ bconfig.h: cs-bconfig.h ; @true
 tconfig.h: cs-tconfig.h ; @true
 tm.h: cs-tm.h ; @true
 tm_p.h: cs-tm_p.h ; @true
-tm_d.h: cs-tm_d.h ; @true
 
 cs-config.h: Makefile
TARGET_CPU_DEFAULT="" \
@@ -1964,11 +1960,6 @@ cs-tm_p.h: Makefile
HEADERS="$(tm_p_include_list)" DEFINES="" \
$(SHELL) $(srcdir)/mkconfig.sh tm_p.h
 
-cs-tm_d.h: Makefile
-   TARGET_CPU_DEFAULT="" \
-   HEADERS="$(tm_d_include_list)" DEFINES="" \
-   $(SHELL) $(srcdir)/mkconfig.sh tm_d.h
-
 # Don't automatically run autoconf, since configure.ac might be accidentally
 # newer than configure.  Also, this 

[committed] d: Update DIP links in gdc documentation to point at upstream repository

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

This patch fixes the broken DIP links in the GDC documentation.

The wiki links probably worked at some point in the distant past, but
now the official location of tracking all D Improvement Proposals is on
the upstream dlang/DIPs GitHub repository.

Regtested, committed to mainline, and backported to the releases/gcc-10,
releases/gcc-11, and releases/gcc-12 branches.

Regards,
Iain.

---
PR d/106638

gcc/d/ChangeLog:

* gdc.texi: Update DIP links to point at upstream dlang/DIPs
repository.
---
 gcc/d/gdc.texi | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/gcc/d/gdc.texi b/gcc/d/gdc.texi
index 2be3154bf86..2bff627d863 100644
--- a/gcc/d/gdc.texi
+++ b/gcc/d/gdc.texi
@@ -326,14 +326,17 @@ values are supported:
 @item all
 Turns on all upcoming D language features.
 @item dip1000
-Implements @uref{https://wiki.dlang.org/DIP1000} (Scoped pointers).
+Implements 
@uref{https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md}
+(Scoped pointers).
 @item dip1008
-Implements @uref{https://wiki.dlang.org/DIP1008} (Allow exceptions in
-@code{@@nogc} code).
+Implements 
@uref{https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1008.md}
+(Allow exceptions in @code{@@nogc} code).
 @item dip1021
-Implements @uref{https://wiki.dlang.org/DIP1021} (Mutable function arguments).
+Implements 
@uref{https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1021.md}
+(Mutable function arguments).
 @item dip25
-Implements @uref{https://wiki.dlang.org/DIP25} (Sealed references).
+Implements 
@uref{https://github.com/dlang/DIPs/blob/master/DIPs/archive/DIP25.md}
+(Sealed references).
 @item dtorfields
 Turns on generation for destructing fields of partially constructed objects.
 @item fieldwise
@@ -383,7 +386,8 @@ are supported:
 @item all
 Turns off all revertable D language features.
 @item dip25
-Reverts @uref{https://wiki.dlang.org/DIP25} (Sealed references).
+Reverts @uref{https://github.com/dlang/DIPs/blob/master/DIPs/archive/DIP25.md}
+(Sealed references).
 @item dtorfields
 Turns off generation for destructing fields of partially constructed objects.
 @item markdown
-- 
2.34.1



[committed] d: Defer compiling inline definitions until after the module has finished.

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

This patch is a follow-up to r13-2002 and r12-8673 (PR d/106563), that
instead pushes inline definitions onto a deferred list to be compiled
after the current module has finished.

This is to prevent the case of when generating the methods of a struct
type, we don't accidentally emit an inline function that references it,
as the outer struct itself would still be incomplete.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* d-tree.h (d_defer_declaration): Declare.
* decl.cc (function_needs_inline_definition_p): Defer checking
DECL_UNINLINABLE and DECL_DECLARED_INLINE_P.
(maybe_build_decl_tree): Call d_defer_declaration instead of
build_decl_tree.
* modules.cc (deferred_inline_declarations): New variable.
(build_module_tree): Set deferred_inline_declarations and a handle
declarations pushed to it.
(d_defer_declaration): New function.
---
 gcc/d/d-tree.h   |  1 +
 gcc/d/decl.cc| 22 +++---
 gcc/d/modules.cc | 20 
 3 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/gcc/d/d-tree.h b/gcc/d/d-tree.h
index 809a242ea93..4885cfe2b15 100644
--- a/gcc/d/d-tree.h
+++ b/gcc/d/d-tree.h
@@ -673,6 +673,7 @@ extern tree maybe_expand_intrinsic (tree);
 extern void build_module_tree (Module *);
 extern tree d_module_context (void);
 extern void register_module_decl (Declaration *);
+extern void d_defer_declaration (Declaration *);
 extern void d_finish_compilation (tree *, int);
 
 /* In runtime.cc.  */
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 0131b01dcc9..e91aee30845 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -1046,18 +1046,10 @@ function_needs_inline_definition_p (FuncDeclaration *fd)
   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 ()
@@ -1070,6 +1062,14 @@ function_needs_inline_definition_p (FuncDeclaration *fd)
   if (function_defined_in_root_p (fd))
 return false;
 
+  /* Non-inlineable functions are always external.  */
+  if (DECL_UNINLINABLE (fd->csym))
+return false;
+
+  /* Ignore functions that aren't decorated with `pragma(inline)'.  */
+  if (!DECL_DECLARED_INLINE_P (fd->csym))
+return false;
+
   /* Weak functions cannot be inlined.  */
   if (lookup_attribute ("weak", DECL_ATTRIBUTES (fd->csym)))
 return false;
@@ -1081,8 +1081,8 @@ function_needs_inline_definition_p (FuncDeclaration *fd)
   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.  */
+/* If the variable or function declaration in DECL needs to be defined, add it
+   to the list of deferred declarations to build later.  */
 
 static tree
 maybe_build_decl_tree (Declaration *decl)
@@ -1103,7 +1103,7 @@ maybe_build_decl_tree (Declaration *decl)
   if (function_needs_inline_definition_p (fd))
{
  DECL_EXTERNAL (fd->csym) = 0;
- build_decl_tree (fd);
+ d_defer_declaration (fd);
}
 }
 
diff --git a/gcc/d/modules.cc b/gcc/d/modules.cc
index edc79122365..0aac8fe3545 100644
--- a/gcc/d/modules.cc
+++ b/gcc/d/modules.cc
@@ -121,6 +121,9 @@ static module_info *current_testing_module;
 
 static Module *current_module_decl;
 
+/* Any inline symbols that were deferred during codegen.  */
+vec *deferred_inline_declarations;
+
 /* Returns an internal function identified by IDENT.  This is used
by both module initialization and dso handlers.  */
 
@@ -724,6 +727,9 @@ build_module_tree (Module *decl)
   current_testing_module = 
   current_module_decl = decl;
 
+  vec deferred_decls = vNULL;
+  deferred_inline_declarations = _decls;
+
   /* Layout module members.  */
   if (decl->members)
 {
@@ -811,9 +817,14 @@ build_module_tree (Module *decl)
   layout_moduleinfo (decl);
 }
 
+  /* Process all deferred functions after finishing module.  */
+  for (size_t i = 0; i < deferred_decls.length (); ++i)
+build_decl_tree (deferred_decls[i]);
+
   current_moduleinfo = NULL;
   current_testing_module = NULL;
   current_module_decl = NULL;
+  deferred_inline_declarations = NULL;
 }
 
 /* Returns the current function or module context for the purpose
@@ -888,6 +899,15 @@ register_module_decl (Declaration *d)
 }
 }
 
+/* Add DECL as a declaration to emit at the end of the current module.  */
+
+void
+d_defer_declaration (Declaration 

[committed] d: Fix internal compiler error: Segmentation fault at gimple-expr.cc:88

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

This patch fixes an ICE in the middle-end caused by the D front-end's
code generation for the special enum representing native complex types.

Because complex types are deprecated in the language, the new way to
expose native complex types is by defining an enum with a basetype of a
library-defined struct that is implicitly treated as-if it is native.
As casts are not implicitly added by the front-end when downcasting from
enum to its underlying type, we must insert an explicit cast during the
code generation pass.

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

gcc/d/ChangeLog:

* d-codegen.cc (underlying_complex_expr): New function.
(d_build_call): Handle passing native complex objects as the
library-defined equivalent.
* d-tree.h (underlying_complex_expr): Declare.
* expr.cc (ExprVisitor::visit (DotVarExp *)): Call
underlying_complex_expr instead of build_vconvert.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/pr106623.d: New test.
---
 gcc/d/d-codegen.cc  | 34 +
 gcc/d/d-tree.h  |  1 +
 gcc/d/expr.cc   |  2 +-
 gcc/testsuite/gdc.dg/torture/pr106623.d | 28 
 4 files changed, 64 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gdc.dg/torture/pr106623.d

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index d02da1f81e3..aa6bc9e53e4 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -1588,6 +1588,32 @@ complex_expr (tree type, tree re, tree im)
  type, re, im);
 }
 
+/* Build a two-field record TYPE representing the complex expression EXPR.  */
+
+tree
+underlying_complex_expr (tree type, tree expr)
+{
+  gcc_assert (list_length (TYPE_FIELDS (type)) == 2);
+
+  expr = d_save_expr (expr);
+
+  /* Build a constructor from the real and imaginary parts.  */
+  if (COMPLEX_FLOAT_TYPE_P (TREE_TYPE (expr)) &&
+  (!INDIRECT_REF_P (expr)
+   || !CONVERT_EXPR_CODE_P (TREE_CODE (TREE_OPERAND (expr, 0)
+{
+  vec  *ve = NULL;
+  CONSTRUCTOR_APPEND_ELT (ve, TYPE_FIELDS (type),
+real_part (expr));
+  CONSTRUCTOR_APPEND_ELT (ve, TREE_CHAIN (TYPE_FIELDS (type)),
+imaginary_part (expr));
+  return build_constructor (type, ve);
+}
+
+  /* Replace type in the reinterpret cast with a cast to the record type.  */
+  return build_vconvert (type, expr);
+}
+
 /* Cast EXP (which should be a pointer) to TYPE* and then indirect.
The back-end requires this cast in many cases.  */
 
@@ -2214,6 +2240,14 @@ d_build_call (TypeFunction *tf, tree callable, tree 
object,
  build_address (targ));
}
 
+ /* Complex types are exposed as special types with an underlying
+struct representation, if we are passing the native type to a
+function that accepts the library-defined version, then ensure
+it is properly reinterpreted as the underlying struct type.  */
+ if (COMPLEX_FLOAT_TYPE_P (TREE_TYPE (targ))
+ && arg->type->isTypeStruct ())
+   targ = underlying_complex_expr (build_ctype (arg->type), targ);
+
  /* Type `noreturn` is a terminator, as no other arguments can possibly
 be evaluated after it.  */
  if (TREE_TYPE (targ) == noreturn_type_node)
diff --git a/gcc/d/d-tree.h b/gcc/d/d-tree.h
index c3e95e4d2d2..809a242ea93 100644
--- a/gcc/d/d-tree.h
+++ b/gcc/d/d-tree.h
@@ -576,6 +576,7 @@ extern tree size_mult_expr (tree, tree);
 extern tree real_part (tree);
 extern tree imaginary_part (tree);
 extern tree complex_expr (tree, tree, tree);
+extern tree underlying_complex_expr (tree, tree);
 extern tree indirect_ref (tree, tree);
 extern tree build_deref (tree);
 extern tree build_pointer_index (tree, tree);
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 40c2689a3b9..140df7ee41d 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -1892,7 +1892,7 @@ public:
   underlying is really a complex type.  */
if (e->e1->type->ty == TY::Tenum
&& e->e1->type->isTypeEnum ()->sym->isSpecial ())
- object = build_vconvert (build_ctype (tb), object);
+ object = underlying_complex_expr (build_ctype (tb), object);
 
this->result_ = component_ref (object, get_symbol_decl (vd));
  }
diff --git a/gcc/testsuite/gdc.dg/torture/pr106623.d 
b/gcc/testsuite/gdc.dg/torture/pr106623.d
new file mode 100644
index 000..d782b236861
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/pr106623.d
@@ -0,0 +1,28 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106623
+// { dg-do compile }
+private struct _Complex(T) { T re; T im; }
+enum __c_complex_double : _Complex!double;
+
+pragma(inline, true)
+ulong hashOf()(scope const 

[committed] d: Build internal TypeInfo types when module name is "object"

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

This patch is a fix-up for a previous change in r13-1070.

If for whatever reason the module declaration doesn't exist in the
object file, ensure that the internal definitions for TypeInfo and
TypeInfo_Class are still created, otherwise an ICE could occur later if
they are required for a run-time helper call.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* d-compiler.cc (Compiler::onParseModule): Call create_tinfo_types
when module name is object.
* typeinfo.cc (create_tinfo_types): Add guard for multiple
invocations.
---
 gcc/d/d-compiler.cc | 11 +--
 gcc/d/typeinfo.cc   |  4 
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/gcc/d/d-compiler.cc b/gcc/d/d-compiler.cc
index ada9721541b..ef19df12437 100644
--- a/gcc/d/d-compiler.cc
+++ b/gcc/d/d-compiler.cc
@@ -130,8 +130,7 @@ Compiler::onParseModule (Module *m)
 {
   if (md->packages.length == 0)
{
- Identifier *id = (md && md->id) ? md->id : m->ident;
- if (!strcmp (id->toChars (), "object"))
+ if (!strcmp (md->id->toChars (), "object"))
{
  create_tinfo_types (m);
  return;
@@ -147,6 +146,14 @@ Compiler::onParseModule (Module *m)
}
}
 }
+  else if (m->ident)
+{
+  if (!strcmp (m->ident->toChars (), "object"))
+   {
+ create_tinfo_types (m);
+ return;
+   }
+}
 
   if (!flag_no_builtin)
 d_add_builtin_module (m);
diff --git a/gcc/d/typeinfo.cc b/gcc/d/typeinfo.cc
index d1f0d59952f..3577f669ed1 100644
--- a/gcc/d/typeinfo.cc
+++ b/gcc/d/typeinfo.cc
@@ -244,6 +244,10 @@ make_frontend_typeinfo (Identifier *ident, 
ClassDeclaration *base = NULL)
 void
 create_tinfo_types (Module *mod)
 {
+  /* Already generated internal types for the object module.  */
+  if (object_module != NULL)
+return;
+
   /* Build the internal TypeInfo and ClassInfo types.
  See TypeInfoVisitor for documentation of field layout.  */
   make_internal_typeinfo (TK_TYPEINFO_TYPE, Identifier::idPool ("TypeInfo"),
-- 
2.34.1



[committed] d: Field names of anonymous delegates should be same as regular delegate types.

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

This patch adjusts the field names of delegate csts constructed inline.
Doesn't change anything in the code generation or ABI, but makes it
consistent with regular delegates as names would match up when
inspecting tree dumps.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* d-codegen.cc (build_delegate_cst): Give anonymous delegate field
names same as per ABI spec.
---
 gcc/d/d-codegen.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 3fd4bee58f6..d02da1f81e3 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -419,8 +419,8 @@ build_delegate_cst (tree method, tree object, Type *type)
 {
   /* Convert a function method into an anonymous delegate.  */
   ctype = make_struct_type ("delegate()", 2,
-   get_identifier ("object"), TREE_TYPE (object),
-   get_identifier ("func"), TREE_TYPE (method));
+   get_identifier ("ptr"), TREE_TYPE (object),
+   get_identifier ("funcptr"), TREE_TYPE (method));
   TYPE_DELEGATE (ctype) = 1;
 }
 
-- 
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] 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



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

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



[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 

[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 

[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



[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 *)'
+   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 @@ public:

[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 *)'
+   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 = 

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

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

Casting from vector to static array is permitted in the D, and the
front-end generates a reinterpret cast, but casting back the other way
resulted in an error.

This has been fixed to be properly handled in the code generation pass
of VectorExp, and the conversion for lvalue and rvalue handling done in
convert_expr and convert_for_rvalue respectively.

As this is a bug also affecting previous versions, this will be
backported as appropriate, with a couple more changes required to fix
other related issues in the dmd front-end, so it'll go out separately.

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

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.
* 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.
---
 gcc/d/d-convert.cc   | 44 +++-
 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 
 7 files changed, 178 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

diff --git a/gcc/d/d-convert.cc b/gcc/d/d-convert.cc
index 3a6a32ab024..ec5da6c10a6 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 == 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",
@@ -643,6 +652,39 @@ convert_for_rvalue (tree expr, Type *etype, Type *totype)
   result = convert (build_ctype (tbtype), result);
 }
 
+  if (tbtype->ty == TY::Tsarray
+  && ebtype->ty == 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 *)'
+   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);
 }
 
@@ -703,7 +745,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/expr.cc b/gcc/d/expr.cc
index 34b3ddd3f10..1bb10a835d2 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -2917,14 

[committed] d: Fix build on aarch64-suse-linux

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

The variables being used to get the result out of TYPE_VECTOR_SUBPARTS
were being flagged by -Werror=maybe-uninitialized.  As they have already
been checked for being constant earlier, use `to_constant' instead.

This patch is based on feedback from Andreas.  Given the error they got,
this seems obvious.  Have only regstrapped on x86_64-linux-gnu though.

Regards,
Iain.

---
gcc/d/ChangeLog:

* intrinsics.cc (build_shuffle_mask_type): Use to_constant when
getting the number of subparts from a vector type.
(expand_intrinsic_vec_shufflevector): Likewise.
---
 gcc/d/intrinsics.cc | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/d/intrinsics.cc b/gcc/d/intrinsics.cc
index 454d940d1b5..75d43186909 100644
--- a/gcc/d/intrinsics.cc
+++ b/gcc/d/intrinsics.cc
@@ -273,8 +273,7 @@ build_shuffle_mask_type (tree type)
  printed (this should really be handled by a D tree printer).  */
   Type *t = build_frontend_type (inner);
   gcc_assert (t != NULL);
-  unsigned HOST_WIDE_INT nunits;
-  TYPE_VECTOR_SUBPARTS (type).is_constant ();
+  unsigned HOST_WIDE_INT nunits = TYPE_VECTOR_SUBPARTS (type).to_constant ();
 
   return build_ctype (TypeVector::create (t->sarrayOf (nunits)));
 }
@@ -1190,9 +1189,10 @@ expand_intrinsic_vec_shufflevector (tree callexp)
   tree vec0 = CALL_EXPR_ARG (callexp, 0);
   tree vec1 = CALL_EXPR_ARG (callexp, 1);
 
-  unsigned HOST_WIDE_INT v0elems, v1elems;
-  TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec0)).is_constant ();
-  TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec1)).is_constant ();
+  unsigned HOST_WIDE_INT v0elems =
+TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec0)).to_constant ();
+  unsigned HOST_WIDE_INT v1elems =
+TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec1)).to_constant ();
 
   unsigned HOST_WIDE_INT num_indices = call_expr_nargs (callexp) - 2;
   unsigned HOST_WIDE_INT masklen = MAX (num_indices, MAX (v0elems, v1elems));
-- 
2.34.1



Re: [committed] d: Add SIMD intrinsics module and compiler built-ins.

2022-06-29 Thread Iain Buclaw via Gcc-patches
Excerpts from Andreas Schwab's message of Juni 29, 2022 12:09 pm:
> make[3]: Entering directory '/opt/gcc/gcc-20220629/Build/gcc'
> /opt/gcc/gcc-20220629/Build/./prev-gcc/xg++ 
> -B/opt/gcc/gcc-20220629/Build/./prev-gcc/ -B/usr/aarch64-suse-linux/bin/ 
> -nostdinc++ 
> -B/opt/gcc/gcc-20220629/Build/prev-aarch64-suse-linux/libstdc++-v3/src/.libs 
> -B/opt/gcc/gcc-20220629/Build/prev-aarch64-suse-linux/libstdc++-v3/libsupc++/.libs
>   
> -I/opt/gcc/gcc-20220629/Build/prev-aarch64-suse-linux/libstdc++-v3/include/aarch64-suse-linux
>   -I/opt/gcc/gcc-20220629/Build/prev-aarch64-suse-linux/libstdc++-v3/include  
> -I/opt/gcc/gcc-20220629/libstdc++-v3/libsupc++ 
> -L/opt/gcc/gcc-20220629/Build/prev-aarch64-suse-linux/libstdc++-v3/src/.libs 
> -L/opt/gcc/gcc-20220629/Build/prev-aarch64-suse-linux/libstdc++-v3/libsupc++/.libs
>   -fno-PIE -c  -DIN_GCC_FRONTEND -g -O2 -fno-checking -gtoggle -DIN_GCC 
> -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall 
> -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute 
> -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros 
> -Wno-overlength-strings -Werror -fno-common  -DHAVE_CONFIG_H -I. -Id 
> -I../../gcc -I../../gcc/d -I../../gcc/../include 
> -I../../gcc/../libcpp/include -I../../gcc/../libcody  
> -I../../gcc/../libdecnumber -I../../gcc/../libdecnumber/bid -I../libdecnumber 
> -I../../gcc/../libbacktrace   -o d/intrinsics.o -MT d/intrinsics.o -MMD -MP 
> -MF d/.deps/intrinsics.TPo ../../gcc/d/intrinsics.cc
> ../../gcc/d/intrinsics.cc: In function 'tree_node* 
> build_shuffle_mask_type(tree)':
> ../../gcc/d/intrinsics.cc:279:42: error: 'nunits' may be used uninitialized 
> [-Werror=maybe-uninitialized]
>   279 |   return build_ctype (TypeVector::create (t->sarrayOf (nunits)));
>   |   ~~~^~
> ../../gcc/d/intrinsics.cc:276:26: note: 'nunits' was declared here
>   276 |   unsigned HOST_WIDE_INT nunits;
>   |  ^~
> In file included from ../../gcc/d/intrinsics.cc:19:
> ../../gcc/system.h: In function 'tree_node* 
> expand_intrinsic_vec_shufflevector(tree)':
> ../../gcc/system.h:396:29: error: 'v1elems' may be used uninitialized 
> [-Werror=maybe-uninitialized]
>   396 | #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
>   | ^
> ../../gcc/d/intrinsics.cc:1193:35: note: 'v1elems' was declared here
>  1193 |   unsigned HOST_WIDE_INT v0elems, v1elems;
>   |   ^~~
> ../../gcc/d/intrinsics.cc:1193:26: error: 'v0elems' may be used uninitialized 
> [-Werror=maybe-uninitialized]
>  1193 |   unsigned HOST_WIDE_INT v0elems, v1elems;
>   |  ^~~
> cc1plus: all warnings being treated as errors
> make[3]: *** [Makefile:1146: d/intrinsics.o] Error 1
> make[3]: Leaving directory '/opt/gcc/gcc-20220629/Build/gcc'
> 

Hi Andreas,

That's unfortunate, though curious why I am not seeing this on x86.
Does the error goes away if you wrap that around gcc_assert?

As I am already checking this a lot earlier before expansion, perhaps
it would be better to use to_constant().

Regards,
Iain.


[committed] d: Add SIMD intrinsics module and compiler built-ins.

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

This patch adds a SIMD intrinsics module, and compiler intrinsics.

Vectors in D are exposed by the use of the `__vector(T[N])' type, and
whilst most unary and binary operations work as you'd expect, there are
some operations that are not possible without doing the operation
unrolled, or calling some target-specific built-in, or with inline asm.

This introduces a new `gcc.simd' module that introduces the following.

 - Prefetching has been exposed by a convenient `prefetch' function in
   the library.

 - Loading and storing from an unaligned address have been exposed by
   `loadUnaligned' and `storeUnaligned' intrinsics.

 - Vector permutations have been exposed by `shuffle`, and
   `shufflevector' intrinsics.

 - Converting between two vectors with a different element type has been
   exposed by a `convertvector' intrinsic.

 - The ternary operator has been exposed with a `blendvector' intrinsic.

 - Comparison operators have been exposed by `equalMask',
   `notEqualMask', `greaterMask', and `greaterEqualMask' intrinsics.

 - Logic operators have been exposed by convenient `notMask',
   `andAndMask', and `orOrMask' functions in the library.

To be compatible with the LLVM D compiler's own SIMD intrinsic module,
there is also the addition of an `extractelement' and `insertelement'
convenience functions, and an alternative interface for calling the
`shufflevector' function.

The addition of these intrinsics lowers the boundary for users working
in SIMD to get the desired codegen they want out of the compiler.

Most of what is present here - apart from tests - is the adding of
machinery in the intrinsics suite of functions to do validation on
templated intrinsics.  Whilst these are still matched from the library
by their generic (untyped) signature, there is a still an assumption
that what has been instantiated and handed down to the code generator is
valid, because why would these definitions be found outside of the
in-tree D runtime library?  The majority of intrinsics are not
templates, so the test on the mangled signature string still guarantees
all types are as we expect them to be.  However there are still a small
handful of other templated intrinsics (core.bitop.{rol,ror},
core.math.toPrec, std.math.traits.isNaN, ...) that are currently
unchecked, so would benefit from being included into this built-in
checking function at some point in the future.

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

Regards,
Iain

---
gcc/d/ChangeLog:

* intrinsics.cc: Include diagnostic.h, langhooks.h,
vec-perm-indices.h.
(maybe_set_intrinsic): Add cases for new simd intrinsics.
(warn_mismatched_return_type): New function.
(warn_mismatched_argument): New function.
(build_shuffle_mask_type): New function.
(maybe_warn_intrinsic_mismatch): New function.
(expand_intrinsic_vec_cond): New function.
(expand_intrinsic_vec_convert): New function.
(expand_intrinsic_vec_blend): New function.
(expand_intrinsic_vec_shuffle): New function.
(expand_intrinsic_vec_shufflevector): New function.
(expand_intrinsic_vec_load_unaligned): New function.
(expand_intrinsic_vec_store_unaligned): New function.
(maybe_expand_intrinsic): Check signature of intrinsic before handing
off to front-end lowering.  Add cases for new simd intrinsics.
* intrinsics.def (INTRINSIC_LOADUNALIGNED): Define intrinsic.
(INTRINSIC_STOREUNALIGNED): Define intrinsic.
(INTRINSIC_SHUFFLE): Define intrinsic.
(INTRINSIC_SHUFFLEVECTOR): Define intrinsic.
(INTRINSIC_CONVERTVECTOR): Define intrinsic.
(INTRINSIC_BLENDVECTOR): Define intrinsic.
(INTRINSIC_EQUALMASK): Define intrinsic.
(INTRINSIC_NOTEQUALMASK): Define intrinsic.
(INTRINSIC_GREATERMASK): Define intrinsic.
(INTRINSIC_GREATEREQUALMASK): Define intrinsic.

libphobos/ChangeLog:

* libdruntime/Makefile.am (DRUNTIME_DSOURCES): Add gcc/simd.d.
* libdruntime/Makefile.in: Regenerate.
* libdruntime/gcc/simd.d: New file.

gcc/testsuite/ChangeLog:

* gdc.dg/Wbuiltin_declaration_mismatch.d: Rename to...
* gdc.dg/Wbuiltin_declaration_mismatch1.d: ...this.
* gdc.dg/Wbuiltin_declaration_mismatch2.d: New test.
* gdc.dg/torture/simd_blendvector.d: New test.
* gdc.dg/torture/simd_cond.d: New test.
* gdc.dg/torture/simd_convertvector.d: New test.
* gdc.dg/torture/simd_load.d: New test.
* gdc.dg/torture/simd_logical.d: New test.
* gdc.dg/torture/simd_shuffle.d: New test.
* gdc.dg/torture/simd_shufflevector.d: New test.
* gdc.dg/torture/simd_store.d: New test.
---
 gcc/d/intrinsics.cc   | 587 ++
 gcc/d/intrinsics.def  |  23 +
 ...tch.d => Wbuiltin_declaration_mismatch1.d} |   0
 

[committed] d: Use create_tmp_var_raw and get_callee_fndecl

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

A couple of small patterns that repeat are generating a temporary, and
getting a function out of a CALL_EXPR (there are other changes that are
in the works where I ended up adding more repeats of these patterns).
There are convenience functions for these in the common parts of gcc,
use them instead.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* d-codegen.cc: Include gimple-expr.h.
(force_target_expr): Use create_tmp_var_raw.
* decl.cc: Inlucde gimple-expr.h.
(build_local_temp): Use create_tmp_var_raw.
* intrinsics.cc (expand_intrinsic_rotate): Use get_callee_fndecl.
(maybe_expand_intrinsic): Likewise.
---
 gcc/d/d-codegen.cc  |  6 ++
 gcc/d/decl.cc   |  7 ++-
 gcc/d/intrinsics.cc | 13 +++--
 3 files changed, 7 insertions(+), 19 deletions(-)

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 8a8bf12e7fc..2d90899b37f 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -38,6 +38,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "stor-layout.h"
 #include "attribs.h"
 #include "function.h"
+#include "gimple-expr.h"
 
 #include "d-tree.h"
 
@@ -623,11 +624,8 @@ build_target_expr (tree decl, tree exp)
 tree
 force_target_expr (tree exp)
 {
-  tree decl = build_decl (input_location, VAR_DECL, NULL_TREE,
- TREE_TYPE (exp));
+  tree decl = create_tmp_var_raw (TREE_TYPE (exp));
   DECL_CONTEXT (decl) = current_function_decl;
-  DECL_ARTIFICIAL (decl) = 1;
-  DECL_IGNORED_P (decl) = 1;
   layout_decl (decl, 0);
 
   return build_target_expr (decl, exp);
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 5032ae02d6b..3caa465dd1e 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -57,6 +57,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "alloc-pool.h"
 #include "symbol-summary.h"
 #include "symtab-thunks.h"
+#include "gimple-expr.h"
 
 #include "d-tree.h"
 #include "d-target.h"
@@ -1465,11 +1466,7 @@ declare_local_var (VarDeclaration *var)
 tree
 build_local_temp (tree type)
 {
-  tree decl = build_decl (input_location, VAR_DECL, NULL_TREE, type);
-
-  DECL_CONTEXT (decl) = current_function_decl;
-  DECL_ARTIFICIAL (decl) = 1;
-  DECL_IGNORED_P (decl) = 1;
+  tree decl = create_tmp_var_raw (type);
   d_pushdecl (decl);
 
   return decl;
diff --git a/gcc/d/intrinsics.cc b/gcc/d/intrinsics.cc
index 0f96284473f..0dd5543fdd1 100644
--- a/gcc/d/intrinsics.cc
+++ b/gcc/d/intrinsics.cc
@@ -421,12 +421,8 @@ expand_intrinsic_rotate (intrinsic_code intrinsic, tree 
callexp)
 count = CALL_EXPR_ARG (callexp, 1);
   else
 {
-  tree callee = CALL_EXPR_FN (callexp);
-
-  if (TREE_CODE (callee) == ADDR_EXPR)
-   callee = TREE_OPERAND (callee, 0);
-
   /* Retrieve from the encoded template instantation.  */
+  tree callee = get_callee_fndecl (callexp);
   TemplateInstance *ti = DECL_LANG_FRONTEND (callee)->isInstantiated ();
   gcc_assert (ti && ti->tiargs && ti->tiargs->length == 2);
 
@@ -761,12 +757,9 @@ expand_volatile_store (tree callexp)
 tree
 maybe_expand_intrinsic (tree callexp)
 {
-  tree callee = CALL_EXPR_FN (callexp);
-
-  if (TREE_CODE (callee) == ADDR_EXPR)
-callee = TREE_OPERAND (callee, 0);
+  tree callee = get_callee_fndecl (callexp);
 
-  if (TREE_CODE (callee) != FUNCTION_DECL)
+  if (callee == NULL_TREE || TREE_CODE (callee) != FUNCTION_DECL)
 return callexp;
 
   /* Don't expand CTFE-only intrinsics outside of semantic processing.  */
-- 
2.34.1



[committed] d: Add @simd and @simd_clones attributes to compiler and library

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

This patch adds a `@simd' attribute to the D front-end, which is
equivalent to `__attribute__((simd))', and `@simd_clones' is a
convenience alias to allow specifying whether the compiler should
generated masked or non-masked simd clones.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* d-attribs.cc (handle_omp_declare_simd_attribute): New function.
(d_handle_simd_attribute): New function.
(d_langhook_common_attribute_table): Add 'omp declare simd' attribute.
(d_langhook_attribute_table): Add simd attribute.

libphobos/ChangeLog:

* libdruntime/gcc/attributes.d (simd): Define.

gcc/testsuite/ChangeLog:

* gdc.dg/attr_simd1.d: New test.
* gdc.dg/attr_simd2.d: New test.
---
 gcc/d/d-attribs.cc | 65 ++
 gcc/testsuite/gdc.dg/attr_simd1.d  | 40 
 gcc/testsuite/gdc.dg/attr_simd2.d  | 16 +++
 libphobos/libdruntime/gcc/attributes.d | 40 
 4 files changed, 161 insertions(+)
 create mode 100644 gcc/testsuite/gdc.dg/attr_simd1.d
 create mode 100644 gcc/testsuite/gdc.dg/attr_simd2.d

diff --git a/gcc/d/d-attribs.cc b/gcc/d/d-attribs.cc
index 1dd806f7144..04f7f1686a2 100644
--- a/gcc/d/d-attribs.cc
+++ b/gcc/d/d-attribs.cc
@@ -58,6 +58,7 @@ static tree handle_type_generic_attribute (tree *, tree, 
tree, int, bool *);
 static tree handle_transaction_pure_attribute (tree *, tree, tree, int, bool 
*);
 static tree handle_returns_twice_attribute (tree *, tree, tree, int, bool *);
 static tree handle_fnspec_attribute (tree *, tree, tree, int, bool *);
+static tree handle_omp_declare_simd_attribute (tree *, tree, tree, int, bool 
*);
 
 /* D attribute handlers for user defined attributes.  */
 static tree d_handle_noinline_attribute (tree *, tree, tree, int, bool *);
@@ -80,6 +81,7 @@ static tree d_handle_restrict_attribute (tree *, tree, tree, 
int, bool *);
 static tree d_handle_used_attribute (tree *, tree, tree, int, bool *);
 static tree d_handle_visibility_attribute (tree *, tree, tree, int, bool *);
 static tree d_handle_no_sanitize_attribute (tree *, tree, tree, int, bool *);
+static tree d_handle_simd_attribute (tree *, tree, tree, int, bool *);
 
 /* Helper to define attribute exclusions.  */
 #define ATTR_EXCL(name, function, type, variable)  \
@@ -186,6 +188,8 @@ const attribute_spec d_langhook_common_attribute_table[] =
 handle_type_generic_attribute, NULL),
   ATTR_SPEC ("fn spec", 1, 1, false, true, true, false,
 handle_fnspec_attribute, NULL),
+  ATTR_SPEC ("omp declare simd", 0, -1, true,  false, false, false,
+handle_omp_declare_simd_attribute, NULL),
   ATTR_SPEC (NULL, 0, 0, false, false, false, false, NULL, NULL),
 };
 
@@ -228,6 +232,8 @@ const attribute_spec d_langhook_attribute_table[] =
 d_handle_register_attribute, NULL),
   ATTR_SPEC ("restrict", 0, 0, true, false, false, false,
 d_handle_restrict_attribute, NULL),
+  ATTR_SPEC ("simd", 0, 1, true,  false, false, false,
+d_handle_simd_attribute, NULL),
   ATTR_SPEC ("used", 0, 0, true, false, false, false,
 d_handle_used_attribute, NULL),
   ATTR_SPEC ("visibility", 1, 1, false, false, false, false,
@@ -664,6 +670,16 @@ handle_fnspec_attribute (tree *, tree, tree args, int, 
bool *)
   return NULL_TREE;
 }
 
+/* Handle an "omp declare simd" attribute; arguments as in
+   struct attribute_spec.handler.  */
+
+tree
+handle_omp_declare_simd_attribute (tree *node, tree, tree, int, bool *)
+{
+  gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
+  return NULL_TREE;
+}
+
 /* Language specific attribute handlers.
These functions take the arguments:
(tree *node, tree name, tree args, int flags, bool *no_add_attrs)  */
@@ -1474,6 +1490,55 @@ d_handle_restrict_attribute (tree *node, tree name, 
tree, int,
   return NULL_TREE;
 }
 
+/* Handle a "simd" attribute; arguments as in
+   struct attribute_spec.handler.  */
+
+static tree
+d_handle_simd_attribute (tree *node, tree name, tree args, int,
+bool *no_add_attrs)
+{
+  if (TREE_CODE (*node) != FUNCTION_DECL)
+{
+  warning (OPT_Wattributes, "%qE attribute ignored", name);
+  *no_add_attrs = true;
+  return NULL_TREE;
+}
+
+  tree omp_attr = get_identifier ("omp declare simd");
+  tree omp_flags = NULL_TREE;
+  if (args)
+{
+  tree id = TREE_VALUE (args);
+
+  if (TREE_CODE (id) != STRING_CST)
+   {
+ error ("%qE attribute argument not a string constant", name);
+ *no_add_attrs = true;
+ return NULL_TREE;
+   }
+
+  if (strcmp (TREE_STRING_POINTER (id), "notinbranch") == 0)
+   omp_flags = build_omp_clause (DECL_SOURCE_LOCATION (*node),
+ OMP_CLAUSE_NOTINBRANCH);
+  else if (strcmp (TREE_STRING_POINTER (id), "inbranch") == 0)
+   omp_flags = 

[committed] d: Give consistent error message when attribute argument not a string constant

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

This patch adjusts all the "not a string" errors in the D attribute
handlers to use the same format string for consistency.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* d-attribs.cc (d_handle_section_attribute): Update error message.
(d_handle_symver_attribute): Likewise.
(d_handle_no_sanitize_attribute): Likewise.
(d_handle_visibility_attribute): Likewise.

gcc/testsuite/ChangeLog:

* gdc.dg/attr_section1.d: Update dg-error.
* gdc.dg/attr_visibility1.d: Likewise.
---
 gcc/d/d-attribs.cc  | 11 ++-
 gcc/testsuite/gdc.dg/attr_section1.d|  2 +-
 gcc/testsuite/gdc.dg/attr_visibility1.d |  2 +-
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/gcc/d/d-attribs.cc b/gcc/d/d-attribs.cc
index 23bbe3946fb..b7b014f72be 100644
--- a/gcc/d/d-attribs.cc
+++ b/gcc/d/d-attribs.cc
@@ -1015,7 +1015,7 @@ d_handle_section_attribute (tree *node, tree name, tree 
args, int flags,
 
   if (TREE_CODE (TREE_VALUE (args)) != STRING_CST)
 {
-  error ("section attribute argument not a string constant");
+  error ("%qE attribute argument not a string constant", name);
   *no_add_attrs = true;
   return NULL_TREE;
 }
@@ -1065,7 +1065,8 @@ d_handle_section_attribute (tree *node, tree name, tree 
args, int flags,
struct attribute_spec.handler.  */
 
 static tree
-d_handle_symver_attribute (tree *node, tree, tree args, int, bool 
*no_add_attrs)
+d_handle_symver_attribute (tree *node, tree name, tree args, int,
+  bool *no_add_attrs)
 {
   if (TREE_CODE (*node) != FUNCTION_DECL && TREE_CODE (*node) != VAR_DECL)
 {
@@ -1088,7 +1089,7 @@ d_handle_symver_attribute (tree *node, tree, tree args, 
int, bool *no_add_attrs)
   tree symver = TREE_VALUE (args);
   if (TREE_CODE (symver) != STRING_CST)
{
- error ("% attribute argument not a string constant");
+ error ("%qE attribute argument not a string constant", name);
  *no_add_attrs = true;
  return NULL_TREE;
}
@@ -1391,7 +1392,7 @@ d_handle_no_sanitize_attribute (tree *node, tree name, 
tree args, int,
   tree id = TREE_VALUE (args);
   if (TREE_CODE (id) != STRING_CST)
{
- error ("%qE argument not a string", name);
+ error ("%qE attribute argument not a string constant", name);
  return NULL_TREE;
}
 
@@ -1525,7 +1526,7 @@ d_handle_visibility_attribute (tree *node, tree name, 
tree args,
   tree id = TREE_VALUE (args);
   if (TREE_CODE (id) != STRING_CST)
 {
-  error ("visibility argument not a string");
+  error ("%qE attribute argument not a string constant", name);
   return NULL_TREE;
 }
 
diff --git a/gcc/testsuite/gdc.dg/attr_section1.d 
b/gcc/testsuite/gdc.dg/attr_section1.d
index c24634f7fd5..759b203dd44 100644
--- a/gcc/testsuite/gdc.dg/attr_section1.d
+++ b/gcc/testsuite/gdc.dg/attr_section1.d
@@ -7,7 +7,7 @@ import gcc.attributes;
 struct S {} // { dg-warning ".section. attribute does not apply to types" }
 
 @attribute("section", 123)
-int f1(); // { dg-error "section attribute argument not a string constant" }
+int f1(); // { dg-error ".section. attribute argument not a string constant" }
 
 int f2(@section("param") int a) // { dg-error "section attribute not allowed 
for .a." }
 {
diff --git a/gcc/testsuite/gdc.dg/attr_visibility1.d 
b/gcc/testsuite/gdc.dg/attr_visibility1.d
index a7ed4065605..932e6e6051f 100644
--- a/gcc/testsuite/gdc.dg/attr_visibility1.d
+++ b/gcc/testsuite/gdc.dg/attr_visibility1.d
@@ -13,7 +13,7 @@ void nested()
 }
 
 @attribute("visibility", 123)
-int not_a_string(); // { dg-error "visibility argument not a string" }
+int not_a_string(); // { dg-error ".visibility. attribute argument not a 
string constant" }
 
 @attribute("visibility", "invalid argument")
 int invalid_argument(); // { dg-error ".visibility. argument must be one of" }
-- 
2.34.1



[committed] d: Add `@register' attribute to compiler and library (PR105413)

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

This patch adds a new `@register' attribute to the D compiler and
library.  Addressing a feature request in PR105413.

The `@register` attribute specifies that a local or `__gshared` variable
is to be given a register storage-class in the C sense of the term, and
will be placed into a register named `registerName`.

The variable needs to boiled down to a data type that fits the target
register.  It also cannot have either thread-local or `extern` storage.
It is an error to take the address of a register variable.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* d-attribs.cc (d_handle_register_attribute): New function.
(d_langhook_attribute_table): Add register attribute.
* d-codegen.cc (d_mark_addressable): Error if taken address of
register variable.
(build_frame_type): Error if register variable has non-local
references.
* d-tree.h (d_mark_addressable): Add complain parameter.
* decl.cc (get_symbol_decl): Mark register varibles DECL_REGISTER.
Error when register variable declared thread-local or extern.
* expr.cc (ExprVisitor::visit (IndexExp *)): Don't complain about
marking register vectors as addressable in an ARRAY_REF.

libphobos/ChangeLog:

* libdruntime/gcc/attributes.d (register): Define.

gcc/testsuite/ChangeLog:

* gdc.dg/attr_register1.d: New test.
* gdc.dg/attr_register2.d: New test.
* gdc.dg/attr_register3.d: New test.
---
 gcc/d/d-attribs.cc | 40 ++-
 gcc/d/d-codegen.cc | 32 ---
 gcc/d/d-tree.h |  2 +-
 gcc/d/decl.cc  | 24 ++-
 gcc/d/expr.cc  |  2 +-
 gcc/testsuite/gdc.dg/attr_register1.d  | 55 ++
 gcc/testsuite/gdc.dg/attr_register2.d  | 11 ++
 gcc/testsuite/gdc.dg/attr_register3.d  | 22 +++
 libphobos/libdruntime/gcc/attributes.d | 28 +
 9 files changed, 204 insertions(+), 12 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/attr_register1.d
 create mode 100644 gcc/testsuite/gdc.dg/attr_register2.d
 create mode 100644 gcc/testsuite/gdc.dg/attr_register3.d

diff --git a/gcc/d/d-attribs.cc b/gcc/d/d-attribs.cc
index 4b54426be39..23bbe3946fb 100644
--- a/gcc/d/d-attribs.cc
+++ b/gcc/d/d-attribs.cc
@@ -75,6 +75,7 @@ static tree d_handle_weak_attribute (tree *, tree, tree, int, 
bool *) ;
 static tree d_handle_noplt_attribute (tree *, tree, tree, int, bool *) ;
 static tree d_handle_alloc_size_attribute (tree *, tree, tree, int, bool *);
 static tree d_handle_cold_attribute (tree *, tree, tree, int, bool *);
+static tree d_handle_register_attribute (tree *, tree, tree, int, bool *);
 static tree d_handle_restrict_attribute (tree *, tree, tree, int, bool *);
 static tree d_handle_used_attribute (tree *, tree, tree, int, bool *);
 static tree d_handle_visibility_attribute (tree *, tree, tree, int, bool *);
@@ -223,6 +224,8 @@ const attribute_spec d_langhook_attribute_table[] =
 d_handle_cold_attribute, attr_cold_hot_exclusions),
   ATTR_SPEC ("no_sanitize", 1, -1, true, false, false, false,
 d_handle_no_sanitize_attribute, NULL),
+  ATTR_SPEC ("register", 1, 1, true, false, false, false,
+d_handle_register_attribute, NULL),
   ATTR_SPEC ("restrict", 0, 0, true, false, false, false,
 d_handle_restrict_attribute, NULL),
   ATTR_SPEC ("used", 0, 0, true, false, false, false,
@@ -1409,8 +1412,41 @@ d_handle_no_sanitize_attribute (tree *node, tree name, 
tree args, int,
   else
 {
   DECL_ATTRIBUTES (*node) = tree_cons (get_identifier ("no_sanitize"),
-  build_int_cst (d_uint_type, flags),
-  DECL_ATTRIBUTES (*node));
+  build_int_cst (d_uint_type, flags),
+  DECL_ATTRIBUTES (*node));
+}
+
+  return NULL_TREE;
+}
+
+/* Handle a "register" attribute; arguments as in
+   struct attribute_spec.handler.  */
+
+static tree
+d_handle_register_attribute (tree *node, tree name, tree args, int,
+bool *no_add_attrs)
+{
+  if (!VAR_P (*node))
+{
+  warning (OPT_Wattributes, "%qE attribute ignored", name);
+  *no_add_attrs = true;
+}
+  else if (TREE_CODE (TREE_VALUE (args)) != STRING_CST)
+{
+  error ("%qE attribute argument not a string constant", name);
+  *no_add_attrs = true;
+}
+  else if (TREE_STRING_LENGTH (TREE_VALUE (args)) == 0
+  || TREE_STRING_POINTER (TREE_VALUE (args))[0] == '\0')
+{
+  error ("register name not specified for %q+D", *node);
+  *no_add_attrs = true;
+}
+  else
+{
+  DECL_REGISTER (*node) = 1;
+  set_user_assembler_name (*node, TREE_STRING_POINTER (TREE_VALUE 

[committed] d: Construct indexes of ARRAY_TYPE using ARRAY_REF.

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

This patch changes the D front-end code generation of index expressions
to use an ARRAY_REF when the array expression is a ARRAY_TYPE.

This is a small simplification over `((T *))[index]', which also
allows eliding an unneccesary marking of TREE_ADDRESSABLE when the array
expression is a parameter or variable declaration.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* d-codegen.cc (build_array_index): Rename to...
(build_pointer_index): ...this.
* d-tree.h (build_array_index): Rename declaration to...
(build_pointer_index): ...this.
* expr.cc (ExprVisitor::visit (IndexExp *)): Construct indexes of
ARRAY_TYPE using ARRAY_REF.
(ExprVisitor::visit (SliceExp *)): Update.
* intrinsics.cc (expand_intrinsic_bt): Update.
---
 gcc/d/d-codegen.cc  |  2 +-
 gcc/d/d-tree.h  |  2 +-
 gcc/d/expr.cc   | 38 +++---
 gcc/d/intrinsics.cc |  4 ++--
 4 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 0e14654e56b..3a201149d74 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -1626,7 +1626,7 @@ build_deref (tree exp)
 /* Builds pointer offset expression PTR[INDEX].  */
 
 tree
-build_array_index (tree ptr, tree index)
+build_pointer_index (tree ptr, tree index)
 {
   if (error_operand_p (ptr) || error_operand_p (index))
 return error_mark_node;
diff --git a/gcc/d/d-tree.h b/gcc/d/d-tree.h
index 751746395e6..a6c38119458 100644
--- a/gcc/d/d-tree.h
+++ b/gcc/d/d-tree.h
@@ -578,7 +578,7 @@ extern tree imaginary_part (tree);
 extern tree complex_expr (tree, tree, tree);
 extern tree indirect_ref (tree, tree);
 extern tree build_deref (tree);
-extern tree build_array_index (tree, tree);
+extern tree build_pointer_index (tree, tree);
 extern tree build_offset_op (tree_code, tree, tree);
 extern tree build_offset (tree, tree);
 extern tree build_memref (tree, tree, tree);
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index fba397bed35..bf750924594 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -1222,9 +1222,8 @@ public:
   }
 else
   {
-   /* Get the data pointer and length for static and dynamic arrays.  */
+   /* Get the array and length for static and dynamic arrays.  */
tree array = d_save_expr (build_expr (e->e1));
-   tree ptr = convert_expr (array, tb1, tb1->nextOf ()->pointerTo ());
 
tree length = NULL_TREE;
if (tb1->ty != TY::Tpointer)
@@ -1245,10 +1244,35 @@ public:
if (tb1->ty != TY::Tpointer)
  index = build_bounds_index_condition (e, index, length);
 
-   /* Index the .ptr.  */
-   ptr = void_okay_p (ptr);
-   this->result_ = indirect_ref (TREE_TYPE (TREE_TYPE (ptr)),
- build_array_index (ptr, index));
+   /* Convert vectors to their underlying array type.  */
+   if (VECTOR_TYPE_P (TREE_TYPE (array)))
+ {
+   tree array_type =
+ build_array_type_nelts (TREE_TYPE (TREE_TYPE (array)),
+ TYPE_VECTOR_SUBPARTS (TREE_TYPE (array)));
+   d_mark_addressable (array);
+   array = build1 (VIEW_CONVERT_EXPR, array_type, array);
+ }
+
+   if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
+ {
+   /* Generate `array[index]'.  When the index is non-constant, we must
+  mark the array as addressable because we'll need to do pointer
+  arithmetic on its address.  */
+   if (TREE_CODE (index) != INTEGER_CST)
+ d_mark_addressable (array);
+
+   this->result_ = build4 (ARRAY_REF, TREE_TYPE (TREE_TYPE (array)),
+   array, index, NULL_TREE, NULL_TREE);
+ }
+   else
+ {
+   /* Generate `array.ptr[index]'.  */
+   tree ptr = convert_expr (array, tb1, tb1->nextOf ()->pointerTo ());
+   ptr = void_okay_p (ptr);
+   this->result_ = indirect_ref (TREE_TYPE (TREE_TYPE (ptr)),
+ build_pointer_index (ptr, index));
+ }
   }
   }
 
@@ -1347,7 +1371,7 @@ public:
 if (!integer_zerop (lwr_tree))
   {
tree ptrtype = TREE_TYPE (ptr);
-   ptr = build_array_index (void_okay_p (ptr), lwr_tree);
+   ptr = build_pointer_index (void_okay_p (ptr), lwr_tree);
ptr = build_nop (ptrtype, ptr);
   }
 
diff --git a/gcc/d/intrinsics.cc b/gcc/d/intrinsics.cc
index 4222b8a0290..0f96284473f 100644
--- a/gcc/d/intrinsics.cc
+++ b/gcc/d/intrinsics.cc
@@ -306,8 +306,8 @@ expand_intrinsic_bt (intrinsic_code intrinsic, tree callexp)
   tree bitsize = fold_convert (type, TYPE_SIZE (TREE_TYPE (ptr)));
 
   /* ptr[bitnum / bitsize]  */
-  ptr = build_array_index (ptr, fold_build2 (TRUNC_DIV_EXPR, type,
-bitnum, bitsize));
+  ptr 

  1   2   3   4   5   6   >