Re: [PATCH 4/4][Ada,DJGPP] Ada support for DJGPP

2016-09-25 Thread Andris Pavenis

On 09/25/2016 09:10 PM, Arnaud Charlet wrote:

Is the above change really necessary? Would be nice to get rid of this
extra code. The rest looks OK to me.

It is required for support of environment when LFN support is either
not available or disabled for some reason (for example FreeDOS
without LFN support loaded).

Does it matter for GNAT usage/users in practice?

Arno


It may. I do not actually have information about environments used by poeple using DJGPP build. I'm 
providing compiler packages for them.


There are actually 2 levels of non-LFN support for DJGPP port of CCC:

1) ability to run user compiled programs (the ones which are compatible with required restrictions) 
without LFN support


2) the ability to compile using GCC in such environment

Submitted patches only addresses level 1. I'm not sure I'll ever submit changes for level 2. 
Absence of these changes does not prevent bootstrapping GCC iwhen LFN is available (like in recent 
Windows versions).


Discussed change belongs to level 1 (ability to run compiled programs without 
LFN support available).

Andris




Re: [PR77719] Fix ICE in pp_string, at pretty-print.c:955

2016-09-25 Thread kugan



On 25/09/16 04:50, kugan wrote:

Hi,

In make_new_ssa_for_def (tree-reassoc.c) we should use gimple_get_lhs to
get lhs instead of gimple_assign_lhs as stmt can be builtins too.
Attached patch fixes this.

Testcase from PR (attached) seems to fail. I dont any fortran so I didnt
try fixing it. Any help here is appreciate. The log is:


Here is a patch with the testcase based on the feedback from Joost 
VandeVondele and Dominique d'Humieres. Bootstrapped and regression 
tested on x86_64-linux-gnu with no new regressions.


Is this OK for trunk?

Thanks,
kugan

gcc/testsuite/ChangeLog:

2016-09-25  Kugan Vivekanandarajah  

* gfortran.dg/pr77719.f90: New test.

gcc/ChangeLog:

2016-09-25  Kugan Vivekanandarajah  

* tree-ssa-reassoc.c (make_new_ssa_for_def): Use gimple_get_lhs to get 
lhs
instead of gimple_assign_lhs as stmt can be builtins too.

diff --git a/gcc/testsuite/gfortran.dg/pr77719.f90 
b/gcc/testsuite/gfortran.dg/pr77719.f90
index e69de29..974d70a 100644
--- a/gcc/testsuite/gfortran.dg/pr77719.f90
+++ b/gcc/testsuite/gfortran.dg/pr77719.f90
@@ -0,0 +1,26 @@
+! PR middle-end/77719
+! { dg-do compile }
+! { dg-options "-O3 -ffast-math" }
+
+SUBROUTINE urep_egr(erep,derep,surr)
+  INTEGER, PARAMETER :: dp=8
+  REAL(dp), INTENT(inout)  :: erep, derep(3)
+  REAL(dp), INTENT(in) :: surr(2)
+  REAL(dp) :: de_z, rz
+  INTEGER :: isp,spdim,jsp,nsp
+  IF (n_urpoly > 0) THEN
+IF (r < spxr(1,1)) THEN
+  ispg: DO isp = 1,spdim ! condition ca)
+IF (isp /= spdim) THEN
+  nsp = 5 ! condition cb
+  DO jsp = 0,nsp
+IF( jsp <= 3 ) THEN
+ELSE
+  erep = erep + surr(jsp-3)*rz**(jsp)
+ENDIF
+  END DO
+END IF
+  END DO ispg
+END IF
+  END IF
+END SUBROUTINE urep_egr
diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
index 8fc76e4..d94ff70 100644
--- a/gcc/tree-ssa-reassoc.c
+++ b/gcc/tree-ssa-reassoc.c
@@ -1158,7 +1158,7 @@ make_new_ssa_for_def (gimple *stmt)
   use_operand_p use;
   imm_use_iterator iter;
   tree new_lhs;
-  tree lhs = gimple_assign_lhs (stmt);
+  tree lhs = gimple_get_lhs (stmt);
 
   new_lhs = make_ssa_name (TREE_TYPE (lhs));
   gimple_set_lhs (stmt, new_lhs);


Re: [PATCH, 5.x/6.x/7.x] Be more conservative in early inliner if FDO is enabled

2016-09-25 Thread Yuan, Pengfei
Hi,

May I ask if there is any decision?

Regards,
Yuan, Pengfei

