Re: [PATCH] Fix PR55152

2016-10-05 Thread Richard Biener
On Tue, 4 Oct 2016, Joseph Myers wrote:

> On Tue, 4 Oct 2016, Richard Biener wrote:
> 
> > On Tue, 4 Oct 2016, Joseph Myers wrote:
> > 
> > > On Tue, 4 Oct 2016, Richard Biener wrote:
> > > 
> > > > Possibly.  Though then for FP we also want - abs (a) -> copysign (a, 
> > > > -1).
> > > 
> > > For architectures such as powerpc that have a negated-abs instruction, 
> > > does it get properly generated from the copysign code?  (The relevant 
> > > pattern in rs6000.md uses (neg (abs)) - is that the correct canonical RTL 
> > > for this?)
> > 
> > I have no idea - given that there is no copysign RTL code I suppose
> > it is the only machine independent RTL that can do this?
> > 
> > The question would be whether the copysign optab of said targets would
> > special-case the -1 case appropriately.
> 
> Why -1?  Any constant in copysign should be handled appropriately.  I'd 
> say that (neg (abs)) is probably better as a canonical representation, so 
> map copysign from a constant to either (abs) or (neg (abs)) appropriately.
> 
> Then in the case where abs is expanded with bit manipulation, (neg (abs)) 
> should be expanded to a single OR.  I don't know whether the RTL 
> optimizers will map the AND / OR combination to a single OR, but if they 
> do then there should be no need to special-case (neg (abs)) in expansion, 
> and when (abs) RTL is generated a machine description's (neg (abs)) 
> pattern should match automatically.

Ok, that's a good point -- I'll do copysign (X, const) canonicalization
to [-]abs() then.  Hopefully that's a valid transform even if NaNs and
signed zeros are involved.

For now I've installed the requested min(a,-a)->-abs(a) pattern.

Bootstrapped / tested on x86_64-unknown-linux-gnu.

Richard.

2016-10-05  Richard Biener  

PR middle-end/55152
* match.pd (min(a,-a) -> -abs(a)): New pattern.

* gcc.dg/pr55152-2.c: New testcase.

Index: gcc/match.pd
===
--- gcc/match.pd(revision 240738)
+++ gcc/match.pd(working copy)
@@ -1291,6 +1302,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   && (! ANY_INTEGRAL_TYPE_P (type)
  || TYPE_OVERFLOW_UNDEFINED (type)))
   (abs @0)))
