Re: [PATCH] Fix ix86_split_long_move collision handling with TLS (PR target/66470)

2015-06-10 Thread Jakub Jelinek
On Wed, Jun 10, 2015 at 08:06:08AM +0200, Uros Bizjak wrote:
> > If -mx32 is a non-issue here, then perhaps my initial patch is good enough?
> 
> It looks to me, that if you detect and record zero-extended UNSPEC_TP,
> your original patch would also handle -mx32.
> 
> Can you please repost your original patch with the above addition?

I've managed to come up with a testcase that ICEs on -mx32 (with
-maddress-mode=long, with the default UNSPEC_TP seems to be always loaded
separately), and this version fixes even that, ok for trunk/5/4.9/4.8?

2015-06-10  Jakub Jelinek  

PR target/66470
* config/i386/i386.c (ix86_split_long_move): For collisions
involving direct tls segment refs, move the UNSPEC_TP possibly
wrapped in ZERO_EXTEND out of the address for lea, to each of
the memory loads.

* gcc.dg/tls/pr66470.c: New test.
* gcc.target/i386/pr66470.c: New test.

--- gcc/config/i386/i386.c.jj   2015-06-10 08:18:31.170053193 +0200
+++ gcc/config/i386/i386.c  2015-06-10 08:51:21.315434960 +0200
@@ -22858,7 +22858,7 @@ ix86_split_long_move (rtx operands[])
 Do an lea to the last part and use only one colliding move.  */
   else if (collisions > 1)
{
- rtx base;
+ rtx base, addr, tls_base = NULL_RTX;
 
  collisions = 1;
 
@@ -22869,10 +22869,50 @@ ix86_split_long_move (rtx operands[])
  if (GET_MODE (base) != Pmode)
base = gen_rtx_REG (Pmode, REGNO (base));
 
- emit_insn (gen_rtx_SET (base, XEXP (part[1][0], 0)));
+ addr = XEXP (part[1][0], 0);
+ if (TARGET_TLS_DIRECT_SEG_REFS)
+   {
+ struct ix86_address parts;
+ int ok = ix86_decompose_address (addr, &parts);
+ gcc_assert (ok);
+ if (parts.seg == DEFAULT_TLS_SEG_REG)
+   {
+ /* It is not valid to use %gs: or %fs: in
+lea though, so we need to remove it from the
+address used for lea and add it to each individual
+memory loads instead.  */
+ addr = copy_rtx (addr);
+ rtx *x = &addr;
+ while (GET_CODE (*x) == PLUS)
+   {
+ for (i = 0; i < 2; i++)
+   {
+ rtx u = XEXP (*x, i);
+ if (GET_CODE (u) == ZERO_EXTEND)
+   u = XEXP (u, 0);
+ if (GET_CODE (u) == UNSPEC
+ && XINT (u, 1) == UNSPEC_TP)
+   {
+ tls_base = XEXP (*x, i);
+ *x = XEXP (*x, 1 - i);
+ break;
+   }
+   }
+ if (tls_base)
+   break;
+ x = &XEXP (*x, 0);
+   }
+ gcc_assert (tls_base);
+   }
+   }
+ emit_insn (gen_rtx_SET (base, addr));
+ if (tls_base)
+   base = gen_rtx_PLUS (GET_MODE (base), base, tls_base);
  part[1][0] = replace_equiv_address (part[1][0], base);
  for (i = 1; i < nparts; i++)
{
+ if (tls_base)
+   base = copy_rtx (base);
  tmp = plus_constant (Pmode, base, UNITS_PER_WORD * i);
  part[1][i] = replace_equiv_address (part[1][i], tmp);
}
--- gcc/testsuite/gcc.dg/tls/pr66470.c.jj   2015-06-10 08:43:27.719773302 
+0200
+++ gcc/testsuite/gcc.dg/tls/pr66470.c  2015-06-10 08:43:27.719773302 +0200
@@ -0,0 +1,29 @@
+/* PR target/66470 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-require-effective-target tls } */
+
+extern __thread unsigned long long a[10];
+extern __thread struct S { int a, b; } b[10];
+
+unsigned long long
+foo (long x)
+{
+  return a[x];
+}
+
+struct S
+bar (long x)
+{
+  return b[x];
+}
+
+#ifdef __SIZEOF_INT128__
+extern __thread unsigned __int128 c[10];
+
+unsigned __int128
+baz (long x)
+{
+  return c[x];
+}
+#endif
--- gcc/testsuite/gcc.target/i386/pr66470.c.jj  2015-06-10 08:45:10.86752 
+0200
+++ gcc/testsuite/gcc.target/i386/pr66470.c 2015-06-10 08:47:30.914005019 
+0200
@@ -0,0 +1,13 @@
+/* PR target/66470 */
+/* { dg-do compile { target { ! { ia32 } } } } */
+/* { dg-options "-O2 -mx32 -maddress-mode=long" } */
+/* { dg-require-effective-target tls } */
+
+extern __thread unsigned __int128 c[10];
+int d;
+
+unsigned __int128
+foo (void)
+{
+  return c[d];
+}


Jakub


Re: [PATCH] Move gen_* stubs from defaults.h to genflags

2015-06-10 Thread Richard Sandiford
Mikhail Maltsev  writes:
> Hi, all.
>
> I noticed that defaults.h file contains stub generator functions which
> simply call gcc_unreachable. FWIW, Trevor added them to remove some
> conditional compilation which depends on HAVE_ macros (I mean
> something like r223624).
>
> Because we still have ~80 more such conditions in GCC, and probably some
> of them will be fixed in the same way, I propose a patch, which allows
> to generate required stubs in genflags.

Nice!

> +/* Structure which holds data, required for generating stub gen_* function.  
> */

No comma after "data"

> +/* These instructions require default stub function.  Stubs are never called.

"require a default"

> +/* Helper traits for using null-terminated strings as keys in hash map.
> +   FIXME: Unify various "string hashers" and move them to hash-map-traits.h. 
>  */
> +struct gflg_string_hasher : default_hashmap_traits
> +{
> +  typedef const char *value_type;
> +  typedef const char *compare_type;
> +
> +  static inline hashval_t hash (const char *s)
> +  {
> +return htab_hash_string (s);
> +  }
> +
> +  static inline bool equal_keys (const char *p1, const char *p2)
> +  {
> +return strcmp (p1, p2) == 0;
> +  }
> +};
> +
> +/* Mapping from insn name to corresponding stub_info_t entry.  */
> +static hash_map
> +stubs_map (ARRAY_SIZE (stubs), false, false);

Seems like this is more naturally a hash_table rather than a hash_map.
I think there's also a preference to avoid static constructor-based
initialisation.

There again, this is a generator, so those kinds of concerns aren't
particularly important.  If we do keep the above though, I think we
should put the hasher in hash-map-table.h now.  Otherwise these FIXMEs
are just going to accumulate, and each time makes it less likely that
any consolidation will actually happen.

Thanks,
Richard



Re: [PATCH] Fix ix86_split_long_move collision handling with TLS (PR target/66470)

2015-06-10 Thread Uros Bizjak
On Wed, Jun 10, 2015 at 9:06 AM, Jakub Jelinek  wrote:
> On Wed, Jun 10, 2015 at 08:06:08AM +0200, Uros Bizjak wrote:
>> > If -mx32 is a non-issue here, then perhaps my initial patch is good enough?
>>
>> It looks to me, that if you detect and record zero-extended UNSPEC_TP,
>> your original patch would also handle -mx32.
>>
>> Can you please repost your original patch with the above addition?
>
> I've managed to come up with a testcase that ICEs on -mx32 (with
> -maddress-mode=long, with the default UNSPEC_TP seems to be always loaded
> separately), and this version fixes even that, ok for trunk/5/4.9/4.8?
>
> 2015-06-10  Jakub Jelinek  
>
> PR target/66470
> * config/i386/i386.c (ix86_split_long_move): For collisions
> involving direct tls segment refs, move the UNSPEC_TP possibly
> wrapped in ZERO_EXTEND out of the address for lea, to each of
> the memory loads.
>
> * gcc.dg/tls/pr66470.c: New test.
> * gcc.target/i386/pr66470.c: New test.

Yes, this patch is OK for mainline and release branches.

Thanks,
Uros.


Re: [PATCH] Move gen_* stubs from defaults.h to genflags

2015-06-10 Thread Richard Sandiford
Richard Sandiford  writes:
> There again, this is a generator, so those kinds of concerns aren't
> particularly important.  If we do keep the above though, I think we
> should put the hasher in hash-map-table.h now.

Of course I mean hash-map-traits.h :-)



[Patch testsuite obvious] gcc.target/arm/pr65710.c should not unconditionally set -mfloat-abi=soft

2015-06-10 Thread James Greenhalgh

Hi,

This is another test which currently fails for -mfloat-abi multilib
testing as it unconditionally sets -mfloat-abi=soft.

Fixed as attached in the same way we deal with other tests like this,
and committed as obvious as revision 224312.

Thanks,
James

---
gcc/testsuite/

2015-06-10  James Greenhalgh  

* gcc.target/arm/pr65710.c: Do not override -mfloat-abi directives
passed by the testsuite driver.

diff --git a/gcc/testsuite/gcc.target/arm/pr65710.c b/gcc/testsuite/gcc.target/arm/pr65710.c
index 227059b..103ce1d 100644
--- a/gcc/testsuite/gcc.target/arm/pr65710.c
+++ b/gcc/testsuite/gcc.target/arm/pr65710.c
@@ -1,4 +1,5 @@
 /* { dg-do compile } */
+/* { dg-skip-if "do not override -mfloat-abi" { *-*-* } { "-mfloat-abi=*" } {"-mfloat-abi=soft" } } */
 /* { dg-options "-mthumb -O2 -mfloat-abi=soft -w" } */
 /* { dg-skip-if "" { ! { arm_thumb1_ok || arm_thumb2_ok } } } */
 


[Patch PR target/66200, target/66498, c++/66192] - Adjust aarch64_guard1.C test

2015-06-10 Thread Ramana Radhakrishnan
Sorry about missing this hunk in the original submission, was in my tree 
but I hadn't spotted this as I was playing between the original AArch64 
TARGET_RELAXED_ORDER and this patch.


Applied as obvious.

PR target/66200
PR target/66498
PR c++/66192
* g++.dg/testsuite/aarch64_guard1.C: Adjust test.


Re: [Patch, fortran, PR44672, v10] [F08] ALLOCATE with SOURCE and no array-spec

2015-06-10 Thread Andre Vehreschild
Hi all,

please find attached an updated version of the patch. This patch simplifies
some cases and ensures more straight line code. Furthermore was a bug in the
interfacing routine for the _vptr->_copy() routine removed, where not the third
and fourth arguments translated to be passed be value but the fourth and fifth
(cs start counting at zero...).

Bootstraps and regtests fine on x86_64-linux-gnu/f21.

Ok for trunk?

Regards,
Andre

On Fri, 5 Jun 2015 13:04:01 +0200
Andre Vehreschild  wrote:

> Hi all,
> 
> attached is the most recent version of the patch. It addresses the standard
> violation of allocate(foo, source=[bar(something)]), where foo after the
> allocate was a zero-based array instead of a one-based. Furthermore does this
> patch fix calling _vptr->_copy () routines, which come without an interface
> specification leading to pass all arguments by reference. When copying a
> deferred length string this is hazardous, because a __copy_character_* ()
> routines third and fourth arguments are passed by value. This is fixed by
> simply counting the actual arguments and using pass by value for third and
> fourth to _copy routine.
> 
> Bootstraps and regtests ok on x86_64-linux-gnu/f21.
> 
> Ok for trunk?
> 
> - Andre


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 


pr44672_10.clog
Description: Binary data
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 8e4ca42..4b07ddb 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -2395,6 +2395,9 @@ typedef struct gfc_code
 {
   gfc_typespec ts;
   gfc_alloc *list;
+  /* Take the array specification from expr3 to allocate arrays
+	 without an explicit array specification.  */
+  unsigned arr_spec_from_expr3:1;
 }
 alloc;
 
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 52dc109..f365e8f 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -6805,7 +6805,7 @@ conformable_arrays (gfc_expr *e1, gfc_expr *e2)
have a trailing array reference that gives the size of the array.  */
 
 static bool
-resolve_allocate_expr (gfc_expr *e, gfc_code *code)
+resolve_allocate_expr (gfc_expr *e, gfc_code *code, bool *array_alloc_wo_spec)
 {
   int i, pointer, allocatable, dimension, is_abstract;
   int codimension;
@@ -7104,13 +7104,24 @@ resolve_allocate_expr (gfc_expr *e, gfc_code *code)
   if (!ref2 || ref2->type != REF_ARRAY || ref2->u.ar.type == AR_FULL
   || (dimension && ref2->u.ar.dimen == 0))
 {
-  gfc_error ("Array specification required in ALLOCATE statement "
-		 "at %L", &e->where);
-  goto failure;
+  /* F08:C633.  */
+  if (code->expr3)
+	{
+	  if (!gfc_notify_std (GFC_STD_F2008, "Array specification required "
+			   "in ALLOCATE statement at %L", &e->where))
+	goto failure;
+	  *array_alloc_wo_spec = true;
+	}
+  else
+	{
+	  gfc_error ("Array specification required in ALLOCATE statement "
+		 "at %L", &e->where);
+	  goto failure;
+	}
 }
 
   /* Make sure that the array section reference makes sense in the
-context of an ALLOCATE specification.  */
+ context of an ALLOCATE specification.  */
 
   ar = &ref2->u.ar;
 
@@ -7125,7 +7136,7 @@ resolve_allocate_expr (gfc_expr *e, gfc_code *code)
 
   for (i = 0; i < ar->dimen; i++)
 {
-  if (ref2->u.ar.type == AR_ELEMENT)
+  if (ar->type == AR_ELEMENT || ar->type == AR_FULL)
 	goto check_symbols;
 
   switch (ar->dimen_type[i])
@@ -7202,6 +7213,7 @@ failure:
   return false;
 }
 
+
 static void
 resolve_allocate_deallocate (gfc_code *code, const char *fcn)
 {
@@ -7376,8 +7388,16 @@ resolve_allocate_deallocate (gfc_code *code, const char *fcn)
 
   if (strcmp (fcn, "ALLOCATE") == 0)
 {
+  bool arr_alloc_wo_spec = false;
   for (a = code->ext.alloc.list; a; a = a->next)
-	resolve_allocate_expr (a->expr, code);
+	resolve_allocate_expr (a->expr, code, &arr_alloc_wo_spec);
+
+  if (arr_alloc_wo_spec && code->expr3)
+	{
+	  /* Mark the allocate to have to take the array specification
+	 from the expr3.  */
+	  code->ext.alloc.arr_spec_from_expr3 = 1;
+	}
 }
   else
 {
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 5ea9aec..e9174ae 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -4998,7 +4998,8 @@ static tree
 gfc_array_init_size (tree descriptor, int rank, int corank, tree * poffset,
 		 gfc_expr ** lower, gfc_expr ** upper, stmtblock_t * pblock,
 		 stmtblock_t * descriptor_block, tree * overflow,
-		 tree expr3_elem_size, tree *nelems, gfc_expr *expr3)
+		 tree expr3_elem_size, tree *nelems, gfc_expr *expr3,
+		 tree expr3_desc, bool e3_is_array_constr)
 {
   tree type;
   tree tmp;
@@ -5041,7 +5042,18 @@ gfc_array_init_size (tree descriptor, int rank, int corank, tree * poffset,
 
   /* Set lower bound.  */
   gfc_init_se (&se, NULL);
-  if (lower == NULL)
+  if (expr3_desc != NULL_TREE)
+	{
+	  if (e3_is_array_constr)
+	/* Th

Re: [PING^2][PATCH][3/3][PR65460] Mark offloaded functions as parallelized

2015-06-10 Thread Tom de Vries

On 10/06/15 00:15, Thomas Schwinge wrote:

Hi Tom!

On Tue, 9 Jun 2015 16:12:12 +0200, Tom de Vries  wrote:

On 09/06/15 13:07, Richard Biener wrote:

On Mon, 8 Jun 2015, Tom de Vries wrote:


On 17/04/15 12:08, Tom de Vries wrote:

On 20-03-15 12:38, Tom de Vries wrote:

On 19-03-15 12:05, Tom de Vries wrote:

On 18-03-15 18:22, Tom de Vries wrote:

this patch fixes PR65460.

The patch marks offloaded functions as parallelized, which means the
parloops
pass no longer attempts to modify that function.



Ok, but shouldn't it be set before calling add_new_function as
add_new_function might run passes that wouldn't identify the
function as parallelized?


Hm, indeed sometimes add_new_function executes some passes itself,
besides queueing the function for further processing. I suppose the
existing settings of parallelized_function should be modified in a
similar way.


(I took note of this small change of the trunk patch vs. the version
present on gomp-4_0-branch, and will adapt the latter as required as part
of the next merge.)


I'll bootstrap and reg-test attached two patches on x86_64, and commit
unless objections.



Mark offloaded functions as parallelized

2015-06-09  Tom de Vries  

PR tree-optimization/65460
* omp-low.c (expand_omp_target): Set parallelized_function on
cgraph_node for child_fn.


(Committed to trunk in r224303.)


--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -8959,6 +8959,8 @@ expand_omp_target (struct omp_region *region)

/* Inform the callgraph about the new function.  */
DECL_STRUCT_FUNCTION (child_fn)->curr_properties = 
cfun->curr_properties;
+  cgraph_node *node = cgraph_node::get_create (child_fn);


Would you please committ a fix: in offloading configurations
(ENABLE_OFFLOADING), this new node variable will clash with an existing
definition a little later:


+  node->parallelized_function = 1;
cgraph_node::add_new_function (child_fn, true);

  #ifdef ENABLE_OFFLOADING

|/* Add the new function to the offload table.  */
|vec_safe_push (offload_funcs, child_fn);
|  #endif
|
|/* Fix the callgraph edges for child_cfun.  Those for cfun will be
|fixed in a following pass.  */
|push_cfun (child_cfun);
|cgraph_edge::rebuild_edges ();
|
|  #ifdef ENABLE_OFFLOADING
|/* Prevent IPA from removing child_fn as unreachable, since there are 
no
|refs from the parent function to child_fn in offload LTO mode.  */
|struct cgraph_node *node = cgraph_node::get (child_fn);
|node->mark_force_output ();
|  #endif



Committed attached patch to trunk as obvious. Build and tested in 
ENABLE_OFFLOADING configuration on top of gomp-4_0-branch.


Thanks,
- Tom
Fix build for ENABLE_OFFLOADING in expand_omp_target

2015-06-10  Tom de Vries  

	* omp-low.c (expand_omp_target): Remove duplicate declaration of node.
---
 gcc/omp-low.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 77716bf6..72c431e 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -8976,8 +8976,7 @@ expand_omp_target (struct omp_region *region)
 #ifdef ENABLE_OFFLOADING
   /* Prevent IPA from removing child_fn as unreachable, since there are no
 	 refs from the parent function to child_fn in offload LTO mode.  */
-  struct cgraph_node *node = cgraph_node::get (child_fn);
-  node->mark_force_output ();
+  cgraph_node::get (child_fn)->mark_force_output ();
 #endif
 
   /* Some EH regions might become dead, see PR34608.  If
-- 
1.9.1



[Patch ARM] Use dmb ish instead of dmb sy

2015-06-10 Thread Ramana Radhakrishnan

Hi,

	A patch that's been sitting in my tree for sometime has been something 
to fix up using dmb ish instead of dmb sy in the ARM backend. This 
brings us in line with the AArch64 backend's behaviour as well for the 
same. A future cleanup to write this in the form of memory_fences and 
exploit all the memory models is something that should be considered in 
the near future, but that's not a part of this patch.


	* config/arm/sync.md (*memory_barrier): Use dmb ish, adjust tab for 
older architectures.


Applied to trunk.

regards
Ramana
Index: gcc/config/arm/sync.md
===
--- gcc/config/arm/sync.md  (revision 224315)
+++ gcc/config/arm/sync.md  (working copy)
@@ -50,14 +50,11 @@
   {
 if (TARGET_HAVE_DMB)
   {
-   /* Note we issue a system level barrier. We should consider issuing
-  a inner shareabilty zone barrier here instead, ie. "DMB ISH".  */
-   /* ??? Differentiate based on SEQ_CST vs less strict?  */
-   return "dmb\tsy";
+   return "dmb\\tish";
   }
 
 if (TARGET_HAVE_DMB_MCR)
-  return "mcr\tp15, 0, r0, c7, c10, 5";
+  return "mcr\\tp15, 0, r0, c7, c10, 5";
 
 gcc_unreachable ();
   }


Re: [PATCH] [AArch64] PR63870 Improve error messages for NEON single lane memory access intrinsics

2015-06-10 Thread Charles Baylis
On 8 June 2015 at 10:33, Alan Lawrence  wrote:
> Thanks for working on this!
>
> I'd been fiddling around with a patch with some similar elements to this,
> but many trials with union types, subregs, etc., all worsened the register
> allocation and led to more unnecessary shuffling / moves.

Kugan has been looking into this at Linaro. We should avoid
duplicating effort here.

> The only real
> thing I tried which you don't do here, was to introduce a set_dreg expander
> to clean up some of those macro definitions in arm_neon.h. That could easily
> follow in a separate patch if desired!

I'd prefer that to be a separate step.

> So your patch looks good to me.
>
> A couple of style nits:
>
> --- a/gcc/config/aarch64/aarch64-builtins.c
> +++ b/gcc/config/aarch64/aarch64-builtins.c
> @@ -128,7 +128,9 @@ enum aarch64_type_qualifiers
>/* Polynomial types.  */
>qualifier_poly = 0x100,
>/* Lane indices - must be in range, and flipped for bigendian.  */
> -  qualifier_lane_index = 0x200
> +  qualifier_lane_index = 0x200,
> +  /* Lane indices for single lane structure loads and stores */
> +  qualifier_struct_load_store_lane_index = 0x400
>  };
>
> should be ...'loads and stores.  */'
>
> also the dg-error messages in the testsuite, do not need to be on the same
> line as the statement generating the error, because the trailing 0 tells dg
> that the position/line number doesn't matter (i.e. dg should allow the error
> to be reported at any line); so these could be brought under 80 chars.

OK, thanks. I'll re-spin once I've tested on big endian.

> Oh, have you tested bigendian?

I have started a bigendian build on our validation infrastructure here.

Thanks for the review
Charles


[PATCH] Fix PR lto/66394

2015-06-10 Thread Martin Liška
Hello.

This patch fixes $SUBJECT, can bootstrap and survive regression tests on 
x86_64-linux-unknown-pc.

Ready for trunk?
If so, I'm going to prepare backportable patches for 4.9 and 5.0 branches.

Thanks,
Martin
>From 9cd5de436cfca51095d63b3a3017df44c95baba6 Mon Sep 17 00:00:00 2001
From: mliska 
Date: Thu, 4 Jun 2015 14:40:33 +0200
Subject: [PATCH] Fix PR lto/66394.

gcc/ChangeLog:

2015-06-10  Martin Liska  

	PR lto/66394
	* lto-cgraph.c (compute_ltrans_boundary): Do not stream
	DECL_ABSTRACT_ORIGIN of a varpool node if it is not present
	in symbol table.

gcc/testsuite/ChangeLog:

2015-06-10  Martin Liska  

	* g++.dg/ipa/pr66394.C: New test.
---
 gcc/lto-cgraph.c   |  4 +++-
 gcc/testsuite/g++.dg/ipa/pr66394.C | 22 ++
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/ipa/pr66394.C

diff --git a/gcc/lto-cgraph.c b/gcc/lto-cgraph.c
index 42db4d8..6849f7e 100644
--- a/gcc/lto-cgraph.c
+++ b/gcc/lto-cgraph.c
@@ -932,7 +932,9 @@ compute_ltrans_boundary (lto_symtab_encoder_t in_encoder)
 	{
 	  varpool_node *origin_node
 	= varpool_node::get (DECL_ABSTRACT_ORIGIN (vnode->decl));
-	  lto_set_symtab_encoder_in_partition (encoder, origin_node);
+
+	  if (origin_node)
+	lto_set_symtab_encoder_in_partition (encoder, origin_node);
 	}
 }
   /* Pickle in also the initializer of all referenced readonly variables
diff --git a/gcc/testsuite/g++.dg/ipa/pr66394.C b/gcc/testsuite/g++.dg/ipa/pr66394.C
new file mode 100644
index 000..a4ceb2e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ipa/pr66394.C
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-fmerge-all-constants -flto -fpermissive -std=c++11" } */
+
+template  void CvtColorLoop(int, int, const Cvt);
+enum { R2Y, G2Y, B2Y };
+struct RGB2Gray {
+  RGB2Gray(int, int, const int *coeffs) {
+const int coeffs0[]{G2Y, B2Y};
+coeffs = coeffs0;
+tab[2] = *coeffs;
+  }
+  int tab[];
+};
+
+void
+cvtColor_bidx() {
+  int src, dst;
+  const int *a = &src;
+  RGB2Gray(0, dst, a);
+  CvtColorLoop(src, dst, 0);
+}
+
-- 
2.1.4



[PATCH, AArch64] [4.9] Backport

2015-06-10 Thread weixiangyu
Another backport patch which fixes a csmith ICE problem. Rebased on the latest 
4.9 branch. 
Tested ok on aarch64-linux with qemu. 

Index: gcc/ChangeLog
===
--- gcc/ChangeLog   (revision 223867)
+++ gcc/ChangeLog   (working copy)
@@ -1,3 +1,12 @@
+2015-06-10 Xiangyu Wei  
+
+   Backport from mainline r210497.
+   2014-05-16  James Greenhalgh  
+   Philipp Tomsich  
+
+   * config/aarch64/aarch64.c (aarch64_strip_shift_or_extend): Check RTX is
+   well formed.
+
 2015-05-28  Mike Frysinger  
 
* config/nios2/linux.h (CPP_SPEC): Define.
===
--- gcc/ChangeLog   (revision 223867)
+++ gcc/ChangeLog   (working copy)
@@ -1,3 +1,12 @@
+2015-06-10 Xiangyu Wei  
+
+   Backport from mainline r210497.
+   2014-05-16  James Greenhalgh  
+   Philipp Tomsich  
+
+   * config/aarch64/aarch64.c (aarch64_strip_shift_or_extend): Check RTX is
+   well formed.
+
 2015-05-28  Mike Frysinger  
 
* config/nios2/linux.h (CPP_SPEC): Define.