> > > I also like a new param better as it avoids a new magic constant and
> > > makes playing with
> > > it easier (your patch removes the ability to do statistics like you did 
> > > via the
> > > early-inlining-insns parameter by forcing it to two).
> > 
> > Hmm, you are right that you do not know if this particular function will get
> > profile (forgot about that).  Still, please use two params - it is more
> > consistent with what we have now and we may make it profile specific in
> > future..
> > 
> > Honza
> > > 
> > > Thanks,
> > > Richard.
> 
> A new patch for trunk is attached.
> 
> Regards,
> Yuan, Pengfei
> 
> 
> 2016-09-16  Yuan Pengfei  
> 
>   * doc/invoke.texi (--param early-inlining-insns-feedback): New.
>   * ipa-inline.c (want_early_inline_function_p): Use
>   PARAM_EARLY_INLINING_INSNS_FEEDBACK when FDO is enabled.
>   * params.def (PARAM_EARLY_INLINING_INSNS_FEEDBACK): Define.
>   (PARAM_EARLY_INLINING_INSNS): Change help string accordingly.
> 
> 
> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> index 8eb5eff..6e7659a 100644
> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -9124,12 +9124,18 @@ given call expression.  This parameter limits 
> inlining only to call expressions
>  whose probability exceeds the given threshold (in percents).
>  The default value is 10.
>  
>  @item early-inlining-insns
> +@itemx early-inlining-insns-feedback
>  Specify growth that the early inliner can make.  In effect it increases
>  the amount of inlining for code having a large abstraction penalty.
>  The default value is 14.
>  
> +The @option{early-inlining-insns-feedback} parameter is used only when
> +profile feedback-directed optimizations are enabled (by
> +@option{-fprofile-generate} or @option{-fprofile-use}).
> +The default value is 2.
> +
>  @item max-early-inliner-iterations
>  Limit of iterations of the early inliner.  This basically bounds
>  the number of nested indirect calls the early inliner can resolve.
>  Deeper chains are still handled by late inlining.
> diff --git a/gcc/ipa-inline.c b/gcc/ipa-inline.c
> index 5c9366a..e028c08 100644
> --- a/gcc/ipa-inline.c
> +++ b/gcc/ipa-inline.c
> @@ -594,10 +594,17 @@ want_early_inline_function_p (struct cgraph_edge *e)
>  }
>else
>  {
>int growth = estimate_edge_growth (e);
> +  int growth_limit;
>int n;
>  
> +  if ((profile_arc_flag && !flag_test_coverage)
> +   || (flag_branch_probabilities && !flag_auto_profile))
> + growth_limit = PARAM_VALUE (PARAM_EARLY_INLINING_INSNS_FEEDBACK);
> +  else
> + growth_limit = PARAM_VALUE (PARAM_EARLY_INLINING_INSNS);
> +
>if (growth <= 0)
>   ;
>else if (!e->maybe_hot_p ()
>  && growth > 0)
> @@ -610,9 +617,9 @@ want_early_inline_function_p (struct cgraph_edge *e)
>xstrdup_for_dump (callee->name ()), callee->order,
>growth);
> want_inline = false;
>   }
> -  else if (growth > PARAM_VALUE (PARAM_EARLY_INLINING_INSNS))
> +  else if (growth > growth_limit)
>   {
> if (dump_file)
>   fprintf (dump_file, "  will not early inline: %s/%i->%s/%i, "
>"growth %i exceeds --param early-inlining-insns\n",
> @@ -622,9 +629,9 @@ want_early_inline_function_p (struct cgraph_edge *e)
>growth);
> want_inline = false;
>   }
>else if ((n = num_calls (callee)) != 0
> -&& growth * (n + 1) > PARAM_VALUE (PARAM_EARLY_INLINING_INSNS))
> +&& growth * (n + 1) > growth_limit)
>   {
> if (dump_file)
>   fprintf (dump_file, "  will not early inline: %s/%i->%s/%i, "
>"growth %i exceeds --param early-inlining-insns "
> diff --git a/gcc/params.def b/gcc/params.def
> index 79b7dd4..91ea513 100644
> --- a/gcc/params.def
> +++ b/gcc/params.def
> @@ -199,12 +199,20 @@ DEFPARAM(PARAM_INLINE_UNIT_GROWTH,
>  DEFPARAM(PARAM_IPCP_UNIT_GROWTH,
>"ipcp-unit-growth",
>"How much can given compilation unit grow because of the 
> interprocedural constant propagation (in percent).",
>10, 0, 0)
> -DEFPARAM(PARAM_EARLY_INLINING_INSNS,
> -  "early-inlining-insns",
> -  "Maximal estimated growth of function body caused by early inlining of 
> single call.",
> -  14, 0, 0)
> +DEFPARAM (PARAM_EARLY_INLINING_INSNS_FEEDBACK,
> +   "early-inlining-insns-feedback",
> +   "Maximal estimated growth of function body caused by early "
> +   "inlining of single call.  Used when profile feedback-directed "
> +   "optimizations are enabled.",
> +   2, 0, 0)
> +DEFPARAM (PARAM_EARLY_INLINING_INSNS,
> +   "early-inlining-insns",
> +   "Maximal estimated growth of function body caused by early "
> +   "inlining of single call.  Used when profile feedback-directed "
> +   "optimizations are not 

[v3 PATCH] PR libstdc++/77727

2016-09-25 Thread Ville Voutilainen
Tested on Linux-x64.

2016-09-26  Ville Voutilainen  

PR libstdc++/77727
* include/std/optional (optional(const optional<_Up>&)):
Default-initialize the base and use emplace.
(optional(optional<_Up>&&)): Likewise.
* testsuite/20_util/optional/cons/77727.cc: New.
diff --git a/libstdc++-v3/include/std/optional 
b/libstdc++-v3/include/std/optional
index efb0eb6..b14faf1 100644
--- a/libstdc++-v3/include/std/optional
+++ b/libstdc++-v3/include/std/optional
@@ -502,7 +502,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__not_<__converts_from_optional<_Tp, _Up>>
>::value, bool> = true>
   constexpr optional(const optional<_Up>& __t)
-: _Base(__t ? _Base(std::in_place, *__t) : _Base()) { }
+  {
+   if (__t)
+ emplace(*__t);
+  }
 
   template >
   >::value, bool> = false>
   explicit constexpr optional(const optional<_Up>& __t)
-: _Base(__t ? _Base(std::in_place, *__t) : _Base()) { }
+  {
+   if (__t)
+ emplace(*__t);
+  }
 
   template >
  >::value, bool> = true>
   constexpr optional(optional<_Up>&& __t)
-: _Base(__t ? _Base(std::in_place, std::move(*__t)) : _Base()) { }
+  {
+   if (__t)
+ emplace(std::move(*__t));
+  }
 
   template >
>::value, bool> = false>
   explicit constexpr optional(optional<_Up>&& __t)
-: _Base(__t ? _Base(std::in_place, std::move(*__t)) : _Base()) { }
+  {
+   if (__t)
+ emplace(std::move(*__t));
+  }
 
   template
   explicit constexpr optional(in_place_t, _Args&&... __args)
diff --git a/libstdc++-v3/testsuite/20_util/optional/cons/77727.cc 
b/libstdc++-v3/testsuite/20_util/optional/cons/77727.cc
new file mode 100644
index 000..7a3b101
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/optional/cons/77727.cc
@@ -0,0 +1,51 @@
+// { dg-options "-std=gnu++17" }
+// { dg-do run }
+
+// Copyright (C) 2016 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 moved_to of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+#include 
+#include 
+
+
+struct NonTransferable
+{
+  int x;
+  NonTransferable(int x) : x(x) {}
+  NonTransferable(NonTransferable&&) = delete;
+  NonTransferable& operator=(NonTransferable&&) = delete;
+  operator int() {return x;}
+};
+
+int main()
+{
+  std::optional oi;
+  std::optional ot(std::move(oi));
+  VERIFY(!ot);
+
+  std::optional oi2;
+  std::optional ot2(oi2);
+  VERIFY(!ot);
+
+  std::optional oi3{42};
+  std::optional ot3(std::move(oi3));
+  VERIFY(ot3 && *ot3 == 42);
+
+  std::optional oi4{666};
+  std::optional ot4(oi4);
+  VERIFY(ot4 && *ot4 == 666);
+}


[Committed] PR fortran/77429

2016-09-25 Thread Steve Kargl
Committed as obvious.

2016-09-25  Steven G. Kargl  

PR fortran/77429 
* dependency.c (gfc_check_dependency):  Convert gcc_assert() to
a conditional and possible call to  gfc_internal_error().

2016-09-25  Steven G. Kargl  

PR fortran/77429 
* gfortran.dg/pr77429.f90: New test.

Index: gcc/fortran/dependency.c
===
--- gcc/fortran/dependency.c(revision 240051)
+++ gcc/fortran/dependency.c(working copy)
@@ -1258,7 +1258,8 @@ gfc_check_dependency (gfc_expr *expr1, g
   && strcmp (expr1->value.function.name, "_F.caf_get") == 0)
 return 0;
 
-  gcc_assert (expr1->expr_type == EXPR_VARIABLE);
+  if (expr1->expr_type != EXPR_VARIABLE)
+gfc_internal_error ("gfc_check_dependency: expecting an EXPR_VARIABLE");
 
   switch (expr2->expr_type)
 {
Index: gcc/testsuite/gfortran.dg/pr77429.f90
===
--- gcc/testsuite/gfortran.dg/pr77429.f90   (nonexistent)
+++ gcc/testsuite/gfortran.dg/pr77429.f90   (working copy)
@@ -0,0 +1,7 @@
+! { dg-do compile }
+program p
+   shape(1) = 0  ! { dg-error "expression in variable definition context" }
+   shape(1,2) = 0! { dg-error "expression in variable definition context" }
+   shape(1,2,3) = 0  ! { dg-error "Too many arguments in call" }
+   lbound([1]) = 0   ! { dg-error "expression in variable definition context" }
+end

-- 
Steve


Re: [PATCH 4/4][Ada,DJGPP] Ada support for DJGPP

2016-09-25 Thread Arnaud Charlet
> >Is the above change really necessary? Would be nice to get rid of this
> >extra code. The rest looks OK to me.
> It is required for support of environment when LFN support is either
> not available or disabled for some reason (for example FreeDOS
> without LFN support loaded).

Does it matter for GNAT usage/users in practice?

Arno


Re: [PATCH] x86_64: fix 'gather' avx2 builtin names

2016-09-25 Thread Sergei Trofimovich
On Sun, 25 Sep 2016 19:01:14 +0200
Jakub Jelinek  wrote:

> On Sun, Sep 25, 2016 at 02:48:19PM +0100, Sergei Trofimovich wrote:
> > From: Sergei Trofimovich 
> > 
> > Today I traced AVX2 optimisation bug in gcc and
> > distilled it down to '__builtin_ia32_gatheraltdiv4si256'
> > generated by gcc.
> > 
> > When I attempted to use this builtin directly
> > in a simple program gcc refused to recognise
> > it as known:
> > 
> >   #include 
> > 
> >   void a (void) {
> > __builtin_ia32_gatheraltdiv4si256 (1);
> >   }
> > 
> >   $ LANG=C gcc -c -march=core-avx2 a.c
> > a.c: In function 'a':
> > a.c:4:5: warning: implicit declaration of function
> > '__builtin_ia32_gatheraltdiv4si256' 
> > [-Wimplicit-function-declaration]
> > 
> > The cause is trailing whitespace in builtin definition:
> > 
> >   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltdiv4si256 
> > ",
> > 
> > Fixed by dropping trailing whitespace.  
> 
> No, that isn't a fix, adding such characters has been an older way to
> express internal only builtins that aren't ever meant to be available to
> users (these days we'd use internal-fn.* stuff, except we don't have support
> for backends adding their own internal functions).

Aha, got it. Having a seemingly callable name is very confusing.

I did grab the name from one of -fdump-tree-all outputs
(bug.c.165t.optimized) which looked as:

  vect_.16_59 = VIEW_CONVERT_EXPR(vect_var_.12_56);
  vect_var_.14_60 = __builtin_ia32_gatheraltdiv4si256  ({ -1, -1, -1, -1, -1, 
-1, -1, -1 }, , vect_.16_59, { -1, -1, -1, 
-1, -1, -1, -1, -1 }, 4);
  vect_.17_61 = VIEW_CONVERT_EXPR(vect_var_.12_57);
  vect_var_.14_62 = __builtin_ia32_gatheraltdiv4si256  ({ -1, -1, -1, -1, -1, 
-1, -1, -1 }, , vect_.17_61, { -1, -1, -1, 
-1, -1, -1, -1, -1 }, 4);

and I assumed that builtin can be used directly to reproduce
smaller example. Sorry for the noise.

-- 

  Sergei


pgpmQcY54o8k2.pgp
Description: Цифровая подпись OpenPGP


Re: [PATCH 4/4][Ada,DJGPP] Ada support for DJGPP

2016-09-25 Thread Andris Pavenis

On 09/25/2016 07:25 PM, Arnaud Charlet wrote:

  int
  __gnat_get_maximum_file_name_length (void)
  {
+#if defined (__DJGPP__)
+  return (_use_lfn(".")) ? -1 : 8;
+#else
return -1;
+#endif
  }

Is the above change really necessary? Would be nice to get rid of this
extra code. The rest looks OK to me.
It is required for support of environment when LFN support is either not available or disabled for 
some reason (for example FreeDOS without LFN support loaded).


Andris



[Committed] PR fortran/77694

2016-09-25 Thread Steve Kargl
Committed as "obvious" even though thomas OK patch
in bugzilla audit trail.

2016-09-25  Steven G. Kargl  

PR fortran/77694
* frontend-passes.c (optimize_binop_array_assignment): Check pointer
for NULL.

2016-09-25  Steven G. Kargl  

PR fortran/77694
* gfortran.dg/pr77694.f90: New test.

Index: gcc/fortran/frontend-passes.c
===
--- gcc/fortran/frontend-passes.c   (revision 240383)
+++ gcc/fortran/frontend-passes.c   (working copy)
@@ -1076,6 +1076,9 @@ optimize_binop_array_assignment (gfc_cod
 {
   gfc_expr *e;
 
+  if (!*rhs)
+return false;
+
   e = *rhs;
   if (e->expr_type == EXPR_OP)
 {
Index: gcc/testsuite/gfortran.dg/pr77694.f90
===
--- gcc/testsuite/gfortran.dg/pr77694.f90   (nonexistent)
+++ gcc/testsuite/gfortran.dg/pr77694.f90   (working copy)
@@ -0,0 +1,7 @@
+! { dg-do compile }
+! { dg-options -O }
+program p
+   logical x(2), y(2)
+   x = .true.
+   y = .nt. x   ! { dg-error "Unknown operator" }
+end

-- 
Steve


Re: [PATCH] x86_64: fix 'gather' avx2 builtin names

2016-09-25 Thread Jakub Jelinek
On Sun, Sep 25, 2016 at 02:48:19PM +0100, Sergei Trofimovich wrote:
> From: Sergei Trofimovich 
> 
> Today I traced AVX2 optimisation bug in gcc and
> distilled it down to '__builtin_ia32_gatheraltdiv4si256'
> generated by gcc.
> 
> When I attempted to use this builtin directly
> in a simple program gcc refused to recognise
> it as known:
> 
>   #include 
> 
>   void a (void) {
> __builtin_ia32_gatheraltdiv4si256 (1);
>   }
> 
>   $ LANG=C gcc -c -march=core-avx2 a.c
> a.c: In function 'a':
> a.c:4:5: warning: implicit declaration of function
> '__builtin_ia32_gatheraltdiv4si256' [-Wimplicit-function-declaration]
> 
> The cause is trailing whitespace in builtin definition:
> 
>   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltdiv4si256 ",
> 
> Fixed by dropping trailing whitespace.

No, that isn't a fix, adding such characters has been an older way to
express internal only builtins that aren't ever meant to be available to
users (these days we'd use internal-fn.* stuff, except we don't have support
for backends adding their own internal functions).

Jakub


Re: [PATCH 4/4][Ada,DJGPP] Ada support for DJGPP

2016-09-25 Thread Arnaud Charlet
>  int
>  __gnat_get_maximum_file_name_length (void)
>  {
> +#if defined (__DJGPP__)
> +  return (_use_lfn(".")) ? -1 : 8;
> +#else
>return -1;
> +#endif
>  }

Is the above change really necessary? Would be nice to get rid of this
extra code. The rest looks OK to me.

Arno


parallel/algo.h cleanup

2016-09-25 Thread François Dumont

Hi

Trivial patch to cleanup parallel/algo.h by generalizing usage of 
std::__iterator_category.


* include/parallel/algo.h: Generalize usage of 
std::__iterator_category.

Adjust whitespaces.

Tested under Linux x86_64 parallel mode.

François

Index: include/parallel/algo.h
===
--- include/parallel/algo.h	(revision 240461)
+++ include/parallel/algo.h	(working copy)
@@ -65,70 +65,66 @@
   // Sequential fallback
   template
 inline _Function
-for_each(_IIter __begin, _IIter __end, _Function __f, 
- __gnu_parallel::sequential_tag)
+for_each(_IIter __begin, _IIter __end, _Function __f,
+	 __gnu_parallel::sequential_tag)
 { return _GLIBCXX_STD_A::for_each(__begin, __end, __f); }
 
-
   // Sequential fallback for input iterator case
   template
 inline _Function
-__for_each_switch(_IIter __begin, _IIter __end, _Function __f, 
-_IteratorTag)
+__for_each_switch(_IIter __begin, _IIter __end, _Function __f,
+		  _IteratorTag)
 { return for_each(__begin, __end, __f, __gnu_parallel::sequential_tag()); }
 
   // Parallel algorithm for random access iterators
   template
 _Function
-__for_each_switch(_RAIter __begin, _RAIter __end, 
-_Function __f, random_access_iterator_tag,
-__gnu_parallel::_Parallelism __parallelism_tag)
+__for_each_switch(_RAIter __begin, _RAIter __end,
+		  _Function __f, random_access_iterator_tag,
+		  __gnu_parallel::_Parallelism __parallelism_tag)
 {
   if (_GLIBCXX_PARALLEL_CONDITION(
-static_cast<__gnu_parallel::_SequenceIndex>(__end - __begin)
->= __gnu_parallel::_Settings::get().for_each_minimal_n
-&& __gnu_parallel::__is_parallel(__parallelism_tag)))
-{
-  bool __dummy;
-__gnu_parallel::__for_each_selector<_RAIter> __functionality;
+	static_cast<__gnu_parallel::_SequenceIndex>(__end - __begin)
+	>= __gnu_parallel::_Settings::get().for_each_minimal_n
+	&& __gnu_parallel::__is_parallel(__parallelism_tag)))
+	{
+	  bool __dummy;
+	  __gnu_parallel::__for_each_selector<_RAIter> __functionality;
 
-  return __gnu_parallel::
-__for_each_template_random_access(
-  __begin, __end, __f, __functionality,
-  __gnu_parallel::_DummyReduct(), true, __dummy, -1,
-  __parallelism_tag);
-}
+	  return __gnu_parallel::
+	__for_each_template_random_access(
+	  __begin, __end, __f, __functionality,
+	  __gnu_parallel::_DummyReduct(), true, __dummy, -1,
+	  __parallelism_tag);
+	}
   else
-return for_each(__begin, __end, __f, __gnu_parallel::sequential_tag());
+	return for_each(__begin, __end, __f, __gnu_parallel::sequential_tag());
 }
 
   // Public interface
   template
 inline _Function
-for_each(_Iterator __begin, _Iterator __end, _Function __f, 
- __gnu_parallel::_Parallelism __parallelism_tag)
+for_each(_Iterator __begin, _Iterator __end, _Function __f,
+	 __gnu_parallel::_Parallelism __parallelism_tag)
 {
-  typedef std::iterator_traits<_Iterator> _IteratorTraits;
-  typedef typename _IteratorTraits::iterator_category _IteratorCategory;
-  return __for_each_switch(__begin, __end, __f, _IteratorCategory(), 
- __parallelism_tag);
+  return __for_each_switch(__begin, __end, __f,
+			   std::__iterator_category(__begin),
+			   __parallelism_tag);
 }
 
   template
 inline _Function
-for_each(_Iterator __begin, _Iterator __end, _Function __f) 
+for_each(_Iterator __begin, _Iterator __end, _Function __f)
 {
-  typedef std::iterator_traits<_Iterator> _IteratorTraits;
-  typedef typename _IteratorTraits::iterator_category _IteratorCategory;
-  return __for_each_switch(__begin, __end, __f, _IteratorCategory());
+  return __for_each_switch(__begin, __end, __f,
+			   std::__iterator_category(__begin));
 }
 
-
   // Sequential fallback
   template
 inline _IIter
-find(_IIter __begin, _IIter __end, const _Tp& __val, 
- __gnu_parallel::sequential_tag)
+find(_IIter __begin, _IIter __end, const _Tp& __val,
+	 __gnu_parallel::sequential_tag)
 { return _GLIBCXX_STD_A::find(__begin, __end, __val); }
 
   // Sequential fallback for input iterator case
@@ -135,7 +131,7 @@
   template
 inline _IIter
 __find_switch(_IIter __begin, _IIter __end, const _Tp& __val,
-_IteratorTag)
+		_IteratorTag)
 { return _GLIBCXX_STD_A::find(__begin, __end, __val); }
 
   // Parallel find for random access iterators
@@ -142,23 +138,23 @@
   template
 _RAIter
 __find_switch(_RAIter __begin, _RAIter __end,
-const _Tp& __val, random_access_iterator_tag)
+		const _Tp& __val, random_access_iterator_tag)
 {
   typedef iterator_traits<_RAIter> _TraitsType;
 

[v3 PATCH] PR libstdc++/77717

2016-09-25 Thread Ville Voutilainen
Tested on Linux-x64.

2016-09-25  Ville Voutilainen  

PR libstdc++/77717
* testsuite/21_strings/basic_string_view/operations/compare/char/1.cc:
Fix an out-of-bounds access.
diff --git 
a/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/compare/char/1.cc
 
b/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/compare/char/1.cc
index 77188b3..28e2514 100644
--- 
a/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/compare/char/1.cc
+++ 
b/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/compare/char/1.cc
@@ -82,8 +82,8 @@ test01()
   test_value(strncmp(str_1.data(), str_0.data(), 6), z);
   test_value(strncmp(str_1.data(), str_0.data(), 14), lt);
   test_value(memcmp(str_1.data(), str_0.data(), 6), z);
-  test_value(memcmp(str_1.data(), str_0.data(), 14), lt);
-  test_value(memcmp("costa marbella", "costa rica", 14), lt);
+  test_value(memcmp(str_1.data(), str_0.data(), 10), lt);
+  test_value(memcmp("costa marbella", "costa rica", 10), lt);
 
   // int compare(const basic_string_view& str) const;
   test_value(str_0.compare(str_1), gt); //because r>m


[PATCH] x86_64: fix 'gather' avx2 builtin names

2016-09-25 Thread Sergei Trofimovich
From: Sergei Trofimovich 

Today I traced AVX2 optimisation bug in gcc and
distilled it down to '__builtin_ia32_gatheraltdiv4si256'
generated by gcc.

When I attempted to use this builtin directly
in a simple program gcc refused to recognise
it as known:

  #include 

  void a (void) {
__builtin_ia32_gatheraltdiv4si256 (1);
  }

  $ LANG=C gcc -c -march=core-avx2 a.c
a.c: In function 'a':
a.c:4:5: warning: implicit declaration of function
'__builtin_ia32_gatheraltdiv4si256' [-Wimplicit-function-declaration]

The cause is trailing whitespace in builtin definition:

  def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltdiv4si256 ",

Fixed by dropping trailing whitespace.

Signed-off-by: Sergei Trofimovich 
---
 gcc/config/i386/i386.c | 32 
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 143b905..48a5354 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -31403,19 +31403,19 @@ ix86_init_mmx_sse_builtins (void)
   V4SI_FTYPE_V4SI_PCINT_V4DI_V4SI_INT,
   IX86_BUILTIN_GATHERDIV8SI);
 
-  def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltsiv4df ",
+  def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltsiv4df",
   V4DF_FTYPE_V4DF_PCDOUBLE_V8SI_V4DF_INT,
   IX86_BUILTIN_GATHERALTSIV4DF);
 
-  def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltdiv4sf256 ",
+  def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltdiv4sf256",
   V8SF_FTYPE_V8SF_PCFLOAT_V4DI_V8SF_INT,
   IX86_BUILTIN_GATHERALTDIV8SF);
 
-  def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltsiv4di ",
+  def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltsiv4di",
   V4DI_FTYPE_V4DI_PCINT64_V8SI_V4DI_INT,
   IX86_BUILTIN_GATHERALTSIV4DI);
 
-  def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltdiv4si256 ",
+  def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltdiv4si256",
   V8SI_FTYPE_V8SI_PCINT_V4DI_V8SI_INT,
   IX86_BUILTIN_GATHERALTDIV8SI);
 
