Re: [Patch] Small refactor on _State<>

2015-07-25 Thread Tim Shen
On Sat, Jul 25, 2015 at 12:11 AM, Tim Shen  wrote:
> It's not a very necessary refactoring, but simply can't resist. :)
>
> I'm not sure of the ::memcpy calls. It looks not very idiomatic, but
> std::copy on char* looks even more weird? :/
>
> Bootstrapped and tested.
>
> Thanks!
>
>
> --
> Regards,
> Tim Shen



-- 
Regards,
Tim Shen


Re: [PATCH, i386]: Fix PR 64003, valgrind complains about get_attr_length_nobnd in insn-attrtab.c from i386.md

2015-07-25 Thread Uros Bizjak
On Sat, Jul 25, 2015 at 1:17 AM, Tom de Vries  wrote:
> On 24/07/15 18:29, Uros Bizjak wrote:
>>
>> This patch introduces ADJUST_INSN_LENGTH define to i386.h to increase
>> the length of the insn when bnd prefix is used.

[...]

> Is it possible this causes a build breaker on x86_64 with
> --enable-checking=rtl?
>
> In file included from src/libgcc/unwind-dw2.c:35:0:
> src/libgcc/unwind-pe.h: In function ‘read_encoded_value_with_base’:
> src/libgcc/unwind-pe.h:271:1: internal compiler error: RTL check: expected
> elt 5 type 'i' or 'n', have '0' (rtx jump_table_data) in recog_memoized, at
> recog.h:167

Yes, it looks so. I really should use --enable-checking=rtl more.

I'm testing following patch:

Index: config/i386/i386.h
===
--- config/i386/i386.h  (revision 226207)
+++ config/i386/i386.h  (working copy)
@@ -2264,7 +2264,7 @@
/* Adjust the length of the insn with the length of BND prefix.  */
#define ADJUST_INSN_LENGTH(INSN, LENGTH)   \
do {   \
-  if (recog_memoized (INSN) >= 0   \
+  if (INSN_P (INSN) && INSN_CODE (INSN) >= 0   \
  && get_attr_maybe_prefix_bnd (INSN)) \
LENGTH += ix86_bnd_prefixed_insn_p (INSN); \
} while (0)

Uros.


Re: [PATCH] [graphite] dump reasons why graphite failed to detect a scop

2015-07-25 Thread Tobias Grosser

On 07/25/2015 12:36 AM, Sebastian Pop wrote:

When trying to analyze why Graphite does not handle a loop nest, it is easy to
look in the dumps of -fdump-tree-graphite-all to guess what has to be changed to
catch the loop.  This patch makes the dumps a bit more verbose and useful.
---
  gcc/graphite-scop-detection.c | 72 +++
  1 file changed, 66 insertions(+), 6 deletions(-)


LGTM.

Tobias


diff --git a/gcc/graphite-scop-detection.c b/gcc/graphite-scop-detection.c
index 686f495..fb7247e 100644
--- a/gcc/graphite-scop-detection.c
+++ b/gcc/graphite-scop-detection.c
@@ -51,6 +51,7 @@ along with GCC; see the file COPYING3.  If not see
  #include "graphite-poly.h"
  #include "tree-ssa-propagate.h"
  #include "graphite-scop-detection.h"
+#include "gimple-pretty-print.h"

  /* Forward declarations.  */
  static void make_close_phi_nodes_unique (basic_block);
@@ -350,13 +351,31 @@ stmt_simple_for_scop_p (basic_block scop_entry, loop_p 
outermost_loop,
|| (gimple_code (stmt) == GIMPLE_CALL
  && !(gimple_call_flags (stmt) & (ECF_CONST | ECF_PURE)))
|| (gimple_code (stmt) == GIMPLE_ASM))
-return false;
+{
+  if (dump_file && (dump_flags & TDF_DETAILS))
+   {
+ fprintf (dump_file, "[scop-detection-fail] ");
+ fprintf (dump_file, "Graphite cannot handle this stmt:\n");
+ print_gimple_stmt (dump_file, stmt, 0, TDF_VOPS|TDF_MEMSYMS);
+   }
+
+  return false;
+}

if (is_gimple_debug (stmt))
  return true;

if (!stmt_has_simple_data_refs_p (outermost_loop, stmt))
-return false;
+{
+  if (dump_file && (dump_flags & TDF_DETAILS))
+   {
+ fprintf (dump_file, "[scop-detection-fail] ");
+ fprintf (dump_file, "Graphite cannot handle data-refs in stmt:\n");
+ print_gimple_stmt (dump_file, stmt, 0, TDF_VOPS|TDF_MEMSYMS);
+   }
+
+  return false;
+}

switch (gimple_code (stmt))
  {
@@ -375,7 +394,16 @@ stmt_simple_for_scop_p (basic_block scop_entry, loop_p 
outermost_loop,
  || code == GE_EXPR
  || code == EQ_EXPR
  || code == NE_EXPR))
-  return false;
+  {
+   if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+   fprintf (dump_file, "[scop-detection-fail] ");
+   fprintf (dump_file, "Graphite cannot handle cond stmt:\n");
+   print_gimple_stmt (dump_file, stmt, 0, TDF_VOPS|TDF_MEMSYMS);
+ }
+
+   return false;
+ }

for (unsigned i = 0; i < 2; ++i)
  {
@@ -383,7 +411,16 @@ stmt_simple_for_scop_p (basic_block scop_entry, loop_p 
outermost_loop,
if (!graphite_can_represent_expr (scop_entry, loop, op)
/* We can not handle REAL_TYPE. Failed for pr39260.  */
|| TREE_CODE (TREE_TYPE (op)) == REAL_TYPE)
- return false;
+ {
+   if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+   fprintf (dump_file, "[scop-detection-fail] ");
+   fprintf (dump_file, "Graphite cannot represent stmt:\n");
+   print_gimple_stmt (dump_file, stmt, 0, 
TDF_VOPS|TDF_MEMSYMS);
+ }
+
+   return false;
+ }
  }

return true;
@@ -395,6 +432,12 @@ stmt_simple_for_scop_p (basic_block scop_entry, loop_p 
outermost_loop,

  default:
/* These nodes cut a new scope.  */
+  if (dump_file && (dump_flags & TDF_DETAILS))
+   {
+ fprintf (dump_file, "[scop-detection-fail] ");
+ fprintf (dump_file, "Gimple stmt not handled in Graphite:\n");
+ print_gimple_stmt (dump_file, stmt, 0, TDF_VOPS|TDF_MEMSYMS);
+   }
return false;
  }