r210497.diff
Description: r210497.diff


RE: backport the fixes of PR target/64011 and /61749 to 4.9 gcc

2015-06-10 Thread Joseph Myers
On Wed, 10 Jun 2015, weixiangyu wrote:

> +  if (bitsize + bitnum > unit && bitnum < unit) 
> +{ 
> +  warning (OPT_Wextra, "write of "HOST_WIDE_INT_PRINT_UNSIGNED"bit data 
> " 
> +   "outside the bound of destination object, data truncated into 
> " 
> +   HOST_WIDE_INT_PRINT_UNSIGNED"bit", bitsize, unit - bitnum); 

HOST_WIDE_INT_PRINT_UNSIGNED is a printf format, which depends on the host 
and is not suitable for any translatable string, not a format for GCC's 
pretty printers.  Use %wu instead in any call to a GCC diagnostic 
function.  Mainline appears to have this correct.

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


Re: Do less generous pointer globbing in alias.c

2015-06-10 Thread Martin Liška
On 05/27/2015 07:28 AM, Jan Hubicka wrote:
> Hi,
> this patch makes it possible for non-LTO alias oracle to TBAA disambiguate
> pointer types. It makes void * conflicting with all of them and does not put 
> it
> to alias set 0. It also preserves the property that qualifiers of pointer-to
> type should not matter to determine the alias set and that pointer to array is
> same as pointer to array element.  Finally it makes pointer void * to be
> equivalent to void ** (and more *) and to types with structural equality only.
> 
> I think those are all globbing rules we discussed for the non-LTO patch.
> 
> It does two things.  First is kind of "canonicalization" where for a given 
> pointer
> it looks for non-pointer pointed-to type and then rebuilds is without 
> qualifiers.
> This is fast, because build_pointer_type will reuse existing types.
> 
> It makes void * to conflict with everyting by making its alias set to be 
> subset
> of alias set of any other pointer.  This means that writes to void * conflict
> with writes to any other pointer without really need to glob all the pointers
> to one equivalence class.
> 
> This patch makes quite some difference on C++.  For example on deal II the 
> TBAA
> stats reports 4344358 disambiguations and 7008576 queries, while with the 
> patch
> we get 5368737 and 5687399 queries (I did not chose deal II for reason, it is
> just random C++ file)
> 
> The patch bootstrap and regtests ppc64le-linux with the following testsuite
> differences:
> @@ -30,7 +30,9 @@
>  FAIL: c-c++-common/asan/null-deref-1.c   -O3 -g  output pattern test, is 
> ASAN:SIGSEGV
>  FAIL: c-c++-common/asan/null-deref-1.c   -Os  output pattern test, is 
> ASAN:SIGSEGV
>  FAIL: gcc.dg/cpp/_Pragma3.c (test for excess errors)
> +XPASS: gcc.dg/alias-8.c  (test for warnings, line 11)
>  FAIL: gcc.dg/loop-8.c scan-rtl-dump-times loop2_invariant "Decided" 1
> +FAIL: gcc.dg/pr62167.c scan-tree-dump-not pre "Removing basic block"
>  FAIL: gcc.dg/sms-4.c scan-rtl-dump-times sms "SMS succeeded" 1
>  XPASS: gcc.dg/guality/example.c   -O0  execution test
>  XPASS: gcc.dg/guality/example.c   -O1  execution test
> @@ -304,6 +306,9 @@
>  FAIL: c-c++-common/asan/null-deref-1.c   -O3 -g  output pattern test, is 
> ASAN:SIGSEGV
>  FAIL: g++.dg/cpp1y/vla-initlist1.C  -std=gnu++11 execution test
>  FAIL: g++.dg/cpp1y/vla-initlist1.C  -std=gnu++14 execution test
> +FAIL: g++.dg/ipa/ipa-icf-4.C  -std=gnu++11  scan-ipa-dump icf "Equal 
> symbols: [67]"
> +FAIL: g++.dg/ipa/ipa-icf-4.C  -std=gnu++14  scan-ipa-dump icf "Equal 
> symbols: [67]"
> +FAIL: g++.dg/ipa/ipa-icf-4.C  -std=gnu++98  scan-ipa-dump icf "Equal 
> symbols: [67]"
> 
> ipa-icf-4 is about alias info now being more perceptive to block the merging.
> pr62167 seems just confused.  The template checks that memory stores are not
> unified.  It looks for BB removal message, but with the patch we get:
>   :
>   node.next = 0B;
>   head.0_4 = head;
>   node.prev = head.0_4;
>   head.0_4->first = &node;
>   k.1_7 = k;
>   h_8 = &heads[k.1_7];
>   heads[2].first = 0B;
>   if (head.0_4 == h_8)
> goto ;
>   else
> goto ;
> 
>   :
>   goto ;
> 
>   :
>   p_10 = MEM[(struct head *)&heads][k.1_7].first;
> 
>   :
>   # p_1 = PHI 
>   _11 = p_1 != 0B;
>   _12 = (int) _11;
>   return _12;
> 
> before PR, the message is about the bb 5 sitting at critical edge removed.
> The TBAA incompatible load it looks for is optimized away by FRE:
>   head->first = &node;
> 
>   struct node *n = head->first;
> 
>   struct head *h = &heads[k];
> 
>   heads[2].first = n->next;
> 
>   if ((void*)n->prev == (void *)h)
> p = h->first;
>   else
> /* Dead tbaa-unsafe load from ((struct node *)&heads[2])->next.  */
> p = n->prev->next;
> 
> here n is known to be head->first that is known to be &node.
> The testcase runtime checks that result is Ok and passes.
> 
> Bootstrapped/regtested ppc64le-linux.
> 
>   * alias.c (get_alias_set): Do not glob all pointer types into one;
>   just produce euqivalence classes based on canonical type of pointed
>   type type; make void * equivalent to void **.
>   (record_component_aliases): Make void * to conflict with all other
>   pointer types.
> Index: alias.c
> ===
> --- alias.c   (revision 223633)
> +++ alias.c   (working copy)
> @@ -903,35 +906,79 @@ get_alias_set (tree t)
>   the pointed-to types.  This issue has been reported to the
>   C++ committee.
>  
> - In addition to the above canonicalization issue, with LTO
> - we should also canonicalize `T (*)[]' to `T *' avoiding
> - alias issues with pointer-to element types and pointer-to
> - array types.
> -
> - Likewise we need to deal with the situation of incomplete
> - pointed-to types and make `*(struct X **)&a' and
> - `*(struct X {} **)&a' alias.  Otherwise we will have to
> - guarantee that all pointer-to incomplete type variants
> - will be replaced by p

[gomp4] Support C++ "this" in OpenACC directives

2015-06-10 Thread Joseph Myers
This patch, for gomp-4_0-branch, adds support for C++ "this" in
OpenACC directives.  (This patch does not do anything to handle OpenMP
differently from OpenACC; that - bug 66053 - will need to be resolved
for mainline, either deciding these cases should be accepted for
OpenMP or making the parsing only accept them in OpenACC directives
and not OpenMP ones.)

Apart from parsing, it's necessary to prevent the "cannot take the
address of 'this', which is an rvalue expression" error from appearing
when "this" is used in such contexts.  This patch duly adds a new
argument to cxx_mark_addressable (default false so callers don't all
need to change) to allow disabling that error, passing that argument
in all calls that seem relevant to OpenACC directives.

Tested for x86_64-none-linux-gnu and applied to gomp-4_0-branch.

gcc/cp:
2015-06-10  Joseph Myers  

* parser.c (cp_parser_omp_var_list_no_open): Handle RID_THIS.
* typeck.c (cxx_mark_addressable): Add argument ALLOW_THIS.
* cp-tree.h (cxx_mark_addressable): Update prototype.
* semantics.c (handle_omp_array_sections)
(finish_omp_reduction_clause, finish_omp_clauses): Pass ALLOW_THIS
to cxx_mark_addressable.

libgomp:
2015-06-10  Cesar Philippidis  

* testsuite/libgomp.oacc-c++/this.C: New test.

Index: gcc/cp/parser.c
===
--- gcc/cp/parser.c (revision 224232)
+++ gcc/cp/parser.c (working copy)
@@ -27872,19 +27872,27 @@ cp_parser_omp_var_list_no_open (cp_parser *parser,
   tree name, decl;
 
   token = cp_lexer_peek_token (parser->lexer);
-  name = cp_parser_id_expression (parser, /*template_p=*/false,
- /*check_dependency_p=*/true,
- /*template_p=*/NULL,
- /*declarator_p=*/false,
- /*optional_p=*/false);
-  if (name == error_mark_node)
-   goto skip_comma;
+  if (current_class_ptr && cp_parser_is_keyword (token, RID_THIS))
+   {
+ decl = current_class_ptr;
+ cp_lexer_consume_token (parser->lexer);
+   }
+  else
+   {
+ name = cp_parser_id_expression (parser, /*template_p=*/false,
+ /*check_dependency_p=*/true,
+ /*template_p=*/NULL,
+ /*declarator_p=*/false,
+ /*optional_p=*/false);
+ if (name == error_mark_node)
+   goto skip_comma;
 
-  decl = cp_parser_lookup_name_simple (parser, name, token->location);
-  if (decl == error_mark_node)
-   cp_parser_name_lookup_error (parser, name, decl, NLE_NULL,
-token->location);
-  else if (kind != 0)
+ decl = cp_parser_lookup_name_simple (parser, name, token->location);
+ if (decl == error_mark_node)
+   cp_parser_name_lookup_error (parser, name, decl, NLE_NULL,
+token->location);
+   }
+  if (decl != error_mark_node && kind != 0)
{
  switch (kind)
{
@@ -27958,7 +27966,7 @@ cp_parser_omp_var_list_no_open (cp_parser *parser,
  OMP_CLAUSE_CHAIN (u) = list;
  list = u;
}
-  else
+  else if (decl != error_mark_node)
list = tree_cons (decl, NULL_TREE, list);
 
 get_comma:
Index: gcc/cp/typeck.c
===
--- gcc/cp/typeck.c (revision 224232)
+++ gcc/cp/typeck.c (working copy)
@@ -6019,10 +6019,11 @@ unary_complex_lvalue (enum tree_code code, tree ar
address of it; it should not be allocated in a register.
Value is true if successful.
 
-   C++: we do not allow `current_class_ptr' to be addressable.  */
+   C++: we do not allow `current_class_ptr' to be addressable unless
+   ALLOW_THIS is true.  */
 
 bool
-cxx_mark_addressable (tree exp)
+cxx_mark_addressable (tree exp, bool allow_this)
 {
   tree x = exp;
 
@@ -6040,7 +6041,8 @@ bool
   case PARM_DECL:
if (x == current_class_ptr)
  {
-   error ("cannot take the address of %, which is an rvalue 
expression");
+   if (!allow_this)
+ error ("cannot take the address of %, which is an rvalue 
expression");
TREE_ADDRESSABLE (x) = 1; /* so compiler doesn't die later.  */
return true;
  }
@@ -6083,7 +6085,7 @@ bool
 
   case TARGET_EXPR:
TREE_ADDRESSABLE (x) = 1;
-   cxx_mark_addressable (TREE_OPERAND (x, 0));
+   cxx_mark_addressable (TREE_OPERAND (x, 0), allow_this);
return true;
 
   default:
Index: gcc/cp/cp-tree.h
===
--- gcc/cp/cp-tree.h(revision 224232)
+++ gcc/cp/cp-tree.h(working copy)
@@ -6168,7 +6168,7 @@ extern void cxx_p

Re: [gomp4] Support C++ "this" in OpenACC directives

2015-06-10 Thread Jakub Jelinek
On Wed, Jun 10, 2015 at 11:38:25AM +, Joseph Myers wrote:
> This patch, for gomp-4_0-branch, adds support for C++ "this" in
> OpenACC directives.  (This patch does not do anything to handle OpenMP
> differently from OpenACC; that - bug 66053 - will need to be resolved
> for mainline, either deciding these cases should be accepted for
> OpenMP or making the parsing only accept them in OpenACC directives
> and not OpenMP ones.)

For OpenMP 4.1, this is being considered as allowed (both alone or
supposedly in some cases also for array sections (like this[0],
this[:1] or this[0:1]) to a subset of clauses, but what exact clauses
will it be allowed on and the exact wording is a matter of hopefully next
few weeks.

Jakub


Re: Fortran's C_CHAR type

2015-06-10 Thread Mikael Morin
Le 08/06/2015 17:31, Jan Hubicka a écrit :
> Hi,
> to furhter add to the topics to discuss, I noticed that Fortran FE seems to 
> be quite
> ambivalent about C_CHAR type:
> [jh@gcc2-power8 gcc]$ cat ../b.f90
> ! This testcase will abort if C_CHAR types are not interoperable
> module lto_type_merge_test
>   use, intrinsic :: iso_c_binding
>   implicit none
> 
> contains
>   function types_test1(V) bind(c)
> USE, INTRINSIC :: ISO_C_BINDING
> CHARACTER(C_CHAR) :: types_test1
> CHARACTER(C_CHAR), VALUE :: V
> types_test1 = V
>   end function types_test1
> end module lto_type_merge_test
> 
> [jh@gcc2-power8 gcc]$ cat ../a.c
> extern unsigned char types_test1 (char v);
> void
> main ()
> { 
>   if (types_test1 ('a') != 'a')
> __builtin_abort ();
>   return 0;
> }
> 
> As my fortran-fu goes, i think this testcase is correct. Fortran FE however
> builds types_test1 as a function return char but taking the array of size of 1
> as a parameter.
C_CHAR is a named constant of value 1 (the number of bytes of a char),
and character(foo) declares a string of length foo and default kind
(which is 1 for character types).
So it is expected that the argument is an array.
If you want to declare a single character, you have to use an integer of
kind 1.
types_test1's result and v should have type integer(c_char), I think.

Mikael


Re: [PATCH] Fix PR ipa/65908.

2015-06-10 Thread Martin Liška
On 05/15/2015 08:52 PM, Jan Hubicka wrote:
>> +/* Return true if DECL_ARGUMENT types are valid to be merged.  */
> Perhaps bettter as
> 
> Perform additional check needed to match types function parameters that are
> used.  Unlike for normal parameters it matters if type is TYPE_RESTRICT and we
> make an assumption that REFERENCE_TYPE parameters are always non-NULL.
> 
>> +
>> +bool
>> +sem_function::compatible_parm_types_p ()
>> +{
>> +  tree parm1, parm2;
>> +  unsigned i = 0;
>> +
>> +  for (parm1 = DECL_ARGUMENTS (decl),
>> +   parm2 = DECL_ARGUMENTS (m_compared_func->decl);
>> +   parm1 && parm2;
>> +   parm1 = DECL_CHAIN (parm1), parm2 = DECL_CHAIN (parm2), i++)
> 
> I think this is still not right.  What you wan to to do is to have
> 
> 1) comparible_parm_types_p (t1,t2, index) that returns true if T1 and T2 are
>matching with checks bellow:
>> +  {
>> +if (!param_used_p (i))
>> +  continue;
>> +
>> +if (POINTER_TYPE_P (parm1)
>> +&& (TYPE_RESTRICT (parm1) != TYPE_RESTRICT (parm2)))
>> +  return return_false_with_msg ("argument restrict flag mismatch");
>> +/* nonnull_arg_p implies non-zero range to REFERENCE types.  */
>> +if (POINTER_TYPE_P (parm1)
>> +&& TREE_CODE (parm1) != TREE_CODE (parm2)
>> +&& opt_for_fn (decl, flag_delete_null_pointer_checks))
>> +  return return_false_with_msg ("pointer wrt reference mismatch");
>> +  }
>withtout actually walking the chain.
> 
> 2) make equals_wpa to walk TYPE_ARG_TYPES of the function type and match them.
>This is because DECL_ARGUMENTS are part of function body and before you
>read it into memory, these are NULL
> 
>Walking DECL_ARGUMENTS here may cause ipa-icf to give up in case one body 
> is
>read (and thus have some arguments) and other is not.
> 
> 3) make equals_private walk DECL_ARGUMENTS and match them
>(well at the time you populate the map.)
>You probalby can skip matching PARM_DECLS that are !parm_used_p (i)
>for anything else than types_compatible_p.
> 
>We only care they are passed the same way by ABI. Everything else is not
>relevant.
> 
> Honza
> 

Hi Honza.

I forgot a bit about the patch.
Please check updated version of the patch which can boostrap and survives
regression tests.

Martin
>From c878090a910bafec5d1f85a58ec3c3dd5dfc9564 Mon Sep 17 00:00:00 2001
From: mliska 
Date: Fri, 15 May 2015 13:23:33 +0200
Subject: [PATCH] Fix PR ipa/65908.

gcc/testsuite/ChangeLog:

2015-05-12  Martin Liska  

	* g++.dg/ipa/pr65908.C: New test.

gcc/ChangeLog:

2015-05-12  Martin Liska  

	PR ipa/65908
	* ipa-icf.c (sem_function::compatible_parm_types_p): New function.
	(sem_function::equals_wpa): Use the function.
	(sem_function::equals_private): Likewise.
	(sem_function::parse_tree_args): Handle case where we have a different
	number of arguments.
	* ipa-icf.h (sem_function::compatible_parm_types_p): Declare new
	function.
---
 gcc/ipa-icf.c  | 73 --
 gcc/ipa-icf.h  |  5 +++
 gcc/testsuite/g++.dg/ipa/pr65908.C | 27 ++
 3 files changed, 70 insertions(+), 35 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ipa/pr65908.C

diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c
index d800e1e..8a00428 100644
--- a/gcc/ipa-icf.c
+++ b/gcc/ipa-icf.c
@@ -583,6 +583,28 @@ sem_function::param_used_p (unsigned int i)
   return ipa_is_param_used (IPA_NODE_REF (get_node ()), i);
 }
 
+/* Perform additional check needed to match types function parameters that are
+used.  Unlike for normal parameters it matters if type is TYPE_RESTRICT and we
+make an assumption that REFERENCE_TYPE parameters are always non-NULL.  */
+
+bool
+sem_function::compatible_parm_types_p (tree parm1, tree parm2, unsigned index)
+{
+  if (!param_used_p (index))
+return true;
+
+if (POINTER_TYPE_P (parm1)
+	&& (TYPE_RESTRICT (parm1) != TYPE_RESTRICT (parm2)))
+  return return_false_with_msg ("argument restrict flag mismatch");
+/* nonnull_arg_p implies non-zero range to REFERENCE types.  */
+if (POINTER_TYPE_P (parm1)
+	&& TREE_CODE (parm1) != TREE_CODE (parm2)
+	&& opt_for_fn (decl, flag_delete_null_pointer_checks))
+  return return_false_with_msg ("pointer wrt reference mismatch");
+
+  return true;
+}
+
 /* Fast equality function based on knowledge known in WPA.  */
 
 bool
@@ -703,19 +725,9 @@ sem_function::equals_wpa (sem_item *item,
 	 m_compared_func->arg_types[i]))
 	return return_false_with_msg ("argument type is different");
 
-  /* On used arguments we need to do a bit more of work.  */
-  if (!param_used_p (i))
-	continue;
-  if (POINTER_TYPE_P (arg_types[i])
-	  && (TYPE_RESTRICT (arg_types[i])
-	  != TYPE_RESTRICT (m_compared_func->arg_types[i])))
-	return return_false_with_msg ("argument restrict flag mismatch");
-  /* nonnull_arg_p implies non-zero range to REFERENCE types.  */
-  if (POINTER_TYPE_P (arg_types[i])
-	  && TREE_CODE (arg_types[i])

[gomp4] Add tests for atomic read / write.

2015-06-10 Thread James Norris

Hi,

This patch adds tests for OpenACC atomic read and atomic write.


Patch applied to gomp-4_0-branch

Regards,
Jim

diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/atomic_rw-1.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/atomic_rw-1.c
new file mode 100644
index 000..ae4f22e
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/atomic_rw-1.c
@@ -0,0 +1,34 @@
+/* { dg-do run } */
+
+#include 
+
+int
+main(int argc, char **argv)
+{
+  int v1, v2;
+  int x;
+
+  x = 99;
+
+#pragma acc parallel copy (v1, v2, x)
+  {
+
+#pragma acc atomic read
+v1 = x;
+
+#pragma acc atomic write
+x = 32;
+
+#pragma acc atomic read
+v2 = x;
+
+  }
+
+  if (v1 != 99)
+abort ();
+
+  if (v2 != 32)
+abort ();
+
+  return 0;
+}


Re: [PATCH] [AArch64] PR63870 Improve error messages for NEON single lane memory access intrinsics

2015-06-10 Thread Alan Lawrence

Charles Baylis wrote:

On 8 June 2015 at 10:33, Alan Lawrence  wrote:

Thanks for working on this!

I'd been fiddling around with a patch with some similar elements to this,
but many trials with union types, subregs, etc., all worsened the register
allocation and led to more unnecessary shuffling / moves.


Kugan has been looking into this at Linaro. We should avoid
duplicating effort here.


Yes. I stopped short of looking into the internals of the register allocator, 
although I believe any proper solution is going to have to make changes here. 
However, I am working on (/nearly finished, just some tidying!) a patch series 
to add D-registers to TARGET_ARRAY_MODE_SUPPORTED_P, which may help matters.



The only real
thing I tried which you don't do here, was to introduce a set_dreg expander
to clean up some of those macro definitions in arm_neon.h. That could easily
follow in a separate patch if desired!


I'd prefer that to be a separate step.


Sure. (*If* we go that route - I hope to have another look after 
aarch64_array_mode_supported_p).


Cheers,
Alan



C++ PATCH for c++/66387 (error with lambda and constexpr array)

2015-06-10 Thread Jason Merrill
My change to rationalize the *_constant_value functions broke this 
testcase, because we were no longer replacing the reference to the array 
with its constant value.  Fixed by using maybe_constant_value instead.


Tested x86_64-pc-linux-gnu, applying to trunk.
commit 00557979b84dabd18eb7cf46cb20bed9cf9bd7f6
Author: Jason Merrill 
Date:   Fri Jun 5 16:19:11 2015 -0400

	PR c++/66387
	* semantics.c (process_outer_var_ref): Make sure the value is
	actually constant before returning it.
	* typeck.c (cp_build_array_ref): Allow subscripting non-lvalue
	array.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 650ef4c..59ec9047 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -3128,7 +3128,11 @@ process_outer_var_ref (tree decl, tsubst_flags_t complain)
 	   form, so wait until instantiation time.  */
 	return decl;
   else if (decl_constant_var_p (decl))
-	return scalar_constant_value (decl);
+	{
+	  tree t = maybe_constant_value (convert_from_reference (decl));
+	  if (TREE_CONSTANT (t))
+	return t;
+	}
 }
 
   if (parsing_nsdmi ())
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 6c4b038..5b09b73 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -3141,15 +3141,6 @@ cp_build_array_ref (location_t loc, tree array, tree idx,
 	return error_mark_node;
 	}
 
-  if (!lvalue_p (array))
-	{
-	  if (complain & tf_error)
-	pedwarn (loc, OPT_Wpedantic, 
-		 "ISO C++ forbids subscripting non-lvalue array");
-	  else
-	return error_mark_node;
-	}
-
   /* Note in C++ it is valid to subscript a `register' array, since
 	 it is valid to take the address of something with that
 	 storage specification.  */
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const5.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const5.C
new file mode 100644
index 000..cba0370
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const5.C
@@ -0,0 +1,16 @@
+// PR c++/66387
+// { dg-do compile { target c++11 } }
+
+template 
+void
+bar (T x)
+{
+  x ();
+}
+
+void
+foo ()
+{
+  constexpr int a[1] = { 1 };
+  bar ([&]{ return a[0]; });
+}


Re: [PATCH][PR debug/65549] Restore DW_AT_abstract_origin for cross-unit call sites

2015-06-10 Thread Pierre-Marie de Rodat

Thank you for your answer, Richard!

On 06/10/2015 08:58 AM, Richard Biener wrote:

Hmm, so the underlying issue is that we don't associate comp_unit_die ()
with any TRANSLATION_UNIT_DECL.


Indeed.


For the LTO early debug work I did the following at the very
beginning of dwarf2out_early_finish:

   /* Pick the first TRANSLATION_UNIT_DECL we didn't create a DIE for
  and equate it with our default CU DIE.  LTO output needs to be
  able to lookup DIEs for translation unit decls.  */
   unsigned i;
   tree decl;
   FOR_EACH_VEC_SAFE_ELT (all_translation_units, i, decl)
 if (!lookup_decl_die (decl))
   equate_decl_number_to_die (decl, comp_unit_die ());


If I understand correctly, this does not only "pick the first" (as the 
comment says) but do equate for all DIE-less units, right? Why isn't 
this hunk in mainline yet by the way?



We create some DIEs for builtin types too early before frontends
got a chance to build their TRANSLATION_UNIT_DECL, so comp_unit_die
gets created before there is any TRANSLATION_UNIT_DECL.  Another
approach would of course be that the Frontends register their main
TRANSLATION_UNIT_DECL with dwarf2out via a debug hook.

But - does the above work for you and fix the regression?  If so
adding a debug hook would probably be the cleaner solution still.


Yes it does, thanks! However we need to fix this on the 4.9 branch as 
well and this patch would need reworking to be applied there (no debug 
early). So here's a patch that introduce a 
register_main_translation_unit debug hook: is this what you had in mind? 
This works for me on the 4.9 branch and on mainline as well, regtested 
on x86_64-linux.


--
Pierre-Marie de Rodat
>From 285ea98dfdf3d45f32fc0141aa182f07d172612d Mon Sep 17 00:00:00 2001
From: Pierre-Marie de Rodat 
Date: Wed, 10 Jun 2015 10:59:40 +0200
Subject: [PATCH] Restore DW_AT_abstract_origin for cross-unit call sites

gcc/ChangeLog:
	* debug.h (struct gcc_debug_hooks): Add a
	register_main_translation_unit hook.
	* debug.c (do_nothing_debug_hooks): Provide a function for this
	new hook.
	* dbxout.c (dbx_debug_hooks): Likewise.
	* sdbout.c (sdb_debug_hooks): Likewise.
	* vmsdbgout.c (vmsdbg_debug_hooks): Likewise.
	* dwarf2out.c (main_translation_unit): New global variable.
	(dwarf2out_register_main_translation_unit): New function
	implementing the new hook.
	(dwarf2_debug_hooks): Assign
	dwarf2out_register_main_translation_unit to this new hook.
	(dwarf2out_init): Associate any main translation unit to
	comp_unit_die ().
	* c/c-decl.c (pop_scope): Register the main translation unit
	through the new debug hook.
	* cp/decl.c (cxx_init_decl_processing): Likewise.

gcc/ada/ChangeLog:
	* gcc-interface/utils.c (get_global_context): Register the main
	translation unit through the new debug hook.

gcc/fortran/ChangeLog:
	* f95-lang.c (gfc_create_decls): Register the main translation
	unit through the new debug hook.
---
 gcc/ada/gcc-interface/utils.c |  5 -
 gcc/c/c-decl.c|  1 +
 gcc/cp/decl.c |  2 ++
 gcc/dbxout.c  |  1 +
 gcc/debug.c   |  1 +
 gcc/debug.h   |  4 
 gcc/dwarf2out.c   | 27 +++
 gcc/fortran/f95-lang.c|  1 +
 gcc/sdbout.c  |  1 +
 gcc/vmsdbgout.c   |  1 +
 10 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c
index 9076529..655bfa1 100644
--- a/gcc/ada/gcc-interface/utils.c
+++ b/gcc/ada/gcc-interface/utils.c
@@ -667,7 +667,10 @@ static tree
 get_global_context (void)
 {
   if (!global_context)
-global_context = build_translation_unit_decl (NULL_TREE);
+{
+  global_context = build_translation_unit_decl (NULL_TREE);
+  debug_hooks->register_main_translation_unit (global_context);
+}
   return global_context;
 }
 
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 7fd662d..3fde22f 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -1196,6 +1196,7 @@ pop_scope (void)
 {
   tree file_decl = build_translation_unit_decl (NULL_TREE);
   context = file_decl;
+  debug_hooks->register_main_translation_unit (file_decl);
 }
   else
 context = block;
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 3bed538..ffd068a 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -3831,6 +3831,8 @@ cxx_init_decl_processing (void)
   global_namespace = build_lang_decl (NAMESPACE_DECL, global_scope_name,
   void_type_node);
   DECL_CONTEXT (global_namespace) = build_translation_unit_decl (NULL_TREE);
+  debug_hooks->register_main_translation_unit
+(DECL_CONTEXT (global_namespace));
   TREE_PUBLIC (global_namespace) = 1;
   begin_scope (sk_namespace, global_namespace);
 
diff --git a/gcc/dbxout.c b/gcc/dbxout.c
index 48b5065..94fac42 100644
--- a/gcc/dbxout.c
+++ b/gcc/dbxout.c
@@ -380,6 +380,7 @@ const struct gcc_debug_hooks dbx_debug_hooks =
   debug_nothing_tree,		 /* begin_functio

C++ PATCH for c++/66289 (ICE with alias-template)

2015-06-10 Thread Jason Merrill
My patch for DR 1558 broke this testcase: suppressing the stripping of 
alias template-ids with dependent arguments prevented us from 
recognizing that APtr is more specialized than shared_ptr.  At the 
Lenexa meeting we in Core talked about establishing a category of alias 
templates that are actually equivalent to their expansions, based 
largely on whether all the template parameters are used.  This patch 
implements that idea, and fixes the testcase.


Tested x86_64-pc-linux-gnu, applying to trunk and 5.
commit 434545f66e7c33ab7f8d9604d894c33bab9a5f1e
Author: Jason Merrill 
Date:   Fri Jun 5 18:48:24 2015 -0400

	PR c++/66289
	* pt.c (uses_all_template_parms_data, uses_all_template_parms_r)
	(complex_alias_template_p): New.
	(dependent_alias_template_spec_p): Use complex_alias_template_p.
	(dependent_type_p_r): Use dependent_alias_template_spec_p.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 2ebeb65..15dba30 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -5353,7 +5353,49 @@ alias_template_specialization_p (const_tree t)
   return false;
 }
 
-/* Return TRUE iff T is a specialization of an alias template with
+/* An alias template is complex from a SFINAE perspective if a template-id
+   using that alias can be ill-formed when the expansion is not, as with
+   the void_t template.  We determine this by checking whether the
+   expansion for the alias template uses all its template parameters.  */
+
+struct uses_all_template_parms_data
+{
+  int level;
+  bool *seen;
+};
+
+static int
+uses_all_template_parms_r (tree t, void *data_)
+{
+  struct uses_all_template_parms_data &data
+= *(struct uses_all_template_parms_data*)data_;
+  tree idx = get_template_parm_index (t);
+
+  if (TEMPLATE_PARM_LEVEL (idx) == data.level)
+data.seen[TEMPLATE_PARM_IDX (idx)] = true;
+  return 0;
+}
+
+bool
+complex_alias_template_p (const_tree tmpl)
+{
+  struct uses_all_template_parms_data data;
+  tree pat = TREE_TYPE (tmpl);
+  tree parms = DECL_TEMPLATE_PARMS (tmpl);
+  data.level = TMPL_PARMS_DEPTH (parms);
+  int len = TREE_VEC_LENGTH (INNERMOST_TEMPLATE_PARMS (parms));
+  data.seen = XALLOCAVEC (bool, len);
+  for (int i = 0; i < len; ++i)
+data.seen[i] = false;
+
+  for_each_template_parm (pat, uses_all_template_parms_r, &data, NULL, true);
+  for (int i = 0; i < len; ++i)
+if (!data.seen[i])
+  return true;
+  return false;
+}
+
+/* Return TRUE iff T is a specialization of a complex alias template with
dependent template-arguments.  */
 
 bool
@@ -5361,7 +5403,8 @@ dependent_alias_template_spec_p (const_tree t)
 {
   return (alias_template_specialization_p (t)
 	  && (any_dependent_template_arguments_p
-	  (INNERMOST_TEMPLATE_ARGS (TYPE_TI_ARGS (t);
+	  (INNERMOST_TEMPLATE_ARGS (TYPE_TI_ARGS (t
+	  && complex_alias_template_p (DECL_TI_TEMPLATE (TYPE_NAME (t;
 }
 
 /* Return the number of innermost template parameters in TMPL.  */
@@ -20951,9 +20994,7 @@ dependent_type_p_r (tree type)
 return true;
   /* For an alias template specialization, check the arguments both to the
  class template and the alias template.  */
-  else if (alias_template_specialization_p (type)
-	   && (any_dependent_template_arguments_p
-	   (INNERMOST_TEMPLATE_ARGS (TYPE_TI_ARGS (type)
+  else if (dependent_alias_template_spec_p (type))
 return true;
 
   /* All TYPEOF_TYPEs, DECLTYPE_TYPEs, and UNDERLYING_TYPEs are
diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-48.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-48.C
new file mode 100644
index 000..8d5eb23
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-48.C
@@ -0,0 +1,13 @@
+// PR c++/66289
+// { dg-do compile { target c++11 } }
+
+template struct A {};
+
+template struct shared_ptr { };
+template using APtr = shared_ptr>;
+
+template struct foo;
+template struct foo> { };
+template struct foo> { };
+
+foo>> aa;


Re: [Patch PR target/66200, target/66498, c++/66192] - Adjust aarch64_guard1.C test

2015-06-10 Thread Ramana Radhakrishnan

Bah, Now with patch attached.

Ramana

On 10/06/15 08:44, Ramana Radhakrishnan wrote:

Sorry about missing this hunk in the original submission, was in my tree
but I hadn't spotted this as I was playing between the original AArch64
TARGET_RELAXED_ORDER and this patch.

Applied as obvious.

PR target/66200
PR target/66498
PR c++/66192
* g++.dg/testsuite/aarch64_guard1.C: Adjust test.
Index: gcc/testsuite/g++.dg/abi/aarch64_guard1.C
===
--- gcc/testsuite/g++.dg/abi/aarch64_guard1.C   (revision 224311)
+++ gcc/testsuite/g++.dg/abi/aarch64_guard1.C   (working copy)
@@ -13,4 +13,4 @@
 }
 
 // { dg-final { scan-assembler _ZGVZ3foovE1x,8,8 } }
-// { dg-final { scan-tree-dump "_ZGVZ3foovE1x & 1" "original" } }
+// { dg-final { scan-tree-dump "& 1" "original" } }


Re: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-06-10 Thread Rainer Orth
"H.J. Lu"  writes:

> On Tue, May 19, 2015 at 8:33 AM, Joseph Myers  wrote:
>> On Tue, 19 May 2015, H.J. Lu wrote:
>>
>>> > I think the whole thing should be posted as one patch, with both the
>>> > target-independent changes and the target-specific changes for all
>>> > targets.
>>> >
>>>
>>> That is what makes me concerned.  I have some simple target-specified
>>> patches which weren't reviewed for years. What will happen if no one
>>
>> For any unreviewed patch, keep pinging weekly.
>>
>>> reviews some simple target-specified changes due to
>>>
>>> 1. Reviewers don't have access to those targets.
>>> 2. Target maintainers aren't review them.
>>> 3. There are no clear maintainers for those targets.
>>
>> I've already said in
>>  that, given
>> target maintainers CC:ed, I might be inclined to approve the patch on the
>> basis of allowing them a week to test their target changes.
>>
>
> Here is the complete patch.  Tested on Linux/x86-64.  It is also
> available on hjl/pie/master branch in git mirror.

I just noticed that with --enable-default-pie, while crtbeginS.o is
linked into the executable, crtend.o is used, while with an explicit
-pie, crtendS.o is taken.  Shouldn't GNU_USER_TARGET_ENDFILE_SPEC have
the same treatment as GNU_USER_TARGET_STARTFILE_SPEC already did?

* config/gnu-user.h (GNU_USER_TARGET_STARTFILE_SPEC): Use
PIE_SPEC and NO_PIE_SPEC if HAVE_LD_PIE is defined.

Rainer

-- 
-
Rainer Orth, Center for Biotechnology, Bielefeld University


Re: [PR64164] drop copyrename, integrate into expand

2015-06-10 Thread Richard Biener
On Wed, Jun 10, 2015 at 2:24 AM, Alexandre Oliva  wrote:
> On Jun  5, 2015, Alexandre Oliva  wrote:
>
>> On Apr 27, 2015, Richard Biener  wrote:
>
 +/* Return the promoted mode for name.  If it is a named SSA_NAME, it
 +   is the same as promote_decl_mode.  Otherwise, it is the promoted
 +   mode of a temp decl of same type as the SSA_NAME, if we had created
 +   one.  */
 +
 +machine_mode
 +promote_ssa_mode (const_tree name, int *punsignedp)
 +{
 +  gcc_assert (TREE_CODE (name) == SSA_NAME);
 +
 +  if (SSA_NAME_VAR (name))
 +return promote_decl_mode (SSA_NAME_VAR (name), punsignedp);
>
>>> As above I'd rather not have different paths for anonymous vs. non-anonymous
>>> vars (so just delete the above two lines).
>
>> Check
>
> This caused the sparc regression reported by Eric in
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64164#c37
>
> We need to match the mode of the rtl created for the partition and the
> promoted mode expected for the parm.  I recall working to make parm and
> result decls the partition leaders, so that promote_ssa_mode would DTRT,
> but this escaped my mind when revisiting the patch after some time on
> another project.
>
> So we either restore promote_ssa_mode's check for an underlying decl, at
> least for PARM_ and RESULT_DECLs, or further massage function.c to deal
> with the mode difference.  Any preference?

Alternatively not coalesce SSA names when promote_decl_mode gives
different answers (for their underlying decl)?  It sounds wrong to do that
(if that is really what happens).

Richard.

> I'm reverting the patch for now, so that we don't have to rush to a fix
> on this, and I can have more time to test and fix other arches.  It was
> a terrible mistake to not do so before submitting the final version of
> the patch, or at least before installing it.  I apologize for that.
>
> --
> Alexandre Oliva, freedom fighterhttp://FSFLA.org/~lxoliva/
> You must be the change you wish to see in the world. -- Gandhi
> Be Free! -- http://FSFLA.org/   FSF Latin America board member
> Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer


Re: [PATCH][PR debug/65549] Restore DW_AT_abstract_origin for cross-unit call sites

2015-06-10 Thread Richard Biener
On Wed, 10 Jun 2015, Pierre-Marie de Rodat wrote:

> Thank you for your answer, Richard!
> 
> On 06/10/2015 08:58 AM, Richard Biener wrote:
> > Hmm, so the underlying issue is that we don't associate comp_unit_die ()
> > with any TRANSLATION_UNIT_DECL.
> 
> Indeed.
> 
> > For the LTO early debug work I did the following at the very
> > beginning of dwarf2out_early_finish:
> > 
> >/* Pick the first TRANSLATION_UNIT_DECL we didn't create a DIE for
> >   and equate it with our default CU DIE.  LTO output needs to be
> >   able to lookup DIEs for translation unit decls.  */
> >unsigned i;
> >tree decl;
> >FOR_EACH_VEC_SAFE_ELT (all_translation_units, i, decl)
> >  if (!lookup_decl_die (decl))
> >equate_decl_number_to_die (decl, comp_unit_die ());
> 
> If I understand correctly, this does not only "pick the first" (as the comment
> says) but do equate for all DIE-less units, right? Why isn't this hunk in
> mainline yet by the way?

Hmm, yes.  It meant to break after the first ;)  (without LTO
there usually is only one TU decl, apart from Java I think).
The hunk isn't in mainline because it was part of an experimental patch I 
did on the early-debug branch.

> 
> > We create some DIEs for builtin types too early before frontends
> > got a chance to build their TRANSLATION_UNIT_DECL, so comp_unit_die
> > gets created before there is any TRANSLATION_UNIT_DECL.  Another
> > approach would of course be that the Frontends register their main
> > TRANSLATION_UNIT_DECL with dwarf2out via a debug hook.
> > 
> > But - does the above work for you and fix the regression?  If so
> > adding a debug hook would probably be the cleaner solution still.
> 
> Yes it does, thanks! However we need to fix this on the 4.9 branch as well and
> this patch would need reworking to be applied there (no debug early). So
> here's a patch that introduce a register_main_translation_unit debug hook: is
> this what you had in mind? This works for me on the 4.9 branch and on mainline
> as well, regtested on x86_64-linux.

Yeah, that looks great!

Of course I wonder about Java (builds multiple ones, one for each
input file) and Go (no idea).  I suppose Java would need to build
another one where all the "defaults" go (or it doesn't have any
such entities).

In theory we could have changed dwarf2out_init to get a
translation-unit-decl argument as well.  But your patch looks like
we don't have such at the point of dwarf2out_init in all frontends.

Your patch is ok (and ok to backport) IMHO, though please give
others the chance to chime in.

Thanks,
Richard.


[PING] Vector ABI attribute

2015-06-10 Thread Andreas Krebbel
Hi,

any ideas how this could be improved:
https://gcc.gnu.org/ml/gcc-patches/2015-05/msg00924.html

Bye,

-Andreas-



[PATCH][RFC] Add FRE in pass_vectorize

2015-06-10 Thread Richard Biener

The following patch adds FRE after vectorization which is needed
for IVOPTs to remove redundant PHI nodes (well, I'm testing a
patch for FRE that will do it already there).

The patch also makes FRE preserve loop-closed SSA form and thus
make it suitable for use in the loop pipeline.

With the placement in the vectorizer sub-pass FRE will effectively
be enabled by -O3 only (well, or if one requests loop vectorization).
I've considered placing it after complete_unroll instead but that
would enable it at -O1 already.  I have no strong opinion on the
exact placement, but it should help all passes between vectorizing
and ivopts for vectorized loops.

Yeah, it adds yet another pass and thus I don't like it very much.
But it for example improves code generated for
gfortran.dg/vect/fast-math-pr37021.f90
from

.L14:
movupd  (%r11), %xmm3
addl$1, %ecx
addq%rax, %r11
movupd  (%r8), %xmm0
addq%rax, %r8
unpckhpd%xmm3, %xmm3
movupd  (%rdi), %xmm2
unpcklpd%xmm0, %xmm0
addq%rsi, %rdi
movupd  (%rbx), %xmm1
mulpd   %xmm3, %xmm2
addq%rsi, %rbx
cmpl%ecx, %ebp
palignr $8, %xmm1, %xmm1
mulpd   %xmm1, %xmm0
movapd  %xmm2, %xmm1
addpd   %xmm0, %xmm1
subpd   %xmm2, %xmm0
shufpd  $2, %xmm0, %xmm1
addpd   %xmm1, %xmm4
jne .L14

to

.L14:
movupd  (%r8), %xmm0
addl$1, %ecx
addq%rax, %r8
movapd  %xmm0, %xmm2
movupd  (%rdi), %xmm1
addq%rsi, %rdi
cmpl%ecx, %r11d
unpckhpd%xmm0, %xmm2
unpcklpd%xmm0, %xmm0
mulpd   %xmm1, %xmm2
palignr $8, %xmm1, %xmm1
mulpd   %xmm1, %xmm0
movapd  %xmm2, %xmm1
addpd   %xmm0, %xmm1
subpd   %xmm2, %xmm0
shufpd  $2, %xmm0, %xmm1
addpd   %xmm1, %xmm3
jne .L14

(yeah, the vectorizer happily generates redundant loads and one IV
for each such load)

Any other suggestions on pass placement?  I can of course key
that FRE run on -O3 explicitely.  Not sure if we at this point
want to start playing fancy games like setting a property
when a pass (likely) generated redundancies that are worth
fixing up and then key FRE on that one (it gets harder and
less predictable what transforms are run on code).

Bootstrap / regtest running on x86_64-unknown-linux-gnu.  With
other placements I'd expect quite some testsuite fallout
eventually.

Thoughts?

Thanks,
Richard.

2015-06-10  Richard Biener  

* passes.def (pass_vectorize): Add pass_fre.
* tree-ssa-pre.c (eliminate_dom_walker::before_dom_children):
Preserve loop-closed SSA form.

Index: gcc/passes.def
===
*** gcc/passes.def  (revision 224324)
--- gcc/passes.def  (working copy)
*** along with GCC; see the file COPYING3.
*** 252,257 
--- 252,258 
 Please do not add any other passes in between.  */
  NEXT_PASS (pass_vectorize);
PUSH_INSERT_PASSES_WITHIN (pass_vectorize)
+ NEXT_PASS (pass_fre);
  NEXT_PASS (pass_dce);
POP_INSERT_PASSES ()
NEXT_PASS (pass_predcom);
Index: gcc/tree-ssa-pre.c
===
*** gcc/tree-ssa-pre.c  (revision 224324)
--- gcc/tree-ssa-pre.c  (working copy)
*** eliminate_dom_walker::before_dom_childre
*** 4013,4018 
--- 4013,4028 
   tailmerging.  Eventually we can reduce its reliance on SCCVN now
   that we fully copy/constant-propagate (most) things.  */
  
+   /* Compute whether this block has loop-closed PHI nodes we need
+  to preserve.  */
+   bool lc_phi = false;
+   edge e;
+   if (loops_state_satisfies_p (LOOP_CLOSED_SSA)
+   && single_pred_p (b)
+   && (e = single_pred_edge (b))
+   && loop_exit_edge_p (e->src->loop_father, e))
+ lc_phi = true;
+ 
for (gphi_iterator gsi = gsi_start_phis (b); !gsi_end_p (gsi);)
  {
gphi *phi = gsi.phi ();
*** eliminate_dom_walker::before_dom_childre
*** 4026,4032 
  
tree sprime = eliminate_avail (res);
if (sprime
! && sprime != res)
{
  if (dump_file && (dump_flags & TDF_DETAILS))
{
--- 4036,4043 
  
tree sprime = eliminate_avail (res);
if (sprime
! && sprime != res
! && !lc_phi)
{
  if (dump_file && (dump_flags & TDF_DETAILS))
{
*** eliminate_dom_walker::before_dom_childre
*** 4466,4472 
  
/* Replace destination PHI arguments.  */
edge_iterator ei;
-   edge e;
FOR_EACH_EDGE (e, ei, b->succs)
  {
for (gphi_iterator gsi = gsi_start_phis (e->dest);
--- 4477,4482 


[PATCH] Fix SCCVN to optimistically value-number PHIs with backedges

2015-06-10 Thread Richard Biener

The following patch fixes a preference that causes SCCVN to fail to
eliminate redundant IVs.  It will prefer to try eliminating IVs to
eliminating degenerate PHIs (if the degenerate PHI has a backedge).
I failed to create a testcase for that - the one below is essentially
what the vectorizer can end up generating (bah).  I believe it
will still work out in the end, just FRE itself won't remove the
PHI node in a single pass iteration but just value-number to
a degenerate PHI (a testcase would still be nice - I'm still trying).

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

Richard.

2015-06-10  Richard Biener  

* tree-ssa-sccvn.c (vn_phi_compute_hash): Do not include
backedge arguments.
(vn_phi_lookup): Adjust.
(vn_phi_insert): Likewise.
(visit_phi): Prefer to value-number to another PHI node
over value-numbering to a PHI argument.
(init_scc_vn): Mark DFS back edges.

* gcc.dg/tree-ssa/ssa-fre-46.c: New testcase.

Index: gcc/tree-ssa-sccvn.c
===
--- gcc/tree-ssa-sccvn.c(revision 224324)
+++ gcc/tree-ssa-sccvn.c(working copy)
@@ -2682,17 +2679,24 @@ static inline hashval_t
 vn_phi_compute_hash (vn_phi_t vp1)
 {
   inchash::hash hstate (vp1->block->index);
-  int i;
   tree phi1op;
   tree type;
+  edge e;
+  edge_iterator ei;
 
   /* If all PHI arguments are constants we need to distinguish
  the PHI node via its type.  */
   type = vp1->type;
   hstate.merge_hash (vn_hash_type (type));
 
-  FOR_EACH_VEC_ELT (vp1->phiargs, i, phi1op)
+  FOR_EACH_EDGE (e, ei, vp1->block->preds)
 {
+  /* Don't hash backedge values they need to be handled as VN_TOP
+ for optimistic value-numbering.  */
+  if (e->flags & EDGE_DFS_BACK)
+   continue;
+
+  phi1op = vp1->phiargs[e->dest_idx];
   if (phi1op == VN_TOP)
continue;
   inchash::add_expr (phi1op, hstate);
@@ -2745,16 +2749,18 @@ vn_phi_lookup (gimple phi)
 {
   vn_phi_s **slot;
   struct vn_phi_s vp1;
-  unsigned i;
+  edge e;
+  edge_iterator ei;
 
   shared_lookup_phiargs.truncate (0);
+  shared_lookup_phiargs.safe_grow (gimple_phi_num_args (phi));
 
   /* Canonicalize the SSA_NAME's to their value number.  */
-  for (i = 0; i < gimple_phi_num_args (phi); i++)
+  FOR_EACH_EDGE (e, ei, gimple_bb (phi)->preds)
 {
-  tree def = PHI_ARG_DEF (phi, i);
+  tree def = PHI_ARG_DEF_FROM_EDGE (phi, e);
   def = TREE_CODE (def) == SSA_NAME ? SSA_VAL (def) : def;
-  shared_lookup_phiargs.safe_push (def);
+  shared_lookup_phiargs[e->dest_idx] = def;
 }
   vp1.type = TREE_TYPE (gimple_phi_result (phi));
   vp1.phiargs = shared_lookup_phiargs;
@@ -2778,15 +2784,18 @@ vn_phi_insert (gimple phi, tree result)
 {
   vn_phi_s **slot;
   vn_phi_t vp1 = current_info->phis_pool->allocate ();
-  unsigned i;
   vec args = vNULL;
+  edge e;
+  edge_iterator ei;
+
+  args.safe_grow (gimple_phi_num_args (phi));
 
   /* Canonicalize the SSA_NAME's to their value number.  */
-  for (i = 0; i < gimple_phi_num_args (phi); i++)
+  FOR_EACH_EDGE (e, ei, gimple_bb (phi)->preds)
 {
-  tree def = PHI_ARG_DEF (phi, i);
+  tree def = PHI_ARG_DEF_FROM_EDGE (phi, e);
   def = TREE_CODE (def) == SSA_NAME ? SSA_VAL (def) : def;
-  args.safe_push (def);
+  args[e->dest_idx] = def;
 }
   vp1->value_id = VN_INFO (result)->value_id;
   vp1->type = TREE_TYPE (gimple_phi_result (phi));
@@ -3284,15 +3293,14 @@ visit_phi (gimple phi)
  }
   }
 
-  /* If all value numbered to the same value, the phi node has that
- value.  */
-  if (allsame)
-return set_ssa_val_to (PHI_RESULT (phi), sameval);
-
   /* Otherwise, see if it is equivalent to a phi node in this block.  */
   result = vn_phi_lookup (phi);
   if (result)
 changed = set_ssa_val_to (PHI_RESULT (phi), result);
+  /* If all value numbered to the same value, the phi node has that
+ value.  */
+  else if (allsame)
+changed = set_ssa_val_to (PHI_RESULT (phi), sameval);
   else
 {
   vn_phi_insert (phi, PHI_RESULT (phi));
@@ -4182,6 +4190,8 @@ init_scc_vn (void)
   int *rpo_numbers_temp;
 
   calculate_dominance_info (CDI_DOMINATORS);
+  mark_dfs_back_edges ();
+
   sccstack.create (0);
   constant_to_value_id = new hash_table (23);
 
Index: gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-46.c
===
--- gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-46.c  (revision 0)
+++ gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-46.c  (working copy)
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-fre1-details" } */
+
+int x[1024];
+int foo (int a, int s, unsigned int k)
+{
+  int i = a, j = a;
+  int sum = 0;
+  do
+{
+  sum += x[i];
+  sum += x[j];
+  i += s;
+  j += s;
+}
+  while (k--);
+  return sum;
+}
+
+/* We want to remove the redundant induction variable and thus its PHI node.  
*/
+
+/

Re: [PATCH][PR debug/65549] Restore DW_AT_abstract_origin for cross-unit call sites

2015-06-10 Thread Pierre-Marie de Rodat

On 06/10/2015 03:36 PM, Richard Biener wrote:

Hmm, yes.  It meant to break after the first ;)  (without LTO
there usually is only one TU decl, apart from Java I think).
The hunk isn't in mainline because it was part of an experimental patch I
did on the early-debug branch.


Understood, thanks!


Yeah, that looks great!

Of course I wonder about Java (builds multiple ones, one for each
input file) and Go (no idea).  I suppose Java would need to build
another one where all the "defaults" go (or it doesn't have any
such entities).


Yeah, I'm not familiar with them neither...


In theory we could have changed dwarf2out_init to get a
translation-unit-decl argument as well.  But your patch looks like
we don't have such at the point of dwarf2out_init in all frontends.

Your patch is ok (and ok to backport) IMHO, though please give
others the chance to chime in.


Thank you very much. :-) I will soon become unavailable until July, so I 
think I'll wait until then to commit anyway.


--
Pierre-Marie de Rodat


Re: [PATCH] Fix SCCVN to optimistically value-number PHIs with backedges

2015-06-10 Thread Richard Biener
On Wed, 10 Jun 2015, Richard Biener wrote:

> 
> The following patch fixes a preference that causes SCCVN to fail to
> eliminate redundant IVs.  It will prefer to try eliminating IVs to
> eliminating degenerate PHIs (if the degenerate PHI has a backedge).
> I failed to create a testcase for that - the one below is essentially
> what the vectorizer can end up generating (bah).  I believe it
> will still work out in the end, just FRE itself won't remove the
> PHI node in a single pass iteration but just value-number to
> a degenerate PHI (a testcase would still be nice - I'm still trying).

Just to explain, I'm thinking of the case where optimistically
value-numbering to the first arg is required to make SCCVN
realize the 2nd arg is the same.  Like

int foo (int a, int s, unsigned int k)
{
  int i = a, j = a;
  do
{
  i += s;
  j += j;
  j -= a;
}
  while (k--);
  return j+i;
}

(heh, depends on the order of i and j declarations!)

In the above case SCCVN doesn't do anything after the patch
but before we eliminate j in the return statement to a.

I wonder what the theory(TM) says about the two cases
(that is, how to catch both).

Richard.


Re: [PATCH v2] xtensa: implement trap pattern

2015-06-10 Thread augustine.sterl...@gmail.com
On Tue, Jun 9, 2015 at 3:14 PM, Max Filippov  wrote:
> gcc/
> * config/xtensa/xtensa.h (TARGET_DEBUG): New definition.
> * config/xtensa/xtensa.md (define_attr "type"): New type "trap".
> (define_insn "trap"): New definition.
> ---
> Changes v1->v2:
> - drop break.n, replace break 0, 0 with break 1, 15, coded breakpoint
>   that transfers control to debugger if present.

This is OK for xtensa. Please apply.


Re: Fortran's C_CHAR type

2015-06-10 Thread Jan Hubicka
> > [jh@gcc2-power8 gcc]$ cat ../b.f90
> > ! This testcase will abort if C_CHAR types are not interoperable
> > module lto_type_merge_test
> >   use, intrinsic :: iso_c_binding
> >   implicit none
> > 
> > contains
> >   function types_test1(V) bind(c)
> > USE, INTRINSIC :: ISO_C_BINDING
> > CHARACTER(C_CHAR) :: types_test1
> > CHARACTER(C_CHAR), VALUE :: V
> > types_test1 = V
> >   end function types_test1
> > end module lto_type_merge_test
> > 
> > [jh@gcc2-power8 gcc]$ cat ../a.c
> > extern unsigned char types_test1 (char v);
> > void
> > main ()
> > { 
> >   if (types_test1 ('a') != 'a')
> > __builtin_abort ();
> >   return 0;
> > }
> > 
> > As my fortran-fu goes, i think this testcase is correct. Fortran FE however
> > builds types_test1 as a function return char but taking the array of size 
> > of 1
> > as a parameter.
> C_CHAR is a named constant of value 1 (the number of bytes of a char),
> and character(foo) declares a string of length foo and default kind
> (which is 1 for character types).
> So it is expected that the argument is an array.

I see, what is the reason for assymetry for return value to not be array in 
this case?

> If you want to declare a single character, you have to use an integer of
> kind 1.
> types_test1's result and v should have type integer(c_char), I think.

I will fix the testcase accordingly.  I basicallly copied what is in table
15.2 of the Fortran 2008 draft that explicitely lists Fortran type CHARACTER
if kind C_CHAR compatible with "char". On the other hand there are no examples
in the standard that would suggest that this should work this way.
It only shows stuff like
 CHARACTER(KIND=C_CHAR), DIMENSION(*) :: IN, OUT
which corresponds to char []

Is my testcase supposed to work if I simply add KIND= before "C_CHAR"

If you can look at the other c-bind testcases I produced, I would really 
appreachiate that.
Honza
> 
> Mikael


Re: [PATCH] Move gen_* stubs from defaults.h to genflags

2015-06-10 Thread Trevor Saunders
On Wed, Jun 10, 2015 at 07:28:10AM +0300, Mikhail Maltsev wrote:
> Hi, all.
> 
> I noticed that defaults.h file contains stub generator functions which
> simply call gcc_unreachable. FWIW, Trevor added them to remove some
> conditional compilation which depends on HAVE_ macros (I mean
> something like r223624).
> 
> Because we still have ~80 more such conditions in GCC, and probably some
> of them will be fixed in the same way, I propose a patch, which allows
> to generate required stubs in genflags.

yeah, I've been meaning to do this, thanks for taking care of it.  My
plan had been to do it after all the defaults had been added, but if you
can do it now great.

See https://github.com/tbsaunde/gcc/tree/ifdef for the patches I have in
this area, unfortunately I don't expect to commit any of that till july
when I get back from travel.

> diff --git a/gcc/genflags.c b/gcc/genflags.c
> index 0da15f1..2a70b56 100644
> --- a/gcc/genflags.c
> +++ b/gcc/genflags.c
> @@ -26,10 +26,65 @@ along with GCC; see the file COPYING3.  If not see
>  #include "tm.h"
>  #include "rtl.h"
>  #include "obstack.h"
> +#include "hash-map.h"
>  #include "errors.h"
>  #include "read-md.h"
>  #include "gensupport.h"
>  
> +/* Structure which holds data, required for generating stub gen_* function.  
> */
> +struct stub_info_t
> +{
> +  /* Instruction name.  */
> +  const char *name;
> +  /* Number of arguments (i.e., instruction operands).  */
> +  int opno;

unsigned?

> +  /* Set to true when generator is output, so no stub is needed.  */
> +  bool done;
> +};
> +
> +/* These instructions require default stub function.  Stubs are never called.

are the ones that don't call gcc_unreachable () called?

> +/* Print out a dummy for generator for instruction NAME with NUM arguments
> +   which either does nothing, or aborts (depending on UNREACHABLE).  */

I believe you should drop the first "for" in this sentence.

Trev


Re: [PATCH v2] xtensa: implement trap pattern

2015-06-10 Thread Max Filippov
On Wed, Jun 10, 2015 at 5:37 PM, augustine.sterl...@gmail.com
 wrote:
> On Tue, Jun 9, 2015 at 3:14 PM, Max Filippov  wrote:
>> gcc/
>> * config/xtensa/xtensa.h (TARGET_DEBUG): New definition.
>> * config/xtensa/xtensa.md (define_attr "type"): New type "trap".
>> (define_insn "trap"): New definition.
>> ---
>> Changes v1->v2:
>> - drop break.n, replace break 0, 0 with break 1, 15, coded breakpoint
>>   that transfers control to debugger if present.
>
> This is OK for xtensa. Please apply.

Applied to trunk. Thanks!

-- Max


[PATCH 00/17] RFC: Addding a unit testing framework to gcc

2015-06-10 Thread David Malcolm
Our current test suite is rather coarse-grained, acting at the level
of running gcc subprocesses, and verifying externally-visible
properties:
  - Did the compile succeed?
  - Was a particular dumpfile emitted, containing something matching
some regex?
  - Does the generated code run and exit gracefully?
etc

The strength of this approach is that we have good "integration"
coverage: we know that the compiler runs and generates good code.
However it's slow, and doesn't allow very precise control over what
properties we can assert.

The following patch kit adds a suite of unit tests to gcc, aimed at
giving test coverage for properties that are difficult to test for
in the current system.  For example, there are tests of ggc to
verify that gengtype is doing sane things, of various container
classes (vec, hash_map, hash_set) and of wide-int.  Some of the
tests are rather "placeholdery" e.g. the tests of folding trees,
where there's plenty of room for adding new testcases.

I've split them up into multiple patches for ease of review, but
they all stand together.

I picked the Google Test framework:
  http://code.google.com/p/googletest/

I didn't do a very thorough survey of C++ test frameworks; I picked
this one as it's used by several very large projects (including
LLVM [1]), and is actively maintained.  Working with it has largely been
a pleasant experience: it generates good error messages when tests
fail (e.g. with enough information so that I can click on failures
in Emacs and have it go to the failing test), and is sane to work
with in gdb.  The log is easy to read; I've added an example to
the end of this mail.  It supports parameterizing testcases across
multiple types (I use this for testing wide-int).

The only other "framework" I've used has been the DejaGnu unittest
header, which I use for the jit testsuite; I can't recommend it (it's
a pain to use, and I've had to extend it repeatedly to get basic
functionality like string equality assertions).

The testsuite is intended to be very fast, all in one process, and it
takes less than a second to run; it fact, the time is dominated by a
single very slow test, which takes 300-400ms to run, but which could
be sped up [2]; other than that, it takes about 10ms to run.

Structurally, the patches add a "unittests" frontend: this is rather
analogous to libgccjit.so: it's a dummy frontend.  The
unittests/Make-lang.in builds a libgccunittests.so, which does
nothing, stubbing out the frontend hooks, but provides a DSO holding
the code to be tested.

libgccunittests.so is then linked into a "unittests.exe" binary, which
holds the actual testcases.  An advantage of this separation is that
although linking libgccunittests.so is rather slow (like linking "cc1"
etc), unittests.exe is very fast to link, so that it's very fast to
hack on individual tests without needing to relink "everything" for
each edit.

Of course, this means that we can't unittest the real frontends this
way (but we couldn't before, and maybe we can find a route to doing
this).

I have the Make-lang.in implementing the "unittests" target so that
it builds and *runs* the unit tests i.e. if you do a "make", the
unittests are run (rather than just on a "make check").  Given how
fast they are (especially relative to "make check", the only issue
I can see with this is the output log spew).  One nice thing about
doing it there is that it can be run at each stage of a bootstrap,
so hopefully we fail earlier when we're going to fail.

I marked it in config-lang.in as
  build_by_default="no"
so you have to opt-in to building it by adding "unittests" to the
  --enable-languages=
configure options.

The split of the bulk of the link into a libgccjitunittests.so
means that it also requires the
  --enable-host-shared
configure-time option.

It doesn't yet bootstrap; the link fails with:
test-folding.o: In function `testing::AssertionResult 
testing::internal::CmpHelperNE(char const*, char 
const*, tree_node* const&, tree_node* const&)':
test-folding.c:(.text._ZN7testing8internal11CmpHelperNEIP9tree_nodeS3_EENS_15AssertionResultEPKcS6_RKT_RKT0_[_ZN7testing8internal11CmpHelperNEIP9tree_nodeS3_EENS_15AssertionResultEPKcS6_RKT_RKT0_]+0x26e):
 undefined reference to 
`testing::internal::StringStreamToString(std::__cxx11::basic_stringstream, std::allocator >*)'

though this was using a system copy of gtest
(is this due to the C++ stdlib ABI change?  it seems to only affect
tests using EXPECT_STREQ, and if I hack them out, it seems to work).
(perhaps we'd need to bundle our own copy of gtest?)

Here's a sample log (and it's sanely color-coded if you run it at
a tty):

$ make unittests
[==] Running 56 tests from 16 test cases.
[--] Global test environment set-up.
[--] 6 tests from ggc_test
[ RUN  ] ggc_test.tree_marking
[   OK ] ggc_test.tree_marking (0 ms)
[ RUN  ] ggc_test.custom_struct
[   OK ] ggc_test.custom_struct (0 ms)
[ RUN  ] ggc_test.finalization
[   OK ] 

[PATCH 02/17] Add test-bitmap.c to gcc/unittests

2015-06-10 Thread David Malcolm
gcc/unittests/ChangeLog:
* test-bitmap.c: New file.
---
 gcc/unittests/test-bitmap.c | 117 
 1 file changed, 117 insertions(+)
 create mode 100644 gcc/unittests/test-bitmap.c

diff --git a/gcc/unittests/test-bitmap.c b/gcc/unittests/test-bitmap.c
new file mode 100644
index 000..38adff3
--- /dev/null
+++ b/gcc/unittests/test-bitmap.c
@@ -0,0 +1,117 @@
+/* Unit tests for GCC's bitmap-handling.
+   Copyright (C) 2015 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include 
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "opts.h"
+#include "bitmap.h"
+
+namespace {
+
+/* Freshly-created bitmaps ought to be empty.  */
+
+TEST (bitmap_test, gc_alloc)
+{
+  bitmap b = bitmap_gc_alloc ();
+  EXPECT_TRUE (bitmap_empty_p (b));
+}
+
+/* Verify bitmap_set_range.  */
+
+TEST (bitmap_test, set_range)
+{
+  bitmap b = bitmap_gc_alloc ();
+  EXPECT_TRUE (bitmap_empty_p (b));
+
+  bitmap_set_range (b, 7, 5);
+  EXPECT_FALSE (bitmap_empty_p (b));
+  EXPECT_EQ (5, bitmap_count_bits (b));
+
+  /* Verify bitmap_bit_p at the boundaries.  */
+  EXPECT_FALSE (bitmap_bit_p (b, 6));
+  EXPECT_TRUE (bitmap_bit_p (b, 7));
+  EXPECT_TRUE (bitmap_bit_p (b, 11));
+  EXPECT_FALSE (bitmap_bit_p (b, 12));
+}
+
+/* Verify splitting a range into two pieces using bitmap_clear_bit.  */
+
+TEST (bitmap_test, clear_bit_in_middle)
+{
+  bitmap b = bitmap_gc_alloc ();
+
+  /* Set b to [100..200].  */
+  bitmap_set_range (b, 100, 100);
+  EXPECT_EQ (100, bitmap_count_bits (b));
+
+  /* Clear a bit in the middle.  */
+  bool changed = bitmap_clear_bit (b, 150);
+  EXPECT_TRUE (changed);
+  EXPECT_EQ (99, bitmap_count_bits (b));
+  EXPECT_TRUE (bitmap_bit_p (b, 149));
+  EXPECT_FALSE (bitmap_bit_p (b, 150));
+  EXPECT_TRUE (bitmap_bit_p (b, 151));
+}
+
+/* Verify bitmap_copy.  */
+
+TEST (bitmap_test, copying)
+{
+  bitmap src = bitmap_gc_alloc ();
+  bitmap_set_range (src, 40, 10);
+
+  bitmap dst = bitmap_gc_alloc ();
+  EXPECT_FALSE (bitmap_equal_p (src, dst));
+  bitmap_copy (dst, src);
+  EXPECT_TRUE (bitmap_equal_p (src, dst));
+
+  /* Verify that we can make them unequal again...  */
+  bitmap_set_range (src, 70, 5);
+  EXPECT_FALSE (bitmap_equal_p (src, dst));
+
+  /* ...and that changing src after the copy didn't affect
+ the other: */
+  EXPECT_FALSE (bitmap_bit_p (dst, 70));
+}
+
+/* Verify bitmap_single_bit_set_p.  */
+TEST (bitmap_test, bitmap_single_bit_set_p)
+{
+  bitmap b = bitmap_gc_alloc ();
+
+  EXPECT_FALSE (bitmap_single_bit_set_p (b));
+
+  bitmap_set_range (b, 42, 1);
+  EXPECT_TRUE (bitmap_single_bit_set_p (b));
+  EXPECT_EQ (42, bitmap_first_set_bit (b));
+
+  bitmap_set_range (b, 1066, 1);
+  EXPECT_FALSE (bitmap_single_bit_set_p (b));
+  EXPECT_EQ (42, bitmap_first_set_bit (b));
+
+  bitmap_clear_range (b, 0, 100);
+  EXPECT_TRUE (bitmap_single_bit_set_p (b));
+  EXPECT_EQ (1066, bitmap_first_set_bit (b));
+}
+
+}  // anon namespace
-- 
1.8.5.3



[PATCH 01/17] Add Make-lang.in and config-lang.in to gcc/unittests

2015-06-10 Thread David Malcolm
gcc/unittests/ChangeLog:
* Make-lang.in: New file.
* config-lang.in: New file.
---
 gcc/unittests/Make-lang.in   | 200 +++
 gcc/unittests/config-lang.in |  34 
 2 files changed, 234 insertions(+)
 create mode 100644 gcc/unittests/Make-lang.in
 create mode 100644 gcc/unittests/config-lang.in

diff --git a/gcc/unittests/Make-lang.in b/gcc/unittests/Make-lang.in
new file mode 100644
index 000..50d6e4f
--- /dev/null
+++ b/gcc/unittests/Make-lang.in
@@ -0,0 +1,200 @@
+# Top level -*- makefile -*- fragment for unittests.
+#   Copyright (C) 2013-2015 Free Software Foundation, Inc.
+
+#This file is part of GCC.
+
+#GCC is free software; you can redistribute it and/or modify
+#it under the terms of the GNU General Public License as published by
+#the Free Software Foundation; either version 3, or (at your option)
+#any later version.
+
+#GCC is distributed in the hope that it will be useful,
+#but WITHOUT ANY WARRANTY; without even the implied warranty of
+#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# .
+
+# This file provides the language dependent support in the main Makefile.
+# Each language makefile fragment must provide the following targets:
+#
+# foo.all.cross, foo.start.encap, foo.rest.encap,
+# foo.install-common, foo.install-man, foo.install-info, foo.install-pdf,
+# foo.install-html, foo.info, foo.dvi, foo.pdf, foo.html, foo.uninstall,
+# foo.mostlyclean, foo.clean, foo.distclean,
+# foo.maintainer-clean, foo.stage1, foo.stage2, foo.stage3, foo.stage4
+#
+# where `foo' is the name of the language.
+#
+# It should also provide rules for:
+#
+# - making any compiler driver (eg: g++)
+# - the compiler proper (eg: cc1plus)
+# - define the names for selecting the language in LANGUAGES.
+
+#
+# Define the names for selecting unittests in LANGUAGES.
+# Note that it would be nice to move the dependency on g++
+# into the unittests rule, but that needs a little bit of work
+# to do the right thing within all.cross.
+
+LIBGCCUNITTESTS_LINKER_NAME = libgccunittests.so
+LIBGCCUNITTESTS_VERSION_NUM = 0
+LIBGCCUNITTESTS_MINOR_NUM = 0
+LIBGCCUNITTESTS_RELEASE_NUM = 1
+LIBGCCUNITTESTS_SONAME = 
$(LIBGCCUNITTESTS_LINKER_NAME).$(LIBGCCUNITTESTS_VERSION_NUM)
+LIBGCCUNITTESTS_FILENAME = \
+  
$(LIBGCCUNITTESTS_SONAME).$(LIBGCCUNITTESTS_MINOR_NUM).$(LIBGCCUNITTESTS_RELEASE_NUM)
+
+LIBGCCUNITTESTS_LINKER_NAME_SYMLINK = $(LIBGCCUNITTESTS_LINKER_NAME)
+LIBGCCUNITTESTS_SONAME_SYMLINK = $(LIBGCCUNITTESTS_SONAME)
+
+TESTPROGRAMS = unittests.exe
+
+RUN_TESTPROGRAMS = run-unittests.exe
+
+unittests: $(LIBGCCUNITTESTS_FILENAME) \
+   $(LIBGCCUNITTESTS_SYMLINK) \
+   $(LIBGCCUNITTESTS_LINKER_NAME_SYMLINK) \
+   $(FULL_DRIVER_NAME) \
+   $(TESTPROGRAMS) \
+   $(RUN_TESTPROGRAMS)
+
+# Tell GNU make to ignore these if they exist.
+.PHONY: unittests $(RUN_TESTPROGRAMS)
+
+# "Frontend" objects, which go into libgccunittests.so
+unittests_OBJS = attribs.o \
+   unittests/unittests-frontend.o
+
+# Build various files against gtest
+
+# Files that are linked into unittests.exe
+UNITTESTS_EXE_OBJS = \
+   test-bitmap.o \
+   test-cfg.o \
+   test-folding.o \
+   test-functions.o \
+   test-gimple.o \
+   test-hash-map.o \
+   test-hash-set.o \
+   test-locations.o \
+   test-rtl.o \
+   test-tree.o \
+   test-vec.o \
+   test-wide-int.o \
+   unittests-main.o
+
+# Files to be built against gtest
+# test-ggc.o has to be linked in to libgccunittests.so
+OBJS_BUILT_AGAINST_GTEST = $(UNITTESTS_EXE_OBJS) test-ggc.o
+
+# All objects (for the main Makefile.in's dependency tracking)
+#extra_OBJS += $(OBJS_BUILT_AGAINST_GTEST)
+
+# Use strict warnings for this front end.
+unittests-warn = $(STRICT_WARN)
+
+# We avoid using $(BACKEND) from Makefile.in in order to avoid pulling
+# in main.o
+$(LIBGCCUNITTESTS_FILENAME): $(unittests_OBJS) \
+   libbackend.a libcommon-target.a libcommon.a \
+   $(CPPLIB) $(LIBDECNUMBER) \
+   $(LIBDEPS) test-ggc.o
+   +$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ -shared \
+$(unittests_OBJS) libbackend.a libcommon-target.a libcommon.a \
+$(CPPLIB) $(LIBDECNUMBER) $(LIBS) $(BACKENDLIBS) test-ggc.o \
+-Wl,-soname,$(LIBGCCUNITTESTS_SONAME)
+
+$(LIBGCCUNITTESTS_SONAME_SYMLINK): $(LIBGCCUNITTESTS_FILENAME)
+   ln -sf $(LIBGCCUNITTESTS_FILENAME) $(LIBGCCUNITTESTS_SONAME_SYMLINK)
+
+$(LIBGCCUNITTESTS_LINKER_NAME_SYMLINK): $(LIBGCCUNITTESTS_SONAME_SYMLINK)
+   ln -sf $(LIBGCCUNITTESTS_SONAME_SYMLINK) 
$(LIBGCCUNITTESTS_LINKER_NAME_SYMLINK)
+
+#
+# Build hooks:
+
+unittests.all.cross:
+unittests.start.encap:
+unittests.rest.encap:
+
+$(OBJS_BUILT_AGAINST_GTEST): %.o: $(srcdir)/unittests/%.c
+   $(COMPILER

[PATCH 03/17] Add test-cfg.c to gcc/unittests

2015-06-10 Thread David Malcolm
gcc/unittests/ChangeLog:
* test-cfg.c: New file.
---
 gcc/unittests/test-cfg.c | 319 +++
 1 file changed, 319 insertions(+)
 create mode 100644 gcc/unittests/test-cfg.c

diff --git a/gcc/unittests/test-cfg.c b/gcc/unittests/test-cfg.c
new file mode 100644
index 000..4781092
--- /dev/null
+++ b/gcc/unittests/test-cfg.c
@@ -0,0 +1,319 @@
+/* Unit tests for CFG-handling.
+   Copyright (C) 2015 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include 
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "opts.h"
+#include "signop.h"
+#include "hash-set.h"
+#include "fixed-value.h"
+#include "alias.h"
+#include "flags.h"
+#include "symtab.h"
+#include "tree-core.h"
+#include "stor-layout.h"
+#include "tree.h"
+#include "stringpool.h"
+#include "stor-layout.h"
+#include "rtl.h"
+#include "pretty-print.h"
+#include "tree-cfg.h"
+#include "predict.h"
+#include "basic-block.h"
+#include "hard-reg-set.h"
+#include "function.h"
+#include "dominance.h"
+#include "cfg.h"
+
+namespace {
+
+class cfg_test : public ::testing::Test
+{
+ protected:
+  tree
+  push_fndecl (const char *name)
+  {
+tree fn_type = build_function_type_array (integer_type_node, /* 
return_type */
+   0, NULL);
+/* FIXME: this uses input_location: */
+tree fndecl = build_fn_decl (name, fn_type);
+tree retval = build_decl (UNKNOWN_LOCATION, RESULT_DECL,
+ NULL_TREE, integer_type_node);
+DECL_RESULT (fndecl) = retval;
+push_struct_function (fndecl);
+function *fun = DECL_STRUCT_FUNCTION (fndecl);
+EXPECT_TRUE (fun != NULL);
+init_empty_tree_cfg_for_function (fun);
+EXPECT_EQ (2, n_basic_blocks_for_fn (fun));
+EXPECT_EQ (0, n_edges_for_fn (fun));
+return fndecl;
+  }
+};
+
+/* These tests directly create CFGs.
+   Compare with the static fns within tree-cfg.c:
+ - build_gimple_cfg
+ - make_blocks: calls create_basic_block (seq, bb);
+ - make_edges.   */
+
+/* Verify a simple cfg of the form:
+ ENTRY -> A -> B -> C -> EXIT.  */
+TEST_F (cfg_test, linear_chain)
+{
+  gimple_register_cfg_hooks ();
+
+  tree fndecl = push_fndecl ("cfg_test_linear_chain");
+  function *fun = DECL_STRUCT_FUNCTION (fndecl);
+  EXPECT_TRUE (fun != NULL);
+
+  EXPECT_EQ (2, n_basic_blocks_for_fn (fun));
+  EXPECT_EQ (0, n_edges_for_fn (fun));
+
+  /* Create some empty blocks.  */
+  basic_block bb_a = create_empty_bb (ENTRY_BLOCK_PTR_FOR_FN (fun));
+  basic_block bb_b = create_empty_bb (bb_a);
+  basic_block bb_c = create_empty_bb (bb_b);
+
+  EXPECT_EQ (5, n_basic_blocks_for_fn (fun));
+  EXPECT_EQ (0, n_edges_for_fn (fun));
+
+  /* Create some edges: a simple linear chain of BBs.  */
+  make_edge (ENTRY_BLOCK_PTR_FOR_FN (fun), bb_a, EDGE_FALLTHRU);
+  make_edge (bb_a, bb_b, 0);
+  make_edge (bb_b, bb_c, 0);
+  make_edge (bb_c, EXIT_BLOCK_PTR_FOR_FN (fun), 0);
+
+  /* Verify the edges.  */
+  EXPECT_EQ (4, n_edges_for_fn (fun));
+  EXPECT_EQ (NULL, ENTRY_BLOCK_PTR_FOR_FN (fun)->preds);
+  EXPECT_EQ (1, ENTRY_BLOCK_PTR_FOR_FN (fun)->succs->length ());
+  EXPECT_EQ (1, bb_a->preds->length ());
+  EXPECT_EQ (1, bb_a->succs->length ());
+  EXPECT_EQ (1, bb_b->preds->length ());
+  EXPECT_EQ (1, bb_b->succs->length ());
+  EXPECT_EQ (1, bb_c->preds->length ());
+  EXPECT_EQ (1, bb_c->succs->length ());
+  EXPECT_EQ (1, EXIT_BLOCK_PTR_FOR_FN (fun)->preds->length ());
+  EXPECT_EQ (NULL, EXIT_BLOCK_PTR_FOR_FN (fun)->succs);
+
+  /* Verify the dominance information
+ Each BB in our simple chain should be dominated by the one before
+ it.  */
+  calculate_dominance_info (CDI_DOMINATORS);
+  EXPECT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_b));
+  EXPECT_EQ (bb_b, get_immediate_dominator (CDI_DOMINATORS, bb_c));
+  vec dom_by_b = get_dominated_by (CDI_DOMINATORS, bb_b);
+  EXPECT_EQ (1, dom_by_b.length ());
+  EXPECT_EQ (bb_c, dom_by_b[0]);
+  free_dominance_info (CDI_DOMINATORS);
+
+  /* Similarly for post-dominance: each BB in our chain is post-dominated
+ by the one after it.  */
+  calculate_dominance_info (CDI_POST_DOMINATORS);
+  EXPECT_EQ (bb_b, get_immediate_dominator (CDI_POST_DOMINATORS, bb_a));
+  EXPECT_EQ (bb_c, get_immediate_dominator (CDI_POST_DOMINATORS, bb_b));
+  vec postdom_by_b = get_dominated_by (CDI_

[PATCH 10/17] Add test-locations.c to gcc/unittests

2015-06-10 Thread David Malcolm
gcc/unittests/ChangeLog:
* test-locations.c: New file.
---
 gcc/unittests/test-locations.c | 148 +
 1 file changed, 148 insertions(+)
 create mode 100644 gcc/unittests/test-locations.c

diff --git a/gcc/unittests/test-locations.c b/gcc/unittests/test-locations.c
new file mode 100644
index 000..7c93594
--- /dev/null
+++ b/gcc/unittests/test-locations.c
@@ -0,0 +1,148 @@
+/* Unit tests for GCC's source location-handling (and thus libcpp).
+   Copyright (C) 2015 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include 
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "opts.h"
+#include "signop.h"
+#include "hash-set.h"
+#include "fixed-value.h"
+#include "alias.h"
+#include "flags.h"
+#include "symtab.h"
+#include "tree-core.h"
+#include "stor-layout.h"
+#include "tree.h"
+#include "stringpool.h"
+#include "stor-layout.h"
+#include "predict.h"
+#include "vec.h"
+#include "hashtab.h"
+#include "hash-set.h"
+#include "machmode.h"
+
+namespace {
+
+/* Fixture for testing location-handling.
+   Creates some pre-canned location_t values.  */
+
+class location_test : public ::testing::Test
+{
+ protected:
+  location_test ()
+  {
+/* Build a simple linemap describing some locations. */
+linemap_add (line_table, LC_ENTER, false, "foo.c", 0);
+
+linemap_line_start (line_table, 1, 100);
+loc_a = linemap_position_for_column (line_table, 1);
+loc_b = linemap_position_for_column (line_table, 23);
+
+linemap_line_start (line_table, 2, 100);
+loc_c = linemap_position_for_column (line_table, 1);
+loc_d = linemap_position_for_column (line_table, 17);
+
+/* Example of a very long line.  */
+linemap_line_start (line_table, 3, 2000);
+loc_e = linemap_position_for_column (line_table, 700);
+
+linemap_add (line_table, LC_LEAVE, false, NULL, 0);
+
+/* Multiple files.  */
+linemap_add (line_table, LC_ENTER, false, "bar.c", 0);
+linemap_line_start (line_table, 1, 200);
+loc_f = linemap_position_for_column (line_table, 150);
+linemap_add (line_table, LC_LEAVE, false, NULL, 0);
+  }
+
+  /* Verify the result of LOCATION_FILE/LOCATION_LINE/LOCATION_COLUMN
+ on LOC.  */
+  void
+  expect_loceq (const char *exp_filename,
+   int exp_linenum,
+   int exp_colnum,
+   location_t loc)
+  {
+EXPECT_STREQ (exp_filename, LOCATION_FILE (loc));
+EXPECT_EQ (exp_linenum, LOCATION_LINE (loc));
+EXPECT_EQ (exp_colnum, LOCATION_COLUMN (loc));
+  }
+
+  location_t loc_a;
+  location_t loc_b;
+  location_t loc_c;
+  location_t loc_d;
+  location_t loc_e;
+  location_t loc_f;
+};
+
+/* Verify basic operation of ordinary linemaps.  */
+
+TEST_F (location_test, accessing_ordinary_linemaps)
+{
+  /* Verify that we can recover the location info.  */
+  expect_loceq ("foo.c", 1, 1, loc_a);
+  expect_loceq ("foo.c", 1, 23, loc_b);
+  expect_loceq ("foo.c", 2, 1, loc_c);
+  expect_loceq ("foo.c", 2, 17, loc_d);
+  expect_loceq ("foo.c", 3, 700, loc_e);
+  expect_loceq ("bar.c", 1, 150, loc_f);
+}
+
+TEST_F (location_test, unknown_location)
+{
+  EXPECT_EQ (NULL, LOCATION_FILE (UNKNOWN_LOCATION));
+  EXPECT_EQ (0, LOCATION_LINE (UNKNOWN_LOCATION));
+  EXPECT_EQ (0, LOCATION_COLUMN (UNKNOWN_LOCATION));
+}
+
+TEST_F (location_test, builtins)
+{
+  expect_loceq ("", 0, 0, BUILTINS_LOCATION);
+  EXPECT_PRED1 (is_location_from_builtin_token, BUILTINS_LOCATION);
+  EXPECT_FALSE (is_location_from_builtin_token (loc_a));
+}
+
+/* Verify reading of input files (e.g. for caret-based diagnostics.  */
+
+TEST_F (location_test, reading_source_line)
+{
+  /* We will read *this* source file, using __FILE__.
+ Here is some specific text to read and test for:
+ The quick brown fox jumps over the lazy dog.  */
+  const int linenum_after_test_message = __LINE__;
+
+  /* Locate the precanned text above.  */
+  expanded_location xloc;
+  xloc.file = __FILE__;
+  xloc.line = linenum_after_test_message - 1;
+  xloc.column = 0;
+
+  int line_size;
+  const char *source_line = location_get_source_line (xloc, &line_size);
+  EXPECT_TRUE (source_line != NULL);
+  EXPECT_STREQ (" The quick brown fox jumps over the lazy dog.  */",
+   source_line);
+  EXPECT_EQ (53, line_size);
+}
+
+} /* anon namespace. */
-- 
1.8.5.3



[PATCH 12/17] Add test-tree.c to gcc/unittests

2015-06-10 Thread David Malcolm
gcc/unittests/ChangeLog:
* test-tree.c: New file.
---
 gcc/unittests/test-tree.c | 102 ++
 1 file changed, 102 insertions(+)
 create mode 100644 gcc/unittests/test-tree.c

diff --git a/gcc/unittests/test-tree.c b/gcc/unittests/test-tree.c
new file mode 100644
index 000..d6832d2
--- /dev/null
+++ b/gcc/unittests/test-tree.c
@@ -0,0 +1,102 @@
+/* Unit tests for GCC's tree types.
+   Copyright (C) 2015 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include 
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "opts.h"
+#include "signop.h"
+#include "hash-set.h"
+#include "fixed-value.h"
+#include "alias.h"
+#include "flags.h"
+#include "symtab.h"
+#include "tree-core.h"
+#include "stor-layout.h"
+#include "tree.h"
+#include "stringpool.h"
+#include "stor-layout.h"
+#include "rtl.h"
+#include "predict.h"
+#include "vec.h"
+#include "hashtab.h"
+#include "hash-set.h"
+#include "machmode.h"
+#include "hard-reg-set.h"
+#include "input.h"
+#include "function.h"
+#include "dominance.h"
+#include "cfg.h"
+#include "cfganal.h"
+#include "basic-block.h"
+#include "tree-ssa-alias.h"
+#include "internal-fn.h"
+#include "gimple-fold.h"
+#include "gimple-expr.h"
+#include "toplev.h"
+#include "print-tree.h"
+#include "tree-iterator.h"
+#include "gimplify.h"
+#include "tree-cfg.h"
+#include "fold-const.h"
+
+namespace {
+
+/* Verify that integer constants are sane.  */
+
+TEST (tree_test, integer_constants)
+{
+  ASSERT_TRUE (integer_type_node != NULL);
+  EXPECT_TRUE (build_int_cst (integer_type_node, 0) != NULL);
+
+  tree type = integer_type_node;
+
+  tree zero = build_zero_cst (type);
+  EXPECT_EQ (INTEGER_CST, TREE_CODE (zero));
+  EXPECT_EQ (type, TREE_TYPE (zero));
+
+  tree one = build_int_cst (type, 1);
+  EXPECT_EQ (INTEGER_CST, TREE_CODE (one));
+  EXPECT_EQ (type, TREE_TYPE (zero));
+}
+
+/* Verify identifiers.  */
+
+TEST (tree_test, identifiers)
+{
+  tree identifier = get_identifier ("foo");
+  EXPECT_EQ (3, IDENTIFIER_LENGTH (identifier));
+  EXPECT_STREQ ("foo", IDENTIFIER_POINTER (identifier));
+}
+
+/* Verify LABEL_DECL.  */
+
+TEST (tree_test, labels)
+{
+  tree identifier = get_identifier ("err");
+  tree label_decl = build_decl (UNKNOWN_LOCATION, LABEL_DECL,
+   identifier, void_type_node);
+  EXPECT_EQ (-1, LABEL_DECL_UID (label_decl));
+  EXPECT_FALSE (FORCED_LABEL (label_decl));
+}
+
+}  // anon namespace
-- 
1.8.5.3



[PATCH 09/17] Add test-hash-set.c to gcc/unittests

2015-06-10 Thread David Malcolm
gcc/unittests/ChangeLog:
* test-hash-set.c: New file.
---
 gcc/unittests/test-hash-set.c | 54 +++
 1 file changed, 54 insertions(+)
 create mode 100644 gcc/unittests/test-hash-set.c

diff --git a/gcc/unittests/test-hash-set.c b/gcc/unittests/test-hash-set.c
new file mode 100644
index 000..3d6f0b4
--- /dev/null
+++ b/gcc/unittests/test-hash-set.c
@@ -0,0 +1,54 @@
+/* Unit tests for hash-set.h.
+   Copyright (C) 2015 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include 
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "opts.h"
+#include "signop.h"
+#include "hash-set.h"
+
+namespace {
+
+TEST (hash_set_test, set_of_strings)
+{
+  hash_set  s;
+  EXPECT_EQ (0, s.elements ());
+
+  const char *red = "red";
+  const char *green = "green";
+  const char *blue = "blue";
+
+  EXPECT_EQ (false, s.contains (red));
+
+  /* Populate the hash_set.  */
+  EXPECT_EQ (false, s.add (red));
+  EXPECT_EQ (false, s.add (green));
+  EXPECT_EQ (false, s.add (blue));
+
+  /* Verify that the values are now within the set.  */
+  EXPECT_EQ (true, s.contains (red));
+  EXPECT_EQ (true, s.contains (green));
+  EXPECT_EQ (true, s.contains (blue));
+}
+
+}  /* anon namespace.  */
-- 
1.8.5.3



[PATCH 11/17] Add test-rtl.c to gcc/unittests

2015-06-10 Thread David Malcolm
gcc/unittests/ChangeLog:
* test-rtl.c: New file.
---
 gcc/unittests/test-rtl.c | 94 
 1 file changed, 94 insertions(+)
 create mode 100644 gcc/unittests/test-rtl.c

diff --git a/gcc/unittests/test-rtl.c b/gcc/unittests/test-rtl.c
new file mode 100644
index 000..cba7bb8
--- /dev/null
+++ b/gcc/unittests/test-rtl.c
@@ -0,0 +1,94 @@
+/* Unit tests for RTL-handling.
+   Copyright (C) 2015 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include 
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "opts.h"
+#include "signop.h"
+#include "hash-set.h"
+#include "fixed-value.h"
+#include "alias.h"
+#include "flags.h"
+#include "symtab.h"
+#include "tree-core.h"
+#include "stor-layout.h"
+#include "tree.h"
+#include "stringpool.h"
+#include "stor-layout.h"
+#include "rtl.h"
+#include "pretty-print.h"
+#include "cfgbuild.h"
+
+namespace {
+
+class rtl_test : public ::testing::Test
+{
+ protected:
+  void
+  verify_print_pattern (const char *expected, rtx pat)
+  {
+pretty_printer pp;
+print_pattern (&pp, pat, 1);
+EXPECT_STREQ (expected, pp_formatted_text (&pp));
+  }
+};
+
+/* Unit testing of "single_set".  */
+TEST_F (rtl_test, test_single_set)
+{
+  /* A label is not a SET.  */
+  EXPECT_EQ (NULL_RTX, single_set (gen_label_rtx ()));
+
+  /* An unconditional jump insn is a single SET.  */
+  rtx set_pc = gen_rtx_SET (pc_rtx,
+   gen_rtx_LABEL_REF (VOIDmode,
+  gen_label_rtx ()));
+  rtx_insn *jump_insn = emit_jump_insn (set_pc);
+  EXPECT_EQ (set_pc, single_set (jump_insn));
+
+  /* etc */
+}
+
+TEST_F (rtl_test, uncond_jump)
+{
+  rtx_insn *label = gen_label_rtx ();
+  rtx jump_pat = gen_rtx_SET (pc_rtx,
+ gen_rtx_LABEL_REF (VOIDmode,
+label));
+  EXPECT_EQ (SET, jump_pat->code);
+  EXPECT_EQ (LABEL_REF, SET_SRC (jump_pat)->code);
+  EXPECT_EQ (label, LABEL_REF_LABEL (SET_SRC (jump_pat)));
+  EXPECT_EQ (PC, SET_DEST (jump_pat)->code);
+
+  verify_print_pattern ("pc=L0", jump_pat);
+
+  rtx_insn *jump_insn = emit_jump_insn (jump_pat);
+  EXPECT_FALSE (any_condjump_p (jump_insn));
+  EXPECT_TRUE (any_uncondjump_p (jump_insn));
+  EXPECT_TRUE (pc_set (jump_insn));
+  EXPECT_TRUE (simplejump_p (jump_insn));
+  EXPECT_TRUE (onlyjump_p (jump_insn));
+  EXPECT_TRUE (control_flow_insn_p (jump_insn));
+}
+
+}  /* anon namespace.  */
-- 
1.8.5.3



[PATCH 04/17] Add test-folding.c to gcc/unittests

2015-06-10 Thread David Malcolm
gcc/unittests/ChangeLog:
* test-folding.c: New file.
---
 gcc/unittests/test-folding.c | 121 +++
 1 file changed, 121 insertions(+)
 create mode 100644 gcc/unittests/test-folding.c

diff --git a/gcc/unittests/test-folding.c b/gcc/unittests/test-folding.c
new file mode 100644
index 000..277acea
--- /dev/null
+++ b/gcc/unittests/test-folding.c
@@ -0,0 +1,121 @@
+/* Unit tests for GCC's expression folding.
+   Copyright (C) 2015 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include 
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "opts.h"
+#include "signop.h"
+#include "hash-set.h"
+#include "fixed-value.h"
+#include "alias.h"
+#include "flags.h"
+#include "symtab.h"
+#include "tree-core.h"
+#include "stor-layout.h"
+#include "tree.h"
+#include "stringpool.h"
+#include "stor-layout.h"
+#include "rtl.h"
+#include "predict.h"
+#include "vec.h"
+#include "hashtab.h"
+#include "hash-set.h"
+#include "machmode.h"
+#include "hard-reg-set.h"
+#include "input.h"
+#include "function.h"
+#include "dominance.h"
+#include "cfg.h"
+#include "cfganal.h"
+#include "basic-block.h"
+#include "tree-ssa-alias.h"
+#include "internal-fn.h"
+#include "gimple-fold.h"
+#include "gimple-expr.h"
+#include "toplev.h"
+#include "print-tree.h"
+#include "tree-iterator.h"
+#include "gimplify.h"
+#include "tree-cfg.h"
+#include "fold-const.h"
+
+namespace {
+
+/* A test fixture for writing tests of folding trees.  */
+class tree_folding_test : public ::testing::Test
+{
+ protected:
+  void
+  assert_binop_folds_to_const (tree lhs, enum tree_code code, tree rhs,
+  tree constant)
+  {
+EXPECT_EQ (constant, fold_build2 (code, TREE_TYPE (lhs), lhs, rhs));
+  }
+
+  void
+  assert_binop_folds_to_nonlvalue (tree lhs, enum tree_code code, tree rhs,
+  tree wrapped_expr)
+  {
+tree result = fold_build2 (code, TREE_TYPE (lhs), lhs, rhs);
+EXPECT_NE (wrapped_expr, result);
+EXPECT_EQ (NON_LVALUE_EXPR, TREE_CODE (result));
+EXPECT_EQ (wrapped_expr, TREE_OPERAND (result, 0));
+  }
+};
+
+TEST_F (tree_folding_test, arithmetic_folding)
+{
+  tree type = integer_type_node;
+  tree x = create_tmp_var_raw (type, "x");
+  tree zero = build_zero_cst (type);
+  tree one = build_int_cst (type, 1);
+
+  /* Addition.  */
+  /* 1 <-- (0 + 1) */
+  assert_binop_folds_to_const (zero, PLUS_EXPR, one,
+  one);
+  assert_binop_folds_to_const (one, PLUS_EXPR, zero,
+  one);
+
+  /* (nonlvalue)x <-- (x + 0) */
+  assert_binop_folds_to_nonlvalue (x, PLUS_EXPR, zero,
+  x);
+
+  /* Subtraction.  */
+  /* 0 <-- (x - x) */
+  assert_binop_folds_to_const (x, MINUS_EXPR, x,
+  zero);
+  assert_binop_folds_to_nonlvalue (x, MINUS_EXPR, zero,
+  x);
+
+  /* Multiplication.  */
+  /* 0 <-- (x * 0) */
+  assert_binop_folds_to_const (x, MULT_EXPR, zero,
+  zero);
+
+  /* (nonlvalue)x <-- (x * 1) */
+  assert_binop_folds_to_nonlvalue (x, MULT_EXPR, one,
+  x);
+}
+
+}  // anon namespace
-- 
1.8.5.3



[PATCH 05/17] Add test-functions.c to gcc/unittests

2015-06-10 Thread David Malcolm
gcc/unittests/ChangeLog:
* test-functions.c: New file.
---
 gcc/unittests/test-functions.c | 634 +
 1 file changed, 634 insertions(+)
 create mode 100644 gcc/unittests/test-functions.c

diff --git a/gcc/unittests/test-functions.c b/gcc/unittests/test-functions.c
new file mode 100644
index 000..347e23f
--- /dev/null
+++ b/gcc/unittests/test-functions.c
@@ -0,0 +1,634 @@
+/* Unit tests for function-handling.
+   Copyright (C) 2015 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include 
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "opts.h"
+#include "signop.h"
+#include "hash-set.h"
+#include "fixed-value.h"
+#include "alias.h"
+#include "flags.h"
+#include "symtab.h"
+#include "tree-core.h"
+#include "stor-layout.h"
+#include "tree.h"
+#include "stringpool.h"
+#include "stor-layout.h"
+#include "rtl.h"
+#include "predict.h"
+#include "vec.h"
+#include "hashtab.h"
+#include "hash-set.h"
+#include "machmode.h"
+#include "hard-reg-set.h"
+#include "input.h"
+#include "function.h"
+#include "dominance.h"
+#include "cfg.h"
+#include "cfganal.h"
+#include "basic-block.h"
+#include "tree-ssa-alias.h"
+#include "internal-fn.h"
+#include "gimple-fold.h"
+#include "gimple-expr.h"
+#include "toplev.h"
+#include "print-tree.h"
+#include "tree-iterator.h"
+#include "gimplify.h"
+#include "tree-cfg.h"
+#include "basic-block.h"
+#include "double-int.h"
+#include "alias.h"
+#include "symtab.h"
+#include "wide-int.h"
+#include "inchash.h"
+#include "tree.h"
+#include "fold-const.h"
+#include "stor-layout.h"
+#include "stmt.h"
+#include "hash-table.h"
+#include "tree-ssa-alias.h"
+#include "internal-fn.h"
+#include "gimple-expr.h"
+#include "is-a.h"
+#include "gimple.h"
+#include "tree-pass.h"
+#include "context.h"
+#include "hash-map.h"
+#include "plugin-api.h"
+#include "ipa-ref.h"
+#include "cgraph.h"
+
+namespace {
+
+class function_test : public ::testing::Test
+{
+ protected:
+  tree
+  make_fndecl (tree return_type,
+  const char *name,
+  vec  ¶m_types,
+  bool is_variadic = false)
+  {
+tree fn_type;
+if (is_variadic)
+  fn_type = build_varargs_function_type_array (return_type,
+  param_types.length (),
+  param_types.address ());
+else
+  fn_type = build_function_type_array (return_type,
+  param_types.length (),
+  param_types.address ());
+/* FIXME: this uses input_location: */
+tree fndecl = build_fn_decl (name, fn_type);
+
+return fndecl;
+  }
+};
+
+TEST_F (function_test, fndecl_int_void)
+{
+  auto_vec  param_types;
+  tree fndecl = make_fndecl (integer_type_node,
+"test_fndecl_int_void",
+param_types);
+  ASSERT_TRUE (fndecl != NULL);
+  if (0)
+debug_tree (fndecl);
+
+  /* Verify name of decl.  */
+  tree declname = DECL_NAME (fndecl);
+  ASSERT_TRUE (declname != NULL);
+  EXPECT_EQ (IDENTIFIER_NODE, TREE_CODE (declname));
+  /* We expect it to use a *copy* of the string we passed in.  */
+  const char *identifier_ptr = IDENTIFIER_POINTER (declname);
+  EXPECT_NE ("test_fndecl_int_void", identifier_ptr);
+  EXPECT_EQ (0, strcmp ("test_fndecl_int_void", identifier_ptr));
+
+  /* Verify type of fndecl.  */
+  EXPECT_EQ (FUNCTION_DECL, TREE_CODE (fndecl));
+  tree fntype = TREE_TYPE (fndecl);
+  EXPECT_EQ (FUNCTION_TYPE, TREE_CODE (fntype));
+
+  /* Verify return type.  */
+  EXPECT_EQ (integer_type_node, TREE_TYPE (fntype));
+
+  /* Verify "void" args.  */
+  tree argtypes = TYPE_ARG_TYPES (fntype);
+  EXPECT_EQ (TREE_LIST, TREE_CODE (argtypes));
+  EXPECT_EQ (void_type_node, TREE_VALUE (argtypes));
+  EXPECT_EQ (NULL, TREE_CHAIN (argtypes));
+}
+
+TEST_F (function_test, fndecl_float_intchar)
+{
+  auto_vec  param_types;
+  param_types.safe_push (integer_type_node);
+  param_types.safe_push (char_type_node);
+  tree fndecl = make_fndecl (float_type_node,
+"test_fndecl_float_intchar",
+param_types);
+  ASSERT_TRUE (fndecl != NULL);
+  if (0)
+debug_tree (fndecl);
+
+  /* Verify name of decl.  */
+  tree declname = DECL_NAME (fndecl);
+  A

[PATCH 08/17] Add test-hash-map.c to gcc/unittests

2015-06-10 Thread David Malcolm
gcc/unittests/ChangeLog:
* test-hash-map.c: New file.
---
 gcc/unittests/test-hash-map.c | 78 +++
 1 file changed, 78 insertions(+)
 create mode 100644 gcc/unittests/test-hash-map.c

diff --git a/gcc/unittests/test-hash-map.c b/gcc/unittests/test-hash-map.c
new file mode 100644
index 000..938c22b
--- /dev/null
+++ b/gcc/unittests/test-hash-map.c
@@ -0,0 +1,78 @@
+/* Unit tests for hash-map.h.
+   Copyright (C) 2015 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include 
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "opts.h"
+#include "signop.h"
+#include "hash-set.h"
+#include "fixed-value.h"
+#include "alias.h"
+#include "flags.h"
+#include "symtab.h"
+#include "tree-core.h"
+#include "stor-layout.h"
+#include "tree.h"
+#include "stringpool.h"
+
+namespace {
+
+TEST (hash_map_test, map_of_strings_to_int)
+{
+  hash_map  m;
+
+  const char *ostrich = "ostrich";
+  const char *elephant = "elephant";
+  const char *ant = "ant";
+  const char *spider = "spider";
+  const char *millipede = "Illacme plenipes";
+  const char *eric = "half a bee";
+
+  /* A fresh hash_map should be empty.  */
+  EXPECT_EQ (0, m.elements ());
+  EXPECT_EQ (NULL, m.get (ostrich));
+
+  /* Populate the hash_map.  */
+  EXPECT_EQ (false, m.put (ostrich, 2));
+  EXPECT_EQ (false, m.put (elephant, 4));
+  EXPECT_EQ (false, m.put (ant, 6));
+  EXPECT_EQ (false, m.put (spider, 8));
+  EXPECT_EQ (false, m.put (millipede, 750));
+  EXPECT_EQ (false, m.put (eric, 3));
+
+  /* Verify that we can recover the stored values.  */
+  EXPECT_EQ (6, m.elements ());
+  EXPECT_EQ (2, *m.get (ostrich));
+  EXPECT_EQ (4, *m.get (elephant));
+  EXPECT_EQ (6, *m.get (ant));
+  EXPECT_EQ (8, *m.get (spider));
+  EXPECT_EQ (750, *m.get (millipede));
+  EXPECT_EQ (3, *m.get (eric));
+
+  /* Verify removing an item.  */
+  m.remove (eric);
+  EXPECT_EQ (5, m.elements ());
+  EXPECT_EQ (NULL, m.get (eric));
+}
+
+}  /* anon namespace.  */
-- 
1.8.5.3



[PATCH 07/17] Add test-gimple.c to gcc/unittests

2015-06-10 Thread David Malcolm
gcc/unittests/ChangeLog:
* test-gimple.c: New file.
---
 gcc/unittests/test-gimple.c | 179 
 1 file changed, 179 insertions(+)
 create mode 100644 gcc/unittests/test-gimple.c

diff --git a/gcc/unittests/test-gimple.c b/gcc/unittests/test-gimple.c
new file mode 100644
index 000..093f5fb
--- /dev/null
+++ b/gcc/unittests/test-gimple.c
@@ -0,0 +1,179 @@
+/* Unit tests for gimple.
+   Copyright (C) 2015 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include 
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "opts.h"
+#include "signop.h"
+#include "hash-set.h"
+#include "fixed-value.h"
+#include "alias.h"
+#include "flags.h"
+#include "symtab.h"
+#include "tree-core.h"
+#include "stor-layout.h"
+#include "tree.h"
+#include "stringpool.h"
+#include "stor-layout.h"
+#include "rtl.h"
+#include "predict.h"
+#include "vec.h"
+#include "hashtab.h"
+#include "hash-set.h"
+#include "machmode.h"
+#include "hard-reg-set.h"
+#include "input.h"
+#include "function.h"
+#include "dominance.h"
+#include "cfg.h"
+#include "cfganal.h"
+#include "basic-block.h"
+#include "tree-ssa-alias.h"
+#include "internal-fn.h"
+#include "gimple-fold.h"
+#include "gimple-expr.h"
+#include "toplev.h"
+#include "print-tree.h"
+#include "tree-iterator.h"
+#include "gimplify.h"
+#include "tree-cfg.h"
+#include "basic-block.h"
+#include "double-int.h"
+#include "alias.h"
+#include "symtab.h"
+#include "wide-int.h"
+#include "inchash.h"
+#include "tree.h"
+#include "fold-const.h"
+#include "stor-layout.h"
+#include "stmt.h"
+#include "hash-table.h"
+#include "tree-ssa-alias.h"
+#include "internal-fn.h"
+#include "gimple-expr.h"
+#include "is-a.h"
+#include "gimple.h"
+#include "tree-pass.h"
+#include "context.h"
+#include "hash-map.h"
+#include "plugin-api.h"
+#include "ipa-ref.h"
+#include "cgraph.h"
+#include "gimple-pretty-print.h"
+
+namespace {
+
+class gimple_test : public ::testing::Test
+{
+ protected:
+  void
+  verify_gimple_pp (const char *expected, gimple stmt)
+  {
+pretty_printer pp;
+pp_gimple_stmt_1 (&pp, stmt, 0 /* spc */, 0 /* flags */);
+EXPECT_STREQ (expected, pp_formatted_text (&pp));
+  }
+};
+
+TEST_F (gimple_test, assign_single)
+{
+  /* Build "tmp = 5;"  */
+  tree type = integer_type_node;
+  tree lhs = build_decl (UNKNOWN_LOCATION, VAR_DECL,
+get_identifier ("tmp"),
+type);
+  tree rhs = build_int_cst (type, 5);
+  gassign *stmt = gimple_build_assign (lhs, rhs);
+  verify_gimple_pp ("tmp = 5;", stmt);
+
+  EXPECT_TRUE (is_gimple_assign (stmt));
+  EXPECT_EQ (lhs, gimple_assign_lhs (stmt));
+  EXPECT_EQ (lhs, gimple_get_lhs (stmt));
+  EXPECT_EQ (rhs, gimple_assign_rhs1 (stmt));
+  EXPECT_EQ (NULL, gimple_assign_rhs2 (stmt));
+  EXPECT_EQ (NULL, gimple_assign_rhs3 (stmt));
+  EXPECT_TRUE (gimple_assign_single_p (stmt));
+  EXPECT_EQ (INTEGER_CST, gimple_assign_rhs_code (stmt));
+}
+
+TEST_F (gimple_test, assign_binop)
+{
+  /* Build "tmp = a + b;"  */
+  tree type = integer_type_node;
+  tree lhs = build_decl (UNKNOWN_LOCATION, VAR_DECL,
+get_identifier ("tmp"),
+type);
+  tree a = build_decl (UNKNOWN_LOCATION, VAR_DECL,
+  get_identifier ("a"),
+  type);
+  tree b = build_decl (UNKNOWN_LOCATION, VAR_DECL,
+  get_identifier ("b"),
+  type);
+  gassign *stmt = gimple_build_assign (lhs, MULT_EXPR, a, b);
+  verify_gimple_pp ("tmp = a * b;", stmt);
+
+  EXPECT_TRUE (is_gimple_assign (stmt));
+  EXPECT_EQ (lhs, gimple_assign_lhs (stmt));
+  EXPECT_EQ (lhs, gimple_get_lhs (stmt));
+  EXPECT_EQ (a, gimple_assign_rhs1 (stmt));
+  EXPECT_EQ (b, gimple_assign_rhs2 (stmt));
+  EXPECT_EQ (NULL, gimple_assign_rhs3 (stmt));
+  EXPECT_FALSE (gimple_assign_single_p (stmt));
+  EXPECT_EQ (MULT_EXPR, gimple_assign_rhs_code (stmt));
+}
+
+TEST_F (gimple_test, nop_stmt)
+{
+  gimple stmt = gimple_build_nop ();
+  verify_gimple_pp ("GIMPLE_NOP", stmt);
+  EXPECT_EQ (GIMPLE_NOP, gimple_code (stmt));
+  EXPECT_EQ (NULL, gimple_get_lhs (stmt));
+  EXPECT_FALSE (gimple_assign_single_p (stmt));
+}
+
+TEST_F (gimple_test, return_stmt)
+{
+  /* Build "return 7;"  */
+  tree type = integer_type_node;
+  tree val = build_int_cst (type, 7);
+  greturn 

Re: C++ PATCH for c++/66289 (ICE with alias-template)

2015-06-10 Thread Jason Merrill

On 06/10/2015 09:09 AM, Jason Merrill wrote:

My patch for DR 1558 broke this testcase: suppressing the stripping of
alias template-ids with dependent arguments prevented us from
recognizing that APtr is more specialized than shared_ptr.  At the
Lenexa meeting we in Core talked about establishing a category of alias
templates that are actually equivalent to their expansions, based
largely on whether all the template parameters are used.  This patch
implements that idea, and fixes the testcase.

Tested x86_64-pc-linux-gnu, applying to trunk and 5.


Actually, applying this patch, which uses a flag to remember whether an 
alias template is complex.
commit 51f060584f93ef1f3d9ad56b5f11c5b2cfe6fd7a
Author: Jason Merrill 
Date:   Fri Jun 5 18:48:24 2015 -0400

	PR c++/66289
	* cp-tree.h (TEMPLATE_DECL_COMPLEX_ALIAS_P): New.
	* pt.c (push_template_decl_real): Set it.
	(dependent_alias_template_spec_p): Use it.
	(dependent_type_p_r): Use dependent_alias_template_spec_p.
	(uses_all_template_parms_data, uses_all_template_parms_r)
	(complex_alias_template_p): New.
	(get_template_parm_index): Handle BOUND_TEMPLATE_TEMPLATE_PARM.

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 603a871..1eac636 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -155,6 +155,7 @@ c-common.h, not after.
   LABEL_DECL_CONTINUE (in LABEL_DECL)
2: DECL_THIS_EXTERN (in VAR_DECL or FUNCTION_DECL).
   DECL_IMPLICIT_TYPEDEF_P (in a TYPE_DECL)
+  TEMPLATE_DECL_COMPLEX_ALIAS_P (in TEMPLATE_DECL)
3: DECL_IN_AGGR_P.
4: DECL_C_BIT_FIELD (in a FIELD_DECL)
   DECL_ANON_UNION_VAR_P (in a VAR_DECL)
@@ -2732,6 +2733,10 @@ extern void decl_shadowed_for_var_insert (tree, tree);
 #define TYPE_DECL_ALIAS_P(NODE) \
   DECL_LANG_FLAG_6 (TYPE_DECL_CHECK (NODE))
 
+/* Nonzero for TEMPLATE_DECL means that it is a 'complex' alias template.  */
+#define TEMPLATE_DECL_COMPLEX_ALIAS_P(NODE) \
+  DECL_LANG_FLAG_2 (TEMPLATE_DECL_CHECK (NODE))
+
 /* Nonzero for a type which is an alias for another type; i.e, a type
which declaration was written 'using name-of-type =
another-type'.  */
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 2ebeb65..7f04fe6 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -211,6 +211,7 @@ static tree template_parm_to_arg (tree t);
 static tree current_template_args (void);
 static tree tsubst_template_parm (tree, tree, tsubst_flags_t);
 static tree instantiate_alias_template (tree, tree, tsubst_flags_t);
+static bool complex_alias_template_p (const_tree tmpl);
 
 /* Make the current scope suitable for access checking when we are
processing T.  T can be FUNCTION_DECL for instantiated function
@@ -4420,6 +4421,7 @@ get_template_parm_index (tree parm)
 	   || TREE_CODE (parm) == TEMPLATE_DECL)
 parm = TREE_TYPE (parm);
   if (TREE_CODE (parm) == TEMPLATE_TYPE_PARM
+  || TREE_CODE (parm) == BOUND_TEMPLATE_TEMPLATE_PARM
   || TREE_CODE (parm) == TEMPLATE_TEMPLATE_PARM)
 parm = TEMPLATE_TYPE_PARM_INDEX (parm);
   gcc_assert (TREE_CODE (parm) == TEMPLATE_PARM_INDEX);
@@ -5096,6 +5098,11 @@ template arguments to %qD do not match original template %qD",
 	  if (TREE_CODE (parm) == TEMPLATE_DECL)
 	DECL_CONTEXT (parm) = tmpl;
 	}
+
+  if (TREE_CODE (decl) == TYPE_DECL
+	  && TYPE_DECL_ALIAS_P (decl)
+	  && complex_alias_template_p (tmpl))
+	TEMPLATE_DECL_COMPLEX_ALIAS_P (tmpl) = true;
 }
 
   /* The DECL_TI_ARGS of DECL contains full set of arguments referring
@@ -5353,13 +5360,56 @@ alias_template_specialization_p (const_tree t)
   return false;
 }
 
-/* Return TRUE iff T is a specialization of an alias template with
+/* An alias template is complex from a SFINAE perspective if a template-id
+   using that alias can be ill-formed when the expansion is not, as with
+   the void_t template.  We determine this by checking whether the
+   expansion for the alias template uses all its template parameters.  */
+
+struct uses_all_template_parms_data
+{
+  int level;
+  bool *seen;
+};
+
+static int
+uses_all_template_parms_r (tree t, void *data_)
+{
+  struct uses_all_template_parms_data &data
+= *(struct uses_all_template_parms_data*)data_;
+  tree idx = get_template_parm_index (t);
+
+  if (TEMPLATE_PARM_LEVEL (idx) == data.level)
+data.seen[TEMPLATE_PARM_IDX (idx)] = true;
+  return 0;
+}
+
+static bool
+complex_alias_template_p (const_tree tmpl)
+{
+  struct uses_all_template_parms_data data;
+  tree pat = DECL_ORIGINAL_TYPE (DECL_TEMPLATE_RESULT (tmpl));
+  tree parms = DECL_TEMPLATE_PARMS (tmpl);
+  data.level = TMPL_PARMS_DEPTH (parms);
+  int len = TREE_VEC_LENGTH (INNERMOST_TEMPLATE_PARMS (parms));
+  data.seen = XALLOCAVEC (bool, len);
+  for (int i = 0; i < len; ++i)
+data.seen[i] = false;
+
+  for_each_template_parm (pat, uses_all_template_parms_r, &data, NULL, true);
+  for (int i = 0; i < len; ++i)
+if (!data.seen[i])
+  return true;
+  return false;
+}
+
+/* Return TRUE iff T is a specialization of a complex alias template

[PATCH 17/17] toplev.c: move location_adhoc_data_fini call

2015-06-10 Thread David Malcolm
test-functions.c: representation_test.building_cfg and others
need the call to location_adhoc_data_fini to happen later, otherwise
we get a segfault inside gimple_set_block here due to the
adhoc-location data being finalized:

 #0  0x00687800 in ?? ()
 #1  0x77504c22 in htab_find_slot (htab=0x6627a0, 
element=0x7fffde90, insert=INSERT)
 at ../../src/libiberty/hashtab.c:704
 #2  0x774c0de5 in get_combined_adhoc_loc (set=0x77ffa000, 
locus=, data=)
 at ../../src/libcpp/line-map.c:128
 #3  0x773cb047 in COMBINE_LOCATION_DATA (block=, 
loc=, set=)
 at ../../src/gcc/../libcpp/include/line-map.h:794
 #4  gimple_set_block (g=, block=) at 
../../src/gcc/gimple.h:1636
 #5  lower_stmt (data=0x7fffdfa0, gsi=0x7fffdf00) at 
../../src/gcc/gimple-low.c:260
 #6  lower_sequence (seq=seq@entry=0x7fffefa310b8, 
data=data@entry=0x7fffdfa0) at ../../src/gcc/gimple-low.c:227
 #7  0x773caeef in lower_gimple_bind (gsi=gsi@entry=0x7fffdfc0, 
data=data@entry=0x7fffdfa0)
 at ../../src/gcc/gimple-low.c:441
 #8  0x773cc675 in lower_function_body () at 
../../src/gcc/gimple-low.c:131
 #9  (anonymous namespace)::pass_lower_cf::execute (this=) at 
../../src/gcc/gimple-low.c:205
 #10 0x00414030 in (anonymous 
namespace)::representation_test::build_cfg (this=0x66c520, 
fndecl=0x7fffefa43ee0)
 at ../../src/gcc/unittests/test-functions.c:293
 #11 0x0041787d in (anonymous 
namespace)::representation_test_building_cfg_Test::TestBody (this=0x66c520)
 at ../../src/gcc/unittests/test-functions.c:501
 #12 0x77dcf323 in void 
testing::internal::HandleExceptionsInMethodIfSupported(testing::Test*, void (testing::Test::*)(), char const*) () from 
/lib64/libgtest.so.0
 #13 0x77dc4b67 in testing::Test::Run() () from /lib64/libgtest.so.0
 #14 0x77dc4c0e in testing::TestInfo::Run() () from /lib64/libgtest.so.0
 #15 0x77dc4d15 in testing::TestCase::Run() () from /lib64/libgtest.so.0
 #16 0x77dc83a8 in testing::internal::UnitTestImpl::RunAllTests() () 
from /lib64/libgtest.so.0
 #17 0x77dc8647 in testing::UnitTest::Run() () from /lib64/libgtest.so.0
 #18 0x004369cb in main (argc=1, argv=0x7fffe478) at 
../../src/gcc/unittests/unittests-main.c:107

gcc/ChangeLog:
* toplev.c (toplev::main): Move call of
location_adhoc_data_fini from here...
(toplev::finalize): ...to here.
---
 gcc/toplev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/toplev.c b/gcc/toplev.c
index 3b57b48..ca2c18c 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -2194,7 +2194,6 @@ toplev::main (int argc, char **argv)
   diagnostic_finish (global_dc);
 
   finalize_plugins ();
-  location_adhoc_data_fini (line_table);
   if (seen_error () || werrorcount)
 return (FATAL_EXIT_CODE);
 
@@ -2230,4 +2229,6 @@ toplev::finalize (void)
   g = NULL;
 
   obstack_free (&opts_obstack, NULL);
+
+  location_adhoc_data_fini (line_table);
 }
-- 
1.8.5.3



[PATCH 16/17] Add unittests-main.c to gcc/unittests

2015-06-10 Thread David Malcolm
gcc/unittests/ChangeLog:
* unittests-main.c: New file.
---
 gcc/unittests/unittests-main.c | 108 +
 1 file changed, 108 insertions(+)
 create mode 100644 gcc/unittests/unittests-main.c

diff --git a/gcc/unittests/unittests-main.c b/gcc/unittests/unittests-main.c
new file mode 100644
index 000..635a4f3
--- /dev/null
+++ b/gcc/unittests/unittests-main.c
@@ -0,0 +1,108 @@
+/* "main" and other top-level hooks for unittesting GCC.
+   Copyright (C) 2015 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include 
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "opts.h"
+#include "signop.h"
+#include "hash-set.h"
+#include "fixed-value.h"
+#include "alias.h"
+#include "flags.h"
+#include "symtab.h"
+#include "tree-core.h"
+#include "stor-layout.h"
+#include "tree.h"
+#include "stringpool.h"
+#include "stor-layout.h"
+#include "rtl.h"
+#include "predict.h"
+#include "vec.h"
+#include "hashtab.h"
+#include "hash-set.h"
+#include "machmode.h"
+#include "hard-reg-set.h"
+#include "input.h"
+#include "function.h"
+#include "dominance.h"
+#include "cfg.h"
+#include "cfganal.h"
+#include "basic-block.h"
+#include "tree-ssa-alias.h"
+#include "internal-fn.h"
+#include "gimple-fold.h"
+#include "gimple-expr.h"
+#include "toplev.h"
+
+namespace {
+
+class gcc_environment : public ::testing::Environment
+{
+ public:
+  gcc_environment ()
+: m_toplev (true, /* use_TV_TOTAL */
+   false /* init_signals */)
+  {
+  }
+
+  /* Implementation of base class' vfunc.  */
+  void SetUp()
+  {
+/* Hack: run toplev::main once, to force initialization.  */
+auto_vec  args;
+args.safe_push ("unittesting");
+args.safe_push ("-quiet");
+
+/* Hack: give it fake src/dst files, otherwise e.g. asm_out_file
+   becomes stdout, and we have an eventual crash.  */
+args.safe_push ("-o");
+args.safe_push ("/tmp/fake.s");
+args.safe_push ("/tmp/fake.c");
+
+m_toplev.main (args.length (),
+  const_cast  (args.address ()));
+
+/* We've now run toplev once; everything should now be initialized
+   enough to allow use to run unit tests of the various subsystems.  */
+  }
+
+  /* Implementation of base class' vfunc.  */
+  void TearDown()
+  {
+m_toplev.finalize ();
+  }
+
+ private:
+  toplev m_toplev;
+};
+
+}  // anon namespace
+
+int main (int argc, char **argv)
+{
+  ::testing::InitGoogleTest(&argc, argv);
+
+  ::testing::AddGlobalTestEnvironment(new gcc_environment);
+
+  return RUN_ALL_TESTS();
+}
-- 
1.8.5.3



[PATCH 13/17] Add test-vec.c to gcc/unittests

2015-06-10 Thread David Malcolm
gcc/unittests/ChangeLog:
* test-vec.c: New file.
---
 gcc/unittests/test-vec.c | 162 +++
 1 file changed, 162 insertions(+)
 create mode 100644 gcc/unittests/test-vec.c

diff --git a/gcc/unittests/test-vec.c b/gcc/unittests/test-vec.c
new file mode 100644
index 000..5ea6ca3
--- /dev/null
+++ b/gcc/unittests/test-vec.c
@@ -0,0 +1,162 @@
+/* Unit tests for vec<>.
+   Copyright (C) 2015 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include 
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "opts.h"
+#include "vec.h"
+
+namespace {
+
+class vec_test : public ::testing::Test
+{
+ protected:
+  /* Add the range [START..LIMIT) to V.  */
+  void
+  safe_push_range (vec &v, int start, int limit)
+  {
+for (int i = start; i < limit; i++)
+  v.safe_push (i);
+  }
+};
+
+TEST_F (vec_test, quick_push)
+{
+  auto_vec  v;
+  EXPECT_EQ (0, v.length ());
+  v.reserve (3);
+  EXPECT_EQ (0, v.length ());
+  EXPECT_TRUE (v.space (3));
+  v.quick_push (5);
+  v.quick_push (6);
+  v.quick_push (7);
+  EXPECT_EQ (3, v.length ());
+  EXPECT_EQ (5, v[0]);
+  EXPECT_EQ (6, v[1]);
+  EXPECT_EQ (7, v[2]);
+}
+
+TEST_F (vec_test, safe_push)
+{
+  auto_vec  v;
+  EXPECT_EQ (0, v.length ());
+  v.safe_push (5);
+  v.safe_push (6);
+  v.safe_push (7);
+  EXPECT_EQ (3, v.length ());
+  EXPECT_EQ (5, v[0]);
+  EXPECT_EQ (6, v[1]);
+  EXPECT_EQ (7, v[2]);
+}
+
+TEST_F (vec_test, truncate)
+{
+  auto_vec  v;
+  EXPECT_EQ (0, v.length ());
+  safe_push_range (v, 0, 10);
+  EXPECT_EQ (10, v.length ());
+
+  v.truncate (5);
+  EXPECT_EQ (5, v.length ());
+}
+
+TEST_F (vec_test, safe_grow_cleared)
+{
+  auto_vec  v;
+  EXPECT_EQ (0, v.length ());
+  v.safe_grow_cleared (50);
+  EXPECT_EQ (50, v.length ());
+  EXPECT_EQ (0, v[0]);
+  EXPECT_EQ (0, v[49]);
+}
+
+TEST_F (vec_test, pop)
+{
+  auto_vec  v;
+  safe_push_range (v, 5, 20);
+  EXPECT_EQ (15, v.length ());
+
+  int last = v.pop ();
+  EXPECT_EQ (19, last);
+  EXPECT_EQ (14, v.length ());
+}
+
+TEST_F (vec_test, safe_insert)
+{
+  auto_vec  v;
+  safe_push_range (v, 0, 10);
+  v.safe_insert (5, 42);
+  EXPECT_EQ (4, v[4]);
+  EXPECT_EQ (42, v[5]);
+  EXPECT_EQ (5, v[6]);
+  EXPECT_EQ (11, v.length ());
+}
+
+TEST_F (vec_test, ordered_remove)
+{
+  auto_vec  v;
+  safe_push_range (v, 0, 10);
+  v.ordered_remove (5);
+  EXPECT_EQ (4, v[4]);
+  EXPECT_EQ (6, v[5]);
+  EXPECT_EQ (9, v.length ());
+}
+
+TEST_F (vec_test, unordered_remove)
+{
+  auto_vec  v;
+  safe_push_range (v, 0, 10);
+  v.unordered_remove (5);
+  EXPECT_EQ (9, v.length ());
+}
+
+TEST_F (vec_test, block_remove)
+{
+  auto_vec  v;
+  safe_push_range (v, 0, 10);
+  v.block_remove (5, 3);
+  EXPECT_EQ (3, v[3]);
+  EXPECT_EQ (4, v[4]);
+  EXPECT_EQ (8, v[5]);
+  EXPECT_EQ (9, v[6]);
+  EXPECT_EQ (7, v.length ());
+}
+
+static int reverse_cmp (const void *p_i, const void *p_j)
+{
+  return *(const int *)p_j - *(const int *)p_i;
+}
+
+TEST_F (vec_test, qsort)
+{
+  auto_vec  v;
+  safe_push_range (v, 0, 10);
+  v.qsort (reverse_cmp);
+  EXPECT_EQ (9, v[0]);
+  EXPECT_EQ (8, v[1]);
+  EXPECT_EQ (1, v[8]);
+  EXPECT_EQ (0, v[9]);
+  EXPECT_EQ (10, v.length ());
+}
+
+}  // anon namespace
-- 
1.8.5.3



[PATCH 15/17] Add unittests-frontend.c to gcc/unittests

2015-06-10 Thread David Malcolm
gcc/unittests/ChangeLog:
* unittests-frontend.c: New file.
---
 gcc/unittests/unittests-frontend.c | 250 +
 1 file changed, 250 insertions(+)
 create mode 100644 gcc/unittests/unittests-frontend.c

diff --git a/gcc/unittests/unittests-frontend.c 
b/gcc/unittests/unittests-frontend.c
new file mode 100644
index 000..701c184
--- /dev/null
+++ b/gcc/unittests/unittests-frontend.c
@@ -0,0 +1,250 @@
+/* Dummy "frontend" for use within unittests.
+   Copyright (C) 2013-2015 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "opts.h"
+#include "signop.h"
+#include "hash-set.h"
+#include "fixed-value.h"
+#include "alias.h"
+#include "flags.h"
+#include "symtab.h"
+#include "tree-core.h"
+#include "stor-layout.h"
+#include "tree.h"
+#include "debug.h"
+#include "langhooks.h"
+#include "langhooks-def.h"
+#include "hash-map.h"
+#include "is-a.h"
+#include "plugin-api.h"
+#include "vec.h"
+#include "hashtab.h"
+#include "hash-set.h"
+#include "machmode.h"
+#include "tm.h"
+#include "hard-reg-set.h"
+#include "function.h"
+#include "ipa-ref.h"
+#include "dumpfile.h"
+#include "cgraph.h"
+
+#include 
+
+/* Language-dependent contents of a type.  */
+
+struct GTY(()) lang_type
+{
+  char dummy;
+};
+
+/* Language-dependent contents of a decl.  */
+
+struct GTY((variable_size)) lang_decl
+{
+  char dummy;
+};
+
+/* Language-dependent contents of an identifier.  This must include a
+   tree_identifier.  */
+
+struct GTY(()) lang_identifier
+{
+  struct tree_identifier common;
+};
+
+/* The resulting tree type.  */
+
+union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
+  chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), 
TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL")))
+lang_tree_node
+{
+  union tree_node GTY((tag ("0"),
+  desc ("tree_node_structure (&%h)"))) generic;
+  struct lang_identifier GTY((tag ("1"))) identifier;
+};
+
+/* We don't use language_function.  */
+
+struct GTY(()) language_function
+{
+  int dummy;
+};
+
+/* GC-marking callback for use from unittests_root_tab.
+
+   If there's an active playback context, call its marking method
+   so that it can mark any pointers it references.  */
+
+static void my_ggc_walker (void *)
+{
+}
+
+const char *dummy;
+
+struct ggc_root_tab unittests_root_tab[] =
+  {
+{
+  &dummy, 1, 0, my_ggc_walker, NULL
+},
+LAST_GGC_ROOT_TAB
+  };
+
+/* Language hooks.  */
+
+static bool
+unittests_langhook_init (void)
+{
+  static bool registered_root_tab = false;
+  if (!registered_root_tab)
+{
+  ggc_register_root_tab (unittests_root_tab);
+  registered_root_tab = true;
+}
+
+  build_common_tree_nodes (false, false);
+
+  /* I don't know why this has to be done explicitly.  */
+  void_list_node = build_tree_list (NULL_TREE, void_type_node);
+
+  build_common_builtin_nodes ();
+
+  /* The default precision for floating point numbers.  This is used
+ for floating point constants with abstract type.  This may
+ eventually be controllable by a command line option.  */
+  mpfr_set_default_prec (256);
+
+  return true;
+}
+
+static void
+unittests_langhook_parse_file (void)
+{
+}
+
+static tree
+unittests_langhook_type_for_mode (enum machine_mode mode, int unsignedp)
+{
+  if (mode == TYPE_MODE (float_type_node))
+return float_type_node;
+
+  if (mode == TYPE_MODE (double_type_node))
+return double_type_node;
+
+  if (mode == TYPE_MODE (integer_type_node))
+return unsignedp ? unsigned_type_node : integer_type_node;
+
+  if (mode == TYPE_MODE (long_integer_type_node))
+return unsignedp ? long_unsigned_type_node : long_integer_type_node;
+
+  if (COMPLEX_MODE_P (mode))
+{
+  if (mode == TYPE_MODE (complex_float_type_node))
+   return complex_float_type_node;
+  if (mode == TYPE_MODE (complex_double_type_node))
+   return complex_double_type_node;
+  if (mode == TYPE_MODE (complex_long_double_type_node))
+   return complex_long_double_type_node;
+  if (mode == TYPE_MODE (complex_integer_type_node) && !unsignedp)
+   return complex_integer_type_node;
+}
+
+  /* gcc_unreachable */
+  return NULL;
+}
+
+static tree
+unittests_langhook_type_for_size (unsigned int bits ATTRIBU

[PATCH 06/17] Add test-ggc.c to gcc/unittests

2015-06-10 Thread David Malcolm
gcc/unittests/ChangeLog:
* test-ggc.c: New file.
---
 gcc/unittests/test-ggc.c | 292 +++
 1 file changed, 292 insertions(+)
 create mode 100644 gcc/unittests/test-ggc.c

diff --git a/gcc/unittests/test-ggc.c b/gcc/unittests/test-ggc.c
new file mode 100644
index 000..9168b71
--- /dev/null
+++ b/gcc/unittests/test-ggc.c
@@ -0,0 +1,292 @@
+/* Unit tests for GCC's garbage collector (and gengtype etc).
+   Copyright (C) 2015 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include 
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "opts.h"
+#include "signop.h"
+#include "hash-set.h"
+#include "fixed-value.h"
+#include "alias.h"
+#include "flags.h"
+#include "symtab.h"
+#include "tree-core.h"
+#include "stor-layout.h"
+#include "tree.h"
+#include "stringpool.h"
+#include "stor-layout.h"
+#include "predict.h"
+#include "vec.h"
+#include "hashtab.h"
+#include "hash-set.h"
+#include "machmode.h"
+#include "ggc-internal.h" /* (for ggc_force_collect).  */
+
+/* The various GTY markers must be outside of a namespace to be seen by
+   gengtype, so we don't put this file within an anonymous namespace.  */
+
+/* A test fixture for writing ggc tests.  */
+class ggc_test : public ::testing::Test
+{
+ protected:
+  void
+  forcibly_ggc_collect ()
+  {
+ggc_force_collect = true;
+ggc_collect ();
+ggc_force_collect = false;
+  }
+};
+
+/* Smoketest to ensure that a GC root is marked ("tree" type).  */
+
+static GTY(()) tree dummy_unittesting_tree;
+
+TEST_F (ggc_test, tree_marking)
+{
+  dummy_unittesting_tree = build_int_cst (integer_type_node, 1066);
+
+  forcibly_ggc_collect ();
+
+  EXPECT_TRUE (ggc_marked_p (dummy_unittesting_tree));
+}
+
+/* Verify that a simple custom struct works, and that it can
+   own references to non-roots, and have them be marked.  */
+
+struct GTY(()) test_struct
+{
+  test_struct *other;
+};
+
+static GTY(()) test_struct *root_test_struct;
+
+TEST_F (ggc_test, custom_struct)
+{
+  root_test_struct = ggc_cleared_alloc  ();
+  root_test_struct->other = ggc_cleared_alloc  ();
+
+  forcibly_ggc_collect ();
+
+  EXPECT_TRUE (ggc_marked_p (root_test_struct));
+  EXPECT_TRUE (ggc_marked_p (root_test_struct->other));
+}
+
+/* Verify that destructors get run when instances are collected.  */
+
+struct GTY(()) test_struct_with_dtor
+{
+  /* This struct has a destructor; it *ought* to be called
+ by the ggc machinery when instances are collected.  */
+  ~test_struct_with_dtor () { dtor_call_count++; }
+
+  static int dtor_call_count;
+};
+
+int test_struct_with_dtor::dtor_call_count;
+
+TEST_F (ggc_test, finalization)
+{
+  EXPECT_FALSE (need_finalization_p  ());
+  EXPECT_TRUE (need_finalization_p  ());
+
+  /* Create some garbage.  */
+  const int count = 10;
+  for (int i = 0; i < count; i++)
+ggc_cleared_alloc  ();
+
+  test_struct_with_dtor::dtor_call_count = 0;
+
+  forcibly_ggc_collect ();
+
+  /* Verify that the destructor was run for each instance.  */
+  EXPECT_EQ (count, test_struct_with_dtor::dtor_call_count);
+}
+
+/* Verify that a global can be marked as "deletable".  */
+
+static GTY((deletable)) test_struct *test_of_deletable;
+
+TEST_F (ggc_test, deletable_global)
+{
+  test_of_deletable = ggc_cleared_alloc  ();
+  EXPECT_TRUE (test_of_deletable != NULL);
+
+  forcibly_ggc_collect ();
+
+  EXPECT_EQ (NULL, test_of_deletable);
+}
+
+/* Verify that gengtype etc can cope with inheritance.  */
+
+class GTY((desc("%h.m_kind"), tag("0"))) example_base
+{
+ public:
+  example_base ()
+: m_kind (0),
+  m_a (ggc_cleared_alloc  ())
+  {}
+
+  void *
+  operator new (size_t sz)
+  {
+return ggc_internal_cleared_alloc (sz);
+  }
+
+ protected:
+  example_base (int kind)
+: m_kind (kind),
+  m_a (ggc_cleared_alloc  ())
+  {}
+
+ public:
+  int m_kind;
+  test_struct *m_a;
+};
+
+class GTY((tag("1"))) some_subclass : public example_base
+{
+ public:
+  some_subclass ()
+: example_base (1),
+  m_b (ggc_cleared_alloc  ())
+  {}
+
+  test_struct *m_b;
+};
+
+class GTY((tag("2"))) some_other_subclass : public example_base
+{
+ public:
+  some_other_subclass ()
+: example_base (2),
+  m_c (ggc_cleared_alloc  ())
+  {}
+
+  test_struct *m_c;
+};
+
+/* Various test roots, both expressed as a ptr to the actual class, and
+   as a ptr to the base class.  */
+

[PATCH 14/17] Add test-wide-int.c to gcc/unittests

2015-06-10 Thread David Malcolm
gcc/unittests/ChangeLog:
* test-wide-int.c: New file.
---
 gcc/unittests/test-wide-int.c | 186 ++
 1 file changed, 186 insertions(+)
 create mode 100644 gcc/unittests/test-wide-int.c

diff --git a/gcc/unittests/test-wide-int.c b/gcc/unittests/test-wide-int.c
new file mode 100644
index 000..089e80d
--- /dev/null
+++ b/gcc/unittests/test-wide-int.c
@@ -0,0 +1,186 @@
+/* Unit tests for wide-int.
+   Copyright (C) 2015 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include 
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "opts.h"
+#include "signop.h"
+#include "hash-set.h"
+#include "fixed-value.h"
+#include "alias.h"
+#include "flags.h"
+#include "symtab.h"
+#include "tree-core.h"
+#include "stor-layout.h"
+#include "tree.h"
+#include "stringpool.h"
+#include "stor-layout.h"
+#include "rtl.h"
+#include "wide-int-print.h"
+
+namespace {
+
+/* The types we will run the testcases for.  */
+typedef ::testing::Types implementations;
+
+/* A fixture for running the same tests for all of the wide-int.h types
+   listed in "implementations" above.
+
+   Unfortunately, for some reason gtest reports all of the tests as:
+   of type "":
+ [--] 2 tests from wide_int_test/0, where TypeParam = 
+   (snip)
+ [--] 2 tests from wide_int_test/0 (0 ms total)
+ [--] 2 tests from wide_int_test/1, where TypeParam = 
+   (snip)
+ [--] 2 tests from wide_int_test/1 (0 ms total)
+ [--] 2 tests from wide_int_test/2, where TypeParam = 
+   (snip)
+ [--] 2 tests from wide_int_test/2 (0 ms total)
+*/
+
+template 
+class wide_int_test : public ::testing::Test
+{
+ protected:
+  /* Helper function for building a test value.  */
+  VALUE_TYPE from_int (int i);
+};
+
+TYPED_TEST_CASE(wide_int_test, implementations);
+
+/* Specializations of the fixture for each wide-int type.  */
+
+template <>
+wide_int
+wide_int_test ::from_int (int i)
+{
+  return wi::shwi (i, 32);
+}
+
+template <>
+offset_int
+wide_int_test ::from_int (int i)
+{
+  return offset_int (i);
+}
+
+template <>
+widest_int
+wide_int_test ::from_int (int i)
+{
+  return widest_int (i);
+}
+
+/* Verify that print_dec (WI, ..., SGN) gives the expected string
+   representation (using base 10).  */
+
+void
+expect_deceq (const char *expected, const wide_int_ref &wi, signop sgn)
+{
+  char buf[WIDE_INT_PRINT_BUFFER_SIZE];
+  print_dec (wi, buf, sgn);
+  EXPECT_STREQ (expected, buf);
+}
+
+/* Likewise for base 16.  */
+
+void
+expect_hexeq (const char *expected, const wide_int_ref &wi)
+{
+  char buf[WIDE_INT_PRINT_BUFFER_SIZE];
+  print_hex (wi, buf);
+  EXPECT_STREQ (expected, buf);
+}
+
+/* Test cases.  These will be run for each type in "implementations" above,
+   with gtest's TYPED_TEST macro defining the types "TypeParam"
+   and "TestFixture".  */
+
+TYPED_TEST (wide_int_test, test_printing)
+{
+  TypeParam a = TestFixture::from_int (42);
+  expect_deceq ("42", a, SIGNED);
+  expect_hexeq ("0x2a", a);
+}
+
+TYPED_TEST (wide_int_test, test_ops)
+{
+  TypeParam a = TestFixture::from_int (7);
+  TypeParam b = TestFixture::from_int (3);
+
+  /* Using functions.  */
+  expect_deceq ("-7", wi::neg (a), SIGNED);
+  expect_deceq ("10", wi::add (a, b), SIGNED);
+  expect_deceq ("4", wi::sub (a, b), SIGNED);
+  expect_deceq ("-4", wi::sub (b, a), SIGNED);
+  expect_deceq ("21", wi::mul (a, b), SIGNED);
+
+  /* Using operators.  */
+  expect_deceq ("-7", -a, SIGNED);
+  expect_deceq ("10", a + b, SIGNED);
+  expect_deceq ("4", a - b, SIGNED);
+  expect_deceq ("-4", b - a, SIGNED);
+  expect_deceq ("21", a * b, SIGNED);
+}
+
+TYPED_TEST (wide_int_test, test_comparisons)
+{
+  TypeParam a = TestFixture::from_int (7);
+  TypeParam b = TestFixture::from_int (3);
+
+  /* == */
+  EXPECT_TRUE (wi::eq_p (a, a));
+  EXPECT_FALSE (wi::eq_p (a, b));
+
+  /* != */
+  EXPECT_TRUE (wi::ne_p (a, b));
+  EXPECT_FALSE (wi::ne_p (a, a));
+
+  /* < */
+  EXPECT_FALSE (wi::lts_p (a, a));
+  EXPECT_FALSE (wi::lts_p (a, b));
+  EXPECT_TRUE (wi::lts_p (b, a));
+
+  /* <= */
+  EXPECT_TRUE (wi::les_p (a, a));
+  EXPECT_FALSE (wi::les_p (a, b));
+  EXPECT_TRUE (wi::les_p (b, a));
+
+  /* > */
+  EXPECT_FALSE (wi::gts_p (a, a));
+  EXPECT_TRUE (wi::gts_p (a, b));
+  EXPECT_FALSE (wi::gts_p (b, a));
+
+  /* >= */
+ 

Re: [PATCH 00/17] RFC: Addding a unit testing framework to gcc

2015-06-10 Thread Jakub Jelinek
On Wed, Jun 10, 2015 at 11:24:41AM -0400, David Malcolm wrote:
> I picked the Google Test framework:
>   http://code.google.com/p/googletest/

I must say I'm not very excited about using this, it won't integrate
very well with dejagnu, whether talking about results (will it provide
some *.log/*.sum file with FAIL/XFAIL/PASS/XPASS etc. lines?), choosing
what options to use, e.g. global
RUNTESTFLAGS='--target_board=unix/\{-m32,-m64\}'
to test everything twice for 32-bit and 64-bit, will that run just
all unittests twice the same?, or possibility to run a subset of tests
etc.
E.g. for asan.exp testing, I just wrote a gtest emulation using
dejagnu, see testsuite/g++.dg/asan/dejagnu-gtest.h and
testsuite/lib/asan-dg.exp, but that was mainly meant for cases where
many routines are expected to crash the process.  If in unittests
you are doing only operations that aren't meant to take everything down or
if they crash, it is ok if it breaks the whole unit testing,
then perhaps it can be run as a single process and thus a single dejagnu
job, and just let the wrapper parse the output and transform it.

Also, no matter what testsuite framework is used, including any
headers before #include "config.h" line is a big no-no.

Jakub


Re: [PATCH 00/17] RFC: Addding a unit testing framework to gcc

2015-06-10 Thread Richard Biener
On June 10, 2015 5:34:47 PM GMT+02:00, Jakub Jelinek  wrote:
>On Wed, Jun 10, 2015 at 11:24:41AM -0400, David Malcolm wrote:
>> I picked the Google Test framework:
>>   http://code.google.com/p/googletest/
>
>I must say I'm not very excited about using this, it won't integrate
>very well with dejagnu, whether talking about results (will it provide
>some *.log/*.sum file with FAIL/XFAIL/PASS/XPASS etc. lines?), choosing
>what options to use, e.g. global
>RUNTESTFLAGS='--target_board=unix/\{-m32,-m64\}'
>to test everything twice for 32-bit and 64-bit, will that run just
>all unittests twice the same?, or possibility to run a subset of tests
>etc.
>E.g. for asan.exp testing, I just wrote a gtest emulation using
>dejagnu, see testsuite/g++.dg/asan/dejagnu-gtest.h and
>testsuite/lib/asan-dg.exp, but that was mainly meant for cases where
>many routines are expected to crash the process.  If in unittests
>you are doing only operations that aren't meant to take everything down
>or
>if they crash, it is ok if it breaks the whole unit testing,
>then perhaps it can be run as a single process and thus a single
>dejagnu
>job, and just let the wrapper parse the output and transform it.
>
>Also, no matter what testsuite framework is used, including any
>headers before #include "config.h" line is a big no-no.

Agreed.  I think it is reasonable to instead do like the two existing tests - 
piggy back on a plugin testcase.

Richard.

>   Jakub




Re: Fortran's C_CHAR type

2015-06-10 Thread Mikael Morin
Le 10/06/2015 16:38, Jan Hubicka a écrit :
>>> [jh@gcc2-power8 gcc]$ cat ../b.f90
>>> ! This testcase will abort if C_CHAR types are not interoperable
>>> module lto_type_merge_test
>>>   use, intrinsic :: iso_c_binding
>>>   implicit none
>>>
>>> contains
>>>   function types_test1(V) bind(c)
>>> USE, INTRINSIC :: ISO_C_BINDING
>>> CHARACTER(C_CHAR) :: types_test1
>>> CHARACTER(C_CHAR), VALUE :: V
>>> types_test1 = V
>>>   end function types_test1
>>> end module lto_type_merge_test
>>>
>>> [jh@gcc2-power8 gcc]$ cat ../a.c
>>> extern unsigned char types_test1 (char v);
>>> void
>>> main ()
>>> { 
>>>   if (types_test1 ('a') != 'a')
>>> __builtin_abort ();
>>>   return 0;
>>> }
>>>
>>> As my fortran-fu goes, i think this testcase is correct. Fortran FE however
>>> builds types_test1 as a function return char but taking the array of size 
>>> of 1
>>> as a parameter.
>> C_CHAR is a named constant of value 1 (the number of bytes of a char),
>> and character(foo) declares a string of length foo and default kind
>> (which is 1 for character types).
>> So it is expected that the argument is an array.
> 
> I see, what is the reason for assymetry for return value to not be array in 
> this case?

There is this in gfc_sym_type:

  if (sym->ts.type == BT_CHARACTER
  && ((sym->attr.function && sym->attr.is_bind_c)
  || (sym->attr.result
  && sym->ns->proc_name
  && sym->ns->proc_name->attr.is_bind_c)
  || (sym->ts.deferred && (!sym->ts.u.cl
   || !sym->ts.u.cl->backend_decl
type = gfc_character1_type_node;
  else
type = gfc_typenode_for_spec (&sym->ts);


And gfc_character1_type_node is defined as a plain char, it seems.
I don't know about the reason for either.

> 
>> If you want to declare a single character, you have to use an integer of
>> kind 1.
>> types_test1's result and v should have type integer(c_char), I think.
> 
> I will fix the testcase accordingly.  I basicallly copied what is in table
> 15.2 of the Fortran 2008 draft that explicitely lists Fortran type CHARACTER
> if kind C_CHAR compatible with "char". On the other hand there are no examples
> in the standard that would suggest that this should work this way.
> It only shows stuff like
>  CHARACTER(KIND=C_CHAR), DIMENSION(*) :: IN, OUT
> which corresponds to char []
> 
> Is my testcase supposed to work if I simply add KIND= before "C_CHAR"
> 
I have had a look at the table and the text around, and first I should
correct myself.
C_CHAR is 1, C_SIGNED_CHAR is 1, and the default values for len= and
kind= are 1 as well.
So, even if CHARACTER(KIND=C_CHAR) is what should be used as it's not
dependent on the implementation's default kind choice, it boils down to
the same as CHARACTER(C_CHAR), namely CHARACTER(len=1, kind=1) actually.


And about the line saying CHARACTER(KIND=C_CHAR) interoperable with char
in table 15.2:
You're right, while I would myself prefer to use an
INTEGER(KIND=C_SIGNED_CHAR) type, CHARACTER(KIND=C_CHAR) should be
supported as well.
That means that char should be compatible with char[1], I think.
You said there is no guarantee they are passed the same way?


> If you can look at the other c-bind testcases I produced, I would really 
> appreachiate that.
I have looked at:
https://gcc.gnu.org/ml/gcc-patches/2015-06/msg00693.html
https://gcc.gnu.org/ml/gcc-patches/2015-06/msg00713.html
I saw nothing wrong with the tests.
Avoiding character interoperability avoids most of the pain. ;-)

Mikael


Re: [PATCH] PR 66474, Document using %x for VSX registers on PowerPC

2015-06-10 Thread Michael Meissner
On Tue, Jun 09, 2015 at 08:28:35PM -0400, David Edelsohn wrote:
> On Tue, Jun 9, 2015 at 3:26 PM, Michael Meissner
>  wrote:
> > On Tue, Jun 09, 2015 at 02:17:19PM -0500, Segher Boessenkool wrote:
> >> On Tue, Jun 09, 2015 at 02:00:48PM -0400, Michael Meissner wrote:
> >> > +asm ("xvadddp %x0,%x1,%x2" "=wa" (v1) : "wa" (v2), "wa" (v3));
> >>
> >> A colon went missing?   ^^^
> >
> > Yes, I will correct it when I check it in.  Thanks.
> 
> Mike,
> 
> VSX registers are a superset of Altivec registers, so the statement
> about an Altivec register used where a VSX register is expected is a
> little confusing.  How about:
> 
> Otherwise the register number output in the assembly file will be
> incorrect if an Altivec register is an operand of a VSX instruction
> that expects VSX register numbering.

The re-wording is fine with me.  I will check in the patch.  Thanks.

-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meiss...@linux.vnet.ibm.com, phone: +1 (978) 899-4797



Re: [PATCH 00/17] RFC: Addding a unit testing framework to gcc

2015-06-10 Thread David Malcolm
On Wed, 2015-06-10 at 17:34 +0200, Jakub Jelinek wrote:
> On Wed, Jun 10, 2015 at 11:24:41AM -0400, David Malcolm wrote:
> > I picked the Google Test framework:
> >   http://code.google.com/p/googletest/
> 
> I must say I'm not very excited about using this, it won't integrate
> very well with dejagnu

Why is that a goal?  I've been using DejaGnu's unittesting API for
testing the jit, and it is... suboptimal, to put it mildly.

> whether talking about results (will it provide
> some *.log/*.sum file with FAIL/XFAIL/PASS/XPASS etc. lines?),

It doesn't have an output formatter for the DejaGnu format, but I guess
I could write one.  The gtest standard output format is IMHO superior to
DejaGnu's since it tells you start-of-test/end-of-test on separate
lines, so you can see which test killed things in the event of total
failure, and the per-test timings (which can be disabled if you want to
do diffs).

>  choosing
> what options to use, e.g. global
> RUNTESTFLAGS='--target_board=unix/\{-m32,-m64\}'
> to test everything twice for 32-bit and 64-bit, will that run just
> all unittests twice the same?,

Fair enough; yes, as written, RUNTESTFLAGS is ignored; it will run
everything once.  However we could express such a loop directly in the
"main" of the 

> or possibility to run a subset of tests

$ LD_LIBRARY_PATH=. ./unittests.exe --gtest_filter="*push"
Note: Google Test filter = *push
[==] Running 2 tests from 1 test case.
[--] Global test environment set-up.
[--] 2 tests from vec_test
[ RUN  ] vec_test.quick_push
[   OK ] vec_test.quick_push (0 ms)
[ RUN  ] vec_test.safe_push
[   OK ] vec_test.safe_push (0 ms)
[--] 2 tests from vec_test (1 ms total)

[--] Global test environment tear-down
[==] 2 tests from 1 test case ran. (4 ms total)
[  PASSED  ] 2 tests.

> etc.
> E.g. for asan.exp testing, I just wrote a gtest emulation using
> dejagnu, see testsuite/g++.dg/asan/dejagnu-gtest.h and
> testsuite/lib/asan-dg.exp

...which doesn't have things like EXPECT_STREQ, or custom comparators,
doesn't appear to support fixtures, type-parameterized tests,
value-parameterized tests, etc, my point being that a unit-testing
framework is a non-trivial amount of code that could do useful things
for us.

> but that was mainly meant for cases where
> many routines are expected to crash the process.

FWIW, if I'm reading testsuite/g++.dg/asan/dejagnu-gtest.h and
testsuite/lib/asan-dg.exp correctly, it looks like you're spawning the
tool once per EXPECT_DEATH instance in the testsuite.  That seems
suboptimal, gtest uses fork without exec
to do it all directly at the point of the test without lots of extra
work, where the parent verifies the death of the child.

>   If in unittests
> you are doing only operations that aren't meant to take everything down or
> if they crash, it is ok if it breaks the whole unit testing,
> then perhaps it can be run as a single process and thus a single dejagnu
> job, and just let the wrapper parse the output and transform it.

I guess, but having used google test lately, DejaGnu feels like a big
step backwards.

> Also, no matter what testsuite framework is used, including any
> headers before #include "config.h" line is a big no-no.

OK.  Can't remember why I did that.


Dave



[gomp4.1] Add support for array sections in OpenMP reduction clause

2015-06-10 Thread Jakub Jelinek
Hi!

In C/C++, OpenMP 4.1 is going to allow array sections and arrays in
reduction clauses.  This patch implements it.  Committed to gomp-4_1-branch.

2015-06-10  Jakub Jelinek  

* tree.c (omp_clause_num_ops): Bump number of OMP_CLAUSE_REDUCTION
arguments to 5.
(walk_tree_1): Adjust for 5 instead of 4 OMP_CLAUSE_REDUCTION
arguments.
* tree-core.h (OMP_CLAUSE_REDUCTION): Document
OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER.
* tree.h (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER): Define.
* tree-nested.c (convert_nonlocal_omp_clauses,
convert_local_omp_clauses): Temporarily adjust context of
OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER too if non-NULL.
* gimplify.c (omp_add_variable): Call omp_notice_variable
on TYPE_SIZE_UNIT only if it is a DECL_P.
(find_decl_expr): New function.
(gimplify_scan_omp_clauses): Handle OMP_CLAUSE_REDUCTION
with MEM_REF OMP_CLAUSE_DECL.
* omp-low.c (scan_sharing_clauses, lower_rec_input_clauses,
lower_reduction_clauses, lower_send_clauses): Likewise.
gcc/c/
* c-parser.c (c_parser_omp_variable_list): Allow array sections
for OMP_CLAUSE_REDUCTION.
(c_parser_omp_clause_reduction): Compute element type even for
arrays and array sections.
(c_parser_omp_declare_reduction): STRIP_NOPS before checking
for &omp_priv.
* c-typeck.c (handle_omp_array_sections_1): Fix a comment typo.
Handle OMP_CLAUSE_REDUCTION array sections.  Report zero size
array sections on OMP_CLAUSE_DEPEND.
(handle_omp_array_sections): Use auto_vec for types, drop
types.release () calls.  Handle OMP_CLAUSE_REDUCTION array sections.
(c_finish_omp_clauses): Handle OMP_CLAUSE_REDUCTION array sections
and arrays.
gcc/cp/
* parser.c (cp_parser_omp_var_list_no_open): Allow array sections
for OMP_CLAUSE_REDUCTION.
* semantics.c (omp_clause_decl_field, omp_note_field_privatization,
omp_privatize_field): New functions.
(omp_clause_printable_decl): Use omp_clause_decl_field, move
earlier.
(handle_omp_array_sections_1): Fix a comment typo.
Handle OMP_CLAUSE_REDUCTION array sections.  Report zero size
array sections on OMP_CLAUSE_DEPEND.
(handle_omp_array_sections): Handle OMP_CLAUSE_REDUCTION array
sections.
(finish_omp_reduction_clause): Handle OMP_CLAUSE_REDUCTION array
sections and arrays.
(finish_omp_clauses): Likewise.  Use omp_note_field_privatization,
omp_clause_decl_field and omp_privatize_field.
gcc/c-family/
* c-omp.c (c_omp_split_clauses): Copy over also
OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER.
gcc/testsuite/
* gcc.dg/gomp/clause-1.c (foo): Remove one dg-error directive.
* g++.dg/gomp/clause-3.C (foo): Likewise.
* gcc.dg/gomp/reduction-1.c: New test.
* c-c++-common/gomp/depend-3.c: New test.
* c-c++-common/gomp/reduction-1.c: New test.
* c-c++-common/gomp/udr-1.c: New test.
libgomp/
* testsuite/libgomp.c/reduction-7.c: New test.
* testsuite/libgomp.c/reduction-8.c: New test.
* testsuite/libgomp.c/reduction-9.c: New test.
* testsuite/libgomp.c/reduction-10.c: New test.
* testsuite/libgomp.c++/taskloop-5.C (foo): Wrap #pragma omp
parallel bodies into #pragma omp single.
* testsuite/libgomp.c++/reduction-5.C: New test.
* testsuite/libgomp.c++/reduction-6.C: New test.
* testsuite/libgomp.c++/reduction-7.C: New test.
* testsuite/libgomp.c++/reduction-8.C: New test.
* testsuite/libgomp.c++/reduction-9.C: New test.
* testsuite/libgomp.c++/reduction-10.C: New test.

--- gcc/tree.c.jj   2015-05-19 18:56:50.0 +0200
+++ gcc/tree.c  2015-06-08 10:49:02.965545605 +0200
@@ -321,7 +321,7 @@ unsigned const char omp_clause_num_ops[]
   1, /* OMP_CLAUSE_SHARED  */
   1, /* OMP_CLAUSE_FIRSTPRIVATE  */
   2, /* OMP_CLAUSE_LASTPRIVATE  */
-  4, /* OMP_CLAUSE_REDUCTION  */
+  5, /* OMP_CLAUSE_REDUCTION  */
   1, /* OMP_CLAUSE_COPYIN  */
   1, /* OMP_CLAUSE_COPYPRIVATE  */
   3, /* OMP_CLAUSE_LINEAR  */
@@ -11361,7 +11361,7 @@ walk_tree_1 (tree *tp, walk_tree_fn func
case OMP_CLAUSE_REDUCTION:
  {
int i;
-   for (i = 0; i < 4; i++)
+   for (i = 0; i < 5; i++)
  WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, i));
WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
  }
--- gcc/tree-core.h.jj  2015-05-06 17:04:52.0 +0200
+++ gcc/tree-core.h 2015-06-08 11:08:41.914555026 +0200
@@ -230,7 +230,10 @@ enum omp_clause_code {
  Operand 2: OMP_CLAUSE_REDUCTION_MERGE: Stmt-list to merge private var
 into the shared one.
  Operand 3: OMP_CLAUSE_REDUCTION_PLACEHOLDER: A dummy VAR_DECL
-placeholder used in OMP_CLAUSE_REDUCTION_{INIT,MERGE}.  *

C/C++ PATCH to smarten up -Wswitch-bool (PR c/66322)

2015-06-10 Thread Marek Polacek
Linus's kind words here  prodded
me to improving the -Wswitch-bool warning.  In particular, this patch
makes the warning not warn when the case values aren't outside bool
range.  But it will still warn about

  switch (boolean)
{
case false ... true: ...
default: ...
}

That of course means that the warning must be delayed to the point where
all the case labels have been parsed.  Then there are these annoying
differences between C and C++ (type of a comparison), which means some
splay trees fun.  Another problem stems from the fact that case labels
that are outside the range of the original type of the switch controlling
expression are dropped on the floor, so I had to add the OUTSIDE_RANGE_P
flag.  Case ranges are fun as well.

If this patch is approved, I'd like to backport it even to 5 branch after
some time so it's fixed in 5.2.

There's also the possibility to add -Wswitch-bool=2 that would warn every
time the compiler sees a switch with a boolean controlling expr, i.e. do
what we're doing now.  But that would be something for trunk only.

Thoughts?

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

2015-06-10  Marek Polacek  

PR c/66322
* c-common.c (check_case_bounds): Add bool * parameter.  Set
OUTSIDE_RANGE_P.
(c_add_case_label): Add bool * parameter.  Pass it down to
check_case_bounds.
(c_do_switch_warnings): Add bool parameters.  Implement -Wswitch-bool
warning here.
* c-common.h (c_add_case_label, c_do_switch_warnings): Update
declarations.

* c-typeck.c (struct c_switch): Add BOOL_COND_P and OUTSIDE_RANGE_P.
(c_start_case): Set BOOL_COND_P and OUTSIDE_RANGE_P.  Don't warn
about -Wswitch-bool here.
(do_case): Update c_add_case_label call.
(c_finish_case): Update c_do_switch_warnings call.

* decl.c (struct cp_switch): Add OUTSIDE_RANGE_P.
(push_switch): Set OUTSIDE_RANGE_P.
(pop_switch): Update c_do_switch_warnings call.
(finish_case_label): Update c_add_case_label call.
* semantics.c (finish_switch_cond): Don't warn about -Wswitch-bool
here.

* function.c (stack_protect_epilogue): Remove a cast to int.
* doc/invoke.texi: Update -Wswitch-bool description.

* c-c++-common/pr60439.c: Add dg-prune-output and add switch cases.
* c-c++-common/pr66322.c: New test.
* g++.dg/eh/scope1.C: Remove dg-warning.

diff --git gcc/doc/invoke.texi gcc/doc/invoke.texi
index 5903c75..3746de7 100644
--- gcc/doc/invoke.texi
+++ gcc/doc/invoke.texi
@@ -4012,7 +4012,8 @@ warning about an omitted enumeration code even if there 
is a
 @item -Wswitch-bool
 @opindex Wswitch-bool
 @opindex Wno-switch-bool
-Warn whenever a @code{switch} statement has an index of boolean type.
+Warn whenever a @code{switch} statement has an index of boolean type
+and the case values are outside the range of a boolean type.
 It is possible to suppress this warning by casting the controlling
 expression to a type other than @code{bool}.  For example:
 @smallexample
diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
index 5b76567..6f9f056 100644
--- gcc/c-family/c-common.c
+++ gcc/c-family/c-common.c
@@ -312,7 +312,8 @@ struct visibility_flags visibility_options;
 
 static tree c_fully_fold_internal (tree expr, bool, bool *, bool *, bool);
 static tree check_case_value (location_t, tree);
-static bool check_case_bounds (location_t, tree, tree, tree *, tree *);
+static bool check_case_bounds (location_t, tree, tree, tree *, tree *,
+  bool *);
 
 static tree handle_packed_attribute (tree *, tree, tree, int, bool *);
 static tree handle_nocommon_attribute (tree *, tree, tree, int, bool *);
@@ -3639,13 +3640,15 @@ check_case_value (location_t loc, tree value)
bound of the case label, and CASE_HIGH_P is the upper bound or NULL
if the case is not a case range.
The caller has to make sure that we are not called with NULL for
-   CASE_LOW_P (i.e. the default case).
+   CASE_LOW_P (i.e. the default case).  OUTSIDE_RANGE_P says whether there
+   was a case value that doesn't fit into the range of the ORIG_TYPE.
Returns true if the case label is in range of ORIG_TYPE (saturated or
untouched) or false if the label is out of range.  */
 
 static bool
 check_case_bounds (location_t loc, tree type, tree orig_type,
-  tree *case_low_p, tree *case_high_p)
+  tree *case_low_p, tree *case_high_p,
+  bool *outside_range_p)
 {
   tree min_value, max_value;
   tree case_low = *case_low_p;
@@ -3664,6 +3667,7 @@ check_case_bounds (location_t loc, tree type, tree 
orig_type,
 {
   warning_at (loc, 0, "case label value is less than minimum value "
  "for type");
+  *outside_range_p = true;
   return false;
 }
 
@@ -3672,6 +3676,7 @@ check_case_bounds (location_t loc, tree type,

Re: [PATCH 00/17] RFC: Addding a unit testing framework to gcc

2015-06-10 Thread David Malcolm
On Wed, 2015-06-10 at 17:34 +0200, Jakub Jelinek wrote:
> On Wed, Jun 10, 2015 at 11:24:41AM -0400, David Malcolm wrote:
(...snip...)

> Also, no matter what testsuite framework is used, including any
> headers before #include "config.h" line is a big no-no.

The issue was that libiberty/safe-ctype.h
has various macros of the form:
  #define toupper(c) do_not_use_toupper_with_safe_ctype

which, if I include gtest.h last, breaks the STL e.g. in 
  const char_type*
  toupper(char_type *__lo, const char_type* __hi) const
  { return this->do_toupper(__lo, __hi); }

/usr/include/c++/4.8.3/bits/locale_facets.h:240:53: error: macro
"toupper" passed 2 arguments, but takes just 1
   toupper(char_type *__lo, const char_type* __hi) const
 ^
Adding a #undef of these things before including gtest.h fixes it,
though we then run into:

In file included from /usr/include/gtest/internal/gtest-internal.h:40:0,
 from /usr/include/gtest/gtest.h:57,
 from ../../src/gcc/unittests/test-tree.c:73:
/usr/include/gtest/internal/gtest-port.h:1595:47: error: attempt to use
poisoned "strdup"
 inline char* StrDup(const char* src) { return strdup(src); }
   ^
/usr/include/gtest/internal/gtest-port.h:1638:50: error: attempt to use
poisoned "strerror"
 inline const char* StrError(int errnum) { return strerror(errnum); }
  ^

FWIW this goes away if I simply include gtest.h immediately after
config.h, but before system.h.


Dave



[PATCH, i386]: Fix PR 66473, unrecognizable insn with -mavx512f

2015-06-10 Thread Uros Bizjak
Hello!

Again the case of pushing an out-of-range constant to a mode register.

2015-10-03  Uros Bizjak  

PR target/66473
* config/i386/i386.c (ix86_expand_vector_set): Use gen_int_mode
to prepare mask operand for AVX512 modes.

testsuite/ChangeLog:

2015-10-03  Uros Bizjak  

PR target/66473
* gcc.target/i386/pr66473.c: New test.

Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.
Committed to mainline and gcc-5 branch.

Uros.
Index: config/i386/i386.c
===
--- config/i386/i386.c  (revision 224330)
+++ config/i386/i386.c  (working copy)
@@ -44720,6 +44720,8 @@ ix86_expand_vector_set (bool mmx_ok, rtx target, r
{ gen_vec_set_lo_v4df, gen_vec_set_hi_v4df }
   };
   int i, j, n;
+  machine_mode mmode = VOIDmode;
+  rtx (*gen_blendm) (rtx, rtx, rtx, rtx);
 
   switch (mode)
 {
@@ -44936,76 +44938,65 @@ half:
 case V8DFmode:
   if (TARGET_AVX512F)
{
- tmp = gen_reg_rtx (mode);
- emit_insn (gen_rtx_SET (tmp, gen_rtx_VEC_DUPLICATE (mode, val)));
- emit_insn (gen_avx512f_blendmv8df (target, tmp, target,
-force_reg (QImode, GEN_INT (1 << 
elt;
- return;
+ mmode = QImode;
+ gen_blendm = gen_avx512f_blendmv8df;
}
-  else
-   break;
+  break;
+
 case V8DImode:
   if (TARGET_AVX512F)
{
- tmp = gen_reg_rtx (mode);
- emit_insn (gen_rtx_SET (tmp, gen_rtx_VEC_DUPLICATE (mode, val)));
- emit_insn (gen_avx512f_blendmv8di (target, tmp, target,
-force_reg (QImode, GEN_INT (1 << 
elt;
- return;
+ mmode = QImode;
+ gen_blendm = gen_avx512f_blendmv8di;
}
-  else
-   break;
+  break;
+
 case V16SFmode:
   if (TARGET_AVX512F)
{
- tmp = gen_reg_rtx (mode);
- emit_insn (gen_rtx_SET (tmp, gen_rtx_VEC_DUPLICATE (mode, val)));
- emit_insn (gen_avx512f_blendmv16sf (target, tmp, target,
- force_reg (HImode, GEN_INT (1 << 
elt;
- return;
+ mmode = HImode;
+ gen_blendm = gen_avx512f_blendmv16sf;
}
-  else
-   break;
+  break;
+
 case V16SImode:
   if (TARGET_AVX512F)
{
- tmp = gen_reg_rtx (mode);
- emit_insn (gen_rtx_SET (tmp, gen_rtx_VEC_DUPLICATE (mode, val)));
- emit_insn (gen_avx512f_blendmv16si (target, tmp, target,
- force_reg (HImode, GEN_INT (1 << 
elt;
- return;
+ mmode = HImode;
+ gen_blendm = gen_avx512f_blendmv16si;
}
-  else
-   break;
+  break;
+
 case V32HImode:
   if (TARGET_AVX512F && TARGET_AVX512BW)
{
- tmp = gen_reg_rtx (mode);
- emit_insn (gen_rtx_SET (tmp, gen_rtx_VEC_DUPLICATE (mode, val)));
- emit_insn (gen_avx512bw_blendmv32hi (target, tmp, target,
-  force_reg (SImode, GEN_INT (1 << 
elt;
- return;
+ mmode = SImode;
+ gen_blendm = gen_avx512bw_blendmv32hi;
}
-  else
-   break;
+  break;
+
 case V64QImode:
   if (TARGET_AVX512F && TARGET_AVX512BW)
{
- tmp = gen_reg_rtx (mode);
- emit_insn (gen_rtx_SET (tmp, gen_rtx_VEC_DUPLICATE (mode, val)));
- emit_insn (gen_avx512bw_blendmv64qi (target, tmp, target,
-  force_reg (DImode, GEN_INT (1 << 
elt;
- return;
+ mmode = DImode;
+ gen_blendm = gen_avx512bw_blendmv64qi;
}
-  else
-   break;
+  break;
 
 default:
   break;
 }
 
-  if (use_vec_merge)
+  if (mmode != VOIDmode)
 {
+  tmp = gen_reg_rtx (mode);
+  emit_insn (gen_rtx_SET (tmp, gen_rtx_VEC_DUPLICATE (mode, val)));
+  emit_insn (gen_blendm (target, tmp, target,
+force_reg (mmode,
+   gen_int_mode (1 << elt, mmode;
+}
+  else if (use_vec_merge)
+{
   tmp = gen_rtx_VEC_DUPLICATE (mode, val);
   tmp = gen_rtx_VEC_MERGE (mode, tmp, target, GEN_INT (1 << elt));
   emit_insn (gen_rtx_SET (target, tmp));
Index: testsuite/gcc.target/i386/pr66473.c
===
--- testsuite/gcc.target/i386/pr66473.c (revision 0)
+++ testsuite/gcc.target/i386/pr66473.c (working copy)
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512f" } */
+
+typedef double __m512d __attribute__ ((__vector_size__ (64)));
+
+extern __m512d _ZGVeN8v_func (__m512d);
+
+double
+func_vlen8 (double x)
+{
+  __m512d mx, mr;
+
+  mx[0] = mx[1] = mx[2] = mx[3] = mx[4] = mx[5] = mx[6] = mx[7] = x;
+  mr = _ZGVeN8v_func (mx);
+
+  return (double) mr[0];
+}


[PATCH, testsuite]: Add -save-temps to g++.dg/abi/mangle-regparm.C

2015-06-10 Thread Uros Bizjak
Hello!

The runtime testcase needs -save-temps in order to use scan-assembler
dg-final directive.

2015-06-10  Uros Bizjak  

* g++.dg/abi/mangle-regparm.C (dg-optiond): Add -save-temps.

Tested on x86_64-linux-gnu {,-m32}  and committed to mainline SVN.

Uros.

Index: g++.dg/abi/mangle-regparm.C
===
--- g++.dg/abi/mangle-regparm.C (revision 224330)
+++ g++.dg/abi/mangle-regparm.C (working copy)
@@ -1,5 +1,5 @@
// { dg-do run { target { { i?86-*-* x86_64-*-* } && ia32 } } }
-// { dg-options "-Wabi=8" }
+// { dg-options "-Wabi=8 -save-temps" }
// { dg-final { scan-assembler
"_Z18IndirectExternCallIPU7stdcallU7regparmILi3EEFviiEiEvT_T0_S3_" } }

typedef __SIZE_TYPE__ size_t;


[gomp4] filter out unrecognized device_type targets

2015-06-10 Thread Cesar Philippidis
This patch addresses a bug where the c and c++ front ends would ICE in
the event that an unrecognized target is specified as a device_type,
e.g. device_type (foo). The device_type clause is still highly specific
to nvidia targets, so it's likely something to be be merged in gcc 7.1
rather than 6.1. In the meantime, I've applied this patch to
gomp-4_0-branch.

Cesar

2015-06-10  Cesar Philippidis  

	gcc/
	* c-family/c-omp.c (oacc_filter_device_types): Filter out
	device_type clauses even when the device_type isn't recognized.

	gcc/testsuite
	* c-c++-common/goacc/dtype-3.c: New test.

diff --git a/gcc/c-family/c-omp.c b/gcc/c-family/c-omp.c
index 1c82bf5..c30e0d8 100644
--- a/gcc/c-family/c-omp.c
+++ b/gcc/c-family/c-omp.c
@@ -1109,6 +1109,7 @@ oacc_filter_device_types (tree clauses)
   tree dtype = NULL_TREE;
   tree seen_nvidia = NULL_TREE;
   tree seen_default = NULL_TREE;
+  int device = 0;
 
   /* First scan for all device_type clauses.  */
   for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
@@ -1119,33 +1120,43 @@ oacc_filter_device_types (tree clauses)
 
 	  if (code == GOMP_DEVICE_DEFAULT)
 	{
-	  if (seen_default)
+	  if (device & (1 << GOMP_DEVICE_DEFAULT))
 		{
 		  seen_default = NULL_TREE;
 		  error_at (OMP_CLAUSE_LOCATION (c),
 			"duplicate device_type (*)");
 		  goto filter_error;
 		}
-	  else
-		seen_default = OMP_CLAUSE_DEVICE_TYPE_CLAUSES (c);
+
+	  seen_default = OMP_CLAUSE_DEVICE_TYPE_CLAUSES (c);
 	}
-	  if (code & (1 << GOMP_DEVICE_NVIDIA_PTX))
+	  else if (code & (1 << GOMP_DEVICE_NVIDIA_PTX))
 	{
-	  if (seen_nvidia)
+	  if (device & code)
 		{
 		  seen_nvidia = NULL_TREE;
 		  error_at (OMP_CLAUSE_LOCATION (c),
 			"duplicate device_type (nvidia)");
 		  goto filter_error;
 		}
-	  else
-		seen_nvidia = OMP_CLAUSE_DEVICE_TYPE_CLAUSES (c);
+
+	  seen_nvidia = OMP_CLAUSE_DEVICE_TYPE_CLAUSES (c);
+	}
+	  else
+	{
+	  if (device & (1 << code))
+		{
+		  error_at (OMP_CLAUSE_LOCATION (c),
+			"duplicate device_type");
+		  goto filter_error;
+		}
 	}
+	  device |= (1 << code);
 	}
 }
 
   /* Don't do anything if there aren't any device_type clauses.  */
-  if (seen_nvidia == NULL_TREE && seen_default == NULL_TREE)
+  if (device == 0)
 return clauses;
 
   dtype = seen_nvidia ? seen_nvidia : seen_default;
diff --git a/gcc/testsuite/c-c++-common/goacc/dtype-3.c b/gcc/testsuite/c-c++-common/goacc/dtype-3.c
new file mode 100644
index 000..53ab94c
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/goacc/dtype-3.c
@@ -0,0 +1,34 @@
+/* { dg-do compile } */
+
+float b;
+#pragma acc declare link (b)
+
+int
+main (int argc, char **argv)
+{
+  float a;
+
+  a = 2.0;
+
+#pragma acc parallel device_type (*) copy (a) /* { dg-error "not valid" } */
+  {
+  }
+
+#pragma acc parallel device_type (acc_device_nvidia) num_gangs (1)
+  {
+  }
+
+#pragma acc parallel device_type (acc_device_host, acc_device_nvidia) num_gangs (1)
+  {
+  }
+
+#pragma acc parallel device_type (acc_device_host) num_gangs (1)
+  {
+  }
+
+#pragma acc parallel device_type (foo)
+  {
+  }
+
+  return 0;
+}


[patch commit SH] Fix failures for gcc.target/sh/pr49263-2.c with -mlra

2015-06-10 Thread Kaz Kojima
Hi,

Some scan-assembler-times tests fail with -mlra for
gcc.target/sh/pr49263-2.c and gcc.target/sh/pr64345-2.c.
A reduced test case

int foo (int x) { return (x & 255) == 0;}

gives a code like

mov r4,r0
tst #255,r0
rts
movtr0

with -mno-lra and

mov.w   .L2,r1
tst r1,r4
rts
movtr0
.align 1
.L2:
.short  255

with -mlra.  These tst instructions come from tstsi_t insn:

 (define_insn_and_split "tstsi_t"
   [(set (reg:SI T_REG)
(eq:SI (and:SI (match_operand:SI 0 "arith_reg_operand" "%z,r")
   (match_operand:SI 1 "arith_or_int_operand" "K08,r"))
   (const_int 0)))]

It looks that LRA somtimes prefers r/r alternative to z/K08.
The attached patch tunes it with disparaging r/r slightly.  Tested
on sh4-unknown-linux-gnu with no new failures for -mlra/-mno-lra.
There are no visible changes over generated objects with -mno-lra
in CSiBE.  Committed on trunk.

Regards,
kaz
--
2015-06-10  Kaz Kojima  

* config/sh/sh.md (tstsi_t): Add '?' modifier to 'r' alternative
of the second operand.

diff --git a/config/sh/sh.md b/config/sh/sh.md
index 33241a8..e88d249 100644
--- a/config/sh/sh.md
+++ b/config/sh/sh.md
@@ -616,7 +616,7 @@
 (define_insn_and_split "tstsi_t"
   [(set (reg:SI T_REG)
(eq:SI (and:SI (match_operand:SI 0 "arith_reg_operand" "%z,r")
-  (match_operand:SI 1 "arith_or_int_operand" "K08,r"))
+  (match_operand:SI 1 "arith_or_int_operand" "K08,?r"))
   (const_int 0)))]
   "TARGET_SH1
&& (can_create_pseudo_p () || arith_reg_operand (operands[1], SImode)


Re: [PATCH 00/17] RFC: Addding a unit testing framework to gcc

2015-06-10 Thread Jakub Jelinek
On Wed, Jun 10, 2015 at 02:04:11PM -0400, David Malcolm wrote:
> FWIW this goes away if I simply include gtest.h immediately after
> config.h, but before system.h.

Yeah, I guess including it before system.h and after config.h is fine.

Jakub


Re: [PATCH, Google] Notify df framework when removing an insn in simplify-got

2015-06-10 Thread Carrot Wei
On Tue, Jun 9, 2015 at 11:43 PM, Richard Sandiford
 wrote:
> Carrot Wei  writes:
>> Index: simplify-got.c
>> ===
>> --- simplify-got.c (revision 224174)
>> +++ simplify-got.c (working copy)
>> @@ -169,7 +169,10 @@
>>
>>/* Since there is no usage of pic_reg now, we can remove it.  */
>>if (use)
>> -remove_insn (use);
>> +{
>> +  df_insn_delete (use);
>> +  remove_insn (use);
>> +}
>>targetm.got_access.clear_pic_reg ();
>>free (got_accesses);
>>htab_delete (var_table);
>
> Why not just use delete_insn ()?
>
> Thanks,
> Richard
>

Good suggestion, testing following patch,

Index: simplify-got.c
===
--- simplify-got.c (revision 224174)
+++ simplify-got.c (working copy)
@@ -169,7 +169,7 @@

   /* Since there is no usage of pic_reg now, we can remove it.  */
   if (use)
-remove_insn (use);
+delete_insn (use);
   targetm.got_access.clear_pic_reg ();
   free (got_accesses);
   htab_delete (var_table);


Re: [PATCH 00/17] RFC: Addding a unit testing framework to gcc

2015-06-10 Thread Jakub Jelinek
On Wed, Jun 10, 2015 at 01:16:20PM -0400, David Malcolm wrote:
> On Wed, 2015-06-10 at 17:34 +0200, Jakub Jelinek wrote:
> > On Wed, Jun 10, 2015 at 11:24:41AM -0400, David Malcolm wrote:
> > > I picked the Google Test framework:
> > >   http://code.google.com/p/googletest/
> > 
> > I must say I'm not very excited about using this, it won't integrate
> > very well with dejagnu
> 
> Why is that a goal?  I've been using DejaGnu's unittesting API for
> testing the jit, and it is... suboptimal, to put it mildly.

Primarily consistency, people want consistent output of the testresults from
the compiler, not to have to pass one set of magic options to dejagnu to do
something and then mirror them to something completely different to make
gtest happy.  Similarly, there are all kinds of scripts that analyze gcc
testresults, having to parse a completely different format because a tiny
percentage of tests runs something different isn't a very good idea.
Plus, by using googletest, you add another build requirement, we already
have quite a lot of them.

> > whether talking about results (will it provide
> > some *.log/*.sum file with FAIL/XFAIL/PASS/XPASS etc. lines?),
> 
> It doesn't have an output formatter for the DejaGnu format, but I guess
> I could write one.  The gtest standard output format is IMHO superior to
> DejaGnu's since it tells you start-of-test/end-of-test on separate
> lines, so you can see which test killed things in the event of total

I find the dejagnu log files quite readable, unlike the gtest stuff, so
supposedly this is quite subjective.

> > etc.
> > E.g. for asan.exp testing, I just wrote a gtest emulation using
> > dejagnu, see testsuite/g++.dg/asan/dejagnu-gtest.h and
> > testsuite/lib/asan-dg.exp
> 
> ...which doesn't have things like EXPECT_STREQ, or custom comparators,
> doesn't appear to support fixtures, type-parameterized tests,
> value-parameterized tests, etc, my point being that a unit-testing
> framework is a non-trivial amount of code that could do useful things
> for us.

The question is why you really need it, or if it is more than a few lines of
macros.

> > but that was mainly meant for cases where
> > many routines are expected to crash the process.
> 
> FWIW, if I'm reading testsuite/g++.dg/asan/dejagnu-gtest.h and
> testsuite/lib/asan-dg.exp correctly, it looks like you're spawning the
> tool once per EXPECT_DEATH instance in the testsuite.  That seems
> suboptimal, gtest uses fork without exec
> to do it all directly at the point of the test without lots of extra
> work, where the parent verifies the death of the child.

That was a design choice, makes it much easier to debug the individual
tests, especially for asan where for gtest there are just way too many forks
and way too many (expected) crashes.
For the unittests, I see no problem running numerous tests from within one
process, it can emit multiple PASS/FAIL/XFAIL etc.

Jakub