@@ -31452,19 +31452,19 @@ ix86_init_mmx_sse_builtins (void)
   V8DI_FTYPE_V8DI_PCINT64_V8DI_QI_INT,
   IX86_BUILTIN_GATHER3DIV8DI);
 
-  def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltsiv8df ",
+  def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltsiv8df",
   V8DF_FTYPE_V8DF_PCDOUBLE_V16SI_QI_INT,
   IX86_BUILTIN_GATHER3ALTSIV8DF);
 
-  def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltdiv8sf ",
+  def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltdiv8sf",
   V16SF_FTYPE_V16SF_PCFLOAT_V8DI_HI_INT,
   IX86_BUILTIN_GATHER3ALTDIV16SF);
 
-  def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltsiv8di ",
+  def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltsiv8di",
   V8DI_FTYPE_V8DI_PCINT64_V16SI_QI_INT,
   IX86_BUILTIN_GATHER3ALTSIV8DI);
 
-  def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltdiv8si ",
+  def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltdiv8si",
   V16SI_FTYPE_V16SI_PCINT_V8DI_HI_INT,
   IX86_BUILTIN_GATHER3ALTDIV16SI);
 
@@ -31565,19 +31565,19 @@ ix86_init_mmx_sse_builtins (void)
   V4SI_FTYPE_V4SI_PCINT_V4DI_QI_INT,
   IX86_BUILTIN_GATHER3DIV8SI);
 