@@ -488,7 +531,16 @@ scopdet_basic_block_info (basic_block bb, loop_p 
outermost_loop,
 with make_forwarder_block.  */
if (!single_succ_p (bb)
  || bb_has_abnormal_pred (single_succ (bb)))
-   result.difficult = true;
+   {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+   {
+ fprintf (dump_file, "[scop-detection-fail] ");
+ fprintf (dump_file, "BB %d cannot be part of a scop.\n",
+  bb->index);
+   }
+
+ result.difficult = true;
+   }
else
result.exit = single_succ (bb);

@@ -509,7 +561,15 @@ scopdet_basic_block_info (basic_block bb, loop_p 
outermost_loop,
sinfo = build_scops_1 (bb, outermost_loop, ®ions, loop);

if (!graphite_can_represent_loop (entry_block, loop))
- result.difficult = true;
+ {
+   if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+   fprintf (dump_file, "[scop-detection-fail] ");
+   fprintf (dump_file, "Graphite cannot represent loop %d.\n",
+loop->num);
+ }
+   result.difficult = true;
+ }

Re: [PATCH] Don't allow unsafe reductions in graphite

2015-07-25 Thread Tom de Vries

On 24/07/15 22:20, Sebastian Pop wrote:

Richard Biener wrote:

On Wed, Jul 22, 2015 at 6:00 PM, Tom de Vries  wrote:

Currently bootstrapping and reg-testing on x86_64.

OK for trunk?

OK 5 and 4.9 release branches?


Ok if Sebastian is fine with it.


Ok to backport as well.
Thanks Tom for the patches.


And thanks for the review.

This follow-up patch:
- makes sure that the uns-*.c variants are handled the same as the
  original ones in graphite.exp.
- actually makes the uns-*.c variants use unsigned arithmetic.

Committed to trunk.

Thanks,
- Tom



Fixup graphite/uns-*.c testcases

2015-07-25  Tom de Vries  

	* gcc.dg/graphite/graphite.exp: Include uns-*.c files in
	interchange_files and block_files variables.
	* gcc.dg/graphite/uns-block-1.c (main): Change signed into unsigned
	arithmetic.
	* gcc.dg/graphite/uns-interchange-12.c: Same.
	* gcc.dg/graphite/uns-interchange-14.c: Same.
	* gcc.dg/graphite/uns-interchange-15.c: Same.
	* gcc.dg/graphite/uns-interchange-9.c (foo): Same.
	* gcc.dg/graphite/uns-interchange-mvt.c: Same.
---
 gcc/testsuite/gcc.dg/graphite/graphite.exp  |  6 --
 gcc/testsuite/gcc.dg/graphite/uns-block-1.c |  6 +++---
 gcc/testsuite/gcc.dg/graphite/uns-interchange-12.c  |  7 ---
 gcc/testsuite/gcc.dg/graphite/uns-interchange-14.c  |  5 +++--
 gcc/testsuite/gcc.dg/graphite/uns-interchange-15.c  |  7 ---
 gcc/testsuite/gcc.dg/graphite/uns-interchange-9.c   | 11 ++-
 gcc/testsuite/gcc.dg/graphite/uns-interchange-mvt.c |  7 ---
 7 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/graphite/graphite.exp b/gcc/testsuite/gcc.dg/graphite/graphite.exp
index 9dba5d6..9e7ede6 100644
--- a/gcc/testsuite/gcc.dg/graphite/graphite.exp
+++ b/gcc/testsuite/gcc.dg/graphite/graphite.exp
@@ -41,8 +41,10 @@ set wait_to_run_files [lsort [glob -nocomplain $srcdir/$subdir/*.c ] ]
 set scop_files[lsort [glob -nocomplain $srcdir/$subdir/scop-*.c ] ]
 set id_files  [lsort [glob -nocomplain $srcdir/$subdir/id-*.c ] ]
 set run_id_files  [lsort [glob -nocomplain $srcdir/$subdir/run-id-*.c ] ]
-set interchange_files [lsort [glob -nocomplain $srcdir/$subdir/interchange-*.c ] ]
-set block_files   [lsort [glob -nocomplain $srcdir/$subdir/block-*.c ] ]
+set interchange_files [lsort [glob -nocomplain $srcdir/$subdir/interchange-*.c \
+			  $srcdir/$subdir/uns-interchange-*.c ] ]
+set block_files   [lsort [glob -nocomplain $srcdir/$subdir/block-*.c \
+			  $srcdir/$subdir/uns-block-*.c ] ]
 set vect_files[lsort [glob -nocomplain $srcdir/$subdir/vect-*.c ] ]
 
 # Tests to be compiled.
diff --git a/gcc/testsuite/gcc.dg/graphite/uns-block-1.c b/gcc/testsuite/gcc.dg/graphite/uns-block-1.c
index 57d522b..c50b770 100644
--- a/gcc/testsuite/gcc.dg/graphite/uns-block-1.c
+++ b/gcc/testsuite/gcc.dg/graphite/uns-block-1.c
@@ -13,9 +13,9 @@ int
 main (void)
 {
   int i, j;
-  int sum = 0;
-  int A[MAX * MAX];
-  int B[MAX * MAX];
+  unsigned int sum = 0;
+  unsigned int A[MAX * MAX];
+  unsigned int B[MAX * MAX];
 
   /* These loops should be loop blocked.  */
   for (i = 0; i < MAX; i++)
diff --git a/gcc/testsuite/gcc.dg/graphite/uns-interchange-12.c b/gcc/testsuite/gcc.dg/graphite/uns-interchange-12.c
index dc26926..bd21ba9 100644
--- a/gcc/testsuite/gcc.dg/graphite/uns-interchange-12.c
+++ b/gcc/testsuite/gcc.dg/graphite/uns-interchange-12.c
@@ -7,9 +7,9 @@
 
 #define N 200
 
-int A[N][N], B[N][N], C[N][N];
+unsigned int A[N][N], B[N][N], C[N][N];
 
-static int __attribute__((noinline))
+static unsigned int __attribute__((noinline))
 matmult (void)
 {
   int i, j, k;
@@ -31,7 +31,8 @@ extern void abort ();
 int
 main (void)
 {
-  int i, j, res;
+  int i, j;
+  unsigned int res;
 
   for (i = 0; i < N; i++)
 for (j = 0; j < N; j++)
diff --git a/gcc/testsuite/gcc.dg/graphite/uns-interchange-14.c b/gcc/testsuite/gcc.dg/graphite/uns-interchange-14.c
index 36990ab..b1abd13 100644
--- a/gcc/testsuite/gcc.dg/graphite/uns-interchange-14.c
+++ b/gcc/testsuite/gcc.dg/graphite/uns-interchange-14.c
@@ -7,7 +7,7 @@
 
 #define N 200
 
-int A[N][N], B[N][N], C[N][N];
+unsigned int A[N][N], B[N][N], C[N][N];
 
 static void __attribute__((noinline))
 matmult (void)
@@ -30,7 +30,8 @@ extern void abort ();
 int
 main (void)
 {
-  int i, j, res = 0;
+  int i, j;
+  unsigned res = 0;
 
   for (i = 0; i < N; i++)
 for (j = 0; j < N; j++)
diff --git a/gcc/testsuite/gcc.dg/graphite/uns-interchange-15.c b/gcc/testsuite/gcc.dg/graphite/uns-interchange-15.c
index 3ddb74f..a5a2e27 100644
--- a/gcc/testsuite/gcc.dg/graphite/uns-interchange-15.c
+++ b/gcc/testsuite/gcc.dg/graphite/uns-interchange-15.c
@@ -7,9 +7,9 @@
 
 #define NMAX 2000
 
-static int x[NMAX], a[NMAX][NMAX];
+static unsigned int x[NMAX], a[NMAX][NMAX];
 
-static int __attribute__((noinline))
+static unsigned int __attribute__((noinline))
 mvt (long N)
 {
   int i,j;
@@ -27,7 +27,8 @@ extern void abort ();
 int
 main (void)
 {
-  int i, j, res;
+  int i, j;
+  uns

[PATCH, i386]: Fix PR 66648, incorrect memcpy expansion with unrolled_loop strategy at -O2

2015-07-25 Thread Uros Bizjak
We have to emit check for main loop execution UNLESS we guarantee that
min_size is at least equal to size_needed. In this testcase, VRP
declared minimum copying size, and after unaligned prologue
adjustment, min_size was still non-zero. The !min_size check didn't
account for the case that min_size can be non-zero, but still less
than size_needed.

2015-07-25  Uros Bizjak  

PR target/66648
* config/i386/i386.c (ix86_expand_set_or_movmem): Emit main loop
execution guard when min_size is less than size_needed.

testsuite/ChangeLog:

2015-07-25  Uros Bizjak  

PR target/66648
* gcc.target/i386/pr66648.c: New test.

Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.

Committed to mainline, will be backported to release branches.

Uros.
Index: config/i386/i386.c
===
--- config/i386/i386.c  (revision 224993)
+++ config/i386/i386.c  (working copy)
@@ -25008,7 +25008,8 @@ ix86_expand_set_or_movmem (rtx dst, rtx src, rtx c
   dst = change_address (dst, BLKmode, destreg);
   set_mem_align (dst, desired_align * BITS_PER_UNIT);
   epilogue_size_needed = 0;
-  if (need_zero_guard && !min_size)
+  if (need_zero_guard
+ && min_size < (unsigned HOST_WIDE_INT) size_needed)
{
  /* It is possible that we copied enough so the main loop will not
 execute.  */
@@ -25140,7 +25141,7 @@ ix86_expand_set_or_movmem (rtx dst, rtx src, rtx c
  max_size -= align_bytes;
}
   if (need_zero_guard
- && !min_size
+ && min_size < (unsigned HOST_WIDE_INT) size_needed
  && (count < (unsigned HOST_WIDE_INT) size_needed
  || (align_bytes == 0
  && count < ((unsigned HOST_WIDE_INT) size_needed
Index: testsuite/gcc.target/pr66648.c
===
--- testsuite/gcc.target/pr66648.c  (revision 0)
+++ testsuite/gcc.target/pr66648.c  (working copy)
@@ -0,0 +1,33 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -mstringop-strategy=unrolled_loop -mtune=nocona" } */
+
+#define PATTERN 0xdeadbeef
+#define SIZE32
+
+struct S { int i; char str[SIZE]; int j; };
+
+void __attribute__((noclone, noinline))
+my_memcpy (char *, const char *, unsigned int);
+
+void
+my_memcpy (char *dst, const char *src, unsigned int len)
+{
+  if (len < 8)
+__builtin_abort ();
+
+  __builtin_memcpy (dst, src, len);
+}
+
+int
+main (void)
+{
+  const char str[SIZE]= "1234567890123456789012345678901";
+  struct S *s = __builtin_malloc (sizeof (struct S));
+
+  s->j = PATTERN;
+  my_memcpy (s->str, str, SIZE);
+  if (s->j != PATTERN)
+__builtin_abort ();
+
+  return 0;
+}


[PATCH, i386]: Fix PR 67004, valgrind error in recog_memoized & shorten_branches

2015-07-25 Thread Uros Bizjak
This patch fixes/improves check for valid insn in newly introduced
ADJUST_INSN_LENGTH.

(Please note that other targets (e.g. aarch64) needs similar fix. MIPS
could use NONDEBUG_INSN_P instead of INSN_P there.)

2015-07-25  Uros Bizjak  

PR target/67004
* config/i386/i386.h (ADJUST_INSN_LENGTH): Use NONDEBUG_INSN_P (INSN)
predicate and INSN_CODE (INSN) >= 0 to check for valid instruction.

Bootstrapped and regression tested on x86_64-linux-gnu {,-m32} with
--enable-checking=rtl. Also, I have started bootstrap with
--enable-checking=valgrind, but it will probably finish sometime in
the next ice age.

Committed to mainline SVN.

Uros.
Index: config/i386/i386.h
===
--- config/i386/i386.h  (revision 226207)
+++ config/i386/i386.h  (working copy)
@@ -2262,11 +2262,12 @@
 #define DEFAULT_LARGE_SECTION_THRESHOLD 65536
 
 /* Adjust the length of the insn with the length of BND prefix.  */
-#define ADJUST_INSN_LENGTH(INSN, LENGTH)   \
-do {   \
-  if (recog_memoized (INSN) >= 0   \
-  && get_attr_maybe_prefix_bnd (INSN)) \
-LENGTH += ix86_bnd_prefixed_insn_p (INSN); \
+
+#define ADJUST_INSN_LENGTH(INSN, LENGTH)   \
+do {   \
+  if (NONDEBUG_INSN_P (INSN) && INSN_CODE (INSN) >= 0  \
+  && get_attr_maybe_prefix_bnd (INSN)) \
+LENGTH += ix86_bnd_prefixed_insn_p (INSN); \
 } while (0)
 
 /* Which processor to tune code generation for.  These must be in sync


[PATCH, i386]: Use SUBREG_P predicate

2015-07-25 Thread Uros Bizjak
2015-07-25  Uros Bizjak  

* config/i386/i386.c: Use SUBREG_P predicate.
* config/i386/i386.md: Ditto.
* config/i386/sse.md: Ditto.
* config/i386/predicates.md: Ditto.

Bootstrapped on x86_64-linux-gnu, committed to mainline SVN.

Uros.
Index: config/i386/i386.c
===
--- config/i386/i386.c  (revision 226212)
+++ config/i386/i386.c  (working copy)
@@ -6180,7 +6180,7 @@ ix86_legitimate_combined_insn (rtx_insn *insn)
  if (UNARY_P (op))
op = XEXP (op, 0);
 
- if (GET_CODE (op) == SUBREG)
+ if (SUBREG_P (op))
{
  if (REG_P (SUBREG_REG (op))
  && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
@@ -9477,7 +9477,7 @@ ix86_check_movabs (rtx insn, int opnum)
 set = XVECEXP (set, 0, 0);
   gcc_assert (GET_CODE (set) == SET);
   mem = XEXP (set, opnum);
-  while (GET_CODE (mem) == SUBREG)
+  while (SUBREG_P (mem))
 mem = SUBREG_REG (mem);
   gcc_assert (MEM_P (mem));
   return volatile_ok || !MEM_VOLATILE_P (mem);
@@ -12895,7 +12895,7 @@ ix86_decompose_address (rtx addr, struct ix86_addr
  they will be emitted with addr32 prefix.  */
   if (TARGET_64BIT && GET_MODE (addr) == SImode)
 {
-  if (GET_CODE (addr) == SUBREG
+  if (SUBREG_P (addr)
  && GET_MODE (SUBREG_REG (addr)) == DImode)
{
  addr = SUBREG_REG (addr);
@@ -12906,7 +12906,7 @@ ix86_decompose_address (rtx addr, struct ix86_addr
 
   if (REG_P (addr))
 base = addr;
-  else if (GET_CODE (addr) == SUBREG)
+  else if (SUBREG_P (addr))
 {
   if (REG_P (SUBREG_REG (addr)))
base = addr;
@@ -13024,7 +13024,7 @@ ix86_decompose_address (rtx addr, struct ix86_addr
 {
   if (REG_P (index))
;
-  else if (GET_CODE (index) == SUBREG
+  else if (SUBREG_P (index)
   && REG_P (SUBREG_REG (index)))
;
   else
@@ -13039,8 +13039,8 @@ ix86_decompose_address (rtx addr, struct ix86_addr
   scale = INTVAL (scale_rtx);
 }
 
-  base_reg = base && GET_CODE (base) == SUBREG ? SUBREG_REG (base) : base;
-  index_reg = index && GET_CODE (index) == SUBREG ? SUBREG_REG (index) : index;
+  base_reg = base && SUBREG_P (base) ? SUBREG_REG (base) : base;
+  index_reg = index && SUBREG_P (index) ? SUBREG_REG (index) : index;
 
   /* Avoid useless 0 displacement.  */
   if (disp == const0_rtx && (base || index))
@@ -13108,9 +13108,9 @@ ix86_address_cost (rtx x, machine_mode, addr_space
 
   gcc_assert (ok);
 
-  if (parts.base && GET_CODE (parts.base) == SUBREG)
+  if (parts.base && SUBREG_P (parts.base))
 parts.base = SUBREG_REG (parts.base);
-  if (parts.index && GET_CODE (parts.index) == SUBREG)
+  if (parts.index && SUBREG_P (parts.index))
 parts.index = SUBREG_REG (parts.index);
 
   /* Attempt to minimize number of registers in the address by increasing
@@ -13515,7 +13515,7 @@ ix86_validate_address_register (rtx op)
 
   if (REG_P (op))
 return op;
-  else if (GET_CODE (op) == SUBREG)
+  else if (SUBREG_P (op))
 {
   rtx reg = SUBREG_REG (op);
 
@@ -16727,7 +16727,7 @@ output_387_binary_op (rtx insn, rtx *operands)
 static bool
 ix86_check_avx256_register (const_rtx exp)
 {
-  if (GET_CODE (exp) == SUBREG)
+  if (SUBREG_P (exp))
 exp = SUBREG_REG (exp);
 
   return (REG_P (exp)
@@ -17555,7 +17555,7 @@ ix86_expand_vector_move (machine_mode mode, rtx op
   if (can_create_pseudo_p ()
   && register_operand (op0, mode)
   && (CONSTANT_P (op1)
- || (GET_CODE (op1) == SUBREG
+ || (SUBREG_P (op1)
  && CONSTANT_P (SUBREG_REG (op1
   && !standard_sse_constant_p (op1))
 op1 = validize_mem (force_const_mem (mode, op1));
@@ -17571,7 +17571,7 @@ ix86_expand_vector_move (machine_mode mode, rtx op
 
   /* ix86_expand_vector_move_misalign() does not like constants ... */
   if (CONSTANT_P (op1)
- || (GET_CODE (op1) == SUBREG
+ || (SUBREG_P (op1)
  && CONSTANT_P (SUBREG_REG (op1
op1 = validize_mem (force_const_mem (mode, op1));
 
@@ -18129,12 +18129,12 @@ ix86_expand_vector_logical_operator (enum rtx_code
 rtx operands[])
 {
   rtx op1 = NULL_RTX, op2 = NULL_RTX;
-  if (GET_CODE (operands[1]) == SUBREG)
+  if (SUBREG_P (operands[1]))
 {
   op1 = operands[1];
   op2 = operands[2];
 }
-  else if (GET_CODE (operands[2]) == SUBREG)
+  else if (SUBREG_P (operands[2]))
 {
   op1 = operands[2];
   op2 = operands[1];
@@ -18146,7 +18146,7 @@ ix86_expand_vector_logical_operator (enum rtx_code
  to cast them temporarily to integer vectors.  */
   if (op1
   && !TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL
-  && ((GET_CODE (op2) == SUBREG || GET_CODE (op2) == CONST_VECTOR))
+  && (SUBREG_P (op2) || GET_CODE (op2) == CONST_VECTOR)
   && GET_MODE_CLASS (GET_MODE (SUBREG_REG (op1))) == MODE_VECTOR_FLOAT
   && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op1)

[SH][committed] Fix PR 66930

2015-07-25 Thread Oleg Endo
Hi,

This fixes an SH bug that has been discovered during the discussions of PR 
66930.
Tested by Kaz on sh4-linux.
Committed to trunk as r226218 and to GCC 5 branch as r226219.

Cheers,
Oleg

gcc/ChangeLog
PR target/66930
* config/sh/sh.c (sh_split_movrt_negc_to_movt_xor): Add missing
T bit register modified_between_p check.



sh_pr66930.patch
Description: Binary data


Re: [PATCH] warn for unsafe calls to __builtin_return_address

2015-07-25 Thread Segher Boessenkool
On Thu, Jul 23, 2015 at 11:08:21PM -0600, Jeff Law wrote:
> >There's the following comment in expand_builtin_frame_address:
> >
> >   /* Some ports cannot access arbitrary stack frames.  */
> >
> >just before a block of code where the function can lead to
> >an "invalid argument" warning which would cause the newly
> >added tests to fail (since the newly added warning wouldn't
> >be issued).
> >
> >I tried to determine what ports these might be so I could add
> >conditionals to the tests to prevent false positives there but
> >couldn't find any.

A quick grep shows aarch64.  Also many other ports, for
__builtin_return_address.  For __builtin_frame_address there is no
non-hacky way for ports to say "I cannot access other frames"; see
mmix_dynamic_chain_address for more complaints about this.

> You have to start thinking creatively.  For example, consider ports 
> without dwarf2 unwinders :-)  Consider ports where the linker inserts 
> stubs between caller & callee for various reasons  Consider cases where 
> the next outermost frame is compiled by something other than GCC, or 
> perhaps was written in pure assembly.  Or consider the case when we're 
> currently in a signal handling frame...

Or simply the case where the caller does not have a frame pointer, and
the ABI does not provide another way to get at (the size of) stack frames.

> So, my suggestion would be to warn for any call with a nonzero value.

The current documentation says that you should only use nonzero values
for debug purposes.  A warning would help yes, how many people read the
manual after all :-)


Segher


Re: [PATCH 1/4] convert ASM_OUTPUT_ASCII to a hook

2015-07-25 Thread Segher Boessenkool
On Fri, Jul 24, 2015 at 10:36:57PM -0400, tbsaunde+...@tbsaunde.org wrote:
> -@defmac ASM_OUTPUT_ASCII (@var{stream}, @var{ptr}, @var{len})
> -A C statement to output to the stdio stream @var{stream} an assembler
> -instruction to assemble a string constant containing the @var{len}
> -bytes at @var{ptr}.  @var{ptr} will be a C expression of type
> -@code{char *} and @var{len} a C expression of type @code{int}.
> +@deftypefn {Target Hook} void TARGET_ASM_OUTPUT_ASCII (FILE *@var{f}, const 
> char *@var{str}, size_t @var{length})
> +A target hook to output an assembly instruction to assemble a string
> + constant containing the @var{length} bytes at @var{str}.

   ^ stray space

> -If the assembler has a @code{.ascii} pseudo-op as found in the
> -Berkeley Unix assembler, do not define the macro
> -@code{ASM_OUTPUT_ASCII}.
> -@end defmac
> +The defalt hook uses the @code{.ascii} pseudo op as found in the Berkely 
> Unix assembler.

Typoes ("defalt", "Berkely").

> +DEFHOOK
> +(output_ascii,
> + "A target hook to output an assembly instruction to assemble a string\n\
> + constant containing the @var{length} bytes at @var{str}.\n\
> +\n\
> +The defalt hook uses the @code{.ascii} pseudo op as found in the Berkely 
> Unix assembler.",
> + void, (FILE *f, const char *str, size_t length),
> + default_output_ascii)

Both here as well, of course.

> -   FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
> -   characters - instead it treats them as sub-string separators.  Since
> -   we want to emit NUL strings terminators into the object file we have to 
> use
> -   ASM_OUTPUT_SKIP.  */
> +   FIXME: target.asm_out.output_ascii, as defined in config/elfos.h will not

targetm?


Segher


Re: [PATCH 4/4] define ASM_OUTPUT_LABEL to the name of a function

2015-07-25 Thread Segher Boessenkool
On Fri, Jul 24, 2015 at 10:37:00PM -0400, tbsaunde+...@tbsaunde.org wrote:
> --- a/gcc/config/pa/pa.c
> +++ b/gcc/config/pa/pa.c
> @@ -9761,6 +9761,18 @@ pa_reloc_rw_mask (void)
>return 3;
>  }
>  
> +/* Assemble a lable.  */

Typo.

> +void
> +pa_output_label (FILE *f, const char *label)
> +{
> +  assemble_name (f, label);
> +  if (TARGET_GAS)
> +fputs (":\n", f);
> +  else
> +fputc ('\n', (f));

You forgot to remove the extra parens here :-)

If so many targets use default_assemble_label, can you make it an actual
default instead of defining it everywhere?


Segher


Re: PR c/16351 Extend Wnonnull for returns_nonnull

2015-07-25 Thread Bernhard Reutner-Fischer
On July 25, 2015 1:15:21 AM GMT+02:00, Trevor Saunders  
wrote:

>
>Another case is
>
>Foo *
>bar()
>{
>  #if SHOULD_USE_BAR
>  ...
>#else
>  return NULL;
>#endif
>}
>
>And somehow your program is setup so bar is only called when
>SHOULD_USE_BAR is defined.  In that sort of case it may be convenient
>for the function bar to always be defined, but not for the type Foo to
>be defined in which case there is no real value for the function to
>return.

Which just proves that cxx is just too broken^wcomplicated to grok for any 
human being or compiler, for that matter |)

Cheers,



Re: [Patch, fortran] PR66929 fix iso_varying_string ICE

2015-07-25 Thread Mikael Morin

Le 21/07/2015 23:10, Paul Richard Thomas a écrit :

Hi Mikael,

This looks fine to me - OK for trunk.

Thanks for the patch

Paul

On 21 July 2015 at 14:53, Mikael Morin  wrote:

Hello,

The fix for PR61831 committed recently [1] introduced/uncovered a NULLL
pointer dereference with iso_varying_string, because a generic symbol (which
has a NULL result) is used as procedure symbol, instead of the specific one.
Fixed by using esym if it's available.

Regression-tested on x86_64-linux. OK for trunk?

Mikael

[1]: https://gcc.gnu.org/ml/gcc-patches/2015-06/msg01389.html




Hello,

I would like to backport the patch.
As the bug was discovered with the patch [1] above, the test 
generic_30.f90 works on the branches, which don't have that patch.
Meanwhile, I have managed to find a test generic_31.f90 that exhibits a 
wrong code already on the branch, which justifies the backport.


Regression tested on the 5 branch, OK for 5 and 4.9?

Mikael


2015-07-25  Mikael Morin  

PR fortran/66929
* trans-array.c (gfc_get_proc_ifc_for_expr): Use esym as procedure
symbol if available.

2015-07-25  Mikael Morin  

PR fortran/66929
* gfortran.dg/generic_30.f90: New.
* gfortran.dg/generic_31.f90: New.
Index: trans-array.c
===
--- trans-array.c	(révision 225979)
+++ trans-array.c	(copie de travail)
@@ -9166,7 +9166,11 @@ gfc_get_proc_ifc_for_expr (gfc_expr *procedure_ref
 return NULL;
 
   /* Normal procedure case.  */
-  sym = procedure_ref->symtree->n.sym;
+  if (procedure_ref->expr_type == EXPR_FUNCTION
+  && procedure_ref->value.function.esym)
+sym = procedure_ref->value.function.esym;
+  else
+sym = procedure_ref->symtree->n.sym;
 
   /* Typebound procedure case.  */
   for (ref = procedure_ref->ref; ref; ref = ref->next)

! { dg-do compile }
!
! PR fortran/66929
! Generic procedures as actual argument used to lead to
! a NULL pointer dereference in gfc_get_proc_ifc_for_expr
! because the generic symbol was used as procedure symbol,
! instead of the specific one.

module iso_varying_string
  type, public :: varying_string
 character(LEN=1), dimension(:), allocatable :: chars
  end type varying_string
  interface operator(/=)
 module procedure op_ne_VS_CH
  end interface operator (/=)
  interface trim
 module procedure trim_
  end interface
contains
  elemental function op_ne_VS_CH (string_a, string_b) result (op_ne)
type(varying_string), intent(in) :: string_a
character(LEN=*), intent(in) :: string_b
logical  :: op_ne
op_ne = .true.
  end function op_ne_VS_CH
  elemental function trim_ (string) result (trim_string)
type(varying_string), intent(in) :: string
type(varying_string) :: trim_string
trim_string = varying_string(["t", "r", "i", "m", "m", "e", "d"])
  end function trim_
end module iso_varying_string
module syntax_rules
  use iso_varying_string, string_t => varying_string
contains
  subroutine set_rule_type_and_key
type(string_t) :: key
if (trim (key) /= "") then
  print *, "non-empty"
end if
  end subroutine set_rule_type_and_key
end module syntax_rules

! { dg-do run }
!
! PR fortran/66929
! Check that the specific FIRST symbol is used for the call to FOO,
! so that the J argument is not assumed to be present

module m
  interface foo
module procedure first
  end interface foo
contains
  elemental function bar(j) result(r)
integer, intent(in), optional :: j
integer :: r, s(2)
! We used to have NULL dereference here, in case of a missing J argument
s = foo(j, [3, 7])
r = sum(s)
  end function bar
  elemental function first(i, j) result(r)
integer, intent(in), optional :: i
integer, intent(in) :: j
integer :: r
if (present(i)) then
  r = i
else
  r = -5
end if
  end function first
end module m
program p
  use m
  integer :: i
  i = bar()
  if (i /= -10) call abort
end program p



Re: [PATCH 4/4] define ASM_OUTPUT_LABEL to the name of a function

2015-07-25 Thread Trevor Saunders
On Sat, Jul 25, 2015 at 10:59:19AM -0500, Segher Boessenkool wrote:
> On Fri, Jul 24, 2015 at 10:37:00PM -0400, tbsaunde+...@tbsaunde.org wrote:
> > --- a/gcc/config/pa/pa.c
> > +++ b/gcc/config/pa/pa.c
> > @@ -9761,6 +9761,18 @@ pa_reloc_rw_mask (void)
> >return 3;
> >  }
> >  
> > +/* Assemble a lable.  */
> 
> Typo.
> 
> > +void
> > +pa_output_label (FILE *f, const char *label)
> > +{
> > +  assemble_name (f, label);
> > +  if (TARGET_GAS)
> > +fputs (":\n", f);
> > +  else
> > +fputc ('\n', (f));
> 
> You forgot to remove the extra parens here :-)
> 
> If so many targets use default_assemble_label, can you make it an actual
> default instead of defining it everywhere?

 Well, it is the default, but many targets do over ride it to set it to
 the default ;)  Its certainly possible to remove some of those cases,
 but that seems like the sort of thing one might want to test more than
 just making sure gcc/ builds, and I'm not really set up to do that.  Is
 there a problem with leaving this for target maintainers to do?  It
 seems like an improvement over what we have, and I don't think they are
 getting in anyones way.

 Trev

> 
> 
> Segher


[v3 PATCH] PR libstdc++/60970, implement LWG 2148

2015-07-25 Thread Ville Voutilainen
Tested on Linux-PPC64.

The proposed resolution of the issue doesn't really say whether our
regression test for PR libstdc++/52931 should remain valid. However,
it doesn't say that we shouldn't keep it valid, either. This approach
keeps it valid, but provides support for hashing enums. It took a while
to figure out suitable jiggery-pokery to make it so, but this approach
passes the testsuite without regressions. I considered an alternative
alias-template-based approach, but while that attempt would've worked
with our current front-end, it would not have worked on clang (and
it's thus far unclear whether it was intended to work by the language
rules).

2015-07-25  Ville Voutilainen  
PR libstdc++/60970, implement LWG 2148, hash support for
enum types.
* include/bits/functional_hash.h
(__hash_enum): New.
(hash): Derive from __hash_enum.
* testsuite/20_util/hash/60970.cc: New.
diff --git a/libstdc++-v3/include/bits/functional_hash.h 
b/libstdc++-v3/include/bits/functional_hash.h
index d94843f..f81864f 100644
--- a/libstdc++-v3/include/bits/functional_hash.h
+++ b/libstdc++-v3/include/bits/functional_hash.h
@@ -57,6 +57,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 struct hash;
 
+  // Helper struct for SFINAE-poisoning non-enum types.
+  template
+struct __hash_enum
+{
+private:
+  __hash_enum(__hash_enum&&);
+  ~__hash_enum();
+};
+
+  // Helper struct for hash with enum types.
+  template
+struct __hash_enum<_Tp, true> : public __hash_base
+{
+  size_t
+  operator()(_Tp __val) const noexcept
+  {
+   using __type = typename underlying_type<_Tp>::type;
+   return hash<__type>{}(static_cast<__type>(__val));
+  }
+};
+
+  /// Primary class template hash, usable for enum types only.
+  // Use with non-enum types still SFINAES.
+  template
+struct hash : __hash_enum<_Tp, is_enum<_Tp>::value>
+{ };
+
   /// Partial specializations for pointer types.
   template
 struct hash<_Tp*> : public __hash_base
diff --git a/libstdc++-v3/testsuite/20_util/hash/60970.cc 
b/libstdc++-v3/testsuite/20_util/hash/60970.cc
new file mode 100644
index 000..ddc626f
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/hash/60970.cc
@@ -0,0 +1,36 @@
+// { dg-options "-std=gnu++11" }
+// { dg-do run }
+
+// Copyright (C) 2015 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING3.  If not see
+// .
+
+
+#include 
+#include 
+
+using namespace std;
+
+enum E1 : int {FIRST=1, SECOND=2};
+enum class E2 : int {THIRD=42, FOURTH=666};
+
+int main()
+{
+  VERIFY(hash{}(1) == hash{}(FIRST));
+  VERIFY(hash{}(2) == hash{}(SECOND));
+  VERIFY(hash{}(42) == hash{}(E2::THIRD));
+  VERIFY(hash{}(666) == hash{}(E2::FOURTH));
+}


Re: [PATCH 4/4] define ASM_OUTPUT_LABEL to the name of a function

2015-07-25 Thread Segher Boessenkool
On Sat, Jul 25, 2015 at 02:40:56PM -0400, Trevor Saunders wrote:
> > If so many targets use default_assemble_label, can you make it an actual
> > default instead of defining it everywhere?
> 
>  Well, it is the default, but many targets do over ride it to set it to
>  the default ;)

Right, noticed that too late :-)

>  Its certainly possible to remove some of those cases,
>  but that seems like the sort of thing one might want to test more than
>  just making sure gcc/ builds, and I'm not really set up to do that.  Is
>  there a problem with leaving this for target maintainers to do?  It
>  seems like an improvement over what we have, and I don't think they are
>  getting in anyones way.

If you're not confident removing it yourself, then don't.  It isn't
getting in anyone's way, simply because there is so *much* clutter...


Segher


Re: [PATCH 1/4] convert ASM_OUTPUT_ASCII to a hook

2015-07-25 Thread Trevor Saunders
On Fri, Jul 24, 2015 at 08:09:26PM -0700, pins...@gmail.com wrote:
> 
> 
> 
> 
> > On Jul 24, 2015, at 7:36 PM, tbsaunde+...@tbsaunde.org wrote:
> > +++ b/gcc/config/arm/arm.c
> > @@ -18963,14 +18963,13 @@ int_log2 (HOST_WIDE_INT power)
> > #define MAX_ASCII_LEN 51
> > 
> > void
> > -output_ascii_pseudo_op (FILE *stream, const unsigned char *p, int len)
> > +output_ascii_pseudo_op (FILE *stream, const char *p, size_t len)
> 
> You changed the signedness of p here for some targets. Can you confirm that 
> this code does not depend on if char is signed or unsigned?  Almost all the 
> rest of the target macro conversions look correct and kept the casting. Just 
> this one seems missing. 

hrm I think that might be a real issue.  that function just assigns p[i]
to an int and then passes that to ISPRINT and putc or printf.  I'm not
totally sure sign extending and then passingto ISPriNt is ok, so its
probably best to change it to int c = (unsigned char) p[i];  I'll make
that change if nobody objects and it seems like the right thing to do.

Trev

> 
> Thanks,
> Andrew
> 
> > {
> > -  int i;
> >   int len_so_far = 0;
> > 
> >   fputs ("\t.ascii\t\"", stream);
> > 
> > -  for (i = 0; i < len; i++)
> > +  for (size_t i = 0; i < len; i++)
> > {
> >   int c = p[i];
> > 
> > @@ -19586,7 +19585,7 @@ arm_poke_function_name (FILE *stream, const char 
> > *name)
> >   length  = strlen (name) + 1;
> >   alignlength = ROUND_UP_WORD (length);
> > 
> > -  ASM_OUTPUT_ASCII (stream, name, length);
> > +  targetm.asm_out.output_ascii (stream, name, length);
> >   ASM_OUTPUT_ALIGN (stream, 2);
> >   x = GEN_INT ((unsigned HOST_WIDE_INT) 0xff00 + alignlength);
> >   assemble_aligned_integer (UNITS_PER_WORD, x);
> > diff --git a/gcc/config/elfos.h b/gcc/config/elfos.h
> > index bcc3870..d2cbbfb 100644
> > --- a/gcc/config/elfos.h
> > +++ b/gcc/config/elfos.h
> > @@ -385,7 +385,7 @@ see the files COPYING3 and COPYING.RUNTIME 
> > respectively.  If not, see
> >   while (0)
> > #endif
> > 
> > -/* A table of bytes codes used by the ASM_OUTPUT_ASCII and
> > +/* A table of bytes codes used by the TARGET_ASM_OUTPUT_ASCII and
> >ASM_OUTPUT_LIMITED_STRING macros.  Each byte in the table
> >corresponds to a particular byte value [0..255].  For any
> >given byte value, if the value in the corresponding table
> > @@ -442,9 +442,8 @@ see the files COPYING3 and COPYING.RUNTIME 
> > respectively.  If not, see
> >character sequence which end with NUL (and which are shorter than
> >STRING_LIMIT) we output those using ASM_OUTPUT_LIMITED_STRING.  */
> > 
> > -#undef  ASM_OUTPUT_ASCII
> > -#define ASM_OUTPUT_ASCII(FILE, STR, LENGTH)\
> > -  default_elf_asm_output_ascii ((FILE), (STR), (LENGTH));
> > +#undef  TARGET_ASM_OUTPUT_ASCII
> > +#define TARGET_ASM_OUTPUT_ASCII default_elf_asm_output_ascii
> > 
> > /* Allow the use of the -frecord-gcc-switches switch via the
> >elf_record_gcc_switches function defined in varasm.c.  */
> > diff --git a/gcc/config/i386/att.h b/gcc/config/i386/att.h
> > index f58bef9..45210b7 100644
> > --- a/gcc/config/i386/att.h
> > +++ b/gcc/config/i386/att.h
> > @@ -37,17 +37,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively. 
> >  If not, see
> > 
> > /* How to output an ASCII string constant.  */
> > 
> > -#undef ASM_OUTPUT_ASCII
> > -#define ASM_OUTPUT_ASCII(FILE, PTR, SIZE)\
> > -do\
> > -{ size_t i = 0, limit = (SIZE);\
> > -  while (i < limit)\
> > -{ if (i%10 == 0) { if (i!=0) putc ('\n', (FILE));\
> > -   fputs (ASM_BYTE, (FILE)); }\
> > -  else putc (',', (FILE));\
> > -  fprintf ((FILE), "0x%x", ((PTR)[i++] & 0377)) ;}\
> > -  putc ('\n', (FILE));\
> > -} while (0)
> > +#undef TARGET_ASM_OUTPUT_ASCII
> > +#define TARGET_ASM_OUTPUT_ASCII ix86_att_output_ascii
> > 
> > /* Output at beginning of assembler file.  */
> > #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
> > diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h
> > index 6a17ef4..0b5e64f 100644
> > --- a/gcc/config/i386/i386-protos.h
> > +++ b/gcc/config/i386/i386-protos.h
> > @@ -152,6 +152,8 @@ extern machine_mode ix86_fp_compare_mode (enum 
> > rtx_code);
> > 
> > extern rtx ix86_libcall_value (machine_mode);
> > extern bool ix86_function_arg_regno_p (int);
> > +extern void ix86_elf_output_ascii (FILE *, const char *, size_t);
> > +extern void ix86_att_output_ascii (FILE *, const char *, size_t);
> > extern void ix86_asm_output_function_label (FILE *, const char *, tree);
> > extern void ix86_call_abi_override (const_tree);
> > extern int ix86_reg_parm_stack_space (const_tree);
> > diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
> > index d6b4508..1e07243 100644
> > --- a/gcc/config/i386/i386.c
> > +++ b/gcc/config/i386/i386.c
> > @@ -96,10 +96,18 @@ static rtx legitimize_dllimport_sy

Re: [Revert][AArch64] PR 63521 Define REG_ALLOC_ORDER/HONOR_REG_ALLOC_ORDER

2015-07-25 Thread Andrew Pinski
On Fri, Jul 24, 2015 at 2:07 AM, Jiong Wang  wrote:
>
> James Greenhalgh writes:
>
>> On Wed, May 20, 2015 at 01:35:41PM +0100, Jiong Wang wrote:
>>> Current IRA still use both target macros in a few places.
>>>
>>> Tell IRA to use the order we defined rather than with it's own cost
>>> calculation. Allocate caller saved first, then callee saved.
>>>
>>> This is especially useful for LR/x30, as it's free to allocate and is
>>> pure caller saved when used in leaf function.
>>>
>>> Haven't noticed significant impact on benchmarks, but by grepping some
>>> keywords like "Spilling", "Push.*spill" etc in ira rtl dump, the number
>>> is smaller.
>>>
>>> OK for trunk?
>>
>> OK, sorry for the delay.
>>
>> It might be mail client mangling, but please check that the trailing slashes
>> line up in the version that gets committed.
>>
>> Thanks,
>> James
>>
>>> 2015-05-19  Jiong. Wang  
>>>
>>> gcc/
>>>   PR 63521
>>>   * config/aarch64/aarch64.h (REG_ALLOC_ORDER): Define.
>>>   (HONOR_REG_ALLOC_ORDER): Define.
>
> Patch reverted.

I did not see a reason why this patch was reverted.  Maybe I am
missing an email or something.

Thanks,
Andrew


>


[PATCH] DWARF: materialize subprogram renamings in Ada as imported declarations

2015-07-25 Thread Pierre-Marie de Rodat

Hello,

This change makes GCC materialize subprogram renamings in Ada as 
imported declarations (DW_TAG_imported_declarations). For instance,


procedure Foo renames Bar;

will output:

DW_TAG_imported_declaration:
DW_AT_name: foo
DW_AT_import: 

This new debugging information will let users reference the renamings 
instead of the renamed subprograms.  This is in accordance with the 
DWARF specification: the section 3.2.3 (Imported (or Renamed) 
Declaration Entities) allows DW_TAG_imported_declaration DIEs to be used 
"as a general means to rename or provide an alias for an entity 
regardless of the context in which the importing declaration or the 
imported entity occur." (wording from the DWARFv3 and DWARFv4 
specifications, allowed in DWARFv2).


gcc/ada/ChangeLog:

* gcc-interface/decl.c (gnat_to_gnu_entity): Create
IMPORTED_DECL nodes to describe the subprogram renamings which
are relevant at debug time.
* gcc-interface/gigi.h (get_debug_scope): Add declaration.
* gcc-interface/trans.c (Identifier_to_gnu): Consider
N_Defining_Operator_Symbol as valid entities.
(gnat_to_gnu): Handle N_Defining_Operator_Symbol the same way as
other entities.  Introduce a specific handling for
N_Subprogram_Renaming_Declaration: call gnat_to_gnu_entity on
the entity defined for relevant ones.
(process_decls): Process subprogram renaming declarations during
the second pass only.
* gcc-interface/utils.c (get_debug_scope): Make it external.
Consider N_Defining_Operator_Symbol as valid entities.
(gnat_write_global_declarations): Output debugging information
for top-level imported declarations.
* namet.ads (Name_Equals): New function.
* namet.adb (Name_Equals): New function.
* namet.h (Name_Equals): New macro.  Declare Name_Equals from
the Namet Ada unit.

gcc/ChangeLog:

* dwarf2out.c (gen_decl_die): Generate DW_TAG_imported_* instead
of DW_TAG_namespace for IMPORTED_DECL declarations.  Call
dwarf2out_imported_module_or_decl_1 for all DWARF versions as
this function already takes care of checking what it can emit.

Bootstrapped, regtested and checked with GDB's testsuite on x86_64-linux 
(GDB cannot use this yet but I'm about to submit a patch for it). Ok for 
trunk?


Thank you in advance for your feedback!

--
Pierre-Marie de Rodat
>From 8eed7558683e817755314d00adaf9b4820742d22 Mon Sep 17 00:00:00 2001
From: Pierre-Marie de Rodat 
Date: Wed, 22 Jul 2015 19:41:08 +0200
Subject: [PATCH] DWARF: materialize subprogram renamings in Ada as imported
 declarations

... so that debugger users can reference them instead of the renamed
subprograms.  This is in accordance with the DWARF specification: the
section 3.2.3 (Imported (or Renamed) Declaration Entities) allows
DW_TAG_imported_declaration DIEs to be used "as a general means to
rename or provide an alias for an entity regardless of the context in
which the importing declaration or the imported entity occur." (wording
from the DWARFv3 and DWARFv4 specifications, allowed in DWARFv2).

gcc/ada/ChangeLog:

	* gcc-interface/decl.c (gnat_to_gnu_entity): Create
	IMPORTED_DECL nodes to describe the subprogram renamings which
	are relevant at debug time.
	* gcc-interface/gigi.h (get_debug_scope): Add declaration.
	* gcc-interface/trans.c (Identifier_to_gnu): Consider
	N_Defining_Operator_Symbol as valid entities.
	(gnat_to_gnu): Handle N_Defining_Operator_Symbol the same way as
	other entities.  Introduce a specific handling for
	N_Subprogram_Renaming_Declaration: call gnat_to_gnu_entity on
	the entity defined for relevant ones.
	(process_decls): Process subprogram renaming declarations during
	the second pass only.
	* gcc-interface/utils.c (get_debug_scope): Make it external.
	Consider N_Defining_Operator_Symbol as valid entities.
	(gnat_write_global_declarations): Output debugging information
	for top-level imported declarations.
	* namet.ads (Name_Equals): New function.
	* namet.adb (Name_Equals): New function.
	* namet.h (Name_Equals): New macro.  Declare Name_Equals from
	the Namet Ada unit.

gcc/ChangeLog:

	* dwarf2out.c (gen_decl_die): Generate DW_TAG_imported_* instead
	of DW_TAG_namespace for IMPORTED_DECL declarations.  Call
	dwarf2out_imported_module_or_decl_1 for all DWARF versions as
	this function already takes care of checking what it can emit.

Bootstrapped, regtested and checked with GDB's testsuite on
x86_64-linux.
---
 gcc/ada/gcc-interface/decl.c  | 29 +
 gcc/ada/gcc-interface/gigi.h  |  5 +
 gcc/ada/gcc-interface/trans.c | 41 +++--
 gcc/ada/gcc-interface/utils.c | 18 +-
 gcc/ada/namet.adb | 30 ++
 gcc/ada/namet.ads |  3 +++
 gcc/ada/namet.h   |  3 +++
 gcc/dwarf2out.c   |  6 +-
 8 files chan

[gomp4] Fix some gomp tests

2015-07-25 Thread Nathan Sidwell
I've committed this to gomp4 branch.  It fixes some tests that were incorrect 
and fail with some development I am working on.


nathan
2015-07-25  Nathan Sidwell  

	* testsuite/libgomp.oacc-c-c++-common/reduction-2.c: Copy lresult,
	not result for logical reductions.
	* testsuite/libgomp.oacc-c-c++-common/reduction-3.c: Likewise.
	* testsuite/libgomp.oacc-fortran/data-2.f90: Add present clauses
	to parallels.
	* testsuite/libgomp.oacc-fortran/lib-14.f90: Likewise.

Index: libgomp/testsuite/libgomp.oacc-c-c++-common/reduction-2.c
===
--- libgomp/testsuite/libgomp.oacc-c-c++-common/reduction-2.c	(revision 226189)
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/reduction-2.c	(working copy)
@@ -90,7 +90,7 @@ main(void)
   lvresult = 0;
 
   /* '&&' reductions.  */
-#pragma acc parallel num_gangs (ng) copy (result)
+#pragma acc parallel num_gangs (ng) copy (lresult)
 #pragma acc loop reduction (&&:lresult) gang
   for (i = 0; i < n; i++)
 lresult = lresult && (result > array[i]);
@@ -109,7 +109,7 @@ main(void)
   lvresult = 0;
 
   /* '||' reductions.  */
-#pragma acc parallel num_gangs (ng) copy (result)
+#pragma acc parallel num_gangs (ng) copy (lresult)
 #pragma acc loop reduction (||:lresult) gang
   for (i = 0; i < n; i++)
 lresult = lresult || (result > array[i]);
Index: libgomp/testsuite/libgomp.oacc-c-c++-common/reduction-3.c
===
--- libgomp/testsuite/libgomp.oacc-c-c++-common/reduction-3.c	(revision 226189)
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/reduction-3.c	(working copy)
@@ -90,7 +90,7 @@ main(void)
   lvresult = 0;
 
   /* '&&' reductions.  */
-#pragma acc parallel num_gangs (ng) copy (result)
+#pragma acc parallel num_gangs (ng) copy (lresult)
 #pragma acc loop reduction (&&:lresult) gang
   for (i = 0; i < n; i++)
 lresult = lresult && (result > array[i]);
@@ -109,7 +109,7 @@ main(void)
   lvresult = 0;
 
   /* '||' reductions.  */
-#pragma acc parallel num_gangs (ng) copy (result)
+#pragma acc parallel num_gangs (ng) copy (lresult)
 #pragma acc loop reduction (||:lresult) gang
   for (i = 0; i < n; i++)
 lresult = lresult || (result > array[i]);
Index: libgomp/testsuite/libgomp.oacc-fortran/data-2.f90
===
--- libgomp/testsuite/libgomp.oacc-fortran/data-2.f90	(revision 226189)
+++ libgomp/testsuite/libgomp.oacc-fortran/data-2.f90	(working copy)
@@ -19,7 +19,7 @@ program test
 
   !$acc enter data copyin (a(1:N,1:N), b(1:N,1:N))
 
-  !$acc parallel
+  !$acc parallel present (a(1:N,1:N), b(1:N,1:N))
   do i = 1, n
 do j = 1, n
   b(j,i) = a (j,i)
@@ -45,7 +45,7 @@ program test
   !$acc enter data copyin (c(1:N)) create (d(1:N)) async
   !$acc wait
   
-  !$acc parallel 
+  !$acc parallel present (c(1:N), d(1:N))
 do i = 1, N
   d(i) = c(i) + 1
 end do
@@ -65,7 +65,7 @@ program test
   !$acc enter data create (d(1:N)) wait
   !$acc wait
 
-  !$acc parallel 
+  !$acc parallel present (c(1:N), d(1:N))
 do i = 1, N
   d(i) = c(i) + 1
 end do
@@ -128,7 +128,7 @@ program test
   if (acc_is_present (c) .eqv. .FALSE.) call abort
   if (acc_is_present (d) .eqv. .FALSE.) call abort
 
-  !$acc parallel
+  !$acc parallel present (c(0:N), d(0:N))
 do i = 1, N
   c(i) = 1.0;
   d(i) = 2.0;
Index: libgomp/testsuite/libgomp.oacc-fortran/lib-14.f90
===
--- libgomp/testsuite/libgomp.oacc-fortran/lib-14.f90	(revision 226189)
+++ libgomp/testsuite/libgomp.oacc-fortran/lib-14.f90	(working copy)
@@ -46,7 +46,7 @@ program main
 
   if (acc_is_present (h) .neqv. .TRUE.) call abort
 
-  !$acc parallel loop
+  !$acc parallel loop present (h)
 do i = 1, N
   h(i) = i
 end do


[PATCH] [5/6 Regression] Fix PR c++/66857

2015-07-25 Thread Patrick Palka
gcc/cp/ChangeLog:

PR c++/66857
* cvt.c (ocp_convert): Don't call scalar_constant_value when
converting to a class type.

gcc/testsuite/ChangeLog:

PR c++/66857
* g++.dg/init/pr66857.C: New test.
---
 gcc/cp/cvt.c|  3 ++-
 gcc/testsuite/g++.dg/init/pr66857.C | 19 +++
 2 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/init/pr66857.C

diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 13bc1f7..6d4bd9a 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -687,7 +687,8 @@ ocp_convert (tree type, tree expr, int convtype, int flags,
 }
 
   /* FIXME remove when moving to c_fully_fold model.  */
-  e = scalar_constant_value (e);
+  if (!CLASS_TYPE_P (type))
+e = scalar_constant_value (e);
   if (error_operand_p (e))
 return error_mark_node;
 
diff --git a/gcc/testsuite/g++.dg/init/pr66857.C 
b/gcc/testsuite/g++.dg/init/pr66857.C
new file mode 100644
index 000..43b0927
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/pr66857.C
@@ -0,0 +1,19 @@
+// PR c++/66857
+// { dg-do run }
+
+const int i = 0;
+
+struct Test
+{
+  Test (const int &rhs)
+  {
+if (&rhs != &i)
+  __builtin_abort ();
+  }
+};
+
+int
+main (void)
+{
+  Test test = i;
+}
-- 
2.5.0.rc2.22.g69b1679.dirty



Re: [PATCH] [5/6 Regression] Fix PR c++/66857

2015-07-25 Thread Patrick Palka
On Sat, Jul 25, 2015 at 7:12 PM, Patrick Palka  wrote:
> gcc/cp/ChangeLog:
>
> PR c++/66857
> * cvt.c (ocp_convert): Don't call scalar_constant_value when
> converting to a class type.
>
> gcc/testsuite/ChangeLog:
>
> PR c++/66857
> * g++.dg/init/pr66857.C: New test.

This fix was approved here https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66857#c5

Committed to mainline.  Is it OK for the GCC 5 branch?


[PATCH] Fix PR c++/18969 (invalid return statement diagnosed too late)

2015-07-25 Thread Patrick Palka
This patch makes check_return_expr less paranoid about checking the
return value of a return-statement when processing a template
declaration.

At the same time this patch removes some vestigial code (the middle two
hunks) that were related to the long-removed "named return value" gcc
extension.

In the PR, Manuel expressed concern about this change repeating the same
error multiple times, once at declaration time and then at instantiation
time.  But IMHO the benefit of emitting an early error at declaration
time far outweighs the inconvenience of that error possibly being
printed more than once.  Also it is already the case that the same such
error can be printed more than once if we instantiate a template more
than once (using different template arguments each time).

This patch helped to catch a potential error in libstdc++:

https://gcc.gnu.org/ml/libstdc++/2015-07/msg00053.html

OK to commit after bootstrap + regtest?

gcc/cp/ChangeLog:

PR c++/18969
* typeck.c (check_return_expr): Also do the basic return-value
validity checking if processing_template_decl and yet types are
not dependent.  Remove obsolete code.

gcc/testsuite/ChangeLog:

PR c++/18969
* g++.dg/template/pr18969.C: New test.
* g++.dg/template/pr18969-2.C: New test.
---
 gcc/cp/typeck.c   | 22 --
 gcc/testsuite/g++.dg/template/pr18969-2.C | 11 +++
 gcc/testsuite/g++.dg/template/pr18969.C   | 14 ++
 3 files changed, 41 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/template/pr18969-2.C
 create mode 100644 gcc/testsuite/g++.dg/template/pr18969.C

diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index b88a3fd..36a3ee7 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -8515,12 +8515,19 @@ check_return_expr (tree retval, bool *no_warning)
   return NULL_TREE;
 }
 
+  const tree saved_retval = retval;
+
   if (processing_template_decl)
 {
   current_function_returns_value = 1;
+
   if (check_for_bare_parameter_packs (retval))
-retval = error_mark_node;
-  return retval;
+   return error_mark_node;
+
+  if (WILDCARD_TYPE_P (TREE_TYPE (DECL_RESULT (current_function_decl)))
+ || (retval != NULL_TREE
+ && type_dependent_expression_p (retval)))
+return retval;
 }
 
   functype = TREE_TYPE (TREE_TYPE (current_function_decl));
@@ -8564,14 +8571,10 @@ check_return_expr (tree retval, bool *no_warning)
   functype = type;
 }
 
-  /* When no explicit return-value is given in a function with a named
- return value, the named return value is used.  */
   result = DECL_RESULT (current_function_decl);
   valtype = TREE_TYPE (result);
   gcc_assert (valtype != NULL_TREE);
   fn_returns_value_p = !VOID_TYPE_P (valtype);
-  if (!retval && DECL_NAME (result) && fn_returns_value_p)
-retval = result;
 
   /* Check for a return statement with no return value in a function
  that's supposed to return a value.  */
@@ -8656,6 +8659,13 @@ check_return_expr (tree retval, bool *no_warning)
warning (OPT_Weffc__, "% should return a reference to 
%<*this%>");
 }
 
+  if (processing_template_decl)
+{
+  /* We should not have altered the return value.  */
+  gcc_assert (retval == saved_retval);
+  return retval;
+}
+
   /* The fabled Named Return Value optimization, as per [class.copy]/15:
 
  [...]  For  a function with a class return type, if the expression
diff --git a/gcc/testsuite/g++.dg/template/pr18969-2.C 
b/gcc/testsuite/g++.dg/template/pr18969-2.C
new file mode 100644
index 000..e0b0c1b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/pr18969-2.C
@@ -0,0 +1,11 @@
+// PR c++/18969
+// { dg-do compile { target c++14 } }
+
+template 
+struct A
+{
+auto *f1 () { return; } // { dg-error "return-statement" }
+auto &f2 () { return; } // { dg-error "return-statement" }
+
+auto f3 () { return; } // { dg-bogus "return-statement" }
+};
diff --git a/gcc/testsuite/g++.dg/template/pr18969.C 
b/gcc/testsuite/g++.dg/template/pr18969.C
new file mode 100644
index 000..dba5eb9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/pr18969.C
@@ -0,0 +1,14 @@
+// PR c++/18969
+
+template 
+struct A
+{
+int f1 () { return; } // { dg-error "return-statement" }
+void f2 () { return 5; } // { dg-error "return-statement" }
+T *f3 () { return; } // { dg-error "return-statement" }
+typename T::f &f4 () { return; } // { dg-error "return-statement" }
+
+T f5 () { return; } // { dg-bogus "return-statement" }
+void f6 () { return (T)true; } // { dg-bogus "return-statement" }
+typename T::f f7 () { return; } // { dg-bogus "return-statement" }
+};
-- 
2.5.0.rc2.22.g69b1679.dirty



Re: [PATCH] Fix PR c++/18969 (invalid return statement diagnosed too late)

2015-07-25 Thread Jason Merrill

OK.

Jason


Re: [PATCH] [5/6 Regression] Fix PR c++/66857

2015-07-25 Thread Jason Merrill

On 07/25/2015 04:16 PM, Patrick Palka wrote:

On Sat, Jul 25, 2015 at 7:12 PM, Patrick Palka  wrote:

gcc/cp/ChangeLog:

 PR c++/66857
 * cvt.c (ocp_convert): Don't call scalar_constant_value when
 converting to a class type.

gcc/testsuite/ChangeLog:

 PR c++/66857
 * g++.dg/init/pr66857.C: New test.


This fix was approved here https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66857#c5

Committed to mainline.  Is it OK for the GCC 5 branch?


Yes, thanks.

Jason