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

2022-10-23 Thread ibuclaw--- via Gcc-patches
> On 17/10/2022 20:08 CEST Iain Buclaw  wrote:
> 
>  
> 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?
> 

Ping?

I'll apply this tomorrow, but there is a general open question about whether 
taking logic out of target headers and putting it in config.gcc is the right 
approach moving forward for non C/C++ front-ends.  This is also relevant for 
Rust, which initially put all their target support definitions in headers, and 
have since removed the entire tangled mess that created.

Regards,
Iain.


[committed] d: Merge upstream dmd d579c467c1, phobos 88aa69b14.

2022-09-27 Thread ibuclaw--- via Gcc-patches
Hi,

This patch merges the D front-end/run-time library with upstream dmd
d579c467c1, and standard library with phobos 88aa69b14.

D front-end changes:

- Throwing from contracts of `nothrow' functions has been
  deprecated, as this breaks the guarantees of `nothrow'.
- Added language support for initializing the interior pointer of
  associative arrays using `new' keyword.

Phobos changes:

- The std.digest.digest module has been removed.
- The std.xml module has been removed.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd d579c467c1.
* decl.cc (layout_struct_initializer): Update for new front-end
interface.
* expr.cc (ExprVisitor::visit (AssignExp *)): Remove lowering of array
assignments.
(ExprVisitor::visit (NewExp *)): Add new lowering of new'ing
associative arrays to an _aaNew() library call.
* runtime.def (ARRAYSETASSIGN): Remove.
(AANEW): Define.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime d579c467c1.
* libdruntime/Makefile.am (DRUNTIME_DSOURCES): Remove
rt/arrayassign.d.
* libdruntime/Makefile.in: Regenerate.
* src/MERGE: Merge upstream phobos 88aa69b14.
* src/Makefile.am (PHOBOS_DSOURCES): Remove std/digest/digest.d,
std/xml.d.
* src/Makefile.in: Regenerate.
---
 gcc/d/decl.cc |2 +-
 gcc/d/dmd/MERGE   |2 +-
 gcc/d/dmd/aggregate.d |   13 +-
 gcc/d/dmd/aggregate.h |2 +-
 gcc/d/dmd/apply.d |   25 +-
 gcc/d/dmd/arrayop.d   |   12 +-
 gcc/d/dmd/attrib.d|4 +-
 gcc/d/dmd/canthrow.d  |6 +-
 gcc/d/dmd/chkformat.d |  600 +---
 gcc/d/dmd/clone.d |6 +-
 gcc/d/dmd/cparse.d|   19 +-
 gcc/d/dmd/dcast.d |4 +-
 gcc/d/dmd/declaration.h   |4 +-
 gcc/d/dmd/dimport.d   |7 +-
 gcc/d/dmd/dinterpret.d|   12 +-
 gcc/d/dmd/dmangle.d   |   17 +
 gcc/d/dmd/doc.d   |4 +-
 gcc/d/dmd/dsymbol.d   |6 +
 gcc/d/dmd/dsymbol.h   |2 +-
 gcc/d/dmd/dsymbolsem.d|   48 +-
 gcc/d/dmd/dtemplate.d |   71 +-
 gcc/d/dmd/escape.d|5 +-
 gcc/d/dmd/expression.d|   20 +
 gcc/d/dmd/expression.h|   22 +-
 gcc/d/dmd/expressionsem.d |   92 +-
 gcc/d/dmd/func.d  |   19 +-
 gcc/d/dmd/iasmgcc.d   |8 +-
 gcc/d/dmd/id.d|2 +
 gcc/d/dmd/init.d  |1 +
 gcc/d/dmd/init.h  |1 +
 gcc/d/dmd/initsem.d   |  553 +--
 gcc/d/dmd/lexer.d |9 +-
 gcc/d/dmd/module.h|2 +-
 gcc/d/dmd/mtype.d |  649 ++--
 gcc/d/dmd/mtype.h |4 +-
 gcc/d/dmd/opover.d|9 +-
 gcc/d/dmd/parse.d |  102 +-
 gcc/d/dmd/root/object.h   |2 +-
 gcc/d/dmd/semantic3.d |   40 +-
 gcc/d/dmd/transitivevisitor.d |   73 +-
 gcc/d/dmd/typesem.d   |   18 +-
 gcc/d/expr.cc |   33 +-
 gcc/d/runtime.def |5 +-
 .../gdc.test/compilable/commontype.d  |   20 +-
 .../gdc.test/compilable/imports/cimports2a.i  |4 +
 .../gdc.test/compilable/imports/cimports2b.i  |4 +
 .../gdc.test/compilable/imports/format23327.d |7 +
 .../compilable/imports/format23327/write.d|0
 .../gdc.test/compilable/segfaultgolf.d|   50 +
 .../gdc.test/compilable/statictemplatethis.d  |   45 +
 gcc/testsuite/gdc.test/compilable/test13123.d |   38 +
 gcc/testsuite/gdc.test/compilable/test21243.d |   21 +
 gcc/testsuite/gdc.test/compilable/test21956.d |   16 +
 gcc/testsuite/gdc.test/compilable/test22674.d |   10 +
 gcc/testsuite/gdc.test/compilable/test23173.d |6 +
 gcc/testsuite/gdc.test/compilable/test23258.d |   21 +
 gcc/testsuite/gdc.test/compilable/test23306.d |7 +
 gcc/testsuite/gdc.test/compilable/test23327.d |3 +
 gcc/testsuite/gdc.test/compilable/vararg.d|   20 +
 .../gdc.test/fail_compilation/diag10169.d |2 +-
 .../gdc.test/fail_compilation/diag10783.d |2 +-
 .../gdc.test/fail_compilation/diag13528.d |  

[committed] d: Merge upstream dmd 817610b16d, phobos b578dfad9

2022-08-27 Thread ibuclaw--- via Gcc-patches
Hi,

This patch merges the D front-end with upstream dmd 817610b16d, and
standard library with phobos b578dfad9.

D front-end changes:

- Import latest bug fixes to mainline.

Phobos changes:

- Import latest bug fixes to mainline.
- std.logger module has been moved out of experimental.
- Removed std.experimental.typecons module.

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

Regards,
Iain.

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 817610b16d.
* d-ctfloat.cc (CTFloat::parse): Update for new front-end interface.
* d-lang.cc (d_parse_file): Likewise.
* expr.cc (ExprVisitor::visit (AssignExp *)): Remove handling of array
assignments to non-trivial static and dynamic arrays.
* runtime.def (ARRAYASSIGN): Remove.
(ARRAYASSIGN_L): Remove.
(ARRAYASSIGN_R): Remove.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 817610b16d.
* libdruntime/Makefile.am (DRUNTIME_DSOURCES): Add
core/internal/array/arrayassign.d.
* libdruntime/Makefile.in: Regenerate.
* src/MERGE: Merge upstream phobos b578dfad9.
* src/Makefile.am (PHOBOS_DSOURCES): Remove
std/experimental/typecons.d. Add std/logger package.
* src/Makefile.in: Regenerate.
---
 gcc/d/d-ctfloat.cc|5 +-
 gcc/d/d-lang.cc   |1 -
 gcc/d/dmd/MERGE   |2 +-
 gcc/d/dmd/README.md   |  282 +-
 gcc/d/dmd/astenums.d  |1 -
 gcc/d/dmd/canthrow.d  |4 +-
 gcc/d/dmd/common/README.md|8 +-
 gcc/d/dmd/common/outbuffer.d  |   78 +-
 gcc/d/dmd/ctfeexpr.d  |   20 +-
 gcc/d/dmd/declaration.d   |   22 +-
 gcc/d/dmd/declaration.h   |9 +-
 gcc/d/dmd/dimport.d   |   11 +-
 gcc/d/dmd/dinterpret.d|   35 +-
 gcc/d/dmd/dmacro.d|   42 +-
 gcc/d/dmd/dmodule.d   |   22 +-
 gcc/d/dmd/doc.d   |   80 +-
 gcc/d/dmd/dsymbolsem.d|  162 +-
 gcc/d/dmd/dtemplate.d |9 +-
 gcc/d/dmd/escape.d|  185 +-
 gcc/d/dmd/expression.d|2 +-
 gcc/d/dmd/expressionsem.d |   95 +-
 gcc/d/dmd/func.d  |2 -
 gcc/d/dmd/globals.d   |   47 +-
 gcc/d/dmd/globals.h   |   37 +-
 gcc/d/dmd/hdrgen.d|   16 +-
 gcc/d/dmd/id.d|3 +
 gcc/d/dmd/identifier.d|2 +-
 gcc/d/dmd/lexer.d |2 +-
 gcc/d/dmd/module.h|1 -
 gcc/d/dmd/mtype.d |   38 +-
 gcc/d/dmd/parse.d |   80 +-
 gcc/d/dmd/root/README.md  |   44 +-
 gcc/d/dmd/root/array.d|   18 +
 gcc/d/dmd/root/ctfloat.d  |2 +-
 gcc/d/dmd/root/ctfloat.h  |2 +-
 gcc/d/dmd/semantic3.d |3 -
 gcc/d/dmd/traits.d|5 +
 gcc/d/dmd/typesem.d   |5 +
 gcc/d/expr.cc |   30 +-
 gcc/d/runtime.def |9 +-
 .../gdc.test/compilable/aliasassign.d |  105 +-
 .../compilable/scope_infer_array_assign.d |   28 +
 gcc/testsuite/gdc.test/compilable/test21197.d |   25 +
 gcc/testsuite/gdc.test/compilable/uda.d   |6 +
 .../gdc.test/fail_compilation/aliasassign2.d  |   33 +
 .../gdc.test/fail_compilation/diag23295.d |   40 +
 .../gdc.test/fail_compilation/fail10968.d |   29 +-
 .../gdc.test/fail_compilation/fail14669.d |4 +-
 .../gdc.test/fail_compilation/ice8795.d   |2 +-
 .../fail_compilation/imports/import15525.d|3 +
 .../gdc.test/fail_compilation/issue12652.d|   24 +
 .../gdc.test/fail_compilation/retscope6.d |2 +
 .../gdc.test/fail_compilation/shared.d|   11 +
 .../gdc.test/fail_compilation/test15525.d |   17 +
 .../gdc.test/fail_compilation/test17423.d |3 +-
 .../gdc.test/fail_compilation/test17764.d |   21 +
 .../gdc.test/fail_compilation/test20245.d |   19 +-
 .../gdc.test/fail_compilation/test20809.d |   44 +
 .../gdc.test/fail_compilation/test23073.d |   35 +
 .../gdc.test/fail_compilation/testsemi.d  |   46 +
 gcc/testsuite/gdc.test/runnable/test20365.d   |   21 +
 gcc/testsuite/gdc.test/runnable/test20809.d   |   14 +
 libphobos/libdruntime/MERGE   |2 +-
 libphobos/libdruntime/Makefile.am |   23 +-
 

[committed] d: Merge upstream dmd 60bfa0ee7, druntime 94bd5bcb, phobos 3a1cd9a01.

2022-05-16 Thread ibuclaw--- via Gcc-patches
Hi,

Upstream dmd has now released v2.100.0, this patch merges in the
latest bug fixes since the last sync-up of the release branch, as well
as all new feature changes on development branch.

D front-end changes:

- Import dmd v2.100.0.
- Add bit fields to D, enabled via the -fpreview=bitfields switch.
- Removed the -ftransition=markdown and -frevert=markdown switches.
- Added new trait `__traits(classInstanceAlignment)' to provide the
  required data alignment for classes.