-  def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altsiv4df ",
+  def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altsiv4df",
   V4DF_FTYPE_V4DF_PCDOUBLE_V8SI_QI_INT,
   IX86_BUILTIN_GATHER3ALTSIV4DF);
 
-  def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altdiv8sf ",
+  def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altdiv8sf",
   V8SF_FTYPE_V8SF_PCFLOAT_V4DI_QI_INT,
   IX86_BUILTIN_GATHER3ALTDIV8SF);
 
-  def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altsiv4di ",
+  def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altsiv4di",
   V4DI_FTYPE_V4DI_PCINT64_V8SI_QI_INT,
   IX86_BUILTIN_GATHER3ALTSIV4DI);
 
-  def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altdiv8si ",
+  def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altdiv8si",
   V8SI_FTYPE_V8SI_PCINT_V4DI_QI_INT,
   IX86_BUILTIN_GATHER3ALTDIV8SI);
 
@@ -31644,19 +31644,19 @@ ix86_init_mmx_sse_builtins (void)
   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv2di",
   VOID_FTYPE_PLONGLONG_QI_V2DI_V2DI_INT,
   IX86_BUILTIN_SCATTERDIV2DI);
-  def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scatteraltsiv8df ",
+  def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scatteraltsiv8df",
   

Re: [PATCH 6/17][ARM] Add data processing intrinsics for float16_t.

