Re: [PATCH] Fix PR middle-end/80775, -O3 produces ice in group_case_labels_stmt

2017-05-17 Thread Richard Biener
On Tue, 16 May 2017, Peter Bergner wrote:

> The test case in PR80775 exposes a problem in handling two separate
> case labels that lead to the same block that contains a call to
> __builtin_unreachable().   The current code handles the first label
> and deletes the associated edge/block, but trips up when we see the
> second case label that now points to a removed block.  This patch moves
> the deletion of the unreachable case statement to after the merging
> of consecutive case labels, which easily fixes the issue.  It also has
> a side benefit of reducing the number of calls to gimple_seq_unreachable_p()
> when we have consecutive case labels that point to unreachable blocks.
> 
> This bootstrapped and regtested with no regressions on both powerpc64le-linux
> and x86_64-linux.  Is this ok for trunk?

Ok.

Thanks,
Richard.

> Peter
> 
> gcc/
>   PR middle-end/80775
>   * tree-cfg.c: Move deletion of unreachable case statements to after
>   the merging of consecutive case labels.
> 
> gcc/testsuite/
>   PR middle-end/80775
>   * gcc.dg/pr80775.c: New test.
> 
> Index: gcc/tree-cfg.c
> ===
> --- gcc/tree-cfg.c(revision 248119)
> +++ gcc/tree-cfg.c(working copy)
> @@ -1661,7 +1661,7 @@ void
>  group_case_labels_stmt (gswitch *stmt)
>  {
>int old_size = gimple_switch_num_labels (stmt);
> -  int i, j, new_size = old_size;
> +  int i, j, base_index, new_size = old_size;
>basic_block default_bb = NULL;
>  
>default_bb = label_to_block (CASE_LABEL (gimple_switch_default_label 
> (stmt)));
> @@ -1678,16 +1678,9 @@ group_case_labels_stmt (gswitch *stmt)
>gcc_assert (base_case);
>base_bb = label_to_block (CASE_LABEL (base_case));
>  
> -  /* Discard cases that have the same destination as the default case
> -  or if their destination block is unreachable.  */
> -  if (base_bb == default_bb
> -   || (EDGE_COUNT (base_bb->succs) == 0
> -   && gimple_seq_unreachable_p (bb_seq (base_bb
> +  /* Discard cases that have the same destination as the default case.  
> */
> +  if (base_bb == default_bb)
>   {
> -   edge e;
> -   if (base_bb != default_bb
> -   && (e = find_edge (gimple_bb (stmt), base_bb)) != NULL)
> - remove_edge_and_dominated_blocks (e);
> gimple_switch_set_label (stmt, i, NULL_TREE);
> i++;
> new_size--;
> @@ -1697,7 +1690,7 @@ group_case_labels_stmt (gswitch *stmt)
>base_high = CASE_HIGH (base_case)
> ? CASE_HIGH (base_case)
> : CASE_LOW (base_case);
> -  i++;
> +  base_index = i++;
>  
>/* Try to merge case labels.  Break out when we reach the end
>of the label vector or when we cannot merge the next case
> @@ -1723,6 +1716,18 @@ group_case_labels_stmt (gswitch *stmt)
> else
>   break;
>   }
> +
> +  /* Discard cases that have an unreachable destination block.  */
> +  if (EDGE_COUNT (base_bb->succs) == 0
> +   && gimple_seq_unreachable_p (bb_seq (base_bb)))
> + {
> +   edge base_edge = find_edge (gimple_bb (stmt), base_bb);
> +   if (base_edge != NULL)
> + remove_edge_and_dominated_blocks (base_edge);
> +   gimple_switch_set_label (stmt, base_index, NULL_TREE);
> +   new_size--;
> +   i++;
> + }
>  }
>  
>/* Compress the case labels in the label vector, and adjust the
> Index: gcc/testsuite/gcc.dg/pr80775.c
> ===
> --- gcc/testsuite/gcc.dg/pr80775.c(nonexistent)
> +++ gcc/testsuite/gcc.dg/pr80775.c(working copy)
> @@ -0,0 +1,21 @@
> +/* PR middle-end/80775 ICE: -O3 produces ice in group_case_labels_stmt.  */
> +/* { dg-do compile }  */
> +/* { dg-options "-O3" }  */
> +
> +typedef struct { short a; } b;
> +b c[10];
> +int d, e, f, g, h;
> +int
> +i (void)
> +{
> +  f = 0;
> +  for (; f < e; f++) {
> +switch (g) {
> +case 1:
> +  d = 1;
> +case 2:
> +  c[2 + f].a = 1;
> +}
> +h += c[f].a;
> +  }
> +}
> 
> 

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


Re: C PATCH to fix ASAN ICE with a compound literal (PR sanitizer/80659)

2017-05-17 Thread Richard Biener
On Tue, 16 May 2017, Marek Polacek wrote:

> Martin L. asked me to have a look at this ICE with ASAN.  This is an ICE with 
> a
> compound literal in a switch.  A hash map gimplify_ctxp->live_switch_vars is
> filled when processing DECL_EXPRs with their DECL_EXPR_DECLs.  Such decls 
> should
> then be removed from the hash map when gimplifying a BIND_EXPR.
> 
> In C, non-static compound literals aren't pushed into any scope, so they were
> never found by gimplify_bind_expr, so they stayed in the hash map resulting in
> a crash on
>  2299   if (gimplify_ctxp->live_switch_vars)
>  2300 {
>  2301   gcc_assert (gimplify_ctxp->live_switch_vars->elements () == 
> 0);
>  2302   delete gimplify_ctxp->live_switch_vars;
>  2303 }
> 
> We don't add artificial decls to the hash map:
>  1647   if (!DECL_ARTIFICIAL (decl) && 
> gimplify_ctxp->live_switch_vars)
>  1648 gimplify_ctxp->live_switch_vars->add (decl);
> 
> build_compound_literal only marks a decl of a compound literal as artificial
> when the compound literal is static.  I think there's no harm in marking
> decls of non-static compound literals as artificial, too (provided it's fine 
> to
> skip asan instrumentation of compound literals).

But probably DECL_IGNORED_P as well at the same time?

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

Ok with moving that as well (and re-testing).

Thanks,
Richard.

> 2017-05-16  Marek Polacek  
> 
>   PR sanitizer/80659
>   * c-decl.c (build_compound_literal): Set DECL_ARTIFICIAL even for
>   non-static compound literals.
> 
>   * gcc.dg/asan/pr80659.c: New test.
> 
> diff --git gcc/c/c-decl.c gcc/c/c-decl.c
> index b779d37..887e95d 100644
> --- gcc/c/c-decl.c
> +++ gcc/c/c-decl.c
> @@ -5261,6 +5261,7 @@ build_compound_literal (location_t loc, tree type, tree 
> init, bool non_const)
>DECL_CONTEXT (decl) = current_function_decl;
>TREE_USED (decl) = 1;
>DECL_READ_P (decl) = 1;
> +  DECL_ARTIFICIAL (decl) = 1;
>TREE_TYPE (decl) = type;
>TREE_READONLY (decl) = (TYPE_READONLY (type)
> || (TREE_CODE (type) == ARRAY_TYPE
> @@ -5297,7 +5298,6 @@ build_compound_literal (location_t loc, tree type, tree 
> init, bool non_const)
>set_compound_literal_name (decl);
>DECL_DEFER_OUTPUT (decl) = 1;
>DECL_COMDAT (decl) = 1;
> -  DECL_ARTIFICIAL (decl) = 1;
>DECL_IGNORED_P (decl) = 1;
>pushdecl (decl);
>rest_of_decl_compilation (decl, 1, 0);
> diff --git gcc/testsuite/gcc.dg/asan/pr80659.c 
> gcc/testsuite/gcc.dg/asan/pr80659.c
> index e69de29..0cbf2e4 100644
> --- gcc/testsuite/gcc.dg/asan/pr80659.c
> +++ gcc/testsuite/gcc.dg/asan/pr80659.c
> @@ -0,0 +1,13 @@
> +/* PR sanitizer/80659 */
> +/* { dg-do compile } */
> +
> +void
> +foo (int a)
> +{
> +  switch (a)
> +{
> +case 0:
> +  (int[3]) { };
> +  int h;
> +}
> +}
> 
>   Marek
> 
> 

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


Re: [PATCH v2 2/N] Introduce dump_flags_t type and use it instead of int, type.

2017-05-17 Thread Richard Biener
On Tue, May 16, 2017 at 4:55 PM, Martin Liška  wrote:
> On 05/16/2017 03:48 PM, Richard Biener wrote:
>> On Fri, May 12, 2017 at 3:00 PM, Martin Liška  wrote:
>>> Second part changes 'int flags' to a new typedef.
>>> All corresponding interfaces have been changed.
>>>
>>> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
>>>
>>> Ready to be installed?
>>
>> @@ -113,6 +114,14 @@ enum tree_dump_index
>>  #define OPTGROUP_ALL(OPTGROUP_IPA | OPTGROUP_LOOP | OPTGROUP_INLINE 
>> \
>>   | OPTGROUP_OMP | OPTGROUP_VEC | OPTGROUP_OTHER)
>>
>> +/* Dump flags type.  */
>> +
>> +typedef uint64_t dump_flags_t;
>> +
>> +/* Dump flags type.  */
>> +
>> +typedef uint64_t dump_flags_t;
>> +
>>
>> duplicate.
>
> Yes, wrong patch merge.
>
>>
>> +#define TDF_NONE 0
>>
>> this now seems to "conflict" with
>>
>> #define TDF_LANG0   /* is a lang-specific dump.  */
>>
>> ?
>
> I'll make TDF_LANG 1 and will increment next TDF_KIND_MASK values.
> Re-running regression tests.

You'll have to adjust the & value as well then.

I didn't mean to really change this but eventually just document the
behavior of TDF_NONE to just affect the bits "above" TDF_KIND_MASK.

Thus when you test for TDF_NONE you'd use

TDF_FLAGS (flags) == TDF_NONE

rather than flags == TDF_NONE.

RIchard.

> Martin
>
>>
>> that is, TDF_RTL | TDF_NONE would still be "none" conceptually ...
>>
>> Ok with the duplicate typedef removed.
>>
>> Thanks,
>> Richard.
>>
>>> Martin
>


Re: [PATCH] Dump functions for verification failures

2017-05-17 Thread Richard Biener
On Wed, May 17, 2017 at 4:12 AM, Andi Kleen  wrote:
> From: Andi Kleen 
>
> When a verification check fails it is useful to dump the current
> function to the dump file, so it's easier to figure out what
> actually went wrong.
>
> Add function dumps for gimple or SSA verification failures.
>
> Suggested by Jakub.
>
> Passes bootstrap and testing on x86_64-linux
>
> gcc/:
>
> 2017-05-16  Andi Kleen  
>
> * tree-cfg.c (verify_gimple_in_cfg): Dump function.

At this point the dump is probably redundant, there are also many
other verify places.

> * tree-into-ssa.c (update_ssa): Dump function.
> * tree-outof-ssa.c (eliminate_useless_phis): Dump function.
> (rewrite_trees): Dump function.
> ---
>  gcc/tree-cfg.c   | 6 +-
>  gcc/tree-into-ssa.c  | 2 ++
>  gcc/tree-outof-ssa.c | 4 
>  3 files changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
> index 7dbd0a8c247..05073906fbd 100644
> --- a/gcc/tree-cfg.c
> +++ b/gcc/tree-cfg.c
> @@ -5279,7 +5279,11 @@ verify_gimple_in_cfg (struct function *fn, bool 
> verify_nothrow)
>(&visited_stmts);
>
>if (err || eh_error_found)
> -internal_error ("verify_gimple failed");
> +{
> +  if (dump_file)
> +   dump_function_to_file (fn->decl, dump_file, dump_flags);
> +  internal_error ("verify_gimple failed");
> +}
>
>verify_histograms ();
>timevar_pop (TV_TREE_STMT_VERIFY);
> diff --git a/gcc/tree-into-ssa.c b/gcc/tree-into-ssa.c
> index d4056373f31..de150b8e917 100644
> --- a/gcc/tree-into-ssa.c
> +++ b/gcc/tree-into-ssa.c
> @@ -3387,6 +3387,8 @@ update_ssa (unsigned update_flags)
>  "renaming: ");
> print_generic_expr (stderr, name, TDF_SLIM);
> fprintf (stderr, "\n");
> +   if (dump_file)
> + dump_function_to_file (cfun->decl, dump_file, dump_flags);

So you still have to look what dump-file there is.

> internal_error ("SSA corruption");
>   }
>   }
> diff --git a/gcc/tree-outof-ssa.c b/gcc/tree-outof-ssa.c
> index 0ce6c155bd3..8be0b1088df 100644
> --- a/gcc/tree-outof-ssa.c
> +++ b/gcc/tree-outof-ssa.c
> @@ -821,6 +821,8 @@ eliminate_useless_phis (void)
> print_generic_expr (stderr, arg, TDF_SLIM);
> fprintf (stderr, "), but the result is :");
> print_gimple_stmt (stderr, phi, 0, TDF_SLIM);
> +   if (dump_file)
> + dump_function_to_file (cfun->decl, dump_file, 
> dump_flags);
> internal_error ("SSA corruption");
>   }
>   }
> @@ -880,6 +882,8 @@ rewrite_trees (var_map map)
>   print_generic_expr (stderr, arg, TDF_SLIM);
>   fprintf (stderr, "), but the result is not :");
>   print_gimple_stmt (stderr, phi, 0, TDF_SLIM);
> + if (dump_file)
> +   dump_function_to_file (cfun->decl, dump_file, 
> dump_flags);

Maybe we can instead hook into internal_error and

 a) report the pass (and dump_file)
 b) dump the actual error and a disclaimer
 c) dump the function

?  That also catches all the places you forgot.

>   internal_error ("SSA corruption");
> }
> }
> --
> 2.12.2
>


[PATCH] Enable by default -Werror just for bootstrap-debug.mk.

2017-05-17 Thread Martin Liška
Hi.

As discussed on IRC some time ago, there are configurations that produce 
-Werror=maybe-uninitialized
and other warnings that break bootstrap. So that, the patch makes -Werror just 
for default (boostrap-debug)
configuration.

Ready for trunk?
Martin
>From 93a314f17d5cf75e7ecd5cb03a052842aaf30b4f Mon Sep 17 00:00:00 2001
From: marxin 
Date: Wed, 17 May 2017 10:39:58 +0200
Subject: [PATCH] Enable by default -Werror just for bootstrap-debug.mk.

ChangeLog:

2017-05-17  Martin Liska  

	* configure: Regenerate the file.
	* configure.ac: Remove adding enable_werror for 'experimantal'
	DEP-PHASE and add it just for bootstrap-debug BUILD_CONFIG.
---
 configure| 12 ++--
 configure.ac | 13 +++--
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/configure b/configure
index 32a38633ad8..66e51552746 100755
--- a/configure
+++ b/configure
@@ -14587,12 +14587,6 @@ fi
 # Check whether --enable-werror was given.
 if test "${enable_werror+set}" = set; then :
   enableval=$enable_werror;
-else
-  if test -d ${srcdir}/gcc && test x"`cat $srcdir/gcc/DEV-PHASE`" = xexperimental; then
-  enable_werror=yes
-else
-  enable_werror=no
-fi
 fi
 
 case ${enable_werror} in
@@ -14600,6 +14594,12 @@ case ${enable_werror} in
   *) stage2_werror_flag="" ;;
 esac
 
+# Enable -Werror only for selected build configurations.
+case $BUILD_CONFIG in
+bootstrap-debug)
+stage2_werror_flag="--enable-werror-always"
+esac
+
 
 # Enable --enable-host-shared.
 # Check whether --enable-host-shared was given.
diff --git a/configure.ac b/configure.ac
index 12377499295..d622a2fca41 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3461,16 +3461,17 @@ AC_SUBST(stage1_checking)
 # Enable -Werror in bootstrap stage2 and later.
 AC_ARG_ENABLE(werror,
 [AS_HELP_STRING([--enable-werror],
-		[enable -Werror in bootstrap stage2 and later])], [],
-[if test -d ${srcdir}/gcc && test x"`cat $srcdir/gcc/DEV-PHASE`" = xexperimental; then
-  enable_werror=yes
-else
-  enable_werror=no
-fi])
+		[enable -Werror in bootstrap stage2 and later])], [])
 case ${enable_werror} in
   yes) stage2_werror_flag="--enable-werror-always" ;;
   *) stage2_werror_flag="" ;;
 esac
+
+# Enable -Werror only for selected build configurations.
+case $BUILD_CONFIG in
+bootstrap-debug)
+stage2_werror_flag="--enable-werror-always"
+esac
 AC_SUBST(stage2_werror_flag)
 
 # Enable --enable-host-shared.
-- 
2.12.2



Re: [PATCH, GCC/ARM] Fix comment for cmse_nonsecure_call_clear_caller_saved

2017-05-17 Thread Kyrill Tkachov


On 15/05/17 17:13, Thomas Preudhomme wrote:

Hi,

Saving, clearing and restoring of *callee-saved* registers when doing a
cmse_nonsecure_call is done in the __gnu_cmse_nonsecure_call libcall.
Yet, comments for cmse_nonsecure_call_clear_caller_saved claim that
it is this function that does these actions.

This commit fixes the comment to point to the __gnu_cmse_nonsecure_call
libcall instead.

ChangeLog entry is as follows:

*** gcc/ChangeLog ***

2017-05-12  Thomas Preud'homme  

* config/arm/arm.c (cmse_nonsecure_call_clear_caller_saved): Refer
readers to __gnu_cmse_nonsecure_call libcall for saving, clearing and
restoring of callee-saved registers.

Given that this is just a comment fix, is this ok for trunk and
gcc-7-branch after a one day delay?



Ok.
Thanks,
Kyrill


Best regards,

Thomas




Re: [PATCH v2 2/N] Introduce dump_flags_t type and use it instead of int, type.

2017-05-17 Thread Martin Liška
On 05/17/2017 09:44 AM, Richard Biener wrote:
> On Tue, May 16, 2017 at 4:55 PM, Martin Liška  wrote:
>> On 05/16/2017 03:48 PM, Richard Biener wrote:
>>> On Fri, May 12, 2017 at 3:00 PM, Martin Liška  wrote:
 Second part changes 'int flags' to a new typedef.
 All corresponding interfaces have been changed.

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

 Ready to be installed?
>>>
>>> @@ -113,6 +114,14 @@ enum tree_dump_index
>>>  #define OPTGROUP_ALL(OPTGROUP_IPA | OPTGROUP_LOOP | 
>>> OPTGROUP_INLINE \
>>>   | OPTGROUP_OMP | OPTGROUP_VEC | 
>>> OPTGROUP_OTHER)
>>>
>>> +/* Dump flags type.  */
>>> +
>>> +typedef uint64_t dump_flags_t;
>>> +
>>> +/* Dump flags type.  */
>>> +
>>> +typedef uint64_t dump_flags_t;
>>> +
>>>
>>> duplicate.
>>
>> Yes, wrong patch merge.
>>
>>>
>>> +#define TDF_NONE 0
>>>
>>> this now seems to "conflict" with
>>>
>>> #define TDF_LANG0   /* is a lang-specific dump.  */
>>>
>>> ?
>>
>> I'll make TDF_LANG 1 and will increment next TDF_KIND_MASK values.
>> Re-running regression tests.
> 
> You'll have to adjust the & value as well then.
> 
> I didn't mean to really change this but eventually just document the
> behavior of TDF_NONE to just affect the bits "above" TDF_KIND_MASK.
> 
> Thus when you test for TDF_NONE you'd use
> 
> TDF_FLAGS (flags) == TDF_NONE
> 
> rather than flags == TDF_NONE.

You are right, I've just added comment of the original version and installed as 
r248140.

Martin

> 
> RIchard.
> 
>> Martin
>>
>>>
>>> that is, TDF_RTL | TDF_NONE would still be "none" conceptually ...
>>>
>>> Ok with the duplicate typedef removed.
>>>
>>> Thanks,
>>> Richard.
>>>
 Martin
>>



Re: [RFC PATCH, i386]: Enable post-reload compare elimination pass

2017-05-17 Thread Eric Botcazou
> I've got the visium, rx and mn103 patches handy to ensure they don't
> regress.  aarch64 doesn't seem to be affected either way but I didn't
> investigate why -- I expected it to improve with your change.

Thanks for taking care of this, but a couple of comments in config/visium are 
now backwards and must be adjusted too:

Index: config/visium/visium.c
===
--- config/visium/visium.c  (revision 248139)
+++ config/visium/visium.c  (working copy)
@@ -922,8 +922,8 @@ empty_delay_slot (rtx_insn *insn)
   return 1;
 }
 
-/* Wrapper around single_set which returns the first SET of a pair if the
-   second SET is to the flags register.  */
+/* Wrapper around single_set which returns the second SET of a pair if the
+   first SET is to the flags register.  */
 
 static rtx
 single_set_and_flags (rtx_insn *insn)