+/* min(a,-a) -> -abs(a).  */
+(simplify
+ (min:c @0 (negate @0))
+ (if (TREE_CODE (type) != COMPLEX_TYPE
+  && (! ANY_INTEGRAL_TYPE_P (type)
+ || TYPE_OVERFLOW_UNDEFINED (type)))
+  (negate (abs @0
 (simplify
  (min @0 @1)
  (switch
Index: gcc/testsuite/gcc.dg/pr55152-2.c
===
--- gcc/testsuite/gcc.dg/pr55152-2.c(revision 0)
+++ gcc/testsuite/gcc.dg/pr55152-2.c(working copy)
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O -ffinite-math-only -fno-signed-zeros -fstrict-overflow 
-fdump-tree-optimized" } */
+
+double g (double a)
+{
+  return (a<-a)?a:-a;
+}
+int f(int a)
+{
+  return (a<-a)?a:-a;
+}
+
+/* { dg-final { scan-tree-dump-times "ABS_EXPR" 2 "optimized" } } */


Re: [PATCH] Remove .jcr registry from the crtfiles

2016-10-05 Thread Andreas Schwab
* config/ia64/crtbegin.S (__do_jv_register_classes): Remove.
(.section .init_array): Don't call __do_jv_register_classes.
(.section .init): Likewise.

diff --git a/libgcc/config/ia64/crtbegin.S b/libgcc/config/ia64/crtbegin.S
index 3bf0e71a3a..cee0cf567d 100644
--- a/libgcc/config/ia64/crtbegin.S
+++ b/libgcc/config/ia64/crtbegin.S
@@ -63,7 +63,6 @@ __dso_handle:
data8 @fptr(__do_global_dtors_aux)
 
 .section .init_array, "a"
-   data8 @fptr(__do_jv_register_classes)
data8 @fptr(__do_global_ctors_aux)
 
 #else /* !HAVE_INITFINI_ARRAY_SUPPORT */
@@ -95,24 +94,6 @@ __dso_handle:
  mov b6 = r2
  br.call.sptk.many b0 = b6
}
-
-/* Likewise for _init.  */
-
-.section .init,"ax","progbits"
-   { .mlx
- movl r2 = @pcrel(__do_jv_register_classes - 16)
-   }
-   { .mii
- mov r3 = ip
- ;;
- add r2 = r2, r3
- ;;
-   }
-   { .mib
- nop 0
- mov b6 = r2
- br.call.sptk.many b0 = b6
-   }
 #endif /* !HAVE_INITFINI_ARRAY_SUPPORT */
 
 .section .text
@@ -200,50 +181,6 @@ __do_global_dtors_aux:
br.ret.sptk.many rp
.endp __do_global_dtors_aux
 
-   .align  32
-   .proc   __do_jv_register_classes
-__do_jv_register_classes:
-   .prologue
-   .save ar.pfs, r33
-   alloc loc1 = ar.pfs, 0, 3, 1, 0
-   movl out0 = @gprel(__JCR_LIST__)
-   ;;
-
-   addl r14 = @ltoff(@fptr(_Jv_RegisterClasses)), gp
-   add out0 = out0, gp
-   .save rp, loc0
-   mov loc0 = rp
-   .body
-   ;;
-
-   ld8 r14 = [r14]
-   ld8 r15 = [out0]
-   cmp.ne p6, p0 = r0, r0
-   ;;
-
-   cmp.eq.or p6, p0 = r0, r14
-   cmp.eq.or p6, p0 = r0, r15
-(p6)   br.ret.sptk.many rp
-
-   ld8 r15 = [r14], 8
-   ;;
-   nop 0
-   mov b6 = r15
-
-   mov loc2 = gp
-   ld8 gp = [r14]
-   br.call.sptk.many rp = b6
-   ;;
-
-   mov gp = loc2
-   mov rp = loc0
-   mov ar.pfs = loc1
-
-   nop 0
-   nop 0
-   br.ret.sptk.many rp
-   .endp   __do_jv_register_classes
-
 #ifdef SHARED
 .weak __cxa_finalize
 #endif
-- 
2.10.1


Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


Re: [PATCH] DWARF: remove pessimistic DWARF version checks for imported entities

2016-10-05 Thread Pierre-Marie de Rodat

On 10/04/2016 09:50 PM, Jason Merrill wrote:

OK.


On 10/05/2016 06:53 AM, Dominique d'Humières wrote:

The new patch works on darwin without new regression.


Thank you both for your help! This is now comitted.

--
Pierre-Marie de Rodat


Re: [PATCH] Remove .jcr registry from the crtfiles

2016-10-05 Thread Jakub Jelinek
On Wed, Oct 05, 2016 at 09:52:31AM +0200, Andreas Schwab wrote:
>   * config/ia64/crtbegin.S (__do_jv_register_classes): Remove.
>   (.section .init_array): Don't call __do_jv_register_classes.
>   (.section .init): Likewise.

Oops, sorry for missing that.  The patch is ok.
> 
> diff --git a/libgcc/config/ia64/crtbegin.S b/libgcc/config/ia64/crtbegin.S
> index 3bf0e71a3a..cee0cf567d 100644
> --- a/libgcc/config/ia64/crtbegin.S
> +++ b/libgcc/config/ia64/crtbegin.S
> @@ -63,7 +63,6 @@ __dso_handle:
>   data8 @fptr(__do_global_dtors_aux)
>  
>  .section .init_array, "a"
> - data8 @fptr(__do_jv_register_classes)
>   data8 @fptr(__do_global_ctors_aux)
>  
>  #else /* !HAVE_INITFINI_ARRAY_SUPPORT */
> @@ -95,24 +94,6 @@ __dso_handle:
> mov b6 = r2
> br.call.sptk.many b0 = b6
>   }
> -
> -/* Likewise for _init.  */
> -
> -.section .init,"ax","progbits"
> - { .mlx
> -   movl r2 = @pcrel(__do_jv_register_classes - 16)
> - }
> - { .mii
> -   mov r3 = ip
> -   ;;
> -   add r2 = r2, r3
> -   ;;
> - }
> - { .mib
> -   nop 0
> -   mov b6 = r2
> -   br.call.sptk.many b0 = b6
> - }
>  #endif /* !HAVE_INITFINI_ARRAY_SUPPORT */
>  
>  .section .text
> @@ -200,50 +181,6 @@ __do_global_dtors_aux:
>   br.ret.sptk.many rp
>   .endp __do_global_dtors_aux
>  
> - .align  32
> - .proc   __do_jv_register_classes
> -__do_jv_register_classes:
> - .prologue
> - .save ar.pfs, r33
> - alloc loc1 = ar.pfs, 0, 3, 1, 0
> - movl out0 = @gprel(__JCR_LIST__)
> - ;;
> -
> - addl r14 = @ltoff(@fptr(_Jv_RegisterClasses)), gp
> - add out0 = out0, gp
> - .save rp, loc0
> - mov loc0 = rp
> - .body
> - ;;
> -
> - ld8 r14 = [r14]
> - ld8 r15 = [out0]
> - cmp.ne p6, p0 = r0, r0
> - ;;
> -
> - cmp.eq.or p6, p0 = r0, r14
> - cmp.eq.or p6, p0 = r0, r15
> -(p6) br.ret.sptk.many rp
> -
> - ld8 r15 = [r14], 8
> - ;;
> - nop 0
> - mov b6 = r15
> -
> - mov loc2 = gp
> - ld8 gp = [r14]
> - br.call.sptk.many rp = b6
> - ;;
> -
> - mov gp = loc2
> - mov rp = loc0
> - mov ar.pfs = loc1
> -
> - nop 0
> - nop 0
> - br.ret.sptk.many rp
> - .endp   __do_jv_register_classes
> -
>  #ifdef SHARED
>  .weak __cxa_finalize
>  #endif
> -- 
> 2.10.1
> 
> 
> Andreas.
> 
> -- 
> Andreas Schwab, SUSE Labs, sch...@suse.de
> GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
> "And now for something completely different."

Jakub


Re: [RFC][PATCH] Canonicalize address multiplies

2016-10-05 Thread Richard Biener
On Tue, Oct 4, 2016 at 2:53 PM, Wilco Dijkstra  wrote:
> GCC currently doesn't canonicalize address expressions. As a result
> inefficient code is generated even for trivial index address expressions,
> blocking CSE and other optimizations:
>
> int f(int *p, int i) { return p[i+2] + p[i+1]; }
>
> sxtwx1, w1
> add x1, x1, 2
> add x2, x0, x1, lsl 2
> ldr w0, [x0, x1, lsl 2]
> ldr w1, [x2, -4]
> add w0, w1, w0
> ret
>
> After this patch:
>
> add x1, x0, x1, sxtw 2
> ldp w0, w2, [x1, 4]
> add w0, w2, w0
> ret
>
> The reason for this is that array index expressions are preferably kept in
> the *(p + (i + C0) * C1) form eventhough it is best on most targets to make
> use of an offset in memory accesses - ie. *(p + i * C1 + (C0*C1)).
>
> This patch disables the folding in fold_plusminus_mult_expr that changes
> the latter form into the former.  Unfortunately it isn't possible to know
> it is an address expression, and neither is there a way to decide when
> C0*C1 is too complex.
>
> So is there a better way/place to do this, or do we need an address
> canonicalization phase in the tree that ensures we expand addresses in an
> efficient manner, taking into account target offsets?

Note there is also the case where the address expression is not exposed in
GIMPLE until after RTL expansion which is if the array reference is not
based on a pointer but on an actual array.  Then we keep the ARRAY_REF
form in GIMPLE.

The more general issue that want's to be addressed here is expression
re-association to maximize CSE opportunities (or minimize addressing
cost) across all expressions that are "close enough".

We have the re-association pass which does decisions based on
a single expression only (not considering CSE opportunities with others).

Then we have the IVOPTs pass which should do what you want but it
only runs on memory references in loops.  Then we have the SLSR
pass which was supposed to cover the IVOPTs in scalar code case
but it doesn't consider addressing mode costs.

The folding patch disables a (maybe premature) canonicalization
(it's really supposed to be a canonicalization, not an optimization)
which will end up helping a testcase like yours but regress another
case where the CSE opportunity arises with the other canonicalization.

If you disable this canonicalization, saying A * C0 +- C1 is better than
(A +- (C1/C0)) * C0 then you should at least implement the reverse
canonicalization.  These days the appropriate place to do that is
match.pd (ISTR having a patch moving fold_plusminus_mult_expr to
match.pd, I don't remember what happened to it).

Richard.

>
> ChangeLog:
> 2016-10-04  Wilco Dijkstra  
>
> gcc/
> * fold-const.c (fold_plusminus_mult_expr): Block folding of immediates
> into multiply.
> --
>
> diff --git a/gcc/fold-const.c b/gcc/fold-const.c
> index 
> e71ce5e0f23adbb1d4a73506769f7243900cfd2d..bc9fb1e8ff3e33c94e66a2d1282235b71fac2730
>  100644
> --- a/gcc/fold-const.c
> +++ b/gcc/fold-const.c
> @@ -6912,7 +6912,9 @@ fold_plusminus_mult_expr (location_t loc, enum 
> tree_code code, tree type,
>   (A * C) +- A -> A * (C+-1).
>   We are most concerned about the case where C is a constant,
>   but other combinations show up during loop reduction.  Since
> - it is not difficult, try all four possibilities.  */
> + it is not difficult, try all four possibilities.
> + However avoid moving integer constants into the multiply:
> + (A * C0) +- C1 is better than (A +- (C1/C0)) * C0.  */
>
>if (TREE_CODE (arg0) == MULT_EXPR)
>  {
> @@ -6920,10 +6922,7 @@ fold_plusminus_mult_expr (location_t loc, enum 
> tree_code code, tree type,
>arg01 = TREE_OPERAND (arg0, 1);
>  }
>else if (TREE_CODE (arg0) == INTEGER_CST)
> -{
> -  arg00 = build_one_cst (type);
> -  arg01 = arg0;
> -}
> +return NULL_TREE;
>else
>  {
>/* We cannot generate constant 1 for fract.  */
> @@ -6938,20 +6937,7 @@ fold_plusminus_mult_expr (location_t loc, enum 
> tree_code code, tree type,
>arg11 = TREE_OPERAND (arg1, 1);
>  }
>else if (TREE_CODE (arg1) == INTEGER_CST)
> -{
> -  arg10 = build_one_cst (type);
> -  /* As we canonicalize A - 2 to A + -2 get rid of that sign for
> -the purpose of this canonicalization.  */
> -  if (wi::neg_p (arg1, TYPE_SIGN (TREE_TYPE (arg1)))
> - && negate_expr_p (arg1)
> - && code == PLUS_EXPR)
> -   {
> - arg11 = negate_expr (arg1);
> - code = MINUS_EXPR;
> -   }
> -  else
> -   arg11 = arg1;
> -}
> +return NULL_TREE;
>else
>  {
>/* We cannot generate constant 1 for fract.  */
>


Re: [PATCH] Move strchr folding to gimple-fold

2016-10-05 Thread Richard Biener
On Tue, Oct 4, 2016 at 7:20 PM, Wilco Dijkstra  wrote:
> As suggested in https://gcc.gnu.org/ml/gcc-patches/2016-09/msg02216.html,
> move all existing strchr and strrchr folding from builtins.c to gimple-fold.c.
>
> Passes C/C++ regression & bootstrap.

Ok.

Thanks,
Richard.

> 2016-10-04  Wilco Dijkstra  
>
> * builtins.c (fold_builtin_strchr): Remove function.
> (fold_builtin_strrchr): Likewise.
> (fold_builtin2): Remove strchr, index, strrchr, rindex cases.
> * gimple-fold.c (target_char_cst_p): New function.
> (gimple_fold_builtin_strchr) Add more foldings.
> (gimple_fold_builtin): Add index, strrchr, rindex cases.
>
> --
>
> diff --git a/gcc/builtins.c b/gcc/builtins.c
> index 
> 04dcf95acd21bf092c730d5fdd08b58c497c1ab5..6f034ad78fa157bbce65e954fd754347032ab20e
>  100644
> --- a/gcc/builtins.c
> +++ b/gcc/builtins.c
> @@ -148,7 +148,6 @@ static tree rewrite_call_expr (location_t, tree, int, 
> tree, int, ...);
>  static bool validate_arg (const_tree, enum tree_code code);
>  static rtx expand_builtin_fabs (tree, rtx, rtx);
>  static rtx expand_builtin_signbit (tree, rtx);
> -static tree fold_builtin_strchr (location_t, tree, tree, tree);
>  static tree fold_builtin_memchr (location_t, tree, tree, tree, tree);
>  static tree fold_builtin_memcmp (location_t, tree, tree, tree);
>  static tree fold_builtin_strcmp (location_t, tree, tree);
> @@ -168,7 +167,6 @@ static tree fold_builtin_varargs (location_t, tree, 
> tree*, int);
>
>  static tree fold_builtin_strpbrk (location_t, tree, tree, tree);
>  static tree fold_builtin_strstr (location_t, tree, tree, tree);
> -static tree fold_builtin_strrchr (location_t, tree, tree, tree);
>  static tree fold_builtin_strspn (location_t, tree, tree);
>  static tree fold_builtin_strcspn (location_t, tree, tree);
>
> @@ -8393,14 +8391,6 @@ fold_builtin_2 (location_t loc, tree fndecl, tree 
> arg0, tree arg1)
>  case BUILT_IN_STRCSPN:
>return fold_builtin_strcspn (loc, arg0, arg1);
>
> -case BUILT_IN_STRCHR:
> -case BUILT_IN_INDEX:
> -  return fold_builtin_strchr (loc, arg0, arg1, type);
> -
> -case BUILT_IN_STRRCHR:
> -case BUILT_IN_RINDEX:
> -  return fold_builtin_strrchr (loc, arg0, arg1, type);
> -
>  case BUILT_IN_STRCMP:
>return fold_builtin_strcmp (loc, arg0, arg1);
>
> @@ -8893,124 +8883,6 @@ fold_builtin_strstr (location_t loc, tree s1, tree 
> s2, tree type)
>  }
>  }
>
> -/* Simplify a call to the strchr builtin.  S1 and S2 are the arguments to
> -   the call, and TYPE is its return type.
> -
> -   Return NULL_TREE if no simplification was possible, otherwise return the
> -   simplified form of the call as a tree.
> -
> -   The simplified form may be a constant or other expression which
> -   computes the same value, but in a more efficient manner (including
> -   calls to other builtin functions).
> -
> -   The call may contain arguments which need to be evaluated, but
> -   which are not useful to determine the result of the call.  In
> -   this case we return a chain of COMPOUND_EXPRs.  The LHS of each
> -   COMPOUND_EXPR will be an argument which must be evaluated.
> -   COMPOUND_EXPRs are chained through their RHS.  The RHS of the last
> -   COMPOUND_EXPR in the chain will contain the tree for the simplified
> -   form of the builtin function call.  */
> -
> -static tree
> -fold_builtin_strchr (location_t loc, tree s1, tree s2, tree type)
> -{
> -  if (!validate_arg (s1, POINTER_TYPE)
> -  || !validate_arg (s2, INTEGER_TYPE))
> -return NULL_TREE;
> -  else
> -{
> -  const char *p1;
> -
> -  if (TREE_CODE (s2) != INTEGER_CST)
> -   return NULL_TREE;
> -
> -  p1 = c_getstr (s1);
> -  if (p1 != NULL)
> -   {
> - char c;
> - const char *r;
> - tree tem;
> -
> - if (target_char_cast (s2, &c))
> -   return NULL_TREE;
> -
> - r = strchr (p1, c);
> -
> - if (r == NULL)
> -   return build_int_cst (TREE_TYPE (s1), 0);
> -
> - /* Return an offset into the constant string argument.  */
> - tem = fold_build_pointer_plus_hwi_loc (loc, s1, r - p1);
> - return fold_convert_loc (loc, type, tem);
> -   }
> -  return NULL_TREE;
> -}
> -}
> -
> -/* Simplify a call to the strrchr builtin.  S1 and S2 are the arguments to
> -   the call, and TYPE is its return type.
> -
> -   Return NULL_TREE if no simplification was possible, otherwise return the
> -   simplified form of the call as a tree.
> -
> -   The simplified form may be a constant or other expression which
> -   computes the same value, but in a more efficient manner (including
> -   calls to other builtin functions).
> -
> -   The call may contain arguments which need to be evaluated, but
> -   which are not useful to determine the result of the call.  In
> -   this case we return a chain of COMPOUND_EXPRs.  The LHS of each
> -   COMPOUND_EXPR will be an argument which must be evaluated.

Re: [EVRP] Fold stmts with vrp_fold_stmt

2016-10-05 Thread Richard Biener
On Wed, 5 Oct 2016, kugan wrote:

> Hi Richard,
> Thanks for the review.
> 
> On 04/10/16 19:56, Richard Biener wrote:
> > On Tue, 4 Oct 2016, kugan wrote:
> > 
> > > Hi,
> > > 
> > > This patch improves Early VRP by folding stmts using vrp_fold_stmt as it
> > > is
> > > done in ssa_propagate for VRP.
> > 
> > Why?
> 
> I thought it would be good for early vrp to simplify stmts using ranges. If we
> simplify obvious cases early, wouldn't it be better for IPA/LTO?
> 
>   I'd like us to move away from the fold_stmt callback of
> > substitute-and-fold (I have actually started some work towards that).
> 
> I must have missed it. But what is the general issue with 
> substitute-and-fold.

The pass specific stmt folding hook is a distraction and causes extra
work.  Most of the things the CCP variant does are no longer necessary
for example.  First and foremost I'm trying to enable "dce" in
substitute-and-fold for VRP and handle ASSERT_EXPR "removal" by
means of propagation -- this should fix quite a few missed pattern
matchings with fold_stmt which when running into ASSERT_EXPRs just
give up.

> > 
> > > I have also changed EVRP to handle POINTER_TYPE_P. I will send follow up
> > > patches to use this in IPA-VRP.
> > 
> > For pointers all VRP does is track non-NULLness.  Can you split out this
> > part?
> Attached patch does that.

That patch is ok.

> > I'm really worried about all the testsuite changes -- it means we are
> > losing test coverage for VRP :/
> 
> As you said earlier, unit testing with gimple FE should help. I am also
> wondering if we should organize these testcases such that it is run once
> without evrp and once with evrp to test both?

Yeah, that would be nice.  I always wondered about adding the ability
to add a "local torture" to individual testcases, say

{ dg-do compile }
{ dg-torture-options { "-O2 -fdisable-tree-evrp" "-O2" } }

(and make it be "additional" torture options when in dg-torture.exp)

Requires TCL hacking which isn't exactly my favourite...

Alternatively (seen elsewhere) put the testcase in a header and
have two testcases include it, with different dg-options ...

Richard.

> Thanks,
> Kugan
> 
> gcc/ChangeLog:
> 
> 2016-10-05  Kugan Vivekanandarajah  
> 
>   * tree-vrp.c (evrp_dom_walker::before_dom_children): Handle
> POINTER_TYPE_P.
> 
> 
> gcc/testsuite/ChangeLog:
> 
> 2016-10-05  Kugan Vivekanandarajah  
> 
>   * gcc.dg/tree-ssa/evrp4.c: New test.
> 
> > 
> > Richard.
> > 
> > > Bootstrapped and regression testd on x86_64-linux-gnu with no new
> > > regressions.
> > > Is this OK for trunk?
> > > 
> > > Thanks,
> > > Kugan
> > > 
> > > gcc/testsuite/ChangeLog:
> > > 
> > > 2016-10-03  Kugan Vivekanandarajah  
> > > 
> > >   * gcc.dg/pr68217.c: Adjust testcase as more cases are now handled in
> > > evrp.
> > >   * gcc.dg/predict-1.c: Likewise.
> > >   * gcc.dg/predict-9.c: Likewise.
> > >   * gcc.dg/tree-ssa/pr20318.c: Likewise.
> > >   * gcc.dg/tree-ssa/pr21001.c: Likewise.
> > >   * gcc.dg/tree-ssa/pr21090.c: Likewise.
> > >   * gcc.dg/tree-ssa/pr21294.c: Likewise.
> > >   * gcc.dg/tree-ssa/pr21559.c: Likewise.
> > >   * gcc.dg/tree-ssa/pr21563.c: Likewise.
> > >   * gcc.dg/tree-ssa/pr23744.c: Likewise.
> > >   * gcc.dg/tree-ssa/pr25382.c: Likewise.
> > >   * gcc.dg/tree-ssa/pr61839_1.c: Likewise.
> > >   * gcc.dg/tree-ssa/pr68431.c: Likewise.
> > >   * gcc.dg/tree-ssa/vrp03.c: Likewise.
> > >   * gcc.dg/tree-ssa/vrp07.c: Likewise.
> > >   * gcc.dg/tree-ssa/vrp09.c: Likewise.
> > >   * gcc.dg/tree-ssa/vrp17.c: Likewise.
> > >   * gcc.dg/tree-ssa/vrp18.c: Likewise.
> > >   * gcc.dg/tree-ssa/vrp19.c: Likewise.
> > >   * gcc.dg/tree-ssa/vrp20.c: Likewise.
> > >   * gcc.dg/tree-ssa/vrp23.c: Likewise.
> > >   * gcc.dg/tree-ssa/vrp24.c: Likewise.
> > >   * gcc.dg/tree-ssa/vrp58.c: Likewise.
> > >   * gcc.dg/tree-ssa/vrp92.c: Likewise.
> > >   * gcc.dg/tree-ssa/vrp98.c: Likewise.
> > >   * gcc.dg/vrp-min-max-1.c: Likewise.
> > > 
> > > gcc/ChangeLog:
> > > 
> > > 2016-10-03  Kugan Vivekanandarajah  
> > > 
> > >   * tree-vrp.c (evrp_dom_walker::before_dom_children): Handle
> > > POINTER_TYPE_P. Also fold stmts with vrp_fold_stmt.
> > > 
> > 
> 

-- 
Richard Biener 
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 
21284 (AG Nuernberg)


Re: [C++ PATCH] Delete GCJ - C++ part

2016-10-05 Thread Andreas Schwab
FAIL: g++.dg/pr49847-2.C  -std=gnu++11 (test for excess errors)
Excess errors:
/daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:5:13: error: 
'__java_int' does not name a type
/daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:6:13: error: 
'__java_float' does not name a type; did you mean '__cpp_hex_float'?
/daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:18:12: error: 
language string '"Java"' not recognized
/daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:25:5: error: 
'jint' does not name a type; did you mean 'int'?
/daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:26:5: error: 
'jfloat' does not name a type; did you mean 'float'?
/daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:41:6: error: 
'jfloat' was not declared in this scope
/daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:42:13: error: 
expected ';' before 'value1'
/daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:43:10: error: 
'value1' was not declared in this scope
/daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:43:19: error: 
'value2' was not declared in this scope
/daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:43:41: error: 
'union _Jv_word' has no member named 'i'

Andreas.

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


Re: [C++ PATCH] Delete GCJ - C++ part

2016-10-05 Thread Jakub Jelinek
On Wed, Oct 05, 2016 at 11:04:05AM +0200, Andreas Schwab wrote:
> FAIL: g++.dg/pr49847-2.C  -std=gnu++11 (test for excess errors)
> Excess errors:
> /daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:5:13: error: 
> '__java_int' does not name a type
> /daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:6:13: error: 
> '__java_float' does not name a type; did you mean '__cpp_hex_float'?
> /daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:18:12: error: 
> language string '"Java"' not recognized
> /daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:25:5: error: 
> 'jint' does not name a type; did you mean 'int'?
> /daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:26:5: error: 
> 'jfloat' does not name a type; did you mean 'float'?
> /daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:41:6: error: 
> 'jfloat' was not declared in this scope
> /daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:42:13: error: 
> expected ';' before 'value1'
> /daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:43:10: error: 
> 'value1' was not declared in this scope
> /daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:43:19: error: 
> 'value2' was not declared in this scope
> /daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:43:41: error: 
> 'union _Jv_word' has no member named 'i'

Feel free to remove it.  I have no access to m68k.

Jakub


Re: C++ PATCH for C++17 class template placeholders

2016-10-05 Thread Marek Polacek
On Wed, Oct 05, 2016 at 08:58:08AM +0200, Marc Glisse wrote:
> On Tue, 4 Oct 2016, Jason Merrill wrote:
> 
> > C++17 adds the ability to omit the template arguments for a class
> > template when declaring a variable with an initializer, much like auto
> > but supporting a wider variety of initialization.  This is intended to
> > replace functions like make_tuple.
> 
> Nice. Is there a macro to test for this feature? I couldn't find it in the
> latest sg10 list.

And in a similar vein, is there a macro for Selection statements with
initializer?  Can't find it anywhere.

Marek


[PATCH] Fix PR77842

2016-10-05 Thread Richard Biener

Committed as obvious.

Richard.

2016-10-05  Richard Biener  

PR middle-end/77842
* genmatch.c (parser::parse_c_expr): Handle premature EOF.

Index: gcc/genmatch.c
===
--- gcc/genmatch.c  (revision 240770)
+++ gcc/genmatch.c  (working copy)
@@ -4124,6 +4152,8 @@ parser::parse_c_expr (cpp_ttype start)
   else if (token->type == end
   && --opencnt == 0)
break;
+  else if (token->type == CPP_EOF)
+   fatal_at (token, "unexpected end of file");
 
   /* This is a lame way of counting the number of statements.  */
   if (token->type == CPP_SEMICOLON)


Re: [PATCH] add uClibc target hook (PR bootstrap/77819)

2016-10-05 Thread Bernd Schmidt

On 10/04/2016 10:25 PM, Martin Sebor wrote:


Sounds good.  Attached is an updated patch reflecting these changes.
Restested by building the powerpc64-linux and tic6x-uclinux cross
toolchains.  (Sharing the Glibc and uClibc implementation of the
target hook and defining it in targhooks.c also obviates the patch
I sent in for bug 77837 last night so it seems like a win-win.)


Ok.


Bernd



Re: [PATCH] Tree-level fix for PR 69526

2016-10-05 Thread Robin Dapp
Ping.



Re: [PATCH] Fix PR55152

2016-10-05 Thread Richard Biener
On Wed, 5 Oct 2016, Richard Biener wrote:

> On Tue, 4 Oct 2016, Joseph Myers wrote:
> 
> > On Tue, 4 Oct 2016, Richard Biener wrote:
> > 
> > > On Tue, 4 Oct 2016, Joseph Myers wrote:
> > > 
> > > > On Tue, 4 Oct 2016, Richard Biener wrote:
> > > > 
> > > > > Possibly.  Though then for FP we also want - abs (a) -> copysign (a, 
> > > > > -1).
> > > > 
> > > > For architectures such as powerpc that have a negated-abs instruction, 
> > > > does it get properly generated from the copysign code?  (The relevant 
> > > > pattern in rs6000.md uses (neg (abs)) - is that the correct canonical 
> > > > RTL 
> > > > for this?)
> > > 
> > > I have no idea - given that there is no copysign RTL code I suppose
> > > it is the only machine independent RTL that can do this?
> > > 
> > > The question would be whether the copysign optab of said targets would
> > > special-case the -1 case appropriately.
> > 
> > Why -1?  Any constant in copysign should be handled appropriately.  I'd 
> > say that (neg (abs)) is probably better as a canonical representation, so 
> > map copysign from a constant to either (abs) or (neg (abs)) appropriately.
> > 
> > Then in the case where abs is expanded with bit manipulation, (neg (abs)) 
> > should be expanded to a single OR.  I don't know whether the RTL 
> > optimizers will map the AND / OR combination to a single OR, but if they 
> > do then there should be no need to special-case (neg (abs)) in expansion, 
> > and when (abs) RTL is generated a machine description's (neg (abs)) 
> > pattern should match automatically.
> 
> Ok, that's a good point -- I'll do copysign (X, const) canonicalization
> to [-]abs() then.  Hopefully that's a valid transform even if NaNs and
> signed zeros are involved.

AFAICS it is.

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

Richard.

2016-10-05  Richard Biener  

* match.pd (copysign(x, CST) -> [-]abs (x)): New pattern.

* gcc.dg/fold-copysign-1.c: New testcase.

Index: gcc/match.pd
===
--- gcc/match.pd(revision 240770)
+++ gcc/match.pd(working copy)
@@ -452,6 +452,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (hypots @0 (copysigns @1 @2))
   (hypots @0 @1)))
 
+/* copysign(x, CST) -> [-]abs (x).  */
+(for copysigns (COPYSIGN)
+ (simplify
+  (copysigns @0 REAL_CST@1)
+  (if (REAL_VALUE_NEGATIVE (TREE_REAL_CST (@1)))
+   (negate (abs @0))
+   (abs @0
+
 /* copysign(copysign(x, y), z) -> copysign(x, z).  */
 (for copysigns (COPYSIGN)
  (simplify
Index: gcc/testsuite/gcc.dg/fold-copysign-1.c
===
--- gcc/testsuite/gcc.dg/fold-copysign-1.c  (revision 0)
+++ gcc/testsuite/gcc.dg/fold-copysign-1.c  (working copy)
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-cddce1" } */
+
+double foo (double x)
+{
+  double one = 1.;
+  return __builtin_copysign (x, one);
+}
+double bar (double x)
+{
+  double minuszero = -0.;
+  return __builtin_copysign (x, minuszero);
+}
+
+/* { dg-final { scan-tree-dump-times "= -" 1 "cddce1" } } */
+/* { dg-final { scan-tree-dump-times "= ABS_EXPR" 2 "cddce1" } } */


[PATCH] PR 70564 disambiguate constructors for not_fn call wrapper

2016-10-05 Thread Jonathan Wakely

The _Not_fn::_Not_fn<_Fn2>(_Fn2&&) ctor gets chosen by overload
resolution when trying to copy the call wrapper object (although only
for direct-initialization, because it's explicit). Rather than
constraining it using SFINAE I'm just adding a second parameter, so it
isn't viable for copying or moving the call wrapper.

I'm also reusing std::_Not_fn for std::experimental::not_fn, so we
don't need to fix bugs like this twice. _Not_fn uses std::invoke and
std::is_nothrow_callable, but we have __nonstandard versions of both
available in C++14.

PR libstdc++/70564
* include/experimental/functional (_Not_fn): Remove.
(not_fn): Use std::_Not_fn.
* include/std/functional (_Not_fn): Add second parameter to
disambiguate copying from initialization by not_fn. Define for C++14.
(not_fn): Add second argument to initialization.
* testsuite/20_util/not_fn/1.cc: Copy call wrapper using
direct-initialization.

Tested powerpc64le-linux, committing to trunk and gcc-6-branch.

commit a8f00b884083e0ffd9e9aaa919f6ea95adc57c2e
Author: Jonathan Wakely 
Date:   Wed Oct 5 11:22:36 2016 +0100

PR 70564 disambiguate constructors for not_fn call wrapper

PR libstdc++/70564
* include/experimental/functional (_Not_fn): Remove.
(not_fn): Use std::_Not_fn.
* include/std/functional (_Not_fn): Add second parameter to
disambiguate copying from initialization by not_fn. Define for C++14.
(not_fn): Add second argument to initialization.
* testsuite/20_util/not_fn/1.cc: Copy call wrapper using
direct-initialization.

diff --git a/libstdc++-v3/include/experimental/functional 
b/libstdc++-v3/include/experimental/functional
index 082e58c..db45665 100644
--- a/libstdc++-v3/include/experimental/functional
+++ b/libstdc++-v3/include/experimental/functional
@@ -378,64 +378,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #define __cpp_lib_experimental_not_fn 201406
 
-  /// Generalized negator.
-  template
-class _Not_fn
-{
-  _Fn _M_fn;
-
-public:
-  template
-   explicit
-   _Not_fn(_Fn2&& __fn)
-   : _M_fn(std::forward<_Fn2>(__fn)) { }
-
-  _Not_fn(const _Not_fn& __fn) = default;
-  _Not_fn(_Not_fn&& __fn) = default;
-  ~_Not_fn() = default;
-
-  template
-   auto
-   operator()(_Args&&... __args) &
-   noexcept(__is_nothrow_callable<_Fn&(_Args&&...)>::value)
-   -> decltype(!std::declval>())
-   { return !std::__invoke(_M_fn, std::forward<_Args>(__args)...); }
-
-  template
-   auto
-   operator()(_Args&&... __args) const &
-   noexcept(__is_nothrow_callable::value)
-   -> decltype(!std::declval>())
-   { return !std::__invoke(_M_fn, std::forward<_Args>(__args)...); }
-
-  template
-   auto
-   operator()(_Args&&... __args) &&
-   noexcept(__is_nothrow_callable<_Fn&&(_Args&&...)>::value)
-   -> decltype(!std::declval>())
-   {
- return !std::__invoke(std::move(_M_fn),
-   std::forward<_Args>(__args)...);
-   }
-
-  template
-   auto
-   operator()(_Args&&... __args) const &&
-   noexcept(__is_nothrow_callable::value)
-   -> decltype(!std::declval>())
-   {
- return !std::__invoke(std::move(_M_fn),
-   std::forward<_Args>(__args)...);
-   }
-};
-
   /// [func.not_fn] Function template not_fn
   template
 inline auto
 not_fn(_Fn&& __fn)
 noexcept(std::is_nothrow_constructible, _Fn&&>::value)
 {
-  return _Not_fn>{std::forward<_Fn>(__fn)};
+  return std::_Not_fn>{std::forward<_Fn>(__fn), 0};
 }
 
 _GLIBCXX_END_NAMESPACE_VERSION
diff --git a/libstdc++-v3/include/std/functional 
b/libstdc++-v3/include/std/functional
index 74e65c7..1c7523e 100644
--- a/libstdc++-v3/include/std/functional
+++ b/libstdc++-v3/include/std/functional
@@ -2139,19 +2139,14 @@ _GLIBCXX_MEM_FN_TRAITS(&&, false_type, true_type)
 swap(function<_Res(_Args...)>& __x, function<_Res(_Args...)>& __y) noexcept
 { __x.swap(__y); }
 
-
-#if __cplusplus > 201402L
-
-#define __cpp_lib_not_fn 201603
-
-/// Generalized negator.
+#if __cplusplus >= 201402L
+  /// Generalized negator.
   template
 class _Not_fn
 {
 public:
   template
-   explicit
-   _Not_fn(_Fn2&& __fn)
+   _Not_fn(_Fn2&& __fn, int)
: _M_fn(std::forward<_Fn2>(__fn)) { }
 
   _Not_fn(const _Not_fn& __fn) = default;
@@ -2161,21 +2156,21 @@ _GLIBCXX_MEM_FN_TRAITS(&&, false_type, true_type)
   template
auto
operator()(_Args&&... __args) &
-   noexcept(is_nothrow_callable_v<_Fn&(_Args&&...)>)
+   noexcept(__is_nothrow_callable<_Fn&(_Args&&...)>::value)
-> decltype(!std::declval>())
{ return !std::__invoke(_M_fn, std::forward<_Args>(__args)...); }
 
   template
auto
operator()(_Args&&... __args) const &
-   noexcept(is_nothrow_callable_v)

[PATCH] Remove invalid alias declaration from _Node_handle

2016-10-05 Thread Jonathan Wakely

This alias-declaration isn't valid (it should go through
allocator_traits) but isn't needed anyway.

* include/bits/node_handle.h (_Node_handle): Remove invalid and unused
alias declaration.

Tested powerpc64le-linux, committing to trunk.

commit 7ba39a821c7af0991abdec3f071d8f1270652f48
Author: Jonathan Wakely 
Date:   Wed Oct 5 11:26:10 2016 +0100

Remove invalid alias declaration from _Node_handle

* include/bits/node_handle.h (_Node_handle): Remove invalid and unused
alias declaration.

diff --git a/libstdc++-v3/include/bits/node_handle.h 
b/libstdc++-v3/include/bits/node_handle.h
index 60c2883..e89092b 100644
--- a/libstdc++-v3/include/bits/node_handle.h
+++ b/libstdc++-v3/include/bits/node_handle.h
@@ -182,10 +182,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 private:
   using _AllocTraits = allocator_traits<_NodeAlloc>;
 
-  using _PtrTraits = pointer_traits;
-
   _Node_handle(typename _AllocTraits::pointer __ptr,
-  const _NodeAlloc& __alloc)
+  const _NodeAlloc& __alloc)
   : _Node_handle_common<_Value, _NodeAlloc>(__ptr, __alloc)
   {
if (__ptr)
@@ -261,7 +259,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   using _AllocTraits = allocator_traits<_NodeAlloc>;
 
   _Node_handle(typename _AllocTraits::pointer __ptr,
-  const _NodeAlloc& __alloc)
+  const _NodeAlloc& __alloc)
   : _Node_handle_common<_Value, _NodeAlloc>(__ptr, __alloc) { }
 
   const value_type&


Re: [PATCH] Fix PR77826

2016-10-05 Thread Richard Biener
On Tue, 4 Oct 2016, Richard Biener wrote:

> 
> The following will fix PR77826, the issue that in match.pd matching
> up two things uses operand_equal_p which is too lax about the type
> of the toplevel entity (at least for integer constants).
> 
> Bootstrap / regtest pending on x86_64-unknown-linux-gnu.

The following is what I have applied.

Richard.

2016-10-05  Richard Biener  

PR middle-end/77826
* genmatch.c (dt_operand::gen_match_op): Amend operand_equal_p
with types_match for GIMPLE code gen to handle type mismatched
constants properly.
(dt_operand::gen): Adjust.
* match.pd ((X /[ex] A) * A -> X): Properly handle converted
and constant A.

* gcc.dg/torture/pr77826.c: New testcase.

Index: gcc/testsuite/gcc.dg/torture/pr77826.c
===
--- gcc/testsuite/gcc.dg/torture/pr77826.c  (revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr77826.c  (working copy)
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+
+void
+fi(unsigned long int *v0, unsigned int ow, int q2)
+{
+  if (ow + q2 != 0)
+if (q2 == 1)
+  {
+   *v0 |= q2;
+   q2 ^= *v0;
+  }
+}
Index: gcc/genmatch.c
===
--- gcc/genmatch.c  (revision 240744)
+++ gcc/genmatch.c  (working copy)
@@ -1562,7 +1562,7 @@ struct dt_operand : public dt_node
 
   void gen (FILE *, int, bool);
   unsigned gen_predicate (FILE *, int, const char *, bool);
-  unsigned gen_match_op (FILE *, int, const char *);
+  unsigned gen_match_op (FILE *, int, const char *, bool);
 
   unsigned gen_gimple_expr (FILE *, int);
   unsigned gen_generic_expr (FILE *, int, const char *);
@@ -2589,12 +2589,18 @@ dt_operand::gen_predicate (FILE *f, int
a capture-match.  */
 
 unsigned
-dt_operand::gen_match_op (FILE *f, int indent, const char *opname)
+dt_operand::gen_match_op (FILE *f, int indent, const char *opname, bool gimple)
 {
   char match_opname[20];
   match_dop->get_name (match_opname);
-  fprintf_indent (f, indent, "if (%s == %s || operand_equal_p (%s, %s, 0))\n",
- opname, match_opname, opname, match_opname);
+  if (gimple)
+fprintf_indent (f, indent, "if (%s == %s || (operand_equal_p (%s, %s, 0) "
+   "&& types_match (%s, %s)))\n",
+   opname, match_opname, opname, match_opname,
+   opname, match_opname);
+  else
+fprintf_indent (f, indent, "if (%s == %s || operand_equal_p (%s, %s, 
0))\n",
+   opname, match_opname, opname, match_opname);
   fprintf_indent (f, indent + 2, "{\n");
   return 1;
 }
@@ -2991,7 +2997,7 @@ dt_operand::gen (FILE *f, int indent, bo
   else if (type == DT_TRUE)
 ;
   else if (type == DT_MATCH)
-n_braces = gen_match_op (f, indent, opname);
+n_braces = gen_match_op (f, indent, opname, gimple);
   else
 gcc_unreachable ();
 
Index: gcc/match.pd
===
--- gcc/match.pd(revision 240770)
+++ gcc/match.pd(working copy)
@@ -1773,9 +1803,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 
 /* (X /[ex] A) * A -> X.  */
 (simplify
-  (mult (convert? (exact_div @0 @1)) @1)
-  /* Look through a sign-changing conversion.  */
-  (convert @0))
+  (mult (convert1? (exact_div @0 @1)) (convert2? @2))
+  /* We cannot use matching captures here, since in the case of
+ constants we don't see the second conversion.  Look through
+ a sign-changing or widening conversions.  */
+  (if (operand_equal_p (@1, @2, 0)
+   && element_precision (@0) <= element_precision (type))
+   (convert @0)))
 
 /* Canonicalization of binary operations.  */
 


[PATCH] 77864 Fix noexcept conditions for map/set default constructors

2016-10-05 Thread Jonathan Wakely

I added conditional noexcept to maps and sets, but forgot to account
for the comparison function, which could throw when constructed.

PR libstdc++/77864
* include/bits/stl_map.h (map::map()): Use nothrow constructibility
of comparison function in conditional noexcept.
* include/bits/stl_multimap.h (multimap::multimap()): Likewise.
* include/bits/stl_multiset.h (multiset::multiset()): Likewise.
* include/bits/stl_set.h (set::set()): Likewise.
* testsuite/23_containers/map/cons/noexcept_default_construct.cc:
New test.
* testsuite/23_containers/multimap/cons/noexcept_default_construct.cc:
Likewise.
* testsuite/23_containers/multiset/cons/noexcept_default_construct.cc:
Likewise.
* testsuite/23_containers/set/cons/noexcept_default_construct.cc:
Likewise.

Tested powerpc64le-linux, committing to trunk, gcc-5 and gcc-6.

commit 8cf0acf15ae71abeb29c0cf5b900131a20b6f375
Author: Jonathan Wakely 
Date:   Wed Oct 5 12:20:32 2016 +0100

77864 Fix noexcept conditions for map/set default constructors

PR libstdc++/77864
* include/bits/stl_map.h (map::map()): Use nothrow constructibility
of comparison function in conditional noexcept.
* include/bits/stl_multimap.h (multimap::multimap()): Likewise.
* include/bits/stl_multiset.h (multiset::multiset()): Likewise.
* include/bits/stl_set.h (set::set()): Likewise.
* testsuite/23_containers/map/cons/noexcept_default_construct.cc:
New test.
* testsuite/23_containers/multimap/cons/noexcept_default_construct.cc:
Likewise.
* testsuite/23_containers/multiset/cons/noexcept_default_construct.cc:
Likewise.
* testsuite/23_containers/set/cons/noexcept_default_construct.cc:
Likewise.

diff --git a/libstdc++-v3/include/bits/stl_map.h 
b/libstdc++-v3/include/bits/stl_map.h
index 9a0454a..e5b2a1b 100644
--- a/libstdc++-v3/include/bits/stl_map.h
+++ b/libstdc++-v3/include/bits/stl_map.h
@@ -168,9 +168,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*  @brief  Default constructor creates no elements.
*/
   map()
-#if __cplusplus >= 201103L
-  noexcept(is_nothrow_default_constructible::value)
-#endif
+  _GLIBCXX_NOEXCEPT_IF(
+ is_nothrow_default_constructible::value
+ && is_nothrow_default_constructible::value)
   : _M_t() { }
 
   /**
diff --git a/libstdc++-v3/include/bits/stl_multimap.h 
b/libstdc++-v3/include/bits/stl_multimap.h
index c794b9b..d240427 100644
--- a/libstdc++-v3/include/bits/stl_multimap.h
+++ b/libstdc++-v3/include/bits/stl_multimap.h
@@ -165,9 +165,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*  @brief  Default constructor creates no elements.
*/
   multimap()
-#if __cplusplus >= 201103L
-  noexcept(is_nothrow_default_constructible::value)
-#endif
+  _GLIBCXX_NOEXCEPT_IF(
+ is_nothrow_default_constructible::value
+ && is_nothrow_default_constructible::value)
   : _M_t() { }
 
   /**
diff --git a/libstdc++-v3/include/bits/stl_multiset.h 
b/libstdc++-v3/include/bits/stl_multiset.h
index d3219eb..cc068a9 100644
--- a/libstdc++-v3/include/bits/stl_multiset.h
+++ b/libstdc++-v3/include/bits/stl_multiset.h
@@ -145,9 +145,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*  @brief  Default constructor creates no elements.
*/
   multiset()
-#if __cplusplus >= 201103L
-  noexcept(is_nothrow_default_constructible::value)
-#endif
+  _GLIBCXX_NOEXCEPT_IF(
+ is_nothrow_default_constructible::value
+ && is_nothrow_default_constructible::value)
   : _M_t() { }
 
   /**
diff --git a/libstdc++-v3/include/bits/stl_set.h 
b/libstdc++-v3/include/bits/stl_set.h
index 140db39..3938351 100644
--- a/libstdc++-v3/include/bits/stl_set.h
+++ b/libstdc++-v3/include/bits/stl_set.h
@@ -148,9 +148,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*  @brief  Default constructor creates no elements.
*/
   set()
-#if __cplusplus >= 201103L
-  noexcept(is_nothrow_default_constructible::value)
-#endif
+  _GLIBCXX_NOEXCEPT_IF(
+ is_nothrow_default_constructible::value
+ && is_nothrow_default_constructible::value)
   : _M_t() { }
 
   /**
diff --git 
a/libstdc++-v3/testsuite/23_containers/map/cons/noexcept_default_construct.cc 
b/libstdc++-v3/testsuite/23_containers/map/cons/noexcept_default_construct.cc
new file mode 100644
index 000..1286d37
--- /dev/null
+++ 
b/libstdc++-v3/testsuite/23_containers/map/cons/noexcept_default_construct.cc
@@ -0,0 +1,32 @@
+// 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.
+
+// Thi

[PATCH] Fix PR77863

2016-10-05 Thread Richard Biener

Applied as obvious.

Richard.

2016-10-05  Richard Biener  

PR middle-end/77863
* genmatch.c (capture_info::walk_c_expr): Diagnose unknown
capture ids in c-exprs.

Index: gcc/genmatch.c
===
--- gcc/genmatch.c  (revision 240776)
+++ gcc/genmatch.c  (working copy)
@@ -2194,8 +2194,10 @@ capture_info::walk_c_expr (c_expr *e)
id = (const char *)n->val.str.text;
  else
id = (const char *)CPP_HASHNODE (n->val.node.node)->ident.str;
- unsigned where = *e->capture_ids->get(id);
- info[info[where].same_as].force_no_side_effects_p = true;
+ unsigned *where = e->capture_ids->get(id);
+ if (! where)
+   fatal_at (n, "unknown capture id '%s'", id);
+ info[info[*where].same_as].force_no_side_effects_p = true;
  if (verbose >= 1
  && !gimple)
warning_at (t, "capture escapes");



[PATCH] PR 70101 fix allocator-extended ctors for std::priority_queue

2016-10-05 Thread Jonathan Wakely

These constructors were just completely borked.

PR libstdc++/70101
* include/bits/stl_queue.h (priority_queue): Fix allocator-extended
constructors.
* testsuite/23_containers/priority_queue/allocator.cc: New test.

Tested powerpc64le-linux, committing to trunk and gcc-6.


commit 58f7f212b3b73b620d157f33faca7546127a1136
Author: Jonathan Wakely 
Date:   Wed Oct 5 12:12:12 2016 +0100

PR 70101 fix allocator-extended ctors for std::priority_queue

PR libstdc++/70101
* include/bits/stl_queue.h (priority_queue): Fix allocator-extended
constructors.
* testsuite/23_containers/priority_queue/allocator.cc: New test.

diff --git a/libstdc++-v3/include/bits/stl_queue.h 
b/libstdc++-v3/include/bits/stl_queue.h
index da984ff..843199c 100644
--- a/libstdc++-v3/include/bits/stl_queue.h
+++ b/libstdc++-v3/include/bits/stl_queue.h
@@ -462,28 +462,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template>
explicit
priority_queue(const _Alloc& __a)
-   : c(__a) { }
+   : c(__a), comp() { }
 
   template>
priority_queue(const _Compare& __x, const _Alloc& __a)
-   : c(__x, __a) { }
+   : c(__a), comp(__x) { }
 
   template>
priority_queue(const _Compare& __x, const _Sequence& __c,
   const _Alloc& __a)
-   : c(__x, __c, __a) { }
+   : c(__c, __a), comp(__x) { }
 
   template>
priority_queue(const _Compare& __x, _Sequence&& __c, const _Alloc& __a)
-   : c(__x, std::move(__c), __a) { }
+   : c(std::move(__c), __a), comp(__x) { }
 
   template>
priority_queue(const priority_queue& __q, const _Alloc& __a)
-   : c(__q.c, __a) { }
+   : c(__q.c, __a), comp(__q.comp) { }
 
   template>
priority_queue(priority_queue&& __q, const _Alloc& __a)
-   : c(std::move(__q.c), __a) { }
+   : c(std::move(__q.c), __a), comp(std::move(__q.comp)) { }
 #endif
 
   /**
diff --git a/libstdc++-v3/testsuite/23_containers/priority_queue/allocator.cc 
b/libstdc++-v3/testsuite/23_containers/priority_queue/allocator.cc
new file mode 100644
index 000..dd6ca25
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/priority_queue/allocator.cc
@@ -0,0 +1,62 @@
+// 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 copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+// { dg-do run { target c++11 } }
+
+#include 
+#include 
+
+// PR libstdc++/70101
+
+struct comp
+{
+  int init_check[64];
+  bool operator()(int l, int r) const { return l < r; }
+};
+
+struct check_init : std::priority_queue, comp>
+{
+  template
+check_init(Args... args) : priority_queue(args...)
+{
+  push(0);
+
+  for (int i : comp.init_check)
+VERIFY( i == 0 );  // Will not fail if *this was value-initialized.
+}
+};
+
+void
+test01()
+{
+  std::vector vec;
+  comp cmp{};
+  std::allocator alloc;
+  std::priority_queue, comp> pq;
+  check_init c1( pq, alloc );
+  check_init c2( std::move(pq), alloc );
+  check_init c3( alloc );
+  check_init c4( cmp, alloc );
+  check_init c5( cmp, vec, alloc );
+  check_init c6( cmp, std::move(vec), alloc );
+}
+
+int
+main()
+{
+  test01();
+}


Re: [PATCH] 77864 Fix noexcept conditions for map/set default constructors

2016-10-05 Thread Marc Glisse

On Wed, 5 Oct 2016, Jonathan Wakely wrote:


I added conditional noexcept to maps and sets, but forgot to account
for the comparison function, which could throw when constructed.


IMO you are fighting a losing battle. We should implement noexcept(auto) 
(possibly with some private __noexcept_auto__ spelling) and just use that 
in most places where we want a conditional noexcept.


--
Marc Glisse


[PATCH] Fix ICE for sparc targets in function_arg_record_value (PR target/77759)

2016-10-05 Thread James Clarke
gcc/
PR target/77759
* config/sparc/sparc.c (classify_data_t): Remove unused int_regs field.
(classify_registers): Don't set int_regs.
(function_arg_slotno): Don't initialise int_regs. Check slotno is
within range for empty structs, just like int register-only structs.

gcc/testsuite/
PR target/77759
* g++.dg/other/pr77759.C: New test.
---
 gcc/config/sparc/sparc.c | 10 +++---
 gcc/testsuite/g++.dg/other/pr77759.C | 27 +++
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/gcc/config/sparc/sparc.c b/gcc/config/sparc/sparc.c
index c622b66..7af8ba1 100644
--- a/gcc/config/sparc/sparc.c
+++ b/gcc/config/sparc/sparc.c
@@ -6294,7 +6294,6 @@ traverse_record_type (const_tree type, bool named, T 
*data,
 
 typedef struct
 {
-  bool int_regs;   /* true if field eligible to int registers.  */
   bool fp_regs;/* true if field eligible to FP registers.  */
   bool fp_regs_in_first_word;  /* true if such field in first word.  */
 } classify_data_t;
@@ -6311,8 +6310,6 @@ classify_registers (const_tree, HOST_WIDE_INT bitpos, 
bool fp,
   if (bitpos < BITS_PER_WORD)
data->fp_regs_in_first_word = true;
 }
-  else
-data->int_regs = true;
 }
 
 /* Compute the slot number to pass an argument in.
@@ -6439,7 +6436,7 @@ function_arg_slotno (const struct sparc_args *cum, 
machine_mode mode,
 
  if (TREE_CODE (type) == RECORD_TYPE)
{
- classify_data_t data = { false, false, false };
+ classify_data_t data = { false, false };
  traverse_record_type
(type, named, &data);
 
@@ -6450,10 +6447,9 @@ function_arg_slotno (const struct sparc_args *cum, 
machine_mode mode,
  && slotno >= SPARC_FP_ARG_MAX - 1)
return -1;
 
- /* If there are only int args and all int slots are filled,
-then must pass on stack.  */
+ /* If there are only int args or this is an empty record type,
+and all int slots are filled, then must pass on stack.  */
  if (!data.fp_regs
- && data.int_regs
  && slotno >= SPARC_INT_ARG_MAX)
return -1;
}
diff --git a/gcc/testsuite/g++.dg/other/pr77759.C 
b/gcc/testsuite/g++.dg/other/pr77759.C
new file mode 100644
index 000..4494bb5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/pr77759.C
@@ -0,0 +1,27 @@
+/* PR target/77759
+   This testcase ICEd on sparc because function_arg_slotno did not treat empty
+   structs as being passed in integer registers and tried to assign the
+   struct pair_empty to register slot 6, causing function_arg_record_value to
+   fail the assertion that at least one register was available. */
+/* { dg-do compile { target sparc*-*-* } } */
+
+struct empty {};
+
+struct pair_empty
+{
+  struct empty a;
+  struct empty b;
+};
+
+void f1(int slot0 __attribute__((unused)), int slot1 __attribute__((unused)),
+   int slot2 __attribute__((unused)), int slot3 __attribute__((unused)),
+   int slot4 __attribute__((unused)), int slot5 __attribute__((unused)),
+   struct pair_empty pair __attribute__((unused)))
+{
+}
+
+void f2(void)
+{
+  struct pair_empty pair;
+  f1(0, 0, 0, 0, 0, 0, pair);
+}
-- 
2.9.3



Re: [PATCH] 77864 Fix noexcept conditions for map/set default constructors

2016-10-05 Thread Jonathan Wakely

On 05/10/16 14:10 +0200, Marc Glisse wrote:

On Wed, 5 Oct 2016, Jonathan Wakely wrote:


I added conditional noexcept to maps and sets, but forgot to account
for the comparison function, which could throw when constructed.


IMO you are fighting a losing battle. We should implement 
noexcept(auto) (possibly with some private __noexcept_auto__ spelling) 
and just use that in most places where we want a conditional noexcept.


That would be nice, but beyond my ability :-)

So until then we can either remove the exception specs entirely, or
make them correct.



Re: [BUILDROBOT] Selftest failed for i686-wrs-vxworks

2016-10-05 Thread Thomas Schwinge
Hi!

I've now also run into this issue, during contrib/config-list.mk testing;
log/arm-wrs-vxworks-make.out, log/i686-wrs-vxworks-make.out,
log/i686-wrs-vxworksae-make.out, log/mips-wrs-vxworks-make.out,
log/powerpc-wrs-vxworks-make.out, log/powerpc-wrs-vxworksae-make.out,
log/powerpc-wrs-vxworksmils-make.out, log/sh-wrs-vxworks-make.out,
log/sparc-wrs-vxworks-make.out:

[...]/build-multi/arm-wrs-vxworks/./gcc/xgcc 
-B[...]/build-multi/arm-wrs-vxworks/./gcc/ -xc -S -c /dev/null -fself-test
xgcc: fatal error: environment variable 'WIND_BASE' not defined
compilation terminated.
make[2]: *** [s-selftest] Error 1
[...]
make[1]: *** [all-gcc] Error 2

On Thu, 30 Jun 2016 16:09:23 -0400, David Malcolm  wrote:
> On Thu, 2016-06-30 at 08:38 -0400, Nathan Sidwell wrote:
> > [...] WIND_BASE is expected to point at a vxworks install [...]

> [...]
> 
> Hence it appears that passing "-nostdinc" as a param will avoid the
> error: [...]
> 
> Presumably if you're explicitly building for vxworks you have a vxworks
> install, so there is a meaningful value to set WIND_BASE to, whereas if
> you don't have a vxworks install (and are merely building everything as
> a smoketest), you presumably only want to build the "gcc" subdir, since
> AFAIK you can't run then driver.
> 
> So there are at least 2 ways of fixing this:
> 
> (a) add "-nostdinc" when running the selftests i.e. to the invocations
> of GCC_FOR_TARGET in the "s-selftest" and "selftest-gdb" clauses of
> gcc/Makefile.in.
> I've verified that this fixes the issue for --target=i686-wrs-vxworks.

OK to apply the following two patches?  First, a little bit of
refactoring:

commit 0b124fda378c9dc726bd709f805dd52a7dc7c78a
Author: Thomas Schwinge 
Date:   Wed Oct 5 08:06:00 2016 +0200

In gcc/Makefile.in, factor out SELFTEST_FLAGS

gcc/
* Makefile.in (SELFTEST_FLAGS): New variable.
(s-selftest, selftest-gdb, selftest-valgrind): Use it.
---
 gcc/Makefile.in | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git gcc/Makefile.in gcc/Makefile.in
index 15c48bc..08b96a6 100644
--- gcc/Makefile.in
+++ gcc/Makefile.in
@@ -1876,6 +1876,10 @@ endif
 # This does the things that can't be done on the host machine.
 rest.cross: specs
 
+# GCC's selftests.
+# Specify a dummy input file to placate the driver.
+SELFTEST_FLAGS = -x c /dev/null -S -fself-test
+
 # Run the selftests during the build once we have a driver and a cc1,
 # so that self-test failures are caught as early as possible.
 # Use "s-selftest" to ensure that we only run the selftests if the
@@ -1883,18 +1887,19 @@ rest.cross: specs
 .PHONY: selftest
 selftest: s-selftest
 s-selftest: $(GCC_PASSES) cc1$(exeext) stmp-int-hdrs
-   $(GCC_FOR_TARGET) -xc -S -c /dev/null -fself-test
+   $(GCC_FOR_TARGET) $(SELFTEST_FLAGS)
$(STAMP) $@
 
 # Convenience method for running selftests under gdb:
 .PHONY: selftest-gdb
 selftest-gdb: $(GCC_PASSES) cc1$(exeext) stmp-int-hdrs
-   $(GCC_FOR_TARGET) -xc -S -c /dev/null -fself-test -wrapper gdb,--args
+   $(GCC_FOR_TARGET) $(SELFTEST_FLAGS) \
+ -wrapper gdb,--args
 
 # Convenience method for running selftests under valgrind:
 .PHONY: selftest-valgrind
 selftest-valgrind: $(GCC_PASSES) cc1$(exeext) stmp-int-hdrs
-   $(GCC_FOR_TARGET) -xc -S -c /dev/null -fself-test \
+   $(GCC_FOR_TARGET) $(SELFTEST_FLAGS) \
  -wrapper valgrind,--leak-check=full
 
 # Recompile all the language-independent object files.

..., and then the real change:

commit 8ab49582c42809b385eb957c20b84d21a90e041a
Author: Thomas Schwinge 
Date:   Wed Oct 5 08:08:37 2016 +0200

Make GCC selftests work for *-wrs-vxworks-* targets

gcc/
Makefile.in (SELFTEST_FLAGS): Add -nostdinc.
---
 gcc/Makefile.in | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git gcc/Makefile.in gcc/Makefile.in
index 08b96a6..23623ac 100644
--- gcc/Makefile.in
+++ gcc/Makefile.in
@@ -1878,7 +1878,9 @@ rest.cross: specs
 
 # GCC's selftests.
 # Specify a dummy input file to placate the driver.
-SELFTEST_FLAGS = -x c /dev/null -S -fself-test
+# Specify -nostdinc to work around missing WIND_BASE environment variable
+# required for *-wrs-vxworks-* targets.
+SELFTEST_FLAGS = -nostdinc -x c /dev/null -S -fself-test
 
 # Run the selftests during the build once we have a driver and a cc1,
 # so that self-test failures are caught as early as possible.


Grüße
 Thomas


Re: [PATCH] PR 70564 disambiguate constructors for not_fn call wrapper

2016-10-05 Thread Jonathan Wakely

On 05/10/16 12:31 +0100, Jonathan Wakely wrote:

diff --git a/libstdc++-v3/testsuite/20_util/not_fn/1.cc 
b/libstdc++-v3/testsuite/20_util/not_fn/1.cc
index 375c7cc..8d6e9ec 100644
--- a/libstdc++-v3/testsuite/20_util/not_fn/1.cc
+++ b/libstdc++-v3/testsuite/20_util/not_fn/1.cc
@@ -84,6 +84,12 @@ test04()
  VERIFY( not_fn(f)(d) );
}

+void
+test05()
+{
+  auto nf{ std::not_fn([] { return false; }) };
+}
+
int
main()
{



diff --git a/libstdc++-v3/testsuite/experimental/functional/not_fn.cc 
b/libstdc++-v3/testsuite/experimental/functional/not_fn.cc
index d508028..59d7621 100644
--- a/libstdc++-v3/testsuite/experimental/functional/not_fn.cc
+++ b/libstdc++-v3/testsuite/experimental/functional/not_fn.cc
@@ -84,6 +84,12 @@ test04()
  VERIFY( not_fn(f)(d) );
}

+void
+test05()
+{
+  auto nf{ not_fn([] { return false; }) };
+}
+
int
main()
{


Gah, this aren't the tests I meant to commit. Fixed on trunk like so,
with tests that actually failed before the fix.



commit 998cf48ef12d44d215acb70f80600e46648da94f
Author: Jonathan Wakely 
Date:   Wed Oct 5 13:19:38 2016 +0100

70564 fix newly-added tests for not_fn

	PR libstdc++/70564
	* testsuite/20_util/not_fn/1.cc: Fix test.
	* testsuite/experimental/functional/not_fn.cc: Likewise.

diff --git a/libstdc++-v3/testsuite/20_util/not_fn/1.cc b/libstdc++-v3/testsuite/20_util/not_fn/1.cc
index 8d6e9ec..233a6d3 100644
--- a/libstdc++-v3/testsuite/20_util/not_fn/1.cc
+++ b/libstdc++-v3/testsuite/20_util/not_fn/1.cc
@@ -87,7 +87,8 @@ test04()
 void
 test05()
 {
-  auto nf{ std::not_fn([] { return false; }) };
+  auto nf = std::not_fn([] { return false; });
+  auto copy(nf); // PR libstdc++/70564
 }
 
 int
diff --git a/libstdc++-v3/testsuite/experimental/functional/not_fn.cc b/libstdc++-v3/testsuite/experimental/functional/not_fn.cc
index 59d7621..525f59c 100644
--- a/libstdc++-v3/testsuite/experimental/functional/not_fn.cc
+++ b/libstdc++-v3/testsuite/experimental/functional/not_fn.cc
@@ -87,7 +87,8 @@ test04()
 void
 test05()
 {
-  auto nf{ not_fn([] { return false; }) };
+  auto nf = std::experimental::not_fn([] { return false; });
+  auto copy(nf); // PR libstdc++/70564
 }
 
 int


Re: [PATCH] PR 70564 disambiguate constructors for not_fn call wrapper

2016-10-05 Thread Jonathan Wakely

On 05/10/16 12:31 +0100, Jonathan Wakely wrote:

Tested powerpc64le-linux, committing to trunk and gcc-6-branch.


And here's the slightly diffeernt patch for the branch (because we
only have experimental::not_fn there, not std::not_fn).


commit 2484aeb5b25372c3a7833a000b798e3bf6f41c6b
Author: redi 
Date:   Wed Oct 5 12:01:36 2016 +

PR 70564 disambiguate constructor for not_fn call wrapper

	PR libstdc++/70564
	* include/experimental/functional (_Not_fn): Add second parameter to
	disambiguate copying from initialization by not_fn.
	(not_fn): Add second argument to initialization.
	* testsuite/experimental/functional/not_fn.cc: Copy call wrapper using
	direct-initialization. Test abstract class.

diff --git a/libstdc++-v3/include/experimental/functional b/libstdc++-v3/include/experimental/functional
index 0b91dcd..6a21caf 100644
--- a/libstdc++-v3/include/experimental/functional
+++ b/libstdc++-v3/include/experimental/functional
@@ -387,7 +387,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 public:
   template
 	explicit
-	_Not_fn(_Fn2&& __fn) : _M_fn(std::forward<_Fn2>(__fn)) { }
+	_Not_fn(_Fn2&& __fn, int) : _M_fn(std::forward<_Fn2>(__fn)) { }
 
   _Not_fn(const _Not_fn& __fn) = default;
   _Not_fn(_Not_fn&& __fn) = default;
@@ -431,7 +431,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 noexcept(std::is_nothrow_constructible, _Fn&&>::value)
 {
   using __maybe_type = _Maybe_wrap_member_pointer>;
-  return _Not_fn{std::forward<_Fn>(__fn)};
+  return _Not_fn{std::forward<_Fn>(__fn), 0};
 }
 
 _GLIBCXX_END_NAMESPACE_VERSION
diff --git a/libstdc++-v3/testsuite/experimental/functional/not_fn.cc b/libstdc++-v3/testsuite/experimental/functional/not_fn.cc
index 3096eaa..b69d3ac 100644
--- a/libstdc++-v3/testsuite/experimental/functional/not_fn.cc
+++ b/libstdc++-v3/testsuite/experimental/functional/not_fn.cc
@@ -76,10 +76,30 @@ test03()
   VERIFY( not_fn(&X::b)(x) );
 }
 
+void
+test04()
+{
+  struct abstract { virtual void f() = 0; };
+  struct derived : abstract { void f() { } };
+  struct F { bool operator()(abstract&) { return false; } };
+  F f;
+  derived d;
+  VERIFY( not_fn(f)(d) );
+}
+
+void
+test05()
+{
+  auto nf = std::experimental::not_fn([] { return false; });
+  auto copy(nf); // PR libstdc++/70564
+}
+
 int
 main()
 {
   test01();
   test02();
   test03();
+  test04();
+  test05();
 }


C++ PATCH for C++17 selection statements with initializer

2016-10-05 Thread Marek Polacek
This is my attempt to implement P0305R1, Selection statements with initializer.
It allows the users to write

  if (init; cond) // ...

which is equivalent to

  {
init
if (cond) // ...
  }

Similarly for if-else, if constexpr, and switch.

The approach I had taken was to tentatively parse "init" and if no semicolon
follows, abort the parse and just parse the condition.  But this didn't work.
An init-statement is either a simple-declaration or an expression-statement,
and parsing either has irreversible side-effects--e.g. adding a new statement
or a new declaration, or duplicating side-effects.  Using firewalls here
doesn't help.  Since an init-statement ends with a semicolon, I decided to
write cp_parser_init_statement_p, which checks if there's a semicolon in the if
condition that is not nested in () or in {} (think of ({}) or lambda
expressions).  It seemed a bit weird but seems to work well.  And then it's
just a simple matter of calling cp_parser_init_statement that parses either a
simple declaration or an expression statement and does the right thing wrt
scopes.

Since "for-init-statement" is no longer in the standard, I renamed all the
occurrences to "init-statement".

There's also this -ffor-scope thing, but I didn't touch it and it's probably
not necessary to.

Bootstrapped/regtested on x86_64-linux and ppc64-linux, ok for trunk? 

2016-10-05  Marek Polacek  

Implement P0305R1, Selection statements with initializer.
* cp-array-notation.c (create_an_loop): Call finish_init_stmt
instead of finish_for_init_stmt.
* cp-tree.h (finish_for_init_stmt): Rename to finish_init_stmt.
* decl.c (poplevel): Adjust a comment.
* init.c (build_vec_init): Call finish_init_stmt instead of
finish_for_init_stmt.
* name-lookup.c (pushdecl_maybe_friend_1): Adjust a comment.
* name-lookup.h (enum scope_kind): Likewise.
* parser.c (cp_parser_statement): Update commentary.
(cp_parser_init_statement_p): New function.
(cp_parser_selection_statement): Parse the optional init-statement.
(cp_parser_for): Call finish_init_stmt instead of finish_for_init_stmt.
(cp_parser_c_for): Likewise.
(cp_convert_range_for): Call finish_init_stmt instead of 
finish_for_init_stmt.
(cp_parser_range_for_member_function): Update commentary.
(cp_parser_iteration_statement):
(cp_parser_for_init_statement): Rename to cp_parser_init_statement.
* pt.c (tsubst_omp_for_iterator): Update commentary.
(tsubst_expr): Call finish_init_stmt instead of finish_for_init_stmt.
* semantics.c (finish_for_init_stmt): Rename to finish_init_stmt.
Update commentary.

* g++.dg/cpp1z/init-statement1.C: New test.
* g++.dg/cpp1z/init-statement2.C: New test.
* g++.dg/cpp1z/init-statement3.C: New test.
* g++.dg/cpp1z/init-statement4.C: New test.
* g++.dg/cpp1z/init-statement5.C: New test.
* g++.dg/cpp1z/init-statement6.C: New test.
* g++.dg/cpp1z/init-statement7.C: New test.

diff --git gcc/cp/cp-array-notation.c gcc/cp/cp-array-notation.c
index 4687ced..633ab09 100644
--- gcc/cp/cp-array-notation.c
+++ gcc/cp/cp-array-notation.c
@@ -66,7 +66,7 @@ create_an_loop (tree init, tree cond, tree incr, tree body)
 
   finish_expr_stmt (init);
   for_stmt = begin_for_stmt (NULL_TREE, NULL_TREE);
-  finish_for_init_stmt (for_stmt);
+  finish_init_stmt (for_stmt);
   finish_for_cond (cond, for_stmt, false);
   finish_for_expr (incr, for_stmt);
   finish_expr_stmt (body);
diff --git gcc/cp/cp-tree.h gcc/cp/cp-tree.h
index 3fbe1d9..92e4017 100644
--- gcc/cp/cp-tree.h
+++ gcc/cp/cp-tree.h
@@ -6297,7 +6297,7 @@ extern void finish_do_stmt(tree, 
tree, bool);
 extern tree finish_return_stmt (tree);
 extern tree begin_for_scope(tree *);
 extern tree begin_for_stmt (tree, tree);
-extern void finish_for_init_stmt   (tree);
+extern void finish_init_stmt   (tree);
 extern void finish_for_cond(tree, tree, bool);
 extern void finish_for_expr(tree, tree);
 extern void finish_for_stmt(tree);
diff --git gcc/cp/decl.c gcc/cp/decl.c
index 6646062..6a08d8f 100644
--- gcc/cp/decl.c
+++ gcc/cp/decl.c
@@ -639,9 +639,8 @@ poplevel (int keep, int reverse, int functionbody)
   BLOCK_SUPERCONTEXT (link) = block;
 
   /* We still support the old for-scope rules, whereby the variables
- in a for-init statement were in scope after the for-statement
- ended.  We only use the new rules if flag_new_for_scope is
- nonzero.  */
+ in a init statement were in scope after the for-statement ended.
+ We only use the new rules if flag_new_for_scope is nonzero.  */
   leaving_for_scope
 = current_binding_level->kind == sk_for && flag_new_for_scope == 1;
 
diff --git gcc/cp/init.c gcc/cp/init.c
ind

Compile-time improvement for if conversion.

2016-10-05 Thread Yuri Rumyantsev
Hi All,

Here is implementation of Richard proposal:

< For general infrastructure it would be nice to expose a (post-)dominator
< compute for MESE (post-dominators) / SEME (dominators) regions.  I believe
< what makes if-conversion expensive is the post-dom compute which happens
< for each loop for the whole function.  It shouldn't be very difficult
< to write this,
< sharing as much as possible code with the current DOM code might need
< quite some refactoring though.

I implemented this proposal by adding calculation of dominance info
for SESE regions and incorporate this change to if conversion pass.
SESE region is built by adding loop pre-header and possibly fake
post-header blocks to loop body. Fake post-header is deleted after
predication completion.

Bootstrapping and regression testing did not show any new failures.

Is it OK for trunk?

ChangeLog:
2016-10-05  Yuri Rumyantsev  

* dominance.c : Include cfgloop.h for loop recognition.
(dom_info): Add new functions and add boolean argument to recognize
computation for loop region.
(dom_info::dom_info): New function.
(dom_info::calc_dfs_tree): Add boolean argument IN_REGION to not
handle unvisited blocks.
(dom_info::calc_idoms): Likewise.
(compute_dom_fast_query_in_region): New function.
(calculate_dominance_info): Invoke calc_dfs_tree and calc_idoms with
false argument.
(calculate_dominance_info_for_region): New function.
(free_dominance_info_for_region): Likewise.
(verify_dominators): Invoke calc_dfs_tree and calc_idoms with false
argument.
* dominance.h: Add prototype for introduced functions
calculate_dominance_info_for_region and
free_dominance_info_for_region.
tree-if-conv.c: Add to local variables ifc_sese_bbs & fake_postheader.
(build_sese_region): New function.
(if_convertible_loop_p_1): Invoke local version of post-dominators
calculation, free it after basic block predication and delete created
fake post-header block if any.
(tree_if_conversion): Delete call of free_dominance_info for
post-dominators, free ifc_sese_bbs which represents SESE region.
(pass_if_conversion::execute): Delete detection of infinite loops
and fake edges to exit block since post-dominator calculation is
performed per if-converted loop only.


patch
Description: Binary data


Re: C++ PATCH for C++17 selection statements with initializer

2016-10-05 Thread Jakub Jelinek
On Wed, Oct 05, 2016 at 03:14:25PM +0200, Marek Polacek wrote:
> This is my attempt to implement P0305R1, Selection statements with 
> initializer.
> It allows the users to write
> 
>   if (init; cond) // ...
> 
> which is equivalent to
> 
>   {
> init
> if (cond) // ...
>   }

Well, it isn't exactly equivalent, because unlike { init; if (cond) /* ... */; }
there aren't two scopes, but just one.  So I'd say you should have tests
that verify that init and cond are indeed in the same scope, e.g. by trying
something like if (int c = 5; int c = 5) ... and verifying dg-error is
reported.

> + case CPP_CLOSE_PAREN:
> +   /* If the next token is a non-nested '(', then we have reached
> +  the end of the if condition.  */

Looks like typo, shouldn't that be ')' ?

Also, do you really need two counters?

> +   if (paren_depth-- == 0)
> + return false;
> +   break;
> +
> + case CPP_OPEN_PAREN:
> +   ++paren_depth;
> +   break;
> +
> + case CPP_CLOSE_BRACE:
> +   --brace_depth;

I mean, shouldn't you also stop before } when seeing if (int a = }; b)
rather than wrapping around?

> +  /* Consume the token.  */
> +  cp_lexer_consume_token (parser->lexer);
> +}

Also, do you really need to consume all the tokens and then rollback, rather
than just use peek_nth_token with the index increasing in each iteration?

Jakub


[PATCH,committed] PR77847: Add FALLTRHOUGH comment to fix build error

2016-10-05 Thread Kelvin Nilsen

This trivial/obvious patch was committed without review as svn revision
240783.  The patch fixes a compile-time error that recently surfaced
with big-endian Power architecture builds.

libcpp/ChangeLog:

2016-10-04  Kelvin Nilsen  

PR target/77847
* lex.c (search_line_fast): Add a FALLTHROUGH comment to correct
compiler error in the version of this function that is
conditionally compiled when GCC_VERSION >= 4005 and both
__ALTIVEC__ and __BIG_ENDIAN__ symbols are defined.

Index: libcpp/lex.c
===
--- libcpp/lex.c(revision 240755)
+++ libcpp/lex.c(working copy)
@@ -733,6 +733,7 @@
if (l != 0)
  break;
s += sizeof(unsigned long);
+   /* FALLTHROUGH */
   case 2:
l = u.l[i++];
if (l != 0)



Re: [PATCH] Remove x86 pcommit instruction

2016-10-05 Thread Andrew Senkevich
> -mpcommit
> -Target Report Mask(ISA_PCOMMIT) Var(ix86_isa_flags) Save
> -Support PCOMMIT instruction.
> -
>
> You should not simply delete a option that was in the released
> compiler, but a warning should be emitted instead. Please see how
> msse5 is handled in i386.opt.

Thank you, it is fixed in patch below. Ok for trunk?

Is it subject for backport for 5.* and 6.* releases?


2016-10-05  Andrew Senkevich  

gcc/

* common/config/i386/i386-common.c (OPTION_MASK_ISA_PCOMMIT_UNSET,
OPTION_MASK_ISA_PCOMMIT_SET): Deleted definitions.
(ix86_handle_option): Deleted handle of OPT_mpcommit.
* config.gcc: Deleted pcommitintrin.h
* config/i386/pcommitintrin.h: Deleted file.
* config/i386/cpuid.h (bit_PCOMMIT): Deleted.
* config/i386/driver-i386.c (host_detect_local_cpu): Deleted pcommit
detection.
* config/i386/i386-c.c (ix86_target_macros_internal): Deleted define
__PCOMMIT__.
* config/i386/i386.c (ix86_target_string): Deleted -mpcommit.
(PTA_PCOMMIT): Deleted define.
(ix86_option_override_internal): Deleted handle of option.
(ix86_valid_target_attribute_inner_p): Deleted pcommit.
* config/i386/i386-builtin.def (IX86_BUILTIN_PCOMMIT,
__builtin_ia32_pcommit): Deleted.
* config/i386/i386.h (TARGET_PCOMMIT, TARGET_PCOMMIT_P): Deleted.
* config/i386/i386.md (unspecv): Deleted UNSPECV_PCOMMIT.
(pcommit): Deleted instruction.
* config/i386/i386.opt: Warning about mpcommit deprecation.
* config/i386/x86intrin.h: Deleted inclusion of pcommitintrin.h.

gcc/testsuite/

* gcc.target/i386/pcommit-1.c: Deleted.
* gcc.target/i386/sse-12.c: Deleted -mpcommit option.
* gcc.target/i386/sse-13.c: Ditto.
* gcc.target/i386/sse-14.c: Ditto.
* gcc.target/i386/sse-22.c: Ditto.
* gcc.target/i386/sse-23.c: Ditto.
* g++.dg/other/i386-2.C: Ditto.
* g++.dg/other/i386-3.C: Ditto.


diff --git a/gcc/common/config/i386/i386-common.c
b/gcc/common/config/i386/i386-common.c
index 4f0a55f..ce1b5f7 100644
--- a/gcc/common/config/i386/i386-common.c
+++ b/gcc/common/config/i386/i386-common.c
@@ -86,7 +86,6 @@ along with GCC; see the file COPYING3.  If not see
 #define OPTION_MASK_ISA_XSAVEC_SET \
   (OPTION_MASK_ISA_XSAVEC | OPTION_MASK_ISA_XSAVE)
 #define OPTION_MASK_ISA_CLWB_SET OPTION_MASK_ISA_CLWB
-#define OPTION_MASK_ISA_PCOMMIT_SET OPTION_MASK_ISA_PCOMMIT

 /* SSE4 includes both SSE4.1 and SSE4.2. -msse4 should be the same
as -msse4.2.  */
@@ -187,7 +186,6 @@ along with GCC; see the file COPYING3.  If not see
 #define OPTION_MASK_ISA_CLFLUSHOPT_UNSET OPTION_MASK_ISA_CLFLUSHOPT
 #define OPTION_MASK_ISA_XSAVEC_UNSET OPTION_MASK_ISA_XSAVEC
 #define OPTION_MASK_ISA_XSAVES_UNSET OPTION_MASK_ISA_XSAVES
-#define OPTION_MASK_ISA_PCOMMIT_UNSET OPTION_MASK_ISA_PCOMMIT
 #define OPTION_MASK_ISA_CLWB_UNSET OPTION_MASK_ISA_CLWB
 #define OPTION_MASK_ISA_MWAITX_UNSET OPTION_MASK_ISA_MWAITX
 #define OPTION_MASK_ISA_CLZERO_UNSET OPTION_MASK_ISA_CLZERO
@@ -933,19 +931,6 @@ ix86_handle_option (struct gcc_options *opts,
}
   return true;

-case OPT_mpcommit:
-  if (value)
-   {
- opts->x_ix86_isa_flags |= OPTION_MASK_ISA_PCOMMIT_SET;
- opts->x_ix86_isa_flags_explicit |= OPTION_MASK_ISA_PCOMMIT_SET;
-   }
-  else
-   {
- opts->x_ix86_isa_flags &= ~OPTION_MASK_ISA_PCOMMIT_UNSET;
- opts->x_ix86_isa_flags_explicit |= OPTION_MASK_ISA_PCOMMIT_UNSET;
-   }
-  return true;
-
 case OPT_mclwb:
   if (value)
{
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 7d24561..8fd07c5 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -373,8 +373,8 @@ i[34567]86-*-*)
   xsavesintrin.h avx512dqintrin.h avx512bwintrin.h
   avx512vlintrin.h avx512vlbwintrin.h avx512vldqintrin.h
   avx512ifmaintrin.h avx512ifmavlintrin.h
avx512vbmiintrin.h
-  avx512vbmivlintrin.h clwbintrin.h pcommitintrin.h
-  mwaitxintrin.h clzerointrin.h pkuintrin.h"
+  avx512vbmivlintrin.h clwbintrin.h mwaitxintrin.h
+  clzerointrin.h pkuintrin.h"
;;
 x86_64-*-*)
cpu_type=i386
@@ -395,8 +395,8 @@ x86_64-*-*)
   xsavesintrin.h avx512dqintrin.h avx512bwintrin.h
   avx512vlintrin.h avx512vlbwintrin.h avx512vldqintrin.h
   avx512ifmaintrin.h avx512ifmavlintrin.h
avx512vbmiintrin.h
-  avx512vbmivlintrin.h clwbintrin.h pcommitintrin.h
-  mwaitxintrin.h clzerointrin.h pkuintrin.h"
+  avx512vbmivlintrin.h clwbintrin.h mwaitxintrin.h
+  clzerointrin.h pkuintrin.h"
;;
 ia64-*-*)