2016-09-25 Thread Christophe Lyon
Hi Matthew,


On 27 July 2016 at 15:59, Ramana Radhakrishnan
 wrote:
> On Tue, May 17, 2016 at 3:31 PM, Matthew Wahab
>  wrote:
>> The ACLE specifies a number of intrinsics for manipulating vectors
>> holding values in most of the integer and floating point type. These
>> include 16-bit integer types but not 16-bit floating point even though
>> the same instruction is used for both.
>>
>> A future version of the ACLE extends the data processing intrinscs to
>> the 16-bit floating point types, making the intrinsics available
>> under the same conditions as the ARM __fp16 type.
>>
>> This patch adds the new intrinsics:
>>  vbsl_f16, vbslq_f16, vdup_n_f16, vdupq_n_f16, vdup_lane_f16,
>>  vdupq_lane_f16, vext_f16, vextq_f16, vmov_n_f16, vmovq_n_f16,
>>  vrev64_f16, vrev64q_f16, vtrn_f16, vtrnq_f16, vuzp_f16, vuzpq_f16,
>>  vzip_f16, vzipq_f16.
>>
>> This patch also updates the advsimd-intrinsics testsuite to test the f16
>> variants for ARM targets. These intrinsics are only implemented in the
>> ARM target so the tests are disabled for AArch64 using an extra
>> condition on a new convenience macro FP16_SUPPORTED. This patch also
>> disables, for the ARM target, the testsuite defined macro vdup_n_f16 as
>> it is no longer needed.
>>
>> Tested the series for arm-none-linux-gnueabihf with native bootstrap and
>> make check and for arm-none-eabi and armeb-none-eabi with make check on
>> an ARMv8.2-A emulator. Also tested for aarch64-none-elf with the
>> advsimd-intrinsics testsuite using an ARMv8.2-A emulator.
>>
>> Ok for trunk?
>> Matthew
>>
>> 2016-05-17  Matthew Wahab  
>>
>> * config/arm/arm.c (arm_evpc_neon_vuzp): Add support for V8HF and
>> V4HF modes.
>> (arm_evpc_neon_vzip): Likewise.
>> (arm_evpc_neon_vrev): Likewise.
>> (arm_evpc_neon_vtrn): Likewise.
>> (arm_evpc_neon_vext): Likewise.
>> * config/arm/arm_neon.h (vbsl_f16): New.
>> (vbslq_f16): New.
>> (vdup_n_f16): New.
>> (vdupq_n_f16): New.
>> (vdup_lane_f16): New.
>> (vdupq_lane_f16): New.
>> (vext_f16): New.
>> (vextq_f16): New.
>> (vmov_n_f16): New.
>> (vmovq_n_f16): New.
>> (vrev64_f16): New.
>> (vrev64q_f16): New.
>> (vtrn_f16): New.
>> (vtrnq_f16): New.
>> (vuzp_f16): New.
>> (vuzpq_f16): New.
>> (vzip_f16): New.
>> (vzipq_f16): New.
>> * config/arm/arm_neon_buillins.def (vdup_n): New (v8hf, v4hf
>> variants).
>> (vdup_lane): New (v8hf, v4hf variants).
>> (vext): New (v8hf, v4hf variants).
>> (vbsl): New (v8hf, v4hf variants).
>> * config/arm/iterators.md (VDQWH): New.
>> (VH): New.
>> (V_double_vector_mode): Add V8HF and V4HF.  Fix white-space.
>> (Scalar_mul_8_16): Fix white-space.
>> (Is_d_reg): Add V4HF and V8HF.
>> * config/arm/neon.md (neon_vdup_lane_internal): New.
>> (neon_vdup_lane): New.
>> (neon_vtrn_internal): Replace VDQW with VDQWH.
>> (*neon_vtrn_insn): Likewise.
>> (neon_vzip_internal): Likewise. Also fix white-space.
>> (*neon_vzip_insn): Likewise
>> (neon_vuzp_internal): Likewise.
>> (*neon_vuzp_insn): Likewise
>> * config/arm/vec-common.md (vec_perm_const): New.
>>
>> testsuite/
>> 2016-05-17  Matthew Wahab  
>>
>> * gcc.target/aarch64/advsimd-intrinsics/arm-neon-ref.h
>> (FP16_SUPPORTED): New
>> (vdup_n_f16): Disable for non-AArch64 targets.
>> * gcc.target/aarch64/advsimd-intrinsics/vbsl.c: Add __fp16 tests,
>> conditional on FP16_SUPPORTED.
>> * gcc.target/aarch64/advsimd-intrinsics/vdup-vmov.c: Likewise.
>> * gcc.target/aarch64/advsimd-intrinsics/vdup_lane.c: Likewise.
>> * gcc.target/aarch64/advsimd-intrinsics/vext.c: Likewise.
>> * gcc.target/aarch64/advsimd-intrinsics/vrev.c: Likewise.
>> * gcc.target/aarch64/advsimd-intrinsics/vshuffle.inc: Add support
>> for testing __fp16.
>> * gcc.target/aarch64/advsimd-intrinsics/vtrn.c: Add __fp16 tests,
>> conditional on FP16_SUPPORTED.
>> * gcc.target/aarch64/advsimd-intrinsics/vuzp.c: Likewise.
>> * gcc.target/aarch64/advsimd-intrinsics/vzip.c: Likewise.
>>
>
> OK.
>
>
> Ramana