- The check for `pragma(crt_constructor)' and `pragma(crt_destructor)'
  linkage has been relaxed to allow all `void()' signatures.
- ImportC parser now recognizes the `typeof(...)' operator.

D runtime changes:

- Import druntime v2.100.0.

Phobos changes:

- Import phobos v2.100.0.
- To comply with dip1000, `std.socket.Socket` methods now accept only
  `scope' arrays.
- The `fill', `alignSize', `align2', and `align4' methods of
  `std.outbuffer.OutBuffer' have been extended to allow specifying a custom
  value when pre-filling or padding the buffer.

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 60bfa0ee7.
* dmd/VERSION: Update version to v2.100.0.
* d-builtins.cc (d_init_versions): Update for new front-end interface.
* d-codegen.cc (d_decl_context): Use resolvedLinkage to get
declaration linkage.
(build_struct_literal): Track offset in bits.
* d-gimplify.cc (d_gimplify_modify_expr): Check both operands for a
bit-field reference.
* d-lang.cc (d_handle_option): Handle -fpreview=bitfields, remove
-frevert=markdown and -ftransition=vmarkdown.
(d_post_options): Set flag_rtti and flag_exceptions if -fno-druntime
was seen on command-line.
(d_parse_file): Update for new front-end interface.
(d_type_promotes_to): Use resolvedLinkage to get declaration linkage.
* decl.cc (make_thunk): Likewise.
* expr.cc (ExprVisitor::visit (CatAssignExp *)): Remove lowering for
appending of an element or array to another array.
* lang.opt (fpreview=bitfields): New option.
(frevert=markdown): Remove.
(ftransition=vmarkdown): Remove.
* types.cc (layout_aggregate_members): Ignore anonymous fields in
total count.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 94bd5bcb.
* libdruntime/Makefile.am (ALL_DRUNTIME_INSTALL_DSOURCES): Add
$(DRUNTIME_DSOURCES_ELF).
(ALL_DRUNTIME_SOURCES): Likewise.
(DRUNTIME_DSOURCES_ELF): New variable.
* libdruntime/Makefile.in: Regenerate.
* src/MERGE: Merge upstream phobos 3a1cd9a01.
---

0001-d-Merge-upstream-dmd-60bfa0ee7-druntime-94bd5bcb-pho.patch.xz
Description: application/xz


Re: [PATCH 1/2] libphobos: fix CET for non-glibc targets

2021-12-20 Thread ibuclaw--- via Gcc-patches
> On 20/12/2021 16:41 Alex Xu (Hello71)  wrote:
> 
>  
> Excerpts from ibuc...@gdcproject.org's message of December 20, 2021 8:56 am:
> >> On 20/12/2021 01:08 Alex Xu (Hello71) via Gcc-patches 
> >>  wrote:
> >> 
> >>  
> >> On musl, linking against libphobos fails because it requires ucontext
> >> but is not explicitly linked against it. This is caused by configure
> >> assuming that it is implemented in assembly, but it is actually not
> >> implemented. This silently works on other libcs because context API does
> >> not require an external library.
> > 
> > Thanks.
> > 
> > Looks reasonable to me, also for backporting to gcc-11, which also has the 
> > same CET support.
> > 
> > Iain.
> > 
> 
> Yes, we noticed this first on gcc 11. I tested that these patches fix 
> the issue on gcc 11, and since nothing seems to have changed, I think 
> the same problem exists and will be fixed by these patches on master.
> 

Do you need me to commit this?

Iain.


Re: [PATCH 1/2] libphobos: fix CET for non-glibc targets

2021-12-20 Thread ibuclaw--- via Gcc-patches
> On 20/12/2021 01:08 Alex Xu (Hello71) via Gcc-patches 
>  wrote:
> 
>  
> On musl, linking against libphobos fails because it requires ucontext
> but is not explicitly linked against it. This is caused by configure
> assuming that it is implemented in assembly, but it is actually not
> implemented. This silently works on other libcs because context API does
> not require an external library.

Thanks.

Looks reasonable to me, also for backporting to gcc-11, which also has the same 
CET support.

Iain.


Re: [PATCH] config: Add check whether D compiler works (PR103528)

2021-12-19 Thread ibuclaw--- via Gcc-patches
> On 18/12/2021 22:30 Segher Boessenkool  wrote:
> 
>  
> On Fri, Dec 17, 2021 at 12:12:28AM +0100, Iain Buclaw wrote:
> > Hi,
> > 
> > This patch extends AC_PROG_GDC so that as well as checking for the
> > existence of a GDC compiler, also validate that it has also been built
> > with libphobos, otherwise warn or fail with the message that GDC is
> > required to build d.
> > 
> > Tested on a system running powerpcle-linux both without a D compiler,
> > and with a D compiler configured with --disable-libphobos.
> > 
> > This would also help with Solaris and Darwin ports, where support for
> > both D and runtime isn't present across all current releases. 
> > 
> > OK for mainline?
> 
> This fixes PR103739 by not building D at all anymore.  That is also a
> regression of course, but at least it doesn't break bootstrap anymore :-)
> 

Well, you don't have a working D compiler installed then!

As I mentioned in your bug report, from my testing, powerpc can be bootstrapped 
from gcc-10 or gcc-11 without issue.

Iain.


Re: [PATCH] Always default to DWARF2_DEBUG if not specified, warn about deprecated STABS

2021-10-29 Thread ibuclaw--- via Gcc-patches
> On 26/10/2021 03:28 Joseph Myers  wrote:
> 
>  
> On Mon, 25 Oct 2021, Richard Biener via Gcc-patches wrote:
> 
> > So it looks like tm_d.h is much more stripped down compared to regular
> > tm_p.h but also oddly enough config/default-d.c includes tm_d.h
> > while config/default-c.c explicitely documents itself to not do that.
> 
> I think the intent of that comment in default-c.c (which I wrote) was that 
> if a separate tm_c.h is needed, it should use its own headers, disjoint 
> from those used by tm.h.  In particular, as noted in the original patch 
> submission 
> , that 
> avoids making macros used only to define hooks visible throughout the 
> compiler.
> 
> > Is it maybe a bug that tm_d.h includes defaults.h at all?  Should
> 
> It's a bug that it includes defaults.h, and a bug that it includes 
> ${cpu_type}/${cpu_type}.h.  Any macros used only to define D hooks should 
> be in completely separate headers that aren't used elsewhere in the 
> compiler.
> 
> > "d defaults" be in a defaults-d.h instead?  If I remove the
> 
> Yes, and likewise any target-specific overrides of such macros should be 
> in a separate header, not ${cpu_type}/${cpu_type}.h.
> 

So the what default-d.c is doing, is pulling down per-CPU back-end information 
to populate the targetdm structure where there's a supported CPU, but not 
platform.  The why it is doing that was I wanted to avoid both having #ifdef's 
in the D front-end, and altering gcc/target.def.

It seems then that either all TARGET_D_ macros should be moved to 
${cpu_type}/${cpu_type}-d.h, or do one of alternatives I was trying to avoid.

Iain.


Re: [pushed] Darwin, D: Fix bootstrap when target does not support -Bstatic/dynamic.

2021-10-06 Thread ibuclaw--- via Gcc-patches
> On 05/10/2021 21:57 Iain Sandoe  wrote:
> 
>  
> This fixes a bootstrap fail because saw_static_libcxx was unused for
> targets without support for -Bstatic/dynamic.
> 
> The fix applied pushes the -static-libstdc++ back onto the command
> line, which allows a target to substitute a static version of the
> c++ standard library using specs.
> 
> tested on x86_64-darwin, pushed as bootstrap fix (it, or an alternate
> will also be needed on open branches), thanks

Thanks, it will apply cleanly on the other branches, so feel free to backport.

Iain.


Re: [committed] d: gdc driver ignores -static-libstdc++ when automatically linking libstdc++ library

2021-10-05 Thread ibuclaw--- via Gcc-patches
> On 04/10/2021 18:48 Iain Sandoe  wrote:
> 
> For targets that don’t support HAVE_LD_STATIC_DYNAMIC it would be useful
> to push the option back out, so that they can use that to substitute a static 
> version
> of the library using %:replace-outfile(-lx libx+.a%s) [ see darwin.h 
> for 
> examples. ] .. I suppose we could figure out a follow-on patch and test that 
> on
> Darwin?
> 
> so
> #else
>  … code to push the -libstdc++ out
> 
> (yes, we do have this problem also with the g++ driver… I posted a patch eons
>  ago .. but suspect it was never applied)
> 

Sure, seems reasonable to me, will follow up.

I had a look at darwin.h, and it occurs to me that you probably will be wanting 
-static-libphobos added there as well, which means moving that option to 
common.opt.

Iain.


Re: [PATCH] libiberty: d-demangle: remove parenthesis where it is not needed

2021-10-04 Thread ibuclaw--- via Gcc-patches
> On 29/09/2021 18:26 Luís Ferreira  wrote:
> 
>  
> Those parenthesis doesn't increase readability at all and this patch makes the
> source code a bit more consistent with the rest of the dereferencing
> assignments.
> 

OK, but can you write up a changelog entry for it?

Thanks,
Iain.


Re: [PATCH] libiberty: d-demangle: use switch instead of if-else

2021-10-04 Thread ibuclaw--- via Gcc-patches
> On 03/10/2021 23:55 Jeff Law via Gcc-patches  wrote:
> 
>  
> On 9/29/2021 7:08 PM, Luís Ferreira wrote:
> > This patch allows the compiler to efficiently generate jump tables instead 
> > of
> > using if-else-if.
> >
> > Signed-off-by: Luís Ferreira 
> I'm not sure this is terribly useful.  Compilers have the ability to 
> analyze the underlying code and make sensible decisions for how to 
> implement either form.   So the right metric here is does this make the 
> code cleaner/easier to understand.  With just 3 clauses it's hard (for 
> me) to make the case that it is considerably cleaner.
> 

I'd be inclined to agree here.

FAOD, I put together a quick example of what difference this patch makes.  
Other than freely reordering the conditions, the answer is nothing.

https://godbolt.org/z/nKjjv64zM

Iain.


Re: [PATCH] libiberty: prevent null dereferencing on dlang_type

2021-09-23 Thread ibuclaw--- via Gcc-patches
> On 22/09/2021 03:31 Luís Ferreira  wrote:
> 
>  
> This patch prevents dereferencing a null reference on a crafted
> malformed magled name, often causing SIGSEGV to be raised.
> 

OK, seems reasonable to me.

> Signed-off-by: Luís Ferreira 
> ---
>  libiberty/d-demangle.c  | 2 +-
>  libiberty/testsuite/d-demangle-expected | 5 -
>  2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c
> index a2152cc65518..469398261994 100644
> --- a/libiberty/d-demangle.c
> +++ b/libiberty/d-demangle.c
> @@ -875,7 +875,7 @@ dlang_type (string *decl, const char *mangled,
> struct dlang_info *info)
>szmods = string_length ();
>  
>/* Back referenced function type.  */
> -  if (*mangled == 'Q')
> +  if (mangled && *mangled == 'Q')
>   mangled = dlang_type_backref (decl, mangled, info, 1);
>else
>   mangled = dlang_function_type (decl, mangled, info);
> diff --git a/libiberty/testsuite/d-demangle-expected
> b/libiberty/testsuite/d-demangle-expected
> index c35185c3e1e3..799f4724b72e 100644
> --- a/libiberty/testsuite/d-demangle-expected
> +++ b/libiberty/testsuite/d-demangle-expected
> @@ -991,11 +991,14 @@ _D88
>  _D5__T1aZv
>  _D5__T1aZv
>  #
> ---format=dlang
>  _D00
>  _D00
>  #
>  --format=dlang
> +_D01_D
> +_D01_D
> +#
> +--format=dlang
>  _D9223372036854775817
>  _D9223372036854775817
>  #


Re: [PATCH] libiberty: prevent buffer overflow when decoding user input

2021-09-23 Thread ibuclaw--- via Gcc-patches
> On 22/09/2021 03:10 Luís Ferreira  wrote:
> 
>  
> Currently a stack/heap overflow may happen if a crafted mangle is
> maliciously used to cause denial of service, such as intentional
> crashes
> by accessing a reserved memory space.
> 

Hi,

Thanks for this.  Is there a test that could trigger this code path?

Iain.


> Signed-off-by: Luís Ferreira 
> ---
>  libiberty/d-demangle.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c
> index a2152cc65518..7ded3e2a2563 100644
> --- a/libiberty/d-demangle.c
> +++ b/libiberty/d-demangle.c
> @@ -381,7 +381,7 @@ dlang_symbol_backref (string *decl, const char
> *mangled,
>  
>/* Must point to a simple identifier.  */
>backref = dlang_number (backref, );
> -  if (backref == NULL)
> +  if (backref == NULL || strlen(backref) < len)
>  return NULL;
>  
>backref = dlang_lname (decl, backref, len);


Re: [committed] d: Fix ICE in when formating a string with '%' or '`' characters (PR98457)