extra_headers=ia64intrin.h
diff --git a/gcc/config/i386/cpuid.h b/gcc/config/i386/cpuid.h
index 4ea3f74..2a946

Re: [Patch, libgfortran] Inquire internal unit within child dtio procedure

2016-10-05 Thread Dominique d'Humières
Dear Jerry,

> Committed as trivial.

Many things are trivial unless noted otherwise! The patch causes the following 
failures:

FAIL: gfortran.dg/inquire_13.f90   -O0  execution test
FAIL: gfortran.dg/inquire_15.f90   -O0  execution test
FAIL: gfortran.dg/inquire_6.f90   -O0  execution test
FAIL: gfortran.dg/inquire_9.f90   -O0  execution test
FAIL: gfortran.dg/large_unit_2.f90   -O0  execution test
FAIL: gfortran.dg/make_unit.f90   -O0  execution test
FAIL: gfortran.dg/negative_unit.f   -O0  execution test
FAIL: gfortran.dg/negative_unit_int8.f   -O0  execution test
FAIL: gfortran.dg/pr20950.f   -O0  execution test

see, e.g., https://gcc.gnu.org/ml/gcc-testresults/2016-10/msg00375.html.

Also the test gfortran.dg/dtio_15.f90 succeeds even with revision r240768 
reverted.

Thanks for working on the issue while waiting for the four character fix!

Dominique



Re: C++ PATCH for C++17 class template placeholders

2016-10-05 Thread Jason Merrill
On Wed, Oct 5, 2016 at 5:29 AM, Marek Polacek  wrote:
> On Wed, Oct 05, 2016 at 08:58:08AM +0200, Marc Glisse wrote:
>> On Tue, 4 Oct 2016, Jason Merrill wrote:
>>
>> > C++17 adds the ability to omit the template arguments for a class
>> > template when declaring a variable with an initializer, much like auto
>> > but supporting a wider variety of initialization.  This is intended to
>> > replace functions like make_tuple.
>>
>> Nice. Is there a macro to test for this feature? I couldn't find it in the
>> latest sg10 list.
>
> And in a similar vein, is there a macro for Selection statements with
> initializer?  Can't find it anywhere.

Not currently, for either.  The rationale for not defining macros for
some features is that for convenience features like this, anyone
concerned about portability will just write code the old way.

Jason


[PATCH][fold-const] Fix native_encode_real for HFmode constants

2016-10-05 Thread Kyrill Tkachov

Hi all,

I encountered a wrong-code issue with my WIP store merging pass when it was 
trying to encode HFmode constants.
I am using native_encode_real to write the constants to a byte array and it's 
breaking on big-endian.
For a 2-byte constant it ended up writing bytes at offsets 3 and 2 rather than 
1 and 0.

The fix in this patch makes the logic in native_encode_real match the logic in 
native_interpret_real,
I just copied the logic across.

I don't have a testcase against clean trunk that demonstrates the issue but 
with my store merging patch
the testcase gcc.target/aarch64/advsimd-intrinsics/vldX.c starts failing 
without this patch because
adjacent 16-bit float constants are not being merged correctly.

Bootstrapped and tested on aarch64-none-linux-gnu.
As this patch only affects the big-endian code path I also tested it on 
aarch64_be-none-elf.

Ok for trunk? Do you think this needs to be backported?

Thanks,
Kyrill

2016-10-05  Kyrylo Tkachov  

* fold-const.c (native_encode_real): Fix logic for selecting offset
to write to when BYTES_BIG_ENDIAN.
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 81671e9fec68a3281b744626db1b94f26d19aabc..564d086e9636743104d629cd6f5620ac2ee6a544 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -7142,7 +7142,16 @@ native_encode_real (const_tree expr, unsigned char *ptr, int len, int off)
 	offset += byte % UNITS_PER_WORD;
 	}
   else
-	offset = BYTES_BIG_ENDIAN ? 3 - byte : byte;
+	{
+	  offset = byte;
+	  if (BYTES_BIG_ENDIAN)
+	{
+	  /* Reverse bytes within each long, or within the entire float
+		 if it's smaller than a long (for HFmode).  */
+	  offset = MIN (3, total_bytes - 1) - offset;
+	  gcc_assert (offset >= 0);
+	}
+	}
   offset = offset + ((bitpos / BITS_PER_UNIT) & ~3);
   if (offset >= off
 	  && offset - off < len)


Re: [BUILDROBOT] Selftest failed for i686-wrs-vxworks

2016-10-05 Thread David Malcolm
On Wed, 2016-10-05 at 14:34 +0200, Thomas Schwinge wrote:
> Hi!
> 
> I've now also run into this issue, during contrib/config-list.mk
> testing;
> log/arm-wrs-vxworks-make.out, log/i686-wrs-vxworks-make.out,
> log/i686-wrs-vxworksae-make.out, log/mips-wrs-vxworks-make.out,
> log/powerpc-wrs-vxworks-make.out, log/powerpc-wrs-vxworksae-make.out,
> log/powerpc-wrs-vxworksmils-make.out, log/sh-wrs-vxworks-make.out,
> log/sparc-wrs-vxworks-make.out:
> 
> [...]/build-multi/arm-wrs-vxworks/./gcc/xgcc -B[...]/build
> -multi/arm-wrs-vxworks/./gcc/ -xc -S -c /dev/null -fself-test
> xgcc: fatal error: environment variable 'WIND_BASE' not defined
> compilation terminated.
> make[2]: *** [s-selftest] Error 1
> [...]
> make[1]: *** [all-gcc] Error 2
> 
> On Thu, 30 Jun 2016 16:09:23 -0400, David Malcolm <
> dmalc...@redhat.com> wrote:
> > On Thu, 2016-06-30 at 08:38 -0400, Nathan Sidwell wrote:
> > > [...] WIND_BASE is expected to point at a vxworks install [...]
> 
> > [...]
> > 
> > Hence it appears that passing "-nostdinc" as a param will avoid the
> > error: [...]
> > 
> > Presumably if you're explicitly building for vxworks you have a
> > vxworks
> > install, so there is a meaningful value to set WIND_BASE to,
> > whereas if
> > you don't have a vxworks install (and are merely building
> > everything as
> > a smoketest), you presumably only want to build the "gcc" subdir,
> > since
> > AFAIK you can't run then driver.
> > 
> > So there are at least 2 ways of fixing this:
> > 
> > (a) add "-nostdinc" when running the selftests i.e. to the
> > invocations
> > of GCC_FOR_TARGET in the "s-selftest" and "selftest-gdb" clauses of
> > gcc/Makefile.in.
> > I've verified that this fixes the issue for --target=i686-wrs
> > -vxworks.
> 
> OK to apply the following two patches?  First, a little bit of
> refactoring:
> 
> commit 0b124fda378c9dc726bd709f805dd52a7dc7c78a
> Author: Thomas Schwinge 
> Date:   Wed Oct 5 08:06:00 2016 +0200
> 
> In gcc/Makefile.in, factor out SELFTEST_FLAGS
> 
>   gcc/
>   * Makefile.in (SELFTEST_FLAGS): New variable.
>   (s-selftest, selftest-gdb, selftest-valgrind): Use it.
> ---
>  gcc/Makefile.in | 11 ---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git gcc/Makefile.in gcc/Makefile.in
> index 15c48bc..08b96a6 100644
> --- gcc/Makefile.in
> +++ gcc/Makefile.in
> @@ -1876,6 +1876,10 @@ endif
>  # This does the things that can't be done on the host machine.
>  rest.cross: specs
>  
> +# GCC's selftests.
> +# Specify a dummy input file to placate the driver.
> +SELFTEST_FLAGS = -x c /dev/null -S -fself-test
> +
>  # Run the selftests during the build once we have a driver and a
> cc1,
>  # so that self-test failures are caught as early as possible.
>  # Use "s-selftest" to ensure that we only run the selftests if the
> @@ -1883,18 +1887,19 @@ rest.cross: specs
>  .PHONY: selftest
>  selftest: s-selftest
>  s-selftest: $(GCC_PASSES) cc1$(exeext) stmp-int-hdrs
> - $(GCC_FOR_TARGET) -xc -S -c /dev/null -fself-test
> + $(GCC_FOR_TARGET) $(SELFTEST_FLAGS)
>   $(STAMP) $@
>  
>  # Convenience method for running selftests under gdb:
>  .PHONY: selftest-gdb
>  selftest-gdb: $(GCC_PASSES) cc1$(exeext) stmp-int-hdrs
> - $(GCC_FOR_TARGET) -xc -S -c /dev/null -fself-test -wrapper
> gdb,--args
> + $(GCC_FOR_TARGET) $(SELFTEST_FLAGS) \
> +   -wrapper gdb,--args
>  
>  # Convenience method for running selftests under valgrind:
>  .PHONY: selftest-valgrind
>  selftest-valgrind: $(GCC_PASSES) cc1$(exeext) stmp-int-hdrs
> - $(GCC_FOR_TARGET) -xc -S -c /dev/null -fself-test \
> + $(GCC_FOR_TARGET) $(SELFTEST_FLAGS) \
> -wrapper valgrind,--leak-check=full
>  
>  # Recompile all the language-independent object files.
> 
> ..., and then the real change:
> 
> commit 8ab49582c42809b385eb957c20b84d21a90e041a
> Author: Thomas Schwinge 
> Date:   Wed Oct 5 08:08:37 2016 +0200
> 
> Make GCC selftests work for *-wrs-vxworks-* targets
> 
>   gcc/
>   Makefile.in (SELFTEST_FLAGS): Add -nostdinc.
> ---
>  gcc/Makefile.in | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git gcc/Makefile.in gcc/Makefile.in
> index 08b96a6..23623ac 100644
> --- gcc/Makefile.in
> +++ gcc/Makefile.in
> @@ -1878,7 +1878,9 @@ rest.cross: specs
>  
>  # GCC's selftests.
>  # Specify a dummy input file to placate the driver.
> -SELFTEST_FLAGS = -x c /dev/null -S -fself-test
> +# Specify -nostdinc to work around missing WIND_BASE environment
> variable
> +# required for *-wrs-vxworks-* targets.
> +SELFTEST_FLAGS = -nostdinc -x c /dev/null -S -fself-test
>  
>  # Run the selftests during the build once we have a driver and a
> cc1,
>  # so that self-test failures are caught as early as possible.

Thanks.  I'm not able to formally approve these changes, but FWIW these
patches look good to me (assuming usual testing).


[PATCH] Non-backwards compatible improvements to std::deque

2016-10-05 Thread Jonathan Wakely

This is a proof-of-concept showing how we can fix some known
deficiencies in std::deque (24693, 77524, throwing moves) for builds
using --enable-symvers=gnu-versioned-namespace, which don't need to
preserve ABI compatibility.

I'm also considering defining an allocator adaptor that would also
enable these fixes, so that std::deque> would
be equivalent to std::deque except that it would enable these
improvements even for the default --enable-symvers=gnu mode.

There should be very little overhead to the extra code, because most
of the new branches depend on compile-time constants.

Are people interested in seeing this for GCC 7?


commit 4db4982f72c14be120b941b3ee8822e1044ab3e5
Author: Jonathan Wakely 
Date:   Tue Oct 4 15:28:21 2016 +0100

Do not allocate memory for empty deques