Since you committed this patch, I've noticed that libgcc fails to build
when GCC is configured:
--target arm-none-eabi and default cpu
/tmp/9649048_29.tmpdir/ccuBwQJJ.s: Assembler messages:
/tmp/9649048_29.tmpdir/ccuBwQJJ.s:64: Error: selected processor does
not support ARM mode `movwlt r0,32768'
/tmp/9649048_29.tmpdir/ccuBwQJJ.s:65: Error: selected processor does
not support ARM mode `movwge r0,32767'
make[4]: *** [_ssaddHQ.o] Error 1
make[4]: Leaving directory

[PATCH] Make CHECKING_P a boolean flag again

2016-09-25 Thread Bernd Edlinger
Hi!


Currently CHECKING_P is not a boolean flag but a ternary option.
However the _P in the name implies it is a boolean.

That should be cleaned up again IMHO.


So this patch splits CHECKING_P into CHECKING_P and a new flag
ENABLE_EXTRA_CHECKING.  All uses of CHECKING_P are actually of
the form "if (CHECKING_P)" so there is no problem there, only the
flag_checking is tested at one place for > 1,  thus we have to
make sure that the default initial value of flag_checking is
0, 1 or 2, dependent on CHECKING_P and ENABLE_EXTRA_CHECKING.


Bootstrapped and reg-tested on x86_64-pc-linux-gnu.
Is it OK for trunk?


Thanks
Bernd.
2016-09-25  Bernd Edlinger  

* configure.ac: Split CHECKING_P into CHECKING_P and
ENABLE_EXTRA_CHECKING.
* configure: Regenerated.
* config.in: Adjust commment of CHECKING_P.  Add ENABLE_EXTRA_CHECKING.
* common.opt (flag_checking): Use CHECKING_P and ENABLE_EXTRA_CHECKING.
Index: gcc/common.opt
===
--- gcc/common.opt	(revision 240437)
+++ gcc/common.opt	(working copy)
@@ -1034,7 +1034,7 @@ Common Var(flag_check_new)
 Check the return value of new in C++.
 
 fchecking
-Common Var(flag_checking) Init(CHECKING_P)
+Common Var(flag_checking) Init(CHECKING_P ? ENABLE_EXTRA_CHECKING ? 2 : 1 : 0)
 Perform internal consistency checkings.
 
 fchecking=
Index: gcc/config.in
===
--- gcc/config.in	(revision 240437)
+++ gcc/config.in	(working copy)
@@ -30,14 +30,20 @@
 #endif
 
 
-/* Define to 1 if you want more run-time sanity checks. This one gets a grab
-   bag of miscellaneous but relatively cheap checks. Define to 2 if you want
-   also extra run-time checking that might affect code generation. */
+/* Define to 0/1 if you want more run-time sanity checks. This one gets a grab
+   bag of miscellaneous but relatively cheap checks. */
 #ifndef USED_FOR_TARGET
 #undef CHECKING_P
 #endif
 
 
+/* Define to 0/1 if you want also extra run-time checking that might affect
+   code generation. */
+#ifndef USED_FOR_TARGET
+#undef ENABLE_EXTRA_CHECKING
+#endif
+
+
 /* Define 0/1 to force the choice for exception handling model. */
 #ifndef USED_FOR_TARGET
 #undef CONFIG_SJLJ_EXCEPTIONS
Index: gcc/configure
===
--- gcc/configure	(revision 240437)
+++ gcc/configure	(working copy)
@@ -7135,13 +7135,8 @@ IFS="$ac_save_IFS"
 
 nocommon_flag=""
 if test x$ac_checking != x ; then
-  if test x$ac_extra_checking != x ; then
-ac_checking=2
-  fi
 
-cat >>confdefs.h <<_ACEOF
-#define CHECKING_P $ac_checking
-_ACEOF
+$as_echo "#define CHECKING_P 1" >>confdefs.h
 
   nocommon_flag=-fno-common
 else
@@ -7149,6 +7144,14 @@ else
 
 fi
 
+if test x$ac_extra_checking != x ; then
+
+$as_echo "#define ENABLE_EXTRA_CHECKING 1" >>confdefs.h
+
+else
+  $as_echo "#define ENABLE_EXTRA_CHECKING 0" >>confdefs.h
+
+fi
 if test x$ac_df_checking != x ; then
 
 $as_echo "#define ENABLE_DF_CHECKING 1" >>confdefs.h
@@ -18476,7 +18479,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18479 "configure"
+#line 18482 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -18582,7 +18585,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18585 "configure"
+#line 18588 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
Index: gcc/configure.ac
===
--- gcc/configure.ac	(revision 240437)
+++ gcc/configure.ac	(working copy)
@@ -579,18 +579,21 @@ IFS="$ac_save_IFS"
 
 nocommon_flag=""
 if test x$ac_checking != x ; then
