[patch, libgfortran] [F03] Incorrect file position with namelist read under DTIO

2017-03-28 Thread Jerry DeLisle

Hi all,

The attached patch resolves this problem by moving the code that invokes the 
child I/O procedure into nml_read_obj where it belongs.  This allows the normal 
flow of code that parses the namelist decorations before attempting to read the 
object data.


One new test case is provided. Test case dtio_25.f90 is updated to fix it. One 
minor tweak on dtio_4.f90. (tests are in the patch)


As a followup, I will be testing for arrays of derived types in namelists. If 
any problems there I will open a new PR.


Regression tested on x86-64-linux.

OK for trunk?

Regards,

Jerry

2017-03-28  Jerry DeLisle  

PR libgfortran/78670
* io/list_read.c (nml_get_obj_data): Delete code which calls the
child read procedure. (nml_read_obj): Insert the code which
calls the child procedure. Don't need to touch nodes if using
dtio since parent will not be traversing the components.


2017-03-28  Jerry DeLisle  

PR libgfortran/78670
* gfortran.dg/dtio_25.f90: Use 'a1' format when trying to read
a character of length 1. Update test for success.
* gfortran.dg/dtio_28.f03: New test.
* gfortran.dg/dtio_4.f90: Update to open test file with status =
'scratch' to delete the file when done.

diff --git a/gcc/testsuite/gfortran.dg/dtio_25.f90 b/gcc/testsuite/gfortran.dg/dtio_25.f90
index 6e66a312..a90a238e 100644
--- a/gcc/testsuite/gfortran.dg/dtio_25.f90
+++ b/gcc/testsuite/gfortran.dg/dtio_25.f90
@@ -20,7 +20,7 @@ contains
 integer, intent(out) :: iostat
 character(*), intent(inout) :: iomsg
 if (iotype.eq."NAMELIST") then
-  write (unit, '(a3,a1,i3)') dtv%c,',', dtv%k
+  write (unit, '(a1,a1,i3)') dtv%c,',', dtv%k
 else
   write (unit,*) dtv%c, dtv%k
 end if
@@ -34,7 +34,7 @@ contains
 character(*), intent(inout) :: iomsg
 character :: comma
 if (iotype.eq."NAMELIST") then
-  read (unit, '(a4,a1,i3)') dtv%c, comma, dtv%k! FIXME: need a4 here, with a3 above
+  read (unit, '(a1,a1,i3)') dtv%c, comma, dtv%k
 else
   read (unit,*) dtv%c, comma, dtv%k
 end if
@@ -50,7 +50,7 @@ program p
   namelist /nml/ x
   x = t('a', 5)
   write (buffer, nml)
-  if (buffer.ne.'  X=  a,  5  /') call abort
+  if (buffer.ne.'  X=a,  5  /') call abort
   x = t('x', 0)
   read (buffer, nml)
   if (x%c.ne.'a'.or. x%k.ne.5) call abort
diff --git a/gcc/testsuite/gfortran.dg/dtio_28.f03 b/gcc/testsuite/gfortran.dg/dtio_28.f03
new file mode 100644
index ..c70dc344
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dtio_28.f03
@@ -0,0 +1,74 @@
+! { dg-do run }
+! PR78670 Incorrect file position with namelist read under DTIO
+MODULE m
+  IMPLICIT NONE
+  TYPE :: t
+CHARACTER :: c
+  CONTAINS
+PROCEDURE :: read_formatted
+GENERIC :: READ(FORMATTED) => read_formatted
+PROCEDURE :: write_formatted
+GENERIC :: WRITE(FORMATTED) => write_formatted
+  END TYPE t
+CONTAINS
+  SUBROUTINE write_formatted(dtv, unit, iotype, v_list, iostat, iomsg)
+CLASS(t), INTENT(IN) :: dtv
+INTEGER, INTENT(IN) :: unit
+CHARACTER(*), INTENT(IN) :: iotype
+INTEGER, INTENT(IN) :: v_list(:)
+INTEGER, INTENT(OUT) :: iostat
+CHARACTER(*), INTENT(INOUT) :: iomsg
+write(unit,'(a)', iostat=iostat, iomsg=iomsg) dtv%c
+  END SUBROUTINE write_formatted
+  
+  SUBROUTINE read_formatted(dtv, unit, iotype, v_list, iostat, iomsg)
+CLASS(t), INTENT(INOUT) :: dtv
+INTEGER, INTENT(IN) :: unit
+CHARACTER(*), INTENT(IN) :: iotype
+INTEGER, INTENT(IN) :: v_list(:)
+INTEGER, INTENT(OUT) :: iostat
+CHARACTER(*), INTENT(INOUT) :: iomsg
+
+CHARACTER :: ch
+dtv%c = ''
+DO
+  READ (unit, "(A)", IOSTAT=iostat, IOMSG=iomsg) ch
+  IF (iostat /= 0) RETURN
+  ! Store first non-blank
+  IF (ch /= ' ') THEN
+dtv%c = ch
+RETURN
+  END IF
+END DO
+  END SUBROUTINE read_formatted
+END MODULE m
+
+PROGRAM p
+  USE m
+  IMPLICIT NONE
+  TYPE(t) :: x
+  TYPE(t) :: y
+  TYPE(t) :: z
+  integer :: j, k
+  NAMELIST /nml/ j, x, y, z, k
+  INTEGER :: unit, iostatus
+  
+  OPEN(NEWUNIT=unit, STATUS='SCRATCH', ACTION='READWRITE')
+  
+  x%c = 'a'
+  y%c = 'b'
+  z%c = 'c'
+  j=1
+  k=2
+  WRITE(unit, nml)
+  REWIND (unit)
+  x%c = 'x'
+  y%c = 'y'
+  z%c = 'x'
+  j=99
+  k=99
+  READ (unit, nml, iostat=iostatus)
+  if (iostatus.ne.0) call abort
+  if (j.ne.1 .or. k.ne.2 .or. x%c.ne.'a' .or. y%c.ne.'b' .or. z%c.ne.'c') call abort
+  !WRITE(*, nml)
+END PROGRAM p
diff --git a/gcc/testsuite/gfortran.dg/dtio_4.f90 b/gcc/testsuite/gfortran.dg/dtio_4.f90
index 5323194a..44352c1b 100644
--- a/gcc/testsuite/gfortran.dg/dtio_4.f90
+++ b/gcc/testsuite/gfortran.dg/dtio_4.f90
@@ -96,7 +96,7 @@ program test1
   if (iomsg.ne.'SUCCESS') call abort
   if (any(udt1%myarray.ne.result_array)) call abort
   close(10)
-  open (10, form='formatted')
+  open (10, form='formatted', status='scratch')
   write (10, '(dt)') 

[PATCH] rs6000: Fix gcc.target/powerpc/gcse-1.c for PIC (PR43496)

2017-03-28 Thread Segher Boessenkool
With PIC a @ha relocation isn't generated, so skip that test then.
Tested with {-m32,-m64}{,-fPIC,-fpic}; committing to trunk.


Segher


2017-03-28  Segher Boessenkool  

gcc/testsuite/
PR testsuite/43496
* gcc.target/powerpc/gcse-1.c: Skip scan-assembler-times "@ha" if
generating PIC code.

---
 gcc/testsuite/gcc.target/powerpc/gcse-1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.target/powerpc/gcse-1.c 
b/gcc/testsuite/gcc.target/powerpc/gcse-1.c
index 799cde1..ff74048 100644
--- a/gcc/testsuite/gcc.target/powerpc/gcse-1.c
+++ b/gcc/testsuite/gcc.target/powerpc/gcse-1.c
@@ -1,6 +1,6 @@
 /* { dg-do compile { target { *-*-linux* && ilp32 } } } */
 /* { dg-options "-O2" } */
-/* { dg-final { scan-assembler-times "@ha" 1 } } */
+/* { dg-final { scan-assembler-times "@ha" 1 { target { ! fpic } } } } */
 
 
 /* Test for PR 7003, address of array loaded int register
-- 
1.9.3



Re: [PATCH, testsuite] Allow braces around relative line numbers

2017-03-28 Thread Jakub Jelinek
On Tue, Mar 28, 2017 at 08:27:54AM +0200, Tom de Vries wrote:
> this patch fixes testsuite PR80220 - "relative line numbers don't work when
> put between braces".

What is the advantage of putting the line numbers between braces?
Isn't it easier to just drop those?

Jakub


Re: OpenACC default clause maintenance

2017-03-28 Thread Jakub Jelinek
On Tue, Mar 28, 2017 at 11:35:35AM +0200, Thomas Schwinge wrote:
> I noticed that in C++, for a directive like:
> 
> #pragma acc parallel default (hello)
> 
> ... we currently print two error messages for the same location:
> 
> [...]:35:30: error: expected 'none' before 'hello'
> [...]:35:30: error: expected ')' before 'hello'
> 
> I think it should be enough to just print the first syntax error (which
> is what we do for C).  I also generally beefed up testing of the OpenACC
> default clause in C, C++, Fortran.  OK for trunk in next stage 1 (I
> suppose)?  For now committed to gomp-4_0-branch in r246526:
> 
> commit b11ff2d0f10ef2e2005ccac0d84a02c39117ef9a
> Author: tschwinge 
> Date:   Tue Mar 28 09:34:03 2017 +
> 
> OpenACC default clause maintenance
> 
> gcc/cp/
> * parser.c (cp_parser_omp_clause_default): Avoid printing more
> than one syntax error message.
> gcc/testsuite/
> * c-c++-common/goacc/data-default-1.c: Remove file.
> * c-c++-common/goacc/default-1.c: New file.
> * c-c++-common/goacc/default-2.c: Likewise.
> * c-c++-common/goacc/default-3.c: Likewise.
> * c-c++-common/goacc/default-4.c: Likewise.
> * gfortran.dg/goacc/default.f95: Remove file.
> * gfortran.dg/goacc/default-1.f95: New file.
> * gfortran.dg/goacc/default-2.f: Likewise.
> * gfortran.dg/goacc/default-3.f95: Likewise.
> * gfortran.dg/goacc/default-4.f: Likewise.

The parser.c change is fine for stage1, but I wonder why are you removing
the tests.  If you want to rename them and perhaps update, state so in the
ChangeLog and svn mv them, but the removals + addition without any link looks
weird.

Jakub


New Spanish PO file for 'gcc' (version 7.1-b20170226)

2017-03-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-b20170226.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.




patch to fix PR80193

2017-03-28 Thread Vladimir Makarov

The following patch fixes

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80193

The patch was successfully bootstrapped on x86-64.

Committed as rev. 246554.


Index: ChangeLog
===
--- ChangeLog	(revision 246553)
+++ ChangeLog	(working copy)
@@ -1,3 +1,8 @@
+2017-03-28  Vladimir Makarov  
+
+	PR rtl-optimization/80193
+	* ira.c (ira): Do not check allocation for LRA.
+
 2017-03-28  Alexander Monakov  
 
 	* config/nvptx/nvptx-protos.h (nvptx_output_simt_enter): Declare.
Index: ira.c
===
--- ira.c	(revision 246536)
+++ ira.c	(working copy)
@@ -5334,7 +5334,6 @@
reg_alternate_class (old_regno),
reg_allocno_class (old_regno));
 }
-
 	}
 	  else
 	{
@@ -5370,7 +5369,14 @@
   calculate_allocation_cost ();
 
 #ifdef ENABLE_IRA_CHECKING
-  if (ira_conflicts_p)
+  if (ira_conflicts_p && ! ira_use_lra_p)
+/* Opposite to reload pass, LRA does not use any conflict info
+   from IRA.  We don't rebuild conflict info for LRA (through
+   ira_flattening call) and can not use the check here.  We could
+   rebuild this info for LRA in the check mode but there is a risk
+   that code generated with the check and without it will be a bit
+   different.  Calling ira_flattening in any mode would be a
+   wasting CPU time.  So do not check the allocation for LRA.  */
 check_allocation ();
 #endif
 
Index: testsuite/ChangeLog
===
--- testsuite/ChangeLog	(revision 246553)
+++ testsuite/ChangeLog	(working copy)
@@ -1,3 +1,8 @@
+2017-03-28  Vladimir Makarov  
+
+	PR rtl-optimization/80193
+	* gcc.target/i386/pr80193.c: New.
+
 2017-03-28  Janus Weil  
 
 	PR fortran/78661