diff --git a/libstdc++-v3/include/bits/deque.tcc b/libstdc++-v3/include/bits/deque.tcc
index 389e877..e80eb2c 100644
--- a/libstdc++-v3/include/bits/deque.tcc
+++ b/libstdc++-v3/include/bits/deque.tcc
@@ -133,6 +133,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   deque<_Tp, _Alloc>::
   emplace_front(_Args&&... __args)
   {
+	if (!_M_valid_map())
+	  _M_reallocate_map(_Base::_S_initial_map_size, true);
 	if (this->_M_impl._M_start._M_cur != this->_M_impl._M_start._M_first)
 	  {
 	_Alloc_traits::construct(this->_M_impl,
@@ -150,6 +152,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   deque<_Tp, _Alloc>::
   emplace_back(_Args&&... __args)
   {
+	if (!_M_valid_map())
+	  _M_reallocate_map(_Base::_S_initial_map_size, false);
 	if (this->_M_impl._M_finish._M_cur
 	!= this->_M_impl._M_finish._M_last - 1)
 	  {
@@ -903,8 +907,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 deque<_Tp, _Alloc>::
 _M_reallocate_map(size_type __nodes_to_add, bool __add_at_front)
 {
-  const size_type __old_num_nodes
-	= this->_M_impl._M_finish._M_node - this->_M_impl._M_start._M_node + 1;
+  const size_type __old_num_nodes = _M_valid_map()
+	? this->_M_impl._M_finish._M_node - this->_M_impl._M_start._M_node + 1
+: 0;
   const size_type __new_num_nodes = __old_num_nodes + __nodes_to_add;
 
   _Map_pointer __new_nstart;
@@ -931,17 +936,38 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 	  _Map_pointer __new_map = this->_M_allocate_map(__new_map_size);
 	  __new_nstart = __new_map + (__new_map_size - __new_num_nodes) / 2
 	 + (__add_at_front ? __nodes_to_add : 0);
-	  std::copy(this->_M_impl._M_start._M_node,
-		this->_M_impl._M_finish._M_node + 1,
-		__new_nstart);
-	  _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
+  if (_M_valid_map())
+{
+  std::copy(this->_M_impl._M_start._M_node,
+this->_M_impl._M_finish._M_node + 1,
+__new_nstart);
+  _M_deallocate_map(this->_M_impl._M_map,
+this->_M_impl._M_map_size);
+}
+  else
+__try
+  {
+*__new_nstart = this->_M_really_allocate_node();
+  }
+__catch(...)
+  {
+_M_deallocate_map(__new_map, __new_map_size);
+__throw_exception_again;
+  }
 
 	  this->_M_impl._M_map = __new_map;
 	  this->_M_impl._M_map_size = __new_map_size;
 	}
 
   this->_M_impl._M_start._M_set_node(__new_nstart);
-  this->_M_impl._M_finish._M_set_node(__new_nstart + __old_num_nodes - 1);
+  if (__old_num_nodes)
+this->_M_impl._M_finish._M_set_node(__new_nstart + __old_num_nodes - 1);
+  else
+{
+  this->_M_impl._M_finish._M_set_node(__new_nstart);
+  this->_M_impl._M_start._M_cur = this->_M_impl._M_start._M_first;
+  this->_M_impl._M_finish._M_cur = this->_M_impl._M_finish._M_first;
+}
 }
 
   // Overload for deque::iterators, exploiting the "segmented-iterator
diff --git a/libstdc++-v3/include/bits/stl_deque.h b/libstdc++-v3/include/bits/stl_deque.h
index 3b1f8e9..3af3aba 100644
--- a/libstdc++-v3/include/bits/stl_deque.h
+++ b/libstdc++-v3/include/bits/stl_deque.h
@@ -154,7 +154,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 
   iterator
   _M_const_cast() const _GLIBCXX_NOEXCEPT
-  { return iterator(_M_cur, _M_node); }
+  { return _M_cur ? iterator(_M_cur, _M_node) : iterator(); }
 
   reference
   operator*() const _GLIBCXX_NOEXCEPT
@@ -351,6 +351,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 operator-(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
 	  const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
 {
+  if (!__x._M_node && !__y._M_node)
+	return 0;
   return typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
 	(_Deque_iterator<_Tp, _Ref, _Ptr>::_S_buffer_size())
 	* (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
@@ -363,6 +365,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 operator-(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
 	  const _Deque_iterator<_Tp

Re: [RFC] Extend ipa-bitwise-cp with pointer alignment propagation

2016-10-05 Thread Martin Jambor
Hi,

sorry, my main desktop disk has died (a slow but certain) death so I
am not particularly responsive either.

On Tue, Oct 04, 2016 at 12:37:38AM +0530, Prathamesh Kulkarni wrote:
> On 22 September 2016 at 17:26, Jan Hubicka  wrote:
> > Yes, can you please verify that alignments it computes are monotonously
> > worse than those your new code computes and include the removal in the
> > next iteration of the patch?
> >>
> > Otherwise the patch seems fine to me (modulo Richard's comments)


> I tried to verify the alignments are monotonously worse with the
> attached patch (verify.diff),
> which asserts that alignment lattice is not better than bits lattice
> during each propagation
> step in propagate_constants_accross_call().
> Does that look OK ?

After propagation, here should be no TOP lattices anywhere.  That
would mean we have not delteted an unreachable node.  Apart from that,
yes.

> 
> ipa-cp-alignment has better alignments than ipa-bit-cp in following cases:
> 
> a) ipa_get_type() returns NULL: ipa-bits-cp sets lattice to bottom if
> ipa_get_type (param) returns NULL,
> for instance in case of K&R function, while ipa-cp-alignment doesn't

What do you mean by "for instance?"  What are the other cases when it
happens?

> look at param types,
> and can propagate alignments.
> The following assert:
> if (bits_lattice.bottom_p ())
>   gcc_assert (align_lattice.bottom_p())
> 
> triggered for 400.perlbench, 403.gcc, 456.hmmer and 481.wrf due to

that is quite many more examples than I have anticipated, so they all
used K&R?   (But thanks for trying benchmarks diligently).

Have also tried this with LTO?

> ipa_get_type()
> returning NULL. I am not really sure how to handle this case, since we
> need to know parameter's
> type during bits propagation for obtaining precision.
> 
> b) This happens for attached test-case (test.i),
> which is a reduced (and slightly modified) test-case from 458.sjeng.
> Bits propagation sets lattice to bottom, while alignment propagation
> propagates .

yes, I agree we do not need to worry about the case when alignment is 1.

I am only slightly concerned how often ipa_get_type is NULL, so it
would be nice if you looked into those cases once more to make sure
that we do not miss some bug or something that we could handle easily.
But if it is only K&R, I think it is fine.

Thanks,

Martin


Re: [PATCH][fold-const] Fix native_encode_real for HFmode constants

2016-10-05 Thread Bernd Schmidt

On 10/05/2016 04:06 PM, Kyrill Tkachov wrote:

The fix in this patch makes the logic in native_encode_real match the
logic in native_interpret_real,
I just copied the logic across.


Looks reasonable to me. Ok.


Bernd



Re: [BUILDROBOT] Selftest failed for i686-wrs-vxworks

2016-10-05 Thread Bernd Schmidt

On 10/05/2016 04:14 PM, David Malcolm wrote:

Thanks.  I'm not able to formally approve these changes, but FWIW these
patches look good to me (assuming usual testing).


LGTM too, so OK.


Bernd



Re: C++ PATCH for C++17 class template placeholders

2016-10-05 Thread Marc Glisse

On Wed, 5 Oct 2016, Jason Merrill wrote:


On Wed, Oct 5, 2016 at 5:29 AM, Marek Polacek  wrote:

On Wed, Oct 05, 2016 at 08:58:08AM +0200, Marc Glisse wrote:

On Tue, 4 Oct 2016, Jason Merrill wrote:


C++17 adds the ability to omit the template arguments for a class
template when declaring a variable with an initializer, much like auto
but supporting a wider variety of initialization.  This is intended to
replace functions like make_tuple.


Nice. Is there a macro to test for this feature? I couldn't find it in the
latest sg10 list.


And in a similar vein, is there a macro for Selection statements with
initializer?  Can't find it anywhere.


Not currently, for either.  The rationale for not defining macros for
some features is that for convenience features like this, anyone
concerned about portability will just write code the old way.


Thanks. Sadly, this ignores the case of a library that wants to provide an 
explicit deduction guide for its own types to progressive users compiling 
with a C++17 compiler, without preventing C++14 users from using the 
library the old way.


--
Marc Glisse


Re: C++ PATCH for C++17 class template placeholders

2016-10-05 Thread Jason Merrill
On Wed, Oct 5, 2016 at 10:47 AM, Marc Glisse  wrote:
> On Wed, 5 Oct 2016, Jason Merrill wrote:
>> On Wed, Oct 5, 2016 at 5:29 AM, Marek Polacek  wrote:
>>> On Wed, Oct 05, 2016 at 08:58:08AM +0200, Marc Glisse wrote:
 On Tue, 4 Oct 2016, Jason Merrill wrote:

> C++17 adds the ability to omit the template arguments for a class
> template when declaring a variable with an initializer, much like auto
> but supporting a wider variety of initialization.  This is intended to
> replace functions like make_tuple.

 Nice. Is there a macro to test for this feature? I couldn't find it in
 the
 latest sg10 list.
>>>
>>> And in a similar vein, is there a macro for Selection statements with
>>> initializer?  Can't find it anywhere.
>>
>> Not currently, for either.  The rationale for not defining macros for
>> some features is that for convenience features like this, anyone
>> concerned about portability will just write code the old way.
>
> Thanks. Sadly, this ignores the case of a library that wants to provide an
> explicit deduction guide for its own types to progressive users compiling
> with a C++17 compiler, without preventing C++14 users from using the library
> the old way.

True, that's a compelling argument for having a macro for deduction
guides.  I'll propose that to SG10.

Jason


Re: [Patch, libgfortran] Inquire internal unit within child dtio procedure

2016-10-05 Thread Jerry DeLisle

On 10/05/2016 06:47 AM, Dominique d'Humières wrote:

Dear Jerry,


Committed as trivial.


Many things are trivial unless noted otherwise! The patch causes the following 
failures:

FAIL: gfortran.dg/inquire_13.f90   -O0  execution test
FAIL: gfortran.dg/inquire_15.f90   -O0  execution test
FAIL: gfortran.dg/inquire_6.f90   -O0  execution test
FAIL: gfortran.dg/inquire_9.f90   -O0  execution test
FAIL: gfortran.dg/large_unit_2.f90   -O0  execution test
FAIL: gfortran.dg/make_unit.f90   -O0  execution test
FAIL: gfortran.dg/negative_unit.f   -O0  execution test
FAIL: gfortran.dg/negative_unit_int8.f   -O0  execution test
FAIL: gfortran.dg/pr20950.f   -O0  execution test

see, e.g., https://gcc.gnu.org/ml/gcc-testresults/2016-10/msg00375.html.

Also the test gfortran.dg/dtio_15.f90 succeeds even with revision r240768 
reverted.

Thanks for working on the issue while waiting for the four character fix!

Dominique



My haste got me. I did regression test so I must have done something wrong when 
I ran the tests, maybe in the wrong build directory, I only have about 10 of 
them here.


I am pretty sure I know whats wrong so will fix it shortly.

Jerry



Jerry


Re: C++ PATCH for C++17 selection statements with initializer

2016-10-05 Thread Jason Merrill
On Wed, Oct 5, 2016 at 9:14 AM, Marek Polacek  wrote:
> +/* Return true if we're looking at (init; cond), false otherwise.  */
> +
> +static bool
> +cp_parser_init_statement_p (cp_parser *parser)
> +{
> +  unsigned paren_depth = 0;
> +  unsigned brace_depth = 0;

Do we really need another one of these token scanning functions?
Can't you write this in terms of
cp_parser_skip_to_closing_parenthesis?

> +   /* Parse the optional init-statement.  */
> +   tree decl;
> +   cp_lexer_save_tokens (parser->lexer);
> +   const bool init_stmt_p = cp_parser_init_statement_p (parser);
> +   /* Roll back the tokens we skipped.  */
> +   cp_lexer_rollback_tokens (parser->lexer);

The save/rollback should be in the the predicate function, not the caller.

Jason


[committed] Fix a comment

2016-10-05 Thread Jakub Jelinek
Hi!

I've noticed the c_common_reswords table has been changed to use D_CXX11
in 6.x, but the corresponding comment has not been updated (most likely
because of typo in it CXXOX vs. CXX0X.
Also, the -std= options look bogus.

Fixed thusly, committed as obvious to trunk.

2016-10-05  Jakub Jelinek  

* c-common.c (c_common_reswords): Update comment for C++11.

--- gcc/c-family/c-common.c.jj  2016-10-04 13:31:39.0 +0200
+++ gcc/c-family/c-common.c 2016-10-04 16:30:23.542133866 +0200
@@ -411,8 +411,8 @@ static int resort_field_decl_cmp (const
C --std=c89: D_C99 | D_CXXONLY | D_OBJC | D_CXX_OBJC
C --std=c99: D_CXXONLY | D_OBJC
ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
-   C++ --std=c98: D_CONLY | D_CXXOX | D_OBJC
-   C++ --std=c0x: D_CONLY | D_OBJC
+   C++ --std=c++98: D_CONLY | D_CXX11 | D_OBJC
+   C++ --std=c++11: D_CONLY | D_OBJC
ObjC++ is like C++ except that D_OBJC is not set
 
If -fno-asm is used, D_ASM is added to the mask.  If

Jakub


[PATCH] Fix -fsanitize=undefined with PCH (PR sanitizer/66343)

2016-10-05 Thread Jakub Jelinek
Hi!

As mentioned in the PR, ubsan.c uses ASM_GENERATE_INTERNAL_LABEL with
static counters that aren't registered with GC, and those functions can be
called already during parsing, so we can get clashes between labels
created during PCH creation and labels created afterwards.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2016-10-05  Jakub Jelinek  

PR sanitizer/66343
* ubsan.c (ubsan_ids): New GTY(()) array.
(ubsan_type_descriptor, ubsan_create_data): Use ubsan_ids
instead of static local counters.

* gcc.dg/pch/pr66343-1.c: New test.
* gcc.dg/pch/pr66343-1.hs: New file.
* gcc.dg/pch/pr66343-2.c: New test.
* gcc.dg/pch/pr66343-2.hs: New file.

--- gcc/ubsan.c.jj  2016-09-05 09:46:33.0 +0200
+++ gcc/ubsan.c 2016-10-05 11:59:04.650214079 +0200
@@ -314,6 +314,10 @@ get_ubsan_type_info_for_type (tree type)
 return 0;
 }
 
+/* Counters for internal labels.  ubsan_ids[0] for Lubsan_type,
+   ubsan_ids[1] for Lubsan_data labels.  */
+static GTY(()) unsigned int ubsan_ids[2];
+
 /* Helper routine that returns ADDR_EXPR of a VAR_DECL of a type
descriptor.  It first looks into the hash table; if not found,
create the VAR_DECL, put it into the hash table and return the
@@ -461,10 +465,9 @@ ubsan_type_descriptor (tree type, enum u
   TREE_STATIC (str) = 1;
 
   char tmp_name[32];
-  static unsigned int type_var_id_num;
-  ASM_GENERATE_INTERNAL_LABEL (tmp_name, "Lubsan_type", type_var_id_num++);
+  ASM_GENERATE_INTERNAL_LABEL (tmp_name, "Lubsan_type", ubsan_ids[0]++);
   decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (tmp_name),
- dtype);
+dtype);
   TREE_STATIC (decl) = 1;
   TREE_PUBLIC (decl) = 0;
   DECL_ARTIFICIAL (decl) = 1;
@@ -564,8 +567,7 @@ ubsan_create_data (const char *name, int
 
   /* Now, fill in the type.  */
   char tmp_name[32];
-  static unsigned int ubsan_var_id_num;
-  ASM_GENERATE_INTERNAL_LABEL (tmp_name, "Lubsan_data", ubsan_var_id_num++);
+  ASM_GENERATE_INTERNAL_LABEL (tmp_name, "Lubsan_data", ubsan_ids[1]++);
   tree var = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (tmp_name),
 ret);
   TREE_STATIC (var) = 1;
--- gcc/testsuite/gcc.dg/pch/pr66343-1.c.jj 2016-10-05 12:00:38.0 
+0200
+++ gcc/testsuite/gcc.dg/pch/pr66343-1.c2016-10-05 12:30:44.134995415 
+0200
@@ -0,0 +1,15 @@
+/* PR sanitizer/66343 */
+/* { dg-do assemble } */
+/* { dg-options "-fsanitize=undefined" } */
+
+#include "pr66343-1.h"
+
+void
+bar (int a, int b)
+{
+  a / b;
+}
+
+/* Hack to turn off PCH assembly comparison, as it is incompatible
+   with dg-do assemble.  The target condition will be always false.  */
+/* { dg-error "" "" { target { lp64 && { ! lp64 } } } } */
--- gcc/testsuite/gcc.dg/pch/pr66343-1.hs.jj2016-10-05 12:07:27.845784413 
+0200
+++ gcc/testsuite/gcc.dg/pch/pr66343-1.hs   2016-10-05 12:11:25.498754049 
+0200
@@ -0,0 +1,8 @@
+/* PR sanitizer/66343 */
+/* { dg-options "-fsanitize=undefined" } */
+
+void
+foo (int a, int b)
+{
+  a / b;
+}
--- gcc/testsuite/gcc.dg/pch/pr66343-2.c.jj 2016-10-05 12:31:27.569443302 
+0200
+++ gcc/testsuite/gcc.dg/pch/pr66343-2.c2016-10-05 12:31:44.065233616 
+0200
@@ -0,0 +1,10 @@
+/* PR sanitizer/66343 */
+/* { dg-options "-fsanitize=undefined" } */
+
+#include "pr66343-2.h"
+
+void
+bar (int a, int b)
+{
+  a / b;
+}
--- gcc/testsuite/gcc.dg/pch/pr66343-2.hs.jj2016-10-05 12:31:31.452393944 
+0200
+++ gcc/testsuite/gcc.dg/pch/pr66343-2.hs   2016-10-05 12:11:25.0 
+0200
@@ -0,0 +1,8 @@
+/* PR sanitizer/66343 */
+/* { dg-options "-fsanitize=undefined" } */
+
+void
+foo (int a, int b)
+{
+  a / b;
+}

Jakub


Re: [PATCH] Fix -fsanitize=undefined with PCH (PR sanitizer/66343)

2016-10-05 Thread Marek Polacek
On Wed, Oct 05, 2016 at 05:25:23PM +0200, Jakub Jelinek wrote:
> Hi!
> 
> As mentioned in the PR, ubsan.c uses ASM_GENERATE_INTERNAL_LABEL with
> static counters that aren't registered with GC, and those functions can be
> called already during parsing, so we can get clashes between labels
> created during PCH creation and labels created afterwards.
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?

Looks fine but I can't approve.

Marek


[PATCH] Fix -fsanitize=undefined with PCH, part #2 (PR sanitizer/66343)

2016-10-05 Thread Jakub Jelinek
Hi!

When writing test for this PR, I've noticed ICE if the header is compiled
without -fsanitize=undefined, but source is compiled with it.

We had various issues like this in the past, and we handle it by calling
initialize_sanitizer_builtins, which does nothing if the sanitizer bultins
are already created, but after loading PCH (which can kill them) can fix stuff
up again.  I found various spots where the call has been missing in the
ubsan instrumentation, but common feature of all those spots is first
calling ubsan_create_data and only then using builtin_decl_explicit
for the ubsan builtins.  So, this patch puts the initialization call into
that routine, which fixes all uses, and removes the two calls that are now
unnecessary because of that.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-10-05  Jakub Jelinek  

PR sanitizer/66343
* ubsan.c (ubsan_create_data): Call initialize_sanitizer_builtins here.
(ubsan_instrument_float_cast): And not here.

* c-ubsan.c (ubsan_instrument_return): Don't call
initialize_sanitizer_builtins here.

* gcc.dg/pch/pr66343-3.c: New test.
* gcc.dg/pch/pr66343-3.hs: New file.

--- gcc/ubsan.c.jj  2016-10-05 11:59:04.0 +0200
+++ gcc/ubsan.c 2016-10-05 12:52:32.099353026 +0200
@@ -511,6 +511,10 @@ ubsan_create_data (const char *name, int
   size_t i = 0;
   int j;
 
+  /* It is possible that PCH zapped table with definitions of sanitizer
+ builtins.  Reinitialize them if needed.  */
+  initialize_sanitizer_builtins ();
+
   /* Firstly, create a pointer to type descriptor type.  */
   tree td_type = ubsan_get_type_descriptor_type ();
   td_type = build_pointer_type (td_type);
@@ -1589,7 +1593,6 @@ ubsan_instrument_float_cast (location_t
 {
   location_t *loc_ptr = NULL;
   unsigned num_locations = 0;
-  initialize_sanitizer_builtins ();
   /* Figure out if we can propagate location to ubsan_data and use new
  style handlers in libubsan.  */
   if (ubsan_use_new_style_p (loc))
--- gcc/c-family/c-ubsan.c.jj   2016-10-03 16:21:26.0 +0200
+++ gcc/c-family/c-ubsan.c  2016-10-05 12:52:54.623066115 +0200
@@ -233,9 +233,6 @@ ubsan_instrument_return (location_t loc)
 {
   if (flag_sanitize_undefined_trap_on_error)
 return build_call_expr_loc (loc, builtin_decl_explicit (BUILT_IN_TRAP), 0);
-  /* It is possible that PCH zapped table with definitions of sanitizer
- builtins.  Reinitialize them if needed.  */
-  initialize_sanitizer_builtins ();
 
   tree data = ubsan_create_data ("__ubsan_missing_return_data", 1, &loc,
 NULL_TREE, NULL_TREE);
--- gcc/testsuite/gcc.dg/pch/pr66343-3.c.jj 2016-10-05 12:58:35.885719045 
+0200
+++ gcc/testsuite/gcc.dg/pch/pr66343-3.c2016-10-05 12:57:17.600716255 
+0200
@@ -0,0 +1,15 @@
+/* PR sanitizer/66343 */
+/* { dg-do assemble } */
+/* { dg-options "-fsanitize=undefined" } */
+
+#include "pr66343-3.h"
+
+void
+bar (int a, int b)
+{
+  a / b;
+}
+
+/* Hack to turn off PCH assembly comparison, as it is incompatible
+   with dg-do assemble.  The target condition will be always false.  */
+/* { dg-error "" "" { target { lp64 && { ! lp64 } } } } */
--- gcc/testsuite/gcc.dg/pch/pr66343-3.hs.jj2016-10-05 12:45:24.654797897 
+0200
+++ gcc/testsuite/gcc.dg/pch/pr66343-3.hs   2016-10-05 12:56:10.017577142 
+0200
@@ -0,0 +1,4 @@
+/* PR sanitizer/66343 */
+/* { dg-options "-fno-sanitize=undefined" } */
+
+/* Empty.  */

Jakub


Re: [PATCH] Improve target pass registration

2016-10-05 Thread Jakub Jelinek
On Tue, Oct 04, 2016 at 04:54:34PM +0200, Jakub Jelinek wrote:
> > Typo in the comment: duplicated 'after'.
> 
> Will fix.

...

Here is updated patch, bootstrapped/regtested on x86_64-linux and
i686-linux.  I'll still wait a few days before committing to see if somebody
likes to comment on the awk implementation of the script.

2016-10-05  Jakub Jelinek  

* gen-pass-instances.awk: Rewritten.
* Makefile.in (pass-instances.def): Depend on $(PASSES_EXTRA), pass
$(PASSES_EXTRA) after passes.def to the script.
* config/i386/t-i386 (PASSES_EXTRA): Add i386-passes.def.
* config/i386/i386-passes.def: New file.
* config/i386/i386-protos.h (make_pass_insert_vzeroupper,
make_pass_stv): Declare.
* config/i386/i386.c (pass_stv::pass_stv): Initialize timode_p to
false.
(pass_stv::gate): Depending on timode_p member require TARGET_64BIT
or !TARGET_64BIT.
(pass_stv::clone, pass_stv::set_pass_param): New methods.
(pass_stv::timode_p): New non-static data member.
(ix86_option_override): Don't register passes here.

--- gcc/gen-pass-instances.awk.jj   2016-09-29 22:53:10.264776158 +0200
+++ gcc/gen-pass-instances.awk  2016-09-30 13:22:53.745373889 +0200
@@ -17,6 +17,8 @@
 # This Awk script takes passes.def and writes pass-instances.def,
 # counting the instances of each kind of pass, adding an instance number
 # to everywhere that NEXT_PASS is used.
+# Also handle INSERT_PASS_AFTER, INSERT_PASS_BEFORE and REPLACE_PASS
+# directives.
 #
 # For example, the single-instanced pass:
 # NEXT_PASS (pass_warn_unused_result);
@@ -30,81 +32,201 @@
 # through:
 #   NEXT_PASS (pass_copy_prop, 8);
 # (currently there are 8 instances of that pass)
+#
+# INSERT_PASS_AFTER (pass_copy_prop, 1, pass_stv);
+# will insert
+# NEXT_PASS (pass_stv, 1);
+# immediately after the NEXT_PASS (pass_copy_prop, 1) line,
+# similarly INSERT_PASS_BEFORE inserts immediately before that line.
+# REPLACE_PASS (pass_copy_prop, 1, pass_stv, true);
+# will replace NEXT_PASS (pass_copy_prop, 1) line with
+# NEXT_PASS (pass_stv, 1, true);
+# line and renumber all higher pass_copy_prop instances if any.
 
 # Usage: awk -f gen-pass-instances.awk passes.def
 
 BEGIN {
-   print "/* This file is auto-generated by gen-pass-instances.awk";
-   print "   from passes.def.  */";
+  print "/* This file is auto-generated by gen-pass-instances.awk";
+  print "   from passes.def.  */";
+  lineno = 1;
 }
 
-function handle_line()
+function parse_line(line, fnname,  len_of_call, len_of_start,
+   len_of_open, len_of_close,
+   len_of_args, args_start_at,
+   args_str, len_of_prefix,
+   call_starts_at,
+   postfix_starts_at)
 {
-   line = $0;
+  # Find call expression.
+  call_starts_at = match(line, fnname " \\(.+\\)");
+  if (call_starts_at == 0)
+return 0;
+
+  # Length of the call expression.
+  len_of_call = RLENGTH;
+
+  len_of_start = length(fnname " (");
+  len_of_open = length("(");
+  len_of_close = length(")");
+
+  # Find arguments
+  len_of_args = len_of_call - (len_of_start + len_of_close);
+  args_start_at = call_starts_at + len_of_start;
+  args_str = substr(line, args_start_at, len_of_args);
+  split(args_str, args, ",");
+
+  # Find call expression prefix
+  len_of_prefix = call_starts_at - 1;
+  prefix = substr(line, 1, len_of_prefix);
+
+  # Find call expression postfix
+  postfix_starts_at = call_starts_at + len_of_call;
+  postfix = substr(line, postfix_starts_at);
+  return 1;
+}
 
-   # Find call expression.
-   call_starts_at = match(line, /NEXT_PASS \(.+\)/);
-   if (call_starts_at == 0)
-   {
-   print line;
-   return;
-   }
+function adjust_linenos(above, increment,  p, i)
+{
+  for (p in pass_lines)
+if (pass_lines[p] >= above)
+  pass_lines[p] += pass_lines[p];
+  if (increment > 0)
+for (i = lineno - 1; i >= above; i--)
+  lines[i + increment] = lines[i];
+  else
+for (i = above; i < lineno; i++)
+  lines[i + increment] = lines[i];
+  lineno += increment;
+}
 
-   # Length of the call expression.
-   len_of_call = RLENGTH;
+function insert_remove_pass(line, fnname)
+{
+  parse_line($0, fnname);
+  pass_name = args[1];
+  if (pass_name == "PASS")
+return 1;
+  pass_num = args[2] + 0;
+  new_line = prefix "NEXT_PASS (" args[3];
+  if (args[4])
+new_line = new_line ", " args[4];
+  new_line = new_line ")" postfix;
+  if (!pass_lines[pass_name, pass_num])
+{
+  print "ERROR: Can't locate instance of the pass mentioned in " fnname;
+  return 1;
+}
+  return 0;
+}
 
-   len_of_start = length("NEXT_PASS (");
-   len_of_open = length("(");
-   len_of_close = length(")");
-
-   # Find arguments
-   len_o

Re: C++ PATCH for C++17 selection statements with initializer

2016-10-05 Thread Marek Polacek
On Wed, Oct 05, 2016 at 03:31:51PM +0200, Jakub Jelinek wrote:
> On Wed, Oct 05, 2016 at 03:14:25PM +0200, Marek Polacek wrote:
> > This is my attempt to implement P0305R1, Selection statements with 
> > initializer.
> > It allows the users to write
> > 
> >   if (init; cond) // ...
> > 
> > which is equivalent to
> > 
> >   {
> > init
> > if (cond) // ...
> >   }
> 
> Well, it isn't exactly equivalent, because unlike { init; if (cond) /* ... 
> */; }
> there aren't two scopes, but just one.  So I'd say you should have tests

It was basically a quote from the standard.

> that verify that init and cond are indeed in the same scope, e.g. by trying
> something like if (int c = 5; int c = 5) ... and verifying dg-error is
> reported.

This works as expected -- with a "redeclaration" error.  I've added a test.

> > +   case CPP_CLOSE_PAREN:
> > + /* If the next token is a non-nested '(', then we have reached
> > +the end of the if condition.  */
> 
> Looks like typo, shouldn't that be ')' ?

Ah, yes.
 
> Also, do you really need two counters?
> 
> > + if (paren_depth-- == 0)
> > +   return false;
> > + break;
> > +
> > +   case CPP_OPEN_PAREN:
> > + ++paren_depth;
> > + break;
> > +
> > +   case CPP_CLOSE_BRACE:
> > + --brace_depth;
> 
> I mean, shouldn't you also stop before } when seeing if (int a = }; b)
> rather than wrapping around?
 
Ok, one counter seems to work too.  Fixed.

> > +  /* Consume the token.  */
> > +  cp_lexer_consume_token (parser->lexer);
> > +}
> 
> Also, do you really need to consume all the tokens and then rollback, rather
> than just use peek_nth_token with the index increasing in each iteration?

Here I followed cp_parser_compound_literal_p and cp_parser_array_designator_p.
But since I only read token, sure, I can do what you suggest.

Anything else?

Bootstrapped/regtested on x86_64-linux and ppc64-linux, ok for trunk?

2016-10-05  Marek Polacek  

Implement P0305R1, Selection statements with initializer.
* cp-array-notation.c (create_an_loop): Call finish_init_stmt
instead of finish_for_init_stmt.
* cp-tree.h (finish_for_init_stmt): Rename to finish_init_stmt.
* decl.c (poplevel): Adjust a comment.
* init.c (build_vec_init): Call finish_init_stmt instead of
finish_for_init_stmt.
* name-lookup.c (pushdecl_maybe_friend_1): Adjust a comment.
* name-lookup.h (enum scope_kind): Likewise.
* parser.c (cp_parser_statement): Update commentary.
(cp_parser_init_statement_p): New function.
(cp_parser_selection_statement): Parse the optional init-statement.
(cp_parser_for): Call finish_init_stmt instead of finish_for_init_stmt.
(cp_parser_c_for): Likewise.
(cp_convert_range_for): Call finish_init_stmt instead of 
finish_for_init_stmt.
(cp_parser_range_for_member_function): Update commentary.
(cp_parser_iteration_statement):
(cp_parser_for_init_statement): Rename to cp_parser_init_statement.
* pt.c (tsubst_omp_for_iterator): Update commentary.
(tsubst_expr): Call finish_init_stmt instead of finish_for_init_stmt.
* semantics.c (finish_for_init_stmt): Rename to finish_init_stmt.
Update commentary.

* g++.dg/cpp1z/init-statement1.C: New test.
* g++.dg/cpp1z/init-statement2.C: New test.
* g++.dg/cpp1z/init-statement3.C: New test.
* g++.dg/cpp1z/init-statement4.C: New test.
* g++.dg/cpp1z/init-statement5.C: New test.
* g++.dg/cpp1z/init-statement6.C: New test.
* g++.dg/cpp1z/init-statement7.C: New test.
* g++.dg/cpp1z/init-statement8.C: New test.

diff --git gcc/cp/cp-array-notation.c gcc/cp/cp-array-notation.c
index 4687ced..633ab09 100644
--- gcc/cp/cp-array-notation.c
+++ gcc/cp/cp-array-notation.c
@@ -66,7 +66,7 @@ create_an_loop (tree init, tree cond, tree incr, tree body)
 
   finish_expr_stmt (init);
   for_stmt = begin_for_stmt (NULL_TREE, NULL_TREE);
-  finish_for_init_stmt (for_stmt);
+  finish_init_stmt (for_stmt);
   finish_for_cond (cond, for_stmt, false);
   finish_for_expr (incr, for_stmt);
   finish_expr_stmt (body);
diff --git gcc/cp/cp-tree.h gcc/cp/cp-tree.h
index 3fbe1d9..92e4017 100644
--- gcc/cp/cp-tree.h
+++ gcc/cp/cp-tree.h
@@ -6297,7 +6297,7 @@ extern void finish_do_stmt(tree, 
tree, bool);
 extern tree finish_return_stmt (tree);
 extern tree begin_for_scope(tree *);
 extern tree begin_for_stmt (tree, tree);
-extern void finish_for_init_stmt   (tree);
+extern void finish_init_stmt   (tree);
 extern void finish_for_cond(tree, tree, bool);
 extern void finish_for_expr(tree, tree);
 extern void finish_for_stmt(tree);
diff --git gcc/cp/decl.c gcc/cp/decl.c
index 6646062..6a08d8f 100644
--- gcc/cp/decl.c
+++ gcc/cp/decl.c
@@ 

Re: C++ PATCH for C++17 selection statements with initializer

2016-10-05 Thread Marek Polacek
On Wed, Oct 05, 2016 at 10:48:19AM -0400, Jason Merrill wrote:
> On Wed, Oct 5, 2016 at 9:14 AM, Marek Polacek  wrote:
> > +/* Return true if we're looking at (init; cond), false otherwise.  */
> > +
> > +static bool
> > +cp_parser_init_statement_p (cp_parser *parser)
> > +{
> > +  unsigned paren_depth = 0;
> > +  unsigned brace_depth = 0;
> 
> Do we really need another one of these token scanning functions?
> Can't you write this in terms of
> cp_parser_skip_to_closing_parenthesis?
> 
> > +   /* Parse the optional init-statement.  */
> > +   tree decl;
> > +   cp_lexer_save_tokens (parser->lexer);
> > +   const bool init_stmt_p = cp_parser_init_statement_p (parser);
> > +   /* Roll back the tokens we skipped.  */
> > +   cp_lexer_rollback_tokens (parser->lexer);
> 
> The save/rollback should be in the the predicate function, not the caller.

How about the version I just posted, i.e.
?

Marek


Re: [PATCH] - improve sprintf buffer overflow detection (middle-end/49905)

2016-10-05 Thread Joseph Myers
On Tue, 4 Oct 2016, Martin Sebor wrote:

> > Well, typically cases where one of long and int is passed and the other is
> > expected, but they have the same size, are bugs waiting to happen when the
> > code is built on a 64-bit system.  That is, they *should* warn.
> 
> Typically, yes.  In the case of wchar_t (or int) and wint_t I don't
> think it's helpful.  Consider this case from my comment #5 on bug
> 72858.  I don't think there is any point in issuing a warning here.
> On the majority of targets they either all are or promote to a type
> of the same size, don't they?

I'm unconvinced by that "majority of targets" of argument (which once 
would have been true for int and long, and you could say it is true for 
long and size_t).  There's a clear correct type here, and it's wint_t, and 
it's always easy to fix the code to use the correct type.

-- 
Joseph S. Myers
jos...@codesourcery.com


[PATCH 01/16] read-md.c: Add various cleanups to ~rtx_reader

2016-10-05 Thread David Malcolm
Various global data items relating to reading .md files are
currently initialized in rtx_reader::read_md_files, and are
not cleaned up.

The selftests for the RTL frontend require supporting multiple
reader instances being alive one after another in-process, so
this lack of cleanup would become a leak.

To fix this, this patch moves these initializations to the
rtx_reader constructor, and adds matching cleanups to the destructor,
along with a cleanup of m_base_dir.

gcc/ChangeLog:
* read-md.c (rtx_reader::rtx_reader): Move initializations
of various global data from rtx_reader::read_md_files to here.
(rtx_reader::~rtx_reader): Clean up m_base_dir, and various
global data.
(rtx_reader::read_md_files): Move initializations of various
global data from here to the ctor.
---
 gcc/read-md.c | 49 +++--
 1 file changed, 35 insertions(+), 14 deletions(-)

diff --git a/gcc/read-md.c b/gcc/read-md.c
index e158be5..1a13916 100644
--- a/gcc/read-md.c
+++ b/gcc/read-md.c
@@ -925,12 +925,47 @@ rtx_reader::rtx_reader ()
 {
   /* Set the global singleton pointer.  */
   rtx_reader_ptr = this;
+
+  /* Initialize global data.  */
+  obstack_init (&string_obstack);
+  ptr_locs = htab_create (161, leading_ptr_hash, leading_ptr_eq_p, 0);
+  obstack_init (&ptr_loc_obstack);
+  joined_conditions = htab_create (161, leading_ptr_hash, leading_ptr_eq_p, 0);
+  obstack_init (&joined_conditions_obstack);
+  md_constants = htab_create (31, leading_string_hash,
+ leading_string_eq_p, (htab_del) 0);
+  enum_types = htab_create (31, leading_string_hash,
+   leading_string_eq_p, (htab_del) 0);
+
+  /* Unlock the stdio streams.  */
+  unlock_std_streams ();
 }
 
 /* rtx_reader's destructor.  */
 
 rtx_reader::~rtx_reader ()
 {
+  free (m_base_dir);
+
+  /* Clean up global data.  */
+  htab_delete (enum_types);
+  enum_types = NULL;
+
+  htab_delete (md_constants);
+  md_constants = NULL;
+
+  obstack_free (&joined_conditions_obstack, NULL);
+
+  htab_delete (joined_conditions);
+  joined_conditions = NULL;
+
+  obstack_free (&ptr_loc_obstack, NULL);
+
+  htab_delete (ptr_locs);
+  ptr_locs = NULL;
+
+  obstack_free (&string_obstack, NULL);
+
   /* Clear the global singleton pointer.  */
   rtx_reader_ptr = NULL;
 }
@@ -1105,20 +1140,6 @@ rtx_reader::read_md_files (int argc, const char **argv,
   bool already_read_stdin;
   int num_files;
 
-  /* Initialize global data.  */
-  obstack_init (&string_obstack);
-  ptr_locs = htab_create (161, leading_ptr_hash, leading_ptr_eq_p, 0);
-  obstack_init (&ptr_loc_obstack);
-  joined_conditions = htab_create (161, leading_ptr_hash, leading_ptr_eq_p, 0);
-  obstack_init (&joined_conditions_obstack);
-  md_constants = htab_create (31, leading_string_hash,
- leading_string_eq_p, (htab_del) 0);
-  enum_types = htab_create (31, leading_string_hash,
-   leading_string_eq_p, (htab_del) 0);
-
-  /* Unlock the stdio streams.  */
-  unlock_std_streams ();
-
   /* First we loop over all the options.  */
   for (i = 1; i < argc; i++)
 if (argv[i][0] == '-')
-- 
1.8.5.3



[PATCH 02/16] (approved) Add selftest::read_file

2016-10-05 Thread David Malcolm
Jeff: "Seems reasonable.  Install when you have a need."

This is used later in the kit by the selftests for final.c

gcc/ChangeLog:
* selftest.c (selftest::read_file): New function.
(selftest::test_read_file): New function.
(selftest::selftest_c_tests): Call test_read_file.
* selftest.h (selftest::read_file): New decl.
---
 gcc/selftest.c | 60 ++
 gcc/selftest.h |  7 +++
 2 files changed, 67 insertions(+)

diff --git a/gcc/selftest.c b/gcc/selftest.c
index 0db69d2..cf7031f 100644
--- a/gcc/selftest.c
+++ b/gcc/selftest.c
@@ -151,6 +151,53 @@ temp_source_file::temp_source_file (const location &loc,
   fclose (out);
 }
 
+/* Read the contents of PATH into memory, returning a 0-terminated buffer
+   that must be freed by the caller.
+   Fail (and abort) if there are any problems, with LOC as the reported
+   location of the failure.  */
+
+char *
+read_file (const location &loc, const char *path)
+{
+  FILE *f_in = fopen (path, "r");
+  if (!f_in)
+fail_formatted (loc, "unable to open file: %s", path);
+
+  /* Read content, allocating FIXME.  */
+  char *result = NULL;
+  size_t total_sz = 0;
+  size_t alloc_sz = 0;
+  char buf[4096];
+  size_t iter_sz_in;
+
+  while ( (iter_sz_in = fread (buf, 1, sizeof (buf), f_in)) )
+{
+  gcc_assert (alloc_sz >= total_sz);
+  size_t old_total_sz = total_sz;
+  total_sz += iter_sz_in;
+  /* Allow 1 extra byte for 0-termination.  */
+  if (alloc_sz < (total_sz + 1))
+   {
+ size_t new_alloc_sz = alloc_sz ? alloc_sz * 2: total_sz + 1;
+ result = (char *)xrealloc (result, new_alloc_sz);
+ alloc_sz = new_alloc_sz;
+   }
+  memcpy (result + old_total_sz, buf, iter_sz_in);
+}
+
+  if (!feof (f_in))
+fail_formatted (loc, "error reading from %s: %s", path,
+   xstrerror (errno));
+
+  fclose (f_in);
+
+  /* 0-terminate the buffer.  */
+  gcc_assert (total_sz < alloc_sz);
+  result[total_sz] = '\0';
+
+  return result;
+}
+
 /* Selftests for the selftest system itself.  */
 
 /* Sanity-check the ASSERT_ macros with various passing cases.  */
@@ -181,6 +228,18 @@ test_named_temp_file ()
   fclose (f);
 }
 
+/* Verify read_file (and also temp_source_file).  */
+
+static void
+test_read_file ()
+{
+  temp_source_file t (SELFTEST_LOCATION, "test1.s",
+ "\tjmp\t.L2\n");
+  char *buf = read_file (SELFTEST_LOCATION, t.get_filename ());
+  ASSERT_STREQ ("\tjmp\t.L2\n", buf);
+  free (buf);
+}
+
 /* Run all of the selftests within this file.  */
 
 void
@@ -188,6 +247,7 @@ selftest_c_tests ()
 {
   test_assertions ();
   test_named_temp_file ();
+  test_read_file ();
 }
 
 } // namespace selftest
diff --git a/gcc/selftest.h b/gcc/selftest.h
index 3938560..e5f5c60 100644
--- a/gcc/selftest.h
+++ b/gcc/selftest.h
@@ -146,6 +146,13 @@ class line_table_test
 extern void
 for_each_line_table_case (void (*testcase) (const line_table_case &));
 
+/* Read the contents of PATH into memory, returning a 0-terminated buffer
+   that must be freed by the caller.
+   Fail (and abort) if there are any problems, with LOC as the reported
+   location of the failure.  */
+
+extern char *read_file (const location &loc, const char *path);
+
 /* Declarations for specific families of tests (by source file), in
alphabetical order.  */
 extern void bitmap_c_tests ();
-- 
1.8.5.3



[PATCH 03/16] (approved) selftest.h: add temp_override fixture

2016-10-05 Thread David Malcolm
Jeff: "When you need it, this is fine."

We have a lot of global state in our code.  Ideally we'd reduce the
amount of such global state, but a prerequisite for sane refactoring
is having automated testing in place to ensure that the refactoring
doesn't break anything.

However, the global state itself makes it hard to write such automated
testing.

To break this Catch-22, this patch introduces a class temp_override,
for temporarily assigning a value to a global variable, saving the old
value, and then restoring that old value in a dtor.

gcc/ChangeLog:
* selftest.h (selftest::temp_override): New class.
---
 gcc/selftest.h | 29 +
 1 file changed, 29 insertions(+)

diff --git a/gcc/selftest.h b/gcc/selftest.h
index e5f5c60..4c50217 100644
--- a/gcc/selftest.h
+++ b/gcc/selftest.h
@@ -153,6 +153,35 @@ for_each_line_table_case (void (*testcase) (const 
line_table_case &));
 
 extern char *read_file (const location &loc, const char *path);
 
+/* A fixture for temporarily overriding a global variable with a new
+   value.  The original value of the variable is captured in the ctor,
+   and restored in the dtor.  */
+
+template 
+class temp_override
+{
+ public:
+  temp_override (T& var, T new_value)
+  : m_var (var),
+/* Record the current value of VAR.  */
+m_old_value (var)
+  {
+/* Set the var to the new value.  */
+m_var = new_value;
+  }
+
+  ~temp_override ()
+  {
+/* Restore the value of the variable to that stored in the
+   ctor.  */
+m_var = m_old_value;
+  }
+
+ private:
+  T& m_var;
+  T m_old_value;
+};
+
 /* Declarations for specific families of tests (by source file), in
alphabetical order.  */
 extern void bitmap_c_tests ();
-- 
1.8.5.3



[PATCH 07/16] read-md: add some helper functions

2016-10-05 Thread David Malcolm
Add some functions for use by the RTL frontend.

gcc/ChangeLog:
* read-md.c (require_char): New function.
(require_word_ws): New function.
(peek_char): New function.
* read-md.h (peek_char): New decl.
(require_char): New decl.
(require_word_ws): New decl.
---
 gcc/read-md.c | 31 +++
 gcc/read-md.h |  4 
 2 files changed, 35 insertions(+)

diff --git a/gcc/read-md.c b/gcc/read-md.c
index 1a13916..1bbf408 100644
--- a/gcc/read-md.c
+++ b/gcc/read-md.c
@@ -364,6 +364,16 @@ read_skip_spaces (void)
 }
 }
 
+/* Consume the next character, issuing a fatal error if it is not
+   EXPECTED.  */
+
+void require_char (char expected)
+{
+  int ch = read_char ();
+  if (ch != expected)
+fatal_expected_char (expected, ch);
+}
+
 /* Consume any whitespace, then consume the next non-whitespace
character, issuing a fatal error if it is not EXPECTED.  */
 
@@ -375,6 +385,17 @@ require_char_ws (char expected)
 fatal_expected_char (expected, ch);
 }
 
+/* Consume any whitespace, then consume the next word (as per read_name),
+   issuing a fatal error if it is not EXPECTED.  */
+
+void require_word_ws (const char *expected)
+{
+  struct md_name name;
+  read_name (&name);
+  if (strcmp (name.string, expected))
+fatal_with_file_and_line ("missing '%s'", expected);
+}
+
 /* Read the next character from the file.  */
 
 int
@@ -410,6 +431,16 @@ rtx_reader::unread_char (int ch)
   ungetc (ch, m_read_md_file);
 }
 
+/* Peek at the next character from the file without consuming it.  */
+
+int
+peek_char (void)
+{
+  int ch = read_char ();
+  unread_char (ch);
+  return ch;
+}
+
 /* Read an rtx code name into NAME.  It is terminated by any of the
punctuation chars of rtx printed syntax.  */
 
diff --git a/gcc/read-md.h b/gcc/read-md.h
index a74cc72..88d2d4f 100644
--- a/gcc/read-md.h
+++ b/gcc/read-md.h
@@ -194,6 +194,8 @@ unread_char (int ch)
   rtx_reader_ptr->unread_char (ch);
 }
 
+extern int peek_char (void);
+
 extern hashval_t leading_string_hash (const void *);
 extern int leading_string_eq_p (const void *, const void *);
 extern void copy_md_ptr_loc (const void *, const void *);
@@ -209,7 +211,9 @@ extern void fatal_with_file_and_line (const char *, ...)
   ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN;
 extern void fatal_expected_char (int, int) ATTRIBUTE_NORETURN;
 extern int read_skip_spaces (void);
+extern void require_char (char expected);
 extern void require_char_ws (char expected);
+extern void require_word_ws (const char *expected);
 extern void read_name (struct md_name *);
 extern char *read_quoted_string (void);
 extern char *read_string (int);
-- 
1.8.5.3



[PATCH 00/16] RTL frontend (v3)

2016-10-05 Thread David Malcolm
This patch kit is v3 of the RTL frontend.  For reference, the earlier
versions were:

v1 (2016-05-04):
  "[PATCH 0/4] RFC: RTL frontend"
https://gcc.gnu.org/ml/gcc-patches/2016-05/msg00352.html
  
v2 (2016-09-08):
  "[PATCH 0/9] RFC: selftests based on RTL dumps"
https://gcc.gnu.org/ml/gcc-patches/2016-09/msg00483.html

The patch kit is based on top of r240740 (2016-10-04).

What's new in v3:

* The input file format is now the output format of the recently-added
  "print_rtx_function", which emits CFG and crtl information.  The
  code can now parse that new information and reconstruct it.
  The CFG info is optional when parsing, to make it easier to
  edit and create input RTL "by hand".
  (patch 10 in the kit).

* This version adds back in the "rtl1" frontend, and "rtl.dg" in
  the testsuite, capable of running individual passes on RTL dumps.
  (patch 15 in the kit).

* Added an rtl-frontend.texi to the gccint docs (patch 15), which
  contains additional high-level information.

* This version also implements Richi's idea of using the C frontend:
  tagging C functions with "__RTL", and then being able to supply an
  RTL dump as the body of the function.  This allows for more
  interesting decls and types in test cases.
  (patch 16 in the kit).

  There are thus three forms of dump-reading in this kit:
(a) selftests that read a .rtl file,
(b) rtl.dg tests that read a .rtl file, and
(c) rtl.dg tests that read a .c file
  all built on top of class function_reader (and thus sharing most of
  their code).

* Previously all of the various dumps in selftests were string
  fragments in the pass .c files; they've now been moved to .rtl files
  and .c files below the "gcc/testsuite" subdirectory (to
  "gcc/testsuite/selftest" and to "gcc/testsuite/rtl.dg").  Tests
  have been moved to target-specific subdirectories where appropriate.

* I've split out lots of preliminary material from the bigger patches
  (hence this is a 16-patch kit, but hopefully this is easier as a whole
  to digest).

* Rewrote how pseudos get renumbered (see rtl-frontend.texi in patch 15
  for details).

* Much of the unpleasantness of reading the print_rtx format has been
  reduced and contained, by moving the special-case handling of operand
  parsing to read-rtl-function.c, and splitting it out into a collection
  of short routines, rather than one big one.

* I dropped source locations from the parser for now, for the sake of
  simplicity (which means dropping the roundtrip.exp part of rtl.dg).

* Fixed an auto-dependency problem that prevented bootstrap.

* Added a run-one-rtl-pass.c/h (patch 15), to encapsulate the hacks
  that appear to be necessary to do this (for rtl1 and for
  cc1's __RTL mode).

* Added a prototype of an RTL interpreter, a kind of "valgrind for RTL"
  (patch 14) to show how this work could enable such a thing.  This
  patch is more just an idea than a real implementation at this point.

* More test cases

The patch kit (as a whole) bootstraps and passes regression testing,
on x86_64-pc-linux-gnu, at least, adding a new rtl.sum with 46 PASSes
and 2 unsupported; stage 1 builds and passes selftesting and check-rtl
for target aarch64-linux-gnu.

I'm working on doing a full test across all our supported targets (and
there are likely some target-specific failures in there at the moment).

There are still some FIXMEs, TODOs and #if 0 in there, but I thought
it was worth posting to check that this is moving in the right
direction.

Thoughts?
Dave

David Malcolm (16):
  read-md.c: Add various cleanups to ~rtx_reader
  (approved) Add selftest::read_file
  (approved) selftest.h: add temp_override fixture
  (approved) Expose forcibly_ggc_collect and run it after all selftests
  Introduce rtl_data::init_stack_alignment
  Introduce emit_status::ensure_regno_capacity
  read-md: add some helper functions
  (partially-approved): Introduce selftest::locate_file
  Split class rtx_reader into base_rtx_reader vs rtx_reader
  Introduce class function_reader (v3)
  df selftests (v3)
  combine.c selftests (v2)
  cse.c selftests
  RTL interpreter (work-in-progress)
  RTL frontend (rtl1), on top of dump reader
  Add "__RTL" to cc1

 gcc/Makefile.in|   14 +-
 gcc/c-family/c-common.c|1 +
 gcc/c-family/c-common.h|3 +
 gcc/c/c-parser.c   |  102 +-
 gcc/cfgexpand.c|5 +-
 gcc/combine.c  |  121 +
 gcc/common.opt |6 +-
 gcc/cse.c  |   70 +
 gcc/df-core.c  |   73 +
 gcc/doc/rtl-frontend.texi  |  262 +++
 gcc/doc/rtl.texi   |3 +
 gcc/emit-rtl.c |   57 +-
 gcc/emit-rtl.h |2 +

[PATCH 09/16] Split class rtx_reader into base_rtx_reader vs rtx_reader

2016-10-05 Thread David Malcolm
This moves read_rtx and friends into rtx_reader, and splits
rtx_reader into two classes:

class base_rtx_reader: has responsibility for reading chars, managing
include files, top-level directives etc.  It is the read-md.o part.

class rtx_reader, a subclass, has the code for reading hierarchical
rtx expressions using the format codes.   It is the read-rtl.o part.

This split is needed by a followup patch, which converts
read_rtx_operand to a virtual function of rtx_reader.  To do this,
instances of rtx_reader (or its subclasses) need a vtable, which
needs to include a ptr to the code in read-rtl.o.  Splitting it up
allows the gen* tools that currently purely use read-md.o to continue
to do so.

gcc/ChangeLog:
* genpreds.c (write_tm_constrs_h): Update for renaming of
rtx_reader_ptr to base_rtx_reader_ptr.
(write_tm_preds_h): Likewise.
(write_insn_preds_c): Likewise.
* read-md.c (rtx_reader_ptr): Rename to...
(base_rtx_reader_ptr): ...this, and convert
from an rtx_reader * to a base_rtx_reader *.
(fatal_with_file_and_line): Update for renaming of
rtx_reader_ptr to base_rtx_reader_ptr.
(rtx_reader::read_char): Rename to...
(base_rtx_reader::read_char):... this.
(rtx_reader::unread_char): Rename to...
(base_rtx_reader::unread_char):... this.
(read_escape): Update for renaming of rtx_reader_ptr to
base_rtx_reader_ptr.
(read_braced_string): Likewise.
(read_string): Likewise.
(rtx_reader::rtx_reader): Rename to...
(base_rtx_reader::base_rtx_reader): ...this, and update for
renaming of rtx_reader_ptr to base_rtx_reader_ptr.
(rtx_reader::~rtx_reader): Rename to...
(base_rtx_reader::~base_rtx_reader): ...this, and update for
renaming of rtx_reader_ptr to base_rtx_reader_ptr.
(rtx_reader::handle_include): Rename to...
(base_rtx_reader::handle_include): ...this.
(rtx_reader::handle_file): Rename to...
(base_rtx_reader::handle_file): ...this.
(rtx_reader::handle_toplevel_file): Rename to...
(base_rtx_reader::handle_toplevel_file): ...this.
(rtx_reader::get_current_location): Rename to...
(base_rtx_reader::get_current_location): ...this.
(rtx_reader::add_include_path): Rename to...
(base_rtx_reader::add_include_path): ...this.
(rtx_reader::read_md_files): Rename to...
(base_rtx_reader::read_md_files): ...this.
* read-md.h (struct enum_type {): Likewise.
(class rtx_reader): Split into...
(class base_rtx_reader): ...new class.
(rtx_reader_ptr): Rename to...
(base_rtx_reader_ptr): ...this, and convert to a
base_rtx_reader *.
(class noop_reader): Update base class to be base_rtx_reader.
(class rtx_reader): Reintroduce as a subclass of base_rtx_reader.
(rtx_reader_ptr): Reintroduce as a rtx_reader *.
(read_char): Update for renaming of rtx_reader_ptr to
base_rtx_reader_ptr.
(unread_char): Likewise.
* read-rtl.c (rtx_reader_ptr): New global.
(read_rtx): Use rtx_reader_ptr when calling read_rtx_code.
(read_rtx_code): Convert to...
(rtx_reader::read_rtx_code): ...this method.
(read_rtx_operand): Convert to...
(rtx_reader::read_rtx_operand): ...this method, eliminating use of
rtx_reader_ptr singleton.  Convert return type from void to rtx,
and return input.
(read_nested_rtx): Convert to...
(rtx_reader::read_nested_rtx): ...this method.
(read_rtx_variadic): Convert to...
(rtx_reader::read_rtx_variadic): ...this method.
(rtx_reader::rtx_reader): New ctor.
(rtx_reader::~rtx_reader): New dtor.
---
 gcc/genpreds.c |  6 +++---
 gcc/read-md.c  | 54 --
 gcc/read-md.h  | 53 +++--
 gcc/read-rtl.c | 48 +---
 4 files changed, 107 insertions(+), 54 deletions(-)

diff --git a/gcc/genpreds.c b/gcc/genpreds.c
index 6db1b7b..a9092da 100644
--- a/gcc/genpreds.c
+++ b/gcc/genpreds.c
@@ -1205,7 +1205,7 @@ write_tm_constrs_h (void)
   printf ("\
 /* Generated automatically by the program '%s'\n\
from the machine description file '%s'.  */\n\n", progname,
- rtx_reader_ptr->get_top_level_filename ());
+ base_rtx_reader_ptr->get_top_level_filename ());
 
   puts ("\
 #ifndef GCC_TM_CONSTRS_H\n\
@@ -1405,7 +1405,7 @@ write_tm_preds_h (void)
   printf ("\
 /* Generated automatically by the program '%s'\n\
from the machine description file '%s'.  */\n\n", progname,
- rtx_reader_ptr->get_top_level_filename ());
+ base_rtx_reader_ptr->get_top_level_filename ());
 
   puts ("\
 #ifndef GCC_TM_PREDS_H\n\
@@ -1555,7 +1555,7 @@ write_insn_preds_c (void)
   printf ("\
 /* Generated automatically by the 

[PATCH 08/16] (partially-approved): Introduce selftest::locate_file

2016-10-05 Thread David Malcolm
Jeff:
> I do think we should go ahead and plan for a target subdirectory.  With
> that added, this should be OK once dependencies are in.

Loading RTL dumps from files rather than embedding them as strings
in the source requires a way to locate the relevant files.

This patch adds a selftest::locate_file function for locating such
files, relative to "$(SRCDIR)/gcc/testsuite/selftests".  This is
done via a new argument to -fself-test, which supplies the current
value of "$(SRCDIR)/gcc" to cc1.

I chose "$(SRCDIR)/gcc/testsuite/selftests", so as to be below
gcc/testsuite, but not below any of the existing DejaGnu subdirectories,
to avoid selftest-specific files from being picked up by .exp globbing
patterns.

(Depends on the approved-when-needed
  "[PATCH 2/9] Add selftest::read_file"
https://gcc.gnu.org/ml/gcc-patches/2016-09/msg00476.html ).

gcc/ChangeLog:
* Makefile.in (s-selftest) Add $(srcdir) as an argument of
-fself-test.
(selftest-gdb): Likewise.
(selftest-valgrind): Likewise.
* common.opt (fself-test): Rename to...
(fself-test=): ...this, documenting the meaning of the argument.
* selftest-run-tests.c: Include "options.h".
(selftest::run_tests): Initialize selftest::path_to_src_gcc from
flag_self_test.
* selftest.c (selftest::path_to_src_gcc): New global.
(selftest::locate_file): New function.
(selftest::test_locate_file): New function.
(selftest::selftest_c_tests): Call test_locate_file.
* selftest.h (selftest::locate_file): New decl.
(selftest::path_to_src_gcc): New decl.

gcc/testsuite/ChangeLog:
* gcc.dg/cpp/pr71591.c: Add a fake value for the argument of
-fself-test.
* selftests/example.txt: New file.
---
 gcc/Makefile.in |  7 ---
 gcc/common.opt  |  6 +++---
 gcc/selftest-run-tests.c|  7 +++
 gcc/selftest.c  | 28 
 gcc/selftest.h  | 10 ++
 gcc/testsuite/gcc.dg/cpp/pr71591.c  |  2 +-
 gcc/testsuite/selftests/example.txt |  1 +
 7 files changed, 54 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/selftests/example.txt

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 15c48bc..4b50f0b 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1883,18 +1883,19 @@ rest.cross: specs
 .PHONY: selftest
 selftest: s-selftest
 s-selftest: $(GCC_PASSES) cc1$(exeext) stmp-int-hdrs
-   $(GCC_FOR_TARGET) -xc -S -c /dev/null -fself-test
+   $(GCC_FOR_TARGET) -xc -S -c /dev/null -fself-test=$(srcdir)
$(STAMP) $@
 
 # Convenience method for running selftests under gdb:
 .PHONY: selftest-gdb
 selftest-gdb: $(GCC_PASSES) cc1$(exeext) stmp-int-hdrs
-   $(GCC_FOR_TARGET) -xc -S -c /dev/null -fself-test -wrapper gdb,--args
+   $(GCC_FOR_TARGET) -xc -S -c /dev/null -fself-test=$(srcdir) \
+ -wrapper gdb,--args
 
 # Convenience method for running selftests under valgrind:
 .PHONY: selftest-valgrind
 selftest-valgrind: $(GCC_PASSES) cc1$(exeext) stmp-int-hdrs
-   $(GCC_FOR_TARGET) -xc -S -c /dev/null -fself-test \
+   $(GCC_FOR_TARGET) -xc -S -c /dev/null -fself-test=$(srcdir) \
  -wrapper valgrind,--leak-check=full
 
 # Recompile all the language-independent object files.
diff --git a/gcc/common.opt b/gcc/common.opt
index 3425c19..c3cf4c2 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2106,9 +2106,9 @@ fselective-scheduling2
 Common Report Var(flag_selective_scheduling2) Optimization
 Run selective scheduling after reload.
 
-fself-test
-Common Undocumented Var(flag_self_test)
-Run self-tests.
+fself-test=
+Common Undocumented Joined Var(flag_self_test)
+Run self-tests, using the given path to locate test files.
 
 fsel-sched-pipelining
 Common Report Var(flag_sel_sched_pipelining) Init(0) Optimization
diff --git a/gcc/selftest-run-tests.c b/gcc/selftest-run-tests.c
index 54a9b0f..ecc3d71 100644
--- a/gcc/selftest-run-tests.c
+++ b/gcc/selftest-run-tests.c
@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "selftest.h"
 #include "tree.h"
 #include "langhooks.h"
+#include "options.h"
 
 /* This function needed to be split out from selftest.c as it references
tests from the whole source tree, and so is within
@@ -37,6 +38,12 @@ along with GCC; see the file COPYING3.  If not see
 void
 selftest::run_tests ()
 {
+  /* Makefile.in has -fself-test=$(srcdir), so that flag_self_test
+ contains the path to the "gcc" subdirectory of the source tree
+ (without a trailing slash).  Copy it up to path_to_src_gcc, to
+ avoid selftest.c depending on option-handling.  */
+  path_to_src_gcc = flag_self_test;
+
   long start_time = get_run_time ();
 
   /* Run all the tests, in hand-coded order of (approximate) dependencies:
diff --git a/gcc/selftest.c b/gcc/selftest.c
index cf7031f..2a481ad 100644
--- a/gcc/selftest.c
+++ b/gcc/selftest.c
@@ -1

[PATCH 06/16] Introduce emit_status::ensure_regno_capacity

2016-10-05 Thread David Malcolm
gcc/ChangeLog:
* emit-rtl.c (gen_reg_rtx): Move regno_pointer_align and
regno_reg_rtx resizing logic to...
(emit_status::ensure_regno_capacity): ...this new method.
(init_emit): Allocate regno_reg_rtx using ggc_cleared_vec_alloc
rather than ggc_vec_alloc.
* function.h (emit_status::ensure_regno_capacity): New method.
---
 gcc/emit-rtl.c | 45 ++---
 gcc/function.h |  2 ++
 2 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index fdfc790..12bdbb0 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -1056,29 +1056,35 @@ gen_reg_rtx (machine_mode mode)
   /* Do not call gen_reg_rtx with uninitialized crtl.  */
   gcc_assert (crtl->emit.regno_pointer_align_length);
 
-  /* Make sure regno_pointer_align, and regno_reg_rtx are large
- enough to have an element for this pseudo reg number.  */
+  int cur_size = crtl->emit.regno_pointer_align_length;
+  if (reg_rtx_no == cur_size)
+crtl->emit.ensure_regno_capacity (cur_size * 2);
 
-  if (reg_rtx_no == crtl->emit.regno_pointer_align_length)
-{
-  int old_size = crtl->emit.regno_pointer_align_length;
-  char *tmp;
-  rtx *new1;
+  val = gen_raw_REG (mode, reg_rtx_no);
+  regno_reg_rtx[reg_rtx_no++] = val;
+  return val;
+}
+
+/* Make sure m_regno_pointer_align, and regno_reg_rtx are large
+   enough to have elements in the range 0 <= idx < NEW_SIZE.  */
+
+void
+emit_status::ensure_regno_capacity (int new_size)
+{
+  if (new_size < regno_pointer_align_length)
+return;
 
-  tmp = XRESIZEVEC (char, crtl->emit.regno_pointer_align, old_size * 2);
-  memset (tmp + old_size, 0, old_size);
-  crtl->emit.regno_pointer_align = (unsigned char *) tmp;
+  int old_size = regno_pointer_align_length;
 
-  new1 = GGC_RESIZEVEC (rtx, regno_reg_rtx, old_size * 2);
-  memset (new1 + old_size, 0, old_size * sizeof (rtx));
-  regno_reg_rtx = new1;
+  char *tmp = XRESIZEVEC (char, regno_pointer_align, new_size);
+  memset (tmp + old_size, 0, new_size - old_size);
+  regno_pointer_align = (unsigned char *) tmp;
 
-  crtl->emit.regno_pointer_align_length = old_size * 2;
-}
+  rtx *new1 = GGC_RESIZEVEC (rtx, regno_reg_rtx, new_size);
+  memset (new1 + old_size, 0, (new_size - old_size) * sizeof (rtx));
+  regno_reg_rtx = new1;
 
-  val = gen_raw_REG (mode, reg_rtx_no);
-  regno_reg_rtx[reg_rtx_no++] = val;
-  return val;
+  crtl->emit.regno_pointer_align_length = new_size;
 }
 
 /* Return TRUE if REG is a PARM_DECL, FALSE otherwise.  */
@@ -5667,7 +5673,8 @@ init_emit (void)
   crtl->emit.regno_pointer_align
 = XCNEWVEC (unsigned char, crtl->emit.regno_pointer_align_length);
 
-  regno_reg_rtx = ggc_vec_alloc (crtl->emit.regno_pointer_align_length);
+  regno_reg_rtx =
+ggc_cleared_vec_alloc (crtl->emit.regno_pointer_align_length);
 
   /* Put copies of all the hard registers into regno_reg_rtx.  */
   memcpy (regno_reg_rtx,
diff --git a/gcc/function.h b/gcc/function.h
index 590a490..db9f4ea 100644
--- a/gcc/function.h
+++ b/gcc/function.h
@@ -34,6 +34,8 @@ struct GTY(()) sequence_stack {
 };
 
 struct GTY(()) emit_status {
+  void ensure_regno_capacity (int new_size);
+
   /* This is reset to LAST_VIRTUAL_REGISTER + 1 at the start of each function.
  After rtl generation, it is 1 plus the largest register number used.  */
   int x_reg_rtx_no;
-- 
1.8.5.3



[PATCH 05/16] Introduce rtl_data::init_stack_alignment

2016-10-05 Thread David Malcolm
Move this part of "expand"'s initialization of crtl into its own
method so that it can used by the RTL frontend when postprocessing
RTL dumps.

gcc/ChangeLog:
* cfgexpand.c (pass_expand::execute): Move stack initializations
to rtl_data::init_stack_alignment and call it.
* emit-rtl.c (rtl_data::init_stack_alignment): New method.
* emit-rtl.h (rtl_data::init_stack_alignment): New method.
---
 gcc/cfgexpand.c |  5 +
 gcc/emit-rtl.c  | 12 
 gcc/emit-rtl.h  |  2 ++
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index 4190f7f..70dfe34 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -6218,10 +6218,7 @@ pass_expand::execute (function *fun)
   discover_nonconstant_array_refs ();
 
   targetm.expand_to_rtl_hook ();
-  crtl->stack_alignment_needed = STACK_BOUNDARY;
-  crtl->max_used_stack_slot_alignment = STACK_BOUNDARY;
-  crtl->stack_alignment_estimated = 0;
-  crtl->preferred_stack_boundary = STACK_BOUNDARY;
+  crtl->init_stack_alignment ();
   fun->cfg->max_jumptable_ents = 0;
 
   /* Resovle the function section.  Some targets, like ARM EABI rely on 
knowledge
diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index 2d6d1eb..fdfc790 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -6285,5 +6285,17 @@ need_atomic_barrier_p (enum memmodel model, bool pre)
   gcc_unreachable ();
 }
 }
+
+/* Initialize fields of rtl_data related to stack alignment.  */
+
+void
+rtl_data::init_stack_alignment ()
+{
+  stack_alignment_needed = STACK_BOUNDARY;
+  max_used_stack_slot_alignment = STACK_BOUNDARY;
+  stack_alignment_estimated = 0;
+  preferred_stack_boundary = STACK_BOUNDARY;
+}
+
 
 #include "gt-emit-rtl.h"
diff --git a/gcc/emit-rtl.h b/gcc/emit-rtl.h
index 52c72b1..663b4a0 100644
--- a/gcc/emit-rtl.h
+++ b/gcc/emit-rtl.h
@@ -55,6 +55,8 @@ struct GTY(()) incoming_args {
 
 /* Datastructures maintained for currently processed function in RTL form.  */
 struct GTY(()) rtl_data {
+  void init_stack_alignment ();
+
   struct expr_status expr;
   struct emit_status emit;
   struct varasm_status varasm;
-- 
1.8.5.3



[PATCH 11/16] df selftests (v3)

2016-10-05 Thread David Malcolm
Changes since v2:
* moved dump from a string literal to an external file
* update for addition of selftest::location to rtl_dump_test
* remove debug prints

gcc/ChangeLog:
* df-core.c: Include selftest.h and selftest-rtl.h.
(selftest::dataflow_test::dataflow_test): New ctor.
(selftest::dataflow_test::~dataflow_test): New dtor.
(selftest::test_df_single_set): New function.
(selftest::df_core_c_tests): New function.
* selftest-run-tests.c (selftest::run_tests): Call it.
* selftest.h (selftest::df_core_c_tests): New decl.

gcc/testsuite/ChangeLog:
* selftests/single-set.rtl: New file.
---
 gcc/df-core.c  | 73 ++
 gcc/selftest-run-tests.c   |  1 +
 gcc/selftest.h |  1 +
 gcc/testsuite/selftests/single-set.rtl |  5 +++
 4 files changed, 80 insertions(+)
 create mode 100644 gcc/testsuite/selftests/single-set.rtl

diff --git a/gcc/df-core.c b/gcc/df-core.c
index e531d58..2c8ccba 100644
--- a/gcc/df-core.c
+++ b/gcc/df-core.c
@@ -384,6 +384,8 @@ are write-only operations.
 #include "cfganal.h"
 #include "tree-pass.h"
 #include "cfgloop.h"
+#include "selftest.h"
+#include "selftest-rtl.h"
 
 static void *df_get_bb_info (struct dataflow *, unsigned int);
 static void df_set_bb_info (struct dataflow *, unsigned int, void *);
@@ -2482,3 +2484,74 @@ debug_df_chain (struct df_link *link)
   df_chain_dump (link, stderr);
   fputc ('\n', stderr);
 }
+
+#if CHECKING_P
+
+namespace selftest {
+
+/* dataflow_test's constructor.  Initialize df.  */
+
+dataflow_test::dataflow_test ()
+{
+  rest_of_handle_df_initialize ();
+}
+
+/* dataflow_test's destructor.  Clean up df.  */
+
+dataflow_test::~dataflow_test ()
+{
+  rest_of_handle_df_finish ();
+}
+
+/* Verify df_note on a trivial function.  */
+
+void
+test_df_single_set ()
+{
+  rtl_dump_test t (SELFTEST_LOCATION, locate_file ("single-set.rtl"));
+
+  dataflow_test dftest;
+
+  df_note_add_problem ();
+  df_analyze ();
+  df_finish_pass (false);
+
+  rtx_insn *insn = get_insn_by_uid (1);
+
+  ASSERT_NE (NULL, REG_NOTES (insn));
+  rtx_expr_list *note0 = as_a  (REG_NOTES (insn));
+
+  rtx_expr_list *note1 = note0->next ();
+  ASSERT_NE (NULL, note1);
+
+  ASSERT_EQ (NULL, note1->next ());
+
+  ASSERT_EQ (SET_SRC (PATTERN (insn)), note0->element ());
+  ASSERT_EQ (REG_DEAD, REG_NOTE_KIND (note0));
+
+  ASSERT_EQ (SET_DEST (PATTERN (insn)), note1->element ());
+  ASSERT_EQ (REG_UNUSED, REG_NOTE_KIND (note1));
+
+  struct df_lr_bb_info *bb_info = df_lr_get_bb_info (2);
+  ASSERT_NE (NULL, bb_info);
+
+  /* "r100 = r101;" so we should have a use of r101.  */
+  ASSERT_FALSE (bitmap_bit_p (&bb_info->use, t.effective_regno (100)));
+  ASSERT_TRUE (bitmap_bit_p (&bb_info->use, t.effective_regno (101)));
+
+  /* ...and a def of r100.  */
+  ASSERT_TRUE (bitmap_bit_p (&bb_info->def, t.effective_regno (100)));
+  ASSERT_FALSE (bitmap_bit_p (&bb_info->def, t.effective_regno (101)));
+}
+
+/* Run all of the selftests within this file.  */
+
+void
+df_core_c_tests ()
+{
+  test_df_single_set ();
+}
+
+} // namespace selftest
+
+#endif /* #if CHECKING_P */
diff --git a/gcc/selftest-run-tests.c b/gcc/selftest-run-tests.c
index 1dce665..5c95aaa 100644
--- a/gcc/selftest-run-tests.c
+++ b/gcc/selftest-run-tests.c
@@ -71,6 +71,7 @@ selftest::run_tests ()
   gimple_c_tests ();
   rtl_tests_c_tests ();
   read_rtl_function_c_tests ();
+  df_core_c_tests ();
 
   /* Higher-level tests, or for components that other selftests don't
  rely on.  */
diff --git a/gcc/selftest.h b/gcc/selftest.h
index ae39101..0033942 100644
--- a/gcc/selftest.h
+++ b/gcc/selftest.h
@@ -200,6 +200,7 @@ extern const char *path_to_src_gcc;
 /* Declarations for specific families of tests (by source file), in
alphabetical order.  */
 extern void bitmap_c_tests ();
+extern void df_core_c_tests ();
 extern void diagnostic_c_tests ();
 extern void diagnostic_show_locus_c_tests ();
 extern void edit_context_c_tests ();
diff --git a/gcc/testsuite/selftests/single-set.rtl 
b/gcc/testsuite/selftests/single-set.rtl
new file mode 100644
index 000..d72015f
--- /dev/null
+++ b/gcc/testsuite/selftests/single-set.rtl
@@ -0,0 +1,5 @@
+(function "test"
+  (insn-chain
+ (insn 1 0 0 2 (set (reg:SI 100) (reg:SI 101)) -1 (nil))
+  ) ;; insn-chain
+) ;; function
-- 
1.8.5.3



[PATCH 04/16] (approved) Expose forcibly_ggc_collect and run it after all selftests

2016-10-05 Thread David Malcolm
Jeff:
> Seems reasonable and doesn't depend on earlier patches, right?
> Assuming that's correct it seems fine for the trunk whenever you want to
> install it.

gcc/ChangeLog:
* ggc-tests.c (forcibly_ggc_collect): Rename to...
(selftest::forcibly_ggc_collect): ...this, and remove "static".
(test_basic_struct): Update for above renaming.
(test_length): Likewise.
(test_union): Likewise.
(test_finalization): Likewise.
(test_deletable_global): Likewise.
(test_inheritance): Likewise.
(test_chain_next): Likewise.
(test_user_struct): Likewise.
(test_tree_marking): Likewise.
* selftest-run-tests.c (selftest::run_tests): Call
selftest::forcibly_ggc_collect at the end of the selftests.
* selftest.h (selftest::forcibly_ggc_collect): New decl.
---
 gcc/ggc-tests.c  | 28 ++--
 gcc/selftest-run-tests.c |  6 ++
 gcc/selftest.h   |  5 +
 3 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/gcc/ggc-tests.c b/gcc/ggc-tests.c
index 7f97231..b9cd276 100644
--- a/gcc/ggc-tests.c
+++ b/gcc/ggc-tests.c
@@ -27,19 +27,19 @@ along with GCC; see the file COPYING3.  If not see
 
 #if CHECKING_P
 
-/* The various GTY markers must be outside of a namespace to be seen by
-   gengtype, so we don't put this file within the selftest namespace.  */
-
 /* A helper function for writing ggc tests.  */
 
-static void
-forcibly_ggc_collect ()
+void
+selftest::forcibly_ggc_collect ()
 {
   ggc_force_collect = true;
   ggc_collect ();
   ggc_force_collect = false;
 }
 
+/* The various GTY markers must be outside of a namespace to be seen by
+   gengtype, so we don't put this file within the selftest namespace.  */
+
 
 
 /* Verify that a simple struct works, and that it can
@@ -58,7 +58,7 @@ test_basic_struct ()
   root_test_struct = ggc_cleared_alloc  ();
   root_test_struct->other = ggc_cleared_alloc  ();
 
-  forcibly_ggc_collect ();
+  selftest::forcibly_ggc_collect ();
 
   ASSERT_TRUE (ggc_marked_p (root_test_struct));
   ASSERT_TRUE (ggc_marked_p (root_test_struct->other));
@@ -88,7 +88,7 @@ test_length ()
   for (int i = 0; i < count; i++)
 root_test_of_length->elem[i] = ggc_cleared_alloc  ();
 
-  forcibly_ggc_collect ();
+  selftest::forcibly_ggc_collect ();
 
   ASSERT_TRUE (ggc_marked_p (root_test_of_length));
   for (int i = 0; i < count; i++)
@@ -162,7 +162,7 @@ test_union ()
   test_struct *referenced_by_other = ggc_cleared_alloc  ();
   other->m_ptr = referenced_by_other;
 
-  forcibly_ggc_collect ();
+  selftest::forcibly_ggc_collect ();
 
   ASSERT_TRUE (ggc_marked_p (root_test_of_union_1));
   ASSERT_TRUE (ggc_marked_p (ts));
@@ -202,7 +202,7 @@ test_finalization ()
 
   test_struct_with_dtor::dtor_call_count = 0;
 
-  forcibly_ggc_collect ();
+  selftest::forcibly_ggc_collect ();
 
   /* Verify that the destructor was run for each instance.  */
   ASSERT_EQ (count, test_struct_with_dtor::dtor_call_count);
@@ -220,7 +220,7 @@ test_deletable_global ()
   test_of_deletable = ggc_cleared_alloc  ();
   ASSERT_TRUE (test_of_deletable != NULL);
 
-  forcibly_ggc_collect ();
+  selftest::forcibly_ggc_collect ();
 
   ASSERT_EQ (NULL, test_of_deletable);
 }
@@ -293,7 +293,7 @@ test_inheritance ()
   test_some_subclass_as_base_ptr = new some_subclass ();
   test_some_other_subclass_as_base_ptr = new some_other_subclass ();
 
-  forcibly_ggc_collect ();
+  selftest::forcibly_ggc_collect ();
 
   /* Verify that the roots and everything referenced by them got marked
  (both for fields in the base class and those in subclasses).  */
@@ -372,7 +372,7 @@ test_chain_next ()
   tail_node = new_node;
 }
 
-  forcibly_ggc_collect ();
+  selftest::forcibly_ggc_collect ();
 
   /* If we got here, we survived.  */
 
@@ -439,7 +439,7 @@ test_user_struct ()
 
   num_calls_to_user_gt_ggc_mx = 0;
 
-  forcibly_ggc_collect ();
+  selftest::forcibly_ggc_collect ();
 
   ASSERT_TRUE (ggc_marked_p (root_user_struct_ptr));
   ASSERT_TRUE (ggc_marked_p (referenced));
@@ -457,7 +457,7 @@ test_tree_marking ()
 {
   dummy_unittesting_tree = build_int_cst (integer_type_node, 1066);
 
-  forcibly_ggc_collect ();
+  selftest::forcibly_ggc_collect ();
 
   ASSERT_TRUE (ggc_marked_p (dummy_unittesting_tree));
 }
diff --git a/gcc/selftest-run-tests.c b/gcc/selftest-run-tests.c
index d9d3ea1..54a9b0f 100644
--- a/gcc/selftest-run-tests.c
+++ b/gcc/selftest-run-tests.c
@@ -80,6 +80,12 @@ selftest::run_tests ()
   /* Run any lang-specific selftests.  */
   lang_hooks.run_lang_selftests ();
 
+  /* Force a GC at the end of the selftests, to shake out GC-related
+ issues.  For example, if any GC-managed items have buggy (or missing)
+ finalizers, this last collection will ensure that things that were
+ failed to be finalized can be detected by valgrind.  */
+  forcibly_ggc_collect ();
+
   /* Finished running tests.  */
   long finish_time = get_run_time ();
   long elapsed_ti

[PATCH 16/16] Add "__RTL" to cc1

2016-10-05 Thread David Malcolm
This patch implements Richi's idea of having a custom __RTL marker
in C function definitions, to indicate that the body of the function
is to be parsed as RTL, rather than C:

int __RTL test_fn_1 (int i)
{
 (function "times_two"
   (insn-chain
 (note 1 0 4 (nil) NOTE_INSN_DELETED)
 ;; etc
   ) ;; insn-chain
   (crtl
 (return_rtx
   (reg/i:SI 0 ax)
 ) ;; return_rtx
   ) ;; crtl
  ) ;; function
}

This allows for decls and types to be declared in C, and to use
the function decl from the C frontend.

I added support for running a single pass by giving __RTL an optional
parameter (the name of the pass).  For example:

int __RTL ("rtl-dfinit") test_fn_2 (int i)
{
 (function "times_two"
   (insn-chain
 (note 1 0 4 (nil) NOTE_INSN_DELETED)
 ;; etc
   ) ;; insn-chain
   (crtl
 (return_rtx
   (reg/i:SI 0 ax)
 ) ;; return_rtx
   ) ;; crtl
  ) ;; function
}

The top-level "function" directive is rather redundant; perhaps it should
be omitted?  This would give e.g.:

int __RTL ("rtl-dfinit") test_fn_3 (int i)
{
   (insn-chain
 (note 1 0 4 (nil) NOTE_INSN_DELETED)
 ;; etc
   ) ;; insn-chain
   (crtl
 (return_rtx
   (reg/i:SI 0 ax)
 ) ;; return_rtx
   ) ;; crtl
}

(Though maybe we want to keep it as a place to hold top-level metadata)

gcc/c-family/ChangeLog:
* c-common.c (c_common_reswords): Add "__RTL".
* c-common.h (enum rid): Add RID_RTL.

gcc/c/ChangeLog:
* c-parser.c: Include "read-rtl-function.h" and
"run-one-rtl-pass.h".
(c_parser_declaration_or_fndef): Handle "__RID" by calling
c_parser_parse_rtl_body.  Convert a timevar_push/pop pair
to an auto_timevar, to cope with early exit.
(c_parser_parse_rtl_body): New function.

gcc/ChangeLog:
* read-md.c (base_rtx_reader::read_char): Support filtering
the input to a subset of line numbers.
(base_rtx_reader::base_rtx_reader): Initialize fields
m_first_line and m_last_line.
(base_rtx_reader::read_file_fragment): New method.
* read-md.h (base_rtx_reader::read_file_fragment): New decl.
(base_rtx_reader::m_first_line): New field.
(base_rtx_reader::m_last_line): New field.
* read-rtl-function.c (function_reader::create_function): Only create
cfun if it doesn't already exist.
(read_rtl_function_body_from_file_range): New function.
* read-rtl-function.h (read_rtl_function_body_from_file_range):
New decl.

gcc/testsuite/ChangeLog:
* rtl.dg/rtl.exp: Add .c files below rtl.dg to "tests".
* rtl.dg/x86_64/different-structs.c: New file.
* rtl.dg/x86_64/test-return-const.c.after-expand.c: New file.
* rtl.dg/x86_64/test-return-const.c.before-fwprop.c: New file.
* rtl.dg/x86_64/test-rtl.c: New file.
* rtl.dg/x86_64/times-two.c.after-expand.c: New file.
* rtl.dg/x86_64/times-two.c.before-df.c: New file.
---
 gcc/c-family/c-common.c|   1 +
 gcc/c-family/c-common.h|   3 +
 gcc/c/c-parser.c   | 102 -
 gcc/read-md.c  |  34 ++-
 gcc/read-md.h  |   7 ++
 gcc/read-rtl-function.c|  78 
 gcc/read-rtl-function.h|   3 +
 gcc/testsuite/rtl.dg/rtl.exp   |   4 +-
 gcc/testsuite/rtl.dg/x86_64/different-structs.c| 101 
 .../x86_64/test-return-const.c.after-expand.c  |  23 +
 .../x86_64/test-return-const.c.before-fwprop.c |  27 ++
 gcc/testsuite/rtl.dg/x86_64/test-rtl.c |  95 +++
 .../rtl.dg/x86_64/times-two.c.after-expand.c   |  40 
 .../rtl.dg/x86_64/times-two.c.before-df.c  |  57 
 14 files changed, 554 insertions(+), 21 deletions(-)
 create mode 100644 gcc/testsuite/rtl.dg/x86_64/different-structs.c
 create mode 100644 
gcc/testsuite/rtl.dg/x86_64/test-return-const.c.after-expand.c
 create mode 100644 
gcc/testsuite/rtl.dg/x86_64/test-return-const.c.before-fwprop.c
 create mode 100644 gcc/testsuite/rtl.dg/x86_64/test-rtl.c
 create mode 100644 gcc/testsuite/rtl.dg/x86_64/times-two.c.after-expand.c
 create mode 100644 gcc/testsuite/rtl.dg/x86_64/times-two.c.before-df.c

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 491c637..ecef32b 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -524,6 +524,7 @@ const struct c_common_resword c_common_reswords[] =
   { "__underlying_type", RID_UNDERLYING_TYPE, D_CXXONLY },
   { "__volatile",  RID_VOLATILE,   0 },
   { "__volatile__",RID_VOLATILE,   0 },
+  { "__RTL",   RID_RTL,0 },
   { "alignas", RID_ALIGNAS,D_CXXONLY | D_CXX11 | D_CXXWARN },
   { "alignof", RID_ALIGNOF,D_CXXONLY | D_CXX11 | D_CXXWARN },
   { "asm", R

[PATCH 12/16] combine.c selftests (v2)

2016-10-05 Thread David Malcolm
Changed in v2:
* moved dumps from a string literal to external files (sharing
a dump with read-rtl-function.c)
* update for addition of selftest::location to rtl_dump_test

gcc/ChangeLog:
* combine.c: Include selftest.h and selftest-rtl.h.
(try_combine): Add assertion on this_basic_block.
(class selftest::combine_test): New subclass of
selftest::tl_dump_test.
(selftest::combine_test::combine_test): New ctor.
(selftest::test_combining_shifts): New function.
(selftest::test_non_combinable_shifts): New function.
(selftest::combine_c_tests): New function.
* selftest-run-tests.c (selftest::run_tests): Run
selftest::combine_c_tests.
* selftest.h (selftest::combine_c_tests): New decl.

gcc/testsuite/ChangeLog:
* selftests/non-combinable-shifts.rtl: New file.
---
 gcc/combine.c | 121 ++
 gcc/selftest-run-tests.c  |   1 +
 gcc/selftest.h|   1 +
 gcc/testsuite/selftests/non-combinable-shifts.rtl |  18 
 4 files changed, 141 insertions(+)
 create mode 100644 gcc/testsuite/selftests/non-combinable-shifts.rtl

diff --git a/gcc/combine.c b/gcc/combine.c
index b27aae5..ad1655e 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -102,6 +102,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "valtrack.h"
 #include "rtl-iter.h"
 #include "print-rtl.h"
+#include "selftest.h"
+#include "selftest-rtl.h"
 
 #ifndef LOAD_EXTEND_OP
 #define LOAD_EXTEND_OP(M) UNKNOWN
@@ -2625,6 +2627,8 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, 
rtx_insn *i0,
   rtx new_other_notes;
   int i;
 
+  gcc_assert (this_basic_block);
+
   /* Immediately return if any of I0,I1,I2 are the same insn (I3 can
  never be).  */
   if (i1 == i2 || i0 == i2 || (i0 && i0 == i1))
@@ -14443,3 +14447,120 @@ make_pass_combine (gcc::context *ctxt)
 {
   return new pass_combine (ctxt);
 }
+
+#if CHECKING_P
+
+namespace selftest {
+
+/* A subclass of rtl_dump_test for testing combine.c.  */
+
+class combine_test : public rtl_dump_test
+{
+ public:
+  combine_test (const location &loc, char *path);
+
+ private:
+   dataflow_test m_df_test;
+};
+
+/* combine_test's constructor.  Read dumped RTL function from PATH,
+   taking ownership of PATH.
+   Initialize df and perform dataflow analysis.  */
+
+combine_test::combine_test (const location &loc, char *path)
+: rtl_dump_test (loc, path),
+  m_df_test ()
+{
+  /* The dataflow instance should have been created by m_df_test's ctor.  */
+  gcc_assert (df);
+
+  /* From rest_of_handle_combine.  */
+  df_set_flags (/*DF_LR_RUN_DCE + */ DF_DEFER_INSN_RESCAN);
+  df_note_add_problem ();
+  df_analyze ();
+}
+
+/* Verify that combine_instructions works, for combining a pair of shifts.
+   Ideally we'd test try_combine by itself, but a fair amount of
+   refactoring would be needed to do so.  */
+
+static void
+test_combining_shifts ()
+{
+  combine_test t (SELFTEST_LOCATION, locate_file ("asr_div1.rtl"));
+
+  rtx_insn *insn_8 = get_insn_by_uid (8);
+  ASSERT_TRUE (insn_8);
+
+  rtx_insn *insn_9 = get_insn_by_uid (9);
+  ASSERT_TRUE (insn_9);
+
+  int rebuild_jump_labels_after_combine
+= combine_instructions (get_insns (), max_reg_num ());
+  ASSERT_FALSE (rebuild_jump_labels_after_combine);
+
+  /* Verify that insns 8 and 9 were combined.  */
+  ASSERT_EQ (1, combine_merges);
+
+  /* insn 8 should now be deleted.  */
+  ASSERT_EQ (NOTE, GET_CODE (insn_8));
+  ASSERT_EQ (NOTE_INSN_DELETED, NOTE_KIND (insn_8));
+
+  /* insn 9 should now be a shift of 35.
+ On aarch64 it's a set; on x86_64 it's a parallel of a set and a clobber
+ of CC.  */
+  rtx set_in_9 = single_set (insn_9);
+  ASSERT_TRUE (set_in_9);
+  rtx src_of_9 = SET_SRC (set_in_9);
+  ASSERT_EQ (ASHIFTRT, GET_CODE (src_of_9));
+  rtx amt = XEXP (src_of_9, 1);
+  ASSERT_TRUE (CONST_INT_P (amt));
+  ASSERT_EQ (35, INTVAL (amt));
+}
+
+/* Test of failing to combine instructions.
+
+   Similar to test_combining_shifts, but with the input register
+   for the 2nd shift hand-edited (from 78 to 80) so that it doesn't come
+   from the output of the 1st shift, so that the shifts should *not*
+   be combinable.  */
+
+static void
+test_non_combinable_shifts ()
+{
+  combine_test t (SELFTEST_LOCATION, locate_file 
("non-combinable-shifts.rtl"));
+
+  rtx_insn *insn_8 = get_insn_by_uid (8);
+  ASSERT_TRUE (insn_8);
+
+  rtx_insn *insn_9 = get_insn_by_uid (9);
+  ASSERT_TRUE (insn_9);
+
+  int rebuild_jump_labels_after_combine
+= combine_instructions (get_insns (), max_reg_num ());
+  ASSERT_FALSE (rebuild_jump_labels_after_combine);
+
+  /* Verify that no insns were combined.  */
+  ASSERT_EQ (0, combine_merges);
+
+  /* insn 8 should not have be touched.  */
+  ASSERT_EQ (INSN, GET_CODE (insn_8));
+}
+
+/* Run all of the selftests within this file.  */
+
+void
+combine_c_tests ()
+{
+  /* Only run these tests for i386.  */

[PATCH 13/16] cse.c selftests

2016-10-05 Thread David Malcolm
Changed in v2:
* move test dumps into external files
* update for addition of selftest::location to rtl_dump_test

Blurb from v1:

This patch uses rtl_dump_test to start building out a test suite
for cse.

I attempted to create a reproducer for PR 71779; however I'm not yet
able to replicate the bogus cse reported there via the test case.

gcc/ChangeLog:
* cse.c: Include selftest.h and selftest-rtl.h.
(selftest::test_simple_cse): New function.
(selftest::test_pr71779): New function.
(selftest::cse_c_tests): New function.
* selftest-run-tests.c (selftest::run_tests): Call
selftest::cse_c_tests.
* selftest.h (selftest::cse_c_tests): New decl.

gcc/testsuite/ChangeLog:
* selftests/pr71779.rtl: New file.
* selftests/simple-cse.rtl: New file.
---
 gcc/cse.c  | 70 ++
 gcc/selftest-run-tests.c   |  1 +
 gcc/selftest.h |  1 +
 gcc/testsuite/selftests/pr71779.rtl| 39 +++
 gcc/testsuite/selftests/simple-cse.rtl | 12 ++
 5 files changed, 123 insertions(+)
 create mode 100644 gcc/testsuite/selftests/pr71779.rtl
 create mode 100644 gcc/testsuite/selftests/simple-cse.rtl

diff --git a/gcc/cse.c b/gcc/cse.c
index 7069fab..96beb68 100644
--- a/gcc/cse.c
+++ b/gcc/cse.c
@@ -41,6 +41,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-pass.h"
 #include "dbgcnt.h"
 #include "rtl-iter.h"
+#include "selftest.h"
+#include "selftest-rtl.h"
 
 #ifndef LOAD_EXTEND_OP
 #define LOAD_EXTEND_OP(M) UNKNOWN
@@ -7773,3 +7775,71 @@ make_pass_cse_after_global_opts (gcc::context *ctxt)
 {
   return new pass_cse_after_global_opts (ctxt);
 }
+
+#if CHECKING_P
+
+namespace selftest {
+
+/* Selftests for CSE.  */
+
+/* Simple test of eliminating a redundant (reg + 1) computation
+   i.e. that:
+ r101 = r100 + 1;
+ r102 = r100 + 1; <<< common subexpression
+ *r103 = r101 * r102;
+   can be CSE-ed to:
+ r101 = r100 + 1;
+ r102 = r101; <<< replaced
+ *r103 = r101 * r102;
+   by cse_main.  */
+
+static void
+test_simple_cse ()
+{
+  /* Only run this tests for i386.  */
+#ifndef I386_OPTS_H
+  return;
+#endif
+
+  rtl_dump_test t (SELFTEST_LOCATION, locate_file ("simple-cse.rtl"));
+  dataflow_test df_test;
+
+  int tem;
+  tem = cse_main (get_insns (), max_reg_num ());
+  ASSERT_EQ (0, tem);
+
+  /* Verify that insn 2's SET_SRC has been replaced with
+ the SET_DEST of insn 1.  */
+  ASSERT_EQ (SET_DEST (PATTERN (get_insn_by_uid (1))),
+SET_SRC (PATTERN (get_insn_by_uid (2;
+}
+
+/* Towards a regression test for PR 71779.  */
+
+static void
+test_pr71779 ()
+{
+  /* Only run this tests for target==aarch64.  */
+#ifndef GCC_AARCH64_H
+  return;
+#endif
+
+  rtl_dump_test t (SELFTEST_LOCATION, locate_file ("pr71779.rtl"));
+  dataflow_test df_test;
+
+  int tem;
+  tem = cse_main (get_insns (), max_reg_num ());
+  ASSERT_EQ (0, tem);
+}
+
+/* Run all of the selftests within this file.  */
+
+void
+cse_c_tests ()
+{
+  test_simple_cse ();
+  test_pr71779 ();
+}
+
+} // namespace selftest
+#endif /* CHECKING_P */
diff --git a/gcc/selftest-run-tests.c b/gcc/selftest-run-tests.c
index a10657f..f110a08 100644
--- a/gcc/selftest-run-tests.c
+++ b/gcc/selftest-run-tests.c
@@ -72,6 +72,7 @@ selftest::run_tests ()
   rtl_tests_c_tests ();
   read_rtl_function_c_tests ();
   df_core_c_tests ();
+  cse_c_tests ();
 
   /* Higher-level tests, or for components that other selftests don't
  rely on.  */
diff --git a/gcc/selftest.h b/gcc/selftest.h
index 95bf9b2..e07fa26 100644
--- a/gcc/selftest.h
+++ b/gcc/selftest.h
@@ -201,6 +201,7 @@ extern const char *path_to_src_gcc;
alphabetical order.  */
 extern void bitmap_c_tests ();
 extern void combine_c_tests ();
+extern void cse_c_tests ();
 extern void df_core_c_tests ();
 extern void diagnostic_c_tests ();
 extern void diagnostic_show_locus_c_tests ();
diff --git a/gcc/testsuite/selftests/pr71779.rtl 
b/gcc/testsuite/selftests/pr71779.rtl
new file mode 100644
index 000..5c4463f
--- /dev/null
+++ b/gcc/testsuite/selftests/pr71779.rtl
@@ -0,0 +1,39 @@
+;; Dump taken from comment 2 of PR 71779, of
+;; "...the relevant memory access coming out of expand"
+;; with basic block IDs added, and prev/next insns set to
+;; 0 at ends, and 'p' added to pseudo regnos.
+
+(function "fragment"
+  (insn-chain
+
+;; MEM[(struct isl_obj *)&obj1] = &isl_obj_map_vtable;
+(insn 1045 0 1046 2 (set (reg:SI 480)
+(high:SI (symbol_ref:SI ("isl_obj_map_vtable")
+[flags 0xc0]
+)))
+ y.c:12702 -1
+ (nil))
+(insn 1046 1045 1047 2 (set (reg/f:SI 479)
+(lo_sum:SI (reg:SI 480)
+(symbol_ref:SI ("isl_obj_map_vtable")
+   [flags 0xc0]
+   )))
+ y.c:12702 -1
+ (expr_list:REG_EQUAL (symbol_ref:SI ("isl_obj_map_vtable")
+ [flags 0xc0]
+ 

[PATCH 14/16] RTL interpreter (work-in-progress)

2016-10-05 Thread David Malcolm
This patch is much less polished than the rest of the kit; it's
more of an idea, showing an RTL interpreter.  My hope is that
something like this could be used to build a valgrind for RTL,
allowing us to run RTL fragments with a variety of inputs, for
sanity checking.

For example: capture the result of an RTL function on various inputs,
run an optimization pass, then verify that the results are sufficiently
similar to before, potentially auto-detecting.

(could have a gdb stub, for connecting to the interpreter and stepping
through RTL)

(Clearly a lot of hand-waving here; the patch itself is full of FIXMEs).

gcc/ChangeLog:
* Makefile.in (OBJS): Add rtl-interpreter.o.
* rtl-interpreter.c: New file.
* rtl-interpreter.h: New file.
* selftest-run-tests.c (selftest::run_tests): Add call to
rtl_interpreter_c_tests.
* selftest.h (selftest::rtl_interpreter_c_tests): New decl.

gcc/testsuite/ChangeLog:
* selftests/rtl/interp/empty-function.rtl: New file.
* selftests/rtl/interp/simple-arith.rtl: New file.
* selftests/rtl/interp/simple-set.rtl: New file.
* selftests/rtl/interp/undefined-read.rtl: New file.
---
 gcc/Makefile.in|   1 +
 gcc/rtl-interpreter.c  | 371 +
 gcc/rtl-interpreter.h  |  86 +
 gcc/selftest-run-tests.c   |   1 +
 gcc/selftest.h |   1 +
 .../selftests/rtl/interp/empty-function.rtl|  19 ++
 .../selftests/rtl/interp/simple-arith.rtl  |  13 +
 gcc/testsuite/selftests/rtl/interp/simple-set.rtl  |   7 +
 .../selftests/rtl/interp/undefined-read.rtl|  11 +
 9 files changed, 510 insertions(+)
 create mode 100644 gcc/rtl-interpreter.c
 create mode 100644 gcc/rtl-interpreter.h
 create mode 100644 gcc/testsuite/selftests/rtl/interp/empty-function.rtl
 create mode 100644 gcc/testsuite/selftests/rtl/interp/simple-arith.rtl
 create mode 100644 gcc/testsuite/selftests/rtl/interp/simple-set.rtl
 create mode 100644 gcc/testsuite/selftests/rtl/interp/undefined-read.rtl

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 7c8df56..3582bde 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1426,6 +1426,7 @@ OBJS = \
resource.o \
rtl-chkp.o \
rtl-error.o \
+   rtl-interpreter.o \
rtl-tests.o \
rtl.o \
rtlhash.o \
diff --git a/gcc/rtl-interpreter.c b/gcc/rtl-interpreter.c
new file mode 100644
index 000..9c9d48d
--- /dev/null
+++ b/gcc/rtl-interpreter.c
@@ -0,0 +1,371 @@
+/* RTL interpreter.
+   Copyright (C) 2016 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "backend.h"
+#include "target.h"
+#include "rtl.h"
+#include "emit-rtl.h"
+#include "rtl-interpreter.h"
+#include "selftest.h"
+#include "selftest-rtl.h"
+
+static rtl_value::value_t
+get_defined_bits (enum machine_mode mode)
+{
+  switch (mode)
+{
+case VOIDmode: // FIXME
+case SImode:
+  return (1ul << 32) - 1;
+
+default:
+  abort (); // unhandled
+  break;
+}
+}
+
+/* FIXME.  */
+
+rtl_value::rtl_value (enum machine_mode mode, value_t value, value_t 
defined_bits)
+: m_mode (mode), m_value (value), m_defined_bits (defined_bits)
+{
+}
+
+
+/* FIXME.  */
+
+rtl_value
+rtl_state::eval (rtx x) const
+{
+  switch (GET_CODE (x))
+{
+case CONST_INT:
+  return rtl_value (GET_MODE (x), INTVAL (x),
+   get_defined_bits (GET_MODE (x)));
+
+case REG:
+  // FIXME: apply mode
+  return get_reg_value (REGNO (x));
+
+case PLUS:
+  {
+   rtl_value lhs = eval (XEXP (x, 0));
+   rtl_value rhs = eval (XEXP (x, 1));
+   return rtl_value (GET_MODE (x),
+ lhs.m_value + rhs.m_value,
+ // FIXME:
+ lhs.m_defined_bits & rhs.m_defined_bits);
+  }
+  break;
+
+case SUBREG:
+  {
+   rtl_value complete = eval (XEXP (x, 0));
+   int offset = XINT (x, 1);
+   gcc_assert (offset == 0); // TODO: for now
+
+   // TODO: apply offset to complete.m_value
+
+   rtl_value::value_t subreg_bits = get_defined_bits (GET_MODE (x));
+   // TODO: apply offset to subreg_bits
+   

Re: [PATCH] - improve sprintf buffer overflow detection (middle-end/49905)

2016-10-05 Thread Jakub Jelinek
On Wed, Oct 05, 2016 at 03:40:18PM +, Joseph Myers wrote:
> On Tue, 4 Oct 2016, Martin Sebor wrote:
> 
> > > Well, typically cases where one of long and int is passed and the other is
> > > expected, but they have the same size, are bugs waiting to happen when the
> > > code is built on a 64-bit system.  That is, they *should* warn.
> > 
> > Typically, yes.  In the case of wchar_t (or int) and wint_t I don't
> > think it's helpful.  Consider this case from my comment #5 on bug
> > 72858.  I don't think there is any point in issuing a warning here.
> > On the majority of targets they either all are or promote to a type
> > of the same size, don't they?
> 
> I'm unconvinced by that "majority of targets" of argument (which once 
> would have been true for int and long, and you could say it is true for 
> long and size_t).  There's a clear correct type here, and it's wint_t, and 
> it's always easy to fix the code to use the correct type.

But, can we reliably detect differences between wint_t and unsigned int if
wint_t is a typedef to that, or size_t and unsigned long etc., I mean doesn't
early folding already throw it away?

Jakub


[PATCH 15/16] RTL frontend (rtl1), on top of dump reader

2016-10-05 Thread David Malcolm
This patch implements the RTL frontend, using the function_reader
class from earlier in the patch kit.

Compared to this patch in v1 of the kit, most of the work has been
split into earlier patches.  Other changes relative to v1 include:
* fix autodeps (by renaming RTL_OBJS to rtl_OBJS in rtl/Make-lang.in)
* cleanup of rtl/Make-lang.in
* overrride IN_GCC_FRONTEND in rtl/rtl-frontend.c
* split out run-one-rtl-pass.h/c
* added .texi docs to gccint (instead of notes.rst)
* remove roundtrip.exp for now (we don't currently preserve source
location information)
* convert existing test cases to "print_rtx_function" format, and add
new test cases.  Move some to target-specific subdirectories of rtl.dg
(manually adding target filters).

gcc/ChangeLog:
* Makefile.in (OBJS): Add run-one-rtl-pass.o.
* doc/rtl-frontend.texi: New file.
* doc/rtl.texi (RTL Representation): Add "RTL Frontend" to menu.
Include rtl-frontend.texi.
* gcc.c (default_compilers): Add a ".rtl" entry.
* read-rtl-function.c (read_rtl_function_body): Set
in_rtl_frontend_p.
* rtl.c (in_rtl_frontend_p): New global.
* rtl.h (in_rtl_frontend_p): New global decl.
* run-one-rtl-pass.c: New file.
* run-one-rtl-pass.h: New file.
* toplev.c (compile_file): Bail out after the parse_file
langhook if within the RTL frontend.

gcc/rtl/ChangeLog:
* ChangeLog: New file.
* Make-lang.in: New file.
* config-lang.in: New file.
* lang-specs.h: New file.
* lang.opt: New file.
* rtl-errors.c: New file.
* rtl-frontend.c: New file.

gcc/testsuite/ChangeLog:
* lib/rtl-dg.exp: New file.
* rtl.dg/aarch64/asr_div1.rtl: New file.
* rtl.dg/aarch64/pr71779.rtl: New file.
* rtl.dg/cfg-extra-bb.rtl: New file.
* rtl.dg/cfg-missing-bb.rtl: New file.
* rtl.dg/good-include.rtl: New file.
* rtl.dg/good-includee.md: New file.
* rtl.dg/missing-include.rtl: New file.
* rtl.dg/more-than-one-cfg.rtl: New file.
* rtl.dg/rtl.exp: New file.
* rtl.dg/test.c: New file.
* rtl.dg/unknown-insn-uid.rtl: New file.
* rtl.dg/unknown-rtx-code.rtl: New file.
* rtl.dg/x86_64/dfinit.rtl: New file.
* rtl.dg/x86_64/final.rtl: New file.
* rtl.dg/x86_64/into-cfglayout.rtl: New file.
* rtl.dg/x86_64/ira.rtl: New file.
* rtl.dg/x86_64/pro_and_epilogue.rtl: New file.
* rtl.dg/x86_64/vregs.rtl: New file.
---
 gcc/Makefile.in  |   1 +
 gcc/doc/rtl-frontend.texi| 262 +++
 gcc/doc/rtl.texi |   3 +
 gcc/gcc.c|   1 +
 gcc/read-rtl-function.c  |   2 +
 gcc/rtl.c|   2 +
 gcc/rtl.h|   1 +
 gcc/rtl/Make-lang.in |  88 +
 gcc/rtl/config-lang.in   |  36 ++
 gcc/rtl/lang-specs.h |  25 ++
 gcc/rtl/lang.opt |  33 ++
 gcc/rtl/rtl-errors.c |  34 ++
 gcc/rtl/rtl-frontend.c   | 399 +++
 gcc/run-one-rtl-pass.c   | 119 +++
 gcc/run-one-rtl-pass.h   |  25 ++
 gcc/testsuite/lib/rtl-dg.exp |  64 
 gcc/testsuite/rtl.dg/aarch64/asr_div1.rtl|  32 ++
 gcc/testsuite/rtl.dg/aarch64/pr71779.rtl |  44 +++
 gcc/testsuite/rtl.dg/cfg-extra-bb.rtl|  12 +
 gcc/testsuite/rtl.dg/cfg-missing-bb.rtl  |  16 +
 gcc/testsuite/rtl.dg/good-include.rtl|   6 +
 gcc/testsuite/rtl.dg/good-includee.md|   5 +
 gcc/testsuite/rtl.dg/missing-include.rtl |   1 +
 gcc/testsuite/rtl.dg/more-than-one-cfg.rtl   |   7 +
 gcc/testsuite/rtl.dg/rtl.exp |  41 +++
 gcc/testsuite/rtl.dg/test.c  |  31 ++
 gcc/testsuite/rtl.dg/unknown-insn-uid.rtl|   6 +
 gcc/testsuite/rtl.dg/unknown-rtx-code.rtl|   5 +
 gcc/testsuite/rtl.dg/x86_64/dfinit.rtl   | 102 ++
 gcc/testsuite/rtl.dg/x86_64/final.rtl|  58 
 gcc/testsuite/rtl.dg/x86_64/into-cfglayout.rtl   |  91 ++
 gcc/testsuite/rtl.dg/x86_64/ira.rtl  |  91 ++
 gcc/testsuite/rtl.dg/x86_64/pro_and_epilogue.rtl |  44 +++
 gcc/testsuite/rtl.dg/x86_64/vregs.rtl|  88 +
 gcc/toplev.c |   7 +
 35 files changed, 1782 insertions(+)
 create mode 100644 gcc/doc/rtl-frontend.texi
 create mode 100644 gcc/rtl/Make-lang.in
 create mode 100644 gcc/rtl/config-lang.in
 create mode 100644 gcc/rtl/lang-specs.h
 create mode 100644 gcc/rtl/lang.opt
 create mode 100644 gcc/rtl/rtl-errors.c
 create mode 100644 gcc/rtl/rtl-frontend.c
 cre

[PATCH 10/16] Introduce class function_reader (v3)

2016-10-05 Thread David Malcolm
This patch implements class function_reader, which implements
the dump-parsing functionality used in the rest of the kit.

Changed in v3:
* rather than hardcoding the selftest input dumps as escaped C strings
in the source code, move them out into separate files, using
selftest::locate_file
* update to use the new "print_rtx_function" output format, parsing
"(cfg)" and "(crtl)" directives to reconstruct the CFG and various
metadata.
* eliminated regno_remapper in favor of using the absence of a trailing
register name to detect pseudos
* significantly cleaner handling of print_rtx's various "warts",
moving the parsing from read-rtl.c to read-rtl-function.c, by making
read_rtx_operand virtual.  Split the implementation up into smaller
functions to make it easier to grok.
* more test coverage
* lots of other cleanups
(some FIXMEs and TODOs remain)

Blurb from original version:

This patch generalizes the RTL-reading capabilities so that they
can be run on the host as well as the build machine.
The available rtx in rtl.def changes dramatically between these
two configurations, so a fair amount of #ifdef GENERATOR_FILE is
required to express this.

This patch introduces a function_reader subclass of rtx_reader,
capable of reading an RTL function dump (or part of one),
reconstructing a cfun with a CFG and basic blocks containing insns.

gcc/ChangeLog:
* Makefile.in (OBJS): Add errors.o, read-md.o, read-rtl.o,
read-rtl-function.o, and selftest-rtl.o.
* errors.c: Use consistent pattern for bconfig.h vs config.h
includes.
(progname): Wrap with #ifdef GENERATOR_FILE.
(error): Likewise.  Add "error: " to message.
(fatal): Likewise.
(internal_error): Likewise.
(trim_filename): Likewise.
(fancy_abort): Likewise.
* errors.h (struct file_location): Move here from read-md.h.
(file_location::file_location): Likewise.
(error_at): New decl.
* function-tests.c (selftest::verify_three_block_rtl_cfg): Remove
"static".
* function.c (instantiate_decls): Guard call to
instantiate_decls_1 with if (DECL_INITIAL (fndecl)).
* print-rtl.c (print_rtx): Print "(nil)" rather than an empty
string for NULL strings.  Print "(nil)" for NULL basic blocks.
* read-md.c (read_skip_construct): Provide forward decl.
(read_skip_spaces): Support '/'.
(read_name): Rename to...
(read_name_1): ...this new static function, adding "out_loc" param,
and converting "missing name or number" to returning false, rather
than failing.
(read_name): Reimplement in terms of read_name_1.
(read_name_or_nil): New function.
(read_string): Handle "(nil)" by returning NULL.  */
* read-md.h (struct file_location): Move to errors.h.
(file_location::file_location): Likewise.
Include errors.h.
(rtx_reader::read_rtx_operand): Make virtual.
(rtx_reader::read_until): New decl.
(rtx_reader::handle_any_trailing_information): New virtual func.
(rtx_reader::postprocess): New virtual func.
(rtx_reader::m_in_call_function_usage): New field.
(read_name): Convert return type from void to file_location.
(read_name_or_nil): New decl.
* read-rtl-function.c: New file.
* read-rtl-function.h: New file.
* read-rtl.c: Potentially include config.h rather than bconfig.h.
For host, include function.h and emit-rtl.h.
(apply_subst_iterator): Wrap with #ifdef GENERATOR_FILE.
(bind_subst_iter_and_attr): Likewise.
(add_condition_to_string): Likewise.
(add_condition_to_rtx): Likewise.
(apply_attribute_uses): Likewise.
(add_current_iterators): Likewise.
(apply_iterators): Likewise.
(initialize_iterators): Guard usage of apply_subst_iterator with
#ifdef GENERATOR_FILE.
(read_conditions): Wrap with #ifdef GENERATOR_FILE.
(read_mapping): Likewise.
(add_define_attr_for_define_subst): Likewise.
(add_define_subst_attr): Likewise.
(read_subst_mapping): Likewise.
(check_code_iterator): Likewise.
(check_code_iterator): Likewise.
(read_rtx): Likewise.  Move one-time initialization logic to...
(one_time_initialization): New function.
(rtx_reader::read_until): New method.
(read_flags): New function.
(parse_reg_note_name): New function.
(rtx_reader::read_rtx_code): Initialize "iterator" to NULL.
Call one_time_initialization.  Wrap iterator lookup within
#ifdef GENERATOR_FILE.  Add parsing support for RTL dumps,
mirroring the special-cases in print_rtx, by calling read_flags,
reading REG_NOTE names, INSN_UID values, and calling
handle_any_trailing_information.
(rtx_reader::read_rtx_operand): Handle case 'e'.  When on host,
reallocate XSTR and XTMPL fields in th

Re: [PATCH 05/16] Introduce rtl_data::init_stack_alignment

2016-10-05 Thread Bernd Schmidt

On 10/05/2016 06:14 PM, David Malcolm wrote:

Move this part of "expand"'s initialization of crtl into its own
method so that it can used by the RTL frontend when postprocessing
RTL dumps.

gcc/ChangeLog:
* cfgexpand.c (pass_expand::execute): Move stack initializations
to rtl_data::init_stack_alignment and call it.
* emit-rtl.c (rtl_data::init_stack_alignment): New method.
* emit-rtl.h (rtl_data::init_stack_alignment): New method.


Ok.


Bernd



Re: [PATCH 06/16] Introduce emit_status::ensure_regno_capacity

2016-10-05 Thread Bernd Schmidt

On 10/05/2016 06:15 PM, David Malcolm wrote:

-  /* Make sure regno_pointer_align, and regno_reg_rtx are large
- enough to have an element for this pseudo reg number.  */
+  int cur_size = crtl->emit.regno_pointer_align_length;
+  if (reg_rtx_no == cur_size)
+crtl->emit.ensure_regno_capacity (cur_size * 2);


Patch looks ok in principle, but maybe this manipulation of the size 
should be part of the new function as well - i.e. don't pass a new_size 
to it, make it check reg_rtx_no itself.



Bernd


Re: [PATCH 06/16] Introduce emit_status::ensure_regno_capacity

2016-10-05 Thread Bernd Schmidt

On 10/05/2016 06:15 PM, David Malcolm wrote:


-  regno_reg_rtx = ggc_vec_alloc (crtl->emit.regno_pointer_align_length);
+  regno_reg_rtx =
+ggc_cleared_vec_alloc (crtl->emit.regno_pointer_align_length);


Oops, also: formatting, operators go first on a newline.


Bernd



Re: [PATCH 07/16] read-md: add some helper functions

2016-10-05 Thread Bernd Schmidt

On 10/05/2016 06:15 PM, David Malcolm wrote:


+void require_char (char expected)

> +void require_word_ws (const char *expected)

Function name goes on a new line. Otherwise ok.


Bernd


Re: [PATCH 01/16] read-md.c: Add various cleanups to ~rtx_reader

2016-10-05 Thread Bernd Schmidt

On 10/05/2016 06:14 PM, David Malcolm wrote:

The selftests for the RTL frontend require supporting multiple
reader instances being alive one after another in-process, so
this lack of cleanup would become a leak.



+  /* Initialize global data.  */
+  obstack_init (&string_obstack);
+  ptr_locs = htab_create (161, leading_ptr_hash, leading_ptr_eq_p, 0);
+  obstack_init (&ptr_loc_obstack);
+  joined_conditions = htab_create (161, leading_ptr_hash, leading_ptr_eq_p, 0);
+  obstack_init (&joined_conditions_obstack);
+  md_constants = htab_create (31, leading_string_hash,
+ leading_string_eq_p, (htab_del) 0);
+  enum_types = htab_create (31, leading_string_hash,
+   leading_string_eq_p, (htab_del) 0);
+
+  /* Unlock the stdio streams.  */
+  unlock_std_streams ();


Hmm, but these are global statics. Shouldn't they first be moved to 
become class members?



Bernd


[RFA] [PR tree-optimization/71661] Fix forwarder removal when new loops are exposed

2016-10-05 Thread Jeff Law


Removal of forwarder blocks is a two step process.

First we build a worklist of potential forwarder blocks,  Then we 
iterate over that worklist attempting to remove each potential forwarder 
block in the worklist.


The code which builds the worklist is aware that we do not want to 
remove a forwarder that is a loop header and avoids putting such blocks 
into the worklist.


The problem is that removing a forwarder block may turn an irreducible 
region into a natural loop, which of course will have a loop header. 
But that loop header could not be recognized as such during the initial 
building of the worklist.


So as a result if removal of a forwarder block exposes a new loop and 
the header of that newly exposed loop appears to be a forwarder block, 
we may forward through the newly exposed loop header too.  That can 
squash two loops into a single loop, which invalidates the cached 
iteration information and other stuff which can in turn cause incorrect 
code generation (as seen by 71661).


There's two ways to address this problem.  First we could invalidate the 
cached loop info when this situation occurs.  Second, we could avoid 
forwarding through the newly exposed loop header.


The patch takes the latter approach.  Based on the CFG transformations 
for 71661, I think we're better off leaving the newly exposed loop alone 
-- we've exposed a nice simple loop nest, collapsing the nest into a 
single loop with multiple latch edges just seems wrong.


Bootstrapped and regression tested on x86_64-linux.gnu.  OK for the trunk?

Jeff
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 2b56878..33ee250 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2016-10-05  Jeff Law  
+
+   PR tree-optimization/71661
+   * tree-cfgcleanup.c (remove_forwarder_block): Handle case when removal
+   of a forwarder exposes a new natural loop.
+   (remove_forwarder_block_with_phi): Likewise.
+
 2016-10-05  Martin Sebor  
 
PR bootstrap/77819
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index fa1f310..3bba95d 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2016-10-05  Jeff Law  
+
+PR tree-optimization/71661
+   * gcc.dg/tree-ssa/pr71661.c: New test.
+
 2016-10-05  Richard Biener  
 
PR middle-end/77826
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr71661.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr71661.c
new file mode 100644
index 000..c273ea1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr71661.c
@@ -0,0 +1,31 @@
+/* { dg-do run } */
+/* { dg-options "-O3 -fdisable-tree-ethread" } */
+
+extern void exit (int);
+
+int a, b;
+
+void
+fn1 ()
+{
+  unsigned c = 0;
+  int d;
+  b = a;
+  if (a < 0)
+goto L1;
+  for (; a < 1; a++)
+d = 0;
+  for (; d < 2; d++)
+{
+  for (c = 0; c < 3; c++)
+  L1:
+a = 2;
+}
+}
+
+int
+main ()
+{
+  fn1 ();
+  exit (0);
+}
diff --git a/gcc/tree-cfgcleanup.c b/gcc/tree-cfgcleanup.c
index 6052872..e3cb8ee 100644
--- a/gcc/tree-cfgcleanup.c
+++ b/gcc/tree-cfgcleanup.c
@@ -418,6 +418,11 @@ remove_forwarder_block (basic_block bb)
   if (dest == bb)
 return false;
 
+  /* Removal of forwarders may expose new natural loops and thus
+ a block may turn into a loop header.  */
+  if (current_loops && bb_loop_header_p (bb))
+return false;
+
   /* If the destination block consists of a nonlocal label or is a
  EH landing pad, do not merge it.  */
   label = first_stmt (dest);
@@ -840,6 +845,11 @@ remove_forwarder_block_with_phi (basic_block bb)
   if (dest == bb)
 return false;
 
+  /* Removal of forwarders may expose new natural loops and thus
+ a block may turn into a loop header.  */
+  if (current_loops && bb_loop_header_p (bb))
+return false;
+
   /* If the destination block consists of a nonlocal label, do not
  merge it.  */
   label = first_stmt (dest);


Re: [PATCH 10/16] Introduce class function_reader (v3)

2016-10-05 Thread Bernd Schmidt

On 10/05/2016 06:15 PM, David Malcolm wrote:

* errors.c: Use consistent pattern for bconfig.h vs config.h
includes.
(progname): Wrap with #ifdef GENERATOR_FILE.
(error): Likewise.  Add "error: " to message.
(fatal): Likewise.
(internal_error): Likewise.
(trim_filename): Likewise.
(fancy_abort): Likewise.
* errors.h (struct file_location): Move here from read-md.h.
(file_location::file_location): Likewise.
(error_at): New decl.


Can you split these out into a separate patch as well? I'll require more 
explanation for them and they seem largely independent.



Bernd


Re: [PATCH 08/16] (partially-approved): Introduce selftest::locate_file

2016-10-05 Thread Bernd Schmidt

On 10/05/2016 06:15 PM, David Malcolm wrote:

 selftest: s-selftest
 s-selftest: $(GCC_PASSES) cc1$(exeext) stmp-int-hdrs
-   $(GCC_FOR_TARGET) -xc -S -c /dev/null -fself-test
+   $(GCC_FOR_TARGET) -xc -S -c /dev/null -fself-test=$(srcdir)
$(STAMP) $@


I suspect the Makefile parts will need updating once Thomas commits his 
change.


Also,


+  return concat (path_to_src_gcc, "/testsuite/selftests/", name, NULL);


why hardcode directory names here? I think this should just be passed as 
a full pathname so only the Makefiles have knowledge of source directory 
structure.



Bernd



Re: [PATCH 16/16] Add "__RTL" to cc1

2016-10-05 Thread Joseph Myers
On Wed, 5 Oct 2016, David Malcolm wrote:

> @@ -1752,6 +1759,35 @@ c_parser_declaration_or_fndef (c_parser *parser, bool 
> fndef_ok,
>c_parser_skip_to_end_of_block_or_statement (parser);
>return;
>  }
> +
> +  if (c_parser_next_token_is (parser, CPP_KEYWORD))
> +{
> +  c_token *kw_token = c_parser_peek_token (parser);
> +  if (kw_token->keyword == RID_RTL)

if (c_parser_next_token_is_keyword (parser, RID_RTL))

You're missing an update to the comment above this function to show what 
the new syntax is.

-- 
Joseph S. Myers
jos...@codesourcery.com


Re: [PATCH] - improve sprintf buffer overflow detection (middle-end/49905)

2016-10-05 Thread Joseph Myers
On Wed, 5 Oct 2016, Jakub Jelinek wrote:

> On Wed, Oct 05, 2016 at 03:40:18PM +, Joseph Myers wrote:
> > On Tue, 4 Oct 2016, Martin Sebor wrote:
> > 
> > > > Well, typically cases where one of long and int is passed and the other 
> > > > is
> > > > expected, but they have the same size, are bugs waiting to happen when 
> > > > the
> > > > code is built on a 64-bit system.  That is, they *should* warn.
> > > 
> > > Typically, yes.  In the case of wchar_t (or int) and wint_t I don't
> > > think it's helpful.  Consider this case from my comment #5 on bug
> > > 72858.  I don't think there is any point in issuing a warning here.
> > > On the majority of targets they either all are or promote to a type
> > > of the same size, don't they?
> > 
> > I'm unconvinced by that "majority of targets" of argument (which once 
> > would have been true for int and long, and you could say it is true for 
> > long and size_t).  There's a clear correct type here, and it's wint_t, and 
> > it's always easy to fix the code to use the correct type.
> 
> But, can we reliably detect differences between wint_t and unsigned int if
> wint_t is a typedef to that, or size_t and unsigned long etc., I mean doesn't
> early folding already throw it away?

Detecting it in all cases is hard as for size_t etc., but that shouldn't 
stop us warning in the cases where the types are different enough that we 
can tell the program is wrong.

-- 
Joseph S. Myers
jos...@codesourcery.com


Re: C++ PATCH for C++17 selection statements with initializer

2016-10-05 Thread Jason Merrill
On Wed, Oct 5, 2016 at 11:29 AM, Marek Polacek  wrote:
> On Wed, Oct 05, 2016 at 10:48:19AM -0400, Jason Merrill wrote:
>> On Wed, Oct 5, 2016 at 9:14 AM, Marek Polacek  wrote:
>> > +/* Return true if we're looking at (init; cond), false otherwise.  */
>> > +
>> > +static bool
>> > +cp_parser_init_statement_p (cp_parser *parser)
>> > +{
>> > +  unsigned paren_depth = 0;
>> > +  unsigned brace_depth = 0;
>>
>> Do we really need another one of these token scanning functions?
>> Can't you write this in terms of
>> cp_parser_skip_to_closing_parenthesis?
>>
>> > +   /* Parse the optional init-statement.  */
>> > +   tree decl;
>> > +   cp_lexer_save_tokens (parser->lexer);
>> > +   const bool init_stmt_p = cp_parser_init_statement_p (parser);
>> > +   /* Roll back the tokens we skipped.  */
>> > +   cp_lexer_rollback_tokens (parser->lexer);
>>
>> The save/rollback should be in the the predicate function, not the caller.
>
> How about the version I just posted, i.e.
> ?

That doesn't address my first comment.

Jason


Re: [PATCH] - improve sprintf buffer overflow detection (middle-end/49905)

2016-10-05 Thread Martin Sebor

On 10/05/2016 09:40 AM, Joseph Myers wrote:

On Tue, 4 Oct 2016, Martin Sebor wrote:


Well, typically cases where one of long and int is passed and the other is
expected, but they have the same size, are bugs waiting to happen when the
code is built on a 64-bit system.  That is, they *should* warn.


Typically, yes.  In the case of wchar_t (or int) and wint_t I don't
think it's helpful.  Consider this case from my comment #5 on bug
72858.  I don't think there is any point in issuing a warning here.
On the majority of targets they either all are or promote to a type
of the same size, don't they?


I'm unconvinced by that "majority of targets" of argument (which once
would have been true for int and long, and you could say it is true for
long and size_t).  There's a clear correct type here, and it's wint_t, and
it's always easy to fix the code to use the correct type.


The warning would only helpful if there was a target where wchar_t
didn't promote to a type with the same precision as wint_t, or in
other words where printf("%lc", L'a') did something different than
printf("%lc", (wint_t) L'a'). I don't know of such a target.  Can
you give an example of one?

It isn't any of the ILP32 targets where wint_t is int and wchar_t
is long and where the warning was found to cause test suite failures,
and it isn't any other other targets where the warning didn't trigger
because the two types have the same precision.

Otherwise, when there is no such target there is nothing to fix, and
changing working code just for the sake of pedantry only runs the
unnecessary risk of introducing bugs.  IMO, this is especially true
in subtle cases like this where the people who make the changes often
don't fully appreciate the subtleties of the code.  Suggesting the
wrong directive (replacing %lc with %ld) compounds the problem
further(*).

Martin

[*] This is not meant as a dig at David but rather to underscore
that both the "problem" is subtle and the expected solution not
obvious.


Re: [C++ PATCH] Delete GCJ - C++ part

2016-10-05 Thread Jeff Law

On 10/05/2016 03:07 AM, Jakub Jelinek wrote:

On Wed, Oct 05, 2016 at 11:04:05AM +0200, Andreas Schwab wrote:

FAIL: g++.dg/pr49847-2.C  -std=gnu++11 (test for excess errors)
Excess errors:
/daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:5:13: error: 
'__java_int' does not name a type
/daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:6:13: error: 
'__java_float' does not name a type; did you mean '__cpp_hex_float'?
/daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:18:12: error: language 
string '"Java"' not recognized
/daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:25:5: error: 
'jint' does not name a type; did you mean 'int'?
/daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:26:5: error: 
'jfloat' does not name a type; did you mean 'float'?
/daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:41:6: error: 
'jfloat' was not declared in this scope
/daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:42:13: error: 
expected ';' before 'value1'
/daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:43:10: error: 
'value1' was not declared in this scope
/daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:43:19: error: 
'value2' was not declared in this scope
/daten/aranym/gcc/gcc-20161005/gcc/testsuite/g++.dg/pr49847-2.C:43:41: error: 
'union _Jv_word' has no member named 'i'


Feel free to remove it.  I have no access to m68k.
No objections from me either. It was a test for a very obscure 
problem with cc0 targets and the setter/user getting separated.  Given 
we just want to verify compilation without hitting an ICE, we could 
probably create suitable types and save the test, but I doubt it's 
terribly important.


jeff


Re: [PATCH] - improve sprintf buffer overflow detection (middle-end/49905)

2016-10-05 Thread Joseph Myers
On Wed, 5 Oct 2016, Martin Sebor wrote:

> The warning would only helpful if there was a target where wchar_t
> didn't promote to a type with the same precision as wint_t, or in

Or it could show up a logical error where the code should have had a 
wint_t variable and checked for WEOF somewhere but just assumed things 
would fit in wchar_t (and so could be passing a negative value where the 
ABI means the callee expects wint_t values to be zero-extended, with 
consequent undefined behavior there).  The correct fix involves thinking 
about where you know something is a wide character, and where something 
might be a wide character or WEOF.  It might then involve a cast to 
wint_t, or changing the type of a variable, or more changes than that.

-- 
Joseph S. Myers
jos...@codesourcery.com


Re: [PATCH] Delete GCJ

2016-10-05 Thread Jeff Law

On 10/04/2016 12:39 PM, Iain Sandoe wrote:


I don't know who wants to review it, but if people want me to, Ok.  The idea is 
that if ObjC is the last remaining user in tree for boehm-gc, then reasonably 
I'm the last man standing.  Of course, if others want to review approve the 
patch, I'm fine with that.

I'm fine with patches to externalize boehm-gc if people want to push that 
direction.


+1
Works for me as well, particularly since we've been horrible at updating 
boehm-gc.  I think the in-tree version is something like 10 years old at 
this point -- and there's been over a dozen upstream releases since we 
last sync'd.


Jeff


Re: [PATCH] Fix warnings for profiledbootstrap (PR bootstrap/77788)

2016-10-05 Thread Jeff Law

On 10/04/2016 03:16 AM, Martin Liška wrote:

Hello.

In the attached patch I resolve couple of warnings seen during make 
profiledbootstrap.
I can survive bootstrap on both ppc64le-redhat-linux and x86_64-linux-gnu 
targets.

Ready to be installed?
Martin


0001-Fix-warnings-for-make-profiledbootstrap-PR-bootstrap.patch


From 510ac204f2e448d244c8eec5ab8aeab85f6041a9 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Mon, 3 Oct 2016 23:17:05 +0200
Subject: [PATCH] Fix warnings for make profiledbootstrap (PR bootstrap/77788)

gcc/ChangeLog:

2016-10-04  Martin Liska  

PR bootstrap/77788
* expmed.h (mul_highpart_cost_ptr): Add an gcc_assert.
* gimple-ssa-strength-reduction.c (slsr_process_cast):
Initialize a pointer to NULL.
(slsr_process_copy): Likewise.
* input.c (location_get_source_line): Likewise.
* tree-ssa-ccp.c (optimize_atomic_bit_test_and): Likewise.
Presumably what's going on here is that the profiling data is giving the 
jump threader additional information and the threader is refusing to 
thread some jumps because they're not profitable.  AT least that's how 
it looks to me.


Note the input.c change may not be necessary once the input.c cleanups 
are done, but I don't think it'd be actively harmful.


OK.

jeff



Re: [AArch64][0/14] ARMv8.2-A FP16 extension support

2016-10-05 Thread Jiong Wang

On 27/09/16 17:03, Jiong Wang wrote:
>
> Now as ARM patches have gone in around r240427, I have done a quick 
confirmation

> on the status of these four pending testsuite patches:
>
>   https://gcc.gnu.org/ml/gcc-patches/2016-07/msg00337.html
>   https://gcc.gnu.org/ml/gcc-patches/2016-07/msg00338.html
>   https://gcc.gnu.org/ml/gcc-patches/2016-07/msg00339.html
>   https://gcc.gnu.org/ml/gcc-patches/2016-07/msg00340.html
>
> The result is they applies cleanly on gcc trunk, and there is no 
regression on
> AArch64 native regression test.  Testcases enabled without 
requirement of FP16

> all passed.
>
> I will give a final run on ARM native board and AArch64 emulation 
environment
> with ARMv8.2-A FP16 enabled. (Have done this before, just in case 
something

> changed during these days)
>
> OK for trunk if there is no regression?
>
> Thanks

Finished the final tests on emulator with FP16 enabled.

  * No regression on AARCH64, all new testcases passed.
  * No regression on AARCH32, part of these new testcases UNRESOLVED 
because

they should be skipped on AARCH32, fixed by the attached trivial patch
which I will merge into the 4th patch (no affect on changelog).

OK to commit these patches?


diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vcageh_f16_1.c b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vcageh_f16_1.c
index f8c8c79..0bebec7 100644
--- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vcageh_f16_1.c
+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vcageh_f16_1.c
@@ -1,6 +1,7 @@
 /* { dg-do run } */
 /* { dg-require-effective-target arm_v8_2a_fp16_scalar_hw } */
 /* { dg-add-options arm_v8_2a_fp16_scalar }  */
+/* { dg-skip-if "" { arm*-*-* } } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vcagth_f16_1.c b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vcagth_f16_1.c
index 23c11a4..68ce599 100644
--- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vcagth_f16_1.c
+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vcagth_f16_1.c
@@ -1,6 +1,7 @@
 /* { dg-do run } */
 /* { dg-require-effective-target arm_v8_2a_fp16_scalar_hw } */
 /* { dg-add-options arm_v8_2a_fp16_scalar }  */
+/* { dg-skip-if "" { arm*-*-* } } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vcaleh_f16_1.c b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vcaleh_f16_1.c
index ae4c8b5..1b5a09b 100644
--- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vcaleh_f16_1.c
+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vcaleh_f16_1.c
@@ -1,6 +1,7 @@
 /* { dg-do run } */
 /* { dg-require-effective-target arm_v8_2a_fp16_scalar_hw } */
 /* { dg-add-options arm_v8_2a_fp16_scalar }  */
+/* { dg-skip-if "" { arm*-*-* } } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vcalth_f16_1.c b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vcalth_f16_1.c
index 56a6533..766c783 100644
--- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vcalth_f16_1.c
+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vcalth_f16_1.c
@@ -1,6 +1,7 @@
 /* { dg-do run } */
 /* { dg-require-effective-target arm_v8_2a_fp16_scalar_hw } */
 /* { dg-add-options arm_v8_2a_fp16_scalar }  */
+/* { dg-skip-if "" { arm*-*-* } } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vceqh_f16_1.c b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vceqh_f16_1.c
index fb54e96..8f5c14b 100644
--- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vceqh_f16_1.c
+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vceqh_f16_1.c
@@ -1,6 +1,7 @@
 /* { dg-do run } */
 /* { dg-require-effective-target arm_v8_2a_fp16_scalar_hw } */
 /* { dg-add-options arm_v8_2a_fp16_scalar }  */
+/* { dg-skip-if "" { arm*-*-* } } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vceqzh_f16_1.c b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vceqzh_f16_1.c
index 57c765c..ccfecf4 100644
--- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vceqzh_f16_1.c
+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vceqzh_f16_1.c
@@ -1,6 +1,7 @@
 /* { dg-do run } */
 /* { dg-require-effective-target arm_v8_2a_fp16_scalar_hw } */
 /* { dg-add-options arm_v8_2a_fp16_scalar }  */
+/* { dg-skip-if "" { arm*-*-* } } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vcgeh_f16_1.c b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vcgeh_f16_1.c
index f9a5bbe..161c7a0 100644
--- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vcgeh_f16_1.c
+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vcgeh_f16_1.c
@@ -1,6 +1,7 @@
 /* { dg-do run } */
 /* { dg-require-effective-target arm_v8_2a_fp16_scalar_hw } */
 /* { dg-add-options arm_v8_2a_fp16_scalar }  */
+/* { dg-skip-if "" { arm*-*-* } } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vcgezh_f16_1.c b/gcc/te

Re: [PATCH 13/16] cse.c selftests

2016-10-05 Thread Bernd Edlinger
David,

I think this could be added to the pr71779 test case:



  test_pr71779 ()
  {
/* Only run this tests for target==aarch64.  */
  #ifndef GCC_AARCH64_H
+#ifndef I386_OPTS_H
return;
+#endif
  #endif

rtl_dump_test t (SELFTEST_LOCATION, locate_file ("pr71779.rtl"));
dataflow_test df_test;

tem = cse_main (get_insns (), max_reg_num ());
ASSERT_EQ (0, tem);
+  ASSERT_FALSE (REG_POINTER (SET_DEST (PATTERN (get_insn_by_uid (1047);
  }


at least last time when I tried it, this was able
to reproduce the invalid transformation.

It worked for aarch64 and x86_64, not sure if it will work for
i686-pc-linux-gnu too...


Bernd.


Re: [PATCH] Fix ubsan ICE on vector shift (PR sanitizer/77823)

2016-10-05 Thread Jeff Law

On 10/03/2016 11:31 AM, Jakub Jelinek wrote:

Hi!

libsanitizer isn't right now prepared to handle vector types, and we don't
instrument vector additions/multiplications etc. for overflow etc. either,
so this patch just turns the single case that slipped through.

As I wrote in the PR, in the future we should probably change libubsan to
handle them and start instrumenting those.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-10-03  Jakub Jelinek  

PR sanitizer/77823
* c-ubsan.c (ubsan_instrument_shift): Return NULL_TREE if type0
is not integral.

* c-c++-common/ubsan/shift-9.c: New test.
Sorry -- when Jan B. added code to give warnings for shifts of vector 
types I thought we had nailed down the code to avoid sanitizing shifts 
of vector types (by way of Paolo's patch).


OK.

jeff



Re: [PATCH] Fix -fsanitize=undefined with PCH, part #2 (PR sanitizer/66343)

2016-10-05 Thread Marek Polacek
On Wed, Oct 05, 2016 at 05:29:49PM +0200, Jakub Jelinek wrote:
> Hi!
> 
> When writing test for this PR, I've noticed ICE if the header is compiled
> without -fsanitize=undefined, but source is compiled with it.
> 
> We had various issues like this in the past, and we handle it by calling
> initialize_sanitizer_builtins, which does nothing if the sanitizer bultins
> are already created, but after loading PCH (which can kill them) can fix stuff
> up again.  I found various spots where the call has been missing in the
> ubsan instrumentation, but common feature of all those spots is first
> calling ubsan_create_data and only then using builtin_decl_explicit
> for the ubsan builtins.  So, this patch puts the initialization call into
> that routine, which fixes all uses, and removes the two calls that are now
> unnecessary because of that.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

LGTM, but can't approve neither.

Marek


Re: Fix missing -Wimplicit-fallthrough warning

2016-10-05 Thread Marek Polacek
Ping.

On Thu, Sep 29, 2016 at 06:10:27PM +0200, Marek Polacek wrote:
> Here, a missing -Wimplicit-fallthrough warning was caused by a misplaced
> FALLTHROUGH_LABEL_P check.  As it is now, for FALLTHROUGH_LABEL_P we'd
> never gotten around to
>  1933 /* So that next warn_implicit_fallthrough_r will start 
> looking for
>  1934a new sequence starting with this label.  */
>  1935 gsi_prev (gsi_p);
> 
> The fix is to move the check to should_warn_for_implicit_fallthrough.
> 
> Bootstrapped/regtested on x86_64-linux and ppc64-linux, ok for trunk?
> 
> 2016-09-29  Marek Polacek  
> 
>   * gimplify.c (should_warn_for_implicit_fallthrough): Check for
>   FALLTHROUGH_LABEL_P here...
>   (warn_implicit_fallthrough_r): ...not here.
> 
>   * c-c++-common/Wimplicit-fallthrough-22.c: New test.
> 
> diff --git gcc/gimplify.c gcc/gimplify.c
> index 66bb8be..e077a7e 100644
> --- gcc/gimplify.c
> +++ gcc/gimplify.c
> @@ -1817,6 +1817,10 @@ should_warn_for_implicit_fallthrough 
> (gimple_stmt_iterator *gsi_p, tree label)
>  {
>gimple_stmt_iterator gsi = *gsi_p;
>  
> +  /* Don't warn if the label is marked with a "falls through" comment.  */
> +  if (FALLTHROUGH_LABEL_P (label))
> +return false;
> +
>/* Don't warn for a non-case label followed by a statement:
> case 0:
>foo ();
> @@ -1903,7 +1907,6 @@ warn_implicit_fallthrough_r (gimple_stmt_iterator 
> *gsi_p, bool *handled_ops_p,
>   if (gimple_code (next) == GIMPLE_LABEL
>   && gimple_has_location (next)
>   && (label = gimple_label_label (as_a  (next)))
> - && !FALLTHROUGH_LABEL_P (label)
>   && prev != NULL)
> {
>   struct label_entry *l;
> diff --git gcc/testsuite/c-c++-common/Wimplicit-fallthrough-22.c 
> gcc/testsuite/c-c++-common/Wimplicit-fallthrough-22.c
> index e69de29..7a81e47 100644
> --- gcc/testsuite/c-c++-common/Wimplicit-fallthrough-22.c
> +++ gcc/testsuite/c-c++-common/Wimplicit-fallthrough-22.c
> @@ -0,0 +1,23 @@
> +/* { dg-do compile } */
> +/* { dg-options "-Wimplicit-fallthrough" } */
> +
> +void bar (int);
> +
> +void
> +foo (int i)
> +{
> +  switch (i)
> +{
> +case 1:
> +  bar (1);
> +  /* FALLTHROUGH */
> +case 2:
> +  bar (2); /* { dg-warning "statement may fall through" } */
> +case 3:
> +  bar (3); /* { dg-warning "statement may fall through" } */
> +case 4:
> +  bar (4);
> +default:
> +  break;
> +}
> +}
> 
>   Marek

Marek


Re: C++ PATCH for C++17 selection statements with initializer

2016-10-05 Thread Marek Polacek
On Wed, Oct 05, 2016 at 12:11:40PM -0400, Jason Merrill wrote:
> On Wed, Oct 5, 2016 at 11:29 AM, Marek Polacek  wrote:
> > How about the version I just posted, i.e.
> > ?
> 
> That doesn't address my first comment.

The following uses cp_parser_skip_to_closing_parenthesis_1, and is, I think,
much nicer.

Bootstrapped/regtested on x86_64-linux and ppc64-linux, ok for trunk?

2016-10-05  Marek Polacek  

Implement P0305R1, Selection statements with initializer.
* cp-array-notation.c (create_an_loop): Call finish_init_stmt
instead of finish_for_init_stmt.
* cp-tree.h (finish_for_init_stmt): Rename to finish_init_stmt.
* decl.c (poplevel): Adjust a comment.
* init.c (build_vec_init): Call finish_init_stmt instead of
finish_for_init_stmt.
* name-lookup.c (pushdecl_maybe_friend_1): Adjust a comment.
* name-lookup.h (enum scope_kind): Likewise.
* parser.c (cp_parser_statement): Update commentary.
(cp_parser_init_statement_p): New function.
(cp_parser_selection_statement): Parse the optional init-statement.
(cp_parser_for): Call finish_init_stmt instead of finish_for_init_stmt.
(cp_parser_c_for): Likewise.
(cp_convert_range_for): Call finish_init_stmt instead of 
finish_for_init_stmt.
(cp_parser_range_for_member_function): Update commentary.
(cp_parser_iteration_statement):
(cp_parser_for_init_statement): Rename to cp_parser_init_statement.
* pt.c (tsubst_omp_for_iterator): Update commentary.
(tsubst_expr): Call finish_init_stmt instead of finish_for_init_stmt.
* semantics.c (finish_for_init_stmt): Rename to finish_init_stmt.
Update commentary.

* g++.dg/cpp1z/init-statement1.C: New test.
* g++.dg/cpp1z/init-statement2.C: New test.
* g++.dg/cpp1z/init-statement3.C: New test.
* g++.dg/cpp1z/init-statement4.C: New test.
* g++.dg/cpp1z/init-statement5.C: New test.
* g++.dg/cpp1z/init-statement6.C: New test.
* g++.dg/cpp1z/init-statement7.C: New test.
* g++.dg/cpp1z/init-statement8.C: New test.

diff --git gcc/cp/cp-array-notation.c gcc/cp/cp-array-notation.c
index 4687ced..633ab09 100644
--- gcc/cp/cp-array-notation.c
+++ gcc/cp/cp-array-notation.c
@@ -66,7 +66,7 @@ create_an_loop (tree init, tree cond, tree incr, tree body)
 
   finish_expr_stmt (init);
   for_stmt = begin_for_stmt (NULL_TREE, NULL_TREE);
-  finish_for_init_stmt (for_stmt);
+  finish_init_stmt (for_stmt);
   finish_for_cond (cond, for_stmt, false);
   finish_for_expr (incr, for_stmt);
   finish_expr_stmt (body);
diff --git gcc/cp/cp-tree.h gcc/cp/cp-tree.h
index 3fbe1d9..92e4017 100644
--- gcc/cp/cp-tree.h
+++ gcc/cp/cp-tree.h
@@ -6297,7 +6297,7 @@ extern void finish_do_stmt(tree, 
tree, bool);
 extern tree finish_return_stmt (tree);
 extern tree begin_for_scope(tree *);
 extern tree begin_for_stmt (tree, tree);
-extern void finish_for_init_stmt   (tree);
+extern void finish_init_stmt   (tree);
 extern void finish_for_cond(tree, tree, bool);
 extern void finish_for_expr(tree, tree);
 extern void finish_for_stmt(tree);
diff --git gcc/cp/decl.c gcc/cp/decl.c
index 6646062..6a08d8f 100644
--- gcc/cp/decl.c
+++ gcc/cp/decl.c
@@ -639,9 +639,8 @@ poplevel (int keep, int reverse, int functionbody)
   BLOCK_SUPERCONTEXT (link) = block;
 
   /* We still support the old for-scope rules, whereby the variables
- in a for-init statement were in scope after the for-statement
- ended.  We only use the new rules if flag_new_for_scope is
- nonzero.  */
+ in a init statement were in scope after the for-statement ended.
+ We only use the new rules if flag_new_for_scope is nonzero.  */
   leaving_for_scope
 = current_binding_level->kind == sk_for && flag_new_for_scope == 1;
 
diff --git gcc/cp/init.c gcc/cp/init.c
index 2d5877d..d1c8274 100644
--- gcc/cp/init.c
+++ gcc/cp/init.c
@@ -4052,7 +4052,7 @@ build_vec_init (tree base, tree maxindex, tree init,
   tree to;
 
   for_stmt = begin_for_stmt (NULL_TREE, NULL_TREE);
-  finish_for_init_stmt (for_stmt);
+  finish_init_stmt (for_stmt);
   finish_for_cond (build2 (GT_EXPR, boolean_type_node, iterator,
   build_int_cst (TREE_TYPE (iterator), -1)),
   for_stmt, false);
diff --git gcc/cp/name-lookup.c gcc/cp/name-lookup.c
index 1bce63b..9e84a1b 100644
--- gcc/cp/name-lookup.c
+++ gcc/cp/name-lookup.c
@@ -1156,7 +1156,7 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend)
   }
}
  /* Error if redeclaring a local declared in a
-for-init-statement or in the condition of an if or
+init-statement or in 

Re: [PATCH] - improve sprintf buffer overflow detection (middle-end/49905)

2016-10-05 Thread Martin Sebor

On 10/05/2016 10:27 AM, Joseph Myers wrote:

On Wed, 5 Oct 2016, Martin Sebor wrote:


The warning would only helpful if there was a target where wchar_t
didn't promote to a type with the same precision as wint_t, or in


Or it could show up a logical error where the code should have had a
wint_t variable and checked for WEOF somewhere but just assumed things
would fit in wchar_t


WEOF that fits in a wint_t also fits in a wchar_t when the two types
have the same precision, the case where GCC issues the warning (and
where WEOF expands to 0xu).  So this isn't an example of
a problem that could arise on the targets that brought this up, or
any other targets that I'm aware of.


(and so could be passing a negative value where the
ABI means the callee expects wint_t values to be zero-extended, with
consequent undefined behavior there).


Sign extension is also not an issue on the target where the warning
is issued (x86_64 ILP32) and where wchar_t is int and wint_t is
unsigned long.


The correct fix involves thinking
about where you know something is a wide character, and where something
might be a wide character or WEOF.  It might then involve a cast to
wint_t, or changing the type of a variable, or more changes than that.


There is nothing to fix when wchar_t and wint_t have the same
precision and  printf("%lc", L'x') does the same thing as
printf("%lc", (wint_t) L'x').  The cast is entirely superfluous.

Even so, the warning could have merit if there were a different
target to which the program might need to be ported where this
property didn't hold.  But as I said, I don't know of one and,
as it seems, neither do you.

I'm very much in favor of strict warnings that help point out
either real or potential bugs.  But I see no value in warning
about constructs that are perfectly safe.  To the contrary,
I think such warnings are harmful because they lead to
unnecessary churn and to bug injection.

It might be worthwhile to mention that Clang used to issue the
same warning as GCC until 2011 when they fixed it.  The bug is
here:

  https://llvm.org/bugs/show_bug.cgi?id=7981

(Although I think there is a flaw in the logic they used in
comment #2 it's only hypothetical because there is no target
that Clang supports where the submitted test case doesn't do
what it's expected to do either.)

Martin


[Patch, testsuite] Fix pr69941.c test failure for avr

2016-10-05 Thread Senthil Kumar Selvaraj
Hi,

  The below patch fixes gcc.dg/torture/pr69941.c to pass for
  int size != 32 targets like avr.

  For the avr target, ints are 16 bits wide. VRP concludes
  that a right shift by 9 followed by an equality comparison 
  to 0x74 can never be true, and ends up eliminating the
  conditional. The code ends up unconditionally
  calling __builtin_abort and obviously fails when run.

  The patch fixes the testcase to use __INT32_TYPE__ (via a
  typedef) if __SIZEOF_INT__ is less than 4.

  Regtested with both avr and x86_64, the test passes with
  both targets.

Regards
Senthil

gcc/testsuite/ChangeLog

2016-10-05  Senthil Kumar Selvaraj  

* gcc.dg/torture/pr69941.c: Use __INT32_TYPE__ instead
of int if __SIZEOF_INT__ is less than 4 bytes.

Index: gcc/testsuite/gcc.dg/torture/pr69941.c
===
--- gcc/testsuite/gcc.dg/torture/pr69941.c  (revision 240781)
+++ gcc/testsuite/gcc.dg/torture/pr69941.c  (working copy)
@@ -1,11 +1,17 @@
 /* { dg-do run } */
+
+#if __SIZEOF_INT__ < 4
+__extension__ typedef __INT32_TYPE__ int32_t;
+#else
+typedef int int32_t;
+#endif
  
 int a = 0;
 int b = 0;
 int c = 0;
-int e = 0;
+int32_t e = 0;
 int f = 0;
-int *g = &e;
+int32_t *g = &e;
  
 int fn1() { return b ? a : b; }
  


Re: [PATCH] define TARGET_PRINTF_POINTER_FORMAT for powerpc-linux (77837)

2016-10-05 Thread Martin Sebor

On 10/03/2016 08:11 PM, Martin Sebor wrote:

On 10/03/2016 07:10 PM, Segher Boessenkool wrote:

On Mon, Oct 03, 2016 at 05:30:35PM -0600, Martin Sebor wrote:

The attached patch adds definitions of TARGET_PRINTF_POINTER_FORMAT
to the rs6000 pair of linux.h and linux64.h headers, analogous to
the config/linux.h header.  This appears to be necessary since
unlike most other back ends, the rs6000 back end doesn't include
the latter linux.h.

The patch fixes bug 77837 - missing -Wformat-length warning for %p
with null argument on powerpc64.

Thanks
Martin



PR target/77837 - missing -Wformat-length warning for %p with null
argument on powerpc64

gcc/ChangeLog:
2016-10-03  Martin Sebor  

PR target/77837
* config/rs6000/linux.h (TARGET_PRINTF_POINTER_FORMAT): Define.
* config/rs6000/linux64.h (TARGET_PRINTF_POINTER_FORMAT): Likewise.


Okay for trunk, thanks!


I was able to fix this in r240793 without changing the rs6000 back
end so this patch is no longer necessary.

Thanks
Martin


Re: [PATCH] - improve sprintf buffer overflow detection (middle-end/49905)

2016-10-05 Thread Joseph Myers
On Wed, 5 Oct 2016, Martin Sebor wrote:

> > Or it could show up a logical error where the code should have had a
> > wint_t variable and checked for WEOF somewhere but just assumed things
> > would fit in wchar_t
> 
> WEOF that fits in a wint_t also fits in a wchar_t when the two types
> have the same precision, the case where GCC issues the warning (and
> where WEOF expands to 0xu).  So this isn't an example of
> a problem that could arise on the targets that brought this up, or
> any other targets that I'm aware of.

The problem is e.g. code calling getwchar and not checking for WEOF.  
0xu does not fit in a 32-bit signed variable unless your code is 
confusing signed and unsigned freely.  And even if you consider it OK to 
check after conversion to wchar_t rather than before, the lack of a wint_t 
variable for the result seems likely to accompany a missing check.

> > (and so could be passing a negative value where the
> > ABI means the callee expects wint_t values to be zero-extended, with
> > consequent undefined behavior there).
> 
> Sign extension is also not an issue on the target where the warning
> is issued (x86_64 ILP32) and where wchar_t is int and wint_t is
> unsigned long.

There are plenty of architectures where the ABI does require the high part 
to be extended in a particular way; that's why the Linux kernel has 
syscall wrappers, because improperly extended 32-bit syscall arguments 
caused security issues in the past.  In some cases it's even 
architecturally undefined what the processor does when an instruction 
input isn't properly extended (although at least in the MIPS case the 
required extension there is always sign-extension, whether the 32-bit 
value is considered signed or unsigned).

I'd actually hope for future forms of sanitization to be able to detect at 
runtime when you have undefined behavior from incorrectly typed arguments 
to variadic functions.

I think the warning is the correct thing for anyone trying to write C as a 
high-level language and be type-correct and properly check before doing 
conversions that might change values unless those changes are actually 
intended, and that warning rather than lesser warnings for "C as portable 
assembler" is the appropriate default for format checking.

-- 
Joseph S. Myers
jos...@codesourcery.com


Re: C++ PATCH for C++17 selection statements with initializer

2016-10-05 Thread Jason Merrill
OK.


[PATCH] rs6000: Use "dg-warning ... 0" in a few places

2016-10-05 Thread Segher Boessenkool
GCC used to give warnings for line # 1 for these, but it prints no
line number anymore.  Adjust.


2016-10-05  Segher Boessenkool  

gcc/testsuite/
* gcc.target/powerpc/warn-1.c: Change line number in dg-warning.
* gcc.target/powerpc/warn-2.c: Ditto.

---
 gcc/testsuite/gcc.target/powerpc/warn-1.c | 2 +-
 gcc/testsuite/gcc.target/powerpc/warn-2.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.target/powerpc/warn-1.c 
b/gcc/testsuite/gcc.target/powerpc/warn-1.c
index f4cb437..f345106 100644
--- a/gcc/testsuite/gcc.target/powerpc/warn-1.c
+++ b/gcc/testsuite/gcc.target/powerpc/warn-1.c
@@ -3,7 +3,7 @@
 /* { dg-require-effective-target powerpc_vsx_ok } */
 /* { dg-options "-O -mvsx -mno-altivec" } */
 
-/* { dg-warning "-mvsx and -mno-altivec are incompatible" "" { target *-*-* } 
1 } */
+/* { dg-warning "-mvsx and -mno-altivec are incompatible" "" { target *-*-* } 
0 } */
 
 double
 foo (double *x, double *y)
diff --git a/gcc/testsuite/gcc.target/powerpc/warn-2.c 
b/gcc/testsuite/gcc.target/powerpc/warn-2.c
index 45f490c..02e8268 100644
--- a/gcc/testsuite/gcc.target/powerpc/warn-2.c
+++ b/gcc/testsuite/gcc.target/powerpc/warn-2.c
@@ -4,7 +4,7 @@
 /* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { 
"-mcpu=power7" } } */
 /* { dg-options "-O -mcpu=power7 -mno-altivec" } */
 
-/* { dg-warning "-mno-altivec disables vsx" "" { target *-*-* } 1 } */
+/* { dg-warning "-mno-altivec disables vsx" "" { target *-*-* } 0 } */
 
 double
 foo (double *x, double *y)
-- 
1.9.3



[PATCH] testsuite: Prune "non-standard ABI extension" warnings

2016-10-05 Thread Segher Boessenkool
Various testcases fail with "excess errors" for 32-bit PowerPC, for
the warnings about vectors without -mabi=altivec.  This patch adds
dg-prune-output directives to ignore those warnings.

Is there a better way to handle this?  dg-prune-output does not allow
a "target" condition, even.


Segher


2016-10-05  Segher Boessenkool  

gcc/testsuite/
* gcc.dg/plugin/diagnostic-test-expressions-1.c: Add dg-prune-output
"non-standard ABI extension".
* gcc/testsuite/gcc.dg/pr69634.c: Ditto.
* gcc/testsuite/gcc.dg/tree-ssa/forwprop-35.c: Ditto.
* gcc/testsuite/gcc.dg/tree-ssa/pr71179.c: Ditto.
* gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-55.c: Ditto.

---
 gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions-1.c | 1 +
 gcc/testsuite/gcc.dg/pr69634.c  | 1 +
 gcc/testsuite/gcc.dg/tree-ssa/forwprop-35.c | 1 +
 gcc/testsuite/gcc.dg/tree-ssa/pr71179.c | 2 +-
 gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-55.c  | 1 +
 5 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions-1.c 
b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions-1.c
index 9372936..e25a6ef 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions-1.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions-1.c
@@ -1,5 +1,6 @@
 /* { dg-do compile } */
 /* { dg-options "-O -fdiagnostics-show-caret" } */
+/* { dg-prune-output "non-standard ABI extension" } */
 
 /* This is a collection of unittests to verify that we're correctly
capturing the source code ranges of various kinds of expression.
diff --git a/gcc/testsuite/gcc.dg/pr69634.c b/gcc/testsuite/gcc.dg/pr69634.c
index e4032b6..9b3d915 100644
--- a/gcc/testsuite/gcc.dg/pr69634.c
+++ b/gcc/testsuite/gcc.dg/pr69634.c
@@ -2,6 +2,7 @@
 /* { dg-options "-O2 -fno-dce -fschedule-insns -fno-tree-vrp -fcompare-debug" 
} */
 /* { dg-additional-options "-Wno-psabi -mno-sse" { target i?86-*-* x86_64-*-* 
} } */
 /* { dg-require-effective-target scheduling } */
+/* { dg-prune-output "non-standard ABI extension" } */
 
 typedef unsigned short u16;
 typedef short v16u16 __attribute__ ((vector_size (16)));
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-35.c 
b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-35.c
index 79053a2..7c4225f 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-35.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-35.c
@@ -1,6 +1,7 @@
 /* { dg-do compile } */
 /* { dg-options "-O -fdump-tree-cddce1" } */
 /* { dg-additional-options "-msse2" { target { i?86-*-* x86_64-*-* } } } */
+/* { dg-prune-output "non-standard ABI extension" } */
 
 typedef int v4si __attribute__((vector_size(16)));
 typedef float v4sf __attribute__((vector_size(16)));
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr71179.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr71179.c
index 885c643..7e18db6 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr71179.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr71179.c
@@ -1,6 +1,6 @@
-
 /* { dg-do compile } */
 /* { dg-options "-O3 -ffast-math" } */
+/* { dg-prune-output "non-standard ABI extension" } */
 
 typedef float __m128 __attribute__ ((__vector_size__ (16), __may_alias__));
 
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-55.c 
b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-55.c
index 7bfa284..3e29c24 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-55.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-55.c
@@ -1,5 +1,6 @@
 /* { dg-do compile } */
 /* { dg-options "-O -fdump-tree-optimized" } */
+/* { dg-prune-output "non-standard ABI extension" } */
 
 typedef int v4si __attribute__((vector_size(16)));
 
-- 
1.9.3



Re: [PATCH] testsuite: Prune "non-standard ABI extension" warnings

2016-10-05 Thread Jakub Jelinek
On Wed, Oct 05, 2016 at 05:47:30PM +, Segher Boessenkool wrote:
> Various testcases fail with "excess errors" for 32-bit PowerPC, for
> the warnings about vectors without -mabi=altivec.  This patch adds
> dg-prune-output directives to ignore those warnings.
> 
> Is there a better way to handle this?  dg-prune-output does not allow
> a "target" condition, even.

I think it would be nice if rs6000 switches to guarding these warnings
with -Wpsabi, so that one can use -Wno-psabi on all targets.
Then we could remove all these dg-prune-output lines as well as various
other hacks around the rs6000 warnings (-w - because no other warning option
disables those).

> 2016-10-05  Segher Boessenkool  
> 
> gcc/testsuite/
>   * gcc.dg/plugin/diagnostic-test-expressions-1.c: Add dg-prune-output
>   "non-standard ABI extension".
>   * gcc/testsuite/gcc.dg/pr69634.c: Ditto.
>   * gcc/testsuite/gcc.dg/tree-ssa/forwprop-35.c: Ditto.
>   * gcc/testsuite/gcc.dg/tree-ssa/pr71179.c: Ditto.
>   * gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-55.c: Ditto.

No gcc/testsuite/ in the ChangeLog.

Jakub


Re: [PATCH] Extend -Wint-in-bool-context to more conditional expressions

2016-10-05 Thread Jeff Law

On 10/03/2016 11:09 AM, Bernd Edlinger wrote:

Hi!

This is a next step in extending the -Wint-in-bool-context warning
to cover the case when a conditional expression has only
one arm which evaluates to a non-boolean integer value.

With a previous version of this warning, we found PR 77574,
among with several more or less false positives, but meanwhile,
mostly due to excluding conditional expressions that originate
from macro expansion, there are no false positives any more,
so I think this is fine now with -Wall.


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


Thanks
Bernd.


patch-bool-context2.diff


c-family:
2016-10-03  Bernd Edlinger  

* c-common.c (c_common_truthvalue_conversion): Warn also for suspicious
conditional expression in boolean context when only one arm is
non-boolean.

testsuite:
2016-10-03  Bernd Edlinger  

* c-c++-common/Wint-in-bool-context.c: Update test.

OK.
jeff



  1   2   >