-  if test x$ac_extra_checking != x ; then
-ac_checking=2
-  fi
-  AC_DEFINE_UNQUOTED(CHECKING_P, $ac_checking,
-[Define to 1 if you want more run-time sanity checks.  This one gets a grab
-   bag of miscellaneous but relatively cheap checks.  Define to 2 if you want
-   also extra run-time checking that might affect code generation.])
+  AC_DEFINE(CHECKING_P, 1,
+[Define to 0/1 if you want more run-time sanity checks.  This one gets a grab
+bag of miscellaneous but relatively cheap checks.])
   nocommon_flag=-fno-common
 else
   AC_DEFINE(CHECKING_P, 0)
 fi
 AC_SUBST(nocommon_flag)
+if test x$ac_extra_checking != x ; then
+  AC_DEFINE(ENABLE_EXTRA_CHECKING, 1,
+[Define to 0/1 if you want extra run-time checking that might affect code
+generation.])
+else
+  AC_DEFINE(ENABLE_EXTRA_CHECKING, 0)
+fi
 if test x$ac_df_checking != x ; then
   AC_DEFINE(ENABLE_DF_CHECKING, 1,
 [Define if you want more run-time sanity checks for dataflow.])


[PATCH, PR77558] Remove RECORD_TYPE special-casing in std_canonical_va_list_type

2016-09-25 Thread Tom de Vries

Hi,

this patch fixes PR77558, an ice-on-invalid-code 6/7 regression.

The fix for PR71602 introduced the invalid-code test-case 
c-c++-common/va-arg-va-list-type.c:

...
__builtin_va_list *pap;

void
fn1 (void)
{
  __builtin_va_arg (pap, double); /* { dg-error "first argument to 
'va_arg' not of type 'va_list'" } */

}
...

The test-case passes for x86_64, but fails for aarch64 and ICEs for arm.

The ICE happens because the patch for PR71602 is incomplete. The patch 
tries to be more strict about returning a canonical va_list only for 
actual va_lists, but doesn't implement this for structure va_list types, 
such as we have for arm, aarch64 and alpha.


This patch adds the missing part, and fixes the ICE.

OK for trunk, 6-branch?

Thanks,
- Tom
Remove RECORD_TYPE special-casing in std_canonical_va_list_type

2016-09-25  Tom de Vries  

	PR middle-end/77558
	* builtins.c (std_canonical_va_list_type): Remove RECORD_TYPE
	special-casing.

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

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 9a19a75..f91e6d3 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -4089,10 +4089,8 @@ std_canonical_va_list_type (tree type)
 
   wtype = va_list_type_node;
   htype = type;