Index: testsuite/gcc.target/i386/pr80193.c
===
--- testsuite/gcc.target/i386/pr80193.c	(nonexistent)
+++ testsuite/gcc.target/i386/pr80193.c	(working copy)
@@ -0,0 +1,196 @@
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+
+int printf (const char *, ...);
+
+char a, e, h, ag, ak, am, ar, ay, az, bc, bd, k, l;
+int f, i, n, o, c, ac, ad, p, ah, s, aj, al, an, b, ao, aq, at, av, be, t, u, g, q, r, ai, **aa, ap;
+
+int d (int v)
+{ 
+  return v + a;
+}
+
+int j (char v, char w)
+{ 
+  return v - w;
+}
+
+void m (int p)
+{
+}
+
+static void bf ()
+{ 
+  int bg[240], bi, bk, bl, bj, bm = -1;
+  const int *bh;
+  if (h)
+{ 
+  int bn, bo;
+  while (1)
+{ 
+  int *bp = 
+  const int **bq = , **br = bq;
+  while (av)
+while (ah)
+  ;
+  int bs = r, bt;
+  if (bt)
+break;
+bu:
+  for (; r; r = d (r))
+{ 
+  *bp = j (q && b, 0);
+  if (n)
+u = b;
+  if (u && ak)
+p = 0;
+}
+  if (c)
+{ 
+  while (a)
+while (r)
+  { 
+int bw = ar, bx = an;
+  by:
+printf ("%d\n", an);
+while (ao)
+  while (bw)
+{ 
+  a = !g || f / g;
+  if (i)
+az = i;
+  l = j (q && bh, 5);
+  if (n != 0)
+t = l / n;
+  if (t)
+while (bo)
+  ;
+}
+while (a)
+  ;
+if (s)
+  while (bx)
+while (1)
+  { 
+if (r)
+  break;
+*aa || q;
+  }
+while (at)
+  ;
+  }
+  while (av)
+if (b)
+  goto by;
+  while (bl)
+while (1)
+  { 
+if (r)
+  break;
+while (ag)
+  if (bi)
+printf ("%d\n", 0);
+if (bk)
+  { 
+bo = bn = bi = printf ("");
+goto bz;
+  }
+while (o)
+  if (a)
+{ 
+  while (1)
+;
+ca:
+  ;
+}
+if (ap)
+ 

Go patch committed: don't crash returning multiple zero-sized values

2017-03-28 Thread Ian Lance Taylor
In GCC PR 80226 Than reports a Go frontend crash when compiling a
function that returns multiple zero-sized values.  This patch that he
wrote fixes the problem.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian


2017-03-28  Than McIntosh  

PR go/80226
* go-gcc.cc (Gcc_backend::return_statement): Check for
void_type_node when checking result size.
Index: gcc/go/go-gcc.cc
===
--- gcc/go/go-gcc.cc(revision 246552)
+++ gcc/go/go-gcc.cc(working copy)
@@ -2081,7 +2081,8 @@ Gcc_backend::return_statement(Bfunction*
   // If the result size is zero bytes, we have set the function type
   // to have a result type of void, so don't return anything.
   // See the function_type method.
-  if (int_size_in_bytes(TREE_TYPE(result)) == 0)
+  tree res_type = TREE_TYPE(result);
+  if (res_type == void_type_node || int_size_in_bytes(res_type) == 0)
 {
   tree stmt_list = NULL_TREE;
   for (std::vector::const_iterator p = vals.begin();


Re: [Patch, Fortran, OOP] PR 78661: Namelist output missing object designator under DTIO

2017-03-28 Thread Janus Weil
Committed as r246546:

https://gcc.gnu.org/viewcvs/gcc?view=revision=246546

Cheers,
Janus



2017-03-27 23:03 GMT+02:00 Janus Weil :
> Forgot to mention: The patch was pre-approved by Jerry, but of course
> I'm happy to make corrections (if necessary).
>
> Cheers,
> Janus
>
>
> 2017-03-27 22:50 GMT+02:00 Janus Weil :
>> Hi all,
>>
>> I intend to commit the attached patch for a problem with derived-type
>> I/O and namelist output by tomorrow, if there are no objections. The
>> dtio_25.f90 test case needed some adjustments (see the discussion on
>> bugzilla) and still contains a FIXME note, which will be fixed by
>> Jerry's upcoming patch for PR 78670, I hope.
>>
>> Cheers,
>> Janus


[PATCH, i386]: Allow -mpreferred-stack-boundary=3 for 64-bit targets independently of SSE (PR 53383)

2017-03-28 Thread Uros Bizjak
Hello!

As argued in the PR [1], limiting -mpreferred-stack-boundary=3 only
for non-SSE 64bit targets represent artificial limitation, restricting
compiler functionality and user freedom.

Attached patch allows -mpreferred-stack-boundary=3 in all cases. The
compiler will align stack when needed, imposing a small runtime
penalty for functions that require 16-byte alignment.

2017-03-28  Uros Bizjak  

PR target/53383
* config/i386/i386.c (ix86_option_override_internal): Always
allow -mpreferred-stack-boundary=3 for 64-bit targets.

testsuite/ChangeLog:

2017-03-28  Uros Bizjak  

PR target/53383
* gcc.target/i386/pr53383-1.c (dg-options): Remove -mno-sse.
* gcc.target/i386/pr53383-2.c (dg-options): Ditto.
* gcc.target/i386/pr53383-3.c (dg-options): Ditto.

Patch was bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.

Committed to mainline SVN.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383#c25

Uros.
Index: config/i386/i386.c
===
--- config/i386/i386.c  (revision 246531)
+++ config/i386/i386.c  (working copy)
@@ -5927,9 +5927,8 @@ ix86_option_override_internal (bool main_args_p,
   ix86_preferred_stack_boundary = PREFERRED_STACK_BOUNDARY_DEFAULT;
   if (opts_set->x_ix86_preferred_stack_boundary_arg)
 {
-  int min = (TARGET_64BIT_P (opts->x_ix86_isa_flags)
-? (TARGET_SSE_P (opts->x_ix86_isa_flags) ? 4 : 3) : 2);
-  int max = (TARGET_SEH ? 4 : 12);
+  int min = TARGET_64BIT_P (opts->x_ix86_isa_flags)? 3 : 2;
+  int max = TARGET_SEH ? 4 : 12;
 
   if (opts->x_ix86_preferred_stack_boundary_arg < min
  || opts->x_ix86_preferred_stack_boundary_arg > max)
Index: testsuite/gcc.target/i386/pr53383-1.c
===
--- testsuite/gcc.target/i386/pr53383-1.c   (revision 246531)
+++ testsuite/gcc.target/i386/pr53383-1.c   (working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -mno-sse -mpreferred-stack-boundary=3" } */
+/* { dg-options "-O2 -mpreferred-stack-boundary=3" } */
 
 int
 bar (int x)
Index: testsuite/gcc.target/i386/pr53383-2.c
===
--- testsuite/gcc.target/i386/pr53383-2.c   (revision 246531)
+++ testsuite/gcc.target/i386/pr53383-2.c   (working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -mno-sse -mpreferred-stack-boundary=3 
-mincoming-stack-boundary=3" } */
+/* { dg-options "-O2 -mpreferred-stack-boundary=3 -mincoming-stack-boundary=3" 
} */
 
 int
 bar (int x)
Index: testsuite/gcc.target/i386/pr53383-3.c
===
--- testsuite/gcc.target/i386/pr53383-3.c   (revision 246531)
+++ testsuite/gcc.target/i386/pr53383-3.c   (working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -mno-sse -mincoming-stack-boundary=3 
-mpreferred-stack-boundary=3" } */
+/* { dg-options "-O2 -mincoming-stack-boundary=3 -mpreferred-stack-boundary=3" 
} */
 
 int
 bar (int x)


Re: [patch v2] Get rid of stack trampolines for nested functions (1/4)

2017-03-28 Thread Eric Botcazou
> That needs to use ptr_mode, not Pmode.

I don't think so, the whole computation is in Pmode.  Could you try something 
similar to what is done in the 'else' arm of the big surrounding conditional?

-- 
Eric Botcazou


[PATCH] Fix PR target/66015 for MIPS.

2017-03-28 Thread Toma Tabacu
Hi,

The gcc.dg/ipa/iinline-attr.c test has been failing for MIPS when using the n32 
and n64 ABIs.

These two ABIs imply a 64-bit target, which means that the align_loops,
align_jumps, and align_functions flags are set to 8 by default.
Because the MIPS backend doesn't use the TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE 
hook,
those default values will not be propagated through the __optimize__ attribute.

This was a known issue (PR target/66015) and was fixed for other architectures.

This patch implements the TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE for MIPS
and uses it to properly preserve the alignment flags.

Tested with mips-mti-elf.

Because we are in stage 4, we could temporarily xfail iinline-attr.c for MIPS 
instead.

Regards,
Toma

gcc/

* config/mips/mips.c (mips_default_align): New function.
(mips_set_compression_mode): Use mips_default_align to set alignment
flags.
(mips_override_options_after_change): New function for the new hook.
(TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE): New hook.

diff --git a/gcc/config/mips/mips.c b/gcc/config/mips/mips.c
index d1deb52..65e105b 100644
--- a/gcc/config/mips/mips.c
+++ b/gcc/config/mips/mips.c
@@ -19360,6 +19360,21 @@ mips_output_mi_thunk (FILE *file, tree thunk_fndecl 
ATTRIBUTE_UNUSED,
   reload_completed = 0;
 }
 

+/* Provide default values for align_* for 64-bit targets.  */
+
+static void
+mips_default_align (struct gcc_options *opts)
+{
+  if (TARGET_64BIT)
+{
+  if (opts->x_align_loops == 0)
+   opts->x_align_loops = 8;
+  if (opts->x_align_jumps == 0)
+   opts->x_align_jumps = 8;
+  if (opts->x_align_functions == 0)
+   opts->x_align_functions = 8;
+}
+}
 
 /* The last argument passed to mips_set_compression_mode,
or negative if the function hasn't been called yet.  */
@@ -19450,15 +19465,7 @@ mips_set_compression_mode (unsigned int 
compression_mode)
target_flags &= ~MASK_BRANCHLIKELY;
 
   /* Provide default values for align_* for 64-bit targets.  */
-  if (TARGET_64BIT)
-   {
- if (align_loops == 0)
-   align_loops = 8;
- if (align_jumps == 0)
-   align_jumps = 8;
- if (align_functions == 0)
-   align_functions = 8;
-   }
+  mips_default_align (_options);
 
   targetm.min_anchor_offset = -32768;
   targetm.max_anchor_offset = 32767;
@@ -19598,6 +19605,14 @@ mips_set_tune (const struct mips_cpu_info *info)
 }
 }
 
+/* Implement TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE.  */
+
+static void
+mips_override_options_after_change (void)
+{
+  mips_default_align (_options);
+}
+
 /* Implement TARGET_OPTION_OVERRIDE.  */
 
 static void
@@ -22292,6 +22307,8 @@ mips_promote_function_mode (const_tree type 
ATTRIBUTE_UNUSED,
 
 #undef TARGET_OPTION_OVERRIDE
 #define TARGET_OPTION_OVERRIDE mips_option_override
+#undef  TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE
+#define TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE mips_override_options_after_change
 
 #undef TARGET_LEGITIMIZE_ADDRESS
 #define TARGET_LEGITIMIZE_ADDRESS mips_legitimize_address



[PATCH] PR libstdc++/80137 use std::nextafter instead of looping

2017-03-28 Thread Jonathan Wakely

For gcc-6 I fixed a bug in generate_canonical that allowed it to
return a value outside the permitted range (due to rounding), but that
was done by looping until we got a value that was in range, which
violates the complexity requirements.

John Salmon suggested a better fix in bugzilla, which is what is used
here.

PR libstdc++/80137
* include/bits/random.tcc (generate_canonical): Use std::nextafter
or numeric_limits::epsilon() to reduce out-of-range values.
* testsuite/26_numerics/random/uniform_real_distribution/operators/
64351.cc: Verify complexity requirement is met.

Tested powerpc64le-linux, committed to trunk.

This needs to be backported to gcc-6-branch too.

commit 611ce493bb4d47c153ef8b07721433f9d62dfe0d
Author: redi 
Date:   Tue Mar 28 16:09:49 2017 +

PR libstdc++/80137 use std::nextafter instead of looping

PR libstdc++/80137
* include/bits/random.tcc (generate_canonical): Use std::nextafter
or numeric_limits::epsilon() to reduce out-of-range values.
* testsuite/26_numerics/random/uniform_real_distribution/operators/
64351.cc: Verify complexity requirement is met.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@246542 
138bc75d-0d04-0410-961f-82ee72b054a4

diff --git a/libstdc++-v3/include/bits/random.tcc 
b/libstdc++-v3/include/bits/random.tcc
index 2d5582a..df05ebe 100644
--- a/libstdc++-v3/include/bits/random.tcc
+++ b/libstdc++-v3/include/bits/random.tcc
@@ -3323,18 +3323,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   const size_t __m = std::max(1UL,
  (__b + __log2r - 1UL) / __log2r);
   _RealType __ret;
-  do
+  _RealType __sum = _RealType(0);
+  _RealType __tmp = _RealType(1);
+  for (size_t __k = __m; __k != 0; --__k)
{
- _RealType __sum = _RealType(0);
- _RealType __tmp = _RealType(1);
- for (size_t __k = __m; __k != 0; --__k)
-   {
- __sum += _RealType(__urng() - __urng.min()) * __tmp;
- __tmp *= __r;
-   }
- __ret = __sum / __tmp;
+ __sum += _RealType(__urng() - __urng.min()) * __tmp;
+ __tmp *= __r;
+   }
+  __ret = __sum / __tmp;
+  if (__builtin_expect(__ret >= _RealType(1), 0))
+   {
+#if _GLIBCXX_USE_C99_MATH_TR1
+ __ret = std::nextafter(_RealType(1), _RealType(0));
+#else
+ __ret = _RealType(1)
+   - std::numeric_limits<_RealType>::epsilon() / _RealType(2);
+#endif
}
-  while (__builtin_expect(__ret >= _RealType(1), 0));
   return __ret;
 }
 
diff --git 
a/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/operators/64351.cc
 
b/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/operators/64351.cc
index ddb67e8..229fe9c 100644
--- 
a/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/operators/64351.cc
+++ 
b/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/operators/64351.cc
@@ -42,10 +42,18 @@ test02()
   std::mt19937 rng(8890);
   std::seed_seq sequence{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
   rng.seed(sequence);
-  rng.discard(12 * 629143 + 6);
-  float n =
-std::generate_canonical(rng);
-  VERIFY( n != 1.f );
+  rng.discard(12 * 629143);
+  std::mt19937 rng2{rng};
+  for (int i = 0; i < 20; ++i)
+  {
+float n =
+  std::generate_canonical(rng);
+VERIFY( n != 1.f );
+
+// PR libstdc++/80137
+rng2.discard(1);
+VERIFY( rng == rng2 );
+  }
 }
 
 int


Re: PR80218: Call CDCE fails to update the block profile

2017-03-28 Thread Jeff Law

On 03/28/2017 06:45 AM, Richard Sandiford wrote:

tree-call-cdce.c was updating the edge probabilities and counts but
it wasn't updating the corresponding block information.  Among other
things, this tricked the register allocator into thinking that the
libm call was relatively hot and that it wasn't worth assigning
call-clobbered registers to values that were live across the call.
With correct frequency information, the RA instead keeps x in the
first argument register and spills it only around the call.

Although the problem has been around for a long time, it became more
acute (and would only trigger for the first function in the testcase)
after r230488.  Until that patch, the code was specific to calls that
had no lhs, but that we still had to keep for their effect on errno.
After the patch we also used the code for calls with an lhs, provided
that the hardware could calculate the lhs directly.

This showed up as a significant performance drop in an internal
benchmark from GCC 5 to GCC 6.

Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK for trunk
and gcc-6-branch?

Thanks,
Richard


gcc/
PR tree-optimization/80218
* tree-call-cdce.c (shrink_wrap_one_built_in_call_with_conds):
Update block frequencies and counts.

gcc/testsuite/
PR tree-optimization/80218
* gcc.dg/pr80218.c: New test.


OK.  I went ahead and installed this for you.

Thanks,
Jeff


Re: [PATCH] Fix calls.c for a _complex type (PR ipa/80104).

2017-03-28 Thread Jeff Law

On 03/28/2017 02:09 AM, Richard Biener wrote:

On Mon, Mar 27, 2017 at 11:48 PM, Martin Jambor  wrote:

Hi,

On Mon, Mar 27, 2017 at 12:15:10PM -0600, Jeff Law wrote:

On 03/27/2017 05:40 AM, Martin Liška wrote:

Hello.

There's alternative approach suggested by Martin Jambor.
Patch can bootstrap on ppc64le-redhat-linux and survives regression tests and
s390x cross compiler does not ICE.

Martin

2017-03-23  Martin Liska  

PR ipa/80104
* cgraphunit.c (cgraph_node::expand_thunk): Mark argument of a
thunk call as DECL_GIMPLE_REG_P when vector or complex type.

Can you fix the documentation for DECL_GIMPLE_REG_P to indiate that it can
be set on parameters.

In gimplify_function_tree we have this:

 for (parm = DECL_ARGUMENTS (fndecl); parm ; parm = DECL_CHAIN (parm))
{
  /* Preliminarily mark non-addressed complex variables as eligible
 for promotion to gimple registers.  We'll transform their uses
 as we find them.  */
  if ((TREE_CODE (TREE_TYPE (parm)) == COMPLEX_TYPE
   || TREE_CODE (TREE_TYPE (parm)) == VECTOR_TYPE)
  && !TREE_THIS_VOLATILE (parm)
  && !needs_to_live_in_memory (parm))
DECL_GIMPLE_REG_P (parm) = 1;
}

Aren't you essentially doing the same thing for thunks?


Yes.


Does it make sense
to pull that into a little function and just call it from both places?


Possibly...



If not, do we need to add the !TREE_THIS_VOLATILE and
!needs_to_live_in_memory checks to the thunks version?


...although if any of these checks fail, the bug will re-surface.

I do not really know what a volatile parameter means, let alone a
volatile parameter of a hunk.  Unless, I am mistaken, hunk parameters
are never made TREE_ADDRESSABLE, so needs_to_live_in_memory can be
omitted.


Yeah, I think the thunk case is quite constrained so the revised patch
is ok with me.
The volatile check is somewhat superfluous as even DECL_GIMPLE_REG_P volatiles
are not written into-SSA (is_gimple_reg () still returns false).  Likewise for
needs_to_live_in_memory.
Works for me -- I raised those potential issues because of the 
inconsistency with the existing code for normal functions.  I did not 
dig into why we have those additional checks for normal functions.


So, no objections here.

Jeff



[PATCH] Fix PR78644

2017-03-28 Thread Richard Biener

I am testing the following patch that avoids putting non-final copies
into the CCP lattice which eventually results in released SSA names in
the IL.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Richard.

2017-03-28  Richard Biener  

PR tree-optimization/78644
* tree-ssa-ccp.c (evaluate_stmt): When we may not use the value
of a simplification result we may not use it at all.

* gcc.dg/pr78644-1.c: New testcase.
* gcc.dg/pr78644-2.c: Likewise.

Index: gcc/tree-ssa-ccp.c
===
*** gcc/tree-ssa-ccp.c  (revision 246527)
--- gcc/tree-ssa-ccp.c  (working copy)
*** evaluate_stmt (gimple *stmt)
*** 1749,1766 
fold_defer_overflow_warnings ();
simplified = ccp_fold (stmt);
if (simplified
! && TREE_CODE (simplified) == SSA_NAME
  /* We may not use values of something that may be simulated again,
 see valueize_op_1.  */
! && (SSA_NAME_IS_DEFAULT_DEF (simplified)
! || ! prop_simulate_again_p (SSA_NAME_DEF_STMT (simplified
!   {
! ccp_prop_value_t *val = get_value (simplified);
! if (val && val->lattice_val != VARYING)
{
! fold_undefer_overflow_warnings (true, stmt, 0);
! return *val;
}
}
is_constant = simplified && is_gimple_min_invariant (simplified);
fold_undefer_overflow_warnings (is_constant, stmt, 0);
--- 1749,1772 
fold_defer_overflow_warnings ();
simplified = ccp_fold (stmt);
if (simplified
! && TREE_CODE (simplified) == SSA_NAME)
!   {
  /* We may not use values of something that may be simulated again,
 see valueize_op_1.  */
! if (SSA_NAME_IS_DEFAULT_DEF (simplified)
! || ! prop_simulate_again_p (SSA_NAME_DEF_STMT (simplified)))
{
! ccp_prop_value_t *val = get_value (simplified);
! if (val && val->lattice_val != VARYING)
!   {
! fold_undefer_overflow_warnings (true, stmt, 0);
! return *val;
!   }
}
+ else
+   /* We may also not place a non-valueized copy in the lattice
+  as that might become stale if we never re-visit this stmt.  */
+   simplified = NULL_TREE;
}
is_constant = simplified && is_gimple_min_invariant (simplified);
fold_undefer_overflow_warnings (is_constant, stmt, 0);
Index: gcc/testsuite/gcc.dg/pr78644-1.c
===
*** gcc/testsuite/gcc.dg/pr78644-1.c(nonexistent)
--- gcc/testsuite/gcc.dg/pr78644-1.c(working copy)
***
*** 0 
--- 1,21 
+ /* { dg-do compile { target int128 } } */
+ /* { dg-options "-Og -fipa-cp -w -Wno-psabi" } */
+ 
+ typedef unsigned __int128 u128;
+ typedef unsigned __int128 V __attribute__ ((vector_size (64)));
+ 
+ V x4;
+ 
+ static V
+ bar (u128 x2, u128 x3)
+ {
+   while (x4[0]--)
+ x2 /= x3 >>= 1;
+   return x2 + x3 + x4;
+ }
+ 
+ void
+ foo (void)
+ {
+   bar (0, 0);
+ }
Index: gcc/testsuite/gcc.dg/pr78644-2.c
===
*** gcc/testsuite/gcc.dg/pr78644-2.c(nonexistent)
--- gcc/testsuite/gcc.dg/pr78644-2.c(working copy)
***
*** 0 
--- 1,20 
+ /* { dg-do compile { target int128 } } */
+ /* { dg-options "-Og -finline-functions-called-once -w -Wno-psabi" } */
+ 
+ typedef unsigned V __attribute__ ((vector_size (64)));
+ typedef unsigned __int128 U __attribute__ ((vector_size (64)));
+ 
+ U
+ bar4 (U u0, U u1)
+ {
+   if (u1[0])
+ u1 <<= 1;
+   return u0 + u1;
+ }
+ 
+ V
+ foo (U u, V v)
+ {
+   v |= (unsigned)bar4(u, (U){})[0];
+   return v;
+ }


Re: [PATCH] Fix PR80158

2017-03-28 Thread Bill Schmidt
On Mar 24, 2017, at 3:19 AM, Richard Biener  wrote:
> 
> On Thu, Mar 23, 2017 at 7:20 PM, Bill Schmidt
>  wrote:
>> Hi,
>> 
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80158 reports an ICE in
>> SLSR while building 416.gamess on x86_64.  This is a latent (but
>> previously harmless) bug that was exposed by the fix for PR80054.
>> When replacing any statement with a strength reduction, SLSR updates
>> the candidate statement S associated with the associated candidate
>> record in the candidate table.  However, S may actually be associated
>> with two candidate records when an expression may be treated as
>> either a CAND_ADD or a CAND_MULT.  In this case, the second one can
>> be reached via the next_interp field.
> 
> Hmm, the following code in SLSR suggests there may be more than
> one such alternate candidate:
> 
>  while (arg_cand->kind != CAND_ADD && arg_cand->kind != CAND_PHI)
>{
>  if (!arg_cand->next_interp)
>return;
> 
>  arg_cand = lookup_cand (arg_cand->next_interp);
>}

You're right, although with the current design there is never more than one
alternate interpretation.  So the patch is correct now, but I should make it 
handle
additional alternate interpretations to future-proof it.  I'll fix that later 
this week.
Thanks for catching this.

>> In the excerpt from 416.gamess, the first candidate record was
>> updated when its statement was replaced, but the next-interp record
>> was not.  Later, that record was used as a basis for another tree
>> of strength-reduction candidates, but since it now pointed to an
>> orphaned statement without a basic block, the ICE occurred when
>> checking dominance against the statement's block.
>> 
>> The fix is simply to ensure that the next_interp record is always
>> updated when present.
>> 
>> I've bootstrapped and tested this on powerpc64le-unknown-linux-gnu
>> with no regressions.  I tested that the standalone test works on
>> x86_64 with this fix, but I have been unable to perform an x86_64
>> regstrap because the machine I have access to has insufficient
>> disk space. :/  I would appreciate it if you could do this for me.
>> 
>> Assuming no problems with x86_64 regstrap, is this ok for trunk?
>> 
>> Note: I will be unreachable from now until next Tuesday (i.e.,
>> returning the 28th).  If needed, please feel free to commit the
>> patch on my behalf.  Otherwise I will attend to it when I return.
> 
> I'll do a regstrap and gamess build and will commit if that succeeds.

Thank you, I appreciate you handling this for me in my absence!

Bill

> 
> The above can be addressed as followup.
> 
> Thanks,
> Richard.
> 
>> Thanks!
>> Bill
>> 
>> 
>> [gcc]
>> 
>> 2017-03-23  Bill Schmidt  
>> 
>>PR tree-optimization/80158
>>* gimple-ssa-strength-reduction.c (replace_mult_candidate): When
>>replacing a candidate statement, also replace it for the
>>candidate's alternate interpretation.
>>(replace_rhs_if_not_dup): Likewise.
>>(replace_one_candidate): Likewise.
>> 
>> [gcc/testsuite]
>> 
>> 2017-03-23  Bill Schmidt  
>> 
>>PR tree-optimization/80158
>>* gfortran.fortran-torture/compile/pr80158.f: New file.
>> 
>> 
>> Index: gcc/gimple-ssa-strength-reduction.c
>> ===
>> --- gcc/gimple-ssa-strength-reduction.c (revision 246420)
>> +++ gcc/gimple-ssa-strength-reduction.c (working copy)
>> @@ -2089,6 +2089,8 @@ replace_mult_candidate (slsr_cand_t c, tree basis_
>>  gimple_set_location (copy_stmt, gimple_location (c->cand_stmt));
>>  gsi_replace (, copy_stmt, false);
>>  c->cand_stmt = copy_stmt;
>> + if (c->next_interp)
>> +   lookup_cand (c->next_interp)->cand_stmt = copy_stmt;
>>  if (dump_file && (dump_flags & TDF_DETAILS))
>>stmt_to_print = copy_stmt;
>>}
>> @@ -2118,6 +2120,8 @@ replace_mult_candidate (slsr_cand_t c, tree basis_
>>  basis_name, bump_tree);
>>  update_stmt (gsi_stmt (gsi));
>>   c->cand_stmt = gsi_stmt (gsi);
>> + if (c->next_interp)
>> +   lookup_cand (c->next_interp)->cand_stmt = gsi_stmt (gsi);
>>  if (dump_file && (dump_flags & TDF_DETAILS))
>>stmt_to_print = gsi_stmt (gsi);
>>}
>> @@ -3405,6 +3409,8 @@ replace_rhs_if_not_dup (enum tree_code new_code, t
>>   gimple_assign_set_rhs_with_ops (, new_code, new_rhs1, new_rhs2);
>>   update_stmt (gsi_stmt (gsi));
>>   c->cand_stmt = gsi_stmt (gsi);
>> +  if (c->next_interp)
>> +   lookup_cand (c->next_interp)->cand_stmt = gsi_stmt (gsi);
>> 
>>   if (dump_file && (dump_flags & TDF_DETAILS))
>>return gsi_stmt (gsi);
>> @@ -3511,6 +3517,8 @@ replace_one_candidate 

RE: [PATCH,testsuite] Skip pic-3,4.c and pie-3,4.c for mips*-*-linux-*.

2017-03-28 Thread Toma Tabacu
> From: Matthew Fortune
> 
> Given the acceptance that MIPS PIC behaviour is semi-unique then checking
> MIPS
> complies with the rules around pre-processor behaviour doesn't add much
> value.
> I'm happy to skip these tests on the basis that software can't make the same
> assumptions about MIPS and __PIC__ as other architectures do.
> 
> OK to commit.
> 
> Thanks,
> Matthew

Committed as r246533.

Thanks,
Toma


PR80218: Call CDCE fails to update the block profile

2017-03-28 Thread Richard Sandiford
tree-call-cdce.c was updating the edge probabilities and counts but
it wasn't updating the corresponding block information.  Among other
things, this tricked the register allocator into thinking that the
libm call was relatively hot and that it wasn't worth assigning
call-clobbered registers to values that were live across the call.
With correct frequency information, the RA instead keeps x in the
first argument register and spills it only around the call.

Although the problem has been around for a long time, it became more
acute (and would only trigger for the first function in the testcase)
after r230488.  Until that patch, the code was specific to calls that
had no lhs, but that we still had to keep for their effect on errno.
After the patch we also used the code for calls with an lhs, provided
that the hardware could calculate the lhs directly.

This showed up as a significant performance drop in an internal
benchmark from GCC 5 to GCC 6.

Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK for trunk
and gcc-6-branch?

Thanks,
Richard


gcc/
PR tree-optimization/80218
* tree-call-cdce.c (shrink_wrap_one_built_in_call_with_conds):
Update block frequencies and counts.

gcc/testsuite/
PR tree-optimization/80218
* gcc.dg/pr80218.c: New test.

diff --git a/gcc/testsuite/gcc.dg/pr80218.c b/gcc/testsuite/gcc.dg/pr80218.c
new file mode 100644
index 000..8669ee1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr80218.c
@@ -0,0 +1,28 @@
+/* { dg-options "-O2 -fdump-rtl-ira-details-blocks" } */
+/* { dg-require-effective-target c99_runtime } */
+
+#include 
+
+void foo (float *);
+
+void
+f1 (float *x)
+{
+  x[0] = sqrtf (x[0]);
+}
+
+void
+f2 (float *x)
+{
+  sqrtf (x[0]);
+  foo (x);
+}
+
+void
+f3 (float *x)
+{
+  acosf (x[0]);
+  foo (x);
+}
+
+/* { dg-final { scan-rtl-dump-not "Invalid sum" "ira" } } */
diff --git a/gcc/tree-call-cdce.c b/gcc/tree-call-cdce.c
index 10d2c47..7bd242c 100644
--- a/gcc/tree-call-cdce.c
+++ b/gcc/tree-call-cdce.c
@@ -847,10 +847,12 @@ shrink_wrap_one_built_in_call_with_conds (gcall *bi_call, 
vec  conds,
   gsi_insert_before (_call_bsi, c, GSI_SAME_STMT);
   cond_expr = c;
 }
-  nconds--;
   ci++;
   gcc_assert (cond_expr && gimple_code (cond_expr) == GIMPLE_COND);
 
+  typedef std::pair edge_pair;
+  auto_vec edges;
+
   bi_call_in_edge0 = split_block (bi_call_bb, cond_expr);
   bi_call_in_edge0->flags &= ~EDGE_FALLTHRU;
   bi_call_in_edge0->flags |= EDGE_FALSE_VALUE;
@@ -859,17 +861,11 @@ shrink_wrap_one_built_in_call_with_conds (gcall *bi_call, 
vec  conds,
   join_tgt_in_edge_fall_thru = make_edge (guard_bb, join_tgt_bb,
   EDGE_TRUE_VALUE);
 
-  bi_call_in_edge0->probability = REG_BR_PROB_BASE * ERR_PROB;
-  bi_call_in_edge0->count =
-  apply_probability (guard_bb->count,
-bi_call_in_edge0->probability);
-  join_tgt_in_edge_fall_thru->probability =
-  inverse_probability (bi_call_in_edge0->probability);
-  join_tgt_in_edge_fall_thru->count =
-  guard_bb->count - bi_call_in_edge0->count;
+  edges.reserve (nconds);
+  edges.quick_push (edge_pair (bi_call_in_edge0, join_tgt_in_edge_fall_thru));
 
   /* Code generation for the rest of the conditions  */
-  while (nconds > 0)
+  for (unsigned int i = 1; i < nconds; ++i)
 {
   unsigned ci0;
   edge bi_call_in_edge;
@@ -885,7 +881,6 @@ shrink_wrap_one_built_in_call_with_conds (gcall *bi_call, 
vec  conds,
   gsi_insert_before (_bsi, c, GSI_SAME_STMT);
   cond_expr = c;
 }
-  nconds--;
   ci++;
   gcc_assert (cond_expr && gimple_code (cond_expr) == GIMPLE_COND);
   guard_bb_in_edge = split_block (guard_bb, cond_expr);
@@ -893,14 +888,51 @@ shrink_wrap_one_built_in_call_with_conds (gcall *bi_call, 
vec  conds,
   guard_bb_in_edge->flags |= EDGE_TRUE_VALUE;
 
   bi_call_in_edge = make_edge (guard_bb, bi_call_bb, EDGE_FALSE_VALUE);
+  edges.quick_push (edge_pair (bi_call_in_edge, guard_bb_in_edge));
+}
+
+  /* Now update the probability and profile information, processing the
+ guards in order of execution.
+
+ There are two approaches we could take here.  On the one hand we
+ could assign a probability of X to the call block and distribute
+ that probability among its incoming edges.  On the other hand we
+ could assign a probability of X to each individual call edge.
+
+ The choice only affects calls that have more than one condition.
+ In those cases, the second approach would give the call block
+ a greater probability than the first.  However, the difference
+ is only small, and our chosen X is a pure guess anyway.
+
+ Here we take the second approach because it's slightly simpler
+ and because it's easy to see that it doesn't lose profile counts.  */
+  bi_call_bb->count = 0;
+  bi_call_bb->frequency = 0;
+  while (!edges.is_empty ())
+{
+  edge_pair e = 

[PATCH] Add _GLIBCXX_RELEASE macro to "Using" section of manual

2017-03-28 Thread Jonathan Wakely

This documents the new _GLIBCXX_RELEASE macro in the main manual, not
just the appendix on ABI version history.

* doc/xml/manual/abi.xml: Add xml:id anchor.
* doc/xml/manual/using.xml (manual.intro.using.macros): Document
_GLIBCXX_RELEASE. Link to new anchor for __GLIBCXX__ notes.
(concurrency.io.structure): Add markup.
* doc/html/*: Regenerate.

Committing to trunk shortly.
commit 4bf47e5a673d2d2be63b5bad6088c4d1ab29419e
Author: Jonathan Wakely 
Date:   Tue Mar 28 13:37:36 2017 +0100

Add _GLIBCXX_RELEASE macro to "Using" section of manual

* doc/xml/manual/abi.xml: Add xml:id anchor.
* doc/xml/manual/using.xml (manual.intro.using.macros): Document
_GLIBCXX_RELEASE. Link to new anchor for __GLIBCXX__ notes.
(concurrency.io.structure): Add markup.
* doc/html/*: Regenerate.

diff --git a/libstdc++-v3/doc/xml/manual/abi.xml 
b/libstdc++-v3/doc/xml/manual/abi.xml
index 3ef57d5..e79bf8c 100644
--- a/libstdc++-v3/doc/xml/manual/abi.xml
+++ b/libstdc++-v3/doc/xml/manual/abi.xml
@@ -383,7 +383,7 @@ compatible.
 
 
 
-   
+   
 Incremental bumping of a library pre-defined macro. For releases
 before 3.4.0, the macro is __GLIBCPP__. For later
 releases, it's __GLIBCXX__. (The libstdc++ project
diff --git a/libstdc++-v3/doc/xml/manual/using.xml 
b/libstdc++-v3/doc/xml/manual/using.xml
index 3057a93..5c0e1b9 100644
--- a/libstdc++-v3/doc/xml/manual/using.xml
+++ b/libstdc++-v3/doc/xml/manual/using.xml
@@ -829,20 +829,37 @@ g++ -Winvalid-pch -I. -include stdc++.h -H -g -O2 
hello.cc -o test.exe
   general public.

 
-   Below is the macro which users may check for library version
+   Below are the macros which users may check for library version
   information. 
 
 
 
+  _GLIBCXX_RELEASE
+  
+   The major release number for libstdc++.  This macro is defined
+to the GCC major version that the libstdc++ headers belong to,
+as an integer constant.
+When compiling with GCC it has the same value as GCC's pre-defined
+macro __GNUC__.
+This macro can be used when libstdc++ is used with a non-GNU
+compiler where __GNUC__ is not defined, or has a
+different value that doesn't correspond to the libstdc++ version.
+This macro first appeared in the GCC 7.1 release and is not defined
+for GCC 6.x or older releases.
+  
+  
+
+
   __GLIBCXX__
   
-   The current version of
-libstdc++ in compressed ISO date format, as an unsigned
-long. For details on the value of this particular macro for a
-particular release, please consult the 
-ABI Policy and Guidelines appendix.
-
-
+   The revision date of the libstdc++ source code,
+in compressed ISO date format, as an unsigned
+long. For notes about using this macro and details on the value of
+this macro for a particular release, please consult the
+ABI History
+appendix.
+
+  
 
 
 
@@ -1669,10 +1686,11 @@ gcc version 4.1.2 20070925 (Red Hat 4.1.2-33)
   and efficiency.  You, the programmer, are always required to take care
   with multiple threads.

-   (As an example, the POSIX standard requires that C stdio FILE*
-   operations are atomic.  POSIX-conforming C libraries (e.g, on Solaris
-   and GNU/Linux) have an internal mutex to serialize operations on
-   FILE*s.  However, you still need to not do stupid things like calling
+   (As an example, the POSIX standard requires that C stdio
+   FILE* operations are atomic.  POSIX-conforming C libraries
+   (e.g, on Solaris and GNU/Linux) have an internal mutex to serialize
+   operations on FILE*s.
+   However, you still need to not do stupid things like calling
fclose(fs) in one thread followed by an access of
fs in another.)



Re: [PATCH PR80153]Always generate folded type conversion in tree-affine

2017-03-28 Thread Richard Biener
On Tue, Mar 28, 2017 at 2:01 PM, Bin Cheng  wrote:
> Hi,
> This patch is to fix PR80153.  As analyzed in the PR, root cause is 
> tree_affine lacks
> ability differentiating (unsigned)(ptr + offset) and (unsigned)ptr + 
> (unsigned)offset,
> even worse, it always returns the former expression in aff_combination_tree, 
> which
> is wrong if the original expression has the latter form.  The patch resolves 
> the issue
> by always returning the latter form expression, i.e, always trying to 
> generate folded
> expression.  Also as analyzed in comment, I think this change won't result in 
> substantial
> code gen difference.
> I also need to adjust get_computation_aff for test case 
> gcc.dg/tree-ssa/reassoc-19.c.
> Well, I think the changed behavior is correct, but for case the original 
> pointer candidate
> is chosen, it should be unnecessary to compute in uutype.  Also this 
> adjustment only
> generates (unsigned)(pointer + offset) which is generated by tree-affine.c.
> Bootstrap and test on x86_64 and AArch64.  Is it OK?

Hmm.  What is the desired goal?  To have all elts added have
comb->type as type?  Then
the type passed to add_elt_to_tree is redundant with comb->type.  It
looks like it
is always passed comb->type now.

ISTR from past work in this area that it was important for pointer
combinations to allow
both pointer and sizetype elts at least.

Your change is incomplete I think, for the scale == -1 and POINTER_TYPE_P case
elt is sizetype now, not of pointer type.  As said above, we are
trying to maintain
both pointer and sizetype elts with like:

  if (scale == 1)
{
  if (!expr)
{
  if (POINTER_TYPE_P (TREE_TYPE (elt)))
return elt;
  else
return fold_convert (type1, elt);
}

where your earilier fold to type would result in not all cases handled the same
(depending whether scale was -1 for example).

Thus - shouldn't we simply drop the type argument (or rather the comb one?
that wide_int_ext_for_comb looks weird given we get a widest_int as input
and all the other wide_int_ext_for_comb calls around).

And unconditionally convert to type, simplifying the rest of the code?

Richard.


> 2017-03-27  Bin Cheng  
>
> PR tree-optimization/80153
> * tree-affine.c (add_elt_to_tree): Convert to type as required
> by function's parameter.
> * tree-ssa-loop-ivopts.c (alloc_iv): Pass in consistent types.
> (get_computation_aff): Use utype directly for original candidate.
>
> gcc/testsuite/ChangeLog
> 2017-03-27  Bin Cheng  
>
> PR tree-optimization/80153
> * gcc.c-torture/execute/pr80153.c: New.


Re: [PATCH 02/2]Add newly created bb to correct loop when reverting if-conversion in vectorizer

2017-03-28 Thread Richard Biener
On Tue, Mar 28, 2017 at 2:01 PM, Bin Cheng  wrote:
> Hi,
> This patch is to fix a latent vectorizer bug uncovered by previous one.  
> Function optimize_mask_stores
> creates if-then structure in CFG in order to revert if-conversion 
> transformation.  It adds newly created
> then_bb to outer loop when vectorizing two levels loop nest and masked_store 
> is in the inner loop.
> Without this patch, gcc.dg/tree-ssa/pr71077.c would be broken.  Bootstrap and 
> test on AArch64, is it OK?

Ok.

Richard.

> 2017-03-27  Bin Cheng  
>
> * tree-vect-loop.c (optimize_mask_stores): Add bb to the right
> loop.


Re: [PATCH 01/2]Maintain irreducible region information in vectorizer peeling

2017-03-28 Thread Richard Biener
On Tue, Mar 28, 2017 at 2:01 PM, Bin Cheng  wrote:
> Hi,
> This patch fixes a latent bug in vectorizer, specifically, vect_do_peeling 
> doesn't mark newly created edge
> with irreducible flag if the vectorized loop is in irreducible region.  
> Function checking_verify_loop_structure
> needs to be explicitly called in vectorizer otherwise the issue is covered, 
> but I am okay if we should avoid
> this call.
> Bootstrap and test on x86_64 and AArch64.  This patch causes new failure in 
> gcc.dg/tree-ssa/pr71077.c,
> which uncovers another latent bug in vectorizer.  That will be fixed by next 
> patch.  Is this OK?

Ok (please omit the checking_verify_loop_structure call for now).

Thanks,
Richard.

> 2017-03-27  Bin Cheng  
>
> * tree-vect-loop-manip.c (slpeel_add_loop_guard): New param and
> mark new edge's irreducible flag accordign to it.
> (vect_do_peeling): Check loop preheader edge's irreducible flag
> and pass it to function slpeel_add_loop_guard.
> * tree-vectorizer.c (vectorize_loops): Explicitly call function
> checking_verify_loop_structure.
>
> gcc/testsuite/ChangeLog
> 2017-03-27  Bin Cheng  
>
> * gcc.c-torture/compile/irreducible-loop.c: New.


[PATCH 02/2]Add newly created bb to correct loop when reverting if-conversion in vectorizer

2017-03-28 Thread Bin Cheng
Hi,
This patch is to fix a latent vectorizer bug uncovered by previous one.  
Function optimize_mask_stores
creates if-then structure in CFG in order to revert if-conversion 
transformation.  It adds newly created
then_bb to outer loop when vectorizing two levels loop nest and masked_store is 
in the inner loop.  
Without this patch, gcc.dg/tree-ssa/pr71077.c would be broken.  Bootstrap and 
test on AArch64, is it OK?

2017-03-27  Bin Cheng  

* tree-vect-loop.c (optimize_mask_stores): Add bb to the right
loop.diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index 6bbf816..af874e7 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -7229,6 +7229,7 @@ optimize_mask_stores (struct loop *loop)
   unsigned nbbs = loop->num_nodes;
   unsigned i;
   basic_block bb;
+  struct loop *bb_loop;
   gimple_stmt_iterator gsi;
   gimple *stmt;
   auto_vec worklist;
@@ -7267,11 +7268,16 @@ optimize_mask_stores (struct loop *loop)
   last = worklist.pop ();
   mask = gimple_call_arg (last, 2);
   bb = gimple_bb (last);
-  /* Create new bb.  */
+  /* Create then_bb and if-then structure in CFG, then_bb belongs to
+the same loop as if_bb.  It could be different to LOOP when two
+level loop-nest is vectorized and mask_store belongs to the inner
+one.  */
   e = split_block (bb, last);
+  bb_loop = bb->loop_father;
+  gcc_assert (loop == bb_loop || flow_loop_nested_p (loop, bb_loop));
   join_bb = e->dest;
   store_bb = create_empty_bb (bb);
-  add_bb_to_loop (store_bb, loop);
+  add_bb_to_loop (store_bb, bb_loop);
   e->flags = EDGE_TRUE_VALUE;
   efalse = make_edge (bb, store_bb, EDGE_FALSE_VALUE);
   /* Put STORE_BB to likely part.  */


[PATCH PR80153]Always generate folded type conversion in tree-affine

2017-03-28 Thread Bin Cheng
Hi,
This patch is to fix PR80153.  As analyzed in the PR, root cause is tree_affine 
lacks
ability differentiating (unsigned)(ptr + offset) and (unsigned)ptr + 
(unsigned)offset, 
even worse, it always returns the former expression in aff_combination_tree, 
which
is wrong if the original expression has the latter form.  The patch resolves 
the issue
by always returning the latter form expression, i.e, always trying to generate 
folded
expression.  Also as analyzed in comment, I think this change won't result in 
substantial
code gen difference.  
I also need to adjust get_computation_aff for test case 
gcc.dg/tree-ssa/reassoc-19.c.
Well, I think the changed behavior is correct, but for case the original 
pointer candidate
is chosen, it should be unnecessary to compute in uutype.  Also this adjustment 
only
generates (unsigned)(pointer + offset) which is generated by tree-affine.c.
Bootstrap and test on x86_64 and AArch64.  Is it OK?

2017-03-27  Bin Cheng  

PR tree-optimization/80153
* tree-affine.c (add_elt_to_tree): Convert to type as required
by function's parameter.
* tree-ssa-loop-ivopts.c (alloc_iv): Pass in consistent types.
(get_computation_aff): Use utype directly for original candidate.

gcc/testsuite/ChangeLog
2017-03-27  Bin Cheng  

PR tree-optimization/80153
* gcc.c-torture/execute/pr80153.c: New.diff --git a/gcc/testsuite/gcc.c-torture/execute/pr80153.c 
b/gcc/testsuite/gcc.c-torture/execute/pr80153.c
new file mode 100644
index 000..3eed578
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr80153.c
@@ -0,0 +1,48 @@
+/* PR tree-optimization/80153 */
+
+void check (int, int, int) __attribute__((noinline));
+void check (int c, int c2, int val)
+{
+  if (!val) {
+__builtin_abort();
+  }
+}
+
+static const char *buf;
+static int l, i;
+
+void _fputs(const char *str)  __attribute__((noinline));
+void _fputs(const char *str)
+{
+  buf = str;
+  i = 0;
+  l = __builtin_strlen(buf);
+}
+
+char _fgetc() __attribute__((noinline));
+char _fgetc()
+{
+  char val = buf[i];
+  i++;
+  if (i > l)
+return -1;
+  else
+return val;
+}
+
+static const char *string = "oops!\n";
+
+int main(void)
+{
+  int i;
+  int c;
+
+  _fputs(string);
+
+  for (i = 0; i < __builtin_strlen(string); i++) {
+c = _fgetc();
+check(c, string[i], c == string[i]);
+  }
+
+  return 0;
+}
diff --git a/gcc/tree-affine.c b/gcc/tree-affine.c
index e620eea..b10b1aa 100644
--- a/gcc/tree-affine.c
+++ b/gcc/tree-affine.c
@@ -391,6 +391,8 @@ add_elt_to_tree (tree expr, tree type, tree elt, const 
widest_int _in,
   elt = fold_build1 (NEGATE_EXPR, TREE_TYPE (elt), elt);
   scale = 1;
 }
+  else
+elt = fold_convert (type, elt);
 
   if (scale == 1)
 {
diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index 8dc65881..fa993ab 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -1171,7 +1171,7 @@ alloc_iv (struct ivopts_data *data, tree base, tree step,
   || contain_complex_addr_expr (expr))
 {
   aff_tree comb;
-  tree_to_aff_combination (expr, TREE_TYPE (base), );
+  tree_to_aff_combination (expr, TREE_TYPE (expr), );
   base = fold_convert (TREE_TYPE (base), aff_combination_to_tree ());
 }
 
@@ -3787,6 +3787,12 @@ get_computation_aff (struct loop *loop,
  overflows, as all the arithmetics will in the end be performed in UUTYPE
  anyway.  */
   common_type = determine_common_wider_type (, );
+  /* We don't need to compute in UUTYPE if this is the original candidate,
+ and candidate/use have the same (pointer) type.  */
+  if (ctype == utype && common_type == utype
+  && POINTER_TYPE_P (utype) && TYPE_UNSIGNED (utype)
+  && cand->pos == IP_ORIGINAL && cand->incremented_at == use->stmt)
+uutype = utype;
 
   /* use = ubase - ratio * cbase + ratio * var.  */
   tree_to_aff_combination (ubase, common_type, aff);


[PATCH 01/2]Maintain irreducible region information in vectorizer peeling

2017-03-28 Thread Bin Cheng
Hi,
This patch fixes a latent bug in vectorizer, specifically, vect_do_peeling 
doesn't mark newly created edge
with irreducible flag if the vectorized loop is in irreducible region.  
Function checking_verify_loop_structure
needs to be explicitly called in vectorizer otherwise the issue is covered, but 
I am okay if we should avoid
this call.
Bootstrap and test on x86_64 and AArch64.  This patch causes new failure in 
gcc.dg/tree-ssa/pr71077.c,
which uncovers another latent bug in vectorizer.  That will be fixed by next 
patch.  Is this OK?

2017-03-27  Bin Cheng  

* tree-vect-loop-manip.c (slpeel_add_loop_guard): New param and
mark new edge's irreducible flag accordign to it.
(vect_do_peeling): Check loop preheader edge's irreducible flag
and pass it to function slpeel_add_loop_guard.
* tree-vectorizer.c (vectorize_loops): Explicitly call function
checking_verify_loop_structure.

gcc/testsuite/ChangeLog
2017-03-27  Bin Cheng  

* gcc.c-torture/compile/irreducible-loop.c: New.diff --git a/gcc/testsuite/gcc.c-torture/compile/irreducible-loop.c 
b/gcc/testsuite/gcc.c-torture/compile/irreducible-loop.c
new file mode 100644
index 000..e4be667
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/irreducible-loop.c
@@ -0,0 +1,21 @@
+void foo (int n, double a, double *b, double *x)
+{
+  int i, j;
+
+  if(n <= 0) return;
+  if (a == 0.0e0) return;
+
+  if (a > 5.0)
+{
+  i = 0;
+  goto sec;
+}
+  for (i = 0; i < 1024; i++)
+{
+  double y = b[i];
+sec:
+  b[i+1] = y + 5.0;
+  for (j = 0; j < n; j++)
+   x[j] = x[j] + a;
+}
+}
diff --git a/gcc/tree-vect-loop-manip.c b/gcc/tree-vect-loop-manip.c
index 2f82061..f48336b 100644
--- a/gcc/tree-vect-loop-manip.c
+++ b/gcc/tree-vect-loop-manip.c
@@ -534,12 +534,13 @@ slpeel_tree_duplicate_loop_to_edge_cfg (struct loop *loop,
 /* Given the condition expression COND, put it as the last statement of
GUARD_BB; set both edges' probability; set dominator of GUARD_TO to
DOM_BB; return the skip edge.  GUARD_TO is the target basic block to
-   skip the loop.  PROBABILITY is the skip edge's probability.  */
+   skip the loop.  PROBABILITY is the skip edge's probability.  Mark the
+   new edge as irreducible if IRREDUCIBLE_P is true.  */
 
 static edge
 slpeel_add_loop_guard (basic_block guard_bb, tree cond,
   basic_block guard_to, basic_block dom_bb,
-  int probability)
+  int probability, bool irreducible_p)
 {
   gimple_stmt_iterator gsi;
   edge new_e, enter_e;
@@ -566,6 +567,9 @@ slpeel_add_loop_guard (basic_block guard_bb, tree cond,
   new_e->count = guard_bb->count;
   new_e->probability = probability;
   new_e->count = apply_probability (enter_e->count, probability);
+  if (irreducible_p)
+new_e->flags |= EDGE_IRREDUCIBLE_LOOP;
+
   enter_e->count -= new_e->count;
   enter_e->probability = inverse_probability (probability);
   set_immediate_dominator (CDI_DOMINATORS, guard_to, dom_bb);
@@ -1667,6 +1671,7 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree niters, 
tree nitersm1,
 
   struct loop *prolog, *epilog = NULL, *loop = LOOP_VINFO_LOOP (loop_vinfo);
   struct loop *first_loop = loop;
+  bool irred_flag = loop_preheader_edge (loop)->flags & EDGE_IRREDUCIBLE_LOOP;
   create_lcssa_for_virtual_phi (loop);
   update_ssa (TODO_update_ssa_only_virtuals);
 
@@ -1748,7 +1753,8 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree niters, 
tree nitersm1,
  guard_to = split_edge (loop_preheader_edge (loop));
  guard_e = slpeel_add_loop_guard (guard_bb, guard_cond,
   guard_to, guard_bb,
-  inverse_probability (prob_prolog));
+  inverse_probability (prob_prolog),
+  irred_flag);
  e = EDGE_PRED (guard_to, 0);
  e = (e != guard_e ? e : EDGE_PRED (guard_to, 1));
  slpeel_update_phi_nodes_for_guard1 (prolog, loop, guard_e, e);
@@ -1813,7 +1819,8 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree niters, 
tree nitersm1,
  guard_to = split_edge (loop_preheader_edge (epilog));
  guard_e = slpeel_add_loop_guard (guard_bb, guard_cond,
   guard_to, guard_bb,
-  inverse_probability (prob_vector));
+  inverse_probability (prob_vector),
+  irred_flag);
  e = EDGE_PRED (guard_to, 0);
  e = (e != guard_e ? e : EDGE_PRED (guard_to, 1));
  slpeel_update_phi_nodes_for_guard1 (first_loop, epilog, guard_e, e);
@@ -1853,7 +1860,8 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree niters, 
tree nitersm1,
  guard_to = split_edge (single_exit (epilog));
  guard_e = 

[Patch, testsuite] Fix more failing tests for avr

2017-03-28 Thread Senthil Kumar Selvaraj
Hi,

  The below trivial patch fixes some more testsuite failures for the avr
  target. They fail for avr because they assume ints are 32 bits or
  wider. The patch uses explicit __{U}INT32_TYPE__ for targets with
  smaller int size.

  Committed as obvious.

Regards
Senthil

2017-03-28  Senthil Kumar Selvaraj  

* gcc.c-torture/execute/pr79121.c:Use __{U}INT32_TYPE__ for targets
with sizeof(int) < 4.
* gcc.c-torture/execute/pr79737-1.c (struct S): Likewise.
* gcc.c-torture/execute/pr79737-2.c: Likewise.
* gcc.dg/torture/pr79777.c: Likewise.
* gcc.dg/torture/pr79910.c: Likewise.

Index: gcc.c-torture/execute/pr79121.c
===
--- gcc.c-torture/execute/pr79121.c (revision 246528)
+++ gcc.c-torture/execute/pr79121.c (working copy)
@@ -1,21 +1,29 @@
+#if __SIZEOF_INT__ < 4
+  __extension__ typedef __UINT32_TYPE__ uint32_t;
+  __extension__ typedef __INT32_TYPE__ int32_t;
+#else
+  typedef unsigned uint32_t;
+  typedef int int32_t;
+#endif
+
 extern void abort (void);
 
-__attribute__ ((noinline, noclone)) unsigned long long f1 (int x)
+__attribute__ ((noinline, noclone)) unsigned long long f1 (int32_t x)
 {
   return ((unsigned long long) x) << 4;
 }
 
-__attribute__ ((noinline, noclone)) long long f2 (unsigned x)
+__attribute__ ((noinline, noclone)) long long f2 (uint32_t x)
 {
   return ((long long) x) << 4;
 }
 
-__attribute__ ((noinline, noclone)) unsigned long long f3 (unsigned x)
+__attribute__ ((noinline, noclone)) unsigned long long f3 (uint32_t x)
 {
   return ((unsigned long long) x) << 4;
 }
 
-__attribute__ ((noinline, noclone)) long long f4 (int x)
+__attribute__ ((noinline, noclone)) long long f4 (int32_t x)
 {
   return ((long long) x) << 4;
 }
Index: gcc.c-torture/execute/pr79737-1.c
===
--- gcc.c-torture/execute/pr79737-1.c   (revision 246528)
+++ gcc.c-torture/execute/pr79737-1.c   (working copy)
@@ -1,13 +1,19 @@
 /* PR tree-optimization/79737 */
 
+#if __SIZEOF_INT__ < 4
+  __extension__ typedef __INT32_TYPE__ int32_t;
+#else
+  typedef int int32_t;
+#endif
+
 #pragma pack(1)
 struct S
 {
-  int b:18;
-  int c:1;
-  int d:24;
-  int e:15;
-  int f:14;
+  int32_t b:18;
+  int32_t c:1;
+  int32_t d:24;
+  int32_t e:15;
+  int32_t f:14;
 } i;
 int g, j, k;
 static struct S h;
Index: gcc.c-torture/execute/pr79737-2.c
===
--- gcc.c-torture/execute/pr79737-2.c   (revision 246528)
+++ gcc.c-torture/execute/pr79737-2.c   (working copy)
@@ -1,13 +1,19 @@
 /* PR tree-optimization/79737 */
 
+#if __SIZEOF_INT__ < 4
+  __extension__ typedef __INT32_TYPE__ int32_t;
+#else
+  typedef int int32_t;
+#endif
+
 #pragma pack(1)
 struct S
 {
-  int b:18;
-  int c:1;
-  int d:24;
-  int e:15;
-  int f:14;
+  int32_t b:18;
+  int32_t c:1;
+  int32_t d:24;
+  int32_t e:15;
+  int32_t f:14;
 } i, j;
 
 void
Index: gcc.dg/torture/pr79777.c
===
--- gcc.dg/torture/pr79777.c(revision 246528)
+++ gcc.dg/torture/pr79777.c(working copy)
@@ -1,9 +1,14 @@
 /* { dg-do compile } */
 
 typedef unsigned short __u16;
-typedef unsigned int __u32;
+#if __SIZEOF_INT__ < 4
+  __extension__ typedef __UINT32_TYPE__ __u32;
+  __extension__ typedef __UINT32_TYPE__ u32;
+#else
+  typedef unsigned int __u32;
+  typedef unsigned int u32;
+#endif
 typedef unsigned char u8;
-typedef unsigned int u32;
 typedef __u16 __le16;
 typedef __u32 __le32;
 typedef u32 secno;
Index: gcc.dg/torture/pr79910.c
===
--- gcc.dg/torture/pr79910.c(revision 246528)
+++ gcc.dg/torture/pr79910.c(working copy)
@@ -2,7 +2,11 @@
 /* { dg-additional-options "-fweb" } */
 
 typedef unsigned char u8;
-typedef unsigned int u32;
+#if __SIZEOF_INT__ < 4
+  __extension__ typedef __UINT32_TYPE__ u32;
+#else
+  typedef unsigned int u32;
+#endif
 typedef unsigned long long u64;
 int a;
 


[PATCH] Fix PR80222

2017-03-28 Thread Richard Biener

In the context of PR79671 it was noticed that forcing a ref-all
pointer access via a simple static_cast  (obj) and C
with may_alias on it didn't work.

But it should.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2017-03-28  Richard Biener  

PR middle-end/80222
* gimple-fold.c (gimple_fold_indirect_ref): Do not touch
TYPE_REF_CAN_ALIAS_ALL references.
* fold-const.c (fold_indirect_ref_1): Likewise.

* g++.dg/pr80222.C: New testcase.

Index: gcc/gimple-fold.c
===
*** gcc/gimple-fold.c   (revision 246500)
--- gcc/gimple-fold.c   (working copy)
*** gimple_get_virt_method_for_binfo (HOST_W
*** 6539,6546 
return gimple_get_virt_method_for_vtable (token, v, offset, can_refer);
  }
  
! /* Given a pointer value OP0, return a simplified version of an
!indirection through OP0, or NULL_TREE if no simplification is
 possible.  Note that the resulting type may be different from
 the type pointed to in the sense that it is still compatible
 from the langhooks point of view. */
--- 6539,6546 
return gimple_get_virt_method_for_vtable (token, v, offset, can_refer);
  }
  
! /* Given a pointer value T, return a simplified version of an
!indirection through T, or NULL_TREE if no simplification is
 possible.  Note that the resulting type may be different from
 the type pointed to in the sense that it is still compatible
 from the langhooks point of view. */
*** gimple_fold_indirect_ref (tree t)
*** 6554,6560 
  
STRIP_NOPS (sub);
subtype = TREE_TYPE (sub);
!   if (!POINTER_TYPE_P (subtype))
  return NULL_TREE;
  
if (TREE_CODE (sub) == ADDR_EXPR)
--- 6554,6561 
  
STRIP_NOPS (sub);
subtype = TREE_TYPE (sub);
!   if (!POINTER_TYPE_P (subtype)
!   || TYPE_REF_CAN_ALIAS_ALL (ptype))
  return NULL_TREE;
  
if (TREE_CODE (sub) == ADDR_EXPR)
Index: gcc/fold-const.c
===
*** gcc/fold-const.c(revision 246500)
--- gcc/fold-const.c(working copy)
*** fold_indirect_ref_1 (location_t loc, tre
*** 14006,14012 
  
STRIP_NOPS (sub);
subtype = TREE_TYPE (sub);
!   if (!POINTER_TYPE_P (subtype))
  return NULL_TREE;
  
if (TREE_CODE (sub) == ADDR_EXPR)
--- 14006,14013 
  
STRIP_NOPS (sub);
subtype = TREE_TYPE (sub);
!   if (!POINTER_TYPE_P (subtype)
!   || TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (op0)))
  return NULL_TREE;
  
if (TREE_CODE (sub) == ADDR_EXPR)
Index: gcc/testsuite/g++.dg/pr80222.C
===
*** gcc/testsuite/g++.dg/pr80222.C  (nonexistent)
--- gcc/testsuite/g++.dg/pr80222.C  (working copy)
***
*** 0 
--- 1,13 
+ // { dg-do compile }
+ // { dg-options "-O2 -fdump-tree-optimized" } */
+ 
+ struct C { int i; }__attribute__((may_alias)) ;
+ 
+ C a, b;
+ 
+ int main()
+ {
+   a = static_cast  (b);
+ }
+ 
+ // { dg-final { scan-tree-dump "{ref-all}\\\)\];" "optimized" } } */


Re: [v3 PATCH] Implement LWG 2900, The copy and move constructors of optional are not constexpr.

2017-03-28 Thread Jonathan Wakely

On 17/03/17 16:51 +0200, Ville Voutilainen wrote:

diff --git a/libstdc++-v3/include/std/optional 
b/libstdc++-v3/include/std/optional
index 3f540ec..e67ba89 100644
--- a/libstdc++-v3/include/std/optional
+++ b/libstdc++-v3/include/std/optional
@@ -95,125 +95,127 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
-  constexpr _Optional_base(nullopt_t) noexcept
-  : _Optional_base{} { }
+  template
+  constexpr _Optional_payload(std::initializer_list<_Up> __il,
+ _Args&&... __args)
+   : _M_payload(__il, std::forward<_Args>(__args)...),
+ _M_engaged(true) {}
+
+  template  struct __ctor_tag {};


Newline here please, so it doesn't look like this template<...> is on
the constructor.


+  constexpr _Optional_payload(__ctor_tag,
+ const _Tp& __other)
+   : _M_payload(__other),
+ _M_engaged(true)
+  {}
+
+  constexpr _Optional_payload(__ctor_tag)
+   : _M_empty()
+  {}
+
+  constexpr _Optional_payload(__ctor_tag, _Tp&& __other)
+   : _M_payload(std::move(__other)),
+ _M_engaged(true)
+  {}
+
+  constexpr _Optional_payload(bool __engaged,
+ const _Optional_payload&


Looks like we don't need a newline before the parameter name here:


+ __other)
+   : _Optional_payload(__engaged ?
+   _Optional_payload(__ctor_tag{},
+ __other._M_payload) :
+   _Optional_payload(__ctor_tag{}))
+  {}
+
+  constexpr _Optional_payload(bool __engaged,
+ _Optional_payload&&


Nor here:


+ __other)
+   : _Optional_payload(__engaged ?
+   _Optional_payload(__ctor_tag{},
+ std::move(__other._M_payload)) :
+   _Optional_payload(__ctor_tag{}))
+  {}


Hmm, I see we don't actually show a conditional expression in the
Coding Style docs, but I'd do that as:

: _Optional_payload(__engaged
? _Optional_payload(__ctor_tag{},
   std::move(__other._M_payload))
: _Optional_payload(__ctor_tag{}))



-  // Constructors for engaged optionals.
-  template, bool> = false>
-constexpr explicit _Optional_base(in_place_t, _Args&&... __args)
-: _M_payload(std::forward<_Args>(__args)...), _M_engaged(true) { }
+  using _Stored_type = remove_const_t<_Tp>;
+  struct _Empty_byte { };


I was going to ask whether std::byte would be better here, but I think
a valueless struct is better.


+  union {
+  _Empty_byte _M_empty;
+  _Stored_type _M_payload;
+  };
+  bool _M_engaged = false;
+};




+  template
+void
+_M_construct(_Args&&... __args)
+noexcept(is_nothrow_constructible<_Stored_type, _Args...>())
+{
+  ::new (std::__addressof(this->_M_payload))


I think we need (void*) here to ensure we use the reserved placement
form of operator new and not some other overload:

struct X { };
void* operator new(decltype(sizeof(0)) n, X*);

(We don't get this right everywhere that uses placement new with
arbitrary types).



+_Stored_type(std::forward<_Args>(__args)...);
+  this->_M_engaged = true;
+}
};

+  // The _M_construct operation has !_M_engaged as a precondition
+  // while _M_destruct has _M_engaged as a precondition.
  template
void
_M_construct(_Args&&... __args)
noexcept(is_nothrow_constructible<_Stored_type, _Args...>())
{
-  ::new (std::__addressof(this->_M_payload))
+  ::new (std::__addressof(this->_M_payload._M_payload))


Here too.


_Stored_type(std::forward<_Args>(__args)...);
-  this->_M_engaged = true;
+  this->_M_payload._M_engaged = true;
}


OK for trunk with those adjustements, thanks.



[PATCH] Improve scatter/gather cost modeling (PRs 57796/80232)

2017-03-28 Thread Richard Biener

Not actually solving those testcases but currently scatters/gathers
are costed as a single vector load/store.  Micro-architectural Intel
seems to have gotten to the point (with skylake) to hide all but
the scalar loads/stores which seem to take up as many load/store
ports as expected.  I'm not expecting further improvements ontop
of that so the following patch reflects this.

When the vectorizer would open-code gathers/scatters extra cost
of vector element insertion / extraction would be accounted for
(if the CPU doesn't have scatter/gather support).

Bootstrap / regtest running on x86_64-unknown-linux-gnu.

Any objection at this stage?

Thanks,
Richard.

2017-05-28  Richard Biener  

PR tree-optimization/57796
* tree-vect-stmts.c (vect_model_store_cost): Cost scatters
as N scalar stores.
(vect_model_load_cost): Cost gathers as N scalar loads.

Index: gcc/tree-vect-stmts.c
===
--- gcc/tree-vect-stmts.c   (revision 246500)
+++ gcc/tree-vect-stmts.c   (working copy)
@@ -929,7 +929,8 @@ vect_model_store_cost (stmt_vec_info stm
 
   tree vectype = STMT_VINFO_VECTYPE (stmt_info);
   /* Costs of the stores.  */
-  if (memory_access_type == VMAT_ELEMENTWISE)
+  if (memory_access_type == VMAT_ELEMENTWISE
+  || memory_access_type == VMAT_GATHER_SCATTER)
 /* N scalar stores plus extracting the elements.  */
 inside_cost += record_stmt_cost (body_cost_vec,
 ncopies * TYPE_VECTOR_SUBPARTS (vectype),
@@ -1056,7 +1057,8 @@ vect_model_load_cost (stmt_vec_info stmt
 }
 
   /* The loads themselves.  */
-  if (memory_access_type == VMAT_ELEMENTWISE)
+  if (memory_access_type == VMAT_ELEMENTWISE
+  || memory_access_type == VMAT_GATHER_SCATTER)
 {
   /* N scalar loads plus gathering them into a vector.  */
   tree vectype = STMT_VINFO_VECTYPE (stmt_info);


OpenACC default clause maintenance

2017-03-28 Thread Thomas Schwinge
Hi!

I noticed that in C++, for a directive like:

#pragma acc parallel default (hello)

... we currently print two error messages for the same location:

[...]:35:30: error: expected 'none' before 'hello'
[...]:35:30: error: expected ')' before 'hello'

I think it should be enough to just print the first syntax error (which
is what we do for C).  I also generally beefed up testing of the OpenACC
default clause in C, C++, Fortran.  OK for trunk in next stage 1 (I
suppose)?  For now committed to gomp-4_0-branch in r246526:

commit b11ff2d0f10ef2e2005ccac0d84a02c39117ef9a
Author: tschwinge 
Date:   Tue Mar 28 09:34:03 2017 +

OpenACC default clause maintenance

gcc/cp/
* parser.c (cp_parser_omp_clause_default): Avoid printing more
than one syntax error message.
gcc/testsuite/
* c-c++-common/goacc/data-default-1.c: Remove file.
* c-c++-common/goacc/default-1.c: New file.
* c-c++-common/goacc/default-2.c: Likewise.
* c-c++-common/goacc/default-3.c: Likewise.
* c-c++-common/goacc/default-4.c: Likewise.
* gfortran.dg/goacc/default.f95: Remove file.
* gfortran.dg/goacc/default-1.f95: New file.
* gfortran.dg/goacc/default-2.f: Likewise.
* gfortran.dg/goacc/default-3.f95: Likewise.
* gfortran.dg/goacc/default-4.f: Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@246526 
138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/cp/ChangeLog.gomp |  5 ++
 gcc/cp/parser.c   |  3 +-
 gcc/testsuite/ChangeLog.gomp  | 13 +
 gcc/testsuite/c-c++-common/goacc/data-default-1.c | 37 --
 gcc/testsuite/c-c++-common/goacc/default-1.c  |  9 
 gcc/testsuite/c-c++-common/goacc/default-2.c  | 59 ++
 gcc/testsuite/c-c++-common/goacc/default-3.c  | 18 +++
 gcc/testsuite/c-c++-common/goacc/default-4.c  | 45 +
 gcc/testsuite/gfortran.dg/goacc/default-1.f95 | 10 
 gcc/testsuite/gfortran.dg/goacc/default-2.f   | 60 +++
 gcc/testsuite/gfortran.dg/goacc/default-3.f95 | 18 +++
 gcc/testsuite/gfortran.dg/goacc/default-4.f   | 39 +++
 gcc/testsuite/gfortran.dg/goacc/default.f95   | 17 ---
 13 files changed, 278 insertions(+), 55 deletions(-)

diff --git gcc/cp/ChangeLog.gomp gcc/cp/ChangeLog.gomp
[snipped]
diff --git gcc/cp/parser.c gcc/cp/parser.c
index 6dcc099..d80d056 100644
--- gcc/cp/parser.c
+++ gcc/cp/parser.c
@@ -30722,7 +30722,8 @@ cp_parser_omp_clause_default (cp_parser *parser, tree 
list,
cp_parser_error (parser, "expected % or %");
 }
 
-  if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+  if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED
+  || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
 cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
   /*or_comma=*/false,
   /*consume_paren=*/true);
diff --git gcc/testsuite/ChangeLog.gomp gcc/testsuite/ChangeLog.gomp
[snipped]
diff --git gcc/testsuite/c-c++-common/goacc/data-default-1.c 
gcc/testsuite/c-c++-common/goacc/data-default-1.c
deleted file mode 100644
index 631032e..000
--- gcc/testsuite/c-c++-common/goacc/data-default-1.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/* { dg-do compile } */
-
-
-int main ()
-{
-  int n = 2;
-  int ary[2];
-  
-#pragma acc parallel default (none) /* { dg-message "'parallel' construct" 2 } 
*/
-  {
-ary[0] /* { dg-error "not specified in enclosing" } */
-  = n; /* { dg-error "not specified in enclosing" } */
-  }
-
-#pragma acc kernels default (none) /* { dg-message "'kernels' construct" 2 } */
-  {
-ary[0] /* { dg-error "not specified in enclosing" } */
-  = n; /* { dg-error "not specified in enclosing" } */
-  }
-
-#pragma acc data copy (ary, n)
-  {
-#pragma acc parallel default (none)
-{
-  ary[0]
-   = n;
-}
-
-#pragma acc kernels default (none)
-{
-  ary[0]
-   = n;
-}
-  }
-
-  return 0;
-}
diff --git gcc/testsuite/c-c++-common/goacc/default-1.c 
gcc/testsuite/c-c++-common/goacc/default-1.c
new file mode 100644
index 000..4d31dbc
--- /dev/null
+++ gcc/testsuite/c-c++-common/goacc/default-1.c
@@ -0,0 +1,9 @@
+/* OpenACC default clause: valid syntax.  */
+
+void f1 ()
+{
+#pragma acc kernels default (none)
+  ;
+#pragma acc parallel default (none)
+  ;
+}
diff --git gcc/testsuite/c-c++-common/goacc/default-2.c 
gcc/testsuite/c-c++-common/goacc/default-2.c
new file mode 100644
index 000..d6b6cdc
--- /dev/null
+++ gcc/testsuite/c-c++-common/goacc/default-2.c
@@ -0,0 +1,59 @@
+/* OpenACC default clause: invalid syntax.  */
+
+void f1 ()
+{
+#pragma acc kernels default 

[PATCH] Support multiple files w/ -i option in gcov (PR gcov-profile/80224).

2017-03-28 Thread Martin Liška
Hello.

The fix of the PR, where intermediate format is currently dumped in a bit 
different manner.
I believe it can share majority of file creation (and destruction) with normal 
format.
Apart from that I refined usage string from:

Usage: gcov [OPTION]... SOURCE|OBJ...

to:
Usage: gcov [OPTION...] SOURCE|OBJ...

Patch survives make check -k -j10 RUNTESTFLAGS="gcov.exp"

Ready for trunk?
Thanks,
Martin
>From 0d0c574ccf8fc832b5e1f2d6f77ca195a0eb7ea4 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Tue, 28 Mar 2017 10:57:38 +0200
Subject: [PATCH] Support multiple files w/ -i option in gcov (PR
 gcov-profile/80224).

gcc/ChangeLog:

2017-03-28  Martin Liska  

	* gcov.c (print_usage): Fix usage string.
	(get_gcov_intermediate_filename): Remove.
	(output_gcov_file): Use both for normal and intermediate format.
	(generate_results): Do not initialize special file for
	intermediate format.
---
 gcc/gcov.c | 62 +++---
 1 file changed, 7 insertions(+), 55 deletions(-)

diff --git a/gcc/gcov.c b/gcc/gcov.c
index 4198decdabc..05022a6a1ed 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -653,7 +653,7 @@ print_usage (int error_p)
   FILE *file = error_p ? stderr : stdout;
   int status = error_p ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE;
 
-  fnotice (file, "Usage: gcov [OPTION]... SOURCE|OBJ...\n\n");
+  fnotice (file, "Usage: gcov [OPTION...] SOURCE|OBJ...\n\n");
   fnotice (file, "Print code coverage information.\n\n");
   fnotice (file, "  -h, --help  Print this help, then exit\n");
   fnotice (file, "  -a, --all-blocksShow information for every basic block\n");
@@ -791,31 +791,6 @@ process_args (int argc, char **argv)
   return optind;
 }
 
-/* Get the name of the gcov file.  The return value must be free'd.
-
-   It appends the '.gcov' extension to the *basename* of the file.
-   The resulting file name will be in PWD.
-
-   e.g.,
-   input: foo.da,   output: foo.da.gcov
-   input: a/b/foo.cc,   output: foo.cc.gcov  */
-
-static char *
-get_gcov_intermediate_filename (const char *file_name)
-{
-  const char *gcov = ".gcov";
-  char *result;
-  const char *cptr;
-
-  /* Find the 'basename'.  */
-  cptr = lbasename (file_name);
-
-  result = XNEWVEC (char, strlen (cptr) + strlen (gcov) + 1);
-  sprintf (result, "%s%s", cptr, gcov);
-
-  return result;
-}
-
 /* Output the result in intermediate format used by 'lcov'.
 
 The intermediate format contains a single file named 'foo.cc.gcov',
@@ -980,7 +955,11 @@ output_gcov_file (const char *file_name, source_t *src)
   if (gcov_file)
 {
   fnotice (stdout, "Creating '%s'\n", gcov_file_name);
-  output_lines (gcov_file, src);
+
+	  if (flag_intermediate_format)
+	output_intermediate_file (gcov_file, src);
+	  else
+	output_lines (gcov_file, src);
   if (ferror (gcov_file))
 fnotice (stderr, "Error writing output file '%s'\n", gcov_file_name);
   fclose (gcov_file);
@@ -1002,8 +981,6 @@ generate_results (const char *file_name)
   unsigned ix;
   source_t *src;
   function_t *fn;
-  FILE *gcov_intermediate_file = NULL;
-  char *gcov_intermediate_filename = NULL;
 
   for (ix = n_sources, src = sources; ix--; src++)
 if (src->num_lines)
@@ -1033,19 +1010,6 @@ generate_results (const char *file_name)
 	file_name = canonicalize_name (file_name);
 }
 
-  if (flag_gcov_file && flag_intermediate_format)
-{
-  /* Open the intermediate file.  */
-  gcov_intermediate_filename = get_gcov_intermediate_filename (file_name);
-  gcov_intermediate_file = fopen (gcov_intermediate_filename, "w");
-  if (!gcov_intermediate_file)
-	{
-	  fnotice (stderr, "Cannot open intermediate output file %s\n",
-		   gcov_intermediate_filename);
-	  return;
-	}
-}
-
   for (ix = n_sources, src = sources; ix--; src++)
 {
   if (flag_relative_only)
@@ -1068,23 +1032,11 @@ generate_results (const char *file_name)
   total_executed += src->coverage.lines_executed;
   if (flag_gcov_file)
 	{
-  if (flag_intermediate_format)
-/* Output the intermediate format without requiring source
-   files.  This outputs a section to a *single* file.  */
-output_intermediate_file (gcov_intermediate_file, src);
-  else
-output_gcov_file (file_name, src);
+	  output_gcov_file (file_name, src);
   fnotice (stdout, "\n");
 }
 }
 
-  if (flag_gcov_file && flag_intermediate_format)
-{
-  /* Now we've finished writing the intermediate file.  */
-  fclose (gcov_intermediate_file);
-  XDELETEVEC (gcov_intermediate_filename);
-}
-
   if (!file_name)
 executed_summary (total_lines, total_executed);
 }
-- 
2.12.0



RE: [PATCH] [ARC] Define _REENTRANT when -pthread is passed.

2017-03-28 Thread Claudiu Zissulescu
Thank you Andrew. The patch is committed,
Claudiu

P.S. Thomas can you mark fixed the Bugzilla entry for this patch. Thanks!


RE: [PATCH] [ARC] Update ARC SIMD patterns.

2017-03-28 Thread Claudiu Zissulescu
Thank you Andrew. The patch is committed,
Claudiu

> -Original Message-
> From: Andrew Burgess [mailto:andrew.burg...@embecosm.com]
> Sent: Monday, March 27, 2017 9:58 PM
> To: Claudiu Zissulescu 
> Cc: gcc-patches@gcc.gnu.org; francois.bed...@synopsys.com
> Subject: Re: [PATCH] [ARC] Update ARC SIMD patterns.
> 
> * Claudiu Zissulescu  [2017-03-27
> 13:10:12 +0200]:
> 
> > Hi Andrew,
> >
> > vec_select expects in selection a list of subparts. The old ARC SIMD
> > extension instructions were not up-to-date, update them.
> >
> > Whithout this patch ARC backend is broken. It will be great if we can have 
> > it
> in before gcc7.x branch is cut.
> >
> > Thank you,
> > Claudiu
> >
> > gcc/
> > 2017-03-27  Claudiu Zissulescu  
> >
> > * config/arc/simdext.md (vst64_insn): Update pattern.
> > (vld32wh_insn): Likewise.
> > (vld32wl_insn): Likewise.
> > (vld64_insn): Likewise.
> > (vld32_insn): Likewise.
> 
> Looks reasonable.
> 
> Thanks,
> Andrew
> 
> 
> > ---
> >  gcc/config/arc/simdext.md | 98 -
> --
> >  1 file changed, 67 insertions(+), 31 deletions(-)
> >
> > diff --git a/gcc/config/arc/simdext.md b/gcc/config/arc/simdext.md
> > index c9ec5f4..33bb330 100644
> > --- a/gcc/config/arc/simdext.md
> > +++ b/gcc/config/arc/simdext.md
> > @@ -193,11 +193,16 @@
> >  )
> >
> >  (define_insn "vst64_insn"
> > -  [(set(mem:V4HI (plus:SI (zero_extend:SI (vec_select:HI
> (match_operand:V8HI 0 "vector_register_operand"  "v")
> > - (parallel
> [(match_operand:SI 1 "immediate_operand" "L")])))
> > -  (match_operand:SI 2 "immediate_operand" "P")))
> > -   (vec_select:V4HI (match_operand:V8HI 3 "vector_register_operand"
> "=v")
> > -(parallel [(const_int 0)])))]
> > +  [(set(mem:V4HI
> > +(plus:SI
> > + (zero_extend:SI
> > +  (vec_select:HI (match_operand:V8HI 0 "vector_register_operand"
> "v")
> > + (parallel
> > +  [(match_operand:SI 1 "immediate_operand"
> "L")])))
> > + (match_operand:SI 2 "immediate_operand" "P")))
> > +   (vec_select:V4HI
> > +(match_operand:V8HI 3 "vector_register_operand" "=v")
> > +(parallel [(const_int 0) (const_int 1) (const_int 2) (const_int 3)])))]
> >   "TARGET_SIMD_SET"
> >   "vst64 %3, [i%1, %2]"
> >   [(set_attr "type" "simd_vstore")
> > @@ -1191,12 +1196,20 @@
> > (set_attr "cond" "nocond")])
> >
> >  (define_insn "vld32wh_insn"
> > -  [(set (match_operand:V8HI 0 "vector_register_operand"   "=v")
> > -   (vec_concat:V8HI (zero_extend:V4HI (mem:V4QI (plus:SI
> (match_operand:SI 1 "immediate_operand" "P")
> > - (zero_extend: SI
> (vec_select:HI (match_operand:V8HI 2 "vector_register_operand"  "v")
> > -
> (parallel [(match_operand:SI 3 "immediate_operand"
> "L")]))
> > -(vec_select:V4HI (match_dup 0)
> > - (parallel [(const_int 0)]]
> > +  [(set (match_operand:V8HI 0 "vector_register_operand" "=v")
> > +   (vec_concat:V8HI
> > +(zero_extend:V4HI
> > + (mem:V4QI
> > +  (plus:SI
> > +   (match_operand:SI 1 "immediate_operand" "P")
> > +   (zero_extend:SI
> > +(vec_select:HI
> > + (match_operand:V8HI 2 "vector_register_operand"  "v")
> > + (parallel [(match_operand:SI 3 "immediate_operand" "L")]))
> > +(vec_select:V4HI
> > + (match_dup 0)
> > + (parallel [(const_int 0) (const_int 1) (const_int 2) (const_int 3)])
> > + )))]
> >"TARGET_SIMD_SET"
> >"vld32wh %0, [i%3,%1]"
> >[(set_attr "type" "simd_vload")
> > @@ -1204,12 +1217,20 @@
> > (set_attr "cond" "nocond")])
> >
> >  (define_insn "vld32wl_insn"
> > -  [(set (match_operand:V8HI 0 "vector_register_operand"   "=v")
> > -   (vec_concat:V8HI (vec_select:V4HI (match_dup 0)
> > - (parallel [(const_int 1)]))
> > -(zero_extend:V4HI (mem:V4QI (plus:SI
> (match_operand:SI 1 "immediate_operand" "P")
> > - (zero_extend: SI
> (vec_select:HI (match_operand:V8HI 2 "vector_register_operand"  "v")
> > -
> (parallel [(match_operand:SI 3 "immediate_operand"
> "L")])) ))]
> > +  [(set (match_operand:V8HI 0 "vector_register_operand" "=v")
> > +   (vec_concat:V8HI
> > +(vec_select:V4HI
> > + (match_dup 0)
> > + (parallel [(const_int 4) (const_int 5) (const_int 6) (const_int 7)]))
> > +(zero_extend:V4HI
> > + (mem:V4QI
> > +  (plus:SI
> > +   (match_operand:SI 1 "immediate_operand" "P")
> > +   (zero_extend:SI
> > +(vec_select:HI (match_operand:V8HI 2 "vector_register_operand"
> "v")
> > +   (parallel
> > +

Re: [testsuite] Add missing dg-require-effective-target alloca to gcc testsuite

2017-03-28 Thread Tom de Vries

On 28/03/17 10:23, Thomas Schwinge wrote:

Hi!

On Thu, 23 Mar 2017 16:46:19 +0100, Tom de Vries  wrote:

I've run the gcc testsuite for target nvptx-none and ran into "test for
excess errors" FAILs due to:
...
sorry, unimplemented: target cannot support alloca.
...

This patch marks those testcases as requiring alloca.


I observed that this test case:


--- gcc/testsuite/gcc.dg/torture/pr71881.c (revision 246278)
+++ gcc/testsuite/gcc.dg/torture/pr71881.c (working copy)
@@ -1,4 +1,5 @@
 /* { dg-do compile } */
+/* { dg-require-effective-target alloca } */
 /* { dg-additional-options "-g" } */


... as well as this test case:


--- gcc/testsuite/gcc.c-torture/compile/pr79413.c (revision 246278)
+++ gcc/testsuite/gcc.c-torture/compile/pr79413.c (working copy)
@@ -1,3 +1,4 @@
+/* { dg-require-effective-target alloca } */
 /* PR c/79413 */


... previously did PASS for anything but "-O0" (that is, any "alloca"
usage got optimized away).  Now changed as follows:

[-FAIL:-]{+UNSUPPORTED:+} gcc.c-torture/compile/pr79413.c   -O0  [-(test 
for excess errors)-]
[-PASS:-]{+UNSUPPORTED:+} gcc.c-torture/compile/pr79413.c   -O1  [-(test 
for excess errors)-]
[-PASS:-]{+UNSUPPORTED:+} gcc.c-torture/compile/pr79413.c   -O2  [-(test 
for excess errors)-]
[-PASS:-]{+UNSUPPORTED:+} gcc.c-torture/compile/pr79413.c   -O3 -g  [-(test 
for excess errors)-]
[-PASS:-]{+UNSUPPORTED:+} gcc.c-torture/compile/pr79413.c   -Os  [-(test 
for excess errors)-]

[-FAIL:-]{+UNSUPPORTED:+} gcc.dg/torture/pr71881.c   -O0  [-(test for 
excess errors)-]
[-PASS:-]{+UNSUPPORTED:+} gcc.dg/torture/pr71881.c   -O1  [-(test for 
excess errors)-]
[-PASS:-]{+UNSUPPORTED:+} gcc.dg/torture/pr71881.c   -O2  [-(test for 
excess errors)-]
[-PASS:-]{+UNSUPPORTED:+} gcc.dg/torture/pr71881.c   -O3 
-fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions  
[-(test for excess errors)-]
[-PASS:-]{+UNSUPPORTED:+} gcc.dg/torture/pr71881.c   -O3 -g  [-(test for 
excess errors)-]
[-PASS:-]{+UNSUPPORTED:+} gcc.dg/torture/pr71881.c   -Os  [-(test for 
excess errors)-]

Would it be useful to XFAIL these for "-O0" only (along with a comment),
so that we continue testing that any "alloca" usage gets optimized away?
(Just an idea.)


I'd say that makes sense for test-cases which have the purpose of 
testing whether alloca is optimized away at certain optimization levels, 
but not for random test cases.


Thanks,
- Tom



Re: [testsuite] Add missing dg-require-effective-target alloca to gcc testsuite

2017-03-28 Thread Thomas Schwinge
Hi!

On Thu, 23 Mar 2017 16:46:19 +0100, Tom de Vries  wrote:
> I've run the gcc testsuite for target nvptx-none and ran into "test for 
> excess errors" FAILs due to:
> ...
> sorry, unimplemented: target cannot support alloca.
> ...
> 
> This patch marks those testcases as requiring alloca.

I observed that this test case:

> --- gcc/testsuite/gcc.dg/torture/pr71881.c (revision 246278)
> +++ gcc/testsuite/gcc.dg/torture/pr71881.c (working copy)
> @@ -1,4 +1,5 @@
>  /* { dg-do compile } */
> +/* { dg-require-effective-target alloca } */
>  /* { dg-additional-options "-g" } */

... as well as this test case:

> --- gcc/testsuite/gcc.c-torture/compile/pr79413.c (revision 246278)
> +++ gcc/testsuite/gcc.c-torture/compile/pr79413.c (working copy)
> @@ -1,3 +1,4 @@
> +/* { dg-require-effective-target alloca } */
>  /* PR c/79413 */

... previously did PASS for anything but "-O0" (that is, any "alloca"
usage got optimized away).  Now changed as follows:

[-FAIL:-]{+UNSUPPORTED:+} gcc.c-torture/compile/pr79413.c   -O0  [-(test 
for excess errors)-]
[-PASS:-]{+UNSUPPORTED:+} gcc.c-torture/compile/pr79413.c   -O1  [-(test 
for excess errors)-]
[-PASS:-]{+UNSUPPORTED:+} gcc.c-torture/compile/pr79413.c   -O2  [-(test 
for excess errors)-]
[-PASS:-]{+UNSUPPORTED:+} gcc.c-torture/compile/pr79413.c   -O3 -g  [-(test 
for excess errors)-]
[-PASS:-]{+UNSUPPORTED:+} gcc.c-torture/compile/pr79413.c   -Os  [-(test 
for excess errors)-]

[-FAIL:-]{+UNSUPPORTED:+} gcc.dg/torture/pr71881.c   -O0  [-(test for 
excess errors)-]
[-PASS:-]{+UNSUPPORTED:+} gcc.dg/torture/pr71881.c   -O1  [-(test for 
excess errors)-]
[-PASS:-]{+UNSUPPORTED:+} gcc.dg/torture/pr71881.c   -O2  [-(test for 
excess errors)-]
[-PASS:-]{+UNSUPPORTED:+} gcc.dg/torture/pr71881.c   -O3 
-fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions  
[-(test for excess errors)-]
[-PASS:-]{+UNSUPPORTED:+} gcc.dg/torture/pr71881.c   -O3 -g  [-(test for 
excess errors)-]
[-PASS:-]{+UNSUPPORTED:+} gcc.dg/torture/pr71881.c   -Os  [-(test for 
excess errors)-]

Would it be useful to XFAIL these for "-O0" only (along with a comment),
so that we continue testing that any "alloca" usage gets optimized away?
(Just an idea.)


Grüße
 Thomas


Re: [PATCH] Handle PHI nodes w/o a argument (PR ipa/80205).

2017-03-28 Thread Richard Biener
On Tue, Mar 28, 2017 at 9:45 AM, Martin Liška  wrote:
> On 03/27/2017 04:27 PM, Richard Biener wrote:
>> On Mon, Mar 27, 2017 at 4:14 PM, Richard Biener
>>  wrote:
>>> On Mon, Mar 27, 2017 at 2:47 PM, Martin Liška  wrote:
 Hello.

 As described in the PR, we can create a PHI node in einline that has no 
 argument.
 That can cause ICE in devirtualization and should be thus handled.

 Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

 Ready to be installed?
>>>
>>> We shouldn't ever have a PHI w/o argument.
>>
>> ;;   basic block 14, loop depth 0
>> ;;pred:
>>   # SR.2_19 = PHI <>
>>  [0.00%]:
>>   a::~a ();
>>   resx 12
>> ;;succ:   17
>>
>> the CFG has not been cleaned up here (this block is unreachable).
>>
>> Hmm, I see we are called from fold_stmt.  I suppose we process
>> statements_to_fold before removing unreachable blocks to not
>> walk over dead stmts...  chicken-and-egg...
>>
>> Still not creating that PHI should be possible.
>
> I see, thanks for help. Patch fixes the issue, may I install it after
> regression tested?

I think it's progression, still not 100% safe as we have a SSA name with
a GIMPLE_NOP definition that is not in any BB and the SSA name is not
a default def.

But yes, I've written a comment to that effect ;)

Thus ok.

An improvement would be to not copy unreachable regions at all...

Thanks,
Richard.

> Thanks,
> Martin
>
>>
>> Index: gcc/tree-inline.c
>> ===
>> --- gcc/tree-inline.c   (revision 246500)
>> +++ gcc/tree-inline.c   (working copy)
>> @@ -2344,6 +2344,13 @@ copy_phis_for_bb (basic_block bb, copy_b
>>if (!virtual_operand_p (res))
>> {
>>   walk_tree (_res, copy_tree_body_r, id, NULL);
>> + if (EDGE_COUNT (new_bb->preds) == 0)
>> +   {
>> + /* Technically we'd want a SSA_DEFAULT_DEF here... */
>> + SSA_NAME_DEF_STMT (new_res) = gimple_build_nop ();
>> +   }
>> + else
>> +   {
>>   new_phi = create_phi_node (new_res, new_bb);
>>   FOR_EACH_EDGE (new_edge, ei, new_bb->preds)
>> {
>> @@ -2389,6 +2396,7 @@ copy_phis_for_bb (basic_block bb, copy_b
>>
>>   add_phi_arg (new_phi, new_arg, new_edge, locus);
>> }
>> +   }
>> }
>>  }
>>
>>
>>
 Martin
>


Re: [PATCH] Support for Ada on aarch64 with -mabi=ilp32

2017-03-28 Thread Arnaud Charlet
>   PR ada/80117
>   * system-linux-arm-ilp32.ads: New file.
>   * gcc-interface/Makefile.in (LIBGNAT_TARGET_PAIRS_COMMON): Use it
>   for aarch64-linux with -mabi=ilp32.

OK, thanks.

Arno


Re: [PATCH] Fix calls.c for a _complex type (PR ipa/80104).

2017-03-28 Thread Richard Biener
On Mon, Mar 27, 2017 at 11:48 PM, Martin Jambor  wrote:
> Hi,
>
> On Mon, Mar 27, 2017 at 12:15:10PM -0600, Jeff Law wrote:
>> On 03/27/2017 05:40 AM, Martin Liška wrote:
>> > Hello.
>> >
>> > There's alternative approach suggested by Martin Jambor.
>> > Patch can bootstrap on ppc64le-redhat-linux and survives regression tests 
>> > and
>> > s390x cross compiler does not ICE.
>> >
>> > Martin
>> >
>> > 2017-03-23  Martin Liska  
>> >
>> > PR ipa/80104
>> > * cgraphunit.c (cgraph_node::expand_thunk): Mark argument of a
>> > thunk call as DECL_GIMPLE_REG_P when vector or complex type.
>> Can you fix the documentation for DECL_GIMPLE_REG_P to indiate that it can
>> be set on parameters.
>>
>> In gimplify_function_tree we have this:
>>
>>  for (parm = DECL_ARGUMENTS (fndecl); parm ; parm = DECL_CHAIN (parm))
>> {
>>   /* Preliminarily mark non-addressed complex variables as eligible
>>  for promotion to gimple registers.  We'll transform their uses
>>  as we find them.  */
>>   if ((TREE_CODE (TREE_TYPE (parm)) == COMPLEX_TYPE
>>|| TREE_CODE (TREE_TYPE (parm)) == VECTOR_TYPE)
>>   && !TREE_THIS_VOLATILE (parm)
>>   && !needs_to_live_in_memory (parm))
>> DECL_GIMPLE_REG_P (parm) = 1;
>> }
>>
>> Aren't you essentially doing the same thing for thunks?
>
> Yes.
>
>> Does it make sense
>> to pull that into a little function and just call it from both places?
>
> Possibly...
>
>>
>> If not, do we need to add the !TREE_THIS_VOLATILE and
>> !needs_to_live_in_memory checks to the thunks version?
>
> ...although if any of these checks fail, the bug will re-surface.
>
> I do not really know what a volatile parameter means, let alone a
> volatile parameter of a hunk.  Unless, I am mistaken, hunk parameters
> are never made TREE_ADDRESSABLE, so needs_to_live_in_memory can be
> omitted.

Yeah, I think the thunk case is quite constrained so the revised patch
is ok with me.
The volatile check is somewhat superfluous as even DECL_GIMPLE_REG_P volatiles
are not written into-SSA (is_gimple_reg () still returns false).  Likewise for
needs_to_live_in_memory.

Thanks,
Richard.

>>
>> Generally OK, just want to work through these couple niggling details.
>>
>
> Thanks for looking at this,
>
> Martin


Re: [PATCH] Fix ICE in fold_comparison with -fsanitize=shift (PR sanitizer/80067)

2017-03-28 Thread Richard Biener
On Mon, Mar 27, 2017 at 7:30 PM, Marek Polacek  wrote:
> The code in fold_comparison calls save_expr on an expression and then tries to
> set a location of the expression.  But since save_expr calls fold, it can
> produce an integer constant, so we must be more careful when setting its
> location.  In this case we had
>
>   (int) a > 646
>
> where 'a' is signed char so we fold it to 0.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk/6?
>
> 2017-03-27  Marek Polacek  
>
> PR sanitizer/80067
> * fold-const.c (fold_comparison): Use protected_set_expr_location
> instead of SET_EXPR_LOCATION.
>
> * c-c++-common/ubsan/shift-10.c: New test.
>
> diff --git gcc/fold-const.c gcc/fold-const.c
> index 1a9a264..6db16b5 100644
> --- gcc/fold-const.c
> +++ gcc/fold-const.c
> @@ -8704,7 +8704,7 @@ fold_comparison (location_t loc, enum tree_code code, 
> tree type,
>   if (save_p)
> {
>   tem = save_expr (build2 (code, type, cval1, cval2));
> - SET_EXPR_LOCATION (tem, loc);
> + protected_set_expr_location (tem, loc);

I believe using

   tem = save_expr (build2_loc (loc, code, type, cval1, cval2));

would have worked just fine.  save_expr uses the exprs location (if available).

But the patch is ok as well.

Richard.

>   return tem;
> }
>   return fold_build2_loc (loc, code, type, cval1, cval2);
> diff --git gcc/testsuite/c-c++-common/ubsan/shift-10.c 
> gcc/testsuite/c-c++-common/ubsan/shift-10.c
> index e69de29..9202fcc 100644
> --- gcc/testsuite/c-c++-common/ubsan/shift-10.c
> +++ gcc/testsuite/c-c++-common/ubsan/shift-10.c
> @@ -0,0 +1,10 @@
> +/* PR sanitizer/80067 */
> +/* { dg-do compile } */
> +/* { dg-options "-fsanitize=shift" } */
> +
> +extern signed char a;
> +void
> +foo ()
> +{
> +  0 << ((647 > a) - 1);
> +}
>
> Marek


[PATCH] PR libstdc++/80229 restore support for shared_ptr

2017-03-28 Thread Jonathan Wakely

My recent refactoring of enable_shared_from_this broke support for an
obscure use case, where shared_ptr "owns" a pointer to function (and
the deleter does something with it, like unregister a callback from a
plugin).

The problem is simply that I made the new
_M_enable_shared_from_this_with overloads take a const _Yp* parameter,
so that _Yp would be deduced as the non-const type. That was just
laziness, to save using remove_const on the type. But that breaks
function pointers, because const _Yp* won't deduce a type like
void(*)(), and so there is no viable overload of
_M_enable_shared_from_this_with.

The fix is just to use a parameter of _Yp* and then use remove_cv<_Yp>
to get the unqualified type.

I'm also adjusting a test which uses const_pointer_cast to cast a
shared_ptr to shared_ptr, but the object it owns was born
const so casting it away and accessing it as non-const is undefined.

PR libstdc++/80229
* include/bits/shared_ptr_base.h
(__shared_ptr::_M_enable_shared_from_this_with): Change parameters to
non-const and then use remove_cv to get unqualified type.
* testsuite/20_util/enable_shared_from_this/members/const.cc: Don't
cast away constness on object created const.
* testsuite/20_util/shared_ptr/cons/80229.cc: New test.

Tested powerpc64le-linux, committed to trunk.


commit fc31b73a950f957b7b5df2b56cb9285fac3edcd3
Author: Jonathan Wakely 
Date:   Tue Mar 28 01:50:14 2017 +0100

PR libstdc++/80229 restore support for shared_ptr

PR libstdc++/80229
* include/bits/shared_ptr_base.h
(__shared_ptr::_M_enable_shared_from_this_with): Change parameters to
non-const and then use remove_cv to get unqualified type.
* testsuite/20_util/enable_shared_from_this/members/const.cc: Don't
cast away constness on object created const.
* testsuite/20_util/shared_ptr/cons/80229.cc: New test.

diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h 
b/libstdc++-v3/include/bits/shared_ptr_base.h
index a203f42..c8d7f20 100644
--- a/libstdc++-v3/include/bits/shared_ptr_base.h
+++ b/libstdc++-v3/include/bits/shared_ptr_base.h
@@ -1363,17 +1363,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct __has_esft_base<_Yp, __void_t<__esft_base_t<_Yp>>>
: __not_> { }; // No enable shared_from_this for arrays
 
-  template
-   typename enable_if<__has_esft_base<_Yp>::value>::type
-   _M_enable_shared_from_this_with(const _Yp* __p) noexcept
+  template::type>
+   typename enable_if<__has_esft_base<_Yp2>::value>::type
+   _M_enable_shared_from_this_with(_Yp* __p) noexcept
{
  if (auto __base = __enable_shared_from_this_base(_M_refcount, __p))
-   __base->_M_weak_assign(const_cast<_Yp*>(__p), _M_refcount);
+   __base->_M_weak_assign(const_cast<_Yp2*>(__p), _M_refcount);
}
 
-  template
-   typename enable_if::value>::type
-   _M_enable_shared_from_this_with(const _Yp*) noexcept
+  template::type>
+   typename enable_if::value>::type
+   _M_enable_shared_from_this_with(_Yp*) noexcept
{ }
 
   void*
diff --git 
a/libstdc++-v3/testsuite/20_util/enable_shared_from_this/members/const.cc 
b/libstdc++-v3/testsuite/20_util/enable_shared_from_this/members/const.cc
index 0f77726..3f8a6a5 100644
--- a/libstdc++-v3/testsuite/20_util/enable_shared_from_this/members/const.cc
+++ b/libstdc++-v3/testsuite/20_util/enable_shared_from_this/members/const.cc
@@ -32,9 +32,9 @@ test01()
 {
   struct X : public std::enable_shared_from_this { };
   using CX = const X;
-  std::shared_ptr p(new X);
+  std::shared_ptr p(new CX);
   VERIFY( share_ownership(p->shared_from_this(), p) );
-  p.reset(new CX);
+  p.reset(new X);
   VERIFY( share_ownership(p->shared_from_this(), p) );
   auto p2 = std::const_pointer_cast(p)->shared_from_this();
   VERIFY( share_ownership(p2, p) );
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/80229.cc 
b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/80229.cc
new file mode 100644
index 000..7b89066
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/80229.cc
@@ -0,0 +1,26 @@
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library 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.
+
+// This library 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 this library; see the file COPYING3.  If not see
+// .
+

Re: [PATCH] Handle PHI nodes w/o a argument (PR ipa/80205).

2017-03-28 Thread Martin Liška
On 03/27/2017 04:27 PM, Richard Biener wrote:
> On Mon, Mar 27, 2017 at 4:14 PM, Richard Biener
>  wrote:
>> On Mon, Mar 27, 2017 at 2:47 PM, Martin Liška  wrote:
>>> Hello.
>>>
>>> As described in the PR, we can create a PHI node in einline that has no 
>>> argument.
>>> That can cause ICE in devirtualization and should be thus handled.
>>>
>>> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
>>>
>>> Ready to be installed?
>>
>> We shouldn't ever have a PHI w/o argument.
> 
> ;;   basic block 14, loop depth 0
> ;;pred:
>   # SR.2_19 = PHI <>
>  [0.00%]:
>   a::~a ();
>   resx 12
> ;;succ:   17
> 
> the CFG has not been cleaned up here (this block is unreachable).
> 
> Hmm, I see we are called from fold_stmt.  I suppose we process
> statements_to_fold before removing unreachable blocks to not
> walk over dead stmts...  chicken-and-egg...
> 
> Still not creating that PHI should be possible.

I see, thanks for help. Patch fixes the issue, may I install it after
regression tested?

Thanks,
Martin

> 
> Index: gcc/tree-inline.c
> ===
> --- gcc/tree-inline.c   (revision 246500)
> +++ gcc/tree-inline.c   (working copy)
> @@ -2344,6 +2344,13 @@ copy_phis_for_bb (basic_block bb, copy_b
>if (!virtual_operand_p (res))
> {
>   walk_tree (_res, copy_tree_body_r, id, NULL);
> + if (EDGE_COUNT (new_bb->preds) == 0)
> +   {
> + /* Technically we'd want a SSA_DEFAULT_DEF here... */
> + SSA_NAME_DEF_STMT (new_res) = gimple_build_nop ();
> +   }
> + else
> +   {
>   new_phi = create_phi_node (new_res, new_bb);
>   FOR_EACH_EDGE (new_edge, ei, new_bb->preds)
> {
> @@ -2389,6 +2396,7 @@ copy_phis_for_bb (basic_block bb, copy_b
> 
>   add_phi_arg (new_phi, new_arg, new_edge, locus);
> }
> +   }
> }
>  }
> 
> 
> 
>>> Martin



[PATCH, testsuite] Allow braces around relative line numbers

2017-03-28 Thread Tom de Vries

Hi,

this patch fixes testsuite PR80220 - "relative line numbers don't work 
when put between braces".



Consider gcc/testsuite/gcc.dg/990506-0.c, which has absolute line 
numbers between braces:

...
$ cat -n 990506-0.c
 1  /* Verify that a diagnostic is issued without crashing due to
 2 --enable-checking catching a bug in the C front end.  */
 3  /* { dg-do compile } */
 4  x()
 5  {
 6foo (i);
 7	  /* { dg-error "undeclared" "undeclared-variable message" { 
target *-*-* } { 6 } } */
 8	  /* { dg-message "function it appears in" "reminder message" { 
target *-*-* } { 6 } } */

 9  }
...

When we rewrite the test to use relative line numbers:
...
diff --git a/gcc/testsuite/gcc.dg/990506-0.c 
b/gcc/testsuite/gcc.dg/990506-0.c

index 3cd3be3..08ba856 100644
--- a/gcc/testsuite/gcc.dg/990506-0.c
+++ b/gcc/testsuite/gcc.dg/990506-0.c
@@ -4,6 +4,6 @@
 x()
 {
   foo (i);
-  /* { dg-error "undeclared" "undeclared-variable message" { target 
*-*-* } { 6 } } */
-  /* { dg-message "function it appears in" "reminder message" { target 
*-*-* } { 6 } } */
+  /* { dg-error "undeclared" "undeclared-variable message" { target 
*-*-* } { .-1 } } */
+  /* { dg-message "function it appears in" "reminder message" { target 
*-*-* } { .-2 } } */

 }
...

we run into trouble:
...
ERROR: gcc.dg/990506-0.c: expected integer but got " .-1 " for " 
dg-error 7 "undeclared" "undeclared-variable message" { target *-*-* } { 
.-1 } "

...

The problem is that the relative line number is written between braces, 
which results in whitespace before and after the number, and the 
relative line number handling in process-message doesn't handle that 
whitespace well.


This patch fixes that.

Bootstrapped and reg-tested on x86_64.

OK for stage4 or stage1 trunk?

Thanks,
- Tom
Allow braces around relative line numbers

2017-03-27  Tom de Vries  

	PR testsuite/80220
	* gcc.dg/dg-test-1.c: Add dg-error tests using relative line numbers
	between braces.
	(foo2): New function.
	* lib/gcc-dg.exp (process-message): Handle whitespace in relative line
	number argument.

---
 gcc/testsuite/gcc.dg/dg-test-1.c |  7 +++
 gcc/testsuite/lib/gcc-dg.exp | 16 +++-
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/dg-test-1.c b/gcc/testsuite/gcc.dg/dg-test-1.c
index c67f93b..2414ecc 100644
--- a/gcc/testsuite/gcc.dg/dg-test-1.c
+++ b/gcc/testsuite/gcc.dg/dg-test-1.c
@@ -40,3 +40,10 @@ baz (int i, int j)
 
 
 /* { dg-warning "unused parameter 'j'" "warn6" { target *-*-* } .-10 } */
+
+/* Test for relative line numbers in braces */
+void
+foo2 (void)
+{			/* { dg-error "'a' undeclared" "err1" { target *-*-* } { .+1 } } */
+  int z = a + b + c;/* { dg-error "'b' undeclared" "err2" { target *-*-* } { . } } */
+}			/* { dg-error "'c' undeclared" "err3" { target *-*-* } { .-1 } } */
diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp
index 83c38cf..e986d64 100644
--- a/gcc/testsuite/lib/gcc-dg.exp
+++ b/gcc/testsuite/lib/gcc-dg.exp
@@ -988,11 +988,17 @@ if { [info procs saved-dg-error] == [list] \
 proc process-message { msgproc msgprefix dgargs } {
 upvar dg-messages dg-messages
 
-# Handle relative line specification, .+1 or .-1 etc.
-if { [llength $dgargs] == 5
-	 && [regsub "^\.\[+-\](\[0-9\]+)$" [lindex $dgargs 4] "\\1" num] } {
-	set num [expr [lindex $dgargs 0] [string index [lindex $dgargs 4] 1] $num]
-	set dgargs [lreplace $dgargs 4 4 $num]
+if { [llength $dgargs] == 5 } {
+	set linenr [lindex $dgargs 4]
+	# Strip whitespace added by using braces.
+	set linenr [string trimleft [string trimright $linenr]]
+	# Handle relative line specification, .+1 or .-1 etc.
+	if { [regsub "^\.\[+-\](\[0-9\]+)$" $linenr "\\1" num] } {
+	set directivelinenr [lindex $dgargs 0]
+	set op [string index $linenr 1]
+	set linenr [expr $directivelinenr $op $num]
+	}
+	set dgargs [lreplace $dgargs 4 4 $linenr]
 }
 
 # Process the dg- directive, including adding the regular expression