Index: config/visium/visium.md
===
--- config/visium/visium.md (revision 248139)
+++ config/visium/visium.md (working copy)
@@ -240,7 +240,7 @@ (define_code_attr add_str [(plus "plus")
 ;;
 ;; Substitutions.
 ;;
-;; They are used to define the second instruction of the pairs required by
+;; They are used to define the first instruction of the pairs required by
 ;; the postreload compare elimination pass, with a first variant for the
 ;; logical insns and a second variant for the arithmetic insns.
 ;;

I'm going to install the fixlet.

-- 
Eric Botcazou


Re: [PATCH 12/12] [i386,testsuite] Test program for ms to sysv abi function calls.

2017-05-17 Thread Thomas Preudhomme

Hi Daniel,

On 27/04/17 09:09, Daniel Santos wrote:

A comprehensive program for testing x86_64 ms_abi functions that call
sysv_abi functions to help validate -mcall-ms2sysv-xlogues and use of
aligned SSE MOVs after a (non-DRAP) realigned stack.

Signed-off-by: Daniel Santos 
---
 gcc/Makefile.in|   2 +
 .../gcc.target/x86_64/abi/ms-sysv/do-test.S| 163 +
 gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/gen.cc | 807 +
 .../gcc.target/x86_64/abi/ms-sysv/ms-sysv.c| 373 ++
 .../gcc.target/x86_64/abi/ms-sysv/ms-sysv.exp  | 178 +
 5 files changed, 1523 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/do-test.S
 create mode 100644 gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/gen.cc
 create mode 100644 gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.c
 create mode 100644 gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.exp



[SNIP]


diff --git a/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.exp 
b/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.exp
new file mode 100644
index 000..e317af9bd85
--- /dev/null
+++ b/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.exp
@@ -0,0 +1,178 @@


[SNIP]


+
+# Exit immediately if this isn't a native x86_64 target.
+if { (![istarget x86_64-*-*] && ![istarget i?86-*-*])
+ || ![is-effective-target lp64] || ![isnative] } then {
+unsupported "$subdir"
+return
+}


This reports these tests as UNSUPPORTED for non x86_64 target rather than just 
not showing these tests. The usual pattern from what I could see is to just 
return (see gcc.target/arm/acle.exp)


Best regards,

Thomas


Re: [PATCH 1/2] x86,s390: add compiler memory barriers when expanding atomic_thread_fence (PR 80640)

2017-05-17 Thread Alexander Monakov
Ping.

(to be clear, patch 2/2 is my previous followup in this thread, I forgot to
adjust the subject line; it should have said:
"[PATCH 2/2] x86: add compiler memory barriers when expanding atomic_load").

On Wed, 10 May 2017, Alexander Monakov wrote:

> Hi,
> 
> When expanding __atomic_thread_fence(x) to RTL, the i386 backend doesn't emit
> any instruction except for x==__ATOMIC_SEQ_CST (which emits 'mfence').  This 
> is incorrect: although no machine barrier is needed, the compiler still must
> emit a compiler barrier into the IR to prevent propagation and code motion
> across the fence.  The testcase added with the patch shows how it can lead
> to a miscompilation.
> 
> The proposed patch fixes it by handling non-seq-cst fences exactly like
> __atomic_signal_fence is expanded, by emitting asm volatile("":::"memory").
> 
> The s390 backend uses the a similar mem_thread_fence expansion, so the patch
> fixes both backends in the same manner.
> 
> Bootstrapped and regtested on x86_64; also checked that s390-linux cc1
> successfully builds after the change.  OK for trunk?
> 
> (the original source code in the PR was misusing atomic fences by doing
> something like
> 
>   void f(int *p)
>   {
> while (*p)
>   __atomic_thread_fence(__ATOMIC_ACQUIRE);
>   }
> 
> but since *p is not atomic, a concurrent write to *p would cause a data race 
> and
> thus invoke undefined behavior; also, if *p is false prior to entering the 
> loop,
> execution does not encounter the fence; new test here has code usable without 
> UB)
> 
> Alexander
> 
>   * config/i386/sync.md (mem_thread_fence): Emit a compiler barrier for
>   non-seq-cst fences.  Adjust comment.
>   * config/s390/s390.md (mem_thread_fence): Likewise.
>   * optabs.c (expand_asm_memory_barrier): Export.
>   * optabs.h (expand_asm_memory_barrier): Declare.
> testsuite/
>   * gcc.target/i386/pr80640-1.c: New testcase.
> ---
>  gcc/config/i386/sync.md   |  7 ++-
>  gcc/config/s390/s390.md   | 11 +--
>  gcc/optabs.c  |  2 +-
>  gcc/optabs.h  |  3 +++
>  gcc/testsuite/gcc.target/i386/pr80640-1.c | 12 
>  5 files changed, 31 insertions(+), 4 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr80640-1.c
> 
> diff --git a/gcc/config/i386/sync.md b/gcc/config/i386/sync.md
> index 20d46fe..619d53b 100644
> --- a/gcc/config/i386/sync.md
> +++ b/gcc/config/i386/sync.md
> @@ -108,7 +108,7 @@ (define_expand "mem_thread_fence"
>enum memmodel model = memmodel_from_int (INTVAL (operands[0]));
>  
>/* Unless this is a SEQ_CST fence, the i386 memory model is strong
> - enough not to require barriers of any kind.  */
> + enough not to require a processor barrier of any kind.  */
>if (is_mm_seq_cst (model))
>  {
>rtx (*mfence_insn)(rtx);
> @@ -124,6 +124,11 @@ (define_expand "mem_thread_fence"
>  
>emit_insn (mfence_insn (mem));
>  }
> +  else if (!is_mm_relaxed (model))
> +{
> +  /* However, a compiler barrier is still required.  */
> +  expand_asm_memory_barrier ();
> +}
>DONE;
>  })
>  
> diff --git a/gcc/config/s390/s390.md b/gcc/config/s390/s390.md
> index c9fd19a..65e54c4 100644
> --- a/gcc/config/s390/s390.md
> +++ b/gcc/config/s390/s390.md
> @@ -10109,14 +10109,21 @@ (define_expand "mem_thread_fence"
>[(match_operand:SI 0 "const_int_operand")] ;; model
>""
>  {
> +  enum memmodel model = memmodel_from_int (INTVAL (operands[0]));
> +
>/* Unless this is a SEQ_CST fence, the s390 memory model is strong
> - enough not to require barriers of any kind.  */
> -  if (is_mm_seq_cst (memmodel_from_int (INTVAL (operands[0]
> + enough not to require a processor barrier of any kind.  */
> +  if (is_mm_seq_cst (model))
>  {
>rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
>MEM_VOLATILE_P (mem) = 1;
>emit_insn (gen_mem_thread_fence_1 (mem));
>  }
> +  else if (!is_mm_relaxed (model))
> +{
> +  /* However, a compiler barrier is still required.  */
> +  expand_asm_memory_barrier ();
> +}
>DONE;
>  })
>  
> diff --git a/gcc/optabs.c b/gcc/optabs.c
> index 48e37f8..1f1fbc3 100644
> --- a/gcc/optabs.c
> +++ b/gcc/optabs.c
> @@ -6269,7 +6269,7 @@ expand_atomic_compare_and_swap (rtx *ptarget_bool, rtx 
> *ptarget_oval,
>  
>  /* Generate asm volatile("" : : : "memory") as the memory barrier.  */
>  
> -static void
> +void
>  expand_asm_memory_barrier (void)
>  {
>rtx asm_op, clob;
> diff --git a/gcc/optabs.h b/gcc/optabs.h
> index b2dd31a..aca6755 100644
> --- a/gcc/optabs.h
> +++ b/gcc/optabs.h
> @@ -322,6 +322,9 @@ extern bool expand_atomic_compare_and_swap (rtx *, rtx *, 
> rtx, rtx, rtx, bool,
>  extern void expand_mem_thread_fence (enum memmodel);
>  extern void expand_mem_signal_fence (enum memmodel);
>  
> +/* Generate a compile-time memory barrier.  */
> +extern void expand

Re: C PATCH to fix ASAN ICE with a compound literal (PR sanitizer/80659)

2017-05-17 Thread Marek Polacek
On Wed, May 17, 2017 at 09:42:08AM +0200, Richard Biener wrote:
> On Tue, 16 May 2017, Marek Polacek wrote:
> 
> > Martin L. asked me to have a look at this ICE with ASAN.  This is an ICE 
> > with a
> > compound literal in a switch.  A hash map gimplify_ctxp->live_switch_vars is
> > filled when processing DECL_EXPRs with their DECL_EXPR_DECLs.  Such decls 
> > should
> > then be removed from the hash map when gimplifying a BIND_EXPR.
> > 
> > In C, non-static compound literals aren't pushed into any scope, so they 
> > were
> > never found by gimplify_bind_expr, so they stayed in the hash map resulting 
> > in
> > a crash on
> >  2299   if (gimplify_ctxp->live_switch_vars)
> >  2300 {
> >  2301   gcc_assert (gimplify_ctxp->live_switch_vars->elements () == 
> > 0);
> >  2302   delete gimplify_ctxp->live_switch_vars;
> >  2303 }
> > 
> > We don't add artificial decls to the hash map:
> >  1647   if (!DECL_ARTIFICIAL (decl) && 
> > gimplify_ctxp->live_switch_vars)
> >  1648 gimplify_ctxp->live_switch_vars->add (decl);
> > 
> > build_compound_literal only marks a decl of a compound literal as artificial
> > when the compound literal is static.  I think there's no harm in marking
> > decls of non-static compound literals as artificial, too (provided it's 
> > fine to
> > skip asan instrumentation of compound literals).
> 
> But probably DECL_IGNORED_P as well at the same time?

Good point.

> > Bootstrapped/regtested on x86_64-linux, ok for trunk?
> 
> Ok with moving that as well (and re-testing).

Thus applying:

Bootstrapped/regtested on x86_64-linux.

2017-05-17  Marek Polacek  

PR sanitizer/80659
* c-decl.c (build_compound_literal): Set DECL_ARTIFICIAL and
DECL_IGNORED_P even for non-static compound literals.

* gcc.dg/asan/pr80659.c: New test.

diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index b779d37..74186da 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -5261,6 +5261,8 @@ build_compound_literal (location_t loc, tree type, tree 
init, bool non_const)
   DECL_CONTEXT (decl) = current_function_decl;
   TREE_USED (decl) = 1;
   DECL_READ_P (decl) = 1;
+  DECL_ARTIFICIAL (decl) = 1;
+  DECL_IGNORED_P (decl) = 1;
   TREE_TYPE (decl) = type;
   TREE_READONLY (decl) = (TYPE_READONLY (type)
  || (TREE_CODE (type) == ARRAY_TYPE
@@ -5297,8 +5299,6 @@ build_compound_literal (location_t loc, tree type, tree 
init, bool non_const)
   set_compound_literal_name (decl);
   DECL_DEFER_OUTPUT (decl) = 1;
   DECL_COMDAT (decl) = 1;
-  DECL_ARTIFICIAL (decl) = 1;
-  DECL_IGNORED_P (decl) = 1;
   pushdecl (decl);
   rest_of_decl_compilation (decl, 1, 0);
 }
diff --git gcc/testsuite/gcc.dg/asan/pr80659.c 
gcc/testsuite/gcc.dg/asan/pr80659.c
index e69de29..0cbf2e4 100644
--- gcc/testsuite/gcc.dg/asan/pr80659.c
+++ gcc/testsuite/gcc.dg/asan/pr80659.c
@@ -0,0 +1,13 @@
+/* PR sanitizer/80659 */
+/* { dg-do compile } */
+
+void
+foo (int a)
+{
+  switch (a)
+{
+case 0:
+  (int[3]) { };
+  int h;
+}
+}

Marek


Trun predicates into a class

2017-05-17 Thread Jan Hubicka
Hi,
this is first patch of series to modularize function analysis done by
ipa-inline and ipa-cp.  This patch turns predicates into a class. It avoids any
code movement or semnatic changes which I will do next.   Main change is to
turn some of functions into operators which makes the code more compact and
hopefully also more readable.

I plan to move them into separate ipa-predicates.c and then breakup rest of
ipa-inline-analysis into part that is independent of inliner (into new
fnsummary pass doing also some work of ipa-prop) and inliner specific analysis.

Bootstrapped/regtested x86_64-linux. I have checked that there is no effect
on code or inline estimates for tramp3d. Will commit it after bit of further 
testing.

Honza

* ipa-inline-analysis.c (predicate_conditions): Move to ipa-inline.h
(true_predicate, false_predicate, true_predicate_p,
false_predicate_p): Remove.
(single_cond_predicate, not_inlined_predicate): Turn to member function
in ipa-inline.h
(add_condition): Update.
(add_clause): Turn to...
(predicate::add_clause): ... this one; update; allow passing NULL
as parameter.
(and_predicates): Turn to ...
(predicate::operator &=): ... this one.
(predicates_equal_p): Move to predicate::operator == in ipa-inline.h
(or_predicates): Turn to ...
(predicate::or_with): ... this one.
(evaluate_predicate): Turn to ...
(predicate::evaluate): ... this one.
(predicate_probability): Turn to ...
(predicate::probability): ... this one.
(dump_condition): Update.
(dump_predicate): Turn to ...
(predicate::dump): ... this one.
(account_size_time): Update.
(edge_set_predicate): Update.
(set_hint_predicate): UPdate.
(evaluate_conditions_for_known_args): Update.
(evaluate_properties_for_edge): Update.
(remap_predicate_after_duplication): Turn to...
(predicate::remap_after_duplication): ... this one.
(remap_hint_predicate_after_duplication): Update.
(inline_summary_t::duplicate): UPdate.
(dump_inline_edge_summary): Update.
(dump_inline_summary): Update.
(set_cond_stmt_execution_predicate): Update.
(set_switch_stmt_execution_predicate): Update.
(compute_bb_predicates): Update.
(will_be_nonconstant_expr_predicate): Update.
(will_be_nonconstant_predicate): Update.
(phi_result_unknown_predicate): Update.
(predicate_for_phi_result): Update.
(array_index_predicate): Update.
(estimate_function_body_sizes): Update.
(estimate_node_size_and_time): Update.
(estimate_ipcp_clone_size_and_time): Update.
(remap_predicate): Rename to ...
(predicate::remap_after_inlining): ... this one.
(remap_hint_predicate): Update.
(inline_merge_summary): Update.
(inline_update_overall_summary): Update.
(estimate_size_after_inlining): Update.
(read_predicate): Rename to ...
(predicate::stream_in): ... this one.
(read_inline_edge_summary): Update.
(write_predicate): Rename to ...
(predicate::stream_out): ... this one.
(write_inline_edge_summary): Update.
* ipa-inline.h (MAX_CLAUSES): Turn to predicate::max_clauses.
(clause_t): Turn to uint32_t
(predicate): Turn to class; implement constructor and operators
==, !=, &
(size_time_entry): Update.
(inline_summary): Update.
(inline_edge_summary): Update.

Index: ipa-inline-analysis.c
===
--- ipa-inline-analysis.c   (revision 248142)
+++ ipa-inline-analysis.c   (working copy)
@@ -44,17 +44,7 @@ along with GCC; see the file COPYING3.
It is easy to add more variants.  To represent function size and time
that depends on context (i.e. it is known to be optimized away when
context is known either by inlining or from IP-CP and cloning),
-   we use predicates. Predicates are logical formulas in
-   conjunctive-disjunctive form consisting of clauses. Clauses are bitmaps
-   specifying what conditions must be true. Conditions are simple test
-   of the form described above.
-
-   In order to make predicate (possibly) true, all of its clauses must
-   be (possibly) true. To make clause (possibly) true, one of conditions
-   it mentions must be (possibly) true.  There are fixed bounds on
-   number of clauses and conditions and all the manipulation functions
-   are conservative in positive direction. I.e. we may lose precision
-   by thinking that predicate may be true even when it is not.
+   we use predicates.
 
estimate_edge_size and estimate_edge_growth can be used to query
function size/time in the given context.  inline_merge_summary merges
@@ -100,13 +90,6 @@ along with GCC; see the file COPYING3.
hosts.  */
 #define NUM_

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-17 Thread Pedro Alves
On 05/17/2017 02:55 AM, Martin Sebor wrote:
> On 05/16/2017 04:48 PM, Pedro Alves wrote:
>> On 05/16/2017 08:41 PM, Jason Merrill wrote:
>>
>>> I agree that it makes sense to
>>> check for a trivial assignment operator specifically.  I guess we want
>>> a slightly stronger "trivially copyable" that also requires a
>>> non-deleted assignment operator.
>>>
>>> It seems to me that the relevant tests are:
>>>
>>> bcopy/memcpy/memmove want trivally copyable + non-deleted assignment.
>>> bzero/memset want trivial + non-deleted assignment.
>>>
>>> I'm still not convinced we need to consider standard-layout at all.
>>
>> What do you think of warning for memset of types with references? 

Having slept, I now realize you had that covered already by the
"non-deleted assignment" requirement...  A reference data member
makes the assignment operator be implicitly deleted.  Sorry for the noise.

>> While at it, maybe the same reasoning would justify warn of memcpy/memset
>> of types with const data members?  

Ditto.

> I did this because objects with references cannot be assigned
> to (the default copy assignment is deleted).  So as a baseline
> rule, I made the warning trigger whenever a native assignment
> or copy isn't valid.  In the IMO unlikely event that a memcpy
> over a reference is intended, the warning is easy to suppress.

Agreed.

I wondered whether we'll end up wanting to distinguish these cases:

#1memcpy (T *, const T *src, size_t n);
#2.1  memcpy (T *, const char *src, size_t n);  // char, void, std::byte...
#2.2  memcpy (char *, const T *src, size_t n);  // char, void, std::byte...
#3memcpy (T *, const U *src, size_t n);

Where:
- T is a trivially copyable type that still triggers the new warning.
- U is a type unrelated to T, and is not (unsigned) char, void or std::byte.

#1 is the case that looks like copy.

#2.1 and 2.2 may well appear in type-erasing code.

#3 would look like a way to work around aliasing issues and (even though
ISTR that it's OK as GNU extension if T and U are trivial) worthy of a
warning even if T is trivial under the definition of the warning.
Reading your updated patch, I see that you warn already when T is trivial
and U is not trivial, but IIUC, not if U is also trivial, even if
unrelated to T.  Anyway, I don't really want to argue about this -- I
started writing this paragraph before actually reading the patch, and
then actually read the patch and was pleasantly surprised with what
I saw.   I think it's looking great.

> I used a similar (though not exactly the same) rationale for
> warning for const members.  They too cannot be assigned to,
> and letting memset or memcpy silently change them violates
> const-correctnes. 

*Nod*

> It's also undefined 

I'm not sure, I think there may be nuances, as usual.  AFAICS, it's generally
valid to memcpy into trivially copyable types that have const members to/from
untyped/char storage, AFAICS.  Might need to apply std::launder afterwards.  
But it
isn't clear to me, since whether memcpy starts a (trivial) object's lifetime is
up in the air, AFAIK.  But I'm not suggesting to really consider that.  The rare
specialized code will be able to work around the spurious warning.

> and the immutability
> of such members an optimization opportunity waiting to be
> exploited.
> 

*nod*

>>> +Wnon-trivial-memaccess
>>> +C++ ObjC++ Var(warn_nontrival_memaccess) Warning LangEnabledBy(C++
>>> ObjC++, Wall)
>>> +Warn for raw memory writes to objects of non-trivial types.
>>
>> May I suggest renaming the warning (and the description above) from
>> -Wnon-trivial-memaccess to something else that avoids "trivial" in
>> its name?  Because it's no longer strictly about "trivial" in the
>> standard C++ sense.  The documentation talks about "The safe way",
>> and "does not warn on safe calls", so maybe call it -Wunsafe-memaccess?
> 
> I debated whether to rename things (not just the warning but
> also the function that implements it in GCC).  Ultimately I
> decided it wasn't necessary because the rules seem close enough
> to be based on some notion of triviality and because no better
> name came to mind. -Wunsafe-memaccess might work.  The one mild
> concern I have with it is that it could suggest it might do more
> than simple type checking (e.g., buffer overflow and what not).
> Let's see what Jason thinks.

Yet another motivation of avoiding "trivial" that crossed my mind is that
you may want to enable the warning in C too, e.g., for warning about
the memcpy of types with const members.  But C as no concept
of "trivial", everything is "trivial".

>> (I spotted a couple typos in the new patch: "otherwse", "becase", btw.)
> 
> I'm a horrible typist.  I'll proofread the patch again and fix
> them up before committing it.

Thanks much for working on this.  I think this will uncover lots of
latent bugs in many codebases.  Looking forward to have this in.

Thanks,
Pedro Alves



[C++ PATCH] OVERLOAD iterators #4

2017-05-17 Thread Nathan Sidwell
This patch converts pieces of class member function handling.  Plus a 
couple of constraint pieces and an address-of where we wrap an fn in an 
overload.


nathan
--
Nathan Sidwell
2017-05-17  Nathan Sidwell  

	* class.c (handle_using_decl): Use OVL_FIRST, ovl_iterator.
	(maybe_warn_about_overly_private_class): Use ovl_iterator.
	(method_name_cmp, resort_method_name_cmp): Use OVL_NAME.
	(resort_type_method_vec, finish_struct_methods): Use OVL_FIRST.
	(get_base_fndecls): Use ovl_iterator.
	(warn_hidden): Use OVL_NAME, ovl_iterator.
	(add_implicitly_declared_members): Use ovl_iterator.
	* constraint.cc (normalize_template_id_expression): Use OVL_FIRST,
	flatten nested if.
	(finish_shorthand_constraint): Simplify, use ovl_make.
	* pt.c (make_constrained_auto): Simplify.  Use ovl_make.
	* search.c (shared_member_p): Use ovl_iterator.
	(lookup_field_fuzzy_info::fuzzy_lookup_fn): Use OVL_NAME.
	(lookup_conversion_operator): Use OVL_FIRST.
	(lookup_fnfiels_idx_nolazy): Use OVL_FIRST, OVL_NAME.
	(look_for_overrides_here): Use ovl_iterator.
	(lookup_conversions_r): Use OVL_FIRST, OVL_NAME, ovl_iterator.
	* typeck.c (build_x_unary_op): Use ovl_make.

Index: class.c
===
--- class.c	(revision 248127)
+++ class.c	(working copy)
@@ -1359,7 +1359,7 @@ handle_using_decl (tree using_decl, tree
 			 tf_warning_or_error);
   if (old_value)
 {
-  old_value = OVL_CURRENT (old_value);
+  old_value = OVL_FIRST (old_value);
 
   if (DECL_P (old_value) && DECL_CONTEXT (old_value) == t)
 	/* OK */;
@@ -1396,10 +1396,10 @@ handle_using_decl (tree using_decl, tree
 
   /* Make type T see field decl FDECL with access ACCESS.  */
   if (flist)
-for (; flist; flist = OVL_NEXT (flist))
+for (ovl_iterator iter (flist); iter; ++iter)
   {
-	add_method (t, OVL_CURRENT (flist), using_decl);
-	alter_access (t, OVL_CURRENT (flist), access);
+	add_method (t, *iter, true);
+	alter_access (t, *iter, access);
   }
   else
 alter_access (t, decl, access);
@@ -2245,7 +2245,7 @@ maybe_warn_about_overly_private_class (t
   && (!CLASSTYPE_LAZY_DEFAULT_CTOR (t)
 	  || !CLASSTYPE_LAZY_COPY_CTOR (t)))
 {
-  int nonprivate_ctor = 0;
+  bool nonprivate_ctor = false;
 
   /* If a non-template class does not define a copy
 	 constructor, one is defined for it, enabling it to avoid
@@ -2258,25 +2258,20 @@ maybe_warn_about_overly_private_class (t
 	 complete non-template or fully instantiated classes have this
 	 flag set.  */
   if (!TYPE_HAS_COPY_CTOR (t))
-	nonprivate_ctor = 1;
+	nonprivate_ctor = true;
   else
-	for (fn = CLASSTYPE_CONSTRUCTORS (t); fn; fn = OVL_NEXT (fn))
-	  {
-	tree ctor = OVL_CURRENT (fn);
-	/* Ideally, we wouldn't count copy constructors (or, in
-	   fact, any constructor that takes an argument of the
-	   class type as a parameter) because such things cannot
-	   be used to construct an instance of the class unless
-	   you already have one.  But, for now at least, we're
-	   more generous.  */
-	if (! TREE_PRIVATE (ctor))
-	  {
-		nonprivate_ctor = 1;
-		break;
-	  }
-	  }
+	for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t));
+	 !nonprivate_ctor && iter; ++iter)
+	  /* Ideally, we wouldn't count copy constructors (or, in
+	 fact, any constructor that takes an argument of the class
+	 type as a parameter) because such things cannot be used
+	 to construct an instance of the class unless you already
+	 have one.  But, for now at least, we're more
+	 generous.  */
+	  if (! TREE_PRIVATE (*iter))
+	nonprivate_ctor = true;
 
-  if (nonprivate_ctor == 0)
+  if (!nonprivate_ctor)
 	{
 	  warning (OPT_Wctor_dtor_privacy,
 		   "%q#T only defines private constructors and has no friends",
@@ -2305,7 +2300,7 @@ method_name_cmp (const void* m1_p, const
 return -1;
   if (*m2 == NULL_TREE)
 return 1;
-  if (DECL_NAME (OVL_CURRENT (*m1)) < DECL_NAME (OVL_CURRENT (*m2)))
+  if (OVL_NAME (*m1) < OVL_NAME (*m2))
 return -1;
   return 1;
 }
@@ -2325,8 +2320,8 @@ resort_method_name_cmp (const void* m1_p
   if (*m2 == NULL_TREE)
 return 1;
   {
-tree d1 = DECL_NAME (OVL_CURRENT (*m1));
-tree d2 = DECL_NAME (OVL_CURRENT (*m2));
+tree d1 = OVL_NAME (*m1);
+tree d2 = OVL_NAME (*m2);
 resort_data.new_value (&d1, resort_data.cookie);
 resort_data.new_value (&d2, resort_data.cookie);
 if (d1 < d2)
@@ -2353,7 +2348,7 @@ resort_type_method_vec (void* obj,
   for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT;
vec_safe_iterate (method_vec, slot, &fn);
++slot)
-if (!DECL_CONV_FN_P (OVL_CURRENT (fn)))
+if (!DECL_CONV_FN_P (OVL_FIRST (fn)))
   break;
 
   if (len - slot > 1)
@@ -2398,7 +2393,7 @@ finish_struct_methods (tree t)
   for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT;
method_vec->iterate (slot, &fn_fields);
++slot)
-if (!DECL_CONV_FN_P (OVL_CURRENT (fn_fields)))
+if

[PATCH] Fix PR80754

2017-05-17 Thread Wilco Dijkstra
When lra-remat rematerializes an instruction with a clobber, it checks
that the clobber does not kill live registers.  However it fails to check
that the clobber also doesn't overlap with the destination register of the 
final rematerialized instruction.  As a result it is possible to generate
illegal instructions with the same hard register as the destination and a
clobber.  Fix this by also checking for overlaps with the destination
register.

Bootstrap OK on arm-linux-gnueabihf for ARM and Thumb-2, OK for commit?

ChangeLog:
2017-05-16  Wilco Dijkstra  

PR rtl-optimization/80754
* lra-remat.c (do_remat): Add overlap checks for dst_regno.

--
diff --git a/gcc/lra-remat.c b/gcc/lra-remat.c
index 
2c51481374ac1f641ac163d345f2865c5536ef21..5cba7412d79a166f36424ada4e22c3acc9a571d5
 100644
--- a/gcc/lra-remat.c
+++ b/gcc/lra-remat.c
@@ -1122,6 +1122,7 @@ do_remat (void)
  break;
}
  int i, hard_regno, nregs;
+ int dst_hard_regno, dst_nregs;
  rtx_insn *remat_insn = NULL;
  HOST_WIDE_INT cand_sp_offset = 0;
  if (cand != NULL)
@@ -1136,6 +1137,12 @@ do_remat (void)
  gcc_assert (REG_P (saved_op));
  int ignore_regno = REGNO (saved_op); 
 
+ dst_hard_regno = dst_regno < FIRST_PSEUDO_REGISTER
+   ? dst_regno : reg_renumber[dst_regno];
+ gcc_assert (dst_hard_regno >= 0);
+ machine_mode mode = GET_MODE (SET_DEST (set));
+ dst_nregs = hard_regno_nregs[dst_hard_regno][mode];
+
  for (reg = cand_id->regs; reg != NULL; reg = reg->next)
if (reg->type != OP_IN && reg->regno != ignore_regno)
  {
@@ -1146,6 +1153,10 @@ do_remat (void)
break;
if (i < nregs)
  break;
+   /* Ensure the clobber also doesn't overlap dst_regno.  */
+   if (hard_regno + nregs > dst_hard_regno
+   && hard_regno < dst_hard_regno + dst_nregs)
+ break;
  }
 
  if (reg == NULL)
@@ -1153,9 +1164,14 @@ do_remat (void)
  for (reg = static_cand_id->hard_regs;
   reg != NULL;
   reg = reg->next)
-   if (reg->type != OP_IN
-   && TEST_HARD_REG_BIT (live_hard_regs, reg->regno))
- break;
+   if (reg->type != OP_IN)
+ {
+   if (TEST_HARD_REG_BIT (live_hard_regs, reg->regno))
+ break;
+   if (reg->regno >= dst_hard_regno
+   && reg->regno < dst_hard_regno + dst_nregs)
+ break;
+ }
}
 
  if (reg == NULL)

Re: [gomp4] backport misc OMP 4.5 changes from trunk

2017-05-17 Thread Thomas Schwinge
Hi!

On Wed, 15 Mar 2017 07:21:26 -0700, Cesar Philippidis  
wrote:
> This patch backports Jakub's Fortran OMP 4.5 changes to gomp-4_0-branch.
> The original patch may be found here
> . I've applied
> it to gomp-4_0-branch.

> --- a/gcc/fortran/openmp.c
> +++ b/gcc/fortran/openmp.c

> @@ -835,6 +1122,19 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, uint64_t 
> mask,

> +   if ((mask & OMP_CLAUSE_DELETE)
> +   && gfc_match ("delete ( ") == MATCH_YES
> +   && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
> +OMP_MAP_DELETE, openacc,
> +allow_derived))
> + continue;

I noticed that in that backport, the handling of the OpenACC delete
clause (harmlessly) got duplicated.  Cleaned up on gomp-4_0-branch in
r248146:

commit 3463026a7bfd6e704454d3ce8489d3b6b5295ab5
Author: tschwinge 
Date:   Wed May 17 11:37:00 2017 +

Clean up handling of Fortran OpenACC delete clause

gcc/fortran/
* openmp.c (gfc_match_omp_clauses): Handle "OMP_CLAUSE_DELETE"
just once.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@248146 
138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/fortran/ChangeLog.gomp | 5 +
 gcc/fortran/openmp.c   | 7 +--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git gcc/fortran/ChangeLog.gomp gcc/fortran/ChangeLog.gomp
index 0f7c5d2..03bc82e 100644
--- gcc/fortran/ChangeLog.gomp
+++ gcc/fortran/ChangeLog.gomp
@@ -1,3 +1,8 @@
+2017-05-17  Thomas Schwinge  
+
+   * openmp.c (gfc_match_omp_clauses): Handle "OMP_CLAUSE_DELETE"
+   just once.
+
 2017-05-16  Chung-Lin Tang  
 
* gfortran.h (struct gfc_omp_clauses): Add 'finalize:1' bitfield.
diff --git gcc/fortran/openmp.c gcc/fortran/openmp.c
index 1734b7c..0992f0a 100644
--- gcc/fortran/openmp.c
+++ gcc/fortran/openmp.c
@@ -1117,11 +1117,6 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, omp_mask 
mask,
continue;
  break;
case 'd':
- if ((mask & OMP_CLAUSE_DELETE)
- && gfc_match ("delete ( ") == MATCH_YES
- && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
-  OMP_MAP_DELETE, true, allow_derived))
-   continue;
  if ((mask & OMP_CLAUSE_DEFAULT)
  && c->default_sharing == OMP_DEFAULT_UNKNOWN)
{
@@ -1154,7 +1149,7 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, omp_mask 
mask,
  if ((mask & OMP_CLAUSE_DELETE)
  && gfc_match ("delete ( ") == MATCH_YES
  && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
-  OMP_MAP_DELETE, openacc,
+  OMP_MAP_DELETE, true,
   allow_derived))
continue;
  if ((mask & OMP_CLAUSE_DEPEND)


Grüße
 Thomas


Re: [gomp4] Implement OpenACC 2.5 reference counting, and finalize clause

2017-05-17 Thread Thomas Schwinge
Hi!

On Tue, 16 May 2017 20:55:46 +0800, Chung-Lin Tang  
wrote:
> finalize clause of the exit data directive

The OpenACC front end code currently maps the OpenACC delete clause to
"OMP_CLAUSE_DELETE" -- however, without a finalize clause, this clause
actually has "OMP_CLAUSE_RELEASE" semantics.  Committed to
gomp-4_0-branch in r248147:

commit 09ce4545696d19c65a552098187184f179096b45
Author: tschwinge 
Date:   Wed May 17 11:46:53 2017 +

Use "GOMP_MAP_RELEASE" for OpenACC delete clause without finalize clause

gcc/c/
* c-parser.c (c_parser_oacc_data_clause)
: Use "GOMP_MAP_RELEASE".
gcc/cp/
* parser.c (cp_parser_oacc_data_clause)
: Use "GOMP_MAP_RELEASE".
gcc/fortran/
* openmp.c (gfc_match_omp_clauses) : Use
"OMP_MAP_RELEASE".
gcc/
* gimplify.c (gimplify_oacc_declare_1) : Use
"GOMP_MAP_RELEASE".
libgomp/
* oacc-parallel.c (GOACC_enter_exit_data, GOACC_declare): Handle
"GOMP_MAP_RELEASE".

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@248147 
138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog.gomp | 5 +
 gcc/c/ChangeLog.gomp   | 5 +
 gcc/c/c-parser.c   | 2 +-
 gcc/cp/ChangeLog.gomp  | 5 +
 gcc/cp/parser.c| 2 +-
 gcc/fortran/ChangeLog.gomp | 3 +++
 gcc/fortran/openmp.c   | 2 +-
 gcc/gimplify.c | 2 +-
 libgomp/ChangeLog.gomp | 5 +
 libgomp/oacc-parallel.c| 5 -
 10 files changed, 31 insertions(+), 5 deletions(-)

diff --git gcc/ChangeLog.gomp gcc/ChangeLog.gomp
index 77c7899..e858e78 100644
--- gcc/ChangeLog.gomp
+++ gcc/ChangeLog.gomp
@@ -1,3 +1,8 @@
+2017-05-17  Thomas Schwinge  
+
+   * gimplify.c (gimplify_oacc_declare_1) : Use
+   "GOMP_MAP_RELEASE".
+
 2017-05-16  Cesar Philippidis  
 
* doc/include/texinfo.tex: Backport @title linewrap changes from
diff --git gcc/c/ChangeLog.gomp gcc/c/ChangeLog.gomp
index eca8379..c70003f 100644
--- gcc/c/ChangeLog.gomp
+++ gcc/c/ChangeLog.gomp
@@ -1,3 +1,8 @@
+2017-05-17  Thomas Schwinge  
+
+   * c-parser.c (c_parser_oacc_data_clause)
+   : Use "GOMP_MAP_RELEASE".
+
 2017-05-16  Chung-Lin Tang  
 
* c-parser.c (c_parser_omp_clause_name):  Handle 'finalize' clause.
diff --git gcc/c/c-parser.c gcc/c/c-parser.c
index 17045ef..34f8b17 100644
--- gcc/c/c-parser.c
+++ gcc/c/c-parser.c
@@ -10805,7 +10805,7 @@ c_parser_oacc_data_clause (c_parser *parser, 
pragma_omp_clause c_kind,
   kind = GOMP_MAP_ALLOC;
   break;
 case PRAGMA_OACC_CLAUSE_DELETE:
-  kind = GOMP_MAP_DELETE;
+  kind = GOMP_MAP_RELEASE;
   break;
 case PRAGMA_OACC_CLAUSE_DEVICE:
   kind = GOMP_MAP_FORCE_TO;
diff --git gcc/cp/ChangeLog.gomp gcc/cp/ChangeLog.gomp
index 3fa64ee..9a68194 100644
--- gcc/cp/ChangeLog.gomp
+++ gcc/cp/ChangeLog.gomp
@@ -1,3 +1,8 @@
+2017-05-17  Thomas Schwinge  
+
+   * parser.c (cp_parser_oacc_data_clause)
+   : Use "GOMP_MAP_RELEASE".
+
 2017-05-16  Chung-Lin Tang  
 
* parser.c (cp_parser_omp_clause_name): Handle 'finalize' clause.
diff --git gcc/cp/parser.c gcc/cp/parser.c
index c0fe65d..cbb11d0 100644
--- gcc/cp/parser.c
+++ gcc/cp/parser.c
@@ -30222,7 +30222,7 @@ cp_parser_oacc_data_clause (cp_parser *parser, 
pragma_omp_clause c_kind,
   kind = GOMP_MAP_ALLOC;
   break;
 case PRAGMA_OACC_CLAUSE_DELETE:
-  kind = GOMP_MAP_DELETE;
+  kind = GOMP_MAP_RELEASE;
   break;
 case PRAGMA_OACC_CLAUSE_DEVICE:
   kind = GOMP_MAP_FORCE_TO;
diff --git gcc/fortran/ChangeLog.gomp gcc/fortran/ChangeLog.gomp
index 03bc82e..b3e4f8d 100644
--- gcc/fortran/ChangeLog.gomp
+++ gcc/fortran/ChangeLog.gomp
@@ -1,5 +1,8 @@
 2017-05-17  Thomas Schwinge  
 
+   * openmp.c (gfc_match_omp_clauses) : Use
+   "OMP_MAP_RELEASE".
+
* openmp.c (gfc_match_omp_clauses): Handle "OMP_CLAUSE_DELETE"
just once.
 
diff --git gcc/fortran/openmp.c gcc/fortran/openmp.c
index 0992f0a..1d191d2 100644
--- gcc/fortran/openmp.c
+++ gcc/fortran/openmp.c
@@ -1149,7 +1149,7 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, omp_mask 
mask,
  if ((mask & OMP_CLAUSE_DELETE)
  && gfc_match ("delete ( ") == MATCH_YES
  && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
-  OMP_MAP_DELETE, true,
+  OMP_MAP_RELEASE, true,
   allow_derived))
continue;
  if ((mask & OMP_CLAUSE_DEPEND)
diff --git gcc/gimplify.c gcc/gimplify.c
index e6cdadc..7812471 100644
--- gcc/gimplify.c
+++ gcc/gimplify.c
@@ -8593,7 +8593,7 @@ gimplify_oacc_declare_1 (tree clause)
   switch (kind)
 {
   case GOMP_MAP_ALLOC:
-   new_op = GOMP_MAP_DELETE;
+   new_op = GOMP_MAP_RELEASE;
ret = true;
break;
 
diff --git libgomp/ChangeLog.

Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)

2017-05-17 Thread Pedro Alves
[Meant to add this to the other email, but forgot to copy it back.]

On 05/12/2017 03:31 AM, Martin Sebor wrote:
> +  // Zeroing out is diagnosed only because it's difficult not to.
> +  // Otherwise, a class that's non-trivial only because it has
> +  // a non-trivial dtor can be safely zeroed out (that's what
> +  // default-initializing it does).

FWIW, I found references like these to "default initialization" confusing,
until I realized you're likely talking about default initialization in
pre-C++11 terms.  I.e., "new T()" with parens.   I first assumed you're
talking about default initialization like "new T;" or "T t;", but in
that case the object would not the zeroed out, hence the confusion.
It may be beneficial to go over the comments in the patch (and
particularly documentation) and talk in C++11 (and later)
terms -- i.e., say "value-initializing it" instead.

> +  T (bzero, (p, sizeof *p));// { dg-warning "bzero" }
> +  T (memset, (p, 0, sizeof *p));// { dg-warning "memset" }
> +  T (memset, (p, i, sizeof *p));// { dg-warning "memset" }

Thanks,
Pedro Alves



Re: [gomp4] Implement OpenACC 2.5 reference counting, and finalize clause

2017-05-17 Thread Thomas Schwinge
Hi!

On Tue, 16 May 2017 20:55:46 +0800, Chung-Lin Tang  
wrote:
> finalize clause of the exit data directive

This would run into ICEs in the C++ front end (template handling) as well
as C and Fortran front ends (nested function handling), and didn't
pretty-print the "finalize" clause.  Also test cases.  Committed to
gomp-4_0-branch in r248148:

commit 2d734ec8526f73e69c7bfa9b60ec5e9c5a9e4f13
Author: tschwinge 
Date:   Wed May 17 11:52:15 2017 +

Complete compiler-side handling of the OpenACC finalize clause

gcc/cp/
* pt.c (tsubst_omp_clauses): Handle "OMP_CLAUSE_FINALIZE".
gcc/
* tree-nested.c (convert_nonlocal_omp_clauses)
(convert_local_omp_clauses): Handle "OMP_CLAUSE_FINALIZE".
* tree-pretty-print.c (dump_omp_clause): Handle
"OMP_CLAUSE_FINALIZE".
gcc/testsuite/
* c-c++-common/goacc/data-2.c: Update.
* g++.dg/goacc/template.C: Likewise.
* gcc.dg/goacc/nested-function-1.c: Likewise.
* gfortran.dg/goacc/enter-exit-data.f95: Likewise.
* gfortran.dg/goacc/nested-function-1.f90: Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@248148 
138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog.gomp| 5 +
 gcc/cp/ChangeLog.gomp | 2 ++
 gcc/cp/pt.c   | 1 +
 gcc/testsuite/ChangeLog.gomp  | 8 
 gcc/testsuite/c-c++-common/goacc/data-2.c | 3 +++
 gcc/testsuite/g++.dg/goacc/template.C | 9 +
 gcc/testsuite/gcc.dg/goacc/nested-function-1.c| 4 
 gcc/testsuite/gfortran.dg/goacc/enter-exit-data.f95   | 3 +++
 gcc/testsuite/gfortran.dg/goacc/nested-function-1.f90 | 4 
 gcc/tree-nested.c | 2 ++
 gcc/tree-pretty-print.c   | 3 +++
 11 files changed, 44 insertions(+)

diff --git gcc/ChangeLog.gomp gcc/ChangeLog.gomp
index e858e78..d89897d 100644
--- gcc/ChangeLog.gomp
+++ gcc/ChangeLog.gomp
@@ -1,5 +1,10 @@
 2017-05-17  Thomas Schwinge  
 
+   * tree-nested.c (convert_nonlocal_omp_clauses)
+   (convert_local_omp_clauses): Handle "OMP_CLAUSE_FINALIZE".
+   * tree-pretty-print.c (dump_omp_clause): Handle
+   "OMP_CLAUSE_FINALIZE".
+
* gimplify.c (gimplify_oacc_declare_1) : Use
"GOMP_MAP_RELEASE".
 
diff --git gcc/cp/ChangeLog.gomp gcc/cp/ChangeLog.gomp
index 9a68194..b0c3dbf 100644
--- gcc/cp/ChangeLog.gomp
+++ gcc/cp/ChangeLog.gomp
@@ -1,5 +1,7 @@
 2017-05-17  Thomas Schwinge  
 
+   * pt.c (tsubst_omp_clauses): Handle "OMP_CLAUSE_FINALIZE".
+
* parser.c (cp_parser_oacc_data_clause)
: Use "GOMP_MAP_RELEASE".
 
diff --git gcc/cp/pt.c gcc/cp/pt.c
index 84f64d8..abe8d36 100644
--- gcc/cp/pt.c
+++ gcc/cp/pt.c
@@ -14751,6 +14751,7 @@ tsubst_omp_clauses (tree clauses, enum 
c_omp_region_type ort,
case OMP_CLAUSE_AUTO:
case OMP_CLAUSE_SEQ:
case OMP_CLAUSE_IF_PRESENT:
+   case OMP_CLAUSE_FINALIZE:
case OMP_CLAUSE_DEVICE_TYPE:
  break;
case OMP_CLAUSE_BIND:
diff --git gcc/testsuite/ChangeLog.gomp gcc/testsuite/ChangeLog.gomp
index 34f0a06..960ad15 100644
--- gcc/testsuite/ChangeLog.gomp
+++ gcc/testsuite/ChangeLog.gomp
@@ -1,3 +1,11 @@
+2017-05-17  Thomas Schwinge  
+
+   * c-c++-common/goacc/data-2.c: Update.
+   * g++.dg/goacc/template.C: Likewise.
+   * gcc.dg/goacc/nested-function-1.c: Likewise.
+   * gfortran.dg/goacc/enter-exit-data.f95: Likewise.
+   * gfortran.dg/goacc/nested-function-1.f90: Likewise.
+
 2017-05-15  Thomas Schwinge  
 
* c-c++-common/cpp/openacc-define-3.c: Update.
diff --git gcc/testsuite/c-c++-common/goacc/data-2.c 
gcc/testsuite/c-c++-common/goacc/data-2.c
index 1043bf8a..8c5d42a 100644
--- gcc/testsuite/c-c++-common/goacc/data-2.c
+++ gcc/testsuite/c-c++-common/goacc/data-2.c
@@ -10,6 +10,9 @@ foo (void)
 #pragma acc exit data delete (a) if (0)
 #pragma acc exit data copyout (b) if (a)
 #pragma acc exit data delete (b)
+#pragma acc exit data delete (a) if (!0) finalize
+#pragma acc exit data copyout (b) finalize if (!a)
+#pragma acc exit data finalize delete (b)
 #pragma acc enter /* { dg-error "expected 'data' after" } */
 #pragma acc exit /* { dg-error "expected 'data' after" } */
 #pragma acc enter data /* { dg-error "has no data movement clause" } */
diff --git gcc/testsuite/g++.dg/goacc/template.C 
gcc/testsuite/g++.dg/goacc/template.C
index f4d255c..d1acece 100644
--- gcc/testsuite/g++.dg/goacc/template.C
+++ gcc/testsuite/g++.dg/goacc/template.C
@@ -86,6 +86,8 @@ oacc_parallel_copy (T a)
 #pragma acc update self (b)
 #pragma acc update device (b)
 #pragma acc exit data delete (b)
+#pragma acc exit data finalize copyout (b)
+#pragma acc exit data delete (b) finalize
 
   return b;
 }
@@ -133,6 +135,13 @@ oacc_kernel

Re: [gomp4] Implement OpenACC 2.5 reference counting, and finalize clause

2017-05-17 Thread Thomas Schwinge
Hi!

On Tue, 16 May 2017 20:55:46 +0800, Chung-Lin Tang  
wrote:
> finalize clause of the exit data directive

Thanks!

> --- libgomp/oacc-parallel.c   (revision 248095)
> +++ libgomp/oacc-parallel.c   (revision 248096)

>  void
>  GOACC_enter_exit_data (int device, size_t mapnum,
>  void **hostaddrs, size_t *sizes, unsigned short *kinds,
> -int async, int num_waits, ...)
> +int async, int finalize, int num_waits, ...)

> --- gcc/omp-low.c (revision 248095)
> +++ gcc/omp-low.c (revision 248096)

> @@ -14216,6 +14218,13 @@
>   if (t_async)
> args.safe_push (t_async);
>  
> + if (start_ix == BUILT_IN_GOACC_ENTER_EXIT_DATA)
> +   {
> + c = find_omp_clause (clauses, OMP_CLAUSE_FINALIZE);
> + tree t_finalize = c ? integer_one_node : integer_zero_node;
> + args.safe_push (t_finalize);
> +   }
> +
>   /* Save the argument index, and ... */
>   unsigned t_wait_idx = args.length ();
>   unsigned num_waits = 0;

This breaks the ABI.  (Also this didn't update
gcc/omp-builtins.def:BUILT_IN_GOACC_ENTER_EXIT_DATA.  If I remember
correctly, I noted before that we really should add some consistency
checking for definition vs. usage of builtin functions.)

So I changed that to do similar to what Cesar recently had done for the
OpenACC update construct's if_present clause, and also added test cases.
Committed to gomp-4_0-branch in r248149:

commit 98cb728fdc1d848b3beadae5a81b663a30915925
Author: tschwinge 
Date:   Wed May 17 12:03:00 2017 +

Revert GOACC_enter_exit_data ABI change

Instead, use GOMP_MAP_DELETE/GOMP_MAP_FORCE_FROM to denote that "finalize"
semantics apply to all mappings of this OpenACC directive.

gcc/
* omp-low.c (expand_omp_target): Revert GOACC_enter_exit_data ABI
change.
* gimplify.c (gimplify_omp_target_update): Handle
OMP_CLAUSE_FINALIZE for OACC_EXIT_DATA.
gcc/testsuite/
* c-c++-common/goacc/finalize-1.c: New file.
* gfortran.dg/goacc/finalize-1.f: Likewise.
libgomp/
* oacc-parallel.c (GOACC_enter_exit_data): Locally compute
"finalize", and remove the formal parameter.  Adjust all users.
(GOACC_declare): Don't replace GOMP_MAP_FROM with
GOMP_MAP_FORCE_FROM.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@248149 
138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog.gomp|  5 +
 gcc/gimplify.c| 27 ++
 gcc/omp-low.c |  7 ---
 gcc/testsuite/ChangeLog.gomp  |  3 +++
 gcc/testsuite/c-c++-common/goacc/finalize-1.c | 28 +++
 gcc/testsuite/gfortran.dg/goacc/finalize-1.f  | 27 ++
 libgomp/ChangeLog.gomp|  5 +
 libgomp/libgomp_g.h   |  2 +-
 libgomp/oacc-parallel.c   | 22 +++--
 9 files changed, 112 insertions(+), 14 deletions(-)

diff --git gcc/ChangeLog.gomp gcc/ChangeLog.gomp
index d89897d..084ac9b 100644
--- gcc/ChangeLog.gomp
+++ gcc/ChangeLog.gomp
@@ -1,5 +1,10 @@
 2017-05-17  Thomas Schwinge  
 
+   * omp-low.c (expand_omp_target): Revert GOACC_enter_exit_data ABI
+   change.
+   * gimplify.c (gimplify_omp_target_update): Handle
+   OMP_CLAUSE_FINALIZE for OACC_EXIT_DATA.
+
* tree-nested.c (convert_nonlocal_omp_clauses)
(convert_local_omp_clauses): Handle "OMP_CLAUSE_FINALIZE".
* tree-pretty-print.c (dump_omp_clause): Handle
diff --git gcc/gimplify.c gcc/gimplify.c
index 7812471..54c5d43 100644
--- gcc/gimplify.c
+++ gcc/gimplify.c
@@ -10060,6 +10060,33 @@ gimplify_omp_target_update (tree *expr_p, gimple_seq 
*pre_p)
  break;
}
 }
+  else if (TREE_CODE (expr) == OACC_EXIT_DATA
+  && find_omp_clause (OMP_STANDALONE_CLAUSES (expr),
+  OMP_CLAUSE_FINALIZE))
+{
+  /* Use GOMP_MAP_DELETE/GOMP_MAP_FORCE_FROM to denote that "finalize"
+semantics apply to all mappings of this OpenACC directive.  */
+  bool finalize_marked = false;
+  for (tree c = OMP_STANDALONE_CLAUSES (expr); c; c = OMP_CLAUSE_CHAIN (c))
+   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
+ switch (OMP_CLAUSE_MAP_KIND (c))
+   {
+   case GOMP_MAP_FROM:
+ OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_FORCE_FROM);
+ finalize_marked = true;
+ break;
+   case GOMP_MAP_RELEASE:
+ OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_DELETE);
+ finalize_marked = true;
+ break;
+   default:
+ /* Check consistency: libgomp relies on the very first data
+mapping clause being marked, so make sure we did that before

Re: [gomp4] Implement OpenACC 2.5 reference counting, and finalize clause

2017-05-17 Thread Thomas Schwinge
Hi!

On Tue, 16 May 2017 20:55:46 +0800, Chung-Lin Tang  
wrote:
> finalize clause of the exit data directive, and the
> corresponding API routines.

> --- libgomp/oacc-parallel.c   (revision 248095)
> +++ libgomp/oacc-parallel.c   (revision 248096)
> @@ -355,7 +355,22 @@
>   }
>  }
>else
> -tgt->device_descr->openacc.register_async_cleanup_func (tgt, async);
> +{
> +  bool async_unmap = false;
> +  for (size_t i = 0; i < tgt->list_count; i++)
> + {
> +   splay_tree_key k = tgt->list[i].key;
> +   if (k && k->refcount == 1)
> + {
> +   async_unmap = true;
> +   break;
> + }
> + }
> +  if (async_unmap)
> + tgt->device_descr->openacc.register_async_cleanup_func (tgt, async);
> +  else
> + gomp_unmap_vars (tgt, false);
> +}
>  
>acc_dev->openacc.async_set_async_func (acc_async_sync);

This additional gomp_unmap_vars call also needs be instrumented for the
OpenACC Profiling Interface.

> --- libgomp/openacc.h (revision 248095)
> +++ libgomp/openacc.h (revision 248096)

> +/* Finalize versions of copyout/delete functions, specified in OpenACC 2.5.  
> */
> +void acc_copyout_finalize (void *, size_t) __GOACC_NOTHROW;
> +void acc_copyout_finalize_async (void *, size_t, int) __GOACC_NOTHROW;
> +void acc_delete_finalize (void *, size_t) __GOACC_NOTHROW;
> +void acc_delete_finalize_async (void *, size_t, int) __GOACC_NOTHROW;

And for these, the OpenACC Profiling Interface status needs to be
documented.

Committed to gomp-4_0-branch in r248150:

commit dc97f798ad7f7f44f45b2b8e0ece81f3926fa1c2
Author: tschwinge 
Date:   Wed May 17 12:07:30 2017 +

OpenACC 2.5 Profiling Interface changes for "finalize" handling

libgomp/
* libgomp.texi (OpenACC Profiling Interface): Update.
* oacc-parallel.c (GOACC_parallel_keyed): Update profiling event
generation.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@248150 
138bc75d-0d04-0410-961f-82ee72b054a4
---
 libgomp/ChangeLog.gomp  | 4 
 libgomp/libgomp.texi| 4 ++--
 libgomp/oacc-parallel.c | 9 +++--
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git libgomp/ChangeLog.gomp libgomp/ChangeLog.gomp
index 2ea7215..996c1f9 100644
--- libgomp/ChangeLog.gomp
+++ libgomp/ChangeLog.gomp
@@ -1,5 +1,9 @@
 2017-05-17  Thomas Schwinge  
 
+   * libgomp.texi (OpenACC Profiling Interface): Update.
+   * oacc-parallel.c (GOACC_parallel_keyed): Update profiling event
+   generation.
+
* oacc-parallel.c (GOACC_enter_exit_data): Locally compute
"finalize", and remove the formal parameter.  Adjust all users.
(GOACC_declare): Don't replace GOMP_MAP_FROM with
diff --git libgomp/libgomp.texi libgomp/libgomp.texi
index 69fb3be..1dea1e2 100644
--- libgomp/libgomp.texi
+++ libgomp/libgomp.texi
@@ -3459,8 +3459,8 @@ offloading devices (it's not clear if they should be):
 @item @code{acc_free}
 @item @code{acc_copyin}, @code{acc_present_or_copyin}, @code{acc_copyin_async}
 @item @code{acc_create}, @code{acc_present_or_create}, @code{acc_create_async}
-@item @code{acc_copyout}, @code{acc_copyout_async}
-@item @code{acc_delete}, @code{acc_delete_async}
+@item @code{acc_copyout}, @code{acc_copyout_async}, 
@code{acc_copyout_finalize}, @code{acc_copyout_finalize_async}
+@item @code{acc_delete}, @code{acc_delete_async}, @code{acc_delete_finalize}, 
@code{acc_delete_finalize_async}
 @item @code{acc_update_device}, @code{acc_update_device_async}
 @item @code{acc_update_self}, @code{acc_update_self_async}
 @item @code{acc_map_data}, @code{acc_unmap_data}
diff --git libgomp/oacc-parallel.c libgomp/oacc-parallel.c
index ff6e96c..622c711 100644
--- libgomp/oacc-parallel.c
+++ libgomp/oacc-parallel.c
@@ -333,8 +333,10 @@ GOACC_parallel_keyed (int device, void (*fn) (void *),
  async, dims, tgt);
 
   /* If running synchronously, unmap immediately.  */
+  bool copyfrom = true;
   if (async < acc_async_noval)
 {
+unmap:
   if (profiling_dispatch_p)
{
  prof_info.event_type = acc_ev_exit_data_start;
@@ -344,7 +346,7 @@ GOACC_parallel_keyed (int device, void (*fn) (void *),
  goacc_profiling_dispatch (&prof_info, &enter_exit_data_event_info,
&api_info);
}
-  gomp_unmap_vars (tgt, true);
+  gomp_unmap_vars (tgt, copyfrom);
   if (profiling_dispatch_p)
{
  prof_info.event_type = acc_ev_exit_data_end;
@@ -369,7 +371,10 @@ GOACC_parallel_keyed (int device, void (*fn) (void *),
   if (async_unmap)
tgt->device_descr->openacc.register_async_cleanup_func (tgt, async);
   else
-   gomp_unmap_vars (tgt, false);
+   {
+ copyfrom = false;
+ goto unmap;
+   }
 }
 
   acc_dev->openacc.async_set_async_func (acc_async_sync);

(That one can certainly do with some restructuring, to avoid the "goto".)
;-)


Grüße
 Thom

Re: [C++ PATCH, RFC] Implement new C++ intrinsics __is_assignable and __is_constructible.

2017-05-17 Thread Ville Voutilainen
On 16 May 2017 at 21:44, Jason Merrill  wrote:
>> Well, now that Jason pointed out that cp_unevaluated_operand is the
>> trick, here's a new
>> patch that fixes that bug and passes the full testsuite on Linux-x64.
>
> OK, thanks.


One more round. This patch doesn't change any of the compiler bits,
but the llvm testsuite revealed
that we didn't handle things like
is_trivially_copy_constructible properly, so I needed to adjust
the library implementation of the triviality-traits. Now we pass the
llvm testsuite for these traits,
and this patch passes our full testsuite.

Jonathan, ok for trunk?

2017-05-17  Ville Voutilainen  

c-family/

Implement new C++ intrinsics __is_assignable and __is_constructible.
* c-common.c (__is_assignable, __is_constructible): New.
* c-common.h (RID_IS_ASSIGNABLE, RID_IS_CONSTRUCTIBLE): Likewise.

cp/

PR c++/80654
PR c++/80682
Implement new C++ intrinsics __is_assignable and __is_constructible.
* cp-tree.h (CPTK_IS_ASSIGNABLE, CPTK_IS_CONSTRUCTIBLE): New.
(is_xible): New.
* cxx-pretty-print.c (pp_cxx_trait_expression): Handle
CPTK_IS_ASSIGNABLE and CPTK_IS_CONSTRUCTIBLE.
* method.c (constructible_expr): Set cp_unevaluated.
(is_xible_helper): New.
(is_trivially_xible): Adjust.
(is_xible): New.
* parser.c (cp_parser_primary_expression): Handle
RID_IS_ASSIGNABLE and RID_IS_CONSTRUCTIBLE.
(cp_parser_trait_expr): Likewise.
* semantics.c (trait_expr_value): Handle
CPTK_IS_ASSIGNABLE and CPTK_IS_CONSTRUCTIBLE.

testsuite/

* g++.dg/ext/80654.C: New.

libstdc++-v3/

Implement new C++ intrinsics __is_assignable and __is_constructible.
* include/std/type_traits (__do_is_static_castable_impl): Remove.
(__is_static_castable_impl, __is_static_castable_safe): Likewise.
(__is_static_castable, __do_is_direct_constructible_impl): Likewise.
(__is_direct_constructible_impl): Likewise.
(__is_direct_constructible_new_safe): Likewise.
(__is_base_to_derived_ref, __is_lvalue_to_rvalue_ref): Likewise.
(__is_direct_constructible_ref_cast): Likewise.
(__is_direct_constructible_new, __is_direct_constructible): Likewise.
(__do_is_nary_constructible_impl): Likewise.
(__is_nary_constructible_impl, __is_nary_constructible): Likewise.
(__is_constructible_impl): Likewise.
(is_constructible): Call the intrinsic.
(__is_assignable_helper): Remove.
(is_assignable): Call the intrinsic.
(is_trivially_constructible): Likewise.
(__is_trivially_copy_constructible_impl): New.
(is_trivially_copy_constructible): Use it.
(__is_trivially_move_constructible_impl): New.
(is_trivially_move_constructible): Use it.
(is_trivially_assignable): Call the intrinsic.
(__is_trivially_copy_assignable_impl): New.
(is_trivially_copy_assignable): Use it.
(__is_trivially_move_assignable_impl): New.
(is_trivially_move_assignable): Use it.
(testsuite/20_util/declval/requirements/1_neg.cc): Adjust.
(testsuite/20_util/is_trivially_copy_assignable/value.cc):
Add test for void.
(testsuite/20_util/is_trivially_copy_constructible/value.cc): Likewise.
(testsuite/20_util/is_trivially_move_assignable/value.cc): Likewise.
(testsuite/20_util/is_trivially_move_constructible/value.cc): Likewise.
(testsuite/20_util/make_signed/requirements/typedefs_neg.cc): Adjust.
(testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc):
Likewise.
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index ad686d2..369e112 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -514,6 +514,8 @@ const struct c_common_resword c_common_reswords[] =
   { "volatile",RID_VOLATILE,   0 },
   { "wchar_t", RID_WCHAR,  D_CXXONLY },
   { "while",   RID_WHILE,  0 },
+  { "__is_assignable", RID_IS_ASSIGNABLE, D_CXXONLY },
+  { "__is_constructible", RID_IS_CONSTRUCTIBLE, D_CXXONLY },
 
   /* C++ transactional memory.  */
   { "synchronized",RID_SYNCHRONIZED, D_CXX_OBJC | D_TRANSMEM },
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 9e3982d..a986056 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -172,6 +172,7 @@ enum rid
   RID_IS_TRIVIALLY_ASSIGNABLE, RID_IS_TRIVIALLY_CONSTRUCTIBLE,
   RID_IS_TRIVIALLY_COPYABLE,
   RID_IS_UNION,RID_UNDERLYING_TYPE,
+  RID_IS_ASSIGNABLE,   RID_IS_CONSTRUCTIBLE,
 
   /* C++11 */
   RID_CONSTEXPR, RID_DECLTYPE, RID_NOEXCEPT, RID_NULLPTR, RID_STATIC_ASSERT,
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 09b1364..154ba3c 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -927,7 +927,9 @@ enum cp_trait_kind
   CPTK_IS_TRIVIALLY_CONSTRUCTIBLE,
   CPTK_IS_TRIVIALLY_COPYABLE,
   CPTK_IS_UNION,
-  CPTK_UNDERLYING_TYPE
+  CPTK_UNDERLYING_TYPE,
+  CPTK_IS_ASSIGNABLE,
+  CPTK_IS_CONSTRUCTIBLE
 };
 
 /* The types that we are processing.  */
@@ -6112,6 +6114,7 @@ extern void use_thunk 

Re: [PATCH v2 3/N] Transform TDF_{lang,tree,ipa,rtl} to dump_kind enum.

2017-05-17 Thread Richard Biener
On Fri, May 12, 2017 at 3:04 PM, Martin Liška  wrote:
> Third part removes TDF_* flags mentioned in the subject. These flags are used
> to enable all passes of specific type and Nathan has recently separated these
> by a new pair of macros. I hope moving these to a separate enum will help 
> even more.
>
> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
>
> Ready to be installed?

Ok with the constexpr issue solved.

Thanks,
Richard.

> Martin


Re: [PATCH] make RTL/TREE/IPA dump kind an index

2017-05-17 Thread Richard Biener
On Sun, May 14, 2017 at 3:57 AM, Nathan Sidwell  wrote:
> On 05/13/2017 03:58 AM, Bernhard Reutner-Fischer wrote:
>
>> Specifically
>> https://gcc.gnu.org/ml/fortran/2012-03/msg00094.html
>>
>> dejagnu-1.5.2 contains the libdirs tweak and was released 2015-01-30
>>
>> Mike,  can we please bump the required dejagnu version for GCC-8?
>> Thanks
>
>
> There's also the version of TCL. My recent attempt to use an 8.5 feature
> killed some build systems.  install.texi doesn't seem to specify a minimum
> version, just '8.6 is bad, don't use it'

SLES11 already has 8.5.5, so I'm fine specifying a minimal version of 8.5.x

Richard.

> nathan
>
>
> --
> Nathan Sidwell


[RFC, PATCH][ASAN] Implement dynamic allocas/VLAs sanitization.

2017-05-17 Thread Maxim Ostapenko

Hi,

this patch implements dynamic allocas/VLAs sanitization in ASan. 
Basically, this is implemented at compiler part in the following way:


1) For each __builtin_alloca{_with_align} increase its size and 
alignment to contain ASan redzones.
2) Poison redzones by calling __asan_alloca_poison(alloc_addr, size) 
ASan runtime library function.
3) Remember last allocated address into separate variable called 
'last_alloca_addr'. This will be used to implement unpoisoning stuff.
4) On each stackrestore/return perform dynamic stack unpoisoning by 
calling __asan_allocas_unpoison(last_alloca_addr, restored_sp) library 
function.


With this patch I was able to find two bugs in GCC itself [1], [2] as 
well as catch a bug in Radare2 [3] initially found by Clang + LibFuzzer.

I've also managed to build Chromium but didn't find any errors there.

Does this patch looks sensible for GCC? Any feedback/suggestions would 
be greatly appreciated.


Thanks,
-Maxim

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72765
[2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80798
[3] https://github.com/radare/radare2/issues/6918
gcc/ChangeLog:

2017-05-17  Maxim Ostapenko  

	* asan.c: Include gimple-fold.h.
	(get_last_alloca_addr): New function.
	(handle_builtin_stackrestore): Likewise.
	(handle_builtin_alloca): Likewise.
	(asan_emit_allocas_unpoison): Likewise.
	(get_mem_refs_of_builtin_call): Add new parameter, remove const
	quallifier from first paramerer. Handle BUILT_IN_ALLOCA,
	BUILT_IN_ALLOCA_WITH_ALIGN and BUILT_IN_STACK_RESTORE builtins.
	(instrument_builtin_call): Pass gimple iterator to
	get_mem_refs_of_builtin_call.
	(last_alloca_addr): New global.
	* asan.h (asan_emit_allocas_unpoison): Declare.
	* builtins.c (expand_asan_emit_allocas_unpoison): New function.
	(expand_builtin): Handle BUILT_IN_ASAN_ALLOCAS_UNPOISON.
	* cfgexpand.c (expand_used_vars): Call asan_emit_allocas_unpoison
	if function calls alloca.
	* gimple-fold.c (replace_call_with_value): Remove static keyword.
	* gimple-fold.h (replace_call_with_value): Declare.
	* internal-fn.c: Include asan.h.
	* sanitizer.def (BUILT_IN_ASAN_ALLOCA_POISON,
	BUILT_IN_ASAN_ALLOCAS_UNPOISON): New builtins.

gcc/testsuite/ChangeLog:

2017-05-17  Maxim Ostapenko  

	* c-c++-common/asan/alloca_big_alignment.c: New test.
	* c-c++-common/asan/alloca_detect_custom_size.c: Likewise.
	* c-c++-common/asan/alloca_instruments_all_paddings.c: Likewise.
	* c-c++-common/asan/alloca_loop_unpoisoning.c: Likewise.
	* c-c++-common/asan/alloca_overflow_partial.c: Likewise.
	* c-c++-common/asan/alloca_overflow_right.c: Likewise.
	* c-c++-common/asan/alloca_safe_access.c: Likewise.
	* c-c++-common/asan/alloca_underflow_left.c: Likewise.

diff --git a/gcc/asan.c b/gcc/asan.c
index bf564a4..4835db9 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -55,6 +55,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "langhooks.h"
 #include "cfgloop.h"
 #include "gimple-builder.h"
+#include "gimple-fold.h"
 #include "ubsan.h"
 #include "params.h"
 #include "builtins.h"
@@ -245,6 +246,7 @@ along with GCC; see the file COPYING3.  If not see
 static unsigned HOST_WIDE_INT asan_shadow_offset_value;
 static bool asan_shadow_offset_computed;
 static vec sanitized_sections;
+static tree last_alloca_addr = NULL_TREE;
 
 /* Set of variable declarations that are going to be guarded by
use-after-scope sanitizer.  */
@@ -531,11 +533,166 @@ get_mem_ref_of_assignment (const gassign *assignment,
   return true;
 }
 
+/* Return address of last allocated dynamic alloca.  */
+
+static tree
+get_last_alloca_addr ()
+{
+  if (last_alloca_addr)
+return last_alloca_addr;
+
+  gimple_seq seq = NULL;
+  gassign *g;
+
+  last_alloca_addr = create_tmp_reg (ptr_type_node, "last_alloca_addr");
+  g = gimple_build_assign (last_alloca_addr, NOP_EXPR,
+			   build_int_cst (ptr_type_node, 0));
+  gimple_seq_add_stmt_without_update (&seq, g);
+
+  edge e = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun));
+  gsi_insert_seq_on_edge_immediate (e, seq);
+  return last_alloca_addr;
+}
+
+/* Insert __asan_allocas_unpoison(top, bottom) call after
+   __builtin_stackrestore(new_sp) call.
+   The pseudocode of this routine should look like this:
+ __builtin_stackrestore(new_sp);
+ top = last_alloca_addr;
+ bot = virtual_dynamic_stack_rtx;
+ __asan_allocas_unpoison(top, bottom);
+ last_alloca_addr = new_sp;
+   We don't use new_sp as bot parameter because on some architectures
+   SP has non zero offset from dynamic stack area.  Moreover, on some
+   architectures this offset (STACK_DYNAMIC_OFFSET) becomes known for each
+   particular function only after all callees were expanded to rtl.
+   The most noticable example is PowerPC{,64}, see
+   http://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi.html#DYNAM-STACK.
+*/
+
+static void
+handle_builtin_stackrestore (gcall *call, gimple_stmt_iterator *iter)
+{
+  if (!iter)
+return;
+
+  gimple_stmt_iterator gsi = *iter;
+  gimple_seq seq = NULL;
+  t

Re: [PATCH GCC8][29/33]New register pressure estimation

2017-05-17 Thread Richard Biener
On Mon, May 15, 2017 at 5:50 PM, Bin.Cheng  wrote:
> On Thu, May 11, 2017 at 11:39 AM, Richard Biener
>  wrote:
>> On Tue, Apr 18, 2017 at 12:53 PM, Bin Cheng  wrote:
>>> Hi,
>>> Currently IVOPTs shares the same register pressure computation with RTL 
>>> loop invariant pass,
>>> which doesn't work very well.  This patch introduces specific interface for 
>>> IVOPTs.
>>> The general idea is described in the cover message as below:
>>>   C) Current implementation shares the same register pressure computation 
>>> with RTL loop
>>>  inv pass.  It has difficulty in handling (especially large) loop nest, 
>>> and quite
>>>  often generating too many candidates (especially for outer loops).  
>>> This change
>>>  introduces new register pressure computation.  The brief idea is to 
>>> differentiate
>>>  (hot) innermost loop and outer loop.  for (possibly hot) inner most, 
>>> more registers
>>>  are allowed as long as the register pressure is within the range of 
>>> number of target
>>>  available registers.
>>> It can also help to restrict number of candidates for outer loop.
>>> Is it OK?
>>
>> +/* Determine if current loop is the innermost loop and maybe hot.  */
>> +
>> +static void
>> +determine_hot_innermost_loop (struct ivopts_data *data)
>> +{
>> +  data->hot_innermost_loop_p = true;
>> +  if (!data->speed)
>> +return;
>>
>> err, so when not optimizing for speed we assume all loops (even not 
>> innermost)
>> are hot and innermost?!
>>
>> +  HOST_WIDE_INT niter = avg_loop_niter (loop);
>> +  if (niter < PARAM_VALUE (PARAM_AVG_LOOP_NITER)
>> +  || loop_constraint_set_p (loop, LOOP_C_PROLOG)
>> +  || loop_constraint_set_p (loop, LOOP_C_EPILOG)
>> +  || loop_constraint_set_p (loop, LOOP_C_VERSION))
>> +data->hot_innermost_loop_p = false;
>>
>> this needs adjustment for the constraint patch removal.  Also looking at 
>> niter
>> of the loop in question insn't a good metric for hotness.  data->speed is the
>> best guess you get I think (optimize_loop_for_speed_p).
>>
>>data->speed = optimize_loop_for_speed_p (loop);
>> +  determine_hot_innermost_loop (data);
>>
>>   data->hot_innermost_loop_p = determine_hot_innermost_loop (data);
>>
>> would be more consistent here.
> Hi,
> I removed the hot innermost part and here is the updated version.  Is it OK?

Ok.

> Thanks,
> bin
>
> 2017-05-11  Bin Cheng  
>
> * tree-ssa-loop-ivopts.c (ivopts_estimate_reg_pressure): New
> reg_pressure model function.
> (ivopts_global_cost_for_size): Delete.
> (determine_set_costs, iv_ca_recount_cost): Call new model function
> ivopts_estimate_reg_pressure.
>
>>
>> Thanks,
>> Richard.
>>
>>> Thanks,
>>> bin
>>> 2017-04-11  Bin Cheng  
>>>
>>> * tree-ssa-loop-ivopts.c (struct ivopts_data): New field.
>>> (ivopts_estimate_reg_pressure): New reg_pressure model function.
>>> (ivopts_global_cost_for_size): Delete.
>>> (determine_set_costs, iv_ca_recount_cost): Call new model function
>>> ivopts_estimate_reg_pressure.
>>> (determine_hot_innermost_loop): New.
>>> (tree_ssa_iv_optimize_loop): Call above function.


Re: [PATCH GCC8][30/33]Fold more type conversion into binary arithmetic operations

2017-05-17 Thread Richard Biener
On Mon, May 15, 2017 at 5:56 PM, Bin.Cheng  wrote:
> On Thu, May 11, 2017 at 11:54 AM, Richard Biener
>  wrote:
>> On Tue, Apr 18, 2017 at 12:53 PM, Bin Cheng  wrote:
>>> Hi,
>>> Simplification of (T1)(X *+- CST) is already implemented in 
>>> aff_combination_expand,
>>> this patch moves it to tree_to_aff_combination.  It also supports unsigned 
>>> types
>>> if range information allows the transformation, as well as special case 
>>> (T1)(X + X).
>>> Is it OK?
>>
>> Can you first please simply move it?
>>
>> +   /* In case X's type has wrapping overflow behavior, we can still
>> +  convert (T1)(X - CST) into (T1)X - (T1)CST if X - CST doesn't
>> +  overflow by range information.  Also Convert (T1)(X + CST) as
>> +  if it's (T1)(X - (-CST)).  */
>> +   if (TYPE_UNSIGNED (itype)
>> +   && TYPE_OVERFLOW_WRAPS (itype)
>> +   && TREE_CODE (op0) == SSA_NAME
>> +   && TREE_CODE (op1) == INTEGER_CST
>> +   && (icode == PLUS_EXPR || icode == MINUS_EXPR)
>> +   && get_range_info (op0, &minv, &maxv) == VR_RANGE)
>> + {
>> +   if (icode == PLUS_EXPR)
>> + op1 = fold_build1 (NEGATE_EXPR, itype, op1);
>>
>> Negating -INF will produce -INF(OVF) which we don't want to have in our IL,
>> I suggest to use
>>
>>   op1 = wide_int_to_tree (itype, wi::neg (op1));
>>
>> instead.
>>
>> +   if (wi::geu_p (minv, op1))
>> + {
>> +   op0 = fold_convert (otype, op0);
>> +   op1 = fold_convert (otype, op1);
>> +   expr = fold_build2 (MINUS_EXPR, otype, op0, op1);
>> +   tree_to_aff_combination (expr, type, comb);
>> +   return;
>> + }
>> + }
>>
>> I think this is similar to a part of what Robin Dapp (sp?) is
>> proposing as fix for PR69526?
>>
>> The same trick should work for (int)((unsigned)X - CST) with different
>> overflow checks
>> (you need to make sure the resulting expr does not overflow).
> Hi,
> As suggested, I separated the patch into three.  Other review comments
> are also addressed.
> I read Robin's PR and patch, I think it's two different issues sharing
> some aspects, for example, the overflow check using range information
> are quite the same.  In effect, this should also captures the result
> of Robin's patch because we don't want to fold (T1)(x +- CST) in
> general, but here in tree-affine.
>
> Bootstrap and test, is it OK?

Ok.  Please commit as separate revisions.

Thanks,
Richard.

> Part1:
> 2017-04-11  Bin Cheng  
>
> (aff_combination_expand): Move (T1)(X *+- CST) simplification to ...
> (tree_to_aff_combination): ... here.
>
> Part2:
> 2017-04-11  Bin Cheng  
>
> * tree-affine.c (tree_to_aff_combination): Handle (T1)(X + X).
>
> Part3:
> 2017-04-11  Bin Cheng  
>
> * tree-affine.c (ssa.h): Include header file.
> (tree_to_aff_combination): Handle (T1)(X - CST) when inner type
> has wrapping overflow behavior.
>
> Thanks,
> bin
>>
>> Richard.
>>
>>
>>> Thanks,
>>> bin
>>> 2017-04-11  Bin Cheng  
>>>
>>> * tree-affine.c: Include header file.
>>> (aff_combination_expand): Move (T1)(X *+- CST) simplification to ...
>>> (tree_to_aff_combination): ... here.  Support (T1)(X + X) case, and
>>> unsigned type case if range information allows.


Re: [PATCH v2 04/N] Simplify usage of some TDF_* flags.

2017-05-17 Thread Richard Biener
On Tue, May 16, 2017 at 3:53 PM, Martin Liška  wrote:
> There's one another patch that merges some TDF_* flags that have
> very similar meaning and do not influence test-suite, because
> nobody is using them for scanning.
>
> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
>
> Ready to be installed?

I think the patch removes too many TDF flags.  For example
-fdump-tree-xxx-address
will then print not only addresses of gimple stmts but also of each
tree operand.  The
change to dump_generic_node looks ok though.

Did you look who intoduced TDF_COMMENT?  ISTR it was for some graph
dumping stuff.

Likewise the TDF_VERBOSE use in tree-cfg.c shouldn't be replaced with
-details but
dropped if you trop the flag.

Did you look at effects in dump-files at all?

Richard.

> Martin


Re: [PATCH GCC8][29/33]New register pressure estimation

2017-05-17 Thread Richard Sandiford
"Bin.Cheng"  writes:
> -/* Calculates cost for having N_REGS registers.  This number includes
> -   induction variables, invariant variables and invariant expressions.  */
> +/* Estimate register pressure for loop having N_INVS invariants and N_CANDS
> +   induction variables.  Note N_INVS includes both invariant variables and
> +   invariant expressions.  */
>  
>  static unsigned
> -ivopts_global_cost_for_size (struct ivopts_data *data, unsigned n_regs)
> +ivopts_estimate_reg_pressure (struct ivopts_data *data, unsigned n_invs,
> +   unsigned n_cands)
>  {
> -  unsigned cost = estimate_reg_pressure_cost (n_regs,
> -   data->regs_used, data->speed,
> -   data->body_includes_call);
> -  /* Add n_regs to the cost, so that we prefer eliminating ivs if possible.  
> */
> -  return n_regs + cost;
> +  unsigned cost;
> +  unsigned n_old = data->regs_used, n_new = n_invs + n_cands;
> +  unsigned regs_needed = n_new + n_old, available_regs = target_avail_regs;
> +  bool speed = data->speed;
> +
> +  /* If there is a call in the loop body, the call-clobbered registers
> + are not available for loop invariants.  */
> +  if (data->body_includes_call)
> +available_regs = available_regs - target_clobbered_regs;
> +
> +  /* If we have enough registers.  */
> +  if (regs_needed + target_res_regs < available_regs)
> +cost = n_new;
> +  /* If close to running out of registers, try to preserve them.  */
> +  else if (regs_needed <= available_regs)
> +cost = target_reg_cost [speed] * regs_needed;
> +  /* If we run out of available registers but the number of candidates
> + does not, we penalize extra registers using target_spill_cost.  */
> +  else if (n_cands <= available_regs)
> +cost = target_reg_cost [speed] * available_regs
> ++ target_spill_cost [speed] * (regs_needed - available_regs);
> +  /* If the number of candidates runs out available registers, we penalize
> + extra candidate registers using target_spill_cost * 2.  Because it is
> + more expensive to spill induction variable than invariant.  */
> +  else
> +cost = target_reg_cost [speed] * available_regs
> ++ target_spill_cost [speed] * (n_cands - available_regs) * 2
> ++ target_spill_cost [speed] * (regs_needed - n_cands);
> +
> +  /* Finally, add the number of candidates, so that we prefer eliminating
> + induction variables if possible.  */
> +  return cost + n_cands;

It looks like the return is mixing units.  Would it work to return
a  pair instead, and use lexicographical ordering?

Thanks,
Richard


[C++ PATCH] OVERLOAD iterators #5

2017-05-17 Thread Nathan Sidwell

This patch fixes up add_method.  There are two things going on here

1) a new ovl_insert worker to add a new decl to an existing overload 
set.  This is no longer simply prepending the new decl, as we keep the 
set ordered.  The eventual ordering will be 
hidden->using->regular->exported.  But at this point we just keep the 
using decls before the regular ones.  Hidden handling will be later and 
of course exports is a modules thing. (hidden fns are both friend 
injections and anticipated builtins)


2) a remove_node worker, rather than have users directly stitch out the 
node.


Both these behaviours mean that there's an issue with overload lookups 
that are stashed in uninstantiated templates.  If we can subsequently go 
modifying that lookup, a later instantiation may see different functions 
than it should do.  We already have this problem because of #2 (users 
directly stitching out), and #1 now introduces another way it can 
happen.  This patch does not address that problem.  I have further 
patches to rectify this.  There are no new testcase failures because of 
this problem (I have new testcases too).


nathan
--
Nathan Sidwell
2017-05-17  Nathan Sidwell  

	* cp-tree.h (ovl_iterator::using_p): New predicate.
	(ovl_iterator::remove_node): New worker.
	(ovl_insert): Declare.
	* tree.c (ovl_insert): New.
	(ovl_iterator::remove_node): New.
	* class.c (add_method): Use ovl_iterator, ovl_insert.
	(clone_function_decl): Fix description.
	(clone_constructors_and_destructors): Use ovl_iterator.

Index: class.c
===
--- class.c	(revision 248144)
+++ class.c	(working copy)
@@ -1010,7 +1010,6 @@ bool
 add_method (tree type, tree method, bool via_using)
 {
   unsigned slot;
-  tree overload;
   bool template_conv_p = false;
   bool conv_p;
   vec *method_vec;
@@ -1059,7 +1058,7 @@ add_method (tree type, tree method, bool
 	   vec_safe_iterate (method_vec, slot, &m);
 	   ++slot)
 	{
-	  m = OVL_CURRENT (m);
+	  m = OVL_FIRST (m);
 	  if (template_conv_p)
 	{
 	  if (TREE_CODE (m) == TEMPLATE_DECL
@@ -1083,24 +1082,23 @@ add_method (tree type, tree method, bool
   current_fns = insert_p ? NULL_TREE : (*method_vec)[slot];
 
   /* Check to see if we've already got this method.  */
-  for (tree *p = ¤t_fns; *p; )
+  for (ovl_iterator iter (current_fns); iter; ++iter)
 {
-  tree fns = *p;
-  tree fn = OVL_CURRENT (fns);
+  tree fn = *iter;
   tree fn_type;
   tree method_type;
   tree parms1;
   tree parms2;
 
   if (TREE_CODE (fn) != TREE_CODE (method))
-	goto cont;
+	continue;
 
   /* Two using-declarations can coexist, we'll complain about ambiguity in
 	 overload resolution.  */
-  if (via_using && TREE_CODE (fns) == OVERLOAD && OVL_USED (fns)
+  if (via_using && iter.using_p ()
 	  /* Except handle inherited constructors specially.  */
 	  && ! DECL_CONSTRUCTOR_P (fn))
-	goto cont;
+	continue;
 
   /* [over.load] Member function declarations with the
 	 same name and the same parameter types cannot be
@@ -1134,7 +1132,7 @@ add_method (tree type, tree method, bool
 	  == FUNCTION_REF_QUALIFIED (method_type))
 	  && (type_memfn_quals (fn_type) != type_memfn_quals (method_type)
 	  || type_memfn_rqual (fn_type) != type_memfn_rqual (method_type)))
-	  goto cont;
+	  continue;
 
   /* For templates, the return type and template parameters
 	 must be identical.  */
@@ -1143,7 +1141,7 @@ add_method (tree type, tree method, bool
 			TREE_TYPE (method_type))
 	  || !comp_template_parms (DECL_TEMPLATE_PARMS (fn),
    DECL_TEMPLATE_PARMS (method
-	goto cont;
+	continue;
 
   if (! DECL_STATIC_FUNCTION_P (fn))
 	parms1 = TREE_CHAIN (parms1);
@@ -1187,8 +1185,9 @@ add_method (tree type, tree method, bool
 		mangle_decl (method);
 		}
 	  cgraph_node::record_function_versions (fn, method);
-	  goto cont;
+	  continue;
 	}
+
 	  if (DECL_INHERITED_CTOR (method))
 	{
 	  if (DECL_INHERITED_CTOR (fn))
@@ -1202,7 +1201,7 @@ add_method (tree type, tree method, bool
 			  /* Inheriting the same constructor along different
 			 paths, combine them.  */
 			  SET_DECL_INHERITED_CTOR
-			(fn, ovl_cons (DECL_INHERITED_CTOR (method),
+			(fn, ovl_make (DECL_INHERITED_CTOR (method),
 	   DECL_INHERITED_CTOR (fn)));
 			  /* And discard the new one.  */
 			  return false;
@@ -1210,7 +1209,7 @@ add_method (tree type, tree method, bool
 		  else
 			/* Inherited ctors can coexist until overload
 			   resolution.  */
-			goto cont;
+			continue;
 		}
 		  error_at (DECL_SOURCE_LOCATION (method),
 			"%q#D", method);
@@ -1228,8 +1227,8 @@ add_method (tree type, tree method, bool
 	  else if (flag_new_inheriting_ctors
 		   && DECL_INHERITED_CTOR (fn))
 	{
-	  /* Hide the inherited constructor.  */
-	  *p = OVL_NEXT (fns);
+	  /* Remove the inherited constructor.  */
+	  current_fns = iter.remove_node (curre

RE:[PATCH,AIX] Enable FFI Go Closure on AIX

2017-05-17 Thread REIX, Tony
Hi,

We have built and installed the libffi master of yesterday on a AIX 6.1 machine 
and we have rebuilt and tested Python3 (3.5.2) with this libffi. And that is 
OK. 32bit and 64bit.

5 more tests were run and succeeded.
And 1 test (test_ssl) which was skipped before is now run but failed due to no 
access to Web (Resource 'sha256.tbs-internet.com' is not available).

So. our patch does not break libffi build and tests, nor Python3 build and 
tests.

That looks OK.

We'll submit the patch to the libffi project now.

Regards,

Tony


With New libffi:

369 tests OK.
12 tests failed:
test_asyncio test_distutils test_eintr test_httpservers
test_locale test_posix test_socket test_ssl test_tools
test_urllib2 test_urllib2_localnet test_urllib2net
1 test altered the execution environment:
test_io
16 tests skipped:
test_devpoll test_epoll test_gdb test_kqueue test_msilib
test_ossaudiodev test_pep277 test_spwd test_startfile test_tix
test_tk test_ttk_guionly test_unicode_file test_winreg
test_winsound test_zipfile64


With previous libffi:

364 tests OK.
11 tests failed:
test_asyncio test_distutils test_eintr test_httpservers
test_locale test_posix test_socket test_tools test_urllib2
test_urllib2_localnet test_urllib2net
1 test altered the execution environment:
test_io
22 tests skipped:
test_devpoll test_epoll test_gdb test_idle test_kqueue test_msilib
test_ossaudiodev test_pep277 test_smtpnet test_spwd test_ssl
test_startfile test_tcl test_tix test_tk test_ttk_guionly
test_ttk_textonly test_turtle test_unicode_file test_winreg
test_winsound test_zipfile64


# rpm -qa | grep python3
python3-3.5.2-3
# rpm -qa | grep ffi
libffi-devel-20170516-1
libffi-20170516-1


# ldd python
python needs:
 /usr/lib/threads/libc.a(shr.o)
 /usr/lib/libpthreads.a(shr_xpg5.o)
 /opt/freeware/src/packages/BUILD/Python-3.5.2/64bit/libpython3.5m.so
 /opt/freeware/lib/libffi.a(libffi.so.7)
 /unix
 /usr/lib/libcrypt.a(shr.o)
 /usr/lib/libpthreads.a(shr_comm.o)
 /opt/freeware/lib/libgcc_s.a(shr.o)
 /usr/lib/threads/libc.a(shr_64.o)
 /usr/lib/libpthreads.a(shr_xpg5_64.o)
 /opt/freeware/lib/libintl.a(libintl.so.9)
 /usr/lib/libcrypt.a(shr_64.o)
 /opt/freeware/lib/libiconv.a(libiconv.so.2)



Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net


De : David Edelsohn [dje@gmail.com]
Envoyé : mardi 16 mai 2017 17:11
À : REIX, Tony
Cc : GCC Patches; SARTER, MATTHIEU (ext)
Objet : Re: [PATCH,AIX] Enable FFI Go Closure on AIX

On Tue, May 16, 2017 at 10:44 AM, REIX, Tony  wrote:
> Hi David,
>
> We'll submit the patch to the libffi project asap.
>
> We have tested this patch on AIX 6.1 with libffi (master from github) in 
> 32bit and 64bit with same results (same exact failures) when testing with and 
> without our patch, using libffi testsuite.
>
> Without patch:
> === libffi Summary === 64bit & 32bit
> # of expected passes1870
> # of unexpected failures38
> # of unresolved testcases  2
> # of unsupported tests 30
>
> With patch:
> === libffi Summary === 64bit & 32bit
> # of expected passes1890
> # of unexpected failures   38
> # of unresolved testcases 2
> # of unsupported tests28
>
> We'll test with Python asap, probably this week.

Libffi project now is on Github

https://github.com/libffi/libffi

I think that Anthony now uses pull requests.

Once the patches are in the upstream project, we can backport them to GCC.

Thanks, David


Re: [RFC PATCH, i386]: Enable post-reload compare elimination pass

2017-05-17 Thread Hans-Peter Nilsson
On Wed, 17 May 2017, Uros Bizjak wrote:
> On Wed, May 17, 2017 at 4:45 AM, Hans-Peter Nilsson  wrote:
> >> But yes, we definitely should document the final canonical ordering.
> >
> > Is that about to also happen?
> The proposed doc patch is wiating for review at [1].
>
> [1] https://gcc.gnu.org/ml/gcc-patches/2017-05/msg01073.html

Thanks.  LGTM.

brgds, H-P


RE:[PATCH,AIX] Enable FFI Go Closure on AIX

2017-05-17 Thread REIX, Tony
Patch has been submitted to libffi github : 
https://github.com/libffi/libffi/pull/308 .

Regards,

Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net


De : REIX, Tony
Envoyé : mercredi 17 mai 2017 14:53
À : David Edelsohn
Cc : GCC Patches; SARTER, MATTHIEU (ext)
Objet : RE:[PATCH,AIX] Enable FFI Go Closure on AIX

Hi,

We have built and installed the libffi master of yesterday on a AIX 6.1 machine 
and we have rebuilt and tested Python3 (3.5.2) with this libffi. And that is 
OK. 32bit and 64bit.

5 more tests were run and succeeded.
And 1 test (test_ssl) which was skipped before is now run but failed due to no 
access to Web (Resource 'sha256.tbs-internet.com' is not available).

So. our patch does not break libffi build and tests, nor Python3 build and 
tests.

That looks OK.

We'll submit the patch to the libffi project now.

Regards,

Tony


With New libffi:

369 tests OK.
12 tests failed:
test_asyncio test_distutils test_eintr test_httpservers
test_locale test_posix test_socket test_ssl test_tools
test_urllib2 test_urllib2_localnet test_urllib2net
1 test altered the execution environment:
test_io
16 tests skipped:
test_devpoll test_epoll test_gdb test_kqueue test_msilib
test_ossaudiodev test_pep277 test_spwd test_startfile test_tix
test_tk test_ttk_guionly test_unicode_file test_winreg
test_winsound test_zipfile64


With previous libffi:

364 tests OK.
11 tests failed:
test_asyncio test_distutils test_eintr test_httpservers
test_locale test_posix test_socket test_tools test_urllib2
test_urllib2_localnet test_urllib2net
1 test altered the execution environment:
test_io
22 tests skipped:
test_devpoll test_epoll test_gdb test_idle test_kqueue test_msilib
test_ossaudiodev test_pep277 test_smtpnet test_spwd test_ssl
test_startfile test_tcl test_tix test_tk test_ttk_guionly
test_ttk_textonly test_turtle test_unicode_file test_winreg
test_winsound test_zipfile64


# rpm -qa | grep python3
python3-3.5.2-3
# rpm -qa | grep ffi
libffi-devel-20170516-1
libffi-20170516-1


# ldd python
python needs:
 /usr/lib/threads/libc.a(shr.o)
 /usr/lib/libpthreads.a(shr_xpg5.o)
 /opt/freeware/src/packages/BUILD/Python-3.5.2/64bit/libpython3.5m.so
 /opt/freeware/lib/libffi.a(libffi.so.7)
 /unix
 /usr/lib/libcrypt.a(shr.o)
 /usr/lib/libpthreads.a(shr_comm.o)
 /opt/freeware/lib/libgcc_s.a(shr.o)
 /usr/lib/threads/libc.a(shr_64.o)
 /usr/lib/libpthreads.a(shr_xpg5_64.o)
 /opt/freeware/lib/libintl.a(libintl.so.9)
 /usr/lib/libcrypt.a(shr_64.o)
 /opt/freeware/lib/libiconv.a(libiconv.so.2)



Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net


De : David Edelsohn [dje@gmail.com]
Envoyé : mardi 16 mai 2017 17:11
À : REIX, Tony
Cc : GCC Patches; SARTER, MATTHIEU (ext)
Objet : Re: [PATCH,AIX] Enable FFI Go Closure on AIX

On Tue, May 16, 2017 at 10:44 AM, REIX, Tony  wrote:
> Hi David,
>
> We'll submit the patch to the libffi project asap.
>
> We have tested this patch on AIX 6.1 with libffi (master from github) in 
> 32bit and 64bit with same results (same exact failures) when testing with and 
> without our patch, using libffi testsuite.
>
> Without patch:
> === libffi Summary === 64bit & 32bit
> # of expected passes1870
> # of unexpected failures38
> # of unresolved testcases  2
> # of unsupported tests 30
>
> With patch:
> === libffi Summary === 64bit & 32bit
> # of expected passes1890
> # of unexpected failures   38
> # of unresolved testcases 2
> # of unsupported tests28
>
> We'll test with Python asap, probably this week.

Libffi project now is on Github

https://github.com/libffi/libffi

I think that Anthony now uses pull requests.

Once the patches are in the upstream project, we can backport them to GCC.

Thanks, David


Re: [PATCH,AIX] Enable FFI Go Closure on AIX

2017-05-17 Thread David Edelsohn
On Wed, May 17, 2017 at 9:11 AM, REIX, Tony  wrote:
> Patch has been submitted to libffi github : 
> https://github.com/libffi/libffi/pull/308 .

Good.

There still was no ChangeLog included with the patch.

Also, the new functions in the patch are not consistent with the
insertion of the word "go".  Sometimes it is near the end, like
ffi_call_go_AIX, and sometimes it is near the beginning, like
ffi_go_closure_DARWIN.  The naming should be consistent.

Thanks, David


Re: [C++ PATCH, RFC] Implement new C++ intrinsics __is_assignable and __is_constructible.

2017-05-17 Thread Jonathan Wakely

On 17/05/17 15:15 +0300, Ville Voutilainen wrote:

One more round. This patch doesn't change any of the compiler bits,
but the llvm testsuite revealed
that we didn't handle things like
is_trivially_copy_constructible properly, so I needed to adjust
the library implementation of the triviality-traits. Now we pass the
llvm testsuite for these traits,
and this patch passes our full testsuite.

Jonathan, ok for trunk?


Yes OK, thanks.

A few observations ...


@@ -1405,45 +1185,95 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  { };

  /// is_trivially_copy_constructible
+
+  template::value>
+struct __is_trivially_copy_constructible_impl;
+
  template
-struct is_trivially_copy_constructible
+struct __is_trivially_copy_constructible_impl<_Tp, false>
+: public false_type { };
+
+  template
+struct __is_trivially_copy_constructible_impl<_Tp, true>
: public __and_,
integral_constant>
{ };


This could use __bool_constant, and there doesn't seem to be any
advantage to using __and_ here, because there's nothing to
short-circuit. So:

   : public __bool_constant::value
&& __is_trivially_constructible(_Tp, const _Tp&)>

But that was pre-existing, so let's deal with that
separately.


+  template
+struct __is_trivially_move_constructible_impl<_Tp, true>
: public __and_,
integral_constant>
{ };


Ditto.


+  template
+struct __is_trivially_copy_assignable_impl<_Tp, true>
: public __and_,
integral_constant>
{ };


Ditto.


+  template
+struct __is_trivially_move_assignable_impl<_Tp, true>
: public __and_,
integral_constant>


Ditto.



Re: Trun predicates into a class

2017-05-17 Thread David Malcolm
On Wed, 2017-05-17 at 12:48 +0200, Jan Hubicka wrote:
> Hi,
> this is first patch of series to modularize function analysis done by
> ipa-inline and ipa-cp.  This patch turns predicates into a class. It
> avoids any
> code movement or semnatic changes which I will do next.   Main change
> is to
> turn some of functions into operators which makes the code more
> compact and
> hopefully also more readable.
> 
> I plan to move them into separate ipa-predicates.c and then breakup
> rest of
> ipa-inline-analysis into part that is independent of inliner (into
> new
> fnsummary pass doing also some work of ipa-prop) and inliner specific
> analysis.
> 
> Bootstrapped/regtested x86_64-linux. I have checked that there is no
> effect
> on code or inline estimates for tramp3d. Will commit it after bit of
> further testing.
> 
> Honza

[snip]

>   * ipa-inline.h (MAX_CLAUSES): Turn to predicate::max_clauses.
>   (clause_t): Turn to uint32_t
>   (predicate): Turn to class; implement constructor and operators
>   ==, !=, &
>   (size_time_entry): Update.
>   (inline_summary): Update.
>   (inline_edge_summary): Update.
> 

[snip]  

> Index: ipa-inline.h
> ===
> --- ipa-inline.h  (revision 248142)
> +++ ipa-inline.h  (working copy)

[snip]  

 
> -/* Representation of predicates i.e. formulas using conditions
> defined
> -   above.  Predicates are simple logical formulas in conjunctive
> -disjunctive
> -   form.
> -
> -   Predicate is array of clauses terminated by 0.  Every clause must
> be true
> -   in order to make predicate true.
> -   Clauses are represented as bitmaps of conditions. One of
> conditions
> -   must be true in order for clause to be true.  */
> -
> -#define MAX_CLAUSES 8
> -typedef unsigned int clause_t;
> -struct GTY(()) predicate
> 

[snip]  

> +class predicate
>  {

I noticed that the patch removes the "GTY(())" from "predicate".

Was that deliberate?  (I've no idea if it was needed before; I just
thought it was worth mentioning, since gengtype issues can be a pain to
track down).

Dave


Re: Trun predicates into a class

2017-05-17 Thread Jan Hubicka
> On Wed, 2017-05-17 at 12:48 +0200, Jan Hubicka wrote:
> > Hi,
> > this is first patch of series to modularize function analysis done by
> > ipa-inline and ipa-cp.  This patch turns predicates into a class. It
> > avoids any
> > code movement or semnatic changes which I will do next.   Main change
> > is to
> > turn some of functions into operators which makes the code more
> > compact and
> > hopefully also more readable.
> > 
> > I plan to move them into separate ipa-predicates.c and then breakup
> > rest of
> > ipa-inline-analysis into part that is independent of inliner (into
> > new
> > fnsummary pass doing also some work of ipa-prop) and inliner specific
> > analysis.
> > 
> > Bootstrapped/regtested x86_64-linux. I have checked that there is no
> > effect
> > on code or inline estimates for tramp3d. Will commit it after bit of
> > further testing.
> > 
> > Honza
> 
> [snip]
> 
> > * ipa-inline.h (MAX_CLAUSES): Turn to predicate::max_clauses.
> > (clause_t): Turn to uint32_t
> > (predicate): Turn to class; implement constructor and operators
> > ==, !=, &
> > (size_time_entry): Update.
> > (inline_summary): Update.
> > (inline_edge_summary): Update.
> > 
> 
> [snip]
> 
> > Index: ipa-inline.h
> > ===
> > --- ipa-inline.h(revision 248142)
> > +++ ipa-inline.h(working copy)
> 
> [snip]
> 
>  
> > -/* Representation of predicates i.e. formulas using conditions
> > defined
> > -   above.  Predicates are simple logical formulas in conjunctive
> > -disjunctive
> > -   form.
> > -
> > -   Predicate is array of clauses terminated by 0.  Every clause must
> > be true
> > -   in order to make predicate true.
> > -   Clauses are represented as bitmaps of conditions. One of
> > conditions
> > -   must be true in order for clause to be true.  */
> > -
> > -#define MAX_CLAUSES 8
> > -typedef unsigned int clause_t;
> > -struct GTY(()) predicate
> > 
> 
> [snip]
> 
> > +class predicate
> >  {
> 
> I noticed that the patch removes the "GTY(())" from "predicate".
> 
> Was that deliberate?  (I've no idea if it was needed before; I just
> thought it was worth mentioning, since gengtype issues can be a pain to
> track down).

Yep it is deliberate, gengtype does not like classes and it is easy to skip it
in garabage collected structures because it has no further pointers to collect.

Honza
> 
> Dave


[ubsan PATCH] -fsanitize=null fails to sanitize &s->i (PR sanitizer/80797)

2017-05-17 Thread Marek Polacek
We are failing to detect accessing a null pointer in &s->i because
v_3 = &s_2->i;
is not gimple_assign_load_p:  
1997   if (flag_sanitize & (SANITIZE_NULL | SANITIZE_ALIGNMENT))
1998 {
1999   if (gimple_store_p (stmt))
2000 instrument_null (gsi, true);
2001   if (gimple_assign_load_p (stmt))
2002 instrument_null (gsi, false);
2003 }

So I think we can use gimple_assign_single_p instead of gimple_assign_load_p
and then strip the ADDR_EXPR in instrument_null before getting its base
address.  (I've seen stripping ADDR_EXPR before get_base_address elsewhere in
the codebase, too.)

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

2017-05-17  Marek Polacek  

PR sanitizer/80797
* ubsan.c (instrument_null): Unwrap ADDR_EXPRs.
(pass_ubsan::execute): Call gimple_assign_single_p instead of
gimple_assign_load_p.

* c-c++-common/ubsan/null-12.c: New test.

diff --git gcc/testsuite/c-c++-common/ubsan/null-12.c 
gcc/testsuite/c-c++-common/ubsan/null-12.c
index e69de29..3478dc1 100644
--- gcc/testsuite/c-c++-common/ubsan/null-12.c
+++ gcc/testsuite/c-c++-common/ubsan/null-12.c
@@ -0,0 +1,42 @@
+/* PR sanitizer/80797 */
+/* { dg-do run } */
+/* { dg-options "-fsanitize=undefined" } */
+
+struct S
+{
+  int i;
+};
+
+struct R
+{
+  struct T {
+int i;
+  } *t;
+} r;
+
+int
+main ()
+{
+  struct S *s = 0;
+  struct S *s2[1] = { };
+
+  int *v1 = &s->i;
+  int *v2 = &(*s).i;
+  int *v3 = &s2[0]->i;
+  int *v4 = &s->i + 1;
+  int *v5 = &r.t->i;
+
+  asm ("" : : "r" (&v1) : "memory");
+  asm ("" : : "r" (&v2) : "memory");
+  asm ("" : : "r" (&v3) : "memory");
+  asm ("" : : "r" (&v4) : "memory");
+  asm ("" : : "r" (&v5) : "memory");
+
+  return 0;
+}
+
+/* { dg-output "member access within null pointer of type 'struct 
S'\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*member access within null pointer of type 'struct 
S'\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*member access within null pointer of type 'struct 
S'\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*member access within null pointer of type 'struct 
S'\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*member access within null pointer of type 'struct T'" 
} */
diff --git gcc/ubsan.c gcc/ubsan.c
index 4159cc5..a4808d2 100644
--- gcc/ubsan.c
+++ gcc/ubsan.c
@@ -1208,6 +1208,9 @@ instrument_null (gimple_stmt_iterator gsi, bool is_lhs)
 {
   gimple *stmt = gsi_stmt (gsi);
   tree t = is_lhs ? gimple_get_lhs (stmt) : gimple_assign_rhs1 (stmt);
+  /* Handle also e.g. &s->i.  */
+  if (TREE_CODE (t) == ADDR_EXPR)
+t = TREE_OPERAND (t, 0);
   tree base = get_base_address (t);
   const enum tree_code code = TREE_CODE (base);
   if (code == MEM_REF
@@ -1998,7 +2001,7 @@ pass_ubsan::execute (function *fun)
{
  if (gimple_store_p (stmt))
instrument_null (gsi, true);
- if (gimple_assign_load_p (stmt))
+ if (gimple_assign_single_p (stmt))
instrument_null (gsi, false);
}
 

Marek


Re: [PATCH] Add -dB option to disable backtraces

2017-05-17 Thread Andi Kleen
On Tue, May 16, 2017 at 08:40:02PM -0700, Andrew Pinski wrote:
> On Tue, May 16, 2017 at 7:16 PM, Andi Kleen  wrote:
> > From: Andi Kleen 
> >
> > When running creduce on an ICE substantial amounts of the total
> > CPU time go to backtrace_qsort() (sorting dwarf of the compiler) for
> > printing the backtrace of the ICE. When running a reduction we don't need 
> > the
> > backtrace. So add a -dB option to turn it off, and make reduction
> > a bit faster.
> 
> The other thing which you could is strip the binaries.  :)
> j/k.  I think this is a good patch and a good idea.

AFAIK the sort is for the unwind tables. strip removes .dwarf*, but not .eh_*
It can't because that would break C++ exceptions.

-Andi


Re: [PATCH] Add -dB option to disable backtraces

2017-05-17 Thread Ian Lance Taylor via gcc-patches
On Wed, May 17, 2017 at 7:13 AM, Andi Kleen  wrote:
> On Tue, May 16, 2017 at 08:40:02PM -0700, Andrew Pinski wrote:
>> On Tue, May 16, 2017 at 7:16 PM, Andi Kleen  wrote:
>> > From: Andi Kleen 
>> >
>> > When running creduce on an ICE substantial amounts of the total
>> > CPU time go to backtrace_qsort() (sorting dwarf of the compiler) for
>> > printing the backtrace of the ICE. When running a reduction we don't need 
>> > the
>> > backtrace. So add a -dB option to turn it off, and make reduction
>> > a bit faster.
>>
>> The other thing which you could is strip the binaries.  :)
>> j/k.  I think this is a good patch and a good idea.
>
> AFAIK the sort is for the unwind tables. strip removes .dwarf*, but not .eh_*
> It can't because that would break C++ exceptions.

This is libbacktrace.  The calls to backtrace_qsort are for the DWARF
information.  libbacktrace sorts the debug info so it can do faster
lookups of PC values.

That said I'm surprised it takes that much time.  The DWARF info is
usually mostly sorted, and backtrace_qsort is optimized for
information that is mostly sorted.  If you feel like spending time on
this it might be worth figuring out why it is slow.

Ian


C PATCH to use NULL_TREE instead of 0 for trees

2017-05-17 Thread Marek Polacek
I've always disliked using 0 where NULL_TREE should be.  It's confusing to see
if (value != 0), which makes value to look like an integer, even though it may
be a tree.

Next cleanup will probablyn be about using booleans where desirable.

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

2017-05-17  Marek Polacek  

* c-common.c: Use NULL_TREE instead of 0 where appropriate.
* c-warn.c: Likewise.

* c-decl.c: Use NULL_TREE instead of 0 where appropriate.
* c-typeck.c: Likewise.

diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
index f606e94..3ce47c8 100644
--- gcc/c-family/c-common.c
+++ gcc/c-family/c-common.c
@@ -2987,7 +2987,7 @@ shorten_compare (location_t loc, tree *op0_ptr, tree 
*op1_ptr,
   if (!real1 && !real2 && integer_zerop (primop1)
  && TYPE_UNSIGNED (*restype_ptr))
{
- tree value = 0;
+ tree value = NULL_TREE;
  /* All unsigned values are >= 0, so we warn.  However,
 if OP0 is a constant that is >= 0, the signedness of
 the comparison isn't an issue, so suppress the
@@ -3020,7 +3020,7 @@ shorten_compare (location_t loc, tree *op0_ptr, tree 
*op1_ptr,
  break;
}
 
- if (value != 0)
+ if (value != NULL_TREE)
{
  /* Don't forget to evaluate PRIMOP0 if it has side effects.  */
  if (TREE_SIDE_EFFECTS (primop0))
@@ -4649,10 +4649,10 @@ self_promoting_args_p (const_tree parms)
   if (type == error_mark_node)
continue;
 
-  if (TREE_CHAIN (t) == 0 && type != void_type_node)
+  if (TREE_CHAIN (t) == NULL_TREE && type != void_type_node)
return 0;
 
-  if (type == 0)
+  if (type == NULL_TREE)
return 0;
 
   if (TYPE_MAIN_VARIANT (type) == float_type_node)
@@ -5577,7 +5577,7 @@ check_function_arguments_recurse (void (*callback)
format_num = tree_to_uhwi (format_num_expr);
 
for (inner_arg = first_call_expr_arg (param, &iter), i = 1;
-inner_arg != 0;
+inner_arg != NULL_TREE;
 inner_arg = next_call_expr_arg (&iter), i++)
  if (i == format_num)
{
diff --git gcc/c-family/c-warn.c gcc/c-family/c-warn.c
index aa0cfa9..1b2a8d8 100644
--- gcc/c-family/c-warn.c
+++ gcc/c-family/c-warn.c
@@ -1078,7 +1078,7 @@ match_case_to_enum_1 (tree key, tree type, tree label)
   else
 print_hex (key, buf);
 
-  if (TYPE_NAME (type) == 0)
+  if (TYPE_NAME (type) == NULL_TREE)
 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label)),
warn_switch ? OPT_Wswitch : OPT_Wswitch_enum,
"case value %qs not in enumerated type",
diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index bd6c4c1..55fc53e 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -809,7 +809,7 @@ c_finish_incomplete_decl (tree decl)
   if (type != error_mark_node
  && TREE_CODE (type) == ARRAY_TYPE
  && !DECL_EXTERNAL (decl)
- && TYPE_DOMAIN (type) == 0)
+ && TYPE_DOMAIN (type) == NULL_TREE)
{
  warning_at (DECL_SOURCE_LOCATION (decl),
  0, "array %q+D assumed to have one element", decl);
@@ -1146,7 +1146,7 @@ pop_scope (void)
 
   /* If appropriate, create a BLOCK to record the decls for the life
  of this function.  */
-  block = 0;
+  block = NULL_TREE;
   if (keep)
 {
   block = make_node (BLOCK);
@@ -1157,7 +1157,7 @@ pop_scope (void)
   for (p = scope->blocks; p; p = BLOCK_CHAIN (p))
BLOCK_SUPERCONTEXT (p) = block;
 
-  BLOCK_VARS (block) = 0;
+  BLOCK_VARS (block) = NULL_TREE;
 }
 
   /* The TYPE_CONTEXTs for all of the tagged types belonging to this
@@ -1230,9 +1230,9 @@ pop_scope (void)
  /* Propagate TREE_ADDRESSABLE from nested functions to their
 containing functions.  */
  if (!TREE_ASM_WRITTEN (p)
- && DECL_INITIAL (p) != 0
+ && DECL_INITIAL (p) != NULL_TREE
  && TREE_ADDRESSABLE (p)
- && DECL_ABSTRACT_ORIGIN (p) != 0
+ && DECL_ABSTRACT_ORIGIN (p) != NULL_TREE
  && DECL_ABSTRACT_ORIGIN (p) != p)
TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (p)) = 1;
  if (!DECL_EXTERNAL (p)
@@ -1677,18 +1677,18 @@ diagnose_arglist_conflict (tree newdecl, tree olddecl,
 
   if (TREE_CODE (olddecl) != FUNCTION_DECL
   || !comptypes (TREE_TYPE (oldtype), TREE_TYPE (newtype))
-  || !((!prototype_p (oldtype) && DECL_INITIAL (olddecl) == 0)
-  || (!prototype_p (newtype) && DECL_INITIAL (newdecl) == 0)))
+  || !((!prototype_p (oldtype) && DECL_INITIAL (olddecl) == NULL_TREE)
+  || (!prototype_p (newtype) && DECL_INITIAL (newdecl) == NULL_TREE)))
 return;
 
   t = TYPE_ARG_TYPES (oldtype);
-  if (t == 0)
+  if (t == NULL_TREE)
 t = TYPE_ARG_TYPES (newtype);
   for (; t; t = TREE_CHAIN (t))
 {
   tree type = TREE_VALUE (t);
 
-  if (TREE_CHAIN (t) == 0
+

Re: [PATCH] Fix PR middle-end/80775, -O3 produces ice in group_case_labels_stmt

2017-05-17 Thread Peter Bergner
On 5/17/17 2:21 AM, Richard Biener wrote:
> On Tue, 16 May 2017, Peter Bergner wrote:
>> This bootstrapped and regtested with no regressions on both powerpc64le-linux
>> and x86_64-linux.  Is this ok for trunk?
> 
> Ok.

Committed as revision 248155.  Thanks.

Peter



[PATCH, rs6000] gcc mainline, add builtin support for vec_doublee, vec_doubleo, vec_doublel builtins

2017-05-17 Thread Carl E. Love
GCC Maintainers:

This patch adds support for the various vec_doublee, vec_doubleo,
vec_doublel, vec_doubleh builtin-ins.

The patch has been tested on powerpc64le-unknown-linux-gnu (Power 8 LE)
with no regressions.

Is the patch OK for gcc mainline?

  Carl Love
--

gcc/ChangeLog:

2017-05-17  Carl Love  

   * config/rs6000/rs6000-c: Add support for built-in functions
   * config/rs6000/rs6000-builtin.def: Add definitions for
   * config/rs6000/altivec.h: Add define for
   * doc/extend.texi: Update the built-in documentation file for the
   new built-in functions.

gcc/testsuite/ChangeLog:

2017-05-17  Carl Love  

   * gcc.target/powerpc/builtins-3-runable.c: New file of runnable tests
   for the new built-ins.
---
 gcc/config/rs6000/altivec.h|   4 +
 gcc/config/rs6000/altivec.md   | 337 +
 gcc/config/rs6000/rs6000-builtin.def   |  20 ++
 gcc/config/rs6000/rs6000-c.c   |  29 ++
 gcc/doc/extend.texi|  16 +
 .../gcc.target/powerpc/builtins-3-runnable.c   |  84 +
 6 files changed, 490 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/builtins-3-runnable.c

diff --git a/gcc/config/rs6000/altivec.h b/gcc/config/rs6000/altivec.h
index c92bcce..20050eb 100644
--- a/gcc/config/rs6000/altivec.h
+++ b/gcc/config/rs6000/altivec.h
@@ -128,6 +128,10 @@
 #define vec_ctu __builtin_vec_ctu
 #define vec_cpsgn __builtin_vec_copysign
 #define vec_double __builtin_vec_double
+#define vec_doublee __builtin_vec_doublee
+#define vec_doubleo __builtin_vec_doubleo
+#define vec_doublel __builtin_vec_doublel
+#define vec_doubleh __builtin_vec_doubleh
 #define vec_expte __builtin_vec_expte
 #define vec_floor __builtin_vec_floor
 #define vec_loge __builtin_vec_loge
diff --git a/gcc/config/rs6000/altivec.md b/gcc/config/rs6000/altivec.md
index 649f181..7d61641 100644
--- a/gcc/config/rs6000/altivec.md
+++ b/gcc/config/rs6000/altivec.md
@@ -203,6 +203,10 @@
   (KF "FLOAT128_VECTOR_P (KFmode)")
   (TF "FLOAT128_VECTOR_P (TFmode)")])
 
+(define_mode_iterator VM3 [V4SI V4SF])
+(define_mode_attr VM3_char [(V4SI "i")(V4SF "f")])
+(define_mode_attr VM3_x [(V4SI "xw")(V4SF "p")])
+
 ;; Specific iterator for parity which does not have a byte/half-word form, but
 ;; does have a quad word form
 (define_mode_iterator VParity [V4SI
@@ -2739,6 +2743,339 @@
   "stvewx %1,%y0"
   [(set_attr "type" "vecstore")])
 
+;; Generate doublee
+;;signed int/float to double convert words 0 and 2
+(define_expand "doublee2"
+  [(set (match_operand:V2DF 0 "register_operand" "=v")
+(match_operand:VM3 1 "register_operand" "v"))]
+   "TARGET_VSX"
+{
+   machine_mode op_mode = GET_MODE (operands[1]);
+
+   if (VECTOR_ELT_ORDER_BIG)
+ {
+/* Big endian word numbering for words in operand is 0 1 2 3.
+   Input words 0 and 2 are where they need to be. */
+emit_insn (gen_vsx_xvcvsdp (operands[0], operands[1]));
+ }
+   else
+ {
+/* Little endian word numbering for operand is 3 2 1 0.
+   take (operand[1] operand[1]) and shift left one word
+ 3 2 1 03 2 1 0  =>  2 1 0 3
+   Input words 2 and 0 are now where they need to be for the
+   conversion. */
+rtx rtx_tmp;
+rtx rtx_val = GEN_INT (4);
+
+rtx_tmp = gen_reg_rtx (op_mode);
+emit_insn (gen_altivec_vsldoi_v4s (rtx_tmp,
+  operands[1], operands[1], rtx_val));
+emit_insn (gen_vsx_xvcvsdp (operands[0], rtx_tmp));
+ }
+   DONE;
+}
+  [(set_attr "type" "veccomplex")])
+
+;; Generate unsdoublee
+;;unsigned int to double convert words 0 and 2
+(define_expand "unsdoubleev4si2"
+  [(set (match_operand:V2DF 0 "register_operand" "=v")
+(match_operand:V4SI 1 "register_operand" "v"))]
+   "TARGET_VSX"
+{
+   if (VECTOR_ELT_ORDER_BIG)
+ {
+/* Big endian word numbering for words in operand is 0 1 2 3.
+   Input words 0 and 2 are where they need to be. */
+emit_insn (gen_vsx_xvcvuxwdp (operands[0], operands[1]));
+ }
+   else
+ {
+/* Little endian word numbering for operand is 3 2 1 0.
+   take (operand[1] operand[1]) and shift left one word
+ 3 2 1 03 2 1 0  =>   2 1 0 3
+   Input words 2 and 0 are now where they need to be for the
+   conversion. */
+rtx rtx_tmp;
+rtx rtx_val = GEN_INT (4);
+
+rtx_tmp = gen_reg_rtx (V4SImode);
+emit_insn (gen_altivec_vsldoi_v4si (rtx_tmp,
+   operands[1], operands[1], rtx_val));
+emit_insn (gen_vsx_xvcvuxwdp (operands[0], rtx_tmp));
+ }
+   DONE;
+}
+  [(set_attr "type" "veccomplex")])
+
+;; Generate doubleov
+;;signed int/float to double convert words 1 and 3
+(define_expand "doubleo2"
+  [(set (match_o

[PATCH 0/2] [MSP430] Fix issues handling .persistent attribute (PR 78818)

2017-05-17 Thread Jozef Lawrynowicz
The MSP430 target supports an attribute "persistent" that can be set
on variables to indicate that they should be placed in a special
section ".persistent", which will not be re-initialized on reset.

As reported in PR78818
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78818), GCC does not
place variables with the persistent attribute in the .persistent
section if:
1) If -fdata-sections is used.
2) If -mdata-region={lower,upper,either} is used.
3) They are static and initialized to 0 (or uninitialized).

The first of the two following patch fixes these issues by always
setting the section of a variable with the .persistent attribute to
.persistent.

The second patch adds a warning if the persistent attribute is used on
an automatic variable, to warn that this will have no effect.

The patches passed regression testing with "-mcpu=msp430x/-mlarge" for
msp430-elf on the gcc-6-branch (r247086). Trunk doesn't build with C++
support for msp430-elf which is why gcc-6-branch was used.


[PATCH 1/2] [MSP430] Fix issues handling .persistent attribute (PR 78818)

2017-05-17 Thread Jozef Lawrynowicz
Change back end and add tests.

Patch is attached.

Note: Patch will not apply if
https://gcc.gnu.org/ml/gcc-patches/2017-04/msg01030.html has been
committed. "$DEFAULT_CFLAGS" in msp430.exp would need to be changed to
"$MSP430_DEFAULT_CFLAGS".

If the patch is acceptable, I would appreciate if someone could commit
it for me as I do not have write access.

2017-05-XX Jozef Lawrynowicz 
gcc/
PR target/78818
* config/msp430/msp430.c (msp430_unique_section): Set section to
.persistent if persistent attribute is set.

gcc/testsuite
PR target/78818
* gcc.target/msp430/msp430.exp: Search for tests in subfolders as well as
main directory.
* gcc.target/msp430/pr78818/pr78818-real.c: New template for tests.
* gcc.target/msp430/pr78818/pr78818-auto.c: New test.
* gcc.target/msp430/pr78818/pr78818-data-region.c: New test.
* gcc.target/msp430/pr78818/pr78818-data-sec.c: Likewise.


0001-MSP430-Fix-persistent-attribute-not-placing-data-int.patch
Description: Binary data


[PATCH 2/2] [MSP430] Fix issues handling .persistent attribute (PR 78818)

2017-05-17 Thread Jozef Lawrynowicz
Add warning to back end and add test.

Patch is attached.

If the patch is acceptable, I would appreciate if someone could commit
it for me as I do not have write access.

2017-05-XX Jozef Lawrynowicz 
gcc/
PR target/78818
* config/msp430/msp430.c (msp430_unique_section): Warn if .persistent
attribute is used on an automatic variable.

gcc/testsuite
PR target/78818
* gcc.target/msp430/pr78818/pr78818-auto-warn.c: New test.


0002-MSP430-Emit-warning-when-persistent-attribute-is-use.patch
Description: Binary data


[C++ PATCH] extern "C" checking

2017-05-17 Thread Nathan Sidwell
This patch breaks a bit more out of pushdecl.  When pushing an extern 
"C" function, we have to go check for other instances of it in different 
namespaces.  We had lookup_extern_c_fun_in_all_ns to go find it in a 
different namespace.  Looking for a name across all namespaces is the 
one thing our current data representation could do well.  Pity we only 
need it for this case, (and the other use cases suck).


This patch adds a new hash table to record such extern C lists -- and 
commonly of course there are no other instances.  We have to have a new 
hash trait specialization for identifier_node, so that we can use the 
identifier's hash value and not the raw pointer -- because of PCH 
remapping possibilities.  I'll be using this hash table type more later 
on, so this isn't a one-off just for this use.


If it wasn't for redefine_extname pragma we'd only ever need to record a 
single decl per hash slot.


Later patches will use check_extern_c_conflict on another code path, 
where we fail to check properly at the moment.


nathan
--
Nathan Sidwell
2017-05-17  Nathan Sidwell  

	* cp-tree.h (default_hash_traits ): New
	specialization.
	* name-lookup.c (lookup_extern_c_fun_in_all_ns): Delete.
	(extern_c_fns): New hash table.
	(check_extern_c_conflict): New, broken out of ...
	(pushdecl_maybe_friend_1): ... here.  Call it.
	(c_linkage_bindings): Just look in hash table.

Index: cp-tree.h
===
--- cp-tree.h	(revision 248151)
+++ cp-tree.h	(working copy)
@@ -535,6 +535,26 @@ identifier_p (tree t)
   return NULL;
 }
 
+/* Hash trait specialization for lang_identifiers.  This allows
+   PCH-safe maps keyed by DECL_NAME.  If it wasn't for PCH, we could
+   just use a regular tree key.  */
+
+template <>
+struct default_hash_traits 
+  : pointer_hash , ggc_remove 
+{
+  /* Use a regular tree as the type, to make using the hash table
+ simpler.  We'll get dynamic type checking with the hash function
+ itself.  */
+  GTY((skip)) typedef tree value_type;
+  GTY((skip)) typedef tree compare_type;
+
+  static hashval_t hash (const value_type &id)
+  {
+return IDENTIFIER_HASH_VALUE (id);
+  }
+};
+
 /* In an IDENTIFIER_NODE, nonzero if this identifier is actually a
keyword.  C_RID_CODE (node) is then the RID_* value of the keyword.  */
 
Index: name-lookup.c
===
--- name-lookup.c	(revision 248151)
+++ name-lookup.c	(working copy)
@@ -60,7 +60,6 @@ static void consider_binding_level (tree
 enum lookup_name_fuzzy_kind kind);
 static tree lookup_type_current_level (tree);
 static tree push_using_directive (tree);
-static tree lookup_extern_c_fun_in_all_ns (tree);
 static void diagnose_name_conflict (tree, tree);
 
 /* Add DECL to the list of things declared in B.  */
@@ -1184,6 +1183,75 @@ supplement_binding (cxx_binding *binding
   return ret;
 }
 
+/* Map of identifiers to extern C functions (or LISTS thereof).  */
+
+static GTY(()) hash_map *extern_c_fns;
+
+/* DECL has C linkage. If we have an existing instance, make sure it
+   has the same exception specification [7.5, 7.6].  If there's no
+   instance, add DECL to the map.  */
+
+static void
+check_extern_c_conflict (tree decl)
+{
+  /* Ignore artificial or system header decls.  */
+  if (DECL_ARTIFICIAL (decl) || DECL_IN_SYSTEM_HEADER (decl))
+return;
+
+  if (!extern_c_fns)
+extern_c_fns = hash_map::create_ggc (127);
+
+  bool existed;
+  tree *slot = &extern_c_fns->get_or_insert (DECL_NAME (decl), &existed);
+  if (!existed)
+*slot = decl;
+  else
+{
+  tree old = *slot;
+  if (TREE_CODE (old) == TREE_LIST)
+	old = TREE_VALUE (old);
+
+  int mismatch = 0;
+  if (DECL_CONTEXT (old) == DECL_CONTEXT (decl))
+	; /* If they're in the same context, we'll have already complained
+	 about a (possible) mismatch, when inserting the decl.  */
+  else if (!decls_match (decl, old))
+	mismatch = 1;
+  else if (!comp_except_specs (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old)),
+   TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl)),
+   ce_normal))
+	mismatch = -1;
+  else if (DECL_ASSEMBLER_NAME_SET_P (old))
+	SET_DECL_ASSEMBLER_NAME (decl, DECL_ASSEMBLER_NAME (old));
+
+  if (mismatch)
+	{
+	  pedwarn (input_location, 0,
+		   "declaration of %q#D with C language linkage", decl);
+	  pedwarn (DECL_SOURCE_LOCATION (old), 0,
+		   "conflicts with previous declaration %q#D", old);
+	  if (mismatch < 0)
+	pedwarn (input_location, 0,
+		 "due to different exception specifications");
+	}
+  else
+	/* Chain it on for c_linkage_binding's use.  */
+	*slot = tree_cons (NULL_TREE, decl, *slot);
+}
+}
+
+/* Returns a list of C-linkage decls with the name NAME.  Used in
+   c-family/c-pragma.c to implement redefine_extname pragma.  */
+
+tree
+c_linkage_bindings (tree name)
+{
+  if (extern_c_fns)
+if (tree *slot = extern_c_fns->get (name))
+  return *slot;
+  return NULL

[PATCH, Fortran] PR 79968: merge similar diagnostics containing -fdec-structure

2017-05-17 Thread Fritz Reese
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79968

All,

The PR suggests unifying diagnostics of the form "%s at %C is a DEC
extension, enable with ..." I think the patch is obvious/trivial and
speaks for itself. I plan to commit the attached to trunk shortly,
barring any complaints.

(Nb. even with the change in diagnostics, the applicable testcases
(dec_io_3.f90 and dec_static_3.f90) are not regressed as they match
only the "is a DEC extension" portion of the error message.)

---
Fritz Reese

2017-05-17  Fritz Reese 

PR fortran/79968

gcc/fortran/ChangeLog:

PR fortran/79968
* decl.c (match_attr_spec, gfc_match_automatic,
gfc_match_static, gfc_match_structure_decl): Unify diagnostic
errors regarding -fdec options.
* io.c (match_dec_etag, match_dec_vtag, match_dec_ftag): Ditto.
From de4f3b068eff1f33c0f7a8c9a5c328f6c85c712b Mon Sep 17 00:00:00 2001
From: Fritz Reese 
Date: Wed, 17 May 2017 11:36:54 -0400
Subject: [PATCH] 2017-05-17  Fritz Reese  

	PR fortran/79968
	gcc/fortran/
	* decl.c (match_attr_spec, gfc_match_automatic,
	gfc_match_static, gfc_match_structure_decl): Unify diagnostic
	errors regarding -fdec options.
	* io.c (match_dec_etag, match_dec_vtag, match_dec_ftag): Ditto.
---
 gcc/fortran/decl.c | 18 --
 gcc/fortran/io.c   | 12 ++--
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 5ca664e57a5..8d6c2064db4 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -4210,7 +4210,8 @@ match_attr_spec (void)
   if ((d == DECL_STATIC || d == DECL_AUTOMATIC)
 	  && !flag_dec_static)
 	{
-	  gfc_error ("%s at %L is a DEC extension, enable with -fdec-static",
+	  gfc_error ("%s at %L is a DEC extension, enable with "
+		 "%<-fdec-static%>",
 		 d == DECL_STATIC ? "STATIC" : "AUTOMATIC", &seen_at[d]);
 	  m = MATCH_ERROR;
 	  goto cleanup;
@@ -7889,8 +7890,10 @@ gfc_match_automatic (void)
 
   if (!flag_dec_static)
 {
-  gfc_error ("AUTOMATIC at %C is a DEC extension, enable with "
-		 "-fdec-static");
+  gfc_error ("%s at %C is a DEC extension, enable with "
+		 "%<-fdec-static%>",
+		 "AUTOMATIC"
+		 );
   return MATCH_ERROR;
 }
 
@@ -7943,7 +7946,9 @@ gfc_match_static (void)
 
   if (!flag_dec_static)
 {
-  gfc_error ("STATIC at %C is a DEC extension, enable with -fdec-static");
+  gfc_error ("%s at %C is a DEC extension, enable with "
+		 "%<-fdec-static%>",
+		 "STATIC");
   return MATCH_ERROR;
 }
 
@@ -8702,8 +8707,9 @@ gfc_match_structure_decl (void)
 
   if (!flag_dec_structure)
 {
-  gfc_error ("STRUCTURE at %C is a DEC extension, enable with "
-		 "-fdec-structure");
+  gfc_error ("%s at %C is a DEC extension, enable with "
+		 "%<-fdec-structure%>",
+		 "STRUCTURE");
   return MATCH_ERROR;
 }
 
diff --git a/gcc/fortran/io.c b/gcc/fortran/io.c
index 7ab897daa44..b08c785988d 100644
--- a/gcc/fortran/io.c
+++ b/gcc/fortran/io.c
@@ -1515,8 +1515,8 @@ match_dec_etag (const io_tag *tag, gfc_expr **e)
 return m;
   else if (m != MATCH_NO)
 {
-  gfc_error ("%s is a DEC extension at %C, re-compile with "
-	  "-fdec to enable", tag->name);
+  gfc_error ("%s at %C is a DEC extension, enable with "
+		 "%<-fdec%>", tag->name);
   return MATCH_ERROR;
 }
   return m;
@@ -1532,8 +1532,8 @@ match_dec_vtag (const io_tag *tag, gfc_expr **e)
 return m;
   else if (m != MATCH_NO)
 {
-  gfc_error ("%s is a DEC extension at %C, re-compile with "
-	  "-fdec to enable", tag->name);
+  gfc_error ("%s at %C is a DEC extension, enable with "
+		 "%<-fdec%>", tag->name);
   return MATCH_ERROR;
 }
   return m;
@@ -1553,8 +1553,8 @@ match_dec_ftag (const io_tag *tag, gfc_open *o)
 
   if (!flag_dec)
 {
-  gfc_error ("%s is a DEC extension at %C, re-compile with "
-		 "-fdec to enable", tag->name);
+  gfc_error ("%s at %C is a DEC extension, enable with "
+		 "%<-fdec%>", tag->name);
   return MATCH_ERROR;
 }
 
-- 
2.12.2



[PATCH] Fixes to Doxygen comments in libstdc++ headers

2017-05-17 Thread Jonathan Wakely

Nothing very interesting, I noticed a few Doxygen warnings while
building the docs.

* include/bits/refwrap.h: Fix Doxygen warning.
* include/bits/specfun.h: Likewise.
* include/bits/std_function.h: Likewise.
* include/bits/stl_algo.h (set_union, set_intersection)
(set_difference, set_symmetric_difference): Add Doxygen @param tags
for output iterator parameters.
* include/bits/stl_iterator.h (inserter): Add Doxygen @param tag for
iterator parameter.
* include/std/mutex (try_lock, lock): Change Mutex to Lockable in
Doxygen comments.

Committed to trunk.

commit a9465eeeb29c699b88c2f22728a4a5cd248aecad
Author: Jonathan Wakely 
Date:   Wed May 17 11:26:40 2017 +0100

Fixes to Doxygen comments in libstdc++ headers

* include/bits/refwrap.h: Fix Doxygen warning.
* include/bits/specfun.h: Likewise.
* include/bits/std_function.h: Likewise.
* include/bits/stl_algo.h (set_union, set_intersection)
(set_difference, set_symmetric_difference): Add Doxygen @param tags
for output iterator parameters.
* include/bits/stl_iterator.h (inserter): Add Doxygen @param tag for
iterator parameter.
* include/std/mutex (try_lock, lock): Change Mutex to Lockable in
Doxygen comments.

diff --git a/libstdc++-v3/include/bits/refwrap.h 
b/libstdc++-v3/include/bits/refwrap.h
index 786087e..5e5b610 100644
--- a/libstdc++-v3/include/bits/refwrap.h
+++ b/libstdc++-v3/include/bits/refwrap.h
@@ -22,7 +22,7 @@
 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 // .
 
-/** @file include/bits/bind.h
+/** @file include/bits/refwrap.h
  *  This is an internal header file, included by other library headers.
  *  Do not attempt to use it directly. @headername{functional}
  */
diff --git a/libstdc++-v3/include/bits/specfun.h 
b/libstdc++-v3/include/bits/specfun.h
index 6dd23d2..82bd02e 100644
--- a/libstdc++-v3/include/bits/specfun.h
+++ b/libstdc++-v3/include/bits/specfun.h
@@ -118,8 +118,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* versions of this math library because of implementation concerns.
* However, since they were in the TR1 version and since they are popular
* we kept them as an extension in namespace @c __gnu_cxx:
-   * - @ref conf_hyperg "conf_hyperg - Confluent hypergeometric functions"
-   * - @ref hyperg "hyperg - Hypergeometric functions"
+   * - @ref __gnu_cxx::conf_hyperg "conf_hyperg - Confluent hypergeometric 
functions"
+   * - @ref __gnu_cxx::hyperg "hyperg - Hypergeometric functions"
*
* @section general General Features
*
diff --git a/libstdc++-v3/include/bits/std_function.h 
b/libstdc++-v3/include/bits/std_function.h
index b393a94..c4ea347 100644
--- a/libstdc++-v3/include/bits/std_function.h
+++ b/libstdc++-v3/include/bits/std_function.h
@@ -22,7 +22,7 @@
 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 // .
 
-/** @file include/bits/function.h
+/** @file include/bits/std_function.h
  *  This is an internal header file, included by other library headers.
  *  Do not attempt to use it directly. @headername{functional}
  */
diff --git a/libstdc++-v3/include/bits/stl_algo.h 
b/libstdc++-v3/include/bits/stl_algo.h
index 2cd5303..aaa4eef 100644
--- a/libstdc++-v3/include/bits/stl_algo.h
+++ b/libstdc++-v3/include/bits/stl_algo.h
@@ -5103,6 +5103,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
*  @param  __last1   End of first range.
*  @param  __first2  Start of second range.
*  @param  __last2   End of second range.
+   *  @param  __result  Start of output range.
*  @return  End of the output range.
*  @ingroup set_algorithms
*
@@ -5151,6 +5152,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
*  @param  __last1   End of first range.
*  @param  __first2  Start of second range.
*  @param  __last2   End of second range.
+   *  @param  __result  Start of output range.
*  @param  __compThe comparison functor.
*  @return  End of the output range.
*  @ingroup set_algorithms
@@ -5223,6 +5225,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
*  @param  __last1   End of first range.
*  @param  __first2  Start of second range.
*  @param  __last2   End of second range.
+   *  @param  __result  Start of output range.
*  @return  End of the output range.
*  @ingroup set_algorithms
*
@@ -5269,6 +5272,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
*  @param  __last1   End of first range.
*  @param  __first2  Start of second range.
*  @param  __last2   End of second range.
+   *  @param  __result  Start of output range.
*  @param  __compThe comparison functor.
*  @return  End of the output range.
*  @ingroup set_algorithms
@@ -5341,6 +5345,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
*  @param  __last1   End of first range.
*  @param  __first2  Start of second range.
*  @param  __last2   End of second

Re: C PATCH to use NULL_TREE instead of 0 for trees

2017-05-17 Thread Joseph Myers
On Wed, 17 May 2017, Marek Polacek wrote:

> I've always disliked using 0 where NULL_TREE should be.  It's confusing to see
> if (value != 0), which makes value to look like an integer, even though it may
> be a tree.
> 
> Next cleanup will probablyn be about using booleans where desirable.
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
> 
> 2017-05-17  Marek Polacek  
> 
>   * c-common.c: Use NULL_TREE instead of 0 where appropriate.
>   * c-warn.c: Likewise.
> 
>   * c-decl.c: Use NULL_TREE instead of 0 where appropriate.
>   * c-typeck.c: Likewise.

OK.

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


Re: [PATCH] [i386] Recompute the frame layout less often

2017-05-17 Thread Bernd Edlinger
On 05/17/17 04:01, Daniel Santos wrote:
> On 05/16/2017 02:52 PM, Bernd Edlinger wrote:
>> I think I solved the problem with -fsplit-stack, I am not sure
>> if ix86_static_chain_on_stack might change after reload due to
>> final.c possibly calling targetm.calls.static_chain, but if that
>> is the case, that is an already pre-existing problem.
>>
>> The goal of this patch is to make all decisions regarding the
>> frame layout before the reload pass, and to make sure that
>> the frame layout does not change unexpectedly it asserts
>> that the data that goes into the decision does not change
>> after reload_completed.
>>
>> With the attached patch -fsplit-stack and the attribute ms_hook_prologue
>> is handed directly at the ix86_expand_call, because that data is
>> already known before expansion.
>>
>> The calls_eh_return and ix86_static_chain_on_stack may become
>> known at a later time, but after reload it should not change any more.
>> To be sure, I added an assertion at ix86_static_chain, which the
>> regression test did not trigger, neither with -m64 nor with -m32.
>>
>> I have bootstrapped the patch several times, and a few times I
>> encounterd a segfault in the garbage collection, but it did not
>> happen every time.  Currently I think that is unrelated to this patch.
>>
>>
>> Bootstrapped and reg-tested on x86_64-pc-linux-gnu with -m64/-m32.
>> Is it OK for trunk?
>>
>>
>> Thanks
>> Bernd.
>
> With as many formatting errors as I seem to have had, I would like to
> fix those then you patch on top of that if you wouldn't mind terribly.
> While gcc uses subversion, git-blame is still very helpful (then again,
> since Uros committed it for me, I guess that's already off).
>

Apologies if I ruined your patch...

>
>> Index: gcc/config/i386/i386.c
>> ===
>> --- gcc/config/i386/i386.c(revision 248031)
>> +++ gcc/config/i386/i386.c(working copy)
>> @@ -2425,7 +2425,9 @@ static int const x86_64_int_return_registers[4] =
>>
>>  /* Additional registers that are clobbered by SYSV calls.  */
>>
>> -unsigned const x86_64_ms_sysv_extra_clobbered_registers[12] =
>> +#define NUM_X86_64_MS_CLOBBERED_REGS 12
>> +static int const x86_64_ms_sysv_extra_clobbered_registers
>> + [NUM_X86_64_MS_CLOBBERED_REGS] =
>
> Is there a reason you're changing this unsigned to signed int? While
> AX_REG and such are just preprocessor macros, everywhere else it seems
> that register numbers are dealt with as unsigned ints.
>

I actually there seems to be confusion about "int" vs. "unsigned int"
for regno, the advantage of int, is that it can contain -1 as a
exceptional value.  Furthermore there are 3 similar arrays just
above that also use int:

static int const x86_64_int_parameter_registers[6] =
{
   DI_REG, SI_REG, DX_REG, CX_REG, R8_REG, R9_REG
};

static int const x86_64_ms_abi_int_parameter_registers[4] =
{
   CX_REG, DX_REG, R8_REG, R9_REG
};

static int const x86_64_int_return_registers[4] =
{
   AX_REG, DX_REG, DI_REG, SI_REG
};

/* Additional registers that are clobbered by SYSV calls.  */

#define NUM_X86_64_MS_CLOBBERED_REGS 12
static int const x86_64_ms_sysv_extra_clobbered_registers
  [NUM_X86_64_MS_CLOBBERED_REGS] =
{
   SI_REG, DI_REG,
   XMM6_REG, XMM7_REG,
   XMM8_REG, XMM9_REG, XMM10_REG, XMM11_REG,
   XMM12_REG, XMM13_REG, XMM14_REG, XMM15_REG
};

So IMHO it looked odd to have one array use a different type in the
first place.


>> @@ -2484,13 +2486,13 @@ class xlogue_layout {
>>   needs to store registers based upon data in the
>> machine_function.  */
>>HOST_WIDE_INT get_stack_space_used () const
>>{
>> -const struct machine_function &m = *cfun->machine;
>> -unsigned last_reg = m.call_ms2sysv_extra_regs + MIN_REGS - 1;
>> +const struct machine_function *m = cfun->machine;
>> +unsigned last_reg = m->call_ms2sysv_extra_regs + MIN_REGS - 1;
>
> What is the reason for this change?
>

Because a mixture of C and C++ (C wants "struct" machine_function)
looks ugly, and everywhere else in this module, "m" is a pointer and no
reference.

>>
>> -gcc_assert (m.call_ms2sysv_extra_regs <= MAX_EXTRA_REGS);
>> +gcc_assert (m->call_ms2sysv_extra_regs <= MAX_EXTRA_REGS);
>>  return m_regs[last_reg].offset
>> -+ (m.call_ms2sysv_pad_out ? 8 : 0)
>> -+ STUB_INDEX_OFFSET;
>> +   + (m->call_ms2sysv_pad_out ? 8 : 0)
>> +   + STUB_INDEX_OFFSET;
>>}
>>
>>/* Returns the offset for the base pointer used by the stub. */
>> @@ -2532,7 +2534,7 @@ class xlogue_layout {
>>/* Lazy-inited cache of symbol names for stubs.  */
>>char
>> m_stub_names[XLOGUE_STUB_COUNT][VARIANT_COUNT][STUB_NAME_MAX_LEN];
>>
>> -  static const struct xlogue_layout GTY(())
>> s_instances[XLOGUE_SET_COUNT];
>> +  static const struct GTY(()) xlogue_layout
>> s_instances[XLOGUE_SET_COUNT];
>
> Hmm, during development I originally had C-style xlogue_layout as a
> struct and later decided to make it a cl

[PATCH, committed] Typo in gcc.target/powerpc/pr78604.c

2017-05-17 Thread Bill Schmidt
Hi,

I apparently committed the wrong version of this file with a typo in the
dg-options.  Fixed, tested on powerpc64le-unknown-linux-gnu, committed
as obvious.

Thanks,
Bill


2017-05-17  Bill Schmidt  

* gcc.target/powerpc/pr78604.c: Fix typo in dg-options.


Index: gcc/testsuite/gcc.target/powerpc/pr78604.c
===
--- gcc/testsuite/gcc.target/powerpc/pr78604.c  (revision 248164)
+++ gcc/testsuite/gcc.target/powerpc/pr78604.c  (working copy)
@@ -2,7 +2,7 @@
 /* { dg-skip-if "" { powerpc*-*-darwin* } { "*" } { "" } } */
 /* { dg-require-effective-target powerpc_p8vector_ok } */
 /* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { 
"-mcpu=power8" } } */
-/* { dg-options "-mcpu=power8 -O2 -ftree-vectorize -fdump-tree-details" } */
+/* { dg-options "-mcpu=power8 -O2 -ftree-vectorize -fdump-tree-vect-details" } 
*/
 
 #ifndef SIZE
 #define SIZE 1024



[other/80803] libgo

2017-05-17 Thread Nathan Sidwell

Bill,
the revision you converged on is, as Ian, says, just moving some 
interface around.  That was needed to fix obj-c++.


This diff is the combination of that patch and its logical predecessor. 
Does reverting this diff get you back to normalcy?


nathan
--
Nathan Sidwell
Index: gcc/cp/cp-lang.c
===
--- gcc/cp/cp-lang.c	(revision 248144)
+++ gcc/cp/cp-lang.c	(working copy)
@@ -229,6 +229,5 @@ tree cxx_enum_underlying_base_type (cons
   return underlying_type;
 }
 
-
 #include "gt-cp-cp-lang.h"
 #include "gtype-cp.h"
Index: gcc/cp/cp-objcp-common.c
===
--- gcc/cp/cp-objcp-common.c	(revision 248144)
+++ gcc/cp/cp-objcp-common.c	(working copy)
@@ -336,22 +336,6 @@ cxx_block_may_fallthru (const_tree stmt)
 }
 }
 
-/* Return the list of decls in the global namespace.  */
-
-tree
-cp_get_global_decls ()
-{
-  return NAMESPACE_LEVEL (global_namespace)->names;
-}
-
-/* Push DECL into the current scope.  */
-
-tree
-cp_pushdecl (tree decl)
-{
-  return pushdecl (decl);
-}
-
 void
 cp_common_init_ts (void)
 {
Index: gcc/cp/cp-objcp-common.h
===
--- gcc/cp/cp-objcp-common.h	(revision 248144)
+++ gcc/cp/cp-objcp-common.h	(working copy)
@@ -31,8 +31,6 @@ extern int cp_decl_dwarf_attribute (cons
 extern int cp_type_dwarf_attribute (const_tree, int);
 extern void cp_common_init_ts (void);
 extern tree cp_unit_size_without_reusable_padding (tree);
-extern tree cp_get_global_decls ();
-extern tree cp_pushdecl (tree);
 
 /* Lang hooks that are shared between C++ and ObjC++ are defined here.  Hooks
specific to C++ or ObjC++ go in cp/cp-lang.c and objcp/objcp-lang.c,
@@ -167,9 +165,4 @@ extern tree cp_pushdecl (tree);
 
 #undef LANG_HOOKS_EH_PROTECT_CLEANUP_ACTIONS
 #define LANG_HOOKS_EH_PROTECT_CLEANUP_ACTIONS cp_protect_cleanup_actions
-
-#undef LANG_HOOKS_GETDECLS
-#define LANG_HOOKS_GETDECLS cp_get_global_decls
-#undef LANG_HOOKS_PUSHDECL
-#define LANG_HOOKS_PUSHDECL cp_pushdecl
 #endif /* GCC_CP_OBJCP_COMMON */
Index: gcc/cp/name-lookup.c
===
--- gcc/cp/name-lookup.c	(revision 248144)
+++ gcc/cp/name-lookup.c	(working copy)
@@ -1872,6 +1872,16 @@ pushdecl (tree x, bool is_friend)
   return ret;
 }
 
+/* Wrapper for non-friend version.  We have to use a wrapper, rather
+   than default arg, as pieces of the core compiler expect this entry
+   point to exist.  */
+
+tree
+pushdecl (tree x)
+{
+  return pushdecl (x, false);
+}
+
 /* Enter DECL into the symbol table, if that's appropriate.  Returns
DECL, or a modified version thereof.  */
 
@@ -2367,6 +2377,15 @@ get_local_decls (void)
   return current_binding_level->names;
 }
 
+/* Get the global decls.  */
+
+tree
+getdecls (void)
+{
+  gcc_assert (current_binding_level == NAMESPACE_LEVEL (global_namespace));
+  return current_binding_level->names;
+}
+
 /* Return how many function prototypes we are currently nested inside.  */
 
 int
Index: gcc/cp/name-lookup.h
===
--- gcc/cp/name-lookup.h	(revision 248144)
+++ gcc/cp/name-lookup.h	(working copy)
@@ -320,6 +320,7 @@ extern bool pushdecl_class_level (tree);
 extern tree pushdecl_namespace_level (tree, bool);
 extern bool push_class_level_binding (tree, tree);
 extern tree get_local_decls ();
+extern tree getdecls();
 extern int function_parm_depth (void);
 extern tree cp_namespace_decls (tree);
 extern void set_decl_namespace (tree, tree, bool);
@@ -338,7 +339,8 @@ extern cxx_binding *outer_binding (tree,
 extern void cp_emit_debug_info_for_using (tree, tree);
 
 extern tree pushdecl_outermost_localscope (tree);
-extern tree pushdecl (tree, bool is_friend = false);
+extern tree pushdecl (tree, bool is_friend);
+extern tree pushdecl (tree);
 extern tree pushdecl_top_level (tree, bool is_friend = false);
 extern tree pushdecl_top_level_and_finish (tree, tree);
 extern tree pushtag (tree, tree, tag_scope);


Re: [other/80803] libgo

2017-05-17 Thread Nathan Sidwell

On 05/17/2017 01:53 PM, Nathan Sidwell wrote:

Bill,
the revision you converged on is, as Ian, says, just moving some 
interface around.  That was needed to fix obj-c++.


This diff is the combination of that patch and its logical predecessor. 
Does reverting this diff get you back to normalcy?


Sorry, apply this diff. I'd already done the -R applying bits

nathan

--
Nathan Sidwell


[PATCH] Fix comparison of decimal float zeroes (PR80692)

2017-05-17 Thread Segher Boessenkool
Decimal float negative zero should compare equal to positive zero.
Decimal float zeroes are encoded as value class "normal" (in real.c);
they need to be handled specially, but in this one case that does not
yet happen.  This fixes it.

Bootstrapped and tested on powerpc64-linux {-m32,-m64}; also tested
the testcase separately (it fails before the test, except at -O0; it
passes after it).

Is this okay for trunk?


Segher


2017-05-17  Segher Boessenkool  

PR middle-end/80692
* real.c (do_compare): Give decimal_do_compare preference over
comparing just the signs.

gcc/testsuite/
PR middle-end/80692
* gcc.c-torture/execute/pr80692.c: New testcase.

---
 gcc/real.c|  6 +++---
 gcc/testsuite/gcc.c-torture/execute/pr80692.c | 13 +
 2 files changed, 16 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr80692.c

diff --git a/gcc/real.c b/gcc/real.c
index 97452a9..a5671b2 100644
--- a/gcc/real.c
+++ b/gcc/real.c
@@ -960,12 +960,12 @@ do_compare (const REAL_VALUE_TYPE *a, const 
REAL_VALUE_TYPE *b,
   gcc_unreachable ();
 }
 
-  if (a->sign != b->sign)
-return -a->sign - -b->sign;
-
   if (a->decimal || b->decimal)
 return decimal_do_compare (a, b, nan_result);
 
+  if (a->sign != b->sign)
+return -a->sign - -b->sign;
+
   if (REAL_EXP (a) > REAL_EXP (b))
 ret = 1;
   else if (REAL_EXP (a) < REAL_EXP (b))
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr80692.c 
b/gcc/testsuite/gcc.c-torture/execute/pr80692.c
new file mode 100644
index 000..e653c71
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr80692.c
@@ -0,0 +1,13 @@
+/* { dg-require-effective-target dfp } */
+
+int main () {
+   _Decimal64 d64 = -0.DD;
+
+   if (d64 != 0.DD)
+   __builtin_abort ();
+
+   if (d64 != -0.DD)
+   __builtin_abort ();
+
+   return 0;
+}
-- 
1.9.3



Re: [PATCH] [i386] Recompute the frame layout less often

2017-05-17 Thread Bernd Edlinger
On 05/15/17 03:39, Daniel Santos wrote:
> On 05/14/2017 11:31 AM, Bernd Edlinger wrote:
>> Hi Daniel,
>>
>> there is one thing I don't understand in your patch:
>> That is, it introduces a static value:
>>
>> /* Registers who's save & restore will be managed by stubs called from
>>  pro/epilogue.  */
>> static HARD_REG_SET GTY(()) stub_managed_regs;
>>
>> This seems to be set as a side effect of ix86_compute_frame_layout,
>> and depends on the register usage of the current function.
>> But values that depend on the current function need usually be
>> attached to cfun->machine, because the passes can run in parallel
>> unless I am completely mistaken, and the stub_managed_regs may
>> therefore be computed from a different function.
>>
>>
>> Bernd.
>
> I should add that if you want to run faster tests just on the ms to sysv
> abi code, you can use make RUNTESTFLAGS="ms-sysv.exp" check and then if
> that succeeds run the full testsuite.
>
> Daniel

Hmm, that's funny...

If I use "make check-c RUNTESTFLAGS="ms-sysv.exp" -j8" it seems to work,
but if I omit the -j8 it fails:

make check-c RUNTESTFLAGS="ms-sysv.exp"
...Test Run By ed on Wed May 17 20:38:24 2017
Native configuration is x86_64-pc-linux-gnu

=== gcc tests ===

Schedule of variations:
 unix

Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file 
for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for 
target.
Using /home/ed/gnu/gcc-trunk/gcc/testsuite/config/default.exp as 
tool-and-target-specific interface file.
Running 
/home/ed/gnu/gcc-trunk/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.exp 
...
ERROR: tcl error sourcing 
/home/ed/gnu/gcc-trunk/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.exp.
ERROR: no such variable
 (read trace on "env(GCC_RUNTEST_PARALLELIZE_DIR)")
 invoked from within
"set parallel_dir "$env(GCC_RUNTEST_PARALLELIZE_DIR)/abi-ms-sysv""
 (file 
"/home/ed/gnu/gcc-trunk/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.exp"
 
line 154)
 invoked from within
"source 
/home/ed/gnu/gcc-trunk/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.exp"
 ("uplevel" body line 1)
 invoked from within
"uplevel #0 source 
/home/ed/gnu/gcc-trunk/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.exp"
 invoked from within
"catch "uplevel #0 source $test_file_name""

=== gcc Summary ===

/home/ed/gnu/gcc-build/gcc/xgcc  version 8.0.0 20170514 (experimental) 
(GCC)

make[2]: Leaving directory `/home/ed/gnu/gcc-build/gcc'
make[1]: Leaving directory `/home/ed/gnu/gcc-build/gcc'



Bernd.


Re: [patch, fortran] PR80741 [Regression 7/8] DTIO wrong code causes incorrect behaviour of namelist READ

2017-05-17 Thread Paul Richard Thomas
Hi Jerry,

OK for trunk and for 7-branch after a delay.

Cheers and thanks

Paul

On 17 May 2017 at 06:34, Jerry DeLisle  wrote:
> Hi all,
>
> When I first looked at this I thought the minor front end bobble was the
> problem. That turns out to be unrelated but needed to be fixed in trans-io.c
>
> The actual problem was that when I moved the last_char to the unit
> structure, needed for DTIO, the value saved there persists across I/O
> operations so in the case of the PR the REWIND was was working but the EOF
> character from the preceding read was passed on.
>
> I conservatively have reset the last_char in several places out of concern
> for missing a code path on this.
>
> Regression tested on x86_64.  New test case attached.
>
> OK for trunk and then back port to 7 in about a week?
>
> Regards,
>
> Jerry
>
> 2017-05-16  Jerry DeLisle  
>
> PR fortran/80741
> * trans-io.c (transfer_namelist_element): Change check from
> NULL_TREE to null_pointer_node.
>
> 2017-05-16  Jerry DeLisle  
>
> PR libgfortran/80741
> * transfer.c (finalize_transfer): Reset last_char to 'empty'.
> * file_pos.c (formatted_backspace): Likewise.
> (st_endfile): Likewise.
> (st_rewind): Likewise.
> (st_flush): Likewise.



-- 
"If you can't explain it simply, you don't understand it well enough"
- Albert Einstein


Re: [PATCH, Fortran] PR 79968: merge similar diagnostics containing -fdec-structure

2017-05-17 Thread Paul Richard Thomas
Hi Fritz,

Yes, that's good for trunk.

Thanks

Paul


On 17 May 2017 at 16:51, Fritz Reese  wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79968
>
> All,
>
> The PR suggests unifying diagnostics of the form "%s at %C is a DEC
> extension, enable with ..." I think the patch is obvious/trivial and
> speaks for itself. I plan to commit the attached to trunk shortly,
> barring any complaints.
>
> (Nb. even with the change in diagnostics, the applicable testcases
> (dec_io_3.f90 and dec_static_3.f90) are not regressed as they match
> only the "is a DEC extension" portion of the error message.)
>
> ---
> Fritz Reese
>
> 2017-05-17  Fritz Reese 
>
> PR fortran/79968
>
> gcc/fortran/ChangeLog:
>
> PR fortran/79968
> * decl.c (match_attr_spec, gfc_match_automatic,
> gfc_match_static, gfc_match_structure_decl): Unify diagnostic
> errors regarding -fdec options.
> * io.c (match_dec_etag, match_dec_vtag, match_dec_ftag): Ditto.



-- 
"If you can't explain it simply, you don't understand it well enough"
- Albert Einstein


[PATCH, rs6000] Fold Vector misc - fix testcases

2017-05-17 Thread Will Schmidt
Review and update the dg-require-effective-target clauses
for the fold-vec-* tests.  Most of the tests affected here had
specified altivec when they actually needed VSX.

Also simplified the related dg-options statements to eliminate
redundancies.

The testcases have now been double-checked in p6,p7,p8le,p8be
environments.  The test failures reported on AIX appear to match
what I observed in a P6 environment, which had Altivec but not
VSX support, so I expect this update to clear those issues up.

OK for trunk?

Thanks,
-Will

[gcc/testsuite]

2017-05-17  Will Schmidt  

* fold-vec-div-float.c: Update dg-requires and dg-options statements.
* fold-vec-div-floatdouble.c: Likewise.
* fold-vec-div-longlong.c: Likewise.
* fold-vec-logical-ands-char.c: Likewise.
* fold-vec-logical-ands-int.c: Likewise.
* fold-vec-logical-ands-short.c: Likewise.
* fold-vec-logical-ors-char.c: Likewise.
* fold-vec-logical-ors-int.c: Likewise.
* fold-vec-logical-ors-short.c: Likewise.
* fold-vec-logical-other-char.c: Likewise.
* fold-vec-mule-misc.c: Likewise.
* fold-vec-mult-float.c: Likewise.
* fold-vec-mult-floatdouble.c: Likewise.
* fold-vec-mult-int.c: Likewise.
* fold-vec-mult-int128-p8.c: Likewise.
* fold-vec-mult-int128-p9.c: Likewise.
* fold-vec-sub-floatdouble.c: Likewise.
* fold-vec-logical-ors-longlong.c: Fix comment typo.



diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-div-float.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-div-float.c
index 8e8f645..47254ce 100644
--- a/gcc/testsuite/gcc.target/powerpc/fold-vec-div-float.c
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-div-float.c
@@ -1,9 +1,9 @@
 /* Verify that overloaded built-ins for vec_div with float
-   inputs produce the right results with -maltivec.  */
+   inputs produce the right results.  */
 
 /* { dg-do compile } */
-/* { dg-require-effective-target powerpc_altivec_ok } */
-/* { dg-options "-maltivec" } */
+/* { dg-require-effective-target powerpc_vsx_ok } */
+/* { dg-options "-mvsx" } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-div-floatdouble.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-div-floatdouble.c
index 0559013..569467e 100644
--- a/gcc/testsuite/gcc.target/powerpc/fold-vec-div-floatdouble.c
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-div-floatdouble.c
@@ -1,9 +1,9 @@
 /* Verify that overloaded built-ins for vec_div with float and
-   double inputs for VSX produce the right results with -mvsx. */
+   double inputs for VSX produce the right results. */
 
 /* { dg-do compile } */
 /* { dg-require-effective-target powerpc_vsx_ok } */
-/* { dg-options "-maltivec" } */
+/* { dg-options "-mvsx" } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-div-longlong.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-div-longlong.c
index c37c648..e3f9e02 100644
--- a/gcc/testsuite/gcc.target/powerpc/fold-vec-div-longlong.c
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-div-longlong.c
@@ -2,8 +2,8 @@
inputs produce the right results.  */
 
 /* { dg-do compile } */
-/* { dg-require-effective-target powerpc_p8vector_ok } */
-/* { dg-options "-maltivec -mpower8-vector -O3" } */
+/* { dg-require-effective-target powerpc_vsx_ok } */
+/* { dg-options "-mvsx -O2" } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-logical-ands-char.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-logical-ands-char.c
index 021da58..d1f66f4 100644
--- a/gcc/testsuite/gcc.target/powerpc/fold-vec-logical-ands-char.c
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-logical-ands-char.c
@@ -3,7 +3,7 @@
 
 /* { dg-do compile } */
 /* { dg-require-effective-target powerpc_vsx_ok } */
-/* { dg-options "-maltivec -O1" } */
+/* { dg-options "-mvsx -O1" } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-logical-ands-int.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-logical-ands-int.c
index ccac7d5..59a23e8 100644
--- a/gcc/testsuite/gcc.target/powerpc/fold-vec-logical-ands-int.c
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-logical-ands-int.c
@@ -2,8 +2,8 @@
  * with int inputs produce the right results.  */
 
 /* { dg-do compile } */
-/* { dg-require-effective-target powerpc_altivec_ok } */
-/* { dg-options "-maltivec -O1" } */
+/* { dg-require-effective-target powerpc_vsx_ok } */
+/* { dg-options "-mvsx -O1" } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-logical-ands-short.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-logical-ands-short.c
index 8ee3206..805d345 100644
--- a/gcc/testsuite/gcc.target/powerpc/fold-vec-logical-ands-short.c
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-logical-ands-short.c
@@ -2,8 +2,8 @@
inputs produce the right results.  */
 
 /* { dg-do compile } */
-/* { dg-require-effective-target powerpc_altivec_ok } */
-/* { dg-options "-maltivec -O1" } */
+/* { dg-require-e

[PATCH 1/4] Fix typo in config/sparc/sol2.h

2017-05-17 Thread Sheldon Lobo
* config/sparc/sol2.h: Fix a ASM_CPU32_DEFAULT_SPEC typo.
---
 gcc/config/sparc/sol2.h |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/gcc/config/sparc/sol2.h b/gcc/config/sparc/sol2.h
index db24ca3..8a50bfe 100644
--- a/gcc/config/sparc/sol2.h
+++ b/gcc/config/sparc/sol2.h
@@ -169,7 +169,7 @@ along with GCC; see the file COPYING3.  If not see
 #undef CPP_CPU64_DEFAULT_SPEC
 #define CPP_CPU64_DEFAULT_SPEC ""
 #undef ASM_CPU32_DEFAULT_SPEC
-#define ASM_CPU32_DEFAUILT_SPEC AS_SPARC32_FLAG AS_NIAGARA7_FLAG
+#define ASM_CPU32_DEFAULT_SPEC AS_SPARC32_FLAG AS_NIAGARA7_FLAG
 #undef ASM_CPU64_DEFAULT_SPEC
 #define ASM_CPU64_DEFAULT_SPEC AS_SPARC64_FLAG AS_NIAGARA7_FLAG
 #endif
-- 
1.7.1



[PATCH 0/4] Minor SPARC T4 and M7 fixes and additions

2017-05-17 Thread Sheldon Lobo
This patch series contains small fixes and updates for the SPARC 
platform.

Patch 1 fixes a small typo in sol2.h

Patch 2 sets a branch cost for the SPARC T4 processor.

Patch 3 sets a branch cost for the SPARC M7 processor.

Patch 4 changes the function alignment for the M7 processor from 4 to 8 bytes.

Thanks!

Sheldon Lobo (4):
  Fix typo in config/sparc/sol2.h
  Add a branch cost for SPARC T4.
  Add a branch cost for SPARC M7.
  Set function alignment for M7 to 8 bytes.

 gcc/config/sparc/sol2.h |2 +-
 gcc/config/sparc/sparc.c|   13 -
 gcc/config/sparc/sparc.h|   11 +--
 gcc/testsuite/gcc.target/sparc/niagara7-align.c |4 
 4 files changed, 22 insertions(+), 8 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/sparc/niagara7-align.c



[PATCH 4/4] Set function alignment for M7 to 8 bytes.

2017-05-17 Thread Sheldon Lobo
* config/sparc/sparc.c (sparc_option_override): Set function
alignment for -mcpu=niagara7 to 64 to match the I$ line.
* testsuite/gcc.target/sparc/niagara7-align.c: Test case with
-mcpu=niagara7 -falign-functions.
---
 gcc/config/sparc/sparc.c|   13 -
 gcc/testsuite/gcc.target/sparc/niagara7-align.c |4 
 2 files changed, 12 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/sparc/niagara7-align.c

diff --git a/gcc/config/sparc/sparc.c b/gcc/config/sparc/sparc.c
index 8277496..6dfb269 100644
--- a/gcc/config/sparc/sparc.c
+++ b/gcc/config/sparc/sparc.c
@@ -1528,15 +1528,18 @@ sparc_option_override (void)
 target_flags |= MASK_LRA;
 
   /* Supply a default value for align_functions.  */
-  if (align_functions == 0
-  && (sparc_cpu == PROCESSOR_ULTRASPARC
+  if (align_functions == 0)
+{
+  if (sparc_cpu == PROCESSOR_ULTRASPARC
  || sparc_cpu == PROCESSOR_ULTRASPARC3
  || sparc_cpu == PROCESSOR_NIAGARA
  || sparc_cpu == PROCESSOR_NIAGARA2
  || sparc_cpu == PROCESSOR_NIAGARA3
- || sparc_cpu == PROCESSOR_NIAGARA4
- || sparc_cpu == PROCESSOR_NIAGARA7))
-align_functions = 32;
+ || sparc_cpu == PROCESSOR_NIAGARA4)
+   align_functions = 32;
+  else if (sparc_cpu == PROCESSOR_NIAGARA7)
+   align_functions = 64;
+}
 
   /* Validate PCC_STRUCT_RETURN.  */
   if (flag_pcc_struct_return == DEFAULT_PCC_STRUCT_RETURN)
diff --git a/gcc/testsuite/gcc.target/sparc/niagara7-align.c 
b/gcc/testsuite/gcc.target/sparc/niagara7-align.c
new file mode 100644
index 000..a46aac1
--- /dev/null
+++ b/gcc/testsuite/gcc.target/sparc/niagara7-align.c
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* { dg-options "-falign-functions -mcpu=niagara7" } */
+/* { dg-final { scan-assembler "\.align 64" } } */
+void foo(void) {}
-- 
1.7.1



[PATCH 2/4] Add a branch cost for SPARC T4.

2017-05-17 Thread Sheldon Lobo
* config/sparc/sparc.h (BRANCH_COST): Set the SPARC T4 branch
latency to 2.
---
 gcc/config/sparc/sparc.h |8 ++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/gcc/config/sparc/sparc.h b/gcc/config/sparc/sparc.h
index 590a5f4..6277738 100644
--- a/gcc/config/sparc/sparc.h
+++ b/gcc/config/sparc/sparc.h
@@ -1566,7 +1566,9 @@ do {  
   \
and annulled branches insert 4 bubbles.
 
On Niagara-2 and Niagara-3, a not-taken branch costs 1 cycle whereas
-   a taken branch costs 6 cycles.  */
+   a taken branch costs 6 cycles.
+
+   The T4 Supplement specifies the branch latency at 2 cycles. */
 
 #define BRANCH_COST(speed_p, predictable_p) \
((sparc_cpu == PROCESSOR_V9 \
@@ -1579,7 +1581,9 @@ do {  
   \
 : ((sparc_cpu == PROCESSOR_NIAGARA2 \
 || sparc_cpu == PROCESSOR_NIAGARA3) \
? 5 \
-: 3
+: (sparc_cpu == PROCESSOR_NIAGARA4 \
+   ? 2 \
+: 3)
 
 /* Control the assembler format that we output.  */
 
-- 
1.7.1



[PATCH 3/4] Add a branch cost for SPARC M7.

2017-05-17 Thread Sheldon Lobo
* config/sparc/sparc.h (BRANCH_COST): Set the SPARC M7 branch
latency to 1.
---
 gcc/config/sparc/sparc.h |7 +--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/gcc/config/sparc/sparc.h b/gcc/config/sparc/sparc.h
index 6277738..686a3d5 100644
--- a/gcc/config/sparc/sparc.h
+++ b/gcc/config/sparc/sparc.h
@@ -1568,7 +1568,8 @@ do {  
   \
On Niagara-2 and Niagara-3, a not-taken branch costs 1 cycle whereas
a taken branch costs 6 cycles.
 
-   The T4 Supplement specifies the branch latency at 2 cycles. */
+   The T4 Supplement specifies the branch latency at 2 cycles.
+   The M7 Supplement specifies the branch latency at 1 cycle. */
 
 #define BRANCH_COST(speed_p, predictable_p) \
((sparc_cpu == PROCESSOR_V9 \
@@ -1583,7 +1584,9 @@ do {  
   \
? 5 \
 : (sparc_cpu == PROCESSOR_NIAGARA4 \
? 2 \
-: 3)
+: (sparc_cpu == PROCESSOR_NIAGARA7 \
+   ? 1 \
+: 3))
 
 /* Control the assembler format that we output.  */
 
-- 
1.7.1



Re: [PATCH 0/4] Minor SPARC T4 and M7 fixes and additions

2017-05-17 Thread Eric Botcazou
> This patch series contains small fixes and updates for the SPARC
> platform.
> 
> Patch 1 fixes a small typo in sol2.h
> 
> Patch 2 sets a branch cost for the SPARC T4 processor.
> 
> Patch 3 sets a branch cost for the SPARC M7 processor.
> 
> Patch 4 changes the function alignment for the M7 processor from 4 to 8
> bytes.

Thanks, the whole series looks good to me and can probably be applied to every 
branch supporting the M7 processor.

Do you plan to contribute more patches?  If so, are you interested in having 
write access to the repository?  In that case, you can request it by means of 
the form linked to from https://gcc.gnu.org/svnwrite.html with me as sponsor.

-- 
Eric Botcazou


Re: [PATCH 4/4] Set function alignment for M7 to 8 bytes.

2017-05-17 Thread Eric Botcazou
>   * config/sparc/sparc.c (sparc_option_override): Set function
>   alignment for -mcpu=niagara7 to 64 to match the I$ line.
>   * testsuite/gcc.target/sparc/niagara7-align.c: Test case with
>   -mcpu=niagara7 -falign-functions.

The testsuite directory has its own ChangeLog file so the second item must go 
there without the testsuite/ prefix (and "New test" is enough in this case):

* gcc.target/sparc/niagara7-align.c: New test.

-- 
Eric Botcazou


libgo patch committed: add "vendor" to pkgpath for vendored standard packages

2017-05-17 Thread Ian Lance Taylor
This libgo patch ensures that the packages vendored into the standard
library do not have the same pkgpath as the actual packages.  If we
don't, attempts to build and test the actual packages will get
confused.  The specific error I was seeing was import loops, causing
some of the packages to fail to get initialized, causing an obscure
run time crash.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline and GCC 7 branch.

Ian
Index: gcc/go/gofrontend/MERGE
===
--- gcc/go/gofrontend/MERGE (revision 248082)
+++ gcc/go/gofrontend/MERGE (working copy)
@@ -1,4 +1,4 @@
-924a1fcc5658a5d66f5015921d7258e3a77519bc
+ba68a42618d1e8516e38da093d3af731d7fd4f06
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/Makefile.am
===
--- libgo/Makefile.am   (revision 247848)
+++ libgo/Makefile.am   (working copy)
@@ -910,7 +910,7 @@ BUILDDEPS = \
 BUILDPACKAGE = \
$(MKDIR_P) $(@D); \
files=`echo $^ | sed -e 's/[^ ]*\.gox//g' -e 's/[^ ]*\.dep//'`; \
-   $(LTGOCOMPILE) -I . -c -fgo-pkgpath=`echo $@ | sed -e 's/.lo$$//'` 
$($(subst -,_,$(subst .,_,$(subst /,_,$@)))_GOCFLAGS) -o $@ $$files
+   $(LTGOCOMPILE) -I . -c -fgo-pkgpath=`echo $@ | sed -e 's/.lo$$//' -e 
's|golang_org|vendor/golang_org|'` $($(subst -,_,$(subst .,_,$(subst 
/,_,$@)))_GOCFLAGS) -o $@ $$files
 
 # How to build a .gox file from a .lo file.
 # Matching .o file can either be in the same directory as the .lo (non-PIC


Re: [PATCH 4/4] Set function alignment for M7 to 8 bytes.

2017-05-17 Thread Sheldon Lobo


On 05/17/2017 04:11 PM, Eric Botcazou wrote:

* config/sparc/sparc.c (sparc_option_override): Set function
alignment for -mcpu=niagara7 to 64 to match the I$ line.
* testsuite/gcc.target/sparc/niagara7-align.c: Test case with
-mcpu=niagara7 -falign-functions.


The testsuite directory has its own ChangeLog file so the second item must go
there without the testsuite/ prefix (and "New test" is enough in this case):

* gcc.target/sparc/niagara7-align.c: New test.



Thanks for the feedback!

Just so I am clear, gcc/testsuite/ChangeLog needs to be
checked into the patch (but gcc/ChangeLog is not)?

Sorry for the newbie question,
Sheldon


Re: [PATCH] Fix comparison of decimal float zeroes (PR80692)

2017-05-17 Thread Ben Elliston
On Wed, May 17, 2017 at 06:36:38PM +, Segher Boessenkool wrote:

> 2017-05-17  Segher Boessenkool  
> 
>   PR middle-end/80692
>   * real.c (do_compare): Give decimal_do_compare preference over
>   comparing just the signs.
> 
> gcc/testsuite/
>   PR middle-end/80692
>   * gcc.c-torture/execute/pr80692.c: New testcase.

OK, thanks.

Cheers,
Ben


signature.asc
Description: Digital signature


Re: [patch] FreeBSD arm: make _Unwind_G/SetIP available as function.

2017-05-17 Thread Andreas Tobler

On 07.05.17 21:23, Andreas Tobler wrote:

Hi all,

On FreeBSD we make use of the functions _Unwind_GetIP, _Unwind_GetIPInfo
and _Unwind_SetIP outside of GCC. All other FreeBSD targets have these
functions available except arm.

Now since the GCC port for arm*-*-freebsd* is used more often (not only
by me ;), I was pointed out that these functions are not available.

The below patch tries to fix this.

Is the patch ok for trunk and after a while also for all active
branches? (7,6,5?)

I am the FreeBSD maintainer, yes, but I prefer to have an ack since the
affected files are not only used by FreeBSD. And if somebody has better
idea, I welcome the input.


Commit to trunk done. Branch commits will follow soon.
Andreas



TIA,
Andreas

2017-05-07  Andreas Tobler  

* config/arm/unwind-arm.h: Make _Unwind_GetIP, _Unwind_GetIPInfo and
_Unwind_SetIP available as functions for arm*-*-freebsd*.
* config/arm/unwind-arm.c: Implement the above.





Re: [other/80803] libgo

2017-05-17 Thread Bill Schmidt
Hi Nathan,

Interestingly, this patch applies cleanly, but does *not* solve the problem 
with libgo.  
Another puzzling development, since bisection showed all revisions before this
being clean and all revisions afterward being problematic.  Drat. :(

I will have to go deeper into what's happening with the libgo test.

Thanks for the patch!  Too bad it didn't make a difference, though I can't be
surprised since the revision targeted by the bisect looks so innocuous.

Bill

> On May 17, 2017, at 1:02 PM, Nathan Sidwell  wrote:
> 
> On 05/17/2017 01:53 PM, Nathan Sidwell wrote:
>> Bill,
>> the revision you converged on is, as Ian, says, just moving some interface 
>> around.  That was needed to fix obj-c++.
>> This diff is the combination of that patch and its logical predecessor. Does 
>> reverting this diff get you back to normalcy?
> 
> Sorry, apply this diff. I'd already done the -R applying bits
> 
> nathan
> 
> -- 
> Nathan Sidwell
> 



[PATCH rs6000] Fix up dg-options for BMI intrinsic tests

2017-05-17 Thread Steven Munroe
David pointed out that I my earlier X86 BMI intrinsic header submission
was causing make check failures on on powerpc64le platforms. The patch
below tests out on Linux BE powerpc64/32 and should also resolve the
failures on AIX. I don't have access to a AIX so David can you give this
patch a quick test.

Thanks.

[gcc/testsuite]

2017-05-17  Steven Munroe  

* gcc.target/powerpc/bmi-andn-1.c: Fix-up dg-options.
* gcc.target/powerpc/bmi-andn-2.c: Fix-up dg-options.
* gcc.target/powerpc/bmi-bextr-1.c: Fix-up dg-options.
* gcc.target/powerpc/bmi-bextr-2.c: Fix-up dg-options.
* gcc.target/powerpc/bmi-bextr-4.c: Fix-up dg-options.
* gcc.target/powerpc/bmi-bextr-5.c: Fix-up dg-options.
* gcc.target/powerpc/bmi-blsi-1.c: Fix-up dg-options.
* gcc.target/powerpc/bmi-blsi-2.c: Fix-up dg-options.
* gcc.target/powerpc/bmi-blsmsk-1.c: Fix-up dg-options.
* gcc.target/powerpc/bmi-blsmsk-2.c: Fix-up dg-options.
* gcc.target/powerpc/bmi-blsr-1.c: Fix-up dg-options.
* gcc.target/powerpc/bmi-blsr-2.c: Fix-up dg-options.
* gcc.target/powerpc/bmi-tzcnt-1.c: Fix-up dg-options.
* gcc.target/powerpc/bmi-tzcnt-2.c: Fix-up dg-options.
* gcc.target/powerpc/bmi2-bzhi32-1.c: Fix-up dg-options.
* gcc.target/powerpc/bmi2-bzhi64-1.c: Fix-up dg-options.
* gcc.target/powerpc/bmi2-bzhi64-1a.c: Fix-up dg-options.
* gcc.target/powerpc/bmi2-mulx32-1.c: Fix-up dg-options.
* gcc.target/powerpc/bmi2-mulx32-2.c: Fix-up dg-options.
* gcc.target/powerpc/bmi2-mulx64-1.c: Fix-up dg-options.
* gcc.target/powerpc/bmi2-mulx64-2.c: Fix-up dg-options.
* gcc.target/powerpc/bmi2-pdep32-1.c: Fix-up dg-options.
* gcc.target/powerpc/bmi2-pdep64-1.c: Fix-up dg-options.
* gcc.target/powerpc/bmi2-pext32-1.c: Fix-up dg-options.
* gcc.target/powerpc/bmi2-pext64-1.c: Fix-up dg-options.
* gcc.target/powerpc/bmi2-pext64-1a.c: Fix-up dg-options.

Index: gcc/testsuite/gcc.target/powerpc/bmi-andn-1.c
===
--- gcc/testsuite/gcc.target/powerpc/bmi-andn-1.c   (revision 248166)
+++ gcc/testsuite/gcc.target/powerpc/bmi-andn-1.c   (working copy)
@@ -1,5 +1,5 @@
 /* { dg-do run } */
-/* { dg-options "-O3 -m64" } */
+/* { dg-options "-O3" } */
 /* { dg-require-effective-target lp64 } */
 
 #define NO_WARN_X86_INTRINSICS 1
Index: gcc/testsuite/gcc.target/powerpc/bmi-andn-2.c
===
--- gcc/testsuite/gcc.target/powerpc/bmi-andn-2.c   (revision 248166)
+++ gcc/testsuite/gcc.target/powerpc/bmi-andn-2.c   (working copy)
@@ -1,5 +1,5 @@
 /* { dg-do run } */
-/* { dg-options "-O3 -m64" } */
+/* { dg-options "-O3" } */
 /* { dg-require-effective-target lp64 } */
 
 #define NO_WARN_X86_INTRINSICS 1
Index: gcc/testsuite/gcc.target/powerpc/bmi-bextr-1.c
===
--- gcc/testsuite/gcc.target/powerpc/bmi-bextr-1.c  (revision 248166)
+++ gcc/testsuite/gcc.target/powerpc/bmi-bextr-1.c  (working copy)
@@ -1,6 +1,6 @@
 /* { dg-do run } */
+/* { dg-options "-O2 -fno-inline" } */
 /* { dg-require-effective-target lp64 } */
-/* { dg-options "-O2 -m64 -fno-inline" } */
 
 #define NO_WARN_X86_INTRINSICS 1
 #include 
Index: gcc/testsuite/gcc.target/powerpc/bmi-bextr-2.c
===
--- gcc/testsuite/gcc.target/powerpc/bmi-bextr-2.c  (revision 248166)
+++ gcc/testsuite/gcc.target/powerpc/bmi-bextr-2.c  (working copy)
@@ -1,6 +1,6 @@
 /* { dg-do run } */
+/* { dg-options "-O3 -fno-inline" } */
 /* { dg-require-effective-target lp64 } */
-/* { dg-options "-O3 -m64 -fno-inline" } */
 
 #define NO_WARN_X86_INTRINSICS 1
 #include 
Index: gcc/testsuite/gcc.target/powerpc/bmi-bextr-4.c
===
--- gcc/testsuite/gcc.target/powerpc/bmi-bextr-4.c  (revision 248166)
+++ gcc/testsuite/gcc.target/powerpc/bmi-bextr-4.c  (working copy)
@@ -1,6 +1,6 @@
 /* { dg-do run } */
+/* { dg-options "-O3 -fno-inline" } */
 /* { dg-require-effective-target lp64 } */
-/* { dg-options "-O3 -m64 -fno-inline" } */
 
 #define NO_WARN_X86_INTRINSICS 1
 #include 
Index: gcc/testsuite/gcc.target/powerpc/bmi-bextr-5.c
===
--- gcc/testsuite/gcc.target/powerpc/bmi-bextr-5.c  (revision 248166)
+++ gcc/testsuite/gcc.target/powerpc/bmi-bextr-5.c  (working copy)
@@ -1,6 +1,6 @@
 /* { dg-do run } */
+/* { dg-options "-O3 -fno-inline" } */
 /* { dg-require-effective-target lp64 } */
-/* { dg-options "-O3 -m64 -fno-inline" } */
 
 #define NO_WARN_X86_INTRINSICS 1
 #include 
Index: gcc/testsuite/gcc.target/powerpc/bmi-blsi-1.c
===
--- gcc/testsuite/gcc.target/powerpc/bmi-blsi-1.

Re: [RFC] propagate malloc attribute in ipa-pure-const pass

2017-05-17 Thread Martin Sebor

The patch passes bootstrap+test on x86_64 and found a few functions in
the source tree (attached func_names.txt) that could be annotated with
malloc (I gave a brief look at some of the functions and didn't appear
to be false positives but I will recheck thoroughly)


virtual char* libcp1::compiler::find(std::__cxx11::string&) const

The virtual on the list of your candidates gave me pause.  Consider
this completely contrived example:

  struct B {
virtual void* f (unsigned n) {
  return new char [n];
}
  };

  void* foo (B &b, unsigned n)
  {
return b.f (n);
  }

Based on these definitions alone both functions are candidates
for attribute malloc.

But suppose foo is called with an object of a type derived from
B that overrides f() to do something wacky (but strictly not
invalid) like:

  struct D: B {
char buf[32];
virtual void* f (unsigned n) {
  if (n < 32)
  return n <= 32 ? buf : B::f (n);
}

Breaking foo's attribute malloc constraint.

In other words, I think virtual functions need to be excluded
from the list (unless they're defined in a class marked final,
or unless we know they're not overridden to break the constraint
like above).

Martin


Re: [PATCH rs6000] Fix up dg-options for BMI intrinsic tests

2017-05-17 Thread David Edelsohn
On Wed, May 17, 2017 at 4:56 PM, Steven Munroe
 wrote:
> David pointed out that I my earlier X86 BMI intrinsic header submission
> was causing make check failures on on powerpc64le platforms. The patch
> below tests out on Linux BE powerpc64/32 and should also resolve the
> failures on AIX. I don't have access to a AIX so David can you give this
> patch a quick test.

This will fix the failures on AIX.

Thanks, David


Re: [PATCH, rs6000] gcc mainline, add builtin support for vec_doublee, vec_doubleo, vec_doublel builtins

2017-05-17 Thread Segher Boessenkool
Hi Carl,

Bunch of things, I'm afraid.

On Wed, May 17, 2017 at 08:25:38AM -0700, Carl E. Love wrote:
>* config/rs6000/rs6000-c: Add support for built-in functions
>* config/rs6000/rs6000-builtin.def: Add definitions for
>* config/rs6000/altivec.h: Add define for

Some parts are missing here.

> +(define_mode_iterator VM3 [V4SI V4SF])

This is VSX_W.  Is that not a useful name here?

> +(define_mode_attr VM3_char [(V4SI "i")(V4SF "f")])

(There should be a space between ")(").
This is only used as "s" -- that "s" should probably be part
of the attribute.  And that already exists: VEC_base.

> +(define_mode_attr VM3_x [(V4SI "xw")(V4SF "p")])

This probably needs a better name...  not that I know one, mind :-)

> + {
> +/* Little endian word numbering for operand is 3 2 1 0.
> +   take (operand[1] operand[1]) and shift left one word
> + 3 2 1 03 2 1 0  =>  2 1 0 3
> +   Input words 2 and 0 are now where they need to be for the
> +   conversion. */
> +rtx rtx_tmp;
> +rtx rtx_val = GEN_INT (4);
> +
> +rtx_tmp = gen_reg_rtx (op_mode);
> +emit_insn (gen_altivec_vsldoi_v4s (rtx_tmp,
> +  operands[1], operands[1], rtx_val));
> +emit_insn (gen_vsx_xvcvsdp (operands[0], rtx_tmp));
> + }

I think you want xxsldwi instead?  That way, you can use all VSRs (for
the "xw" variants; "p" still needs VRs only).

> +;; Generate unsdoublee
> +;;unsigned int to double convert words 0 and 2
> +(define_expand "unsdoubleev4si2"

Maybe you could use some iterator for the signed and unsigned version?
Many things seem to not do this, so maybe it is hard.

> +vector double vec_doublee (vector signed int);
> +vector double vec_doublee (vector unsigned int);
> +vector double vec_doublee (vector float);
> +
> +vector double vec_doubleh (vector signed int);
> +vector double vec_doubleh (vector unsigned int);
> +vector double vec_doubleh (vector float);
> +
> +vector double vec_doublel (vector signed int);
> +vector double vec_doublel (vector unsigned int);
> +vector double vec_doublel (vector float);
> +
> +vector double vec_doubleo (vector signed int);
> +vector double vec_doubleo (vector unsigned int);
> +vector double vec_doubleo (vector float);

It's more logical to group e/o and h/l together...  This list isn't
totally alphabetical in either case.  Fine like this as well, if you
don't agree.

> +++ b/gcc/testsuite/gcc.target/powerpc/builtins-3-runnable.c
> @@ -0,0 +1,84 @@
> +/* { dg-do run { target { powerpc64*-*-* } } } */
> +/* { dg-require-effective-target powerpc_vsx_ok } */
> +/* { dg-options "-maltivec -mvsx" } */

Similar testcases have

/* { dg-do run { target { powerpc*-*-linux } } }
/* { dg-require-effective-target vsx_hw } */
/* { dg-options "-O2 -mvsx" } */

powerpc64*-*-* does *not* mean it will only run for 64-bit targets:
it will only run if the compiler by default uses a 64-bit ABI.

I don't know if you need -linux.  If you don't use it you may well
have to exclude pretty much everything else.

I don't know if you need -maltivec.  I don't think you do though.

Runtime tests need vsx_hw; vsx_ok is enough for compile tests only.


Segher


[patch, fortran] Handle MATMUL(TRANSPOSE(A),B) in inline matmul

2017-05-17 Thread Thomas Koenig

Hello world,

after receiving no negative feedback on my RFC patch, I have deciced
to submit the patch.

The attached patch handles MATMUL(TRANSPOSE(A),B) in inlining matmul.
Speed is a bit faster than the library version.

Regression-tested.  OK for trunk?

Regards

Thomas

2017-05-17  Thomas Koenig  

PR fortran/66094
* frontend-passes.c (matrix_case):  Add A2TB2.
(inline_limit_check):  Handle MATMUL(TRANSPOSE(A),B)
(inline_matmul_assign):  Likewise.

2017-05-17  Thomas Koenig  

PR fortran/66094
* gfortran.dg/inline_matmul_16.f90:  New test.
! { dg-do run }
! { dg-options "-ffrontend-optimize -fdump-tree-optimized -Wrealloc-lhs -finline-matmul-limit=1000 -O" }
! PR 66094: Check functionality for MATMUL(TRANSPOSE(A),B)) for two-dimensional arrays
program main
  implicit none
  integer, parameter :: n = 3, m=4, cnt=2
  real, dimension(cnt,n) :: a
  real, dimension(cnt,m) :: b
  real, dimension(n,m) :: c, cres
  real, dimension(:,:), allocatable :: calloc
  integer :: in, im, icnt

  data a / 2., -3., 5., -7., 11., -13./
  data b /17., -23., 29., -31., 37., -39., 41., -47./
  data cres /103.,  246.,  486.,  151.,  362.,  722., &
 191.,  458.,  914.,  223.,  534., 1062./

  c = matmul(transpose(a),b)
  if (sum(c-cres)>1e-4) call abort
  if (sum(c-cres)>1e-4) call abort

  ! Unallocated
  calloc = matmul(transpose(a),b) ! { dg-warning "Code for reallocating the allocatable array" }
  if (any(shape(c) /= shape(calloc))) call abort
  if (sum(calloc-cres)>1e-4) call abort
  deallocate(calloc)

  ! Allocated to wrong shape
  allocate (calloc(10,10))
  calloc = matmul(transpose(a),b) ! { dg-warning "Code for reallocating the allocatable array" }
  if (any(shape(c) /= shape(calloc))) call abort
  if (sum(calloc-cres)>1e-4) call abort
  deallocate(calloc)

  ! cycle through a few test cases...
  do in=2,10 
 do im = 2,10
do icnt = 2,10
   block
 real, dimension(icnt,in) :: a2
 real, dimension(icnt,im) :: b2
 real, dimension(in,im) :: c2,cr
 integer :: i,j,k
 call random_number(a2)
 call random_number(b2)
 c2 = 0
 do i=1,size(a2,2)
do j=1, size(b2,2)
   do k=1, size(a2,1)
  c2(i,j) = c2(i,j) + a2(k,i) * b2(k,j)
   end do
end do
 end do
 cr = matmul(transpose(a2), b2)
 if (any(abs(c2-cr) > 1e-4)) call abort
   end block
end do
 end do
  end do
end program main
! { dg-final { scan-tree-dump-times "_gfortran_matmul" 0 "optimized" } }
Index: frontend-passes.c
===
--- frontend-passes.c	(Revision 247809)
+++ frontend-passes.c	(Arbeitskopie)
@@ -112,7 +112,7 @@ static int var_num = 1;
 
 /* What sort of matrix we are dealing with when inlining MATMUL.  */
 
-enum matrix_case { none=0, A2B2, A2B1, A1B2, A2B2T };
+enum matrix_case { none=0, A2B2, A2B1, A1B2, A2B2T, A2TB2 };
 
 /* Keep track of the number of expressions we have inserted so far
using create_var.  */
@@ -2252,7 +2252,7 @@ inline_limit_check (gfc_expr *a, gfc_expr *b, enum
   gfc_typespec ts;
   gfc_expr *cond;
 
-  gcc_assert (m_case == A2B2 || m_case == A2B2T);
+  gcc_assert (m_case == A2B2 || m_case == A2B2T || m_case == A2TB2);
 
   /* Calculation is done in real to avoid integer overflow.  */
 
@@ -2425,6 +2425,20 @@ matmul_lhs_realloc (gfc_expr *c, gfc_expr *a, gfc_
   cond = build_logical_expr (INTRINSIC_OR, ne1, ne2);
   break;
 
+case A2TB2:
+
+  ar->start[0] = get_array_inq_function (GFC_ISYM_SIZE, a, 2);
+  ar->start[1] = get_array_inq_function (GFC_ISYM_SIZE, b, 2);
+
+  ne1 = build_logical_expr (INTRINSIC_NE,
+get_array_inq_function (GFC_ISYM_SIZE, c, 1),
+get_array_inq_function (GFC_ISYM_SIZE, a, 2));
+  ne2 = build_logical_expr (INTRINSIC_NE,
+get_array_inq_function (GFC_ISYM_SIZE, c, 2),
+get_array_inq_function (GFC_ISYM_SIZE, b, 2));
+  cond = build_logical_expr (INTRINSIC_OR, ne1, ne2);
+  break;
+
 case A2B1:
   ar->start[0] = get_array_inq_function (GFC_ISYM_SIZE, a, 1);
   cond = build_logical_expr (INTRINSIC_NE,
@@ -3009,7 +3023,7 @@ inline_matmul_assign (gfc_code **c, int *walk_subt
 
   a = expr2->value.function.actual;
   matrix_a = check_conjg_transpose_variable (a->expr, &conjg_a, &transpose_a);
-  if (transpose_a || matrix_a == NULL)
+  if (matrix_a == NULL)
 return 0;
 
   b = a->next;
@@ -3026,27 +3040,36 @@ inline_matmul_assign (gfc_code **c, int *walk_subt
   || gfc_check_dependency (expr1, matrix_b, true))
 return 0;
 
+  m_case = none;
   if (matrix_a->rank == 2)
 {
-  if (matrix_b->rank == 1)
-	m_case = A2B1;
+  if (transpose_a)
+	{
+	  if (matrix_b->rank == 2 && !transpose_b)
+	m_case = A2TB2;
+	}
   else
 	{
-	  if (transpose_b)
-	m_case = A2

Re: [other/80803] libgo

2017-05-17 Thread Nathan Sidwell

On 05/17/2017 04:56 PM, Bill Schmidt wrote:

Hi Nathan,

Interestingly, this patch applies cleanly, but does *not* solve the problem 
with libgo.
Another puzzling development, since bisection showed all revisions before this
being clean and all revisions afterward being problematic.  Drat. :(


weird.  I did find what looks like a spurious pushdecl_top_level in c/c-decl.c. 
Will post patch to remove it tomorrow, if testing completes.


nathan

--
Nathan Sidwell


Re: [PATCH, rs6000] Fold Vector misc - fix testcases

2017-05-17 Thread Segher Boessenkool
Hi Will,

On Wed, May 17, 2017 at 01:44:45PM -0500, Will Schmidt wrote:
> --- a/gcc/testsuite/gcc.target/powerpc/fold-vec-div-floatdouble.c
> +++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-div-floatdouble.c
> @@ -1,9 +1,9 @@
>  /* Verify that overloaded built-ins for vec_div with float and
> -   double inputs for VSX produce the right results with -mvsx. */
> +   double inputs for VSX produce the right results. */
>  
>  /* { dg-do compile } */
>  /* { dg-require-effective-target powerpc_vsx_ok } */
> -/* { dg-options "-maltivec" } */
> +/* { dg-options "-mvsx" } */

It is more future-proof if you use -O2 (or -O1) here, if you do not
actually need -O0.

> --- a/gcc/testsuite/gcc.target/powerpc/fold-vec-div-longlong.c
> +++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-div-longlong.c
> @@ -2,8 +2,8 @@
> inputs produce the right results.  */
>  
>  /* { dg-do compile } */
> -/* { dg-require-effective-target powerpc_p8vector_ok } */
> -/* { dg-options "-maltivec -mpower8-vector -O3" } */
> +/* { dg-require-effective-target powerpc_vsx_ok } */
> +/* { dg-options "-mvsx -O2" } */

Does this one need p8 and VSX?  The only insns you test for are plain
GPR insns (divd and divdu) (but perhaps some other are generated as well?).
You do need 64-bit though, for those divd instructions:

/* { dg-require-effective-target lp64 } */

is easiest (unless you really really care for -m32 -mpowerpc64).

> --- a/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p8.c
> +++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p8.c
> @@ -4,7 +4,7 @@
>  /* { dg-do compile } */
>  /* { dg-require-effective-target powerpc_p8vector_ok } */
>  /* { dg-require-effective-target int128 } */
> -/* { dg-options "-maltivec -mvsx -mpower8-vector" } */
> +/* { dg-options "-mpower8-vector" } */
>  /* { dg-additional-options "-maix64" { target powerpc-ibm-aix* } } */

This also needs to test for 64-bit (since you want mulld etc. generated).
That -maix64 option then isn't needed I think (won't hurt though).

The rest looks good I think.  Please do one last (hopefully!) pass over
this, and commit.  Thanks,


Segher


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

2017-05-17 Thread Martin Sebor

While working on a new warning for unsafe conversion I noticed
that the existing warnings that diagnose these kinds of problems
are missing some useful detail. For example, given declarations
of an integer Type and an integer Constant defined in some header,
a C programmer who writes this declaration:

  Type x = Constant;

might see the following:

  warning: overflow in implicit constant conversion [-Woverflow]

To help the programmer better understand the problem and its impact
it would be helpful to mention the types of the operands, and if
available, also the values of the expressions.  For instance, like
so:

  warning: overflow in conversion from ‘int’ to ‘T {aka signed char}’ 
changes value from ‘123456789’ to ‘21’ [-Woverflow]


The attached simple patch does just that.  In making the changes
I tried to make the text of all the warnings follow the same
consistent wording pattern without losing any essential information
(e.g., I dropped "implicit" or "constant" because the implicit part
is evident from the code (no cast) and explicit conversions aren't
diagnosed, and because constant is apparent from the rest of the
diagnostic that includes its value.

Besides adding more detail and tweaking the wording the patch
makes no functional changes (i.e., doesn't add new or remove
existing warnings).

Martin

PS While adjusting the tests (a painstaking process) it occurred
to me that these kinds of changes would be a whole lot easier if
dg-warning directives simply checked for "-Woption-name" rather
than some (often arbitrary) part of the warning text.  It might
even be more accurate if the pattern happens to match the text
of two or more warnings controlled by different options.

It's of course important to also exercise the full text of
the warnings, especially where additional detail is included
(like in this patch), but that can be done in a small subset
of tests.  All the others that just verify the presence of
a warning controlled by a given option could use the simpler
approach.
PR c/80731 - poor -Woverflow warnings

gcc/c-family/ChangeLog:

	PR c/80731
	* c-common.h (unsafe_conversion_p): Add a function argument.
	* c-common.c (unsafe_conversion_p): Same.
	Add type names and values to diagnostics.
	(scalar_to_vector): Adjust.
	* c-warn.c (constant_expression_error): Add a function argument.
	Add type names and values to diagnostics.
	(conversion_warning): Add a function argument.
	Add type names and values to diagnostics.
	(warnings_for_convert_and_check): Same.

gcc/c/ChangeLog:

	PR c/80731
	* c-fold.c (c_fully_fold_internal): Adjust.
	* c-typeck.c (parser_build_unary_op): Adjust.

gcc/cp/ChangeLog:

	PR c/80731
	* call.c (fully_fold_internal): Adjust.

gcc/testsuite/ChangeLog:

	PR c/80731
	* c-c++-common/Wfloat-conversion.c: Adjust.
	* c-c++-common/dfp/convert-int-saturate.c: Same.
	* c-c++-common/pr68657-1.c: Same.
	* g++.dg/ext/utf-cvt.C: Same.
	* g++.dg/ext/utf16-4.C: Same.
	* g++.dg/warn/Wconversion-real-integer-3.C: Same.
	* g++.dg/warn/Wconversion-real-integer2.C: Same.
	* g++.dg/warn/Wconversion3.C: Same.
	* g++.dg/warn/Wconversion4.C: Same.
	* g++.dg/warn/Wsign-conversion.C: Same.
	* g++.dg/warn/overflow-warn-1.C: Same.
	* g++.dg/warn/overflow-warn-3.C: Same.
	* g++.dg/warn/overflow-warn-4.C: Same.
	* g++.dg/warn/pr35635.C: Same.
	* g++.old-deja/g++.mike/enum1.C: Same.
	* gcc.dg/Wconversion-3.c: Same.
	* gcc.dg/Wconversion-5.c: Same.
	* gcc.dg/Wconversion-complex-c99.c: Same.
	* gcc.dg/Wconversion-complex-gnu.c: Same.
	* gcc.dg/Wconversion-integer.c: Same.
	* gcc.dg/Wsign-conversion.c: Same.
	* gcc.dg/bitfld-2.c: Same.
	* gcc.dg/c90-const-expr-11.c: Same.
	* gcc.dg/c90-const-expr-7.c: Same.
	* gcc.dg/c99-const-expr-7.c: Same.
	* gcc.dg/overflow-warn-1.c: Same.
	* gcc.dg/overflow-warn-2.c: Same.
	* gcc.dg/overflow-warn-3.c: Same.
	* gcc.dg/overflow-warn-4.c: Same.
	* gcc.dg/overflow-warn-5.c: Same.
	* gcc.dg/overflow-warn-8.c: Same.
	* gcc.dg/overflow-warn-9.c: New test.
	* gcc.dg/pr35635.c: Adjust.
	* gcc.dg/pr59940.c: Same.
	* gcc.dg/pr59963-2.c: Same.
	* gcc.dg/pr60114.c: Same.
	* gcc.dg/switch-warn-2.c: Same.
	* gcc.dg/utf-cvt.c: Same.
	* gcc.dg/utf16-4.c: Same.

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index ad686d2..95841c9 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -1225,16 +1225,24 @@ int_safely_convertible_to_real_p (const_tree from_type, const_tree to_type)
can return SAFE_CONVERSION (zero) in that case.  Function can produce
signedness warnings if PRODUCE_WARNS is true.
 
+   RESULT, when non-null is the result of the conversion.  When constant
+   it is included in the text of diagnostics.
+
Function allows conversions from complex constants to non-complex types,
provided that imaginary part is zero and real part can be safely converted
to TYPE.  */
 
 enum conversion_safety
-unsafe_conversion_p (location_t loc, tree type, tree expr, bool produce_warns)
+unsafe_conversion_p (location_t loc, tree type, tree 

Move X==15-X to match.pd

2017-05-17 Thread Marc Glisse

Hello,

just moving one simple transformation to match.pd. It is actually slightly 
more general, because there is no point restricting to NOP conversions 
when only the lowest bit matters.


By the way, I was thinking of removing from fold-const.c the 
transformation "If we have (A & C) == D where D & ~C != 0, convert this 
into 0." because it is already handled by CCP. Would that be ok or does it 
still need an equivalent match.pd version?


Bootstrap+testsuite on powerpc64le-unknown-linux-gnu.

2017-05-18  Marc Glisse  

* fold-const.c (fold_binary_loc): Move transformation...
* match.pd (C - X CMP X): ... here.

--
Marc GlisseIndex: fold-const.c
===
--- fold-const.c	(revision 248173)
+++ fold-const.c	(working copy)
@@ -10525,44 +10525,20 @@ fold_binary_loc (location_t loc,
 	  && (INTEGRAL_TYPE_P (TREE_TYPE (arg1))
 	  || POINTER_TYPE_P (TREE_TYPE (arg1
 	{
 	  tree val = TREE_OPERAND (arg1, 1);
 	  val = fold_build2_loc (loc, code, type, val,
  build_int_cst (TREE_TYPE (val), 0));
 	  return omit_two_operands_loc (loc, type, val,
 	TREE_OPERAND (arg1, 0), arg0);
 	}
 
-  /* Transform comparisons of the form C - X CMP X if C % 2 == 1.  */
-  if (TREE_CODE (arg0) == MINUS_EXPR
-	  && TREE_CODE (TREE_OPERAND (arg0, 0)) == INTEGER_CST
-	  && operand_equal_p (tree_strip_nop_conversions (TREE_OPERAND (arg0,
-	1)),
-			  arg1, 0)
-	  && wi::extract_uhwi (TREE_OPERAND (arg0, 0), 0, 1) == 1)
-	return omit_two_operands_loc (loc, type,
-  code == NE_EXPR
-  ? boolean_true_node : boolean_false_node,
-  TREE_OPERAND (arg0, 1), arg1);
-
-  /* Transform comparisons of the form X CMP C - X if C % 2 == 1.  */
-  if (TREE_CODE (arg1) == MINUS_EXPR
-	  && TREE_CODE (TREE_OPERAND (arg1, 0)) == INTEGER_CST
-	  && operand_equal_p (tree_strip_nop_conversions (TREE_OPERAND (arg1,
-	1)),
-			  arg0, 0)
-	  && wi::extract_uhwi (TREE_OPERAND (arg1, 0), 0, 1) == 1)
-	return omit_two_operands_loc (loc, type,
-  code == NE_EXPR
-  ? boolean_true_node : boolean_false_node,
-  TREE_OPERAND (arg1, 1), arg0);
-
   /* If this is an EQ or NE comparison with zero and ARG0 is
 	 (1 << foo) & bar, convert it to (bar >> foo) & 1.  Both require
 	 two operations, but the latter can be done in one less insn
 	 on machines that have only two-operand insns or on which a
 	 constant cannot be the first operand.  */
   if (TREE_CODE (arg0) == BIT_AND_EXPR
 	  && integer_zerop (arg1))
 	{
 	  tree arg00 = TREE_OPERAND (arg0, 0);
 	  tree arg01 = TREE_OPERAND (arg0, 1);
Index: match.pd
===
--- match.pd	(revision 248173)
+++ match.pd	(working copy)
@@ -1083,20 +1083,27 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(op @1 @0
 /* For equality and subtraction, this is also true with wrapping overflow.  */
 (for op (eq ne minus)
  (simplify
   (op (minus @2 @0) (minus @2 @1))
   (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
&& (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))
 	   || TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0
(op @1 @0
 
+/* X == C - X can never be true if C is odd.  */
+(for cmp (eq ne)
+ (simplify
+  (cmp:c (convert? @0) (convert1? (minus INTEGER_CST@1 (convert2? @0
+  (if (TREE_INT_CST_LOW (@1) & 1)
+   { constant_boolean_node (cmp == NE_EXPR, type); })))
+
 /* ((X inner_op C0) outer_op C1)
With X being a tree where value_range has reasoned certain bits to always be
zero throughout its computed value range,
inner_op = {|,^}, outer_op = {|,^} and inner_op != outer_op
where zero_mask has 1's for all bits that are sure to be 0 in
and 0's otherwise.
if (inner_op == '^') C0 &= ~C1;
if ((C0 & ~zero_mask) == 0) then emit (X outer_op (C0 outer_op C1)
if ((C1 & ~zero_mask) == 0) then emit (X inner_op (C0 outer_op C1)
 */


Re: [PATCH] [i386] Recompute the frame layout less often

2017-05-17 Thread Daniel Santos

On 05/17/2017 12:41 PM, Bernd Edlinger wrote:

Apologies if I ruined your patch...


As I said before, I'm the new guy here. :) So when this is done I'll 
rebase my changes.  I have some test stuff to fix and some refactoring 
and refinements to xlogue_layout::compute_stub_managed_regs(). And then 
I'll find a solution to the stub_managed_regs after that.



Index: gcc/config/i386/i386.c
===
--- gcc/config/i386/i386.c(revision 248031)
+++ gcc/config/i386/i386.c(working copy)
@@ -2425,7 +2425,9 @@ static int const x86_64_int_return_registers[4] =

  /* Additional registers that are clobbered by SYSV calls.  */

-unsigned const x86_64_ms_sysv_extra_clobbered_registers[12] =
+#define NUM_X86_64_MS_CLOBBERED_REGS 12
+static int const x86_64_ms_sysv_extra_clobbered_registers
+ [NUM_X86_64_MS_CLOBBERED_REGS] =

Is there a reason you're changing this unsigned to signed int? While
AX_REG and such are just preprocessor macros, everywhere else it seems
that register numbers are dealt with as unsigned ints.


I actually there seems to be confusion about "int" vs. "unsigned int"
for regno, the advantage of int, is that it can contain -1 as a
exceptional value.  Furthermore there are 3 similar arrays just
above that also use int:

static int const x86_64_int_parameter_registers[6] =
{
DI_REG, SI_REG, DX_REG, CX_REG, R8_REG, R9_REG
};

static int const x86_64_ms_abi_int_parameter_registers[4] =
{
CX_REG, DX_REG, R8_REG, R9_REG
};

static int const x86_64_int_return_registers[4] =
{
AX_REG, DX_REG, DI_REG, SI_REG
};

/* Additional registers that are clobbered by SYSV calls.  */

#define NUM_X86_64_MS_CLOBBERED_REGS 12
static int const x86_64_ms_sysv_extra_clobbered_registers
   [NUM_X86_64_MS_CLOBBERED_REGS] =
{
SI_REG, DI_REG,
XMM6_REG, XMM7_REG,
XMM8_REG, XMM9_REG, XMM10_REG, XMM11_REG,
XMM12_REG, XMM13_REG, XMM14_REG, XMM15_REG
};

So IMHO it looked odd to have one array use a different type in the
first place.


OK.  I think that when I originally started this I was using elements of 
this array in comparisons and got the signed/unsigned warning and 
changed them.  None of the code gives that warning now however.



@@ -2484,13 +2486,13 @@ class xlogue_layout {
   needs to store registers based upon data in the
machine_function.  */
HOST_WIDE_INT get_stack_space_used () const
{
-const struct machine_function &m = *cfun->machine;
-unsigned last_reg = m.call_ms2sysv_extra_regs + MIN_REGS - 1;
+const struct machine_function *m = cfun->machine;
+unsigned last_reg = m->call_ms2sysv_extra_regs + MIN_REGS - 1;

What is the reason for this change?


Because a mixture of C and C++ (C wants "struct" machine_function)
looks ugly, and everywhere else in this module, "m" is a pointer and no
reference.


I see, consistency with the rest of the file.


-gcc_assert (m.call_ms2sysv_extra_regs <= MAX_EXTRA_REGS);
+gcc_assert (m->call_ms2sysv_extra_regs <= MAX_EXTRA_REGS);
  return m_regs[last_reg].offset
-+ (m.call_ms2sysv_pad_out ? 8 : 0)
-+ STUB_INDEX_OFFSET;
+   + (m->call_ms2sysv_pad_out ? 8 : 0)
+   + STUB_INDEX_OFFSET;
}

/* Returns the offset for the base pointer used by the stub. */
@@ -2532,7 +2534,7 @@ class xlogue_layout {
/* Lazy-inited cache of symbol names for stubs.  */
char
m_stub_names[XLOGUE_STUB_COUNT][VARIANT_COUNT][STUB_NAME_MAX_LEN];

-  static const struct xlogue_layout GTY(())
s_instances[XLOGUE_SET_COUNT];
+  static const struct GTY(()) xlogue_layout
s_instances[XLOGUE_SET_COUNT];

Hmm, during development I originally had C-style xlogue_layout as a
struct and later decided to make it a class and apparently forgot to
remove the "struct" here.  None the less, it's bazaar that the GTY()
would go in between the "struct" and the "xlogue_layout."  As I said
before, I don't fully understand how this GTY works.  Can we just remove
the "struct" keyword?

Also, if the way I had it was wrong, (and resulted in garbage collection
not working right) then perhaps it was the cause of a problem I had with
caching symbol rtx objects.  I could not get this to work because my
cached objects would somehow become stale and I've since removed that
code (from xlogue_layout::get_stub_rtx).  (i.e., does GTY effect
lifespan of globals, TU statics and static C++ data members?)


Yes, I have not noticed the "struct", and agree to remove it.

I just saw every other place where GTY is used it is directly after
"struct" or "static", so my impulse was just to follow that examples.


Yeah, and not understanding how it worked I was just trying to follow suit.


But neither version actually makes the class GC-able.  Apparently
this class construct is too complicated for the gengtype machinery.
So I am inclined to remove the GTY keyword completely as it gives
you only false security in GC's ability to garbage collect anything
in this class.


Th