2021-04-19 Thread ibuclaw--- via Gcc-patches
> On 19/04/2021 19:50 Iain Buclaw  wrote:
> 
>  
> Hi,
> 
> This patch fixes an ICE that occurred in the D front-end diagnostic
> handlers.  The percentage character was being confused for a format
> specifier in pp_format(), whilst the backtick character was confused for
> the beginning of a quoted string in expand_d_format().
> 
> Both are now properly escaped to avoid the ICE.
> 
> Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32, and
> committed to mainline.
> 
> Will also be preparing a backport to the gcc-10 and gcc-9 release
> branches, as the bug is reproducible there as well.

Attached backport, regression tested and applied to both releases/gcc-9
and releases/gcc-10 branches.

Regards,
Iain.

---
gcc/d/ChangeLog:

PR d/98457
* d-diagnostic.cc (expand_d_format): Handle escaped backticks.
(escape_d_format): New funtion.
(verror): Call escape_d_format on prefixing strings.
(vdeprecation): Likewise.

gcc/testsuite/ChangeLog:

PR d/98457
* gdc.dg/pr98457.d: New test.

(cherry picked from commit dc7d1c74ffb1cc85e67984632f581d526c783770)
---
 gcc/d/d-diagnostic.cc  | 64 +++---
 gcc/testsuite/gdc.dg/pr98457.d |  9 +
 2 files changed, 68 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/pr98457.d

