Re: [PATCH 3/3] [D] libiberty: Prefix mangled D initializer symbols

2017-05-28 Thread Iain Buclaw
On 26 May 2017 at 20:20, Ian Lance Taylor  wrote:
> On Fri, May 26, 2017 at 9:08 AM, Iain Buclaw  wrote:
>> This is instead of adding a `.init$' postfix, which gave it a
>> property-style name.  My rationale being that "initializer for symbol"
>> is much more informative when inspecting D runtime type information in
>> gdb, which is the only place where you would encounter references to
>> this compiler-generated symbol.
>
> This is OK.
>
> Thanks.
>
> Ian

Thanks, have committed this to trunk.

Regards
Iain


[PATCH] Fix expand_builtin_atomic_fetch_op for pre-op (PR80902)

2017-05-28 Thread Segher Boessenkool
__atomic_add_fetch adds a value to some memory, and returns the result.
If there is no direct support for this, expand_builtin_atomic_fetch_op
is asked to implement this as __atomic_fetch_add (which returns the
original value of the mem), followed by the addition.  Now, the
__atomic_add_fetch could have been a tail call, but we shouldn't
perform the __atomic_fetch_add as a tail call: following code would
not be executed, and in fact thrown away because there is a barrier
after tail calls.

This fixes it.

Tested on powerpc64-linux {-m32,-m64}.  Is this okay for trunk?


Segher


2017-05-28  Segher Boessenkool  

PR middle-end/80902
* builtins.c (expand_builtin_atomic_fetch_op): If emitting code after
a call, force the call to not be a tail call.

---
 gcc/builtins.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 4f6c9c4..3a70693 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -6079,6 +6079,12 @@ expand_builtin_atomic_fetch_op (machine_mode mode, tree 
exp, rtx target,
   gcc_assert (TREE_OPERAND (addr, 0) == fndecl);
   TREE_OPERAND (addr, 0) = builtin_decl_explicit (ext_call);
 
+  /* If we will emit code after the call, the call can not be a tail call.
+ If it is emitted as a tail call, a barrier is emitted after it, and
+ then all trailing code is removed.  */
+  if (!ignore)
+CALL_EXPR_TAILCALL (exp) = 0;
+
   /* Expand the call here so we can emit trailing code.  */
   ret = expand_call (exp, target, ignore);
 
-- 
1.9.3



Re: [PATCH] Add header implementation of std::to_string for integers (PR libstdc++/71108)

2017-05-28 Thread Daniel Krügler
2017-05-27 23:46 GMT+02:00 Adrian Wielgosik :
> Currently std::to_string takes a fairly long trip to vs(n/w)printf. The patch
> implements int-to-string formatting in header, to improve function 
> performance.

The existing specification of std::to_string is specified in a way
that would make this replacement implementation non-conforming, IMO.
Reason for this is, that the C++ specification says:

"Each function returns a string object holding the character
representation of the value of
its argument that would be generated by calling sprintf(buf, fmt, val)
with a format specifier of
"%d", "%u", "%ld", "%lu", "%lld", "%llu", "%f", "%f", or "%Lf",
respectively, where buf designates
an internal character buffer of sufficient size."

The explicit reference to sprintf without specification of any locale
means that the outcome should depend on the currently set locale, so a
conforming program could notice the difference by either calling
std::setlocale.

This is different for the new "primitive numeric output" functions
(std::to_chars, std::from_chars), which explicitly require a
conversion as if the "C" locale would be active.

- Daniel


Re: [libcc1] add support for C++

2017-05-28 Thread Alexandre Oliva
On May 26, 2017, Richard Biener  wrote:

> On Mon, Jan 30, 2017 at 11:31 PM, Alexandre Oliva  wrote:
>   bool oracle_looked_up;

> that increased lang_identifier size by 8 bytes while there's "plenty" of free
> bits in tree_base (bonus point if you can reap a lang_flag).

Oh, no!  I put it there temporarily, very early in the project, because
I couldn't find a better place (I looked for available bits elsewhere,
and I recall I couldn't find any); at the end we moved to a hash_set
(see query_oracle below), that makes a lot more sense since the bit is
only used when libcc1 is in use.  But I accidentally left in place the
data member I'd added before, completely unused :-(  Ouch!

>> +static inline void
>> +query_oracle (tree name)
>> +{
>> +  if (!cp_binding_oracle)
>> +return;
>> +
>> +  /* LOOKED_UP holds the set of identifiers that we have already
>> + looked up with the oracle.  */
>> +  static hash_set looked_up;
>> +  if (looked_up.add (name))
>> +return;
>> +
>> +  cp_binding_oracle (CP_ORACLE_IDENTIFIER, name);
>> +}

I apologize for making G++ 7.1 plain waste memory on it.

I'll test and install the obvious fix, trunk and branch, though I might
be a bit slow in getting to it: Richard Stallman will be in town this
week, at my place, and we have a busy schedule, so my computer time and
attention will be severely limited.  There's no rush AFAIK, and I'll get
the fix in no later than next weekend, but of course I won't mind at all
if someone else beats me to it.

Thanks for catching this!

-- 
Alexandre Oliva, freedom fighterhttp://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer


[patch, fortran, committed] Fix size of matmul calculation for a special case

2017-05-28 Thread Thomas Koenig

Hello world,

I have just committed as obvious a patch fixing a wrong
calculation for allocating the size of a return variable
in inline matmul (PR 80904).  I will backport to the
other affected branches in the near future.

Regards

Thomas

2017-05-28  Thomas Koenig  

* frontend-passes.c (matmul_lhs_realloc):  Correct
allocation size for case A1B2.

2017-05-28  Thomas Koenig  

* gfortran.dg/matmul_bounds_12.f90:  New test.
Index: frontend-passes.c
===
--- frontend-passes.c	(Revision 248467)
+++ frontend-passes.c	(Arbeitskopie)
@@ -2447,7 +2447,7 @@ matmul_lhs_realloc (gfc_expr *c, gfc_expr *a, gfc_
   break;
 
 case A1B2:
-  ar->start[0] = get_array_inq_function (GFC_ISYM_SIZE, b, 1);
+  ar->start[0] = get_array_inq_function (GFC_ISYM_SIZE, b, 2);
   cond = build_logical_expr (INTRINSIC_NE,
  get_array_inq_function (GFC_ISYM_SIZE, c, 1),
  get_array_inq_function (GFC_ISYM_SIZE, b, 2));


Re: [PATCH] add more detail to -Wconversion and -Woverflow (PR 80731)

2017-05-28 Thread Andreas Schwab
On Mai 17 2017, Martin Sebor  wrote:

> diff --git a/gcc/testsuite/g++.dg/ext/utf16-4.C 
> b/gcc/testsuite/g++.dg/ext/utf16-4.C
> index e8d6531..2c4377c 100644
> --- a/gcc/testsuite/g++.dg/ext/utf16-4.C
> +++ b/gcc/testsuite/g++.dg/ext/utf16-4.C
> @@ -10,9 +10,9 @@ const static char16_t   c2 = u'\U00064321'; /* { 
> dg-warning "constant too long" }
>  const static char16_tc3 = 'a';
>  const static char16_tc4 = U'a';
>  const static char16_tc5 = U'\u2029';
> -const static char16_tc6 = U'\U00064321'; /* { dg-warning 
> "implicitly truncated" } */
> +const static char16_tc6 = U'\U00064321'; /* { dg-warning 
> "conversion from .char32_t. to .char16_t. changes value from .410401. to 
> .17185." } */
>  const static char16_tc7 = L'a';
>  const static char16_tc8 = L'\u2029';
> -const static char16_tc9 = L'\U00064321'; /* { dg-warning 
> "implicitly truncated" "" { target { 4byte_wchar_t } } } */
> +const static char16_tc9 = L'\U00064321'; /* { dg-warning 
> "unsigned conversion from .wchar_t. to .char16_t. changes value from .410401. 
> to .17185." "" { target { 4byte_wchar_t } } } */

That fails on aarch64.

FAIL: g++.dg/ext/utf16-4.C  -std=c++11  (test for warnings, line 16)
FAIL: g++.dg/ext/utf16-4.C  -std=c++11 (test for excess errors)
Excess errors:
/opt/gcc/gcc-20170528/gcc/testsuite/g++.dg/ext/utf16-4.C:16:28: warning: 
conversion from 'wchar_t' to 'char16_t' changes value from '410401' to '17185' 
[-Woverflow]

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Re: MinGW compilation warnings in libiberty's xstrndup.c

2017-05-28 Thread Eli Zaretskii
> From: DJ Delorie 
> Cc: gcc-patches@gcc.gnu.org, gdb-patc...@sourceware.org
> Date: Fri, 26 May 2017 17:34:12 -0400
> 
> 
> Please try this patch:

Seems to work fine, thanks.


Fix libgfortran FMA3/FMA4 tests

2017-05-28 Thread Rainer Orth
The recent libgfortran AVX128 patch broke bootstrap on Solaris/x86 with
the native assembler.  libgfortran compilation fails like this:

Assembler: matmulavx128_r8.c
"/var/tmp//cc51E6lb.s", line 5811 : Illegal mnemonic
Near line: "vfmaddpd%xmm0, (%edi), %xmm5, %xmm7"
"/var/tmp//cc51E6lb.s", line 5811 : Syntax error
Near line: "vfmaddpd%xmm0, (%edi), %xmm5, %xmm7"
[...]
Too many errors - Goodbye
make[3]: *** [Makefile:4663: matmulavx128_r8.lo] Error 1

and several more.

It turns out that the FMA3 and FMA4 tests in acinclude.m4 don't test
what they claim to:  if one compiles the test program

float
flt_mul_add (float a, float b, float c)
{
return __builtin_fmaf (a, b, c);
}

with -O2 -mfma -mno-fma4 (FMA3) resp. -O2 -mfma4 -mno-fma (FMA4), both
boil done to

flt_mul_add:
jmp fmaf

so the test always succeeds.

The following patch fixes this by instead using the tests from
gcc.target/i386/i386.exp.  While the FMA3 test still passes with
/bin/as, the FMA4 one fails, avoiding the breakage.

Bootstrapped on i386-pc-solaris2.12 with both as and gas without
regressions.

Ok for mainline?

Rainer

-- 
-
Rainer Orth, Center for Biotechnology, Bielefeld University


2017-05-28  Rainer Orth  

* acinclude.m4 (LIBGFOR_CHECK_FMA3): Use test from
check_effective_target_fma in gcc.target/i386/i386.exp.
(LIBGFOR_CHECK_FMA4): Use test from check_effective_target_fma4.
* configure: Regenerate.

# HG changeset patch
# Parent  743cb41a74816da876222b6da785fdf5f3fc2efb
Fix libgfortran FMA3/FMA4 tests

diff --git a/libgfortran/acinclude.m4 b/libgfortran/acinclude.m4
--- a/libgfortran/acinclude.m4
+++ b/libgfortran/acinclude.m4
@@ -459,10 +459,13 @@ AC_DEFUN([LIBGFOR_CHECK_FMA3], [
   ac_save_CFLAGS="$CFLAGS"
   CFLAGS="-O2 -mfma -mno-fma4"
   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
-	float
-	flt_mul_add (float a, float b, float c)
+typedef float __m128 __attribute__ ((__vector_size__ (16)));
+	typedef float __v4sf __attribute__ ((__vector_size__ (16)));
+	__m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
 	{
-		return __builtin_fmaf (a, b, c);
+	return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
+		 (__v4sf)__B,
+		 (__v4sf)__C);
 }]], [[]])],
 	AC_DEFINE(HAVE_FMA3, 1,
 	[Define if FMA3 instructions can be compiled.]),
@@ -476,10 +479,13 @@ AC_DEFUN([LIBGFOR_CHECK_FMA4], [
   ac_save_CFLAGS="$CFLAGS"
   CFLAGS="-O2 -mfma4 -mno-fma"
   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
-	float
-	flt_mul_add (float a, float b, float c)
+typedef float __m128 __attribute__ ((__vector_size__ (16)));
+	typedef float __v4sf __attribute__ ((__vector_size__ (16)));
+	__m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
 	{
-		return __builtin_fmaf (a, b, c);
+	return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
+		 (__v4sf)__B,
+		 (__v4sf)__C);
 }]], [[]])],
 	AC_DEFINE(HAVE_FMA4, 1,
 	[Define if FMA4 instructions can be compiled.]),


Re: Fix libgfortran FMA3/FMA4 tests

2017-05-28 Thread Thomas Koenig

Hi Rainer,


It turns out that the FMA3 and FMA4 tests in acinclude.m4 don't test
what they claim to:  if one compiles the test program

float
flt_mul_add (float a, float b, float c)
{
return __builtin_fmaf (a, b, c);
}

with -O2 -mfma -mno-fma4 (FMA3) resp. -O2 -mfma4 -mno-fma (FMA4), both
boil done to

flt_mul_add:
 jmp fmaf

so the test always succeeds.

The following patch fixes this by instead using the tests from
gcc.target/i386/i386.exp.  While the FMA3 test still passes with
/bin/as, the FMA4 one fails, avoiding the breakage.

Bootstrapped on i386-pc-solaris2.12 with both as and gas without
regressions.

Ok for mainline?


OK, and thanks a lot for the patch!

I hope this is the last fallout from the AMD patchess...

Regards

Thomas



Re: [PATCH] Add header implementation of std::to_string for integers (PR libstdc++/71108)

2017-05-28 Thread Adrian Wielgosik
> so a conforming program could notice the difference by either calling 
> std::setlocale.

Unless I missed or misunderstood something about locale (please let me
know if I did), I don't know of any way for locale to affect %d and
its integer friends.


Re: [PATCH] Add header implementation of std::to_string for integers (PR libstdc++/71108)

2017-05-28 Thread Daniel Krügler
2017-05-28 21:38 GMT+02:00 Adrian Wielgosik :
>> so a conforming program could notice the difference by either calling 
>> std::setlocale.
>
> Unless I missed or misunderstood something about locale (please let me
> know if I did), I don't know of any way for locale to affect %d and
> its integer friends.

Hmmh, rethinking about it, I agree that I also cannot see a possible
effect here for the integer types. Initially I was alarmed by the fact
alone that the current wording is basically local-depending, but now I
agree that in this case I cannot find how a conforming program could
observe the difference. Thanks for remaining stubbornly ;-)

- Daniel


Re: Default std::vector default and move constructor

2017-05-28 Thread François Dumont

On 27/05/2017 13:14, Jonathan Wakely wrote:

On 26/05/17 23:13 +0200, François Dumont wrote:

On 25/05/2017 18:28, Jonathan Wakely wrote:

On 15/05/17 19:57 +0200, François Dumont wrote:

Hi

  Following what I have started on RbTree here is a patch to 
default implementation of default and move constructors on 
std::vector.


  As in _Rb_tree_impl the default allocator is not value 
initialized anymore. We could add a small helper type arround the 
allocator to do this value initialization per default. Should I do 
so ?


It's required to be value-initialized, so if your patch changes that
then it's a problem.

Did we decide it's OK to do that for RB-trees? Did we actually discuss
that part of the r243379 changes?


I remember a message pointing this issue but after the commit AFAIR. 
I thought it was from Tim but I can't find it on the archive.


What is the rational of this requirement ? I started working on a 
type to do the allocator value initialization if there is no default 
constructor but it seems quite complicated to do so. It is quite sad 
that we can't fully benefit from this nice C++11 feature just because 
of this requirement. If there is any initialization needed it doesn't 
sound complicated to provide a default constructor.


The standard says that the default constructor is:

 vector() : vector(Allocator()) { }

That value-initializes the allocator. If the allocator type behaves
differently for value-init and default-init (e.g. it has data members
that are left uninitialized by default-init) then the difference
matters. If you change the code so it only does default-init of the
allocator then you will introduce an observable difference.

I don't see any requirement that a DefaultConstructible allocator
cannot leave members uninitialized, so that means the standard
requires default construction of vector to value-init the
allocator. Not default-init.


Sure but like freedom which stop where start others' freedom so does 
those requirements :-). Because the Standard says that an allocator will 
be value-init when there is no default-init it makes usage of the C++11 
default constructor more complicated.


But as it is unavoidable here is a type I tried to work on to keep 
current implementations as long as we inherit from 
__alloc_value_initializer.


I don't like it myself but I propose just in case you are interested.

Otherwise I am also going to rework my patch to keep this initialization.

François

diff --git a/libstdc++-v3/include/bits/allocator.h b/libstdc++-v3/include/bits/allocator.h
index 2081386..9e8afed 100644
--- a/libstdc++-v3/include/bits/allocator.h
+++ b/libstdc++-v3/include/bits/allocator.h
@@ -241,6 +241,52 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 };
 #endif
 
+  template
+struct __alloc_value_initializer;
+
+  template
+struct __alloc_value_initializer<_Alloc, true> : public _Alloc
+{
+  // Explicit value initialization.
+  __alloc_value_initializer() _GLIBCXX_USE_NOEXCEPT
+	: _Alloc()
+  { }
+
+  __alloc_value_initializer(const _Alloc& __other)
+	_GLIBCXX_NOEXCEPT_IF( noexcept(_Alloc(__other)) )
+	: _Alloc(__other)
+  { }
+
+#if __cplusplus >= 201103L
+  __alloc_value_initializer(_Alloc&& __other)
+	noexcept( noexcept(_Alloc(std::move(__other))) )
+	: _Alloc(std::move(__other))
+  { }
+#endif
+};
+
+  template
+struct __alloc_value_initializer<_Alloc, false> : public _Alloc
+{
+#if __cplusplus >= 201103L
+  __alloc_value_initializer() = default;
+
+  __alloc_value_initializer(_Alloc&& __other)
+	noexcept( noexcept(_Alloc(std::move(__other))) )
+	: _Alloc(std::move(__other))
+  { }
+#else
+  __alloc_value_initializer() throw()
+  { }
+#endif
+
+  __alloc_value_initializer(const _Alloc& __other)
+	_GLIBCXX_NOEXCEPT_IF(noexcept(_Alloc(__other)))
+	: _Alloc(__other)
+  { }
+};
+
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
 


Re: [PATCH] Add header implementation of std::to_string for integers (PR libstdc++/71108)

2017-05-28 Thread Tim Song
libstdc++ has a to_chars implementation already. Assuming that the
locale issue isn't a problem, can that be reused?


Re: [PATCH 0/13] D: Submission of D Front End

2017-05-28 Thread Iain Buclaw
On 28 May 2017 at 15:30, Iain Buclaw  wrote:
>
> ---
>
> Iain Buclaw (13):
>   001 - The front-end (DMD) language implementation and license.
>   002 - The front-end (GDC) implementation.
>   003 - The front-end (GDC) changelogs (here be dragons).
>   004 - The front-end (GDC) config, makefile, and manpages.
>   005 - GCC configuration file changes and documentation.
>   006 - Add D language support to GCC proper.
>   007 - Add D language support to GCC targets.
>   008 - D2 Testsuite tests.
>   009 - D2 Testsuite Dejagnu files.
>   010 - The D runtime library and license.
>   011 - GCC builtins and runtime support (part of D runtime)
>   012 - The Phobos runtime library and license.
>   013 - Phobos config, makefiles, and testsuite.
>

Well, it looks like this will need breaking down even more.  The GDC
parts should be OK, it's just the upstream bits that are far to big to
attach here.

Regards
Iain.


Re: [PATCH] Add header implementation of std::to_string for integers (PR libstdc++/71108)

2017-05-28 Thread Ville Voutilainen
On 28 May 2017 at 23:29, Tim Song  wrote:
> libstdc++ has a to_chars implementation already. Assuming that the
> locale issue isn't a problem, can that be reused?

Maybe, but that implementation hasn't landed yet. The patch has been circulated
but I don't see it having been committed.


Re: [PATCH 1/13] D: The front-end (DMD) language implementation and license.

2017-05-28 Thread Iain Buclaw
Split 4/4

Gzipped because of size limitations.

I feel like I should probably put off submitting the libraries, as
they are be far, far, far bigger.  Instead only submitting the GDC
parts for now, and looking at the others when I get back.

---


[PATCH 3/13] D: The front-end (GDC) changelogs.

2017-05-28 Thread Iain Buclaw
This patch just includes all changelogs for the D front-end (GDC),
going back to the dawn of time itself.

Change logs for the DMD front-end and libraries are kept on the dlang site.

Regards
Iain

---


03-d-frontend-changelogs.patch.xz
Description: application/xz


[PATCH 4/13] D: The front-end (GDC) config, makefile, and manpages.

2017-05-28 Thread Iain Buclaw
This patch adds the D frontend language configure make files, as
described on the anatomy of a language front-end.

---
diff --git a/gcc/d/Make-lang.in b/gcc/d/Make-lang.in
new file mode 100644
index 000..9618f5da8c0
--- /dev/null
+++ b/gcc/d/Make-lang.in
@@ -0,0 +1,274 @@
+# Make-lang.in -- Top level -*- makefile -*- fragment for the D frontend.
+# Copyright (C) 2006-2017 Free Software Foundation, Inc.
+
+# 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 file provides the language dependent support in the main Makefile.
+
+# Installation name.
+
+D_INSTALL_NAME = $(shell echo gdc|sed '$(program_transform_name)')
+D_TARGET_INSTALL_NAME = $(target_noncanonical)-$(shell echo gdc|sed '$(program_transform_name)')
+
+# Name of phobos library
+D_LIBPHOBOS = -DLIBPHOBOS=\"gphobos\"
+
+# The name for selecting d in LANGUAGES.
+d: cc1d$(exeext)
+
+# Tell GNU make to ignore these if they exist.
+.PHONY: d
+
+# Create the compiler driver for D.
+CFLAGS-d/d-spec.o += $(DRIVER_DEFINES) $(D_LIBPHOBOS)
+
+GDC_OBJS = $(GCC_OBJS) d/d-spec.o
+gdc$(exeext): $(GDC_OBJS) $(EXTRA_GCC_OBJS) libcommon-target.a $(LIBDEPS)
+	+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
+	  $(GDC_OBJS) $(EXTRA_GCC_OBJS) libcommon-target.a \
+	  $(EXTRA_GCC_LIBS) $(LIBS)
+
+# Create a version of the gdc driver which calls the cross-compiler.
+gdc-cross$(exeext): gdc$(exeext)
+	-rm -f gdc-cross$(exeext)
+	cp gdc$(exeext) gdc-cross$(exeext)
+
+# Filter out pedantic and virtual overload warnings.
+d-warn = $(filter-out -pedantic -Woverloaded-virtual, $(STRICT_WARN))
+
+# D Frontend has slightly relaxed warnings compared to rest of GDC.
+DMD_WARN_CXXFLAGS = -Wno-deprecated -Wstrict-aliasing -Wuninitialized
+DMD_COMPILE = $(subst $(WARN_CXXFLAGS), $(DMD_WARN_CXXFLAGS), $(COMPILE))
+DMDGEN_COMPILE = $(subst $(COMPILER), $(COMPILER_FOR_BUILD), $(DMD_COMPILE))
+
+# D Frontend object files.
+D_FRONTEND_OBJS = \
+	d/argtypes.o d/aav.o d/access.o d/aliasthis.o d/apply.o d/arrayop.o \
+	d/attrib.o d/canthrow.o d/checkedint.o d/clone.o d/cond.o \
+	d/constfold.o d/cppmangle.o d/ctfeexpr.o d/dcast.o d/dclass.o \
+	d/declaration.o d/delegatize.o d/denum.o d/dimport.o d/dinterpret.o \
+	d/dmacro.o d/dmangle.o d/dmodule.o d/doc.o d/dscope.o d/dstruct.o \
+	d/dsymbol.o d/dtemplate.o d/dversion.o d/entity.o d/escape.o \
+	d/expression.o d/file.o d/filename.o d/func.o d/hdrgen.o \
+	d/identifier.o d/imphint.o d/init.o d/inline.o d/intrange.o d/json.o \
+	d/lexer.o d/mtype.o d/nogc.o d/newdelete.o d/nspace.o d/objc.o \
+	d/opover.o d/optimize.o d/outbuffer.o d/parse.o d/rmem.o \
+	d/rootobject.o d/sapply.o d/sideeffect.o d/speller.o d/statement.o \
+	d/statementsem.o d/staticassert.o d/stringtable.o d/tokens.o d/traits.o \
+	d/unittests.o d/utf.o d/utils.o
+
+# D Frontend generated files.
+D_GENERATED_SRCS = d/id.c d/id.h d/impcnvtab.c
+D_GENERATED_OBJS = d/id.o d/impcnvtab.o
+
+# Language-specific object files for D.
+D_OBJS = \
+	d/d-attribs.o d/d-builtins.o d/d-codegen.o d/d-convert.o \
+	d/d-diagnostic.o d/d-frontend.o d/d-incpath.o d/d-lang.o \
+	d/d-longdouble.o d/d-target.o d/decl.o d/expr.o d/imports.o \
+	d/intrinsics.o d/modules.o d/runtime.o d/toir.o d/typeinfo.o d/types.o
+
+# All language-specific object files for D.
+D_ALL_OBJS = $(D_FRONTEND_OBJS) $(D_GENERATED_OBJS) $(D_OBJS)
+
+d_OBJS = $(D_ALL_OBJS) d/d-spec.o
+
+cc1d$(exeext): $(D_ALL_OBJS) attribs.o $(BACKEND) $(LIBDEPS)
+	+$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
+		$(D_ALL_OBJS) attribs.o $(BACKEND) $(LIBS) $(BACKENDLIBS)
+
+# Documentation.
+
+D_TEXI_FILES = \
+	d/gdc.texi \
+	$(gcc_docdir)/include/fdl.texi \
+	$(gcc_docdir)/include/gpl_v3.texi \
+	$(gcc_docdir)/include/gcc-common.texi \
+	gcc-vers.texi
+
+doc/gdc.info: $(D_TEXI_FILES)
+	if test "x$(BUILD_INFO)" = xinfo; then \
+	  rm -f doc/gdc.info*; \
+	  $(MAKEINFO) $(MAKEINFOFLAGS) -I $(gcc_docdir) \
+		-I $(gcc_docdir)/include -o $@ $<; \
+	else true; fi
+
+doc/gdc.dvi: $(D_TEXI_FILES)
+	$(TEXI2DVI) -I $(abs_docdir) -I $(abs_docdir)/include -o $@ $<
+
+doc/gdc.pdf: $(D_TEXI_FILES)
+	$(TEXI2PDF) -I $(abs_docdir) -I $(abs_docdir)/include -o $@ $<
+
+$(build_htmldir)/d/index.html: $(D_TEXI_FILES)
+	$(mkinstalldirs) $(@D)
+	rm -f $(@D)/*
+	$(TEXI2HTML) -I $(gcc_docdir) -I $(gcc_docdir)/include \
+		-I $(srcdir)/d -o $(@D) $<
+
+.INTERMEDIATE: gdc.pod
+
+gdc.pod: d/gdc.texi
+	-$(TEXI2POD) -D gdc < $< > $@
+
+# Build hooks.
+
+d.all.cross: gdc-cross$(exe

[PATCH 5/13] D: GCC configuration file changes and documentation.

2017-05-28 Thread Iain Buclaw
This patch adds the D language front-end to GCC documentation and
configuration files, as described on the anatomy of a language
front-end.

---
ChangeLog:

	* Makefile.def (target_modules): Add libphobos.
	(flags_to_pass): Add GDC_FOR_TARGET.
	(dependencies): Add dependency from configure-target-libphobos to
	configure-target-zlib.  Add dependency from all-target-libphobos to
	all-target-zlib.
	(language): Add languge d.
	* Makefile.in: Rebuild.
	* Makefile.tpl (BUILT_EXPORTS): Add GDC.
	(HOST_EXPORTS): Add GDC.
	(BASE_TARGET_EXPORTS): Add GDC.
	(GDC_FOR_BUILD, GDC_FOR_TARGET): New variables.
	(EXTRA_HOST_FLAGS): Add GDC.
	(EXTRA_TARGET_FLAGS): Add GDC.
	* config-ml.in: Treat GDC and GDCFLAGS like other compiler/flag
	environment variables.
	* configure: Rebuild.
	* configure.ac: Add target-libphobos to target_libraries.  Set and
	substitute GDC_FOR_BUILD and GDC_FOR_TARGET.

config/ChangeLog:

	* multi.m4: Set GDC.

gcc/ChangeLog:

	* doc/contrib.texi (Contributors): Add self for the D frontend.
	* doc/frontends.texi (G++ and GCC): Mention D as a supported language.
	* doc/install.texi (Configuration): Mention libphobos as an option for
	--enable-shared.  Mention d as an option for --enable-languages.
	(Testing): Mention check-d as a target.
	* doc/invoke.texi (Overall Options): Mention .d, .dd, and .di as file
	name suffixes.  Mention d as a -x option.
	* doc/sourcebuild.texi (Top Level): Mention libphobos.
	* doc/standards.texi (Standards): Add section on D language.

diff --git a/Makefile.def b/Makefile.def
index abfa9efe959..eca4d40edf1 100644
--- a/Makefile.def
+++ b/Makefile.def
@@ -158,6 +158,7 @@ target_modules = { module= libgfortran; };
 target_modules = { module= libobjc; };
 target_modules = { module= libgo; };
 target_modules = { module= libhsail-rt; };
+target_modules = { module= libphobos; };
 target_modules = { module= libtermcap; no_check=true;
missing=mostlyclean;
missing=clean;
@@ -283,6 +284,7 @@ flags_to_pass = { flag= FLAGS_FOR_TARGET ; };
 flags_to_pass = { flag= GFORTRAN_FOR_TARGET ; };
 flags_to_pass = { flag= GOC_FOR_TARGET ; };
 flags_to_pass = { flag= GOCFLAGS_FOR_TARGET ; };
+flags_to_pass = { flag= GDC_FOR_TARGET ; };
 flags_to_pass = { flag= LD_FOR_TARGET ; };
 flags_to_pass = { flag= LIPO_FOR_TARGET ; };
 flags_to_pass = { flag= LDFLAGS_FOR_TARGET ; };
@@ -550,6 +552,8 @@ dependencies = { module=configure-target-libgo; on=all-target-libstdc++-v3; };
 dependencies = { module=all-target-libgo; on=all-target-libbacktrace; };
 dependencies = { module=all-target-libgo; on=all-target-libffi; };
 dependencies = { module=all-target-libgo; on=all-target-libatomic; };
+dependencies = { module=configure-target-libphobos; on=configure-target-zlib; };
+dependencies = { module=all-target-libphobos; on=all-target-zlib; };
 dependencies = { module=configure-target-libstdc++-v3; on=configure-target-libgomp; };
 dependencies = { module=configure-target-liboffloadmic; on=configure-target-libgomp; };
 dependencies = { module=configure-target-libsanitizer; on=all-target-libstdc++-v3; };
@@ -604,6 +608,8 @@ languages = { language=go;	gcc-check-target=check-go;
 lib-check-target=check-target-libgo; };
 languages = { language=brig;	gcc-check-target=check-brig;
 lib-check-target=check-target-libhsail-rt; };
+languages = { language=d;	gcc-check-target=check-d;
+lib-check-target=check-target-libphobos; };
 
 // Toplevel bootstrap
 bootstrap_stage = { id=1 ; };
diff --git a/Makefile.in b/Makefile.in
index b824e0a0ca1..6e513d8685c 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -156,6 +156,7 @@ BUILD_EXPORTS = \
 	GFORTRAN="$(GFORTRAN_FOR_BUILD)"; export GFORTRAN; \
 	GOC="$(GOC_FOR_BUILD)"; export GOC; \
 	GOCFLAGS="$(GOCFLAGS_FOR_BUILD)"; export GOCFLAGS; \
+	GDC="$(GDC_FOR_BUILD)"; export GDC; \
 	DLLTOOL="$(DLLTOOL_FOR_BUILD)"; export DLLTOOL; \
 	LD="$(LD_FOR_BUILD)"; export LD; \
 	LDFLAGS="$(LDFLAGS_FOR_BUILD)"; export LDFLAGS; \
@@ -192,6 +193,7 @@ HOST_EXPORTS = \
 	CXXFLAGS="$(CXXFLAGS)"; export CXXFLAGS; \
 	GFORTRAN="$(GFORTRAN)"; export GFORTRAN; \
 	GOC="$(GOC)"; export GOC; \
+	GDC="$(GDC)"; export GDC; \
 	AR="$(AR)"; export AR; \
 	AS="$(AS)"; export AS; \
 	CC_FOR_BUILD="$(CC_FOR_BUILD)"; export CC_FOR_BUILD; \
@@ -278,6 +280,7 @@ BASE_TARGET_EXPORTS = \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	GFORTRAN="$(GFORTRAN_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export GFORTRAN; \
 	GOC="$(GOC_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export GOC; \
+	GDC="$(GDC_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export GDC; \
 	DLLTOOL="$(DLLTOOL_FOR_TARGET)"; export DLLTOOL; \
 	LD="$(COMPILER_LD_FOR_TARGET)"; export LD; \
 	LDFLAGS="$(LDFLAGS_FOR_TARGET)"; export LDFLAGS; \
@@ -342,6 +345,7 @@ CXX_FOR_BUILD = @CXX_FOR_BUILD@
 DLLTOOL_FOR_BUILD = @DLLTOOL_FOR_BUILD@
 GFORTRAN_FOR_BUILD = @GFORTRAN_FOR_BUILD@
 GOC_FOR_BUILD = @GOC_FOR_BUILD@
+GDC_FOR_BUILD = @GDC_FOR_BUILD@
 LDFLAGS_FOR_BUILD = @LDFLAGS_FOR_BUILD@
 

[PATCH 6/13] D: Add D language support to GCC proper.

2017-05-28 Thread Iain Buclaw
This patch adds D language support to GCC itself.

---
gcc/ChangeLog

	* config/rs6000/rs6000.c (rs6000_output_function_epilogue):
	Support GNU D by using 0 as the language type.
	* dwarf2out.c (is_dlang): New function.
	(gen_compile_unit_die): Use DW_LANG_D for D.
	(declare_in_namespace): Return module die for D, instead of adding
	extra declarations into the namespace.
	(gen_namespace_die): Generate DW_TAG_module for D.
	(gen_decl_die, dwarf2out_decl): Handle CONST_DECLSs for D.
	* gcc.c (default_compilers): Add entries for ".d", ".dd" and ".di".

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index b0d1dd95e5d..32f8527d940 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -31921,11 +31921,12 @@ rs6000_output_function_epilogue (FILE *file,
 	 use language_string.
 	 C is 0.  Fortran is 1.  Pascal is 2.  Ada is 3.  C++ is 9.
 	 Java is 13.  Objective-C is 14.  Objective-C++ isn't assigned
-	 a number, so for now use 9.  LTO, Go and JIT aren't assigned numbers
-	 either, so for now use 0.  */
+	 a number, so for now use 9.  LTO, Go, D, and JIT aren't assigned
+	 numbers either, so for now use 0.  */
   if (lang_GNU_C ()
 	  || ! strcmp (language_string, "GNU GIMPLE")
 	  || ! strcmp (language_string, "GNU Go")
+	  || ! strcmp (language_string, "GNU D")
 	  || ! strcmp (language_string, "libgccjit"))
 	i = 0;
   else if (! strcmp (language_string, "GNU F77")
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 5ff45eb4efd..f4f32440695 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -5079,6 +5079,16 @@ is_ada (void)
   return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
 }
 
+/* Return TRUE if the language is D.  */
+
+static inline bool
+is_dlang (void)
+{
+  unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
+
+  return lang == DW_LANG_D;
+}
+
 /* Remove the specified attribute if present.  Return TRUE if removal
was successful.  */
 
@@ -23595,6 +23605,8 @@ gen_compile_unit_die (const char *filename)
 	language = DW_LANG_ObjC;
   else if (strcmp (language_string, "GNU Objective-C++") == 0)
 	language = DW_LANG_ObjC_plus_plus;
+  else if (strcmp (language_string, "GNU D") == 0)
+	language = DW_LANG_D;
   else if (dwarf_version >= 5 || !dwarf_strict)
 	{
 	  if (strcmp (language_string, "GNU Go") == 0)
@@ -25159,7 +25171,7 @@ declare_in_namespace (tree thing, dw_die_ref context_die)
 
   if (ns_context != context_die)
 {
-  if (is_fortran ())
+  if (is_fortran () || is_dlang ())
 	return ns_context;
   if (DECL_P (thing))
 	gen_decl_die (thing, NULL, NULL, ns_context);
@@ -25182,7 +25194,7 @@ gen_namespace_die (tree decl, dw_die_ref context_die)
 {
   /* Output a real namespace or module.  */
   context_die = setup_namespace_context (decl, comp_unit_die ());
-  namespace_die = new_die (is_fortran ()
+  namespace_die = new_die (is_fortran () || is_dlang ()
 			   ? DW_TAG_module : DW_TAG_namespace,
 			   context_die, decl);
   /* For Fortran modules defined in different CU don't add src coords.  */
@@ -25249,7 +25261,7 @@ gen_decl_die (tree decl, tree origin, struct vlr_context *ctx,
   break;
 
 case CONST_DECL:
-  if (!is_fortran () && !is_ada ())
+  if (!is_fortran () && !is_ada () && !is_dlang ())
 	{
 	  /* The individual enumerators of an enum type get output when we output
 	 the Dwarf representation of the relevant enum type itself.  */
@@ -25796,7 +25808,7 @@ dwarf2out_decl (tree decl)
 case CONST_DECL:
   if (debug_info_level <= DINFO_LEVEL_TERSE)
 	return;
-  if (!is_fortran () && !is_ada ())
+  if (!is_fortran () && !is_ada () && !is_dlang ())
 	return;
   if (TREE_STATIC (decl) && decl_function_context (decl))
 	context_die = lookup_decl_die (DECL_CONTEXT (decl));
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 4724276a318..6c3dd23a840 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -1309,6 +1309,7 @@ static const struct compiler default_compilers[] =
   {".java", "#Java", 0, 0, 0}, {".class", "#Java", 0, 0, 0},
   {".zip", "#Java", 0, 0, 0}, {".jar", "#Java", 0, 0, 0},
   {".go", "#Go", 0, 1, 0},
+  {".d", "#D", 0, 1, 0}, {".dd", "#D", 0, 1, 0}, {".di", "#D", 0, 1, 0},
   /* Next come the entries for C.  */
   {".c", "@c", 0, 0, 1},
   {"@c",


[PATCH 7/13] D: Add D language support to GCC targets.

2017-05-28 Thread Iain Buclaw
This patch add D language support to targets of GCC itself.

These are used to declare pre-defined version identifiers in the D
language that describe something about the target that the front-end
itself is unable to obtain.  Version conditions in D can be thought of
as being like the target macros of C, but that where the similarity
ends.

---
[PATCH 7/13] D: Add D language support to GCC targets.


This patch add D language support to targets of GCC itself.

These are used to declare pre-defined version identifiers in the D language that describe something about the target that the front-end itself is unable to obtain.  Version conditions in D can be thought of as being like the target macros of C, but that where the similarity ends.

---
gcc/ChangeLog:

	* config/aarch64/aarch64.h (TARGET_CPU_D_BUILTINS): Define.
	* config/alpha/alpha.h (TARGET_CPU_D_BUILTINS): Define.
	* config/alpha/linux.h (TARGET_OS_D_BUILTINS): Define.
	* config/arm/arm.h (TARGET_CPU_D_BUILTINS): Define.
	* config/arm/linux-eabi.h (TARGET_OS_D_BUILTINS): Define.
	* config/darwin.h (TARGET_OS_D_BUILTINS): Define.
	* config/freebsd.h (TARGET_OS_D_BUILTINS): Define.
	* config/gnu.h (TARGET_OS_D_BUILTINS): Define.
	* config/i386/cygwin.h (TARGET_OS_D_BUILTINS): Define.
	* config/i386/i386.h (TARGET_CPU_D_BUILTINS): Define.
	* config/i386/linux-common.h (TARGET_OS_D_BUILTINS): Define.
	* config/i386/mingw32.h (TARGET_OS_D_BUILTINS): Define.
	(TARGET_GENERIC_MINGW_OS_D_BUILTINS): Define.
	* config/ia64/ia64.h (TARGET_CPU_D_BUILTINS): Define.
	* config/kfreebsd-gnu.h (TARGET_OS_D_BUILTINS): Define.
	* config/kopernsolaris-gnu.h (TARGET_OS_D_BUILTINS): Define.
	* config/linux-android.h (ANDROID_TARGET_OS_D_BUILTINS): Define.
	* config/linux.h (TARGET_OS_D_BUILTINS): Define.
	(TARGET_GENERIC_LINUX_OS_D_BUILTINS): Define.
	* config/mips/linux-common.h (TARGET_OS_D_BUILTINS): Define.
	* config/mips/mips.h (TARGET_CPU_D_BUILTINS): Define.
	* config/netbsd.h (TARGET_OS_D_BUILTINS): Define.
	* config/openbsd.h (TARGET_OS_D_BUILTINS): Define.
	* config/pa.h (TARGET_CPU_D_BUILTINS): Define.
	* config/rs6000/aix.h (TARGET_OS_D_BUILTINS): Define.
	* config/rs6000/linux.h (TARGET_OS_D_BUILTINS): Define.
	* config/rs6000/linux64.h (TARGET_OS_D_BUILTINS): Define.
	* config/rs6000/rs6000.h (TARGET_CPU_D_BUILTINS): Define.
	* config/s390/s390.h (TARGET_CPU_D_BUILTINS): Define.
	* config/sh/sh.h (TARGET_CPU_D_BUILTINS): Define.
	* config/sparc/sparc.h (TARGET_CPU_D_BUILTINS): Define.

diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
index e4fb96fd037..00eef196000 100644
--- a/gcc/config/aarch64/aarch64.h
+++ b/gcc/config/aarch64/aarch64.h
@@ -26,6 +26,14 @@
 #define TARGET_CPU_CPP_BUILTINS()	\
   aarch64_cpu_cpp_builtins (pfile)
 
+/* Target CPU builtins for D.  */
+#define TARGET_CPU_D_BUILTINS()\
+  do			\
+{			\
+  builtin_define ("AArch64");			\
+  builtin_define ("D_HardFloat");			\
+} while (0)
+
 
 
 #define REGISTER_TARGET_PRAGMAS() aarch64_register_pragmas ()
diff --git a/gcc/config/alpha/alpha.h b/gcc/config/alpha/alpha.h
index 460e83715d9..2fba4741ba4 100644
--- a/gcc/config/alpha/alpha.h
+++ b/gcc/config/alpha/alpha.h
@@ -72,6 +72,23 @@ along with GCC; see the file COPYING3.  If not see
 	SUBTARGET_LANGUAGE_CPP_BUILTINS();		\
 } while (0)
 
+/* Target CPU builtins for D.  */
+#define TARGET_CPU_D_BUILTINS()\
+  do			\
+{			\
+	builtin_define ("Alpha");			\
+	if (TARGET_SOFT_FP)\
+	  {		\
+	builtin_define ("D_SoftFloat");		\
+	builtin_define ("Alpha_SoftFloat");		\
+	  }		\
+	else		\
+	  {		\
+	builtin_define ("D_HardFloat");		\
+	builtin_define ("Alpha_HardFloat");		\
+	  }		\
+} while (0)
+
 #ifndef SUBTARGET_LANGUAGE_CPP_BUILTINS
 #define SUBTARGET_LANGUAGE_CPP_BUILTINS()		\
   do			\
diff --git a/gcc/config/alpha/linux.h b/gcc/config/alpha/linux.h
index e15013eb96a..413de60d7f0 100644
--- a/gcc/config/alpha/linux.h
+++ b/gcc/config/alpha/linux.h
@@ -33,6 +33,16 @@ along with GCC; see the file COPYING3.  If not see
 	  builtin_define ("_GNU_SOURCE");			\
 } while (0)
 
+#undef TARGET_OS_D_BUILTINS
+#define TARGET_OS_D_BUILTINS()	\
+do {			\
+	if (OPTION_GLIBC)	\
+	  builtin_define ("GNU_GLibc");\
+\
+	builtin_define ("linux");\
+	builtin_define ("Posix");\
+} while (0)
+
 #undef LIB_SPEC
 #define LIB_SPEC \
   "%{pthread:-lpthread} \
diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h
index 275004af938..86307fb3a4b 100644
--- a/gcc/config/arm/arm.h
+++ b/gcc/config/arm/arm.h
@@ -47,6 +47,31 @@ extern char arm_arch_name[];
 /* Target CPU builtins.  */
 #define TARGET_CPU_CPP_BUILTINS() arm_cpu_cpp_builtins (pfile)
 
+/* Target CPU builtins for D.  */
+#define TARGET_CPU_D_BUILTINS()\
+  do			\
+{			\
+	builtin_define ("ARM");\
+			\
+	if (TARGET_THUMB || TARGET_THUMB2)		\
+	  builtin_define ("ARM_Thumb");			\
+			\
+	if (TARGET_HARD_FLOAT_ABI)			\
+	  buil

[PATCH 9/13] D: D2 Testsuite Dejagnu files.

2017-05-28 Thread Iain Buclaw
This patch adds D language support to the GCC testsuite.

As well as generating the DejaGNU options for compile and link tests,
handles the conversion from DMD-style compiler options to GDC.

---
[PATCH 9/13] D: D2 Testsuite Dejagnu files.

This patch adds D language support to the GCC testsuite.

As well as generating the DejaGNU options for compile and link tests, handles the conversion from DMD-style compiler options to GDC.

---

diff --git a/gcc/testsuite/gdc.test/d_do_test.exp b/gcc/testsuite/gdc.test/d_do_test.exp
new file mode 100644
index 000..94ea92cf94e
--- /dev/null
+++ b/gcc/testsuite/gdc.test/d_do_test.exp
@@ -0,0 +1,376 @@
+#   Copyright (C) 2012-2017 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# .
+
+# Test using the DMD testsuite.
+# Load support procs.
+load_lib gdc-dg.exp
+
+# Convert DMD arguments to GDC equivalent
+proc gdc-convert-args { args } {
+set out ""
+
+foreach arg [split [lindex $args 0] " "] {
+# List of switches kept in ASCII collated order.
+if { [regexp -- {^-I([\w+/-]+)} $arg pattern path] } {
+lappend out "-I$path"
+
+} elseif { [regexp -- {^-J([\w+/-]+)} $arg pattern path] } {
+lappend out "-J$path"
+
+} elseif [string match "-allinst" $arg] {
+lappend out "-femit-templates"
+
+} elseif { [string match "-boundscheck" $arg]
+ || [ string match "-boundscheck=on" $arg] } {
+lappend out "-fbounds-check"
+
+} elseif { [string match "-boundscheck=off" $arg]
+   || [string match "-noboundscheck" $arg] } {
+lappend out "-fno-bounds-check"
+
+} elseif [string match "-boundscheck=safeonly" $arg] {
+lappend out "-fbounds-check=safeonly"
+
+} elseif [string match "-c" $arg] {
+lappend out "-c"
+
+} elseif [string match "-d" $arg] {
+lappend out "-Wno-deprecated"
+
+} elseif [string match "-de" $arg] {
+lappend out "-Wdeprecated"
+lappend out "-Werror"
+
+} elseif [string match "-debug" $arg] {
+lappend out "-fdebug"
+
+} elseif [string match "-dip1000" $arg] {
+lappend out "-ftransition=safe"
+
+} elseif [string match "-dip25" $arg] {
+lappend out "-ftransition=dip25"
+
+} elseif [string match "-dw" $arg] {
+lappend out "-Wdeprecated"
+lappend out "-Wno-error"
+
+} elseif [string match "-fPIC" $arg] {
+lappend out "-fPIC"
+
+} elseif { [string match "-g" $arg]
+   || [string match "-gc" $arg] } {
+lappend out "-g"
+
+} elseif [string match "-inline" $arg] {
+lappend out "-finline-functions"
+
+} elseif [regexp -- {^-mv=([\w+=./-]+)} $arg pattern value] {
+lappend out "-fmodule-filepath=$value"
+
+} elseif [string match "-O" $arg] {
+lappend out "-O2"
+
+} elseif [string match "-property" $arg] {
+lappend out "-fproperty"
+
+} elseif [string match "-release" $arg] {
+lappend out "-frelease"
+
+} elseif [regexp -- {^-transition=(\w+)} $arg pattern value] {
+lappend out "-ftransition=$value"
+
+} elseif [string match "-unittest" $arg] {
+lappend out "-funittest"
+
+} elseif [string match "-verrors=spec" $arg] {
+lappend out "-Wspeculative"
+
+} elseif [regexp -- {^-verrors=(\d+)} $arg pattern num] {
+lappend out "-fmax-errors=$num"
+
+} elseif [regexp -- {^-version=(\w+)} $arg pattern value] {
+lappend out "-fversion=$value"
+
+} elseif [string match "-w" $arg] {
+lappend out "-Wall"
+lappend out "-Werror"
+
+} elseif [string match "-wi" $arg] {
+lappend out "-Wall"
+lappend out "-Wno-error"
+
+} else {
+# print "Unhandled Argument: $arg"
+}
+}
+
+return $out
+}
+
+proc gdc-copy-extra { base extra } {
+# Split base, folder/file.
+set type [file dirname $extra ]
+
+# print "Filename: $base - $extra"
+
+set fdin [open $base/$extra r]
+fconfigure $fdin -encoding binary
+
+file mkdir [file dirname $extra ]
+set fdout [ open $extra w]
+fcon

[PATCH 11/13] D: GCC builtins and runtime support.

2017-05-28 Thread Iain Buclaw
This patch adds GCC builtins and runtime support for GDC compiled code.

  - module __entrypoint defines the C main function.  Its contents are
parsed and compiled in during compilation, but only if needed.
  - module gcc.atomic is a deprecated module that defines templated
__sync builtins.  It's original user, core.atomic, now uses the GCC
__atomic builtins.
  - module gcc.attribute exposes GDC-specific attributes.
  - module gcc.backtrace implements backtrace support for GDC.
  - module gcc.builtins exposes GCC builtins to D code.
  - module gcc.config exposes things determined at configure time to D code.
  - module gcc.deh implements D unwind EH.
  - module gcc.libbacktrace defines C bindings to libbacktrace.
  - module gcc.unwind defines C bindings to libgcc unwind library.
  - libgphobos.spec contains a list of libraries to link in that are
dependencies of D runtime and/or the Phobos standard library.  It is
used by the GDC driver.

---
diff --git a/libphobos/libdruntime/__entrypoint.di b/libphobos/libdruntime/__entrypoint.di
new file mode 100644
index 000..d04fe5d0889
--- /dev/null
+++ b/libphobos/libdruntime/__entrypoint.di
@@ -0,0 +1,56 @@
+/* GDC -- D front-end for GCC
+   Copyright (C) 2013 Free Software Foundation, Inc.
+
+   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 module provides the C main() function supplied by the user's program.  */
+
+module __entrypoint;
+
+extern(C):
+
+/* The D main() function supplied by the user's program
+
+   It always has `_Dmain` symbol name and uses C calling convention.
+   But D frontend returns its type as `extern(D)` because of Issue 9028.
+   As we need to deal with actual calling convention we have to mark it
+   as `extern(C)` and use its symbol name.
+*/
+
+int _Dmain(char[][] args);
+int _d_run_main(int argc, char **argv, void* mainFunc);
+
+/* Substitutes for the C main() function.  Just calls into d_run_main with
+   the default main function.  Applications are free to implement their own
+   main function and call the _d_run_main function themselves with any main
+   function.
+*/
+
+int main(int argc, char **argv)
+{
+return _d_run_main(argc, argv, &_Dmain);
+}
+
+/* This is apparently needed on Solaris because the C tool chain seems to
+   expect the main function to be called _main.  It needs both not just one!
+*/
+
+version (Solaris)
+int _main(int argc, char** argv)
+{
+return main(argc, argv);
+}
+
diff --git a/libphobos/libdruntime/gcc/atomics.d b/libphobos/libdruntime/gcc/atomics.d
new file mode 100644
index 000..4e9aaa0ea94
--- /dev/null
+++ b/libphobos/libdruntime/gcc/atomics.d
@@ -0,0 +1,185 @@
+/* GDC -- D front-end for GCC
+   Copyright (C) 2011, 2012 Free Software Foundation, Inc.
+
+   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 module is intended to provide some basic support for lock-free
+   concurrent programming via the GCC builtins if the platform supports it.  */
+
+deprecated module gcc.atomics;
+
+import gcc.builtins;
+
+/**
+ * Private helper function for generating similar sync functions
+ */
+private template __sync_op_and(string op1, string op2)
+{
+enum __sync_op_and = `
+T __sync_` ~ op1 ~ `_and_` ~ op2 ~ `(T)(const ref shared T ptr, T value)
+{
+static if (T.sizeof == byte.sizeof)
+return __sync_` ~ op1 ~ `_and_`~ op2 ~`_1(cast(void*) ptr, value);
+else static if (T.sizeof == short.sizeof)
+return __sync_` ~ op1 ~ `_and_`~ op2 ~`_2(cast(void*) ptr, value);
+else static if (T.sizeof == int.sizeof)
+return __sync_` ~ op1 ~ `_and_`~ op2 ~`_4(cast(void*) ptr, value);
+else static if (T.sizeof == long.sizeof)
+return __sync_` ~ op1 ~ `_and_`~ op2 ~`_8(cast(void*) ptr, value);
+else
+static assert(0, "Invalid template type specified.");
+}`
+;

Re: [Patch] SFINAE on is_same first in variant's _Tp&& constructor

2017-05-28 Thread Tim Shen via gcc-patches
On Tue, May 23, 2017 at 3:24 AM, Jonathan Wakely wrote:
> On 22/05/17 16:14 -0400, Tim Song wrote:
> Ah I see.
>
>> The original patch does that (assuming core issue 1227's resolution),
>> but the __and_ version doesn't; __and_ only short circuits the
>> immediate parameter, not things used in forming it.
>
>
> Then the original patch is OK for trunk and gcc-7-branch.
>
> Thank you Tim and Tim for the explanations.
>

Committed. I didn't bother using remove_cv> only
because p0088r3 says decay_t.


-- 
Regards,
Tim Shen


[patch, fortran] Create some temporary variables for matmul arguments

2017-05-28 Thread Thomas Koenig

Hello world,

the attached patch generates some more opportunities for matmul inlining
by creating temporaries if arguments overlap, if the return is from
a function or something similar.

With this, we are pretty much coming to the end of the matmul
optimization saga.  After this, on to new shores! :-)

Regression-testing turned up a few problems, which were fixed
(see ChangeLog).

OK for trunk?

Regards

Thomas

2017-05-28  Thomas Koenig  

PR fortran/37131
* frontend-passes.c (check_conjg_transpose_variable):
Add prototype.
(has_dimen_vector_ref):  Likewise
(matmul_temp_args):  New function. Add prototype.
(optimize_namespace):  Call matmul_temp_args.

2017-05-28  Thomas Koenig  

PR fortran/37131
* gfortran.dg/promotion_2.f90: Add -finline-matmul-limit=0 to
flags.
* gfortran.dg/transpose_optimization_1.f90: Likewise.
* gfortran.dg/inline_matmul_17.f90:  New test.
Index: fortran/frontend-passes.c
===
--- fortran/frontend-passes.c	(Revision 248546)
+++ fortran/frontend-passes.c	(Arbeitskopie)
@@ -49,6 +49,10 @@ static int inline_matmul_assign (gfc_code **, int
 static gfc_code * create_do_loop (gfc_expr *, gfc_expr *, gfc_expr *,
   locus *, gfc_namespace *,
   char *vname=NULL);
+static gfc_expr* check_conjg_transpose_variable (gfc_expr *, bool *,
+		 bool *);
+static bool has_dimen_vector_ref (gfc_expr *);
+static int matmul_temp_args (gfc_code **, int *,void *data);
 
 #ifdef CHECKING_P
 static void check_locus (gfc_namespace *);
@@ -1087,11 +1091,13 @@ optimize_namespace (gfc_namespace *ns)
 			   (void *) &found);
 	}
   while (found);
-	
+
+  gfc_code_walker (&ns->code, matmul_temp_args, dummy_expr_callback,
+		   NULL);
   gfc_code_walker (&ns->code, inline_matmul_assign, dummy_expr_callback,
 		   NULL);
 }
-  
+
   /* BLOCKs are handled in the expression walker below.  */
   for (ns = ns->contained; ns; ns = ns->sibling)
 {
@@ -2157,6 +2163,92 @@ matmul_to_var_code (gfc_code **c, int *walk_subtre
 }
 
 
+/* Take a statement of the shape c = matmul(a,b) and create temporaries
+   for a and b if there is a dependency between the arguments and the
+   result variable or if a or b are the result of calculations that cannot
+   be handled by the inliner.  */
+
+static int
+matmul_temp_args (gfc_code **c, int *walk_subtrees ATTRIBUTE_UNUSED,
+		  void *data ATTRIBUTE_UNUSED)
+{
+  gfc_expr *expr1, *expr2;
+  gfc_code *co;
+  gfc_actual_arglist *a, *b;
+  bool a_tmp, b_tmp;
+  gfc_expr *matrix_a, *matrix_b;
+  bool conjg_a, conjg_b, transpose_a, transpose_b;
+  
+  co = *c;
+
+  if (co->op != EXEC_ASSIGN)
+return 0;
+
+  if (forall_level > 0 || iterator_level > 0 || in_omp_workshare
+  || in_where)
+return 0;
+
+  /* This has some duplication with inline_matmul_assign.  This
+ is because the creation of temporary variables could still fail,
+ and inline_matmul_assign still needs to be able to handle these
+ cases.  */
+  expr1 = co->expr1;
+  expr2 = co->expr2;
+
+  if (expr2->expr_type != EXPR_FUNCTION
+  || expr2->value.function.isym == NULL
+  || expr2->value.function.isym->id != GFC_ISYM_MATMUL)
+return 0;
+
+  a_tmp = false;
+  a = expr2->value.function.actual;
+  matrix_a = check_conjg_transpose_variable (a->expr, &conjg_a, &transpose_a);
+  if (matrix_a != NULL)
+{
+  if (matrix_a->expr_type == EXPR_VARIABLE
+	  && (gfc_check_dependency (matrix_a, expr1, true)
+	  || has_dimen_vector_ref (matrix_a)))
+	a_tmp = true;
+}
+  else
+a_tmp = true;
+
+  b_tmp = false;
+  b = a->next;
+  matrix_b = check_conjg_transpose_variable (b->expr, &conjg_b, &transpose_b);
+  if (matrix_b != NULL)
+{
+  if (matrix_b->expr_type == EXPR_VARIABLE
+	  && (gfc_check_dependency (matrix_b, expr1, true)
+	  || has_dimen_vector_ref (matrix_b)))
+	b_tmp = true;
+}
+  else
+b_tmp = true;
+
+  if (!a_tmp && !b_tmp)
+return 0;
+  
+  current_code = c;
+  inserted_block = NULL;
+  changed_statement = NULL;
+  if (a_tmp)
+{
+  gfc_expr *at;
+  at = create_var (a->expr,"mma");
+  if (at)
+	a->expr = at;
+}
+  if (b_tmp)
+{
+  gfc_expr *bt;
+  bt = create_var (b->expr,"mmb");
+  if (bt)
+	b->expr = bt;
+}
+  return 0;
+}
+
 /* Auxiliary function to build and simplify an array inquiry function.
dim is zero-based.  */
 
Index: testsuite/gfortran.dg/promotion_2.f90
===
--- testsuite/gfortran.dg/promotion_2.f90	(Revision 248467)
+++ testsuite/gfortran.dg/promotion_2.f90	(Arbeitskopie)
@@ -1,5 +1,5 @@
 ! { dg-do compile }
-! { dg-options "-fdefault-real-8 -fexternal-blas -fdump-tree-original" }
+! { dg-options "-fdefault-real-8 -fexternal-blas -fdump-tree-original -finline-matmul-limit=0" }
 !
 ! PR fortran/54463
 !
Index: testsuite/gfortran.dg/transpos

[PATCH 10/13] D: The D runtime library and license.

2017-05-28 Thread Iain Buclaw
This patch adds the D runtime library and license (Boost) files.  D
runtime is a low level that implements the building blocks of the
runtime environment, as well as C and C++ platform bindings.  Many
high level operations are lowered to generate calls to various
functions defined in this library.

I've uploaded the patch to my ftp, sorry about the impromptu of this,
I had everything neatly lined up, but stumbled after being rejected by
the mail daemon.

Regards,
Iain.

---

ftp://ftp.gdcproject.org/patches/10-d-runtime-library.patch.xz

 libphobos/libdruntime/LICENSE  |   26 +
 libphobos/libdruntime/core/atomic.d| 1772 ++
 libphobos/libdruntime/core/attribute.d |   57 +
 libphobos/libdruntime/core/bitop.d | 1018 
 libphobos/libdruntime/core/checkedint.d|  519 ++
 libphobos/libdruntime/core/cpuid.d | 1132 
 libphobos/libdruntime/core/demangle.d  | 2030 +++
 libphobos/libdruntime/core/exception.d |  718 +++
 libphobos/libdruntime/core/internal/abort.d|   45 +
 libphobos/libdruntime/core/internal/convert.d  |  638 ++
 libphobos/libdruntime/core/internal/hash.d |  508 ++
 libphobos/libdruntime/core/internal/spinlock.d |  103 +
 libphobos/libdruntime/core/internal/string.d   |  207 +
 libphobos/libdruntime/core/internal/traits.d   |  189 +
 libphobos/libdruntime/core/math.d  |  160 +
 libphobos/libdruntime/core/memory.d|  791 +++
 libphobos/libdruntime/core/runtime.d   |  843 +++
 libphobos/libdruntime/core/simd.d  |  462 ++
 libphobos/libdruntime/core/stdc/complex.d  |  177 +
 libphobos/libdruntime/core/stdc/config.d   |  151 +
 libphobos/libdruntime/core/stdc/ctype.d|   49 +
 libphobos/libdruntime/core/stdc/errno.d| 1232 
 libphobos/libdruntime/core/stdc/errno_.c   |   25 +
 libphobos/libdruntime/core/stdc/fenv.d |  392 ++
 libphobos/libdruntime/core/stdc/float_.d   |   92 +
 libphobos/libdruntime/core/stdc/inttypes.d |  443 ++
 libphobos/libdruntime/core/stdc/limits.d   |   61 +
 libphobos/libdruntime/core/stdc/locale.d   |  186 +
 libphobos/libdruntime/core/stdc/math.d | 2667 +
 libphobos/libdruntime/core/stdc/signal.d   |   78 +
 libphobos/libdruntime/core/stdc/stdarg.d   |  687 +++
 libphobos/libdruntime/core/stdc/stddef.d   |   33 +
 libphobos/libdruntime/core/stdc/stdint.d   |  258 +
 libphobos/libdruntime/core/stdc/stdio.d| 1261 
 libphobos/libdruntime/core/stdc/stdlib.d   |  224 +
 libphobos/libdruntime/core/stdc/string.d   |   95 +
 libphobos/libdruntime/core/stdc/tgmath.d   | 1131 
 libphobos/libdruntime/core/stdc/time.d |  165 +
 libphobos/libdruntime/core/stdc/wchar_.d   |  236 +
 libphobos/libdruntime/core/stdc/wctype.d   |   65 +
 libphobos/libdruntime/core/stdcpp/exception.d  |  106 +
 libphobos/libdruntime/core/stdcpp/typeinfo.d   |  146 +
 libphobos/libdruntime/core/sync/barrier.d  |  151 +
 libphobos/libdruntime/core/sync/condition.d|  606 ++
 libphobos/libdruntime/core/sync/config.d   |   68 +
 libphobos/libdruntime/core/sync/exception.d|   32 +
 libphobos/libdruntime/core/sync/mutex.d|  275 +
 libphobos/libdruntime/core/sync/rwmutex.d  |  528 ++
 libphobos/libdruntime/core/sync/semaphore.d|  445 ++
 libphobos/libdruntime/core/sys/bionic/fcntl.d  |5 +
 libphobos/libdruntime/core/sys/bionic/unistd.d |5 +
 libphobos/libdruntime/core/sys/freebsd/dlfcn.d |  113 +
 libphobos/libdruntime/core/sys/freebsd/execinfo.d  |  133 +
 libphobos/libdruntime/core/sys/freebsd/sys/cdefs.d |   16 +
 libphobos/libdruntime/core/sys/freebsd/sys/elf.d   |   11 +
 libphobos/libdruntime/core/sys/freebsd/sys/elf32.d |  187 +
 libphobos/libdruntime/core/sys/freebsd/sys/elf64.d |  193 +
 .../libdruntime/core/sys/freebsd/sys/elf_common.d  |  853 +++
 libphobos/libdruntime/core/sys/freebsd/sys/event.d |  130 +
 .../libdruntime/core/sys/freebsd/sys/link_elf.d|   79 +
 libphobos/libdruntime/core/sys/freebsd/sys/mman.d  |  143 +
 libphobos/libdruntime/core/sys/freebsd/time.d  |   25 +
 libphobos/libdruntime/core/sys/linux/config.d  |   28 +
 libphobos/libdruntime/core/sys/linux/dlfcn.d   |  306 +
 libphobos/libdruntime/core/sys/linux/elf.d | 2529 
 libphobos/libdruntime/core/sys/linux/epoll.d   |  130 +
 libphobos/libdruntime/core/sys/linux/errno.d   |   19 +
 libphobos/libdruntime/core/sys/linux/execinfo.d|   16 +
 libphobos/libdruntime/core/sys/linux/fcntl.d   |   18 +
 libphobos/libdruntime/core/sys/linux/link.d|  177 +
 libphobos/libdruntime/core/sys/linux/stdio.d   |  105 +
 libphobos/libdruntime/core/sys/linux/sys/inotify.d |  102 +
 li

[PATCH 8/13] D: D2 Testsuite compilable tests.

2017-05-28 Thread Iain Buclaw
This patch adds part of the D2 testsuite, which includes D source code
files that are considered compilable; files that are considered
uncompilable, but should not ICE; and files that should execute on
targets with crash or assertion failures.

I've uploaded the patch to my ftp, sorry about the impromptu of this,
I had everything neatly lined up, but stumbled after being rejected by
the mail daemon.

Regards,
Iain.

---

ftp://ftp.gdcproject.org/patches/08-d-testsuite.patch.xz

 gcc/testsuite/gdc.test/compilable/99bottles.d  |   52 +
 gcc/testsuite/gdc.test/compilable/a3682.d  |   20 +
 gcc/testsuite/gdc.test/compilable/aliasdecl.d  |   40 +
 gcc/testsuite/gdc.test/compilable/art4769.d|   19 +
 gcc/testsuite/gdc.test/compilable/b1215.d  |  146 +
 gcc/testsuite/gdc.test/compilable/b33.d|   12 +
 gcc/testsuite/gdc.test/compilable/b6395.d  |   25 +
 gcc/testsuite/gdc.test/compilable/bug11735.d   |   36 +
 gcc/testsuite/gdc.test/compilable/bug6963.d|   73 +
 gcc/testsuite/gdc.test/compilable/callconv.d   |   75 +
 gcc/testsuite/gdc.test/compilable/compile1.d   |  925 +++
 gcc/testsuite/gdc.test/compilable/const.d  |   41 +
 gcc/testsuite/gdc.test/compilable/cppmangle.d  |  309 +
 gcc/testsuite/gdc.test/compilable/ddoc1.d  |   69 +
 gcc/testsuite/gdc.test/compilable/ddoc10.d |  210 +
 gcc/testsuite/gdc.test/compilable/ddoc10236.d  |   59 +
 gcc/testsuite/gdc.test/compilable/ddoc10236b.d |   69 +
 gcc/testsuite/gdc.test/compilable/ddoc10325.d  |   17 +
 gcc/testsuite/gdc.test/compilable/ddoc10334.d  |   29 +
 gcc/testsuite/gdc.test/compilable/ddoc10366.d  |   20 +
 gcc/testsuite/gdc.test/compilable/ddoc10367.d  |   28 +
 gcc/testsuite/gdc.test/compilable/ddoc10869.d  |   27 +
 gcc/testsuite/gdc.test/compilable/ddoc10870.d  |   10 +
 gcc/testsuite/gdc.test/compilable/ddoc11.d |   69 +
 gcc/testsuite/gdc.test/compilable/ddoc11479.d  |   96 +
 gcc/testsuite/gdc.test/compilable/ddoc11511.d  |   20 +
 gcc/testsuite/gdc.test/compilable/ddoc11823.d  |7 +
 gcc/testsuite/gdc.test/compilable/ddoc12.d |   20 +
 gcc/testsuite/gdc.test/compilable/ddoc12706.d  |9 +
 gcc/testsuite/gdc.test/compilable/ddoc12745.d  |   25 +
 gcc/testsuite/gdc.test/compilable/ddoc13.d |   26 +
 gcc/testsuite/gdc.test/compilable/ddoc13270.d  |   18 +
 gcc/testsuite/gdc.test/compilable/ddoc13502.d  |   24 +
 gcc/testsuite/gdc.test/compilable/ddoc13645.d  |9 +
 gcc/testsuite/gdc.test/compilable/ddoc14.d |   97 +
 gcc/testsuite/gdc.test/compilable/ddoc198.d|   35 +
 gcc/testsuite/gdc.test/compilable/ddoc2.d  |   42 +
 gcc/testsuite/gdc.test/compilable/ddoc2273.d   |   37 +
 gcc/testsuite/gdc.test/compilable/ddoc3.d  |   71 +
 gcc/testsuite/gdc.test/compilable/ddoc4.d  |   11 +
 gcc/testsuite/gdc.test/compilable/ddoc4162.d   |   17 +
 gcc/testsuite/gdc.test/compilable/ddoc4899.d   |   20 +
 gcc/testsuite/gdc.test/compilable/ddoc5.d  |   31 +
 gcc/testsuite/gdc.test/compilable/ddoc5446.d   |   69 +
 gcc/testsuite/gdc.test/compilable/ddoc5446a.d  |   15 +
 gcc/testsuite/gdc.test/compilable/ddoc5446b.d  |6 +
 gcc/testsuite/gdc.test/compilable/ddoc6.d  |   25 +
 gcc/testsuite/gdc.test/compilable/ddoc648.d|   90 +
 gcc/testsuite/gdc.test/compilable/ddoc6491.d   |   14 +
 gcc/testsuite/gdc.test/compilable/ddoc7.d  |   59 +
 gcc/testsuite/gdc.test/compilable/ddoc7555.d   |   53 +
 gcc/testsuite/gdc.test/compilable/ddoc7656.d   |   24 +
 gcc/testsuite/gdc.test/compilable/ddoc7715.d   |   16 +
 gcc/testsuite/gdc.test/compilable/ddoc7795.d   |   17 +
 gcc/testsuite/gdc.test/compilable/ddoc8.d  |9 +
 gcc/testsuite/gdc.test/compilable/ddoc8271.d   |   15 +
 gcc/testsuite/gdc.test/compilable/ddoc8739.d   |   19 +
 gcc/testsuite/gdc.test/compilable/ddoc9.d  |   26 +
 gcc/testsuite/gdc.test/compilable/ddoc9037.d   |   18 +
 gcc/testsuite/gdc.test/compilable/ddoc9155.d   |   80 +
 gcc/testsuite/gdc.test/compilable/ddoc9305.d   |   38 +
 gcc/testsuite/gdc.test/compilable/ddoc9369.d   |   18 +
 gcc/testsuite/gdc.test/compilable/ddoc9475.d   |   29 +
 gcc/testsuite/gdc.test/compilable/ddoc9497a.d  |   12 +
 gcc/testsuite/gdc.test/compilable/ddoc9497b.d  |   12 +
 gcc/testsuite/gdc.test/compilable/ddoc9497c.d  |   12 +
 gcc/testsuite/gdc.test/compilable/ddoc9497d.d  |   12 +
 gcc/testsuite/gdc.test/compilable/ddoc9676a.d  |9 +
 gcc/testsuite/gdc.test/compilable/ddoc9676b.d  |8 +
 gcc/testsuite/gdc.test/compilable/ddoc9727.d   |   25 +
 gcc/testsuite/gdc.test/compilable/ddoc9789.d   |   11 +
 gcc/testsuite/gdc.test/compilable/ddoc9903.d   |   35 +
 gcc/testsuite/gdc.test/compilable/ddocYear.d   |6 +
 gcc/testsuite/gdc.test/compilable/ddocbackticks.d  |   24 +

[PATCH 12/13] D: The Phobos runtime library and license.

2017-05-28 Thread Iain Buclaw
This patch add the Phobos runtime library and license (Boost) files.
Phobos is the standard runtime library that comes with the D language
compiler.  The bulk of which is comprised mostly of generic algorithms
and high level primitives for D applications.

I've uploaded the patch to my ftp, sorry about the impromptu of this,
I had everything neatly lined up, but stumbled after being rejected by
the mail daemon.

Regards,
Iain.

---

ftp://ftp.gdcproject.org/patches/12-d-phobos-library.patch.xz


 libphobos/src/LICENSE_1_0.txt  |23 +
 libphobos/src/etc/c/curl.d |  2320 ++
 libphobos/src/etc/c/sqlite3.d  |  2126 ++
 libphobos/src/etc/c/zlib.d |  1364 +
 libphobos/src/index.d  |   522 +
 libphobos/src/std/algorithm/comparison.d   |  2045 ++
 libphobos/src/std/algorithm/internal.d |77 +
 libphobos/src/std/algorithm/iteration.d|  4397 +++
 libphobos/src/std/algorithm/mutation.d |  2495 ++
 libphobos/src/std/algorithm/package.d  |   191 +
 libphobos/src/std/algorithm/searching.d|  3752 ++
 libphobos/src/std/algorithm/setops.d   |  1397 +
 libphobos/src/std/algorithm/sorting.d  |  3077 ++
 libphobos/src/std/array.d  |  3574 ++
 libphobos/src/std/ascii.d  |   671 +
 libphobos/src/std/base64.d |  2043 ++
 libphobos/src/std/bigint.d |  1596 +
 libphobos/src/std/bitmanip.d   |  3999 +++
 libphobos/src/std/c/fenv.d |16 +
 libphobos/src/std/c/freebsd/socket.d   |17 +
 libphobos/src/std/c/linux/linux.d  |70 +
 libphobos/src/std/c/linux/linuxextern.d|17 +
 libphobos/src/std/c/linux/pthread.d|19 +
 libphobos/src/std/c/linux/socket.d |82 +
 libphobos/src/std/c/linux/termios.d|12 +
 libphobos/src/std/c/linux/tipc.d   |17 +
 libphobos/src/std/c/locale.d   |17 +
 libphobos/src/std/c/math.d |16 +
 libphobos/src/std/c/osx/socket.d   |62 +
 libphobos/src/std/c/process.d  |95 +
 libphobos/src/std/c/stdarg.d   |16 +
 libphobos/src/std/c/stddef.d   |16 +
 libphobos/src/std/c/stdio.d|16 +
 libphobos/src/std/c/stdlib.d   |18 +
 libphobos/src/std/c/string.d   |16 +
 libphobos/src/std/c/time.d |16 +
 libphobos/src/std/c/wcharh.d   |16 +
 libphobos/src/std/c/windows/com.d  |11 +
 libphobos/src/std/c/windows/stat.d |15 +
 libphobos/src/std/c/windows/windows.d  |15 +
 libphobos/src/std/c/windows/winsock.d  |16 +
 libphobos/src/std/compiler.d   |61 +
 libphobos/src/std/complex.d|   937 +
 libphobos/src/std/concurrency.d|  2662 ++
 libphobos/src/std/concurrencybase.d|20 +
 libphobos/src/std/container/array.d|  2181 ++
 libphobos/src/std/container/binaryheap.d   |   438 +
 libphobos/src/std/container/dlist.d|   980 +
 libphobos/src/std/container/package.d  |  1059 +
 libphobos/src/std/container/rbtree.d   |  2058 ++
 libphobos/src/std/container/slist.d|   848 +
 libphobos/src/std/container/util.d |   181 +
 libphobos/src/std/conv.d   |  5799 
 libphobos/src/std/cstream.d|   250 +
 libphobos/src/std/csv.d|  1692 +
 libphobos/src/std/datetime.d   | 34554 +++
 libphobos/src/std/demangle.d   |91 +
 libphobos/src/std/digest/crc.d |   462 +
 libphobos/src/std/digest/digest.d  |   993 +
 libphobos/src/std/digest/hmac.d|   317 +
 libphobos/src/std/digest/md.d  |   591 +
 libphobos/src/std/digest/ripemd.d  |   763 +
 libphobos/src/std/digest/sha.d |  1263 +
 libphobos/src/std/encoding.d   |  3382 ++
 libphobos/src/std/exception.d  |  2256 ++
 .../allocator/building_blocks/affix_allocator.d|   294 +
 .../allocator/building_blocks/allocator_list.d |   621 +
 .../allocator/building_blocks/bitmapped_block.d|  1439 +
 .../allocator/building_blocks/bucketizer.d |   250 +
 .../allocator/building_blocks/fallback_allocator.d |   357 +
 .../allocator/building_blocks/free_list.d  |  1086 +
 .../allocator/building_blocks/free_tree.d  |   40

Re: [PATCH 0/13] D: Submission of D Front End

2017-05-28 Thread Iain Buclaw
On 28 May 2017 at 22:31, Iain Buclaw  wrote:
> On 28 May 2017 at 15:30, Iain Buclaw  wrote:
>>
>> ---
>>
>> Iain Buclaw (13):
>>   001 - The front-end (DMD) language implementation and license.
>>   002 - The front-end (GDC) implementation.
>>   003 - The front-end (GDC) changelogs (here be dragons).
>>   004 - The front-end (GDC) config, makefile, and manpages.
>>   005 - GCC configuration file changes and documentation.
>>   006 - Add D language support to GCC proper.
>>   007 - Add D language support to GCC targets.
>>   008 - D2 Testsuite tests.
>>   009 - D2 Testsuite Dejagnu files.
>>   010 - The D runtime library and license.
>>   011 - GCC builtins and runtime support (part of D runtime)
>>   012 - The Phobos runtime library and license.
>>   013 - Phobos config, makefiles, and testsuite.
>>
>
> Well, it looks like this will need breaking down even more.  The GDC
> parts should be OK, it's just the upstream bits that are far to big to
> attach here.
>

In the meantime, I've uploaded the series here too:

ftp://ftp.gdcproject.org/patches/

I look forward to the discussion when I'm back.

Thanks,
Iain.


New Spanish PO file for 'gcc' (version 7.1.0)

2017-05-28 Thread Translation Project Robot
Hello, gentle maintainer.

This is a message from the Translation Project robot.

A revised PO file for textual domain 'gcc' has been submitted
by the Spanish team of translators.  The file is available at:

http://translationproject.org/latest/gcc/es.po

(This file, 'gcc-7.1.0.es.po', has just now been sent to you in
a separate email.)

All other PO files for your package are available in:

http://translationproject.org/latest/gcc/

Please consider including all of these in your next release, whether
official or a pretest.

Whenever you have a new distribution with a new version number ready,
containing a newer POT file, please send the URL of that distribution
tarball to the address below.  The tarball may be just a pretest or a
snapshot, it does not even have to compile.  It is just used by the
translators when they need some extra translation context.

The following HTML page has been updated:

http://translationproject.org/domain/gcc.html

If any question arises, please contact the translation coordinator.

Thank you for all your work,

The Translation Project robot, in the
name of your translation coordinator.




Re: [Patch, fortran] PR35339 Optimize implied do loops in io statements

2017-05-28 Thread Jerry DeLisle

On 05/27/2017 12:49 PM, Nicolas Koenig wrote:

Hello everyone,

attached is a patch to simplify implied do loops in io statements by replacing 
them with their respective array slices. For example "WRITE (*,*) (a(i), 
i=1,4,2)" becomes "WRITE (*,*) a(1:4:2)".


Ok for trunk?



Thanks for patch. Could you do some timing performance tests with and without 
the patch on large arrays and see if we gain anything?


Also, we should expand the test case to include implied do loops in read 
statements. You could probably just rewind the file, copy down the WRITEs and 
change them to READs or similar and check results.


While doing some checks myself I noticed some odd behavior and found PR53029. I 
posted a patch, but what caught my attention was the implied do version was 
faster than the array version. (about .89 sec vs 6 sec)


So with my patch there I am now getting (.89 sec vs .007 sec)

This prompted me to have you check some performance cases.

Thanks for additional feedback,

Jerry




Re: builtin fenv functions

2017-05-28 Thread Marc Glisse

On Fri, 26 May 2017, Richard Biener wrote:


Similarly, I
don't see div as a builtin in that file, only FILE* has special code, but
that doesn't seem worth the trouble here. So I am only declaring the 5
"simple" functions, with minimal properties: leaf, nothrow, and for
fegetround pure (glibc already declares it that way). We can then discuss
the safety of future optimizations on a case by case basis.



+DEF_C99_BUILTIN(BUILT_IN_FERAISEEXCEPT, "feraiseexcept",
BT_FN_INT_INT, ATTR_NOTHROW_LEAF_LIST)

I think feraiseexcept shouldn't be nothrow?



glibc marks it as nothrow. I can remove the nothrow flag for now, for
safety. It may trap, but it does not throw a C++ exception AFAIU.


Also with -fnon-call-exceptions?


Hmm, maybe on windows where trap handlers turn into system exceptions 
which are handled like C++ exceptions... I am happy to remove nothrow.



But it may be pure.


It writes to the exception register (aka memory for now), so I would hardly
call it pure.


But it doesn't have to be ordered with control word writes/reads, no?


Not sure what you mean here. feraiseexcept(FE_DIVBYZERO) is equivalent to 
1./0., it writes to the exception status flag. Its order with 
respect to fetestexcept must be preserved.



Likewise fetestexcept may be pure?



Too unsafe for now, since any FP operation can write to the memory that
fetestexcept reads.


Ah...  but then FP operations are not ordered with the builtins anyway,
only FP loads/stores would be.


Since gcc doesn't handle fenv properly, people have been using a number of 
workarounds, in particular with pass-through asm, sometimes volatile, 
occasionally with the "memory" clobber.


Some of those versions would still work with pure, but the attribute 
increases the likelyhood of breaking some of those uses, and I don't know 
if it would ever help in practice, so I would rather not add it for now. 
fegetround is very different since it can safely swap position with an 
adjacent float operation.



After all having builtins is only the first easiest step of properly modeling
dependences between FP ops and the FP control/exception registers.


Yes, I didn't expect adding those 5 builtins (modulo the nothrow flag) to 
be controversial...


--
Marc Glisse


Re: [patch, fortran] Create some temporary variables for matmul arguments

2017-05-28 Thread Jerry DeLisle

On 05/28/2017 02:40 PM, Thomas Koenig wrote:

Hello world,

the attached patch generates some more opportunities for matmul inlining
by creating temporaries if arguments overlap, if the return is from
a function or something similar.

With this, we are pretty much coming to the end of the matmul
optimization saga.  After this, on to new shores! :-)

Regression-testing turned up a few problems, which were fixed
(see ChangeLog).

OK for trunk?



OK, and thanks. I do think its time to move on. ;)

Jerry


[patch, libgfortran] PR53029 missed optimization in internal read (without implied-do-loop)

2017-05-28 Thread Jerry DeLisle

Hi all,

The problem here is that we never set the err return to LIBERROR_END in all 
cases. For the example case we are detecting the EOF condition inside the 
read_integer procedure and it gets acted on correctly at higher levels in the 
code. Consequently in the big loop over the array where we call 
list_formatted_read_scalar, we never returned an error code so we never exited 
the loop early.


The patch tests for the EOF first locally as before, but then returns the error 
flags set in dtp->common.flags which are set globally in the individual read 
procedures whene hit_eof is called.


Regression tested on x86_64. I have added a test case which will check the 
execution time of the loop. The previous results of the REAd were correct, just 
took a long time on large arrays.


OK for trunk?

Regards,

Jerry

2017-05-28  Jerry DeLisle  

PR libgfortran/35339
* list_read.c.c (list_formatted_read_scala): Set the err return
value to the common.flags error values.
diff --git a/libgfortran/io/list_read.c b/libgfortran/io/list_read.c
index 6c00d11b..b6cd6670 100644
--- a/libgfortran/io/list_read.c
+++ b/libgfortran/io/list_read.c
@@ -2298,11 +2298,16 @@ list_formatted_read_scalar (st_parameter_dt *dtp, bt type, void *p,
 free_saved (dtp);
 
 cleanup:
+  /* err may have been set above from finish_separator, so if it is set
+ trigger the hit_eof. The hit_eof will set bits in common.flags.  */
   if (err == LIBERROR_END)
 {
   free_line (dtp);
   hit_eof (dtp);
 }
+  /* Now we check common.flags for any errors that could have occurred in
+ a READ elsewhere such as in read_integer.  */
+  err = dtp->common.flags & IOPARM_LIBRETURN_MASK;
   fbuf_flush_list (dtp->u.p.current_unit, LIST_READING);
   return err;
 }
! { dg-do run }
! PR35339 Missed optimization, this test case took several seconds to
  program internalread
  implicit none
  integer m
  parameter(m=100)
  character value*10
  character(80) :: result
  integer i,j,intvalues(m)
  real :: start, finish
  intvalues = 33
  call cpu_time(start)
  do j=1,100
write(value,'(i3,a5)') j," 5 69"
read(value,*,end=20) intvalues
   20   write(result,*) (intvalues(i),i=2,4)
  if (result.ne.('   5  69  33')) call abort
  call cpu_time(finish)
  if ((finish-start).gt. 2.0) call abort
  enddo
  end program internalread


Optimisation of std::binary_search of the header

2017-05-28 Thread jay pokarna
Hey,

I am Jay.

I have written code for an optimised version of the binary_search
algorithm of the algorithm header file of the standard template
library.

I have implemented it for the integer data type, but it can be
implemented for any other data type without any changes in the
algorithm as such.

You are requested to give me feedback on my implementation.


#include
#include
#include
using namespace std;

bool binary_search(int arr[], int size, int ele, bool *fun_ptr);
bool binary_search(int arr[] , int size , int ele);

/*
This version of the binary_search finds an element ele in the array
arr of length size.
*/

/*
Assumptions:
1) Elements are sorted in increasing order in the array
2) The parameter size is the number of elements in the array not the
index of the last element,
i.e. the search space is arr[0,size)
3) Though , I have implemented this version with the int data type,
it is also compatible with other data types like strings , or user
defined data types.
In those cases , only the comparison operation will change without any
changes in the
algorithm.
*/

/*
  If the specified element is in the array, then the function returns
1 else returns 0.
*/

bool binary_search(int arr[] , int size , int ele)
{

/*
The element cannot be in the array if it is larger than the largest
element or smaller than the smallest element
*/

  if( ele < arr[0]||arr[size-1] < ele)
  {
return bool(0);
  }

  /*
After this statement , the element is definitely not outside the array,
but it may or may not be in the array.
  */
  int t=sqrt(size);
  int start =0,end=t*t;

  /*
The algorithm uses the technique of square root decomposition.
It breaks down the problem (the array of length size)
to smaller problems each of length sqrt(size).
It does a kind of binary_search on the first element
of each subarray to find the subproblem to which the element belongs.
  */

  /*
The if part of the if else loop below finds which subproblem the element ele
belongs to.

The last subproblem won't be of length sqrt(size) if size is not a
perfect square.
So , as to handle this corner case , we need the else part of the loop.
  */
  if(ele < arr[end])
  {
while(end-start>t)
{
  int mid = (start+end)/2;

  mid -= (mid%t);

  if(arr[mid]==ele)

  {
return bool(1);
  }
  else if(arr[mid] < ele)
  {
start = mid;
  }
  else
  {
end = mid;
  }
}
  }
  else
  {
start = end;
end = size;
  }

  /*
After this if else loop , [start , end] will have a portion of the
array of maximum length sqrt(size)
which may contain the element.
  */

  /*
The loop below does a normal binary_search in the range [start,end]
  */
  while(end>=start)
  {
int mid = start + ((end-start)/2);

if(ele ==arr[mid])
{
return bool(1);
}

else if(arr[mid] < ele)
{
  start = mid+1;
}
else
{
  end = mid-1;
}
  }
  return bool(0);
}

// Same Code as above just with a comparator specified

bool binary_search(int arr[] , int size , int ele, bool (*fun_ptr)(int ,int))
{

/*
The element cannot be in the array if it is larger than the largest
element or smaller than the smallest element
*/

  if(fun_ptr(ele,arr[0])||fun_ptr(arr[size-1],ele))
  {
return bool(0);
  }

  /*
After this statement , the element is definitely not outside the array,
but it may or may not be in the array.
  */
  int t=sqrt(size);
  int start =0,end=t*t;

  /*
The algorithm uses the technique of square root decomposition.
It breaks down the problem (the array of length size)
to smaller problems each of length sqrt(size).
It does a kind of binary_search on the first element
of each subarray to find the subproblem to which the element belongs.
  */

  /*
The if part of the if else loop below finds which subproblem the element ele
belongs to.

The last subproblem won't be of length sqrt(size) if size is not a
perfect square.
So , as to handle this corner case , we need the else part of the loop.
  */
  if(fun_ptr(ele,arr[end]))
  {
while(end-start>t)
{
  int mid = (start+end)/2;

  mid -= (mid%t);

  if(!fun_ptr(arr[mid],ele)&&!fun_ptr(ele,arr[mid]))
   /*
This is equivalent to checking the condition
ele == arr[mid]
   */
  {
return bool(1);
  }
  else if(fun_ptr(arr[mid],ele))
  {
start = mid;
  }
  else
  {
end = mid;
  }
}
  }
  else
  {
start = end;
end = size;
  }

  /*
After this if else construct , [start , end] will have a portion of
the array of maximum length sqrt(size)
which may contain the element
  */

  /*
The loop below does a normal binary_search in the range [start,end]
  */
  while(end>=start)
  {
int mid = start + ((end-start)/2);

if(!fun_ptr(arr[mid],ele)&&!fun_ptr(ele,arr[mid]))
   /*
This is equivalent to checking the condition
ele == arr[mid]
   */
{
return bool(1);
}

else if(fun_ptr(arr[mid],ele))
{
  start = mid+1;
}
else
{
 

Re: [PATCH 1/5][GIMPLE FE] PR testsuite/80580. Handle missing labels in goto statements

2017-05-28 Thread Mikhail Maltsev
Hi. Sorry for a long delay.

On 02.05.2017 17:16, Richard Biener wrote:
> Certainly an improvement.  I suppose we can do better error recovery
> for cases like
> 
>  if (1)
>goto
>  else
>goto bar;
> 
> but I guess this is better than nothing.
I think it's worth spending a bit more time to get this right.

> 
> And yes, we use c_parser_error -- input_location should be ok but here
> we just peek which may upset the parser.  Maybe it works better
> when consuming the token before issueing the error?  Thus
> 
> Index: gcc/c/gimple-parser.c
> ===
> --- gcc/c/gimple-parser.c   (revision 247498)
> +++ gcc/c/gimple-parser.c   (working copy)
> @@ -1315,8 +1315,8 @@ c_parser_gimple_if_stmt (c_parser *parse
>loc = c_parser_peek_token (parser)->location;
>c_parser_consume_token (parser);
>label = c_parser_peek_token (parser)->value;
> -  t_label = lookup_label_for_goto (loc, label);
>c_parser_consume_token (parser);
> +  t_label = lookup_label_for_goto (loc, label);
>if (! c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
> return;
>  }
> 
I was more focused on cases with missing labels (i.e. 'label' is NULL), rather
than cases with syntactically correct if-statements referencing undefined
labels. And, frankly speaking, I'm not sure that swapping
'c_parser_consume_token' with 'lookup_label_for_goto' will help, because
'lookup_label_for_goto' already gets a 'loc' parameter.

BTW, unfortunately GIMPLE FE does not handle undefined labels properly. I.e.,
this test case

__GIMPLE() void foo()
{
bb_0:
  if (0)
goto bb_0;
  else
goto bb_1;
}

causes an ICE somewhere in build_gimple_cfg/cleanup_dead_labels. But this is a
separate issue, of course.

I attached a slightly modified patch, which incorporates your changes and also 
uses

  if (! c_parser_next_token_is (parser, CPP_NAME))
...

instead of

  label = c_parser_peek_token (parser)->value;
  ...
  if (!label)
...

for better readability. This version correctly handles missing labels and
semicolons in both branches of the 'if' statement.

The only major problem, which I want to fix is error recovery in the following
example:

__GIMPLE() void foo()
{
  if (1)
goto lbl;
  else
goto ; /* { dg-error "expected label" } */
}

__GIMPLE() void bar()
{
  if (1)
goto lbl;
  else
goto
} /* { dg-error "expected label" } */

In this case GCC correctly diagnoses both errors. But if I swap these two
functions so that 'bar' comes before 'foo', the error in 'foo' is not diagnosed.
I did not dive into details, but my speculation is that the parser  enters some
strange state and skips 'foo' entirely (-fdump-tree-gimple contains only 'bar').
If I add another function after 'foo', it is handled correctly.
Any ideas, why this could happen and how to improve error recovery in this case?

-- 
Regards,
   Mikhail Maltsev
diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c
index ed9e7c5..44ca738 100644
--- a/gcc/c/gimple-parser.c
+++ b/gcc/c/gimple-parser.c
@@ -1336,9 +1336,14 @@ c_parser_gimple_if_stmt (c_parser *parser, gimple_seq 
*seq)
 {
   loc = c_parser_peek_token (parser)->location;
   c_parser_consume_token (parser);
+  if (! c_parser_next_token_is (parser, CPP_NAME))
+   {
+ c_parser_error (parser, "expected label");
+ return;
+   }
   label = c_parser_peek_token (parser)->value;
-  t_label = lookup_label_for_goto (loc, label);
   c_parser_consume_token (parser);
+  t_label = lookup_label_for_goto (loc, label);
   if (! c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
return;
 }
@@ -1360,9 +1365,14 @@ c_parser_gimple_if_stmt (c_parser *parser, gimple_seq 
*seq)
 {
   loc = c_parser_peek_token (parser)->location;
   c_parser_consume_token (parser);
+  if (! c_parser_next_token_is (parser, CPP_NAME))
+   {
+ c_parser_error (parser, "expected label");
+ return;
+   }
   label = c_parser_peek_token (parser)->value;
-  f_label = lookup_label_for_goto (loc, label);
   c_parser_consume_token (parser);
+  f_label = lookup_label_for_goto (loc, label);
   if (! c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
return;
 }
diff --git a/gcc/testsuite/gcc.dg/gimplefe-error-7.c 
b/gcc/testsuite/gcc.dg/gimplefe-error-7.c
new file mode 100644
index 000..7d5ff37
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gimplefe-error-7.c
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-options "-fgimple" } */
+
+__GIMPLE() void fn1()
+{
+  if (1)
+goto
+  else /* { dg-error "expected label" } */
+goto lbl;
+}
+
+__GIMPLE() void fn2()
+{
+  if (1)
+goto lbl;
+  else
+goto ; /* { dg-error "expected label" } */
+}
+
+__GIMPLE() void fn3()
+{
+  if (1)
+goto lbl;
+  else
+goto
+} /* { dg-error "expected label" } */
+


Re: [PATCH] Introduce 4-stages profiledbootstrap to get a better profile.

2017-05-28 Thread Markus Trippelsdorf
On 2017.05.25 at 11:55 +0200, Martin Liška wrote:
> Hi.
> 
> As I spoke about the PGO with Honza and Richi, current 3-stage is not ideal 
> for following
> 2 reasons:
> 
> 1) stageprofile compiler is train just on libraries that are built during 
> stage2
> 2) apart from that, as the compiler is also used to build the final compiler, 
> profile
> is being updated during the build. So the stage2 compiler is making different 
> decisions.
> 
> Both problems can be resolved by adding another step in between current 
> stage2 and stage3
> where we train stage2 compiler by building compiler with default options.

Another issue that I've noticed is that LTO doesn't get used in the
final stage (stagefeedback) with "bootstrap-O3 bootstrap-lto".
It only is used during training. So either move -flto to stagefeedback,
or use -flto both during training and during the final stage.

-- 
Markus


Re: Optimisation of std::binary_search of the header

2017-05-28 Thread Tim Song
This is not a patch. Nor is it an implementation of
std::binary_search, which is a function template that accepts
arbitrary forward iterators and optionally arbitrary comparator
objects, rather than just pointers.

If you want to find someone to review your code, consider something
like https://codereview.stackexchange.com/.

While I'm not a maintainer, I strongly suspect that for something like
this to have a chance of getting into libstdc++, it needs to, at the
very minimum, implement the standard signature and be accompanied by
sufficient performance benchmarks showing that it is better performing
than the existing implementation.


[PATCH 0/4 v3][PR 67328] Improve bitfield range tests

2017-05-28 Thread Yuri Gribov
Hi all,

This is a follow up for my previous fix for PR 67328.

My original simple addition to match.pd no longer worked with GCC 7
codebase so I instead added a special case to build_range_check. I
kept match.pd pattern as it still works in some other useful cases as
illustrated by fold-masked-cmp-3.c.

Bootstrapped and regtested on x86_64.

-I


[PATCH 1/4 v3][PR 67328] Generate bittests in range checks if possible

2017-05-28 Thread Yuri Gribov
Added special case to build_range_check. Fixed couple of existing
tests where it changed codegen.

-I


0001-Generate-bittests-in-range-checks-if-possible.patch
Description: Binary data


[PATCH 2/4 v3][PR 67328] Analyze some bit tests in VRP

2017-05-28 Thread Yuri Gribov
This improve VRP handling for bitfield comparisons added by previous patch.

-I


0002-Analyze-some-bit-tests-in-VRP.patch
Description: Binary data