-  /* Treat structure va_list types.  */
-  if (TREE_CODE (wtype) == RECORD_TYPE && POINTER_TYPE_P (htype))
-htype = TREE_TYPE (htype);
-  else if (TREE_CODE (wtype) == ARRAY_TYPE)
+
+  if (TREE_CODE (wtype) == ARRAY_TYPE)
 {
   /* If va_list is an array type, the argument may have decayed
 	 to a pointer type, e.g. by being passed to another function.


[PATCH] Make -Wint-in-bool-context warn on suspicious shift ops

2016-09-25 Thread Bernd Edlinger
Hi!

This patch makes -Wint-in-bool-context warn on suspicious integer left
shifts, when the integer is signed, which is most likely some kind of 
programming error, for instance using "<<" instead of "<".

The warning is motivated by the fact, that an overflow on integer shift
left is undefined behavior, even if gcc won't optimize the shift based
on the undefined behavior.

So in absence of undefined behavior the boolean result does not depend
on the shift value, thus the whole shifting is pointless.


Of course the warning happened to find one bug already.  That is in
cp/parser.c at cp_parser_condition, where we have this:


bool flags = LOOKUP_ONLYCONVERTING;

BUT (cp-tree.h):

#define LOOKUP_ONLYCONVERTING (1 << 2)


So "flags" is actually set to true, which is LOOKUP_PROTECT instead.

Although I tried hard to find a test case where this changes something,
I was not able to construct one.


Bootstrapped and reg-tested on x86_64-pc-linux-gnu.
Is it OK for trunk?


Thanks
Bernd.
gcc:
2016-09-25  Bernd Edlinger  

* doc/invoke.texi: Update -Wint-in-bool-context.

c-family:
2016-09-25  Bernd Edlinger  

* c-common.c (c_common_truthvalue_conversion): Warn for suspicious
signed integer left shift in boolean context.

cp:
2016-09-25  Bernd Edlinger  

* parser.c (cp_parser_condition): Fix a warning.

testsuite:
2016-09-25  Bernd Edlinger  

* c-c++-common/Wint-in-bool-context.c: Update test.
Index: gcc/c-family/c-common.c
===
--- gcc/c-family/c-common.c	(revision 240437)
+++ gcc/c-family/c-common.c	(working copy)
@@ -4651,6 +4651,19 @@ c_common_truthvalue_conversion (location_t locatio
 	return c_common_truthvalue_conversion (location,
 	   TREE_OPERAND (expr, 0));
 
+case LSHIFT_EXPR:
+  /* Warn on signed integer left shift, except 0 << 0, 1 << 0.  */
+  if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
+	  && !TYPE_UNSIGNED (TREE_TYPE (expr))
+	  && !(TREE_CODE (TREE_OPERAND (expr, 0)) == INTEGER_CST
+	   && TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST
+	   && (integer_zerop (TREE_OPERAND (expr, 0))
+		   || integer_onep (TREE_OPERAND (expr, 0)))
+	   && integer_zerop (TREE_OPERAND (expr, 1
+	warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
+		"<< on signed integer in boolean context");
+  break;
+
 case COND_EXPR:
   if (warn_int_in_bool_context
 	  && !from_macro_definition_at (EXPR_LOCATION (expr)))
Index: gcc/cp/parser.c
===
--- gcc/cp/parser.c	(revision 240437)
+++ gcc/cp/parser.c	(working copy)
@@ -11172,7 +11172,7 @@ cp_parser_condition (cp_parser* parser)
 	{
 	  tree pushed_scope;
 	  bool non_constant_p;
-	  bool flags = LOOKUP_ONLYCONVERTING;
+	  int flags = LOOKUP_ONLYCONVERTING;
 
 	  /* Create the declaration.  */
 	  decl = start_decl (declarator, _specifiers,
Index: gcc/doc/invoke.texi
===
--- gcc/doc/invoke.texi	(revision 240437)
+++ gcc/doc/invoke.texi	(working copy)
@@ -5927,7 +5927,8 @@ of the C++ standard.
 @opindex Wno-int-in-bool-context
 Warn for suspicious use of integer values where boolean values are expected,
 such as conditional expressions (?:) using non-boolean integer constants in
-boolean context, like @code{if (a <= b ? 2 : 3)}.
+boolean context, like @code{if (a <= b ? 2 : 3)}.  Or left shifting of a
+signed integer in boolean context, like @code{for (a = 0; 1 << a; a++);}.
 This warning is enabled by @option{-Wall}.
 
 @item -Wno-int-to-pointer-cast
Index: gcc/testsuite/c-c++-common/Wint-in-bool-context.c
===
--- gcc/testsuite/c-c++-common/Wint-in-bool-context.c	(revision 240437)
+++ gcc/testsuite/c-c++-common/Wint-in-bool-context.c	(working copy)
@@ -25,5 +25,7 @@ int foo (int a, int b)
   if (b ? 1+1 : 1) /* { dg-warning "boolean context" } */
 return 7;
 
+  for (a = 0; 1 << a; a++); /* { dg-warning "boolean context" } */
+
   return 0;
 }


[SH][committed] Fix cset_zero pattern regressions

2016-09-25 Thread Oleg Endo
Hi,

This fixes a fallout that actually goes back to 5.0 but went unnoticed.
The costs for movt and movrt type of insns were not correctly reported
and ifcvt thus made some bad choices for SH.  A new cset_zero pattern
variant is also required to fix the matching for some recent changes
in the middle end.

Tested on sh-elf with
make -k check RUNTESTFLAGS="--target_board=sh-sim\{-m2/-ml,-m2/-mb,-
m2a/-mb,-m4/-ml,-m4/-mb,-m4a/-ml,-m4a/-mb}"

Committed as r240471.
Backports to GCC 6 and GCC 5 will follow.

Cheers,
Oleg


gcc/ChangeLog
PR target/51244
* config/sh/sh.c (sh_movt_set_dest, sh_movrt_set_dest): Add overloads.
(sh_rtx_costs): Handle SET of movt and movrt patterns.
* cnofig/sh/sh-protos.h (sh_movt_set_dest, sh_movrt_set_dest): Forward
declare new overloads.
* config/sh/sh.md (*cset_zero): Add variant that takes a treg_set_expr
operand.

gcc/testsuite/ChangeLog
PR target/51244
* gcc.target/sh/pr51244-11.c: Add more detailed expected insn matching.
Index: gcc/config/sh/sh-protos.h
===
--- gcc/config/sh/sh-protos.h	(revision 240470)
+++ gcc/config/sh/sh-protos.h	(working copy)
@@ -235,7 +235,9 @@
 
 extern bool sh_is_nott_insn (const rtx_insn* i);
 extern rtx sh_movt_set_dest (const rtx_insn* i);
+extern rtx sh_movt_set_dest (const_rtx i);
 extern rtx sh_movrt_set_dest (const rtx_insn* i);
+extern rtx sh_movrt_set_dest (const_rtx i);
 
 inline bool sh_is_movt_insn (const rtx_insn* i)
 {
Index: gcc/config/sh/sh.c
===
--- gcc/config/sh/sh.c	(revision 240470)
+++ gcc/config/sh/sh.c	(working copy)
@@ -3208,6 +3208,10 @@
   / mov_insn_size (mode, TARGET_SH2A));
 	  return true;
 }
+
+  if (sh_movt_set_dest (x) != NULL || sh_movrt_set_dest (x) != NULL)
+	return COSTS_N_INSNS (1);
+
   return false;
 
 /* The cost of a mem access is mainly the cost of the address mode.  */
@@ -11703,13 +11707,15 @@
 rtx
 sh_movt_set_dest (const rtx_insn* i)
 {
-  if (i == NULL)
-return NULL;
+  return i == NULL ? NULL : sh_movt_set_dest (PATTERN (i));
+}
 
-  const_rtx p = PATTERN (i);
-  return GET_CODE (p) == SET
-	 && arith_reg_dest (XEXP (p, 0), SImode)
-	 && t_reg_operand (XEXP (p, 1), VOIDmode) ? XEXP (p, 0) : NULL;
+rtx
+sh_movt_set_dest (const_rtx pat)
+{
+  return GET_CODE (pat) == SET
+	 && arith_reg_dest (XEXP (pat, 0), SImode)
+	 && t_reg_operand (XEXP (pat, 1), VOIDmode) ? XEXP (pat, 0) : NULL;
 }
 
 /* Given an insn, check whether it's a 'movrt' kind of insn, i.e. an insn
@@ -11718,18 +11724,20 @@
 rtx
 sh_movrt_set_dest (const rtx_insn* i)
 {
-  if (i == NULL)
-return NULL;
+  return i == NULL ? NULL : sh_movrt_set_dest (PATTERN (i));
+}
 
-  const_rtx p = PATTERN (i);
-
+rtx
+sh_movrt_set_dest (const_rtx pat)
+{
   /* The negc movrt replacement is inside a parallel.  */
-  if (GET_CODE (p) == PARALLEL)
-p = XVECEXP (p, 0, 0);
+  if (GET_CODE (pat) == PARALLEL)
+pat = XVECEXP (pat, 0, 0);
 
-  return GET_CODE (p) == SET
-	 && arith_reg_dest (XEXP (p, 0), SImode)
-	 && negt_reg_operand (XEXP (p, 1), VOIDmode) ? XEXP (p, 0) : NULL;
+  return GET_CODE (pat) == SET
+	 && arith_reg_dest (XEXP (pat, 0), SImode)
+	 && negt_reg_operand (XEXP (pat, 1), VOIDmode) ? XEXP (pat, 0) : NULL;
+
 }
 
 /* Given an insn and a reg number, tell whether the reg dies or is unused
Index: gcc/config/sh/sh.md
===
--- gcc/config/sh/sh.md	(revision 240470)
+++ gcc/config/sh/sh.md	(working copy)
@@ -8524,6 +8524,24 @@
   [(set_attr "type" "arith") ;; poor approximation
(set_attr "length" "4")])
 
+(define_insn_and_split "*cset_zero"
+  [(set (match_operand:SI 0 "arith_reg_dest")
+	(if_then_else:SI (match_operand 1 "treg_set_expr_not_const01")
+			 (match_dup 0) (const_int 0)))
+   (clobber (reg:SI T_REG))]
+  "TARGET_SH1 && TARGET_ZDCBRANCH && can_create_pseudo_p ()"
+  "#"
+  "&& 1"
+  [(set (match_dup 0)
+	(if_then_else:SI (match_dup 1) (match_dup 0) (const_int 0)))]
+{
+  sh_treg_insns ti = sh_split_treg_set_expr (operands[1], curr_insn);
+  if (ti.remove_trailing_nott ())
+operands[1] = gen_rtx_EQ (SImode, get_t_reg_rtx (), const0_rtx);
+  else
+operands[1] = gen_rtx_EQ (SImode, get_t_reg_rtx (), const1_rtx);
+})
+
 (define_expand "cstoresf4"
   [(set (match_operand:SI 0 "register_operand")
 	(match_operator:SI 1 "ordered_comparison_operator"
Index: gcc/testsuite/gcc.target/sh/pr51244-11.c
===
--- gcc/testsuite/gcc.target/sh/pr51244-11.c	(revision 240470)
+++ gcc/testsuite/gcc.target/sh/pr51244-11.c	(working copy)
@@ -1,8 +1,11 @@
 /* Check that zero-displacement branches are used instead of branch-free
-   execution patterns.  */
+   execution patterns.
+   This is usually handled by the *cset_zero patterns.  */
 /* { dg-do compile }  */
-/* { dg-options "-O1