diff --git a/gcc/d/d-diagnostic.cc b/gcc/d/d-diagnostic.cc
index 95a008d1b6f..47c7323aa0b 100644
--- a/gcc/d/d-diagnostic.cc
+++ b/gcc/d/d-diagnostic.cc
@@ -48,7 +48,7 @@ expand_d_format (const char *format)
 
   for (const char *p = format; *p;)
 {
-  while (*p != '\0' && *p != '%' && *p != '`')
+  while (*p != '\0' && *p != '\\' && *p != '%' && *p != '`')
{
  buf.writeByte (*p);
  p++;
@@ -57,6 +57,21 @@ expand_d_format (const char *format)
   if (*p == '\0')
break;
 
+  if (*p == '\\')
+   {
+ if (p[1] == '`')
+   {
+ /* Escaped backtick, don't expand it as a quoted string.  */
+ buf.writeByte ('`');
+ p++;;
+   }
+ else
+   buf.writeByte (*p);
+
+ p++;
+ continue;
+   }
+
   if (*p == '`')
{
  /* Text enclosed by `...` are translated as a quoted string.  */
@@ -113,6 +128,43 @@ expand_d_format (const char *format)
   return buf.extractString ();
 }
 
+/* Rewrite the format string FORMAT to deal with any characters that require
+   escaping before expand_d_format expands it.  */
+
+static char *
+escape_d_format (const char *format)
+{
+  obstack buf;
+
+  gcc_obstack_init ();
+
+  for (const char *p = format; *p; p++)
+{
+  switch (*p)
+   {
+   case '%':
+ /* Escape `%' characters so that pp_format does not confuse them
+for actual format specifiers.  */
+ obstack_1grow (, '%');
+ break;
+
+   case '`':
+ /* Escape '`' characters so that expand_d_format does not confuse them
+for a quoted string.  */
+ obstack_1grow (, '\\');
+ break;
+
+   default:
+ break;
+   }
+
+  obstack_1grow (, *p);
+}
+
+  obstack_1grow (, '\0');
+  return (char *) obstack_finish ();
+}
+
 /* Helper routine for all error routines.  Reports a diagnostic specified by
KIND at the explicit location LOC.  The message FORMAT comes from the dmd
front-end, which does not get translated by the gcc diagnostic routines.  */
@@ -177,9 +229,10 @@ verror (const Loc& loc, const char *format, va_list ap,
 
   /* Build string and emit.  */
   if (prefix2 != NULL)
-   xformat = xasprintf ("%s %s %s", prefix1, prefix2, format);
+   xformat = xasprintf ("%s %s %s", escape_d_format (prefix1),
+escape_d_format (prefix2), format);
   else if (prefix1 != NULL)
-   xformat = xasprintf ("%s %s", prefix1, format);
+   xformat = xasprintf ("%s %s", escape_d_format (prefix1), format);
   else
xformat = xasprintf ("%s", format);
 
@@ -287,9 +340,10 @@ vdeprecation (const Loc& loc, const char *format, va_list 
ap,
 
   /* Build string and emit.  */
   if (prefix2 != NULL)
-   xformat = xasprintf ("%s %s %s", prefix1, prefix2, format);
+   xformat = xasprintf ("%s %s %s", escape_d_format (prefix1),
+escape_d_format (prefix2), format);
   else if (prefix1 != NULL)
-   xformat = xasprintf ("%s %s", prefix1, format);
+   xformat = xasprintf ("%s %s", escape_d_format (prefix1), format);
   else
xformat = xasprintf ("%s", format);
 
diff --git a/gcc/testsuite/gdc.dg/pr98457.d b/gcc/testsuite/gdc.dg/pr98457.d
new file mode 100644
index 000..bc0d8af5d4a
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr98457.d
@@ -0,0 +1,9 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98457
+// { dg-do compile }
+
+void main()
+{
+writef!"%s";// { dg-error "template instance writef!\"%s\" template 
.writef. is not 

[PATCH V2][committed] d: Add TARGET_D_REGISTER_OS_TARGET_INFO

2021-04-14 Thread ibuclaw--- via Gcc-patches
> On 05/04/2021 21:43 Iain Buclaw  wrote:
> 
>  
> Hi,
> 
> This patch adds TARGET_D_REGISTER_OS_TARGET_INFO as a new D front-end
> target hook, implementing `__traits(getTargetInfo, "objectFormat")' for
> all targets that have D support files.
> 
> This trait was added earlier in the front-end as a stub, however the
> target-specific implementation was left out until now.
> 
> Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32, and
> tested on x86_64-darwin for getting the libphobos port set-up.
> 
> Any issues with this, or OK to commit?
> 

After doing some testing on a wide spread of targets, this is not the most
fitting place to have the result of `__traits(getTargetInfo, "objectFormat")' 
set.  So have removed its implementation, but kept the hook in as it will be
useful for Darwin targets later.

Implementation of objectFormat will be done in a follow-up.

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

Regards,
Iain.

---
gcc/ChangeLog:

* doc/tm.texi: Regenerate.
* doc/tm.texi.in (D language and ABI): Add @hook for
TARGET_D_REGISTER_OS_TARGET_INFO.

gcc/d/ChangeLog:

* d-target.cc (Target::_init): Call new targetdm hook to register OS
specific target info keys.
* d-target.def (d_register_os_target_info): New hook.
---
 gcc/d/d-target.cc  | 1 +
 gcc/d/d-target.def | 8 
 gcc/doc/tm.texi| 5 +
 gcc/doc/tm.texi.in | 2 ++
 4 files changed, 16 insertions(+)

diff --git a/gcc/d/d-target.cc b/gcc/d/d-target.cc
index d576b74af1c..be354d9f1f0 100644
--- a/gcc/d/d-target.cc
+++ b/gcc/d/d-target.cc
@@ -199,6 +199,7 @@ Target::_init (const Param &)
   /* Initialize target info tables, the keys required by the language are added
  last, so that the OS and CPU handlers can override.  */
   targetdm.d_register_cpu_target_info ();
+  targetdm.d_register_os_target_info ();
   d_add_target_info_handlers (d_language_target_info);
 }
 
diff --git a/gcc/d/d-target.def b/gcc/d/d-target.def
index cd0397c1577..aa6bf55e6e6 100644
--- a/gcc/d/d-target.def
+++ b/gcc/d/d-target.def
@@ -58,6 +58,14 @@ describing the requested target information.",
  void, (void),
  hook_void_void)
 
+/* getTargetInfo keys relating to the target OS.  */
+DEFHOOK
+(d_register_os_target_info,
+ "Same as @code{TARGET_D_CPU_TARGET_INFO}, but is used for keys relating to\n\
+the target operating system.",
+ void, (void),
+ hook_void_void)
+
 /* ModuleInfo section name and brackets.  */
 DEFHOOKPOD
 (d_minfo_section,
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 6201df9a67d..97c8eebcd6f 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -10817,6 +10817,11 @@ added by this hook are made available at compile time 
by the
 describing the requested target information.
 @end deftypefn
 
+@deftypefn {D Target Hook} void TARGET_D_REGISTER_OS_TARGET_INFO (void)
+Same as @code{TARGET_D_CPU_TARGET_INFO}, but is used for keys relating to
+the target operating system.
+@end deftypefn
+
 @deftypevr {D Target Hook} {const char *} TARGET_D_MINFO_SECTION
 Contains the name of the section in which module info references should be
 placed.  This section is expected to be bracketed by two symbols to indicate
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index bde57585b03..e2d49ee9f57 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -7359,6 +7359,8 @@ floating-point support; they are not included in this 
mechanism.
 
 @hook TARGET_D_REGISTER_CPU_TARGET_INFO
 
+@hook TARGET_D_REGISTER_OS_TARGET_INFO
+
 @hook TARGET_D_MINFO_SECTION
 
 @hook TARGET_D_MINFO_START_NAME
-- 
2.27.0


Re: [PATCH 2/3] d: Add TARGET_D_REGISTER_CPU_TARGET_INFO

2021-04-14 Thread ibuclaw--- via Gcc-patches


> On 05/04/2021 21:43 Iain Buclaw  wrote:
> 
>  
> Hi,
> 
> This patch adds TARGET_D_REGISTER_CPU_TARGET_INFO as a new D front-end
> target hook, implementing `__traits(getTargetInfo, "floatAbi")' for all
> targets that have D support files.
> 
> This trait was added earlier in the front-end as a stub, however the
> target-specific implementation was left out until now.
> 
> Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32, and
> tested on x86_64-darwin for getting the libphobos port set-up.
> 
> Any issues with this, or OK to commit?
> 

As I've seen no objections, this has been committed to mainline.

Regards,
Iain.


Re: [PATCH 1/3] d: Add TARGET_D_HAS_STDCALL_CONVENTION

2021-04-14 Thread ibuclaw--- via Gcc-patches
> On 05/04/2021 21:43 Iain Buclaw  wrote:
> 
>  
> Hi,
> 
> This patch adds TARGET_D_HAS_STDCALL_CONVENTION as a new D front-end
> target hook.  It replaces the use of the D front-end `is64bit' parameter
> in determining whether to insert the "stdcall" function attribute.
> 
> It is also used to determine whether `extern(System)' should be the same
> as `extern(Windows)' in the implementation of Target::systemLinkage.
> 
> Both are prerequesites for being able to compile libphobos on MinGW.
> 
> Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32, and
> tested on x86_64-w64-mingw64 for getting the libphobos port set-up.
> 
> Any issues with the implementation, or OK to commit?
> 

As I've seen no objections, this has been committed to mainline.

Regards,
Iain.


Re: [PATCH] d: Add windows support for D compiler (PR91595)

2021-03-26 Thread ibuclaw--- via Gcc-patches
> On 21/03/2021 12:58 Iain Buclaw  wrote:
> 
>  
> Hi,
> 
> This patch adds necessary backend support for MinGW/Cygwin targets so
> that all relevant predefined version conditions are available, a
> prerequesite for building most parts of libphobos.
> 

After some more testing done building libphobos on MinGW, it was identified
that the version identifiers CRuntime_Microsoft and CRuntime_Newlib need to be
present, as well as definitions for the MINFO section support code.

Bootstrapped on x86_64-w64-mingw64, and committed to mainline.

Regards,
Iain.

---
gcc/ChangeLog:

PR d/91595
* config.gcc (*-*-cygwin*): Add winnt-d.o
(*-*-mingw*): Likewise.
* config/i386/cygwin.h (EXTRA_TARGET_D_OS_VERSIONS): New macro.
* config/i386/mingw32.h (EXTRA_TARGET_D_OS_VERSIONS): Likewise.
* config/i386/t-cygming: Add winnt-d.o.
* config/i386/winnt-d.c: New file.
---
 gcc/config.gcc|  6 +
 gcc/config/i386/cygwin.h  |  9 +++
 gcc/config/i386/mingw32.h | 12 +
 gcc/config/i386/t-cygming |  4 +++
 gcc/config/i386/winnt-d.c | 56 +++
 5 files changed, 87 insertions(+)
 create mode 100644 gcc/config/i386/winnt-d.c

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 34e732d861b..997a9f61a5c 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -2123,6 +2123,8 @@ 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"
+   target_has_targetdm="yes"
if test x$enable_threads = xyes; then
thread_file='posix'
fi
@@ -2139,6 +2141,8 @@ x86_64-*-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"
+   target_has_targetdm="yes"
if test x$enable_threads = xyes; then
thread_file='posix'
fi
@@ -2151,7 +2155,9 @@ i[34567]86-*-mingw* | x86_64-*-mingw*)
xm_file=i386/xm-mingw32.h
c_target_objs="${c_target_objs} winnt-c.o"
cxx_target_objs="${cxx_target_objs} winnt-c.o"
+   d_target_objs="${d_target_objs} winnt-d.o"
target_has_targetcm="yes"
+   target_has_targetdm="yes"
case ${target} in
x86_64-*-* | *-w64-*)
need_64bit_isa=yes
diff --git a/gcc/config/i386/cygwin.h b/gcc/config/i386/cygwin.h
index db0a3cc0b35..71fb6135c2c 100644
--- a/gcc/config/i386/cygwin.h
+++ b/gcc/config/i386/cygwin.h
@@ -29,6 +29,15 @@ along with GCC; see the file COPYING3.  If not see
 }  \
   while (0)
 
+#define EXTRA_TARGET_D_OS_VERSIONS()   \
+  do   \
+{  \
+  builtin_version ("Cygwin");  \
+  builtin_version ("Posix");   \
+  builtin_version ("CRuntime_Newlib"); \
+}  \
+  while (0)
+
 #undef CPP_SPEC
 #define CPP_SPEC "%(cpp_cpu) %{posix:-D_POSIX_SOURCE} \
   %{!ansi:-Dunix} \
diff --git a/gcc/config/i386/mingw32.h b/gcc/config/i386/mingw32.h
index 1a6a3a07ca6..36e7bae5e1b 100644
--- a/gcc/config/i386/mingw32.h
+++ b/gcc/config/i386/mingw32.h
@@ -53,6 +53,18 @@ along with GCC; see the file COPYING3.  If not see
 }  \
   while (0)
 
+#define EXTRA_TARGET_D_OS_VERSIONS()   \
+  do   \
+{  \
+  builtin_version ("MinGW");   \
+  if (TARGET_64BIT && ix86_abi == MS_ABI)  \
+   builtin_version ("Win64");  \
+  else if (!TARGET_64BIT)  \
+   builtin_version ("Win32");  \
+  builtin_version ("CRuntime_Microsoft");  \
+}  \
+  while (0)
+
 #ifndef TARGET_USE_PTHREAD_BY_DEFAULT
 #define SPEC_PTHREAD1 "pthread"
 #define SPEC_PTHREAD2 "!no-pthread"
diff --git a/gcc/config/i386/t-cygming b/gcc/config/i386/t-cygming
index 7ccbb84adad..38e2f0be237 100644
--- a/gcc/config/i386/t-cygming
+++ b/gcc/config/i386/t-cygming
@@ -39,6 +39,10 @@ winnt-stubs.o: $(srcdir)/config/i386/winnt-stubs.c 
$(CONFIG_H) $(SYSTEM_H) coret
$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
$(srcdir)/config/i386/winnt-stubs.c
 
+winnt-d.o: