Re: [PATCH] Fix PR63259: bswap not recognized when finishing with rotation

2014-10-08 Thread Jakub Jelinek
On Wed, Oct 08, 2014 at 02:56:46PM +0800, Thomas Preud'homme wrote:
> > From: gcc-patches-ow...@gcc.gnu.org [mailto:gcc-patches-
> > ow...@gcc.gnu.org] On Behalf Of Thomas Preud'homme
> > Sent: Wednesday, October 08, 2014 2:43 PM
> > > Also, perhaps you could short-circuit this if the rotation isn't by 
> > > constant
> 
> Note that do_shift_rotate already check for this. Is it enough?

The question is only about the compile time cost needed through all the
routines find_bswap_or_nop calls before it finds out it can't do anything
with the rotate, the short-circuiting could avoid that.  E.g.
find_bswap_or_nop_1 first recurses on the argument etc.

Jakub


Re: Towards GNU11

2014-10-08 Thread Richard Biener
On Tue, 7 Oct 2014, Marek Polacek wrote:

> Hi!
> 
> I'd like to kick off a discussion about moving the default standard
> for C from gnu89 to gnu11.
> 
> This really shouldn't be much of a surprise: the docs mention that
> gnu11 is intended future default for a year now.  I would presume now
> is a good time to make this move: together with the new naming scheme
> this should make GCC more modern (C89 really is as old as the hills).
> And we're still in stage1.
> 
> Prerequisites should be largely complete at this point:
> - we have -Wc90-c99-compat option that warns about features not present
>   in ISO C90, but present in ISO C99,
> - we have -Wc99-c11-compat option that warns about features not present
>   in ISO C99, but present in ISO C11,
> - the testsuite has been adjusted so all the test that pass with gnu89
>   default should pass with gnu11 default as well (see my recent batch
>   of cleanup patches).  This unfortunately isn't correct for all archs,
>   I just don't have enough resources to test everything.  But generally
>   the fallout from moving to gnu11 is easy to fix: just add proper decls
>   and return types (to fix defaulting to int), or for inline stuff use
>   -fgnu89-inline/gnu_inline attribute.  I'd appreciate testing on other
>   architectures than x86_64/ppc64.
> 
> The things I had to fix in the testsuite nicely reflect what we can expect
> in the real life: mostly bunch of new warnings about missing declarations
> and defaulting to int (this is probably going to be a pain with -Werror,
> but I feel that people really should write proper declarations), different
> inline semantics (in C99 semantics, the TU has to have the body of the inline
> function etc.), new "return with no value, in function returning non-void"
> warnings.  Different rules for constant expressions, the fact that in C90
> non-lvalue arrays do not decay to pointers, slightly different rules for
> compatible types (?) might come in game as well.
> 
> In turn, you can use all C99 and C11 features even with -pedantic.
> 
> Comments?

I think it makes sense to do this (and I expect C++ will follow
with defaulting to -std=c++11 once the ABI stuff has settled).

Of course it would be nice to look at the actual fallout in
a whole-distribution rebuild...

Thanks,
Richard.

> Regtested/bootstrapped on powerpc64-linux and x86_64-linux.
> 
> 2014-10-07  Marek Polacek  
> 
>   * doc/invoke.texi: Update to reflect that GNU11 is the default
>   mode for C.
>   * c-common.h (c_language_kind): Update comment.
> c-family/
>   * c-opts.c (c_common_init_options): Make -std=gnu11 the default for C.
> 
> diff --git gcc/c-family/c-common.h gcc/c-family/c-common.h
> index 1e3477f..a895084 100644
> --- gcc/c-family/c-common.h
> +++ gcc/c-family/c-common.h
> @@ -445,7 +445,7 @@ struct GTY(()) sorted_fields_type {
>  
>  typedef enum c_language_kind
>  {
> -  clk_c  = 0,/* C90, C94 or C99 */
> +  clk_c  = 0,/* C90, C94, C99 or C11 */
>clk_objc   = 1,/* clk_c with ObjC features.  */
>clk_cxx= 2,/* ANSI/ISO C++ */
>clk_objcxx = 3 /* clk_cxx with ObjC features.  */
> diff --git gcc/c-family/c-opts.c gcc/c-family/c-opts.c
> index 3f295d8..eb078e3 100644
> --- gcc/c-family/c-opts.c
> +++ gcc/c-family/c-opts.c
> @@ -250,6 +250,9 @@ c_common_init_options (unsigned int decoded_options_count,
>  
>if (c_language == clk_c)
>  {
> +  /* The default for C is gnu11.  */
> +  set_std_c11 (false /* ISO */);
> +
>/* If preprocessing assembly language, accept any of the C-family
>front end options since the driver may pass them through.  */
>for (i = 1; i < decoded_options_count; i++)
> diff --git gcc/doc/invoke.texi gcc/doc/invoke.texi
> index 5fe7e15..fa84ed4 100644
> --- gcc/doc/invoke.texi
> +++ gcc/doc/invoke.texi
> @@ -1692,8 +1692,7 @@ interfaces) and L (Analyzability).  The name @samp{c1x} 
> is deprecated.
>  
>  @item gnu90
>  @itemx gnu89
> -GNU dialect of ISO C90 (including some C99 features). This
> -is the default for C code.
> +GNU dialect of ISO C90 (including some C99 features).
>  
>  @item gnu99
>  @itemx gnu9x
> @@ -1701,8 +1700,8 @@ GNU dialect of ISO C99.  The name @samp{gnu9x} is 
> deprecated.
>  
>  @item gnu11
>  @itemx gnu1x
> -GNU dialect of ISO C11.  This is intended to become the default in a
> -future release of GCC.  The name @samp{gnu1x} is deprecated.
> +GNU dialect of ISO C11.  This is the default for C code.
> +The name @samp{gnu1x} is deprecated.
>  
>  @item c++98
>  @itemx c++03
> 
>   Marek
> 
> 

-- 
Richard Biener 
SUSE / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746
GF: Jeff Hawn, Jennifer Guild, Felix Imend"orffer


Re: [Fortran, Patch] Implement IMPLICIT NONE

2014-10-08 Thread FX
> Patch

Patch cleaning up the testsuite (while Tobias is curing is cold :) is 
pre-approved.
It comes from the last-minute wording change I suggested, I suppose.

FX

Re: [PATCH] Fix PR63259: bswap not recognized when finishing with rotation

2014-10-08 Thread Richard Biener
On Wed, Oct 8, 2014 at 9:04 AM, Jakub Jelinek  wrote:
> On Wed, Oct 08, 2014 at 02:56:46PM +0800, Thomas Preud'homme wrote:
>> > From: gcc-patches-ow...@gcc.gnu.org [mailto:gcc-patches-
>> > ow...@gcc.gnu.org] On Behalf Of Thomas Preud'homme
>> > Sent: Wednesday, October 08, 2014 2:43 PM
>> > > Also, perhaps you could short-circuit this if the rotation isn't by 
>> > > constant
>>
>> Note that do_shift_rotate already check for this. Is it enough?
>
> The question is only about the compile time cost needed through all the
> routines find_bswap_or_nop calls before it finds out it can't do anything
> with the rotate, the short-circuiting could avoid that.  E.g.
> find_bswap_or_nop_1 first recurses on the argument etc.

I wouldn't worry about that too much.  Indeed the question would be what
should be canonical on GIMPLE (expanders should choose the optimal
vairant from both).  I think a tree code should be always prefered to a
builtin function call - which means a rotate is more canonical than a
bswap16 call.

>From the performance side the pass could be re-structured to populate
a lattice, thus work from def to use instead of the other way around.  Which
means we visit each stmt exactly once, compute its value symbolically
and check it against a rotate.

Richard.

> Jakub


Re: RFA: Merge definitions of get_some_local_dynamic_name

2014-10-08 Thread Rainer Orth
Hi Richard,

> Does this work for you?  I tested it on x86_64-linux-gnu but obviously
> that's not particularly useful for SEQUENCEs.

the patch is fine, as tested on both sparc-sun-solaris2.11 and (for good
measure) i386-pc-solaris2.11.

Thanks.
Rainer

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


Re: Towards GNU11

2014-10-08 Thread Marek Polacek
On Wed, Oct 08, 2014 at 09:16:18AM +0200, Richard Biener wrote:
> I think it makes sense to do this (and I expect C++ will follow
> with defaulting to -std=c++11 once the ABI stuff has settled).

Thanks.  Moving to -std=c++11 would be cool!
 
> Of course it would be nice to look at the actual fallout in
> a whole-distribution rebuild...

Yeah, I'm worried about that.  Many packages are using -std=gnu99
(e.g. glibc, elfutils, maybe emacs) and these won't be affected at
all.  But e.g. gdb/binutils use the default standard I think.  I
wonder about Linux kernel.
And of course, C++ packages should be out of the picture here.

Marek


RFA: Fix debug address mode for TARGET_MEM_REF

2014-10-08 Thread Joern Rennecke
Trying to build avr2 strftime of avr-libc ICEs as we are trying to
convert a PSImode address to HImode.  There is no reason to
do this conversion in the first place - it is a case of failing to recognize
the proper address space.

The attached patch fixes this.

Bootstrapped on i686-pc-linux-gnu.

OK to apply?


debug-tgt-mem-patch
Description: Binary data


Re: sort_heap complexity guarantee

2014-10-08 Thread Jonathan Wakely

On 06/10/14 23:00 +0200, François Dumont wrote:
Good point, with n calls to pop_heap it means that limit must be 
2*log(1) + 2*log(2) +... + 2*log(n) which is 2*log(n!) and  which is 
also necessarily < 2*n*log(n). I guess Standard comittee has forgotten 
the factor 2 in the limit so this is what I am using as limit in the 
final test, unless someone prefer the stricter 2*log(n!) ?


Ok to commit those new tests ?


Yes please - thanks.


Re: [PATCH 2/n] OpenMP 4.0 offloading infrastructure: LTO streaming

2014-10-08 Thread Jakub Jelinek
On Wed, Oct 01, 2014 at 08:13:32PM +0400, Ilya Verbin wrote:
> @@ -1994,9 +1995,40 @@ output_in_order (bool no_reorder)
>free (nodes);
>  }
>  
> +/* Check whether there is at least one function or global variable to 
> offload.
> +   */

The */ alone on a line is weird, put the last word on the next line too.

> +  FOR_EACH_DEFINED_VARIABLE (vnode)
> +{
> +  if (!lookup_attribute ("omp declare target",
> +  DECL_ATTRIBUTES (vnode->decl))
> +   || TREE_CODE (vnode->decl) != VAR_DECL
> +   || DECL_SIZE (vnode->decl) == 0)

While I hope the varpool code puts only decls that have DECL_ATTRIBUTES
into FOR_EACH_DEFINED_VARIABLE, it would be better to put the
less expensive tests first, i.e. the last two first, then lookup_attribute.
Also, DECL_SIZE is a tree, so == NULL_TREE?

And, once there is an option to select which offload targets to generate
code for (or none), initialize_offload () should supposedly return false
if the user requested no offloading on the command line.

The omp-low.c changes look good, for the cgraph/LTO stuff I defer to Honza
and/or Richard, if they are fine with the changes, so am I.

Jakub


Re: [PATCH 1/2] PR debug/63239 Add DWARF representation for C++11 deleted member function.

2014-10-08 Thread Rainer Orth
Steven Bosscher  writes:

> On Mon, Oct 6, 2014 at 9:54 AM, Mark Wielaard wrote:
>> Just removing the # prefix (but keeping the space) from
>> scan-assembler-times should work for both our cases. I just don't know
>> why our .s outputs look different.
>
> Wild guess: different comment marker in the target's assembly language?

True: on Solaris/x86 with /bin/as, I have

/ DW_AT_GNU_deleted

on Solaris/SPARC with /bin/as, it's

.byte   0x1 ! DW_AT_GNU_deleted

instead, and probably even more others on different platforms.

Rainer

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


Re: [PATCH 5/n] OpenMP 4.0 offloading infrastructure: libgomp

2014-10-08 Thread Kirill Yukhin
Hello Jakub,
On 07 Oct 21:40, Jakub Jelinek wrote:
> On Tue, Oct 07, 2014 at 10:12:22PM +0400, Ilya Verbin wrote:
> OT, from the various IRC discussions with Kirill on IRC, it seems you or
> your colleges typed pretty much all target related tests from OpenMP 4.0.1
> examples, can those be also submitted for inclusion in the testsuite?
> AFAIK we already have the appendix-a/ testcases and had permissions from
> OpenMP committee to use them, so if we put these into the same directory
> (sure, it is not appendix-a anymore, but no tests are in that appendix
> anymore), it would be appreciated.
We've implemented whole OpenMP4.x examples document as part of libgomp 
testsuite.
Currently pass-rate is 100% on kyukhin/gomp4-offload branch.
We'll submit test suite changes in one of our next patches.

--
Thanks, K
> 
>   Jakub


Re: [PATCH] PR58867 ASan and UBSan tests not run for installed testing.

2014-10-08 Thread Marcus Shawcroft
On 1 October 2014 08:09, Maxim Ostapenko
 wrote:
> Hi,
>
> some time ago, Andrew wrote a patch that fixes PR58867
> (http://patchwork.ozlabs.org/patch/286866/), but for some reasons it
> wasn't committed to trunk.
>
> This is resurrected Andrew's patch, extended to support Tsan testsuite.
>
> Tested on x86_64-pc-linux-gnu, ok to commit?
>
> -Maxim

Hi,

This patch  results in wide spread failures in our bare metal test
runs.  I have not dug into the issue in detail but it appears that the
issue is related to the attempted use of  set_ld_library_path_env_vars
 and restore_ld_library_path_env_vars to save and restore nested
contexts.

Consider ubsan/ubsan.exp:

load_lib gcc-dg.exp
...
dg-init
ubsan_init
...
ubsan_finish

The gcc-dg.exp library load calls set_ld_library_path_env_vars the
first time an initializes GCC_EXEC_PREFIX.
The ubsan_init call makes a further call to
set_ld_library_path_env_vars which has no effect.
The ubsan_finish invokes restore_ld_library_path_env_vars, restoring
the environments as it was prior to the call to dg-init.
Any further test execution has now lost the original initialization of
GCC_EXEC_PREFIX by gcc-dg.exp

It seems to me that either this patch assumes  that the
set/restore_ld_library_path_env foo  is capable of maintaining a stack
of saved contexts... which it is not.

Prior to this patch ubsan_finish did not attempt to call
restore_ld_library_path_env_vars hence the gcc-dg.exp environment
remained in place for subsequent test executions.

Cheers
/Marcus


[PATCH, RTL]: Fix PR 63483, Scheduler performs Invalid move of aliased memory reference

2014-10-08 Thread Uros Bizjak
Hello!

This message revives an old thread [1], where the miscompilation of gfortran
on alpha was found that that resulted in:

FAIL: gfortran.dg/assumed_rank_3.f90:15.20:

print *, ubound(x,dim=3)  ! << wrong dim
1
Error: Assumed-rank variable x at (1) may only be used as actual argument

The problem was in the miscompilation of resolve_actual_arglist from
resolve.c.  This function initializes two nearby global bool variables
with the following sequence:

  actual_arg = true;
  first_actual_arg = true;

but due to the miscompilation, the actual_arg was never set to true.
This happened due to the way stores to QImode and HImode locations are
implemented on non-BWX targets. The sequence reads full word, does its
magic to the part and stores the full word with changed part back to
the memory. However - the scheduler mixed two sequences, violating the
atomicity of RMW sequence.

As demostrated in the great detail in the PR [2], the problem is in
early exit  for MEM_READOLNY_P in true_dependence_1 in alias.c. This
early exit declares all MEM_READONLY_P references as non-aliasing,
which is not true when possibly aliasing references with alignment
ANDs are involved.

Proposed patch prevents MEM_READONLY_P memory references to be moved
over possibly aliased memory (with alignment ANDs). The patch prevents
early exit for MEM_READONLY_P references when alignment ANDs are
involved. The aliasing is then determined later in the function. In
effect, it changes early exit to:

-  if (MEM_READONLY_P (x))
-return 0;
+  if (MEM_READONLY_P (x)
+  && GET_CODE (x_addr) != AND
+  && GET_CODE (mem_addr) != AND)
+return 0;

The comment also mentions "... We don't expect to find read-only set
on MEM, but stupid user tricks can produce them, so don't die.". We
certainly don't die anymore, as confirmed by a native alpha-linux-gnu
(please note - not alphaev6!) bootstrap and regression test.

2014-10-08  Uros Bizjak  

* alias.c (true_dependence_1): Do not exit early for MEM_READONLY_P
references when alignment ANDs are involved.

The patch was bootstrapped and regression tested on alpha-linux-gnu.

OK for mainline and release branches?

Please note that the patch by itself is not enough to fix the original
problem with gfortran miscompilation. Another problem in this area is
summarised in PR 63475 [3], where postreload CSE propagates aliased
memory operand.

[1] https://gcc.gnu.org/ml/gcc-patches/2014-06/msg02251.html
[2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63483
[3] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63475

Uros.
Index: alias.c
===
--- alias.c (revision 215966)
+++ alias.c (working copy)
@@ -2458,18 +2458,6 @@ true_dependence_1 (const_rtx mem, enum machine_mod
   || MEM_ALIAS_SET (mem) == ALIAS_SET_MEMORY_BARRIER)
 return 1;
 
-  /* Read-only memory is by definition never modified, and therefore can't
- conflict with anything.  We don't expect to find read-only set on MEM,
- but stupid user tricks can produce them, so don't die.  */
-  if (MEM_READONLY_P (x))
-return 0;
-
-  /* If we have MEMs referring to different address spaces (which can
- potentially overlap), we cannot easily tell from the addresses
- whether the references overlap.  */
-  if (MEM_ADDR_SPACE (mem) != MEM_ADDR_SPACE (x))
-return 1;
-
   if (! mem_addr)
 {
   mem_addr = XEXP (mem, 0);
@@ -2493,6 +2481,22 @@ true_dependence_1 (const_rtx mem, enum machine_mod
}
 }
 
+  /* Read-only memory is by definition never modified, and therefore can't
+ conflict with anything.  However, don't assume anything when AND
+ addresses are involved and leave to the code below to determine
+ dependence.  We don't expect to find read-only set on MEM, but
+ stupid user tricks can produce them, so don't die.  */
+  if (MEM_READONLY_P (x)
+  && GET_CODE (x_addr) != AND
+  && GET_CODE (mem_addr) != AND)
+return 0;
+
+  /* If we have MEMs referring to different address spaces (which can
+ potentially overlap), we cannot easily tell from the addresses
+ whether the references overlap.  */
+  if (MEM_ADDR_SPACE (mem) != MEM_ADDR_SPACE (x))
+return 1;
+
   base = find_base_term (x_addr);
   if (base && (GET_CODE (base) == LABEL_REF
   || (GET_CODE (base) == SYMBOL_REF


[patch] Add const to constexpr member function in regex.h

2014-10-08 Thread Jonathan Wakely

In C++14 constexpr member functions are no longer implicitly const.

Tested x86_64-linux, committed to trunk and 4.9
commit 63d852cc56aa0f44ee0f770594c79705331933ec
Author: Jonathan Wakely 
Date:   Wed Oct 8 09:34:15 2014 +0100

	* include/bits/regex.h (regex_token_iterator::_M_end_of_seq): Add
	const qualifier.

diff --git a/libstdc++-v3/include/bits/regex.h b/libstdc++-v3/include/bits/regex.h
index 4ec20d7..4244f2e 100644
--- a/libstdc++-v3/include/bits/regex.h
+++ b/libstdc++-v3/include/bits/regex.h
@@ -2689,7 +2689,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   }
 
   constexpr bool
-  _M_end_of_seq()
+  _M_end_of_seq() const
   { return _M_result == nullptr; }
 
   _Position _M_position;


Re: Track dynamic type changes

2014-10-08 Thread Rainer Orth
Hi Jan,

> this patch makes ipa_polymorphic_call_context::get_dynamic_type to
> track if vptr has changed in between function entry and polymorphic
> call.
>
> The patch also add logic skipping if (a==0) checks in multiple
> inheritance so I can construct testcase more easily.
>
> I got my SVN tree into an inconsistent state yesterday by stopping in
> middle of commit.  The patch went in in two parts, so i am attaching 
> both changes. Quite few of devirt-4*.C was broken overnight, I apologize
> for that.

as of yesterday (r215969), many of the devirt-4*.C tests come up
UNRESOLVED on both Solaris/x86 and Solaris/SPARC:

UNRESOLVED: g++.dg/ipa/devirt-42.C  -std=gnu++11  scan-ipa-dump-not optimized 
"OBJ_TYPE_REF"
UNRESOLVED: g++.dg/ipa/devirt-42.C  -std=gnu++11  scan-ipa-dump-times optimized 
"return 2" 2
UNRESOLVED: g++.dg/ipa/devirt-42.C  -std=gnu++1y  scan-ipa-dump-not optimized 
"OBJ_TYPE_REF"
UNRESOLVED: g++.dg/ipa/devirt-42.C  -std=gnu++1y  scan-ipa-dump-times optimized 
"return 2" 2
UNRESOLVED: g++.dg/ipa/devirt-42.C  -std=gnu++98  scan-ipa-dump-not optimized 
"OBJ_TYPE_REF"
UNRESOLVED: g++.dg/ipa/devirt-42.C  -std=gnu++98  scan-ipa-dump-times optimized 
"return 2" 2
UNRESOLVED: g++.dg/ipa/devirt-46.C  -std=gnu++11  scan-ipa-dump-not optimized 
"OBJ_TYPE_REF"
UNRESOLVED: g++.dg/ipa/devirt-46.C  -std=gnu++11  scan-ipa-dump-not optimized 
"abort"
UNRESOLVED: g++.dg/ipa/devirt-46.C  -std=gnu++1y  scan-ipa-dump-not optimized 
"OBJ_TYPE_REF"
UNRESOLVED: g++.dg/ipa/devirt-46.C  -std=gnu++1y  scan-ipa-dump-not optimized 
"abort"
UNRESOLVED: g++.dg/ipa/devirt-46.C  -std=gnu++98  scan-ipa-dump-not optimized 
"OBJ_TYPE_REF"
UNRESOLVED: g++.dg/ipa/devirt-46.C  -std=gnu++98  scan-ipa-dump-not optimized 
"abort"
UNRESOLVED: g++.dg/ipa/devirt-47.C  -std=gnu++11  scan-ipa-dump optimized 
"C::_ZThn"
UNRESOLVED: g++.dg/ipa/devirt-47.C  -std=gnu++11  scan-ipa-dump-not optimized 
"OBJ_TYPE_REF"
UNRESOLVED: g++.dg/ipa/devirt-47.C  -std=gnu++1y  scan-ipa-dump optimized 
"C::_ZThn"
UNRESOLVED: g++.dg/ipa/devirt-47.C  -std=gnu++1y  scan-ipa-dump-not optimized 
"OBJ_TYPE_REF"
UNRESOLVED: g++.dg/ipa/devirt-47.C  -std=gnu++98  scan-ipa-dump optimized 
"C::_ZThn"
UNRESOLVED: g++.dg/ipa/devirt-47.C  -std=gnu++98  scan-ipa-dump-not optimized 
"OBJ_TYPE_REF"

both 32 and 64-bit.

In all cases, g++.log shows

g++.dg/ipa/devirt-42.C  -std=gnu++98 : dump file does not exist
UNRESOLVED: g++.dg/ipa/devirt-42.C  -std=gnu++98  scan-ipa-dump-times optimized 
"return 2" 2
g++.dg/ipa/devirt-42.C  -std=gnu++98 : dump file does not exist
UNRESOLVED: g++.dg/ipa/devirt-42.C  -std=gnu++98  scan-ipa-dump-not optimized 
"OBJ_TYPE_REF"

Rainer

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


Re: [PATCH 2/n] OpenMP 4.0 offloading infrastructure: LTO streaming

2014-10-08 Thread Jakub Jelinek
On Wed, Oct 08, 2014 at 10:45:22AM +0200, Jakub Jelinek wrote:
> And, once there is an option to select which offload targets to generate
> code for (or none), initialize_offload () should supposedly return false
> if the user requested no offloading on the command line.

After some thought, I take this back.  We should always stream
.gnu.offload_lto_* if we have any target regions or omp declare target
functions/vars.  The decision should be done during linking, if the user
wants only host fallback, during linking we should just throw away those
.gnu.offload_lto_* sections (could also tweak defaults for that e.g.
in libgomp.spec).  Thinking with a distro hat now, if gcc is configured
as offloading for say MIC, PTX and HSA?, it would be nice if the default
choice was dependent on which offloading compilers the user decided to actually
install.  So one could add a default for
%{!foffloading:-foffloading=x86_64-intelmic-linux-gnu}
if MIC offloading compiler is installed and PTX/HSA is not (for example,
don't remember the name of the option we discussed).

Jakub


Re: [PATCH 3/n] OpenMP 4.0 offloading infrastructure: offload tables

2014-10-08 Thread Jakub Jelinek
On Tue, Sep 30, 2014 at 06:53:20PM +0400, Ilya Verbin wrote:
> Bootstrapped and regtested on top of patch 2.  Is it OK for trunk?

LGTM, with the requested var/section renames.
Would like if Honza and/or Richard had a look at the cgraph/LTO stuff
in the patch though.

Jakub


Re: [gomp4] reduction bug fix

2014-10-08 Thread Thomas Schwinge
Hi Cesar!

On Fri, 3 Oct 2014 09:22:52 -0700, Cesar Philippidis  
wrote:
> There is a reduction bug [...]

Thanks for looking into this!

> This is a problem because initialize_reduction_data originally expected
> a GIMPLE_BIND at the very beginning of a parallel block.  [...]

Does your patch also fix the issue that Jim saw in his C++ work?

> This patch also includes a runtime test case. I won't apply it to
> gomp-4_0-branch just yet. But I wanted to demonstrate a test case
> nonetheless.

You can add it as a compile test, and I'll toggle to a run test as part
of the merge into our internal development branch.

> Also, note that part of this patch also changes a comment.
> I found some typos in the original comment, so I took the opportunity to
> fix them, I hope.

Sure, and it's also always fine to separately apply such patches under
the obvious rule.

> Is this OK for gomp-4_0-branch?

Yes, with the following addressed:

> --- a/gcc/omp-low.c
> +++ b/gcc/omp-low.c
> @@ -10140,11 +10140,20 @@ process_reduction_data (gimple_seq *body, 
> gimple_seq *in_stmt_seqp,

[...]/source-gcc/gcc/omp-low.c: In function 'void 
_ZL22process_reduction_dataPP21gimple_statement_baseS1_S1_P11omp_context.isra.167.constprop.180(gimple_statement_base**,
 gimple_statement_base**, gimple_statement_base**, gimple)':
[...]/source-gcc/gcc/omp-low.c:10172:14: warning: 'inner' may be used 
uninitialized in this function [-Wmaybe-uninitialized]
   gimple_seq inner;
  ^

> --- /dev/null
> +++ b/libgomp/testsuite/libgomp.oacc-c/collapse-4.c
> @@ -0,0 +1,34 @@
> +/* { dg-do run } */
> +/* { dg-options "-O2 -std=c99" } */
> +
> +#include 
> +#include 
> +#include 
> +
> +int
> +main (void)
> +{
> +  int i2, l = 0, r = 0;
> +  int a[3][3][3];
> +  int b[3][3];

A lot of these variables are unused.

> +printf("&a %p\n", &a[0][0][0]);
> +printf("&i2 %p\n", &i2);
> +printf("&l %p\n", &l);
> +printf("&r %p\n", &r);

Please remove  include and the printfs, or at least put those
into DEBUG conditionals.


Grüße,
 Thomas


pgpjFoJdfpG5c.pgp
Description: PGP signature


Re: [PATCH v2] libstdc++: Add hexfloat/defaultfloat io manipulators.

2014-10-08 Thread Jonathan Wakely

On 07/10/14 21:10 +0200, Andreas Schwab wrote:

That cannot work.  std::__convert_from_v always passes __prec before
__v, but the format is "%a".


Ah yes. I'm testing this fix now.

commit 543771e2db1642715854ae4bec81d803ca8e2e59
Author: Jonathan Wakely 
Date:   Wed Oct 8 10:39:27 2014 +0100

	* include/bits/locale_facets.tcc (num_put::_M_insert_float): Do not
	pass precision when using hexfloat format.
	* src/c++98/locale_facets.cc (__num_base::_S_format_float): Always
	output precision if C99 hexfloat conversion specifiers not available.

diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc
index cf12a08..88adc0d 100644
--- a/libstdc++-v3/include/bits/locale_facets.tcc
+++ b/libstdc++-v3/include/bits/locale_facets.tcc
@@ -988,20 +988,32 @@ _GLIBCXX_BEGIN_NAMESPACE_LDBL
 	__num_base::_S_format_float(__io, __fbuf, __mod);
 
 #ifdef _GLIBCXX_USE_C99
+	// Precision is always used except for hexfloat format.
+	const bool __use_prec =
+	  (__io.flags() & ios_base::floatfield) != ios_base::floatfield;
+
 	// First try a buffer perhaps big enough (most probably sufficient
 	// for non-ios_base::fixed outputs)
 	int __cs_size = __max_digits * 3;
 	char* __cs = static_cast(__builtin_alloca(__cs_size));
-	__len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
-  __fbuf, __prec, __v);
+	if (__use_prec)
+	  __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
+	__fbuf, __prec, __v);
+	else
+	  __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
+	__fbuf, __v);
 
 	// If the buffer was not large enough, try again with the correct size.
 	if (__len >= __cs_size)
 	  {
 	__cs_size = __len + 1;
 	__cs = static_cast(__builtin_alloca(__cs_size));
-	__len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
-	  __fbuf, __prec, __v);
+	if (__use_prec)
+	  __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
+	__fbuf, __prec, __v);
+	else
+	  __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
+	__fbuf, __v);
 	  }
 #else
 	// Consider the possibility of long ios_base::fixed outputs
diff --git a/libstdc++-v3/src/c++98/locale_facets.cc b/libstdc++-v3/src/c++98/locale_facets.cc
index 7ed04e6..b3ca5dc 100644
--- a/libstdc++-v3/src/c++98/locale_facets.cc
+++ b/libstdc++-v3/src/c++98/locale_facets.cc
@@ -71,7 +71,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 ios_base::fmtflags __fltfield = __flags & ios_base::floatfield;
 
+#ifdef _GLIBCXX_USE_C99
+// Precision is always used except for hexfloat format.
 if (__fltfield != (ios_base::fixed | ios_base::scientific))
+#endif
   {
 // As per DR 231: not only when __flags & ios_base::fixed || __prec > 0
 *__fptr++ = '.';


Re: [PATCH] PR58867 ASan and UBSan tests not run for installed testing.

2014-10-08 Thread Maxim Ostapenko

Does it work without restore_ld_library_path in {asan, ubsan, tsan}_finish?

I see two opportunities to fix the issue:

1) Implement a stack of saved contexts.

2) Implement new functions, say {asan, ubsan, 
tsan}_restore_ld_library_path, to be able {asan, ubsan, tsan}_finish 
functions restore context correctly.


What solution is preferable?

-Maxim
On 10/08/2014 01:02 PM, Marcus Shawcroft wrote:

On 1 October 2014 08:09, Maxim Ostapenko
 wrote:

Hi,

some time ago, Andrew wrote a patch that fixes PR58867
(http://patchwork.ozlabs.org/patch/286866/), but for some reasons it
wasn't committed to trunk.

This is resurrected Andrew's patch, extended to support Tsan testsuite.

Tested on x86_64-pc-linux-gnu, ok to commit?

-Maxim

Hi,

This patch  results in wide spread failures in our bare metal test
runs.  I have not dug into the issue in detail but it appears that the
issue is related to the attempted use of  set_ld_library_path_env_vars
  and restore_ld_library_path_env_vars to save and restore nested
contexts.

Consider ubsan/ubsan.exp:

load_lib gcc-dg.exp
...
dg-init
ubsan_init
...
ubsan_finish

The gcc-dg.exp library load calls set_ld_library_path_env_vars the
first time an initializes GCC_EXEC_PREFIX.
The ubsan_init call makes a further call to
set_ld_library_path_env_vars which has no effect.
The ubsan_finish invokes restore_ld_library_path_env_vars, restoring
the environments as it was prior to the call to dg-init.
Any further test execution has now lost the original initialization of
GCC_EXEC_PREFIX by gcc-dg.exp

It seems to me that either this patch assumes  that the
set/restore_ld_library_path_env foo  is capable of maintaining a stack
of saved contexts... which it is not.

Prior to this patch ubsan_finish did not attempt to call
restore_ld_library_path_env_vars hence the gcc-dg.exp environment
remained in place for subsequent test executions.

Cheers
/Marcus





[PATCH] PR debug/38757 gcc does not emit DW_LANG_C99

2014-10-08 Thread Mark Wielaard
Hi,

This patch was written a long time ago by Jakub and has been in Fedora
gcc for some time. All I did was rebase it to current gcc trunk
and add a testcase. Back when it was originally proposed the issue was
that because DWARF was generated late adding new lang hooks for this
was problematic for LTO. Now that there is a move towards generating
DWARF early I am hoping this patch can finally make it to mainline gcc.

This lang hook will be more useful when DWARFv5 gets out, which is
supposed to define language identifiers for newer C and C++ versions.

Previous discussions:
http://gcc.gnu.org/ml/gcc-patches/2009-03/msg00858.html
http://gcc.gnu.org/ml/gcc-patches/2010-04/msg00991.html

gcc/ChangeLog

2009-03-18  Jakub Jelinek  

PR debug/38757
* langhooks.h (struct lang_hooks): Add source_language langhook.
* langhooks-def.h (LANG_HOOKS_SOURCE_LANGUAGE): Define to NULL.
(LANG_HOOKS_INITIALIZER): Add LANG_HOOKS_SOURCE_LANGUAGE.
* dwarf2out.c (add_prototyped_attribute): Add DW_AT_prototype
also for DW_LANG_{C,C99,ObjC}.
(gen_compile_unit_die): Use lang_hooks.source_language () to
determine if DW_LANG_C99 or DW_LANG_C89 should be returned.

gcc/c/ChangeLog

2009-03-18  Jakub Jelinek  

PR debug/38757
* c-lang.c (c_source_language): New function.
(LANG_HOOKS_SOURCE_LANGUAGE): Define.

gcc/testsuite/ChangeLog

2014-10-08  Mark Wielaard  

PR debug/38757
* gcc.dg/debug/dwarf2/lang-c89.c: New test.
* gcc.dg/debug/dwarf2/lang-c99.c: Likewise.
---
 gcc/ChangeLog| 11 +++
 gcc/c/ChangeLog  |  6 ++
 gcc/c/c-lang.c   |  8 
 gcc/dwarf2out.c  | 19 ---
 gcc/langhooks-def.h  |  4 +++-
 gcc/langhooks.h  |  4 
 gcc/testsuite/ChangeLog  |  6 ++
 gcc/testsuite/gcc.dg/debug/dwarf2/lang-c89.c |  6 ++
 gcc/testsuite/gcc.dg/debug/dwarf2/lang-c99.c |  6 ++
 9 files changed, 66 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2/lang-c89.c
 create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2/lang-c99.c

diff --git a/gcc/c/c-lang.c b/gcc/c/c-lang.c
index 97c0443..dadeb1a 100644
--- a/gcc/c/c-lang.c
+++ b/gcc/c/c-lang.c
@@ -35,6 +35,12 @@ along with GCC; see the file COPYING3.  If not see
 
 enum c_language_kind c_language = clk_c;
 
+static int
+c_source_language (void)
+{
+  return flag_isoc99 ? 1999 : 1989;
+}
+
 /* Lang hooks common to C and ObjC are declared in c-objc-common.h;
consequently, there should be very few hooks below.  */
 
@@ -44,6 +50,8 @@ enum c_language_kind c_language = clk_c;
 #define LANG_HOOKS_INIT c_objc_common_init
 #undef LANG_HOOKS_INIT_TS
 #define LANG_HOOKS_INIT_TS c_common_init_ts
+#undef LANG_HOOKS_SOURCE_LANGUAGE
+#define LANG_HOOKS_SOURCE_LANGUAGE c_source_language
 
 /* Each front end provides its own lang hook initializer.  */
 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 59c05ed..4932cd0 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -16708,9 +16708,18 @@ add_bit_size_attribute (dw_die_ref die, tree decl)
 static inline void
 add_prototyped_attribute (dw_die_ref die, tree func_type)
 {
-  if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
-  && prototype_p (func_type))
-add_AT_flag (die, DW_AT_prototyped, 1);
+  switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
+{
+case DW_LANG_C:
+case DW_LANG_C89:
+case DW_LANG_C99:
+case DW_LANG_ObjC:
+  if (prototype_p (func_type))
+   add_AT_flag (die, DW_AT_prototyped, 1);
+  break;
+default:
+  break;
+}
 }
 
 /* Add an 'abstract_origin' attribute below a given DIE.  The DIE is found
@@ -19544,6 +19553,10 @@ gen_compile_unit_die (const char *filename)
language = DW_LANG_ObjC;
   else if (strcmp (language_string, "GNU Objective-C++") == 0)
language = DW_LANG_ObjC_plus_plus;
+  else if (strcmp (language_string, "GNU C") == 0
+  && lang_hooks.source_language
+  && lang_hooks.source_language () >= 1999)
+   language = DW_LANG_C99;
   else if (dwarf_version >= 5 || !dwarf_strict)
{
  if (strcmp (language_string, "GNU Go") == 0)
diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h
index e5ae3e3..b6c8dd4 100644
--- a/gcc/langhooks-def.h
+++ b/gcc/langhooks-def.h
@@ -120,6 +120,7 @@ extern bool lhd_omp_mappable_type (tree);
 #define LANG_HOOKS_BLOCK_MAY_FALLTHRU  hook_bool_const_tree_true
 #define LANG_HOOKS_EH_USE_CXA_END_CLEANUP  false
 #define LANG_HOOKS_DEEP_UNSHARING  false
+#define LANG_HOOKS_SOURCE_LANGUAGE NULL
 
 /* Attribute hooks.  */
 #define LANG_HOOKS_ATTRIBUTE_TABLE NULL
@@ -313,7 +314,8 @@ extern void lhd_end_section (void);

Re: [PATCH] PR debug/38757 gcc does not emit DW_LANG_C99

2014-10-08 Thread Marek Polacek
On Wed, Oct 08, 2014 at 12:13:55PM +0200, Mark Wielaard wrote:
> Hi,
> 
> This patch was written a long time ago by Jakub and has been in Fedora
> gcc for some time. All I did was rebase it to current gcc trunk
> and add a testcase. Back when it was originally proposed the issue was
> that because DWARF was generated late adding new lang hooks for this
> was problematic for LTO. Now that there is a move towards generating
> DWARF early I am hoping this patch can finally make it to mainline gcc.
> 
> This lang hook will be more useful when DWARFv5 gets out, which is
> supposed to define language identifiers for newer C and C++ versions.
 
It might have been discussed elsewhere, so sorry for not paying attention,
but what about DW_LANG_C11?

Marek


Re: [PATCH 4/n] OpenMP 4.0 offloading infrastructure: lto-wrapper

2014-10-08 Thread Jakub Jelinek
On Thu, Oct 02, 2014 at 07:14:57PM +0400, Ilya Verbin wrote:
> @@ -1296,6 +1297,9 @@ static const char *const standard_startfile_prefix_2
> relative to the driver.  */
>  static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
>  
> +/* A prefix to be used when this is an accelerator compiler.  */
> +static const char *const accel_dir_suffix = ACCEL_DIR_SUFFIX;

Is ACCEL_DIR_SUFFIX here "" or something starting with "/ ?

> @@ -4122,15 +4126,15 @@ process_command (unsigned int decoded_options_count,
>  }
>  
>gcc_assert (!IS_ABSOLUTE_PATH (tooldir_base_prefix));
> -  tooldir_prefix2 = concat (tooldir_base_prefix, spec_machine,
> +  tooldir_prefix2 = concat (tooldir_base_prefix, spec_host_machine,
>   dir_separator_str, NULL);
>  
>/* Look for tools relative to the location from which the driver is
>   running, or, if that is not available, the configured prefix.  */
>tooldir_prefix
>  = concat (gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix,
> -   spec_machine, dir_separator_str,
> -   spec_version, dir_separator_str, tooldir_prefix2, NULL);
> +   spec_host_machine, dir_separator_str, spec_version,
> +   accel_dir_suffix, dir_separator_str, tooldir_prefix2, NULL);
>free (tooldir_prefix2);
>  
>add_prefix (&exec_prefixes,

The reason I'm asking is that otherwise it seems gcc.c heavily uses
dir_separator_str for the separators.  Don't have any experience with
targets where DIR_SEPARATOR is not / though, perhaps it is a non-issue.

> @@ -6878,8 +6882,8 @@ main (int argc, char **argv)
>  
>/* Read specs from a file if there is one.  */
>  
> -  machine_suffix = concat (spec_machine, dir_separator_str,
> -spec_version, dir_separator_str, NULL);
> +  machine_suffix = concat (spec_host_machine, dir_separator_str, 
> spec_version,
> +accel_dir_suffix, dir_separator_str, NULL);
>just_machine_suffix = concat (spec_machine, dir_separator_str, NULL);
>  
>specs_file = find_a_file (&startfile_prefixes, "specs", R_OK, true);
> @@ -6889,16 +6893,17 @@ main (int argc, char **argv)
>else
>  init_spec ();
>  
> +#ifndef ACCEL_COMPILER
>/* We need to check standard_exec_prefix/just_machine_suffix/specs
>   for any override of as, ld and libraries.  */
>specs_file = (char *) alloca (strlen (standard_exec_prefix)
>  + strlen (just_machine_suffix) + sizeof ("specs"));
> -
>strcpy (specs_file, standard_exec_prefix);
>strcat (specs_file, just_machine_suffix);
>strcat (specs_file, "specs");
>if (access (specs_file, R_OK) == 0)
>  read_specs (specs_file, true, false);
> +#endif

Why do you want to disable specs reading for the accel compiler?
Then users won't have the possibility to override defaults etc. easily...

> @@ -7097,6 +7103,16 @@ main (int argc, char **argv)
>obstack_grow (&collect_obstack, argv[0], strlen (argv[0]) + 1);
>xputenv (XOBFINISH (&collect_obstack, char *));
>  
> +  if (strlen (OFFLOAD_TARGETS) > 0)
> +{
> +  obstack_init (&collect_obstack);
> +  obstack_grow (&collect_obstack, "OFFLOAD_TARGET_NAMES=",
> + sizeof ("OFFLOAD_TARGET_NAMES=") - 1);
> +  obstack_grow (&collect_obstack, OFFLOAD_TARGETS,
> + strlen (OFFLOAD_TARGETS) + 1);
> +  xputenv (XOBFINISH (&collect_obstack, char *));
> +}
> +

I'm surprised to see the obstack_init call here, but looking at
gcc.c, I'm surprised to see it in more places.

I've always thought that obstack_init was something you invoke generally
once on a given obstack object, then work with the obstack and then
obstack_free (..., NULL) it at the end.  Now, if it wants the obstack to be
live until exit, it just would not obstack_free it.  But calling
obstack_init on the already initialized obstack results IMHO in memory
leaks.  It should be initialized just once somewhere.

>/* Set up to remember the pathname of the lto wrapper. */
>  
>if (have_c)
> diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c
> index 08fd090..2c9b503 100644
> --- a/gcc/lto-wrapper.c
> +++ b/gcc/lto-wrapper.c
> @@ -49,6 +49,8 @@ along with GCC; see the file COPYING3.  If not see
>  #include "lto-section-names.h"
>  #include "collect-utils.h"
>  
> +#define OFFLOAD_TARGET_NAMES_ENV "OFFLOAD_TARGET_NAMES"

Missing comment about the env var and what it is for.

> +/* Prepare a target image for offload TARGET, using mkoffload tool from
> +   COMPILER_PATH.  Return the name of the resultant object file.  */
> +
> +static char *
> +compile_offload_image (const char *target, const char *compiler_path,
> +unsigned in_argc, char *in_argv[])
> +{
> +  char *filename = NULL;
> +  char **argv;
> +  char *suffix
> += XALLOCAVEC (char, strlen ("/accel//mkoffload") + strlen (target) + 1);

Use sizeof ("/accel//mkoffload") + strlen (target) instead?

> +  strcpy (suffix, "/accel/");
> +  strca

Re: [PATCH 1/2] PR debug/63239 Add DWARF representation for C++11 deleted member function.

2014-10-08 Thread Mark Wielaard
On Wed, 2014-10-08 at 10:56 +0200, Rainer Orth wrote:
> Steven Bosscher  writes:
> > On Mon, Oct 6, 2014 at 9:54 AM, Mark Wielaard wrote:
> >> Just removing the # prefix (but keeping the space) from
> >> scan-assembler-times should work for both our cases. I just don't know
> >> why our .s outputs look different.
> >
> > Wild guess: different comment marker in the target's assembly language?
> 
> True: on Solaris/x86 with /bin/as, I have
> 
> / DW_AT_GNU_deleted
> 
> on Solaris/SPARC with /bin/as, it's
> 
> .byte   0x1 ! DW_AT_GNU_deleted
> 
> instead, and probably even more others on different platforms.

Thanks for checking this was the cause of the failure Andreas was
seeing. I pushed the following as obvious to fix it. Please yell and
scream if it wasn't obvious or if it doesn't solve the failure.

Cheers,

Mark

diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 723412c..21b2c26 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2014-10-08  Mark Wielaard  
+
+   * g++.dg/debug/dwarf2/deleted-member-function.C: Remove comment marker
+   prefix from scan-assembler-times.
+
 2014-10-07  Marek Polacek  
 
* lib/target-supports.exp (check_effective_target_fd_truncate):
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/deleted-member-function.C 
b/gcc/testsuite/g++.dg/debug/dwarf2/deleted-member-function.C
index 4cc77e6..50a8451 100644
--- a/gcc/testsuite/g++.dg/debug/dwarf2/deleted-member-function.C
+++ b/gcc/testsuite/g++.dg/debug/dwarf2/deleted-member-function.C
@@ -1,6 +1,6 @@
 // { dg-do compile }
 // { dg-options "-O -std=c++11 -g -dA" }
-// { dg-final { scan-assembler-times "# DW_AT_GNU_deleted" 2 } }
+// { dg-final { scan-assembler-times " DW_AT_GNU_deleted" 2 } }
 
 struct Foo
 {



Re: [PATCH RFC]Pair load store instructions using a generic scheduling fusion pass

2014-10-08 Thread Ramana Radhakrishnan
>> If the port has a splitter to rip apart a douple-word load into single-word 
>> loads, then we'd obviously only want to do that in cases where the 
>> double-word load actually generates > 1 assembly instruction.

Or indeed if it is really a performance win. And I think that should
purely be a per port / micro-architectural decision .

>
> For arm/aarch64, I guess it's not an issue, otherwise the peephole2
> won't work at all.  ARM maintainers should have answer to this.

Generating more ldrd's and strd's will be beneficial in the ARM and
the AArch64 port - we save code size and start using more memory
bandwidth available per instruction on most higher end cores that I'm
aware of. Even on the smaller microcontrollers I expect it to be a win
because you've saved code size. There may well be pathological cases
given we've shortened some dependencies or increased lifetimes of
others but overall I'd expect it to be more positive than negative.

I also expect this to be more effective in the T32 (Thumb2) ISA and
AArch64 because ldrd/ strd and ldp / stp respectively can work with
any registers unlike the A32 ISA where the registers loaded or stored
must be consecutive registers. I'm hoping for some more review on the
generic bits before looking into the backend implementation in the
expectation that this is the direction folks want to proceed.


regards
Ramana




>
>
>>
>> jeff


Re: [PATCH] PR debug/38757 gcc does not emit DW_LANG_C99

2014-10-08 Thread Mark Wielaard
On Wed, 2014-10-08 at 12:17 +0200, Marek Polacek wrote:
> On Wed, Oct 08, 2014 at 12:13:55PM +0200, Mark Wielaard wrote:
> > This lang hook will be more useful when DWARFv5 gets out, which is
> > supposed to define language identifiers for newer C and C++ versions.
>  
> It might have been discussed elsewhere, so sorry for not paying attention,
> but what about DW_LANG_C11?

That is one of the new language versions to hopefully gets a definition
with DWARFv5. http://dwarfstd.org/ShowIssue.php?issue=140330.1

Cheers,

Mark


Re: [PATCH] PR debug/38757 gcc does not emit DW_LANG_C99

2014-10-08 Thread Jakub Jelinek
On Wed, Oct 08, 2014 at 12:29:38PM +0200, Mark Wielaard wrote:
> On Wed, 2014-10-08 at 12:17 +0200, Marek Polacek wrote:
> > On Wed, Oct 08, 2014 at 12:13:55PM +0200, Mark Wielaard wrote:
> > > This lang hook will be more useful when DWARFv5 gets out, which is
> > > supposed to define language identifiers for newer C and C++ versions.
> >  
> > It might have been discussed elsewhere, so sorry for not paying attention,
> > but what about DW_LANG_C11?
> 
> That is one of the new language versions to hopefully gets a definition
> with DWARFv5. http://dwarfstd.org/ShowIssue.php?issue=140330.1

Yeah, that is 0x1d it seems, but we don't have
DW_LANG_C_plus_plus_14
unfortunately.  IMHO still something that must be added to DWARF5.

Jakub


[PATCH] libgcc: unwind-dw2-fde.h: Use "(const fde *)" instead of "(char *)" to avoid qualifier warning

2014-10-08 Thread Chen Gang
If no negative effect with keeping code clear and simple, need try to
avoid warning, especially use our own 'xgcc' for our own code. The
related warning under Darwin is:

  /var/root/upstream/build-gcc-new/./gcc/xgcc 
-B/var/root/upstream/build-gcc-new/./gcc/ 
-B/usr/local/x86_64-apple-darwin13.4.0/bin/ 
-B/usr/local/x86_64-apple-darwin13.4.0/lib/ -isystem 
/usr/local/x86_64-apple-darwin13.4.0/include -isystem 
/usr/local/x86_64-apple-darwin13.4.0/sys-include-g -O2 -m32 -O2  -g -O2 
-DIN_GCC-W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-format 
-Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition  -isystem 
./include   -pipe -fno-common -g -DIN_LIBGCC2 -fbuilding-libgcc 
-fno-stack-protector   -pipe -fno-common -I. -I. -I../../.././gcc 
-I../../../../gcc-new/libgcc -I../../../../gcc-new/libgcc/. 
-I../../../../gcc-new/libgcc/../gcc -I../../../../gcc-new/libgcc/../include  
-DHAVE_CC_TLS -DUSE_EMUTLS -o unwind-dw2-fde-darwin_s.o -MT 
unwind-dw2-fde-darwin_s.o -MD -MP -MF unwind-dw2-fde-darwin_s.dep -DSHARED 
-fexceptions -c ../../../../gcc-new/libgcc/config/unwind-dw2-fde-darwin.c
  In file included from 
../../../../gcc-new/libgcc/config/unwind-dw2-fde-darwin.c:35:0:
  ../../../../gcc-new/libgcc/unwind-dw2-fde.h: In function 'last_fde':
  ../../../../gcc-new/libgcc/unwind-dw2-fde.h:172:10: warning: cast discards 
'const' qualifier from pointer target type [-Wcast-qual]
 return (char *)f == obj->fde_end || f->length == 0;
  ^

It passes "make -k check" under Darwin x86_64.

2014-10-07  Chen Gang  

* unwind-dw2-fde.h (last_fde): Use "(const fde *)" instead of
"(char *)" to avoid qualifier warning by 'xgcc' compiling.
---
 libgcc/unwind-dw2-fde.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libgcc/unwind-dw2-fde.h b/libgcc/unwind-dw2-fde.h
index c8201c6..8a71aa6 100644
--- a/libgcc/unwind-dw2-fde.h
+++ b/libgcc/unwind-dw2-fde.h
@@ -169,7 +169,7 @@ static inline int
 last_fde (struct object *obj __attribute__ ((__unused__)), const fde *f)
 {
 #ifdef DWARF2_OBJECT_END_PTR_EXTENSION
-  return (char *)f == obj->fde_end || f->length == 0;
+  return f == (const fde *) obj->fde_end || f->length == 0;
 #else
   return f->length == 0;
 #endif
-- 
1.8.5.2 (Apple Git-48)


Re: [PATCH, RTL]: Fix PR 63483, Scheduler performs Invalid move of aliased memory reference

2014-10-08 Thread Richard Biener
On Wed, 8 Oct 2014, Uros Bizjak wrote:

> Hello!
> 
> This message revives an old thread [1], where the miscompilation of gfortran
> on alpha was found that that resulted in:
> 
> FAIL: gfortran.dg/assumed_rank_3.f90:15.20:
> 
> print *, ubound(x,dim=3)  ! << wrong dim
> 1
> Error: Assumed-rank variable x at (1) may only be used as actual argument
> 
> The problem was in the miscompilation of resolve_actual_arglist from
> resolve.c.  This function initializes two nearby global bool variables
> with the following sequence:
> 
>   actual_arg = true;
>   first_actual_arg = true;
> 
> but due to the miscompilation, the actual_arg was never set to true.
> This happened due to the way stores to QImode and HImode locations are
> implemented on non-BWX targets. The sequence reads full word, does its
> magic to the part and stores the full word with changed part back to
> the memory. However - the scheduler mixed two sequences, violating the
> atomicity of RMW sequence.
> 
> As demostrated in the great detail in the PR [2], the problem is in
> early exit  for MEM_READOLNY_P in true_dependence_1 in alias.c. This
> early exit declares all MEM_READONLY_P references as non-aliasing,
> which is not true when possibly aliasing references with alignment
> ANDs are involved.
> 
> Proposed patch prevents MEM_READONLY_P memory references to be moved
> over possibly aliased memory (with alignment ANDs). The patch prevents
> early exit for MEM_READONLY_P references when alignment ANDs are
> involved. The aliasing is then determined later in the function. In
> effect, it changes early exit to:
> 
> -  if (MEM_READONLY_P (x))
> -return 0;
> +  if (MEM_READONLY_P (x)
> +  && GET_CODE (x_addr) != AND
> +  && GET_CODE (mem_addr) != AND)
> +return 0;
> 
> The comment also mentions "... We don't expect to find read-only set
> on MEM, but stupid user tricks can produce them, so don't die.". We
> certainly don't die anymore, as confirmed by a native alpha-linux-gnu
> (please note - not alphaev6!) bootstrap and regression test.
> 
> 2014-10-08  Uros Bizjak  
> 
> * alias.c (true_dependence_1): Do not exit early for MEM_READONLY_P
> references when alignment ANDs are involved.
> 
> The patch was bootstrapped and regression tested on alpha-linux-gnu.
> 
> OK for mainline and release branches?

As said in the audit trail of the bugreport I think that the caller
of alpha_set_memflags is wrong in applying MEM flags from the _source_
operand to MEMs generated for the RMW sequence for the destination.

It would be better to fix that instead.

Richard.

> Please note that the patch by itself is not enough to fix the original
> problem with gfortran miscompilation. Another problem in this area is
> summarised in PR 63475 [3], where postreload CSE propagates aliased
> memory operand.
> 
> [1] https://gcc.gnu.org/ml/gcc-patches/2014-06/msg02251.html
> [2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63483
> [3] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63475
> 
> Uros.
> 

-- 
Richard Biener 
SUSE / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746
GF: Jeff Hawn, Jennifer Guild, Felix Imend"orffer


Re: RFA: Fix debug address mode for TARGET_MEM_REF

2014-10-08 Thread Richard Biener
On Wed, Oct 8, 2014 at 10:16 AM, Joern Rennecke
 wrote:
> Trying to build avr2 strftime of avr-libc ICEs as we are trying to
> convert a PSImode address to HImode.  There is no reason to
> do this conversion in the first place - it is a case of failing to recognize
> the proper address space.
>
> The attached patch fixes this.
>
> Bootstrapped on i686-pc-linux-gnu.
>
> OK to apply?

The address-space of TARGET_MEM_REFs is in

TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)

see TARGET_MEM_REF expansion or the MEM_REF handling.

It's unconditionally there, all the if()s in the existing code are bogus.

Thus

Index: cfgexpand.c
===
--- cfgexpand.c (revision 215917)
+++ cfgexpand.c (working copy)
@@ -3286,7 +3286,7 @@ expand_gimple_stmt_1 (gimple stmt)
@@ -3983,11 +3983,7 @@ expand_debug_expr (tree exp)
   if (!op0)
return NULL;

-  if (POINTER_TYPE_P (TREE_TYPE (exp)))
-   as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)));
-  else
-   as = ADDR_SPACE_GENERIC;
-
+  as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0;
   op0 = convert_debug_memory_address (targetm.addr_space.address_mode (as),
  op0, as);
   if (op0 == NULL_RTX)

is pre-approved.

Thanks,
Richard.


Re: [PATCH] PR debug/38757 gcc does not emit DW_LANG_C99

2014-10-08 Thread Mark Wielaard
On Wed, 2014-10-08 at 12:35 +0200, Jakub Jelinek wrote:
> On Wed, Oct 08, 2014 at 12:29:38PM +0200, Mark Wielaard wrote:
> > On Wed, 2014-10-08 at 12:17 +0200, Marek Polacek wrote:
> > > On Wed, Oct 08, 2014 at 12:13:55PM +0200, Mark Wielaard wrote:
> > > > This lang hook will be more useful when DWARFv5 gets out, which is
> > > > supposed to define language identifiers for newer C and C++ versions.
> > >  
> > > It might have been discussed elsewhere, so sorry for not paying attention,
> > > but what about DW_LANG_C11?
> > 
> > That is one of the new language versions to hopefully gets a definition
> > with DWARFv5. http://dwarfstd.org/ShowIssue.php?issue=140330.1
> 
> Yeah, that is 0x1d it seems, but we don't have
> DW_LANG_C_plus_plus_14
> unfortunately.  IMHO still something that must be added to DWARF5.

Good point. There is a proposal to add DW_LANG_C_plus_plus_03 (0x17) and
DW_LANG_C_plus_plus_11 (0x18)
http://dwarfstd.org/ShowIssue.php?issue=120628.1
But no DW_LANG_C_plus_plus_14 yet. Probably because C++14 only got
approved last August. Although it has been too late to submit new
proposals for DWARFv5 since a couple of months now I did submit one
anyway. Hopefully we can still sneak it in before there is a first draft
of DWARFv5 out. http://article.gmane.org/gmane.comp.standards.dwarf/218

Cheers,

Mark


Re: [PATCH] gcc.dg/torture/ cleanup

2014-10-08 Thread Rainer Orth
Marek Polacek  writes:

> This patch is a cleanup of tests in gcc.dg/torture directory.
> See https://gcc.gnu.org/ml/gcc-patches/2014-09/msg02656.html for more info.
>
> Tested on x86_64-linux: vanilla results == results with this patch ==
> results with this patch and gnu11 as a default.
>
> Ok?
>
> 2014-10-02  Marek Polacek  
>
>   * gcc.dg/torture/pr24626-2.c: Add function declarations.  Fix
>   defaulting to int.
[...]
>   * gcc.dg/torture/stackalign/builtin-apply-4.c: Use -fgnu89-inline.
[...]
> diff --git gcc/gcc/testsuite/gcc.dg/torture/stackalign/builtin-apply-4.c 
> gcc/gcc/testsuite/gcc.dg/torture/stackalign/builtin-apply-4.c
> index 28dc610..d958293 100644
> --- gcc/gcc/testsuite/gcc.dg/torture/stackalign/builtin-apply-4.c
> +++ gcc/gcc/testsuite/gcc.dg/torture/stackalign/builtin-apply-4.c
> @@ -1,5 +1,6 @@
>  /* PR tree-optimization/20076 */
>  /* { dg-do run } */
> +/* { dg-options "-fgnu89-inline" } */
>  
>  extern void abort (void);
>  

This patch completely broke the builtin-apply-4.c execution tests on
Solaris 11/x86 (and undoubtedly on many other platforms).
stackalign.exp has this comment:

# default_flags are replaced by a dg-options test directive, or appended
# to by using dg-additional-options.  Use default_flags for options that
# are used in all of the torture sets to limit the amount of noise in
# test summaries.
set default_flags ""

and by using dg-options in the testcase, you override everything in
default_flags ;-(

Switching to dg-additional-options fixes the problem, as tested with the
appropriate runtest invocation on i386-pc-solaris2.11.

Installed on mainline.

Rainer


2014-10-08  Rainer Orth  

* gcc.dg/torture/stackalign/builtin-apply-4.c: Use
dg-additional-options.

diff --git a/gcc/testsuite/gcc.dg/torture/stackalign/builtin-apply-4.c b/gcc/testsuite/gcc.dg/torture/stackalign/builtin-apply-4.c
--- a/gcc/testsuite/gcc.dg/torture/stackalign/builtin-apply-4.c
+++ b/gcc/testsuite/gcc.dg/torture/stackalign/builtin-apply-4.c
@@ -1,6 +1,6 @@
 /* PR tree-optimization/20076 */
 /* { dg-do run } */
-/* { dg-options "-fgnu89-inline" } */
+/* { dg-additional-options "-fgnu89-inline" } */
 
 extern void abort (void);
 

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


Re: [PATCH 5/n] OpenMP 4.0 offloading infrastructure: libgomp

2014-10-08 Thread Jakub Jelinek
On Mon, Oct 06, 2014 at 07:53:17PM +0400, Ilya Verbin wrote:
> 2014-10-06  Jakub Jelinek  
>   Ilya Verbin  
>   Thomas Schwinge  
>   Andrey Turetskiy  
> 
> libgomp/
>   * libgomp.map (GOMP_4.0.1): New symbol version.
>   Add GOMP_offload_register.
>   * libgomp_target.h: New file.
>   * splay-tree.h: New file.
>   * target.c: Include config.h, libgomp_target.h, dlfcn.h, splay-tree.h.
>   (gomp_target_init): New forward declaration.
>   (gomp_is_initialized): New static variable.
>   (splay_tree_node, splay_tree, splay_tree_key): New typedefs.
>   (struct target_mem_desc, struct splay_tree_key_s, offload_image_descr):
>   New structures.
>   (offload_images, num_offload_images, devices, num_devices): New static
>   variables.
>   (splay_compare): New static function.
>   (struct gomp_device_descr): New structure.
>   (gomp_get_num_devices): Call gomp_target_init.
>   (resolve_device, gomp_map_vars_existing, gomp_map_vars, gomp_unmap_tgt)
>   (gomp_unmap_vars, gomp_update, gomp_init_device): New static functions.
>   (GOMP_offload_register): New function.
>   (GOMP_target): Arrange for host callback to be performed in a separate
>   initial thread and contention group, inheriting ICVs from
>   gomp_global_icv etc.  Call gomp_map_vars and gomp_unmap_vars.
>   Add device initialization and lookup for target function in splay tree.
>   (GOMP_target_data): Add device initialization and call gomp_map_vars.
>   (GOMP_target_end_data): Call gomp_unmap_vars.
>   (GOMP_target_update): Add device initialization and call gomp_update.
>   (gomp_load_plugin_for_device, gomp_register_images_for_device)
>   (gomp_target_init): New static functions.

This looks good to me.

Jakub


Re: [PATCH v2] libstdc++: Add hexfloat/defaultfloat io manipulators.

2014-10-08 Thread Rainer Orth
Jonathan Wakely  writes:

> On 28/03/14 08:56 +0900, Luke Allardyce wrote:
>>It looks like the new standard also requires the precision to be
>>ignored for hexfloat
>>
>>>For conversion from a floating-point type, if floatfield !=
>> (ios_base::fixed | ios_base:: scientific), str.precision() is specified
>> as precision in the conversion specification. Otherwise, no precision is
>> specified.
>
> I've made this change and adjusted the test so that it doesn't make
> any assumptions about the exact format of hexadecimal float output, as
> it's unspecified whether you get e.g. 0x1.ep+3 or 0xfp+0 for 15.
>
> As Luke pointed out, this changes the behaviour of some valid C++03
> programs, but I think that's the right thing to do in this case. I'll
> document that in the release notes.
>
> Tested x86_64-linux, committed to trunk.

On Solaris 11 (both SPARC and x86), the test execution FAILs:

Assertion failed: os && std::stod(os.str()) == d, file 
/vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/hexfloat.cc,
 line 51, function test01
FAIL: 27_io/basic_ostream/inserters_arithmetic/char/hexfloat.cc execution test

With -DTEST_NUMPUT_VERBOSE, I get

got: 0x1.0p-1074

Rainer

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


Re: [PATCH v2] libstdc++: Add hexfloat/defaultfloat io manipulators.

2014-10-08 Thread Jonathan Wakely

On 08/10/14 13:27 +0200, Rainer Orth wrote:

On Solaris 11 (both SPARC and x86), the test execution FAILs:

Assertion failed: os && std::stod(os.str()) == d, file 
/vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/hexfloat.cc,
 line 51, function test01
FAIL: 27_io/basic_ostream/inserters_arithmetic/char/hexfloat.cc execution test

With -DTEST_NUMPUT_VERBOSE, I get

got: 0x1.0p-1074


Thanks, I'll look into that too.



Re: [PATCH] PR58867 ASan and UBSan tests not run for installed testing.

2014-10-08 Thread Marcus Shawcroft
On 8 October 2014 11:10, Maxim Ostapenko
 wrote:
> Does it work without restore_ld_library_path in {asan, ubsan, tsan}_finish?
>
> I see two opportunities to fix the issue:
>
> 1) Implement a stack of saved contexts.
>
> 2) Implement new functions, say {asan, ubsan, tsan}_restore_ld_library_path,
> to be able {asan, ubsan, tsan}_finish functions restore context correctly.
>
> What solution is preferable?

Option 1 has the advantage that it places all of the context save and
restore in one place rather than spreading it around the
infrastructure.

Please can we revert this patch while a correct implementation is being worked?

Cheers
/Marcus


RE: [Patch, MIPS] Add .note.GNU-stack section

2014-10-08 Thread Matthew Fortune
> I talked to Andrew about what files he changed in GCC and created and
> tested this new patch.  Andrew also mentioned changing some assembly
> files in glibc but I don't see any use of '.section .note.GNU-stack' in
> any assembly files in glibc (for any platform) so I wasn't planning on
> creating a glibc to add them to mips glibc assembly language files.
> 
> OK to check in this patch?

I think we need to wait for some conclusion about how the kernel will
cope with a non-executable stack before committing this. The discussion
is progressing on the glibc and kernel lists.

As far as I can tell the kernel will respond to the PT_GNU_STACK
segment already for MIPS and then lead to a crash if the FPU emulator is
invoked. If this is the case then it would be ideal if we can somehow
prevent a stack becoming non-executable unless built against a kernel
which is known to be safe for no-execstack.

Existing versions of glibc will simply follow suit with the compiler
and apply --noexecstack when building assembly files if the compiler
emits a .note.GNU-stack section. Given that behaviour then as soon
as we enable no-execstack support in the compiler then we will get
PT_GNU_STACK on the binaries and risk a crash.

I'm struggling to come up with a good way to make this safe on existing
kernels. One possibility is that MIPS would have to implement the
compiler driven no-execstack support by passing the --no-execstack
option to the assembler instead of using the .note.GNU-stack section
explicitly. This would avoid triggering the configure check in glibc
and allow us to write a MIPS specific check in glibc which looks at
both the kernel version and whether the compiler enables no-execstack.

Slightly convoluted but safe. I'm not sure how uclibc and musl deal
with this issue but we should really check them too (but they are still
secondary to glibc I think). Any other ideas?

Matthew

> 
> Steve Ellcey
> sell...@mips.com
> 
> 
> 
> 2014-09-26  Steve Ellcey  
> 
>   * config/mips/mips.c (TARGET_ASM_FILE_END): Define.
>   * libgcc/config/mips/mips16.S: Add .note.GNU-stack section.
>   * libgcc/config/mips/vr4120-div.S: Ditto.
>   * libgcc/config/mips/crti.S: Ditto.
>   * libgcc/config/mips/crtn.S: Ditto.
> 
> 
> diff --git a/gcc/config/mips/mips.c b/gcc/config/mips/mips.c
> index f9713c1..39020d7 100644
> --- a/gcc/config/mips/mips.c
> +++ b/gcc/config/mips/mips.c
> @@ -19146,6 +19146,9 @@ mips_lra_p (void)
>  #undef TARGET_LRA_P
>  #define TARGET_LRA_P mips_lra_p
> 
> +#undef TARGET_ASM_FILE_END
> +#define TARGET_ASM_FILE_END file_end_indicate_exec_stack
> +
>  struct gcc_target targetm = TARGET_INITIALIZER;
>  

>  #include "gt-mips.h"
> diff --git a/libgcc/config/mips/crti.S b/libgcc/config/mips/crti.S
> index 6980594..93436c0 100644
> --- a/libgcc/config/mips/crti.S
> +++ b/libgcc/config/mips/crti.S
> @@ -21,6 +21,10 @@ a copy of the GCC Runtime Library Exception along with
> this program;
>  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
>  .  */
> 
> +
> +/* An executable stack is *not* required for these functions.  */
> + .section .note.GNU-stack,"",%progbits
> +
>  /* 4 slots for argument spill area.  1 for cpreturn, 1 for stack.
> Return spill offset of 40 and 20.  Aligned to 16 bytes for n32.  */
> 
> diff --git a/libgcc/config/mips/crtn.S b/libgcc/config/mips/crtn.S
> index 0de2d0c..6f2c301 100644
> --- a/libgcc/config/mips/crtn.S
> +++ b/libgcc/config/mips/crtn.S
> @@ -21,6 +21,9 @@ a copy of the GCC Runtime Library Exception along with
> this program;
>  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
>  .  */
> 
> +/* An executable stack is *not* required for these functions.  */
> +.section .note.GNU-stack,"",%progbits
> +
>  /* 4 slots for argument spill area.  1 for cpreturn, 1 for stack.
> Return spill offset of 40 and 20.  Aligned to 16 bytes for n32.  */
> 
> diff --git a/libgcc/config/mips/mips16.S b/libgcc/config/mips/mips16.S
> index dde8939..58e4377 100644
> --- a/libgcc/config/mips/mips16.S
> +++ b/libgcc/config/mips/mips16.S
> @@ -35,6 +35,10 @@ see the files COPYING3 and COPYING.RUNTIME
> respectively.  If not, see
> values using the soft-float calling convention, but do the actual
> operation using the hard floating point instructions.  */
> 
> +/* An executable stack is *not* required for these functions.  */
> +.section .note.GNU-stack,"",%progbits
> + .previous
> +
>  #if defined _MIPS_SIM && (_MIPS_SIM == _ABIO32 || _MIPS_SIM == _ABIO64)
> 
>  /* This file contains 32-bit assembly code.  */
> diff --git a/libgcc/config/mips/vr4120-div.S b/libgcc/config/mips/vr4120-
> div.S
> index 76c4e7a..664d3c3 100644
> --- a/libgcc/config/mips/vr4120-div.S
> +++ b/libgcc/config/mips/vr4120-div.S
> @@ -26,6 +26,10 @@ see the files COPYING3 and COPYING.RUNTIME
> respectively.  If not, see
> -mfix-vr4120.  div and ddiv do not give the corr

Re: [PATCH, RTL]: Fix PR 63483, Scheduler performs Invalid move of aliased memory reference

2014-10-08 Thread Uros Bizjak
On Wed, Oct 8, 2014 at 12:51 PM, Richard Biener  wrote:

>> This message revives an old thread [1], where the miscompilation of gfortran
>> on alpha was found that that resulted in:

[...]

> As said in the audit trail of the bugreport I think that the caller
> of alpha_set_memflags is wrong in applying MEM flags from the _source_
> operand to MEMs generated for the RMW sequence for the destination.
>
> It would be better to fix that instead.

Please see comment #6 of the referred PR [1] for further analysis and
ammended testcase. The testcase and analysis will show a "native" read
passing possibly aliasing store.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63483#c6

Uros.


[C PATCH] Don't warn on = { } initialization (PR c/63480)

2014-10-08 Thread Marek Polacek
PR63480 points out that -Wmissing-field-initializers warns about
initializing with { }.  Given that we suppress the warning for
initializing with { 0 }, I think it makes sense to suppress it
for { } as well.
(Initializing with { } is a GNU extension and -pedantic warns on that.)

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

2014-10-08  Marek Polacek  

PR c/63480
* c-typeck.c (pop_init_level): Don't warn about initializing
with { }.

* gcc.dg/pr63480.c: New test.

diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
index b3b82bb..5c0697a 100644
--- gcc/c/c-typeck.c
+++ gcc/c/c-typeck.c
@@ -7436,7 +7436,11 @@ pop_init_level (location_t loc, int implicit,
}
 }
 
-  if (vec_safe_length (constructor_elements) != 1)
+  /* Initialization with { } counts as zeroinit.  */
+  if (vec_safe_length (constructor_elements) == 0)
+constructor_zeroinit = 1;
+  /* If the constructor has more than one element, it can't be { 0 }.  */
+  else if (vec_safe_length (constructor_elements) != 1)
 constructor_zeroinit = 0;
 
   /* Warn when some structs are initialized with direct aggregation.  */
@@ -7463,7 +7467,7 @@ pop_init_level (location_t loc, int implicit,
/* Do not warn if this level of the initializer uses member
   designators; it is likely to be deliberate.  */
&& !constructor_designated
-   /* Do not warn about initializing with ` = {0}'.  */
+   /* Do not warn about initializing with { 0 } or with { }.  */
&& !constructor_zeroinit)
  {
if (warning_at (input_location, OPT_Wmissing_field_initializers,
diff --git gcc/testsuite/gcc.dg/pr63480.c gcc/testsuite/gcc.dg/pr63480.c
index e69de29..89e2586 100644
--- gcc/testsuite/gcc.dg/pr63480.c
+++ gcc/testsuite/gcc.dg/pr63480.c
@@ -0,0 +1,14 @@
+/* PR c/63480 */
+/* { dg-do compile } */
+/* { dg-options "-Wmissing-field-initializers" } */
+
+/* Test that we don't warn about initializing with { }.  */
+
+struct S { int a, b, c; } s = { };
+
+void
+foo (void)
+{
+  struct S s = { }; 
+  struct S s2 = (struct S){ };
+}

Marek


Re: [PATCH] gcc.dg/torture/ cleanup

2014-10-08 Thread Marek Polacek
On Wed, Oct 08, 2014 at 01:06:50PM +0200, Rainer Orth wrote:
> This patch completely broke the builtin-apply-4.c execution tests on
> Solaris 11/x86 (and undoubtedly on many other platforms).
> stackalign.exp has this comment:
> 
> # default_flags are replaced by a dg-options test directive, or appended
> # to by using dg-additional-options.  Use default_flags for options that
> # are used in all of the torture sets to limit the amount of noise in
> # test summaries.
> set default_flags ""
> 
> and by using dg-options in the testcase, you override everything in
> default_flags ;-(

Sorry about that.  I haven't seen any fail on x86/ppc64, so I missed
this one.

Marek


Re: [Patch ARM-AArch64/testsuite v2 01/21] Neon intrinsics execution tests initial framework.

2014-10-08 Thread Ramana Radhakrishnan



What do you prefer me to do for these tests? I can think of:
- do not include them at all until fp16 is fully supported on both
AArch32 and AArch64
- include only those with float16x4_t
- include both float16x4_t and float16x8_t tests, leaving float16x8_t commented


I would include them both and XFAIL the failing tests. So when the 
support arrives, it's just a question of adjusting the tests.



regards
Ramana




Thanks,

Christophe.



Thanks
/Marcus




Re: RFA: Fix debug address mode for TARGET_MEM_REF

2014-10-08 Thread Joern Rennecke
On 8 October 2014 12:02, Richard Biener  wrote:
...
> -  if (POINTER_TYPE_P (TREE_TYPE (exp)))
> -   as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)));
> -  else
> -   as = ADDR_SPACE_GENERIC;
> -
> +  as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0;
>op0 = convert_debug_memory_address (targetm.addr_space.address_mode 
> (as),
>   op0, as);
>if (op0 == NULL_RTX)
>
> is pre-approved.

Thanks.  manually applied, avr2 strftime build confirmed,
i386-pc-linux-gnu bootstrapped, and checked in.


Re: [PATCH 2/2] PR debug/63240 Add DWARF representation for C++11 defaulted member function.

2014-10-08 Thread Jason Merrill

On 10/07/2014 09:36 AM, Siva Chandra wrote:

Barring some incompleteness, for which patches are very close to
getting committed, I believe GDB has the rest of the information.


Interesting.  It is still the case that defaulting in the class is 
different from defaulting outside the class, though; a function 
defaulted outside the class is user-provided, and therefore not trivial. 
 But rather than encode "defaulted in the class body" (as Mark's 
initial patch) I'd prefer to just encode "trivial".


DW_AT_artificial is for things not actually declared in the source, so 
using it for explicitly declared functions is incorrect.


Jason



Re: [PATCH, ARM] attribute target (thumb,arm)

2014-10-08 Thread Ramana Radhakrishnan

Hi Christian,

	Thanks for looking at this. I will need to read the code in detail but 
this is a first top level reivew.


On 09/29/14 12:03, Christian Bruel wrote:

Hi Ramana, Richard,

This patch implements the attribute target (and pragma) to allow
function based interworking.

as in the updated documentation, the syntax is:

  __attribute__((target("thumb"))) int foo()
Forces thumb mode for function foo only. If the file was compiled with
-mthumb iit has no effect.


Indeed




Similarly

  __attribute__((target("arm"))) int foo()
Forces arm mode for function foo. It has no effect if the file was not
compiled with -mthumb.


Indeed.



and regions can be grouped together with

#pragma GCC target ("thumb")
or
#pragma GCC target ("arm")

a few notes
- Inlining is allowed between functions of the same mode (compilation
switch, #pragma and attribute)


Why shouldn't we allow inlining between functions of ARM mode vs Thumb 
mode ? After all the choice of mode is irrelevant at the time of 
inlining (except possibly for inline assembler).


Perhaps an option is to try to disable inlining in the presence of 
inline assembler or if not gate it from a command line option.



- 'arm_option_override' is now reorganized around
'arm_option_override_internal' for thumb related macros


Looks like a reasonable start - We need a couple of tests to make sure 
that __attribute__(("arm")) on a file compiled for the M profile results 
in a syntax error. v7(e)m is Thumb2 only.


for bonus points it would be great to get __attribute__(("target")) 
working properly in the backend. I suspect a number of the tuning flags 
and the global architecture state needs to be moved into this as well to 
handle cases where __attribute__(("arm")) used with M profile options is 
error'd out.



- I kept TARGET_UNIFIED_ASM to minimize changes. Although removing it
would avoid to switch between unified/divided asms


I know Terry's been trying to get Thumb1 to also switch by default to 
unified asm. So I think a lot of the logic with "emit_thumb" could just 
go away. Maybe we should just consider switching ARM state to unified 
syntax and that would be as simple as changing TARGET_UNIFIED_SYNTAX in 
arm.h to be TARGET_32BIT. Long overdue IMHO.


The only gotcha here is inline assembler but GAS is so permissive that 
I'm not too worried about it in ARM state and Thumb2 state. I'm a bit 
worried about Thumb1.




   and simplify arm_declare_function_name. Should be considered at some
point.


I think that can be done for a lot of newer cores - some of that logic 
is dated now IIUC.


I remember why my original project failed - I couldn't get enough of the 
backend in shape for the state to be saved and restored and then I moved 
on to other more interesting things, so whatever is done here needs to 
make sure that all ISA mode state is saved and restored.


One thing I experimented with while doing this work was adding something 
like the mflip-mips16 option and then have the testsuite run with this 
option to try and make sure enough of the backend state is saved and 
restored properly.


This will give more testing coverage hopefully to the switching logic 
for the attributes and hopefully expose any issues that are there with 
respect to saving and restoring state. The problem you'll probably find 
is that in some of the gcc.target/arm tests the flipping of state will 
cause various interesting failures. The other side is making sure that 
all state that is global is now captured and reinitialized everytime we 
switch context between ARM and Thumb.


I'm not sure how to best test the pragma switching logic but given that 
the 2 hang off each other, it should just work (TM) if one is right. In 
any case adding some testcases that direct test this would be useful.




- It is only available for Thumb2 variants (for thumb1 lack of interest
and a few complications I was unable to test, although this could be
added easily if needed, I think)



I don't think we should restrict this to Thumb1 or Thumb2 it should be 
allowed if the architecture allows it.


For example __attribute__((thumb)) on a function compiled with 
-march=armv5te -mfloat-abi=softfp -mfpu=vfpv3 should give a syntax error 
as this is not supported. No VFP instructions in Thumb1. Explicit tests 
for this would be appreciated.


IIRC all other cases should be accepted.




Tested for no regression for arm-none-eabi [,-with-arch=armv7-a]

   OK for trunk ?


Sorry not yet.

I would also like some documentation added to extend.texi for these 
attributes.


So in summary.

1. Some documentation in extend.texi please.
2. TARGET_UNIFIED_SYNTAX to be turned on for ARM state too.
3. Testcases for this and some testing with a mflip-thumbness switch 
(added only for testing).

4. Investigate further giving up restriction on Thumb1.
5. Investigate lifting inlining restriction for __attribute__(("arm")) 
or __attribute__ (("thumb")) or maybe gate it off a command line option.
6. Split thi

Re: [PATCH v2] libstdc++: Add hexfloat/defaultfloat io manipulators.

2014-10-08 Thread Jonathan Wakely

On 08/10/14 11:07 +0100, Jonathan Wakely wrote:

On 07/10/14 21:10 +0200, Andreas Schwab wrote:

That cannot work.  std::__convert_from_v always passes __prec before
__v, but the format is "%a".


Ah yes. I'm testing this fix now.


Committed.

I assume it was working for me because __convert_from_v("%a", 6, 272.)
happens to pass the double differently from the integer, and vsnprintf
looks for a double in the relevant register and ignores the integer
argument.



commit 543771e2db1642715854ae4bec81d803ca8e2e59
Author: Jonathan Wakely 
Date:   Wed Oct 8 10:39:27 2014 +0100

* include/bits/locale_facets.tcc (num_put::_M_insert_float): Do not
pass precision when using hexfloat format.
* src/c++98/locale_facets.cc (__num_base::_S_format_float): Always
output precision if C99 hexfloat conversion specifiers not available.

diff --git a/libstdc++-v3/include/bits/locale_facets.tcc 
b/libstdc++-v3/include/bits/locale_facets.tcc
index cf12a08..88adc0d 100644
--- a/libstdc++-v3/include/bits/locale_facets.tcc
+++ b/libstdc++-v3/include/bits/locale_facets.tcc
@@ -988,20 +988,32 @@ _GLIBCXX_BEGIN_NAMESPACE_LDBL
__num_base::_S_format_float(__io, __fbuf, __mod);

#ifdef _GLIBCXX_USE_C99
+   // Precision is always used except for hexfloat format.
+   const bool __use_prec =
+ (__io.flags() & ios_base::floatfield) != ios_base::floatfield;
+
// First try a buffer perhaps big enough (most probably sufficient
// for non-ios_base::fixed outputs)
int __cs_size = __max_digits * 3;
char* __cs = static_cast(__builtin_alloca(__cs_size));
-   __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
- __fbuf, __prec, __v);
+   if (__use_prec)
+ __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
+   __fbuf, __prec, __v);
+   else
+ __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
+   __fbuf, __v);

// If the buffer was not large enough, try again with the correct size.
if (__len >= __cs_size)
  {
__cs_size = __len + 1;
__cs = static_cast(__builtin_alloca(__cs_size));
-   __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
- __fbuf, __prec, __v);
+   if (__use_prec)
+ __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
+   __fbuf, __prec, __v);
+   else
+ __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
+   __fbuf, __v);
  }
#else
// Consider the possibility of long ios_base::fixed outputs
diff --git a/libstdc++-v3/src/c++98/locale_facets.cc 
b/libstdc++-v3/src/c++98/locale_facets.cc
index 7ed04e6..b3ca5dc 100644
--- a/libstdc++-v3/src/c++98/locale_facets.cc
+++ b/libstdc++-v3/src/c++98/locale_facets.cc
@@ -71,7 +71,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION

ios_base::fmtflags __fltfield = __flags & ios_base::floatfield;

+#ifdef _GLIBCXX_USE_C99
+// Precision is always used except for hexfloat format.
if (__fltfield != (ios_base::fixed | ios_base::scientific))
+#endif
  {
// As per DR 231: not only when __flags & ios_base::fixed || __prec > 0
*__fptr++ = '.';




Re: [PATCH v2] libstdc++: Add hexfloat/defaultfloat io manipulators.

2014-10-08 Thread Jonathan Wakely

On 08/10/14 12:37 +0100, Jonathan Wakely wrote:

On 08/10/14 13:27 +0200, Rainer Orth wrote:

On Solaris 11 (both SPARC and x86), the test execution FAILs:

Assertion failed: os && std::stod(os.str()) == d, file 
/vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/hexfloat.cc,
 line 51, function test01
FAIL: 27_io/basic_ostream/inserters_arithmetic/char/hexfloat.cc execution test

With -DTEST_NUMPUT_VERBOSE, I get

got: 0x1.0p-1074


Thanks, I'll look into that too.


I suspect this was the bug Andreas pointed out (which didn't show up
on x86_64-linux)  and so should be fixed now.


Re: [PATCH] PR58867 ASan and UBSan tests not run for installed testing.

2014-10-08 Thread Maxim Ostapenko
Hm, as I see, others testsuites such as gfortran.exp, go.exp etc. do not 
call restore_ld_library_path at all. Perhaps we could simply follow this 
way?


Would failing tests still fail if remove restore_ld_library_path from 
{asan, tsan, ubsan}_finish?


On 10/08/2014 03:40 PM, Marcus Shawcroft wrote:

On 8 October 2014 11:10, Maxim Ostapenko
 wrote:

Does it work without restore_ld_library_path in {asan, ubsan, tsan}_finish?

I see two opportunities to fix the issue:

1) Implement a stack of saved contexts.

2) Implement new functions, say {asan, ubsan, tsan}_restore_ld_library_path,
to be able {asan, ubsan, tsan}_finish functions restore context correctly.

What solution is preferable?

Option 1 has the advantage that it places all of the context save and
restore in one place rather than spreading it around the
infrastructure.

Please can we revert this patch while a correct implementation is being worked?

Cheers
/Marcus



diff --git a/gcc/testsuite/lib/asan-dg.exp b/gcc/testsuite/lib/asan-dg.exp
index 9769138..c98fd3c 100644
--- a/gcc/testsuite/lib/asan-dg.exp
+++ b/gcc/testsuite/lib/asan-dg.exp
@@ -132,7 +132,6 @@ proc asan_finish { args } {
 	unset TEST_ALWAYS_FLAGS
 	}
 }
-restore_ld_library_path_env_vars
 }
 
 # Symbolize lines like
diff --git a/gcc/testsuite/lib/tsan-dg.exp b/gcc/testsuite/lib/tsan-dg.exp
index 54ec404..6f7a4d9 100644
--- a/gcc/testsuite/lib/tsan-dg.exp
+++ b/gcc/testsuite/lib/tsan-dg.exp
@@ -143,5 +143,4 @@ proc tsan_finish { args } {
 } else {
 	unset dg-do-what-default
 }
-restore_ld_library_path_env_vars
 }
diff --git a/gcc/testsuite/lib/ubsan-dg.exp b/gcc/testsuite/lib/ubsan-dg.exp
index 5a7a653..87c460f 100644
--- a/gcc/testsuite/lib/ubsan-dg.exp
+++ b/gcc/testsuite/lib/ubsan-dg.exp
@@ -114,5 +114,4 @@ proc ubsan_finish { args } {
 	unset TEST_ALWAYS_FLAGS
 	}
 }
-restore_ld_library_path_env_vars
 }


libgo patch committed: Fix recover.go test for large args, FFI

2014-10-08 Thread Ian Lance Taylor
This patch to libgo fixes PR 60406, in which a problem arises when
passing a large argument to a deferred function.  The current code
generates a thunk that looks like this:

if (__go_set_defer_retaddr (&&L))
  goto L;
deferred_function(args);
  L:

Then the deferred_function calls

__go_can_recover (__builtin_return_address())

and the code in libgo compares the address passed to __go_can_recover to
the address passed to __go_set_defer_retaddr.  This rather baroque
approach is so that a defer of a variable of function type will work
correctly.

This code normally works fine.  However, if args is very large, then it
will cause GCC to generate a block copy.  And on systems where that
block copy introduces a loop into the code, the exact location of L may
be split to a different block so that it no longer immediately follows
the call to deferred_function.  In that case the comparison in
__go_can_recover will fail, and the call to recover will fail when it
should succeed.

This is an unusual case.  Most calls to defer pass no arguments to the
deferred function.  It's quite unusual to pass a large argument.
However, we should of course handle it correctly.

This patch does this by adding new code when the return address fails to
match.  We fetch the callers to see whether we are being directly
invoked as a deferred function.  We detect this case by the simple
approach of seeing whether the caller starts with "__go_".  The patch
also adjusts one case that calls a deferred function to start with __go_
to match this.  This is a heuristic that is safe at present and be made
more safe in the future.

This patch also tightens up the checks for deferring a function created
by reflect.MakeFunc, to make that case more reliable.

This patch also introduces uses of __builtin_extract_return_addr for
systems that need it, which permits us to remove a #ifdef __sparc__.

Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu and
powerpc64le-unnown-linux-gnu.  Tested by others on Alpha and S/390.

Thanks to Dominik Vogt for forcing the issue and examining the
underlying assumptions.

Committed to mainline.  Although this fixes a bug this seems to me to be
too risky for the 4.9 branch, especially given that the bug has only
ever been seen in the testsuite, and is extremely unlikely to arise in
ordinary user code.

Ian

diff -r 50bdfe92960f libgo/go/reflect/makefunc_ffi_c.c
--- a/libgo/go/reflect/makefunc_ffi_c.c	Fri Oct 03 11:27:25 2014 -0700
+++ b/libgo/go/reflect/makefunc_ffi_c.c	Wed Oct 08 06:45:51 2014 -0700
@@ -36,21 +36,23 @@
Go callback function (passed in user_data) with the pointer to the
arguments and the results area.  */
 
+static void ffi_callback (ffi_cif *, void *, void **, void *)
+  __asm__ ("reflect.ffi_callback");
+
 static void
 ffi_callback (ffi_cif* cif __attribute__ ((unused)), void *results,
 	  void **args, void *user_data)
 {
-  Location locs[6];
+  Location locs[8];
   int n;
   int i;
-  const void *pc;
   FuncVal *fv;
   void (*f) (void *, void *);
 
   /* This function is called from some series of FFI closure functions
- called by a Go function.  We want to pass the PC of the Go
- function to makefunc_can_recover.  Look up the stack for a
- function that is definitely not an FFI function.  */
+ called by a Go function.  We want to see whether the caller of
+ the closure functions can recover.  Look up the stack and skip
+ the FFI functions.  */
   n = runtime_callers (1, &locs[0], sizeof locs / sizeof locs[0], true);
   for (i = 0; i < n; i++)
 {
@@ -61,28 +63,19 @@
   if (locs[i].function.len < 4)
 	break;
   name = locs[i].function.str;
-  if (*name == '_')
-	{
-	  if (locs[i].function.len < 5)
-	break;
-	  ++name;
-	}
   if (name[0] != 'f' || name[1] != 'f' || name[2] != 'i' || name[3] != '_')
 	break;
 }
   if (i < n)
-pc = (const void *) locs[i].pc;
-  else
-pc = __builtin_return_address (0);
-
-  __go_makefunc_can_recover (pc);
+__go_makefunc_ffi_can_recover (locs + i, n - i);
 
   fv = (FuncVal *) user_data;
   __go_set_closure (fv);
   f = (void *) fv->fn;
   f (args, results);
 
-  __go_makefunc_returning ();
+  if (i < n)
+__go_makefunc_returning ();
 }
 
 /* Allocate an FFI closure and arrange to call ffi_callback.  */
diff -r 50bdfe92960f libgo/runtime/go-defer.c
--- a/libgo/runtime/go-defer.c	Fri Oct 03 11:27:25 2014 -0700
+++ b/libgo/runtime/go-defer.c	Wed Oct 08 06:45:51 2014 -0700
@@ -80,6 +80,6 @@
 
   g = runtime_g ();
   if (g->defer != NULL)
-g->defer->__retaddr = retaddr;
+g->defer->__retaddr = __builtin_extract_return_addr (retaddr);
   return 0;
 }
diff -r 50bdfe92960f libgo/runtime/go-panic.h
--- a/libgo/runtime/go-panic.h	Fri Oct 03 11:27:25 2014 -0700
+++ b/libgo/runtime/go-panic.h	Wed Oct 08 06:45:51 2014 -0700
@@ -38,9 +38,12 @@
 
 extern struct __go_empty_interface __go_recover (void);
 
-extern _Bool __go_can_recover (const void *);
+extern _Bool __go_can_re

C++ PATCH for copying volatile class with ellipsis constructor

2014-10-08 Thread Jason Merrill
Ville's test in progress for is_trivially_constructible discovered this 
corner case ICE; trying to force a copy for passing to the ellipsis was 
resulting in infinite recursion as we call the ellipsis ctor to call the 
ellipsis ctor to 


Fixed by short-circuiting this into a call to the actual copy constructor.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit bab3313f7034a836d12247b66c3fe34f8ccfef6a
Author: Jason Merrill 
Date:   Wed Oct 8 09:51:33 2014 -0400

	* call.c (call_copy_ctor): New.
	(build_over_call): Use it to avoid infinite recursion on invalid code.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 347070c..76d8eab 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -6896,6 +6896,25 @@ mark_versions_used (tree fn)
 }
 }
 
+/* Build a call to "the copy constructor" for the type of A, even if it
+   wouldn't be selected by normal overload resolution.  Used for
+   diagnostics.  */
+
+static tree
+call_copy_ctor (tree a, tsubst_flags_t complain)
+{
+  tree ctype = TYPE_MAIN_VARIANT (TREE_TYPE (a));
+  tree binfo = TYPE_BINFO (ctype);
+  tree copy = get_copy_ctor (ctype, complain);
+  copy = build_baselink (binfo, binfo, copy, NULL_TREE);
+  tree ob = build_dummy_object (ctype);
+  vec* args = make_tree_vector_single (a);
+  tree r = build_new_method_call (ob, copy, &args, NULL_TREE,
+  LOOKUP_NORMAL, NULL, complain);
+  release_tree_vector (args);
+  return r;
+}
+
 /* Subroutine of the various build_*_call functions.  Overload resolution
has chosen a winning candidate CAND; build up a CALL_EXPR accordingly.
ARGS is a TREE_LIST of the unconverted arguments to the call.  FLAGS is a
@@ -7234,6 +7253,16 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
   if (magic_varargs_p (fn))
 	/* Do no conversions for magic varargs.  */
 	a = mark_type_use (a);
+  else if (DECL_CONSTRUCTOR_P (fn)
+	   && same_type_ignoring_top_level_qualifiers_p (DECL_CONTEXT (fn),
+			 TREE_TYPE (a)))
+	{
+	  /* Avoid infinite recursion trying to call A(...).  */
+	  if (complain & tf_error)
+	/* Try to call the actual copy constructor for a good error.  */
+	call_copy_ctor (a, complain);
+	  return error_mark_node;
+	}
   else
 	a = convert_arg_to_ellipsis (a, complain);
   argarray[j++] = a;
diff --git a/gcc/testsuite/g++.dg/overload/ellipsis3.C b/gcc/testsuite/g++.dg/overload/ellipsis3.C
new file mode 100644
index 000..e7d34d6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/overload/ellipsis3.C
@@ -0,0 +1,9 @@
+struct A {
+  A(...);
+};
+
+int main()
+{
+  volatile A a;
+  volatile A a2(a);		// { dg-error "volatile" }
+}


Re: [PATCH v2] libstdc++: Add hexfloat/defaultfloat io manipulators.

2014-10-08 Thread Rainer Orth
Jonathan Wakely  writes:

> On 08/10/14 12:37 +0100, Jonathan Wakely wrote:
>>On 08/10/14 13:27 +0200, Rainer Orth wrote:
>>>On Solaris 11 (both SPARC and x86), the test execution FAILs:
>>>
>>>Assertion failed: os && std::stod(os.str()) == d, file
>>> /vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/hexfloat.cc,
>>> line 51, function test01
>>>FAIL: 27_io/basic_ostream/inserters_arithmetic/char/hexfloat.cc execution 
>>>test
>>>
>>>With -DTEST_NUMPUT_VERBOSE, I get
>>>
>>>got: 0x1.0p-1074
>>
>>Thanks, I'll look into that too.
>
> I suspect this was the bug Andreas pointed out (which didn't show up
> on x86_64-linux)  and so should be fixed now.

I'd already tried that patch before you committed it, and unfortunately
it didn't help.

Rainer

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


Re: [PATCH] PR58867 ASan and UBSan tests not run for installed testing.

2014-10-08 Thread Jiong Wang


On 08/10/14 15:00, Maxim Ostapenko wrote:

Hm, as I see, others testsuites such as gfortran.exp, go.exp etc. do not
call restore_ld_library_path at all. Perhaps we could simply follow this
way?

Would failing tests still fail if remove restore_ld_library_path from
{asan, tsan, ubsan}_finish?

Hi Maxim,

  verified those fails gone away on check-gcc.

  but not sure whether this remove will cause problem on other test 
environments which they are aimed to solve.


-- Jiong



On 10/08/2014 03:40 PM, Marcus Shawcroft wrote:

On 8 October 2014 11:10, Maxim Ostapenko
 wrote:

Does it work without restore_ld_library_path in {asan, ubsan, tsan}_finish?

I see two opportunities to fix the issue:

1) Implement a stack of saved contexts.

2) Implement new functions, say {asan, ubsan, tsan}_restore_ld_library_path,
to be able {asan, ubsan, tsan}_finish functions restore context correctly.

What solution is preferable?

Option 1 has the advantage that it places all of the context save and
restore in one place rather than spreading it around the
infrastructure.

Please can we revert this patch while a correct implementation is being worked?

Cheers
/Marcus






Re: [PATCH, ARM] attribute target (thumb,arm)

2014-10-08 Thread Christian Bruel
Hi Ramana,

Thanks for your feedback. Just a few comments while you continue the review

1) about the documentation in extend.texi, it was in the  patch already
: did I miss a part ?
  * doc/extend.texi (arm, thumb): Document target attributes.
  * doc/invoke.texi (arm, thumb): Mention target attributes.

2) about supporting thumb1
   OK I'll suppress this limitation. But I covered the testing only for
thumb2 as I don't have a thumb1 platform, if it's OK with you thumb1
will only be covered by "visual checking". Can you help to test this mode ?
   
3) about inlining
  I dislike inlining different modes, From a conceptual use, a user
might want to switch mode only when changing a function's hotness.
Usually inlining a cold function into a hot one is not what the user
explicitly required when setting different mode attributes for them,

The compiler would take a decision that is not what the user wrote. And
in addition if you consider the few instructions to modify R15 to switch
state that would end up with more code executed in the critical path,
voiding a possible size of speed gain.

4) about coverage.
   Thanks for your idea about a mflip like internal option for the
testsuite. I'll give it a try. Note that in the meantime I gave a few
successful tries with LTO, and I'm in the process of running a
combinatorial exploration of a set of larger benchmarcks.
   Thanks for you hint about testing the  -march=armv7em -march=armv7m
error cases. This is indeed needed.

5) I'm still not sure about what to do with TARGET_UNIFIED_ASM. In one
hand I'm reluctant to bind to this development an improvement that
should be orthogonal (or a prerequisite), in another hand I don't really
like the logic with "emit_thumb". If your recommendation is to make
TARGET_UNIFIED_ASM the default for ARM that great, but I'm still
worrying for thumb1. Terry's feedback might be useful for this.

I'll resent the patch in different parts and thumb1 support. For your
inlining concern do you agree that inlining different modes might not be
mandatory (or even counter-productive) at this stage ?

Best Regards

Christian

On 10/08/2014 03:05 PM, Ramana Radhakrishnan wrote:
> Hi Christian,
>
>   Thanks for looking at this. I will need to read the code in detail but 
> this is a first top level reivew.
>
> On 09/29/14 12:03, Christian Bruel wrote:
>> Hi Ramana, Richard,
>>
>> This patch implements the attribute target (and pragma) to allow
>> function based interworking.
>>
>> as in the updated documentation, the syntax is:
>>
>>   __attribute__((target("thumb"))) int foo()
>> Forces thumb mode for function foo only. If the file was compiled with
>> -mthumb iit has no effect.
> Indeed
>
>
>> Similarly
>>
>>   __attribute__((target("arm"))) int foo()
>> Forces arm mode for function foo. It has no effect if the file was not
>> compiled with -mthumb.
> Indeed.
>
>> and regions can be grouped together with
>>
>> #pragma GCC target ("thumb")
>> or
>> #pragma GCC target ("arm")
>>
>> a few notes
>> - Inlining is allowed between functions of the same mode (compilation
>> switch, #pragma and attribute)
> Why shouldn't we allow inlining between functions of ARM mode vs Thumb 
> mode ? After all the choice of mode is irrelevant at the time of 
> inlining (except possibly for inline assembler).
>
> Perhaps an option is to try to disable inlining in the presence of 
> inline assembler or if not gate it from a command line option.
>
>> - 'arm_option_override' is now reorganized around
>> 'arm_option_override_internal' for thumb related macros
> Looks like a reasonable start - We need a couple of tests to make sure 
> that __attribute__(("arm")) on a file compiled for the M profile results 
> in a syntax error. v7(e)m is Thumb2 only.
>
> for bonus points it would be great to get __attribute__(("target")) 
> working properly in the backend. I suspect a number of the tuning flags 
> and the global architecture state needs to be moved into this as well to 
> handle cases where __attribute__(("arm")) used with M profile options is 
> error'd out.
>
>> - I kept TARGET_UNIFIED_ASM to minimize changes. Although removing it
>> would avoid to switch between unified/divided asms
> I know Terry's been trying to get Thumb1 to also switch by default to 
> unified asm. So I think a lot of the logic with "emit_thumb" could just 
> go away. Maybe we should just consider switching ARM state to unified 
> syntax and that would be as simple as changing TARGET_UNIFIED_SYNTAX in 
> arm.h to be TARGET_32BIT. Long overdue IMHO.
>
> The only gotcha here is inline assembler but GAS is so permissive that 
> I'm not too worried about it in ARM state and Thumb2 state. I'm a bit 
> worried about Thumb1.
>
>
>>and simplify arm_declare_function_name. Should be considered at some
>> point.
> I think that can be done for a lot of newer cores - some of that logic 
> is dated now IIUC.
>
> I remember why my original project failed - I couldn't get enough of the 
> backend in shap

Re: [PATCH] libgcc: unwind-dw2-fde.h: Use "(const fde *)" instead of "(char *)" to avoid qualifier warning

2014-10-08 Thread Richard Henderson
On 10/08/2014 03:47 AM, Chen Gang wrote:
> It passes "make -k check" under Darwin x86_64.
> 
> 2014-10-07  Chen Gang  
> 
>   * unwind-dw2-fde.h (last_fde): Use "(const fde *)" instead of
>   "(char *)" to avoid qualifier warning by 'xgcc' compiling.

Ok.


r~


Re: [PATCH 5/n] OpenMP 4.0 offloading infrastructure: libgomp

2014-10-08 Thread Ilya Verbin
I rebased and updated kyukhin/gomp4-offload branch.
It contains renaming of sections/symbols and fixes the cleanup of temporary
directories in the offload emulator.

On 07 Oct 21:40, Jakub Jelinek wrote:
> One more thing, I've noticed that running target-1.exe testcase also leaves
> /tmp/offload_XX directories around (one for each invocation).
> That can be useful for debugging, but generally should be cleaned up in
> __cxa_atexit callback or similar.

  -- Ilya


[4.8 & 4.9] Backport of r211885

2014-10-08 Thread Felix Yang
The enclosed patch for 4.8 & 4.9 branch is a backport of r211885 from trunk.

The only change is to use:

for (def_rec = DF_INSN_INFO_DEFS (insn_info); *def_rec; def_rec++)

other than the new FOR_EACH_INSN_INFO_DEF interface.

Bootstrapped on x86_64-SUSE-Linux for both branches. OK to apply?


Index: gcc/loop-invariant.c
===
--- gcc/loop-invariant.c(revision 216001)
+++ gcc/loop-invariant.c(working copy)
@@ -839,6 +839,41 @@ check_dependencies (rtx insn, bitmap depends_on)
   return true;
 }

+/* Pre-check candidate DEST to skip the one which can not make a valid insn
+   during move_invariant_reg.  SIMPLE is to skip HARD_REGISTER.  */
+
+static bool
+pre_check_invariant_p (bool simple, rtx dest)
+{
+  if (simple && REG_P (dest) && DF_REG_DEF_COUNT (REGNO (dest)) > 1)
+{
+  df_ref use;
+  rtx ref;
+  unsigned int i = REGNO (dest);
+  struct df_insn_info *insn_info;
+  df_ref *def_rec;
+
+  for (use = DF_REG_USE_CHAIN (i); use; use = DF_REF_NEXT_REG (use))
+{
+  ref = DF_REF_INSN (use);
+  insn_info = DF_INSN_INFO_GET (ref);
+
+  for (def_rec = DF_INSN_INFO_DEFS (insn_info); *def_rec; def_rec++)
+if (DF_REF_REGNO (*def_rec) == i)
+  {
+/* Multi definitions at this stage, most likely are due to
+   instruction constraints, which requires both read and write
+   on the same register.  Since move_invariant_reg is not
+   powerful enough to handle such cases, just ignore the INV
+   and leave the chance to others.  */
+return false;
+  }
+}
+}
+
+  return true;
+}
+
 /* Finds invariant in INSN.  ALWAYS_REACHED is true if the insn is always
executed.  ALWAYS_EXECUTED is true if the insn is always executed,
unless the program ends due to a function call.  */
@@ -869,6 +904,7 @@ find_invariant_insn (rtx insn, bool always_reached
 simple = false;

   if (!may_assign_reg_p (SET_DEST (set))
+  || !pre_check_invariant_p (simple, dest)
   || !check_maybe_invariant (SET_SRC (set)))
 return;


Cheers,
Felix


Re: [PATCH] PR63404, gcc 5 miscompiles linux block layer

2014-10-08 Thread Jiong Wang


On 30/09/14 19:36, Jiong Wang wrote:

2014-09-30 17:30 GMT+01:00 Jeff Law :

On 09/30/14 08:37, Jiong Wang wrote:


On 30/09/14 05:21, Jeff Law wrote:


I do agree with Richard that it would be useful to see the insns that
are incorrectly sunk and the surrounding context.

So I must be missing something.  I thought the shrink-wrapping code wouldn't
sink arithmetic/logical insns like we see with insn 14 and insn 182.  I
thought it was limited to reg-reg copies and constant initializations.

yes, it was limited to reg-reg copies, and my previous sink improvement aimed to
sink any rtx

   A: be single_set
   B: the src operand be any combination of no more than one register
and no non-constant objects.

while some operator like shift may have side effect. IMHO, all side
effects are reflected on RTX,
together with this fail_on_clobber_use modification, the rtx returned
by single_set_no_clobber_use is
safe to sink if it meets the above limit B and pass later register
use/def check in move_insn_for_shrink_wrap ?


Ping ~

And as there is NONDEBUG_INSN_P check before move_insn_for_shrink_wrap invoked,
we could avoid creating new wrapper function by invoke single_set_2 directly.

comments?

bootstrap ok on x86-64, and no regression on check-gcc/g++.
will do aarch64 bootstrapping/regression going on.

2014-10-08  Jiong Wang  

* rtl.h (single_set_2): New parameter "fail_on_clobber_use".
(single_set): Likewise.
* config/ia64/ia64.c (ia64_single_set): Likewise.
* rtlanal.c (single_set_2): Return NULL_RTX if fail_on_clobber_use be 
true.
* shrink-wrap.c (move_insn_for_shrink_wrap): Use single_set_2.

Regards,
Jiong



Regards,
Jiong


Jeff


diff --git a/gcc/config/ia64/ia64.c b/gcc/config/ia64/ia64.c
index 9337be1..09d3c4a 100644
--- a/gcc/config/ia64/ia64.c
+++ b/gcc/config/ia64/ia64.c
@@ -7172,7 +7172,7 @@ ia64_single_set (rtx_insn *insn)
   break;
 
 default:
-  ret = single_set_2 (insn, x);
+  ret = single_set_2 (insn, x, false);
   break;
 }
 
diff --git a/gcc/rtl.h b/gcc/rtl.h
index e73f731..c0b5bf5 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -2797,7 +2797,7 @@ extern void set_insn_deleted (rtx);
 
 /* Functions in rtlanal.c */
 
-extern rtx single_set_2 (const rtx_insn *, const_rtx);
+extern rtx single_set_2 (const rtx_insn *, const_rtx, bool fail_on_clobber_use);
 
 /* Handle the cheap and common cases inline for performance.  */
 
@@ -2810,7 +2810,7 @@ inline rtx single_set (const rtx_insn *insn)
 return PATTERN (insn);
 
   /* Defer to the more expensive case.  */
-  return single_set_2 (insn, PATTERN (insn));
+  return single_set_2 (insn, PATTERN (insn), false);
 }
 
 extern enum machine_mode get_address_mode (rtx mem);
diff --git a/gcc/rtlanal.c b/gcc/rtlanal.c
index 3063458..7d6ed27 100644
--- a/gcc/rtlanal.c
+++ b/gcc/rtlanal.c
@@ -1182,7 +1182,7 @@ record_hard_reg_uses (rtx *px, void *data)
will not be used, which we ignore.  */
 
 rtx
-single_set_2 (const rtx_insn *insn, const_rtx pat)
+single_set_2 (const rtx_insn *insn, const_rtx pat, bool fail_on_clobber_use)
 {
   rtx set = NULL;
   int set_verified = 1;
@@ -1197,6 +1197,8 @@ single_set_2 (const rtx_insn *insn, const_rtx pat)
 	{
 	case USE:
 	case CLOBBER:
+	  if (fail_on_clobber_use)
+		return NULL_RTX;
 	  break;
 
 	case SET:
diff --git a/gcc/shrink-wrap.c b/gcc/shrink-wrap.c
index b1ff8a2..a3b57b6 100644
--- a/gcc/shrink-wrap.c
+++ b/gcc/shrink-wrap.c
@@ -177,7 +177,8 @@ move_insn_for_shrink_wrap (basic_block bb, rtx_insn *insn,
   edge live_edge;
 
   /* Look for a simple register copy.  */
-  set = single_set (insn);
+  set = (GET_CODE (PATTERN (insn)) == SET ? PATTERN (insn)
+	 : single_set_2 (insn, PATTERN (insn), true));
   if (!set)
 return false;
   src = SET_SRC (set);

[libquadmath,committed] Fix typo in doc

2014-10-08 Thread FX
Committed as trivial, rev. 216006


2014-10-08  Francois-Xavier Coudert  

PR libquadmath/63487
* libquadmath.texi (sincosq): Fix typo.


Index: libquadmath.texi
===
--- libquadmath.texi(revision 215645)
+++ libquadmath.texi(working copy)
@@ -199,7 +199,7 @@ The following mathematical functions are
 @item @code{scalblnq}: compute exponent using @code{FLT_RADIX}
 @item @code{scalbnq}: compute exponent using @code{FLT_RADIX}
 @item @code{signbitq}: return sign bit
-@item @code{sincosq}: calculate sine and cosine simulataneously
+@item @code{sincosq}: calculate sine and cosine simultaneously
 @item @code{sinhq}: hyperbolic sine function
 @item @code{sinq}: sine function
 @item @code{sqrtq}: square root function



Re: RFA: Merge definitions of get_some_local_dynamic_name

2014-10-08 Thread Richard Sandiford
Rainer Orth  writes:
> Hi Richard,
>
>> Does this work for you?  I tested it on x86_64-linux-gnu but obviously
>> that's not particularly useful for SEQUENCEs.
>
> the patch is fine, as tested on both sparc-sun-solaris2.11 and (for good
> measure) i386-pc-solaris2.11.

OK, great.

To recap, the idea is that if PATTERN (insn) is a SEQUENCE:

   FOR_EACH_SUBRTX (, insn, x)
 ...

should iterate over the insns in the SEQUENCE (including pattern, notes,
jump label, etc.).  However:

   FOR_EACH_SUBRTX (, PATTERN (insn), x)
 ...

should only iterate over the patterns of the insns in the SEQUENCE,
since the user of FOR_EACH_SUBRTX isn't expecting to see things like
REG_NOTES (and might not handle them correctly).

Also tested on x86_64-linux-gnu.  OK to install?

Thanks,
Richard


gcc/
* rtlanal.c (generic_subrtx_iterator ::add_subrtxes_to_queue):
Add the parts of an insn in reverse order, with the pattern at
the top of the queue.  Detect when we're iterating over a SEQUENCE
pattern and in that case just consider patterns of subinstructions.

Index: gcc/rtlanal.c
===
--- gcc/rtlanal.c   2014-09-25 16:40:44.944406590 +0100
+++ gcc/rtlanal.c   2014-10-07 13:13:57.698132753 +0100
@@ -128,29 +128,58 @@ generic_subrtx_iterator ::add_subrtxe
value_type *base,
size_t end, rtx_type x)
 {
-  const char *format = GET_RTX_FORMAT (GET_CODE (x));
+  enum rtx_code code = GET_CODE (x);
+  const char *format = GET_RTX_FORMAT (code);
   size_t orig_end = end;
-  for (int i = 0; format[i]; ++i)
-if (format[i] == 'e')
-  {
-   value_type subx = T::get_value (x->u.fld[i].rt_rtx);
-   if (__builtin_expect (end < LOCAL_ELEMS, true))
- base[end++] = subx;
-   else
- base = add_single_to_queue (array, base, end++, subx);
-  }
-else if (format[i] == 'E')
-  {
-   int length = GET_NUM_ELEM (x->u.fld[i].rt_rtvec);
-   rtx *vec = x->u.fld[i].rt_rtvec->elem;
-   if (__builtin_expect (end + length <= LOCAL_ELEMS, true))
- for (int j = 0; j < length; j++)
-   base[end++] = T::get_value (vec[j]);
-   else
- for (int j = 0; j < length; j++)
-   base = add_single_to_queue (array, base, end++,
-   T::get_value (vec[j]));
-  }
+  if (__builtin_expect (INSN_P (x), false))
+{
+  /* Put the pattern at the top of the queue, since that's what
+we're likely to want most.  It also allows for the SEQUENCE
+code below.  */
+  for (int i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; --i)
+   if (format[i] == 'e')
+ {
+   value_type subx = T::get_value (x->u.fld[i].rt_rtx);
+   if (__builtin_expect (end < LOCAL_ELEMS, true))
+ base[end++] = subx;
+   else
+ base = add_single_to_queue (array, base, end++, subx);
+ }
+}
+  else
+for (int i = 0; format[i]; ++i)
+  if (format[i] == 'e')
+   {
+ value_type subx = T::get_value (x->u.fld[i].rt_rtx);
+ if (__builtin_expect (end < LOCAL_ELEMS, true))
+   base[end++] = subx;
+ else
+   base = add_single_to_queue (array, base, end++, subx);
+   }
+  else if (format[i] == 'E')
+   {
+ unsigned int length = GET_NUM_ELEM (x->u.fld[i].rt_rtvec);
+ rtx *vec = x->u.fld[i].rt_rtvec->elem;
+ if (__builtin_expect (end + length <= LOCAL_ELEMS, true))
+   for (unsigned int j = 0; j < length; j++)
+ base[end++] = T::get_value (vec[j]);
+ else
+   for (unsigned int j = 0; j < length; j++)
+ base = add_single_to_queue (array, base, end++,
+ T::get_value (vec[j]));
+ if (code == SEQUENCE && end == length)
+   /* If the subrtxes of the sequence fill the entire array then
+  we know that no other parts of a containing insn are queued.
+  The caller is therefore iterating over the sequence as a
+  PATTERN (...), so we also want the patterns of the
+  subinstructions.  */
+   for (unsigned int j = 0; j < length; j++)
+ {
+   typename T::rtx_type x = T::get_rtx (base[j]);
+   if (INSN_P (x))
+ base[j] = T::get_value (PATTERN (x));
+ }
+   }
   return end - orig_end;
 }
 



Re: [PATCH] PR58867 ASan and UBSan tests not run for installed testing.

2014-10-08 Thread Maxim Ostapenko

Hi Jiong,

I couldn't reproduce tests failures on my box, perhaps I missed 
something. How can I test this?


-Maxim
On 10/08/2014 06:30 PM, Jiong Wang wrote:


On 08/10/14 15:00, Maxim Ostapenko wrote:

Hm, as I see, others testsuites such as gfortran.exp, go.exp etc. do not
call restore_ld_library_path at all. Perhaps we could simply follow this
way?

Would failing tests still fail if remove restore_ld_library_path from
{asan, tsan, ubsan}_finish?

Hi Maxim,

  verified those fails gone away on check-gcc.

  but not sure whether this remove will cause problem on other test 
environments which they are aimed to solve.


-- Jiong



On 10/08/2014 03:40 PM, Marcus Shawcroft wrote:

On 8 October 2014 11:10, Maxim Ostapenko
 wrote:
Does it work without restore_ld_library_path in {asan, ubsan, 
tsan}_finish?


I see two opportunities to fix the issue:

1) Implement a stack of saved contexts.

2) Implement new functions, say {asan, ubsan, 
tsan}_restore_ld_library_path,
to be able {asan, ubsan, tsan}_finish functions restore context 
correctly.


What solution is preferable?

Option 1 has the advantage that it places all of the context save and
restore in one place rather than spreading it around the
infrastructure.

Please can we revert this patch while a correct implementation is 
being worked?


Cheers
/Marcus









RE: [Patch, MIPS] Cleanup mips header files.

2014-10-08 Thread Steve Ellcey
On Mon, 2014-10-06 at 14:25 -0700, Matthew Fortune wrote:
> Hi Steve,
> 
> You're the lucky recipient of my first review so apologies for being
> slow and cautious...
> 
> I tried to find a reason why the files were originally separated like this
> and I can't see anything obvious.  I assume you also found no reason.
> Presumably the separation was just to avoid disturbing the 32-bit configs
> but I think it is a sensible move to merge them.

That was also my guess as to why it was done that way.

> With those changes can you double check that a default big and default little
> endian build pass -EB/-EL respectively by default and are changed when using
> -EL/-EB explicitly? There should only be one -E* option passed to the linker
> theoretically, unless multiple explicit -E* options are given on the command
> line.

I made the syntax changes, removed the '%{!EB:%{!EL:%(endian_spec)}}'
part of GNU_USER_TARGET_LINK_SPEC and double checked that we still pass
-EL or -EB to the linker in all cases.

> Otherwise OK (assuming the link specs behave as described above).
> 
> Thanks,
> Matthew

Thanks for the review, I have gone ahead and checked in the patch with
those changes.

Steve Ellcey
sell...@mips.com





Re: [PATCH] PR58867 ASan and UBSan tests not run for installed testing.

2014-10-08 Thread Jiong Wang


On 08/10/14 17:19, Maxim Ostapenko wrote:

Hi Jiong,

I couldn't reproduce tests failures on my box, perhaps I missed
something. How can I test this?


Hi Maxim,

  What I mean is after this patch, those fails gone away on my test environment 
also.

  I am just not sure whether the remove will cause it work on your and my test 
environment but fail on others. because looks like
  these restore_ld_library_path is added deliberately.

Regards,
Jiong



-Maxim
On 10/08/2014 06:30 PM, Jiong Wang wrote:

On 08/10/14 15:00, Maxim Ostapenko wrote:

Hm, as I see, others testsuites such as gfortran.exp, go.exp etc. do not
call restore_ld_library_path at all. Perhaps we could simply follow this
way?

Would failing tests still fail if remove restore_ld_library_path from
{asan, tsan, ubsan}_finish?

Hi Maxim,

   verified those fails gone away on check-gcc.

   but not sure whether this remove will cause problem on other test
environments which they are aimed to solve.

-- Jiong


On 10/08/2014 03:40 PM, Marcus Shawcroft wrote:

On 8 October 2014 11:10, Maxim Ostapenko
 wrote:

Does it work without restore_ld_library_path in {asan, ubsan,
tsan}_finish?

I see two opportunities to fix the issue:

1) Implement a stack of saved contexts.

2) Implement new functions, say {asan, ubsan,
tsan}_restore_ld_library_path,
to be able {asan, ubsan, tsan}_finish functions restore context
correctly.

What solution is preferable?

Option 1 has the advantage that it places all of the context save and
restore in one place rather than spreading it around the
infrastructure.

Please can we revert this patch while a correct implementation is
being worked?

Cheers
/Marcus











Re: [PATCH, ARM] attribute target (thumb,arm)

2014-10-08 Thread Ramana Radhakrishnan

Hi Christian,


On 08/10/14 15:38, Christian Bruel wrote:

Hi Ramana,

Thanks for your feedback. Just a few comments while you continue the review


Sure - all thoughts are welcome, this isn't a trivial project and I'm 
dredging tertiary storage in my brain and old notes for context on all 
the gotchas involved in this.


1) about the documentation in extend.texi, it was in the  patch already
: did I miss a part ?
   * doc/extend.texi (arm, thumb): Document target attributes.
   * doc/invoke.texi (arm, thumb): Mention target attributes.



Indeed - I don't know how I missed it and as I said it was a brief 
review. I am more interested in discussing the semantics up front.



2) about supporting thumb1
OK I'll suppress this limitation. But I covered the testing only for
thumb2 as I don't have a thumb1 platform, if it's OK with you thumb1
will only be covered by "visual checking". Can you help to test this mode ?

3) about inlining
   I dislike inlining different modes, From a conceptual use, a user
might want to switch mode only when changing a function's hotness.
Usually inlining a cold function into a hot one is not what the user
explicitly required when setting different mode attributes for them,


__attribute__((thumb)) should not imply coldness or hotness. Inlining 
between cold and hot functions should be done based on profile feedback. 
The choice of compiling in "Thumb1" state for coldness is a separate one 
because that's where the choice needs to be made.




The compiler would take a decision that is not what the user wrote. And
in addition if you consider the few instructions to modify R15 to switch
state that would end up with more code executed in the critical path,
voiding a possible size of speed gain.


I do not expect there to be any additional instructions needed to switch 
state. If function x is inlined into function y the state would be lost 
and the state would be in terms of the state of function x.


Obviously if the user doesn't want inlining - the user would add 
attributes to disable inlining. You do have extensions such as 
__attribute__((noinline)) and __attribute__((never_inline)) to give the 
user that control and those bits need to be used in addition.


The attribute then purely reflects then the output instruction state of 
the function if a copy of it's body is laid out separately in the output.


IMHO, the heuristics for inlining should be the best judge of when 
functions should be inlined between one and another and we shouldn't be 
second guessing that in the backend.


If there is a copy of the function to be put out by the compiler, only 
then should we choose this based on the state of the "target" i.e. arm 
or thumb.




4) about coverage.
Thanks for your idea about a mflip like internal option for the
testsuite. I'll give it a try. Note that in the meantime I gave a few
successful tries with LTO, and I'm in the process of running a
combinatorial exploration of a set of larger benchmarcks.


Would be interesting to hear in terms of how you played with LTO.


Thanks for you hint about testing the  -march=armv7em -march=armv7m
error cases. This is indeed needed.


Adding some directed tests for the pragmas would also be required.



5) I'm still not sure about what to do with TARGET_UNIFIED_ASM. In one
hand I'm reluctant to bind to this development an improvement that
should be orthogonal (or a prerequisite), in another hand I don't really
like the logic with "emit_thumb". If your recommendation is to make
TARGET_UNIFIED_ASM the default for ARM that great, but I'm still
worrying for thumb1. Terry's feedback might be useful for this.


I want to think about this carefully too.



I'll resent the patch in different parts and thumb1 support. For your
inlining concern do you agree that inlining different modes might not be
mandatory (or even counter-productive) at this stage ?


More practically and from memory I remember that there maybe quite a lot 
of false positives in the other parts of the testsuite if you put in the 
-mflip-thumbness switch if inlining is turned off.


I think I've also explained my reasons for allowing inlining above.

Also with the target macros that you are changing between ARM and Thumb 
it would be good to make sure that you capture everything. I am 
concerned about the __ARM_ARCH_ISA_ARM and __ARM_ARCH_ISA_THUMB macros 
with the M profile cores. Those probably also need handling please.


I'll review this again when the next patch set arrives with the 
different parts.


regards
Ramana



Best Regards

Christian

On 10/08/2014 03:05 PM, Ramana Radhakrishnan wrote:

Hi Christian,

Thanks for looking at this. I will need to read the code in detail but
this is a first top level reivew.

On 09/29/14 12:03, Christian Bruel wrote:

Hi Ramana, Richard,

This patch implements the attribute target (and pragma) to allow
function based interworking.

as in the updated documentation, the syntax is:

   __attribute__((target

Re: [gomp4] reduction bug fix

2014-10-08 Thread Cesar Philippidis
On 10/08/2014 02:38 AM, Thomas Schwinge wrote:

> On Fri, 3 Oct 2014 09:22:52 -0700, Cesar Philippidis  
> wrote:
>> There is a reduction bug [...]
> 
> Thanks for looking into this!
> 
>> This is a problem because initialize_reduction_data originally expected
>> a GIMPLE_BIND at the very beginning of a parallel block.  [...]
> 
> Does your patch also fix the issue that Jim saw in his C++ work?

Yes it does.

>> This patch also includes a runtime test case. I won't apply it to
>> gomp-4_0-branch just yet. But I wanted to demonstrate a test case
>> nonetheless.
> 
> You can add it as a compile test, and I'll toggle to a run test as part
> of the merge into our internal development branch.

OK. I've added a compile test to gcc.dg/goaccc/. Note that this test
depends on -std=c99, so I couldn't put it in the c-c++-common directory.

>> Also, note that part of this patch also changes a comment.
>> I found some typos in the original comment, so I took the opportunity to
>> fix them, I hope.
> 
> Sure, and it's also always fine to separately apply such patches under
> the obvious rule.
> 
>> Is this OK for gomp-4_0-branch?
> 
> Yes, with the following addressed:
> 
>> --- a/gcc/omp-low.c
>> +++ b/gcc/omp-low.c
>> @@ -10140,11 +10140,20 @@ process_reduction_data (gimple_seq *body, 
>> gimple_seq *in_stmt_seqp,
> 
> [...]/source-gcc/gcc/omp-low.c: In function 'void 
> _ZL22process_reduction_dataPP21gimple_statement_baseS1_S1_P11omp_context.isra.167.constprop.180(gimple_statement_base**,
>  gimple_statement_base**, gimple_statement_base**, gimple)':
> [...]/source-gcc/gcc/omp-low.c:10172:14: warning: 'inner' may be used 
> uninitialized in this function [-Wmaybe-uninitialized]
>gimple_seq inner;
>   ^
> 
>> --- /dev/null
>> +++ b/libgomp/testsuite/libgomp.oacc-c/collapse-4.c
>> @@ -0,0 +1,34 @@
>> +/* { dg-do run } */
>> +/* { dg-options "-O2 -std=c99" } */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +
>> +int
>> +main (void)
>> +{
>> +  int i2, l = 0, r = 0;
>> +  int a[3][3][3];
>> +  int b[3][3];
> 
> A lot of these variables are unused.
> 
>> +printf("&a %p\n", &a[0][0][0]);
>> +printf("&i2 %p\n", &i2);
>> +printf("&l %p\n", &l);
>> +printf("&r %p\n", &r);
> 
> Please remove  include and the printfs, or at least put those
> into DEBUG conditionals.

I removed those thanks. This updated patch has been committed.

Thanks,
Cesar

2014-10-08  Cesar Philippidis  

	gcc/
	* omp-low.c (lower_reduction_clauses): Clarify comment.
	(process_reduction_data): Scan for nonempty bind statements at
	the beginning of parallel blocks.

	gcc/testsuite/
	* gcc.dg/goacc/collapse.c: New test.


diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 3bb6a24..5c452c6 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -4434,10 +4434,10 @@ lower_reduction_clauses (tree clauses, gimple_seq *stmt_seqp, omp_context *ctx)
 	  else
 	{
 	  /* The atomic add at the end of the sum creates unnecessary
-	 write contention on accelerators.  To work around that,
-	 create an array or vector_length and assign an element to
-	 each thread.  Later, in lower_omp_for (for openacc), the
-	 values of array will be combined.  */
+	 write contention on accelerators.  To work around this,
+	 create an array to store the partial reductions. Later, in
+	 lower_omp_for (for openacc), the values of array will be
+	 combined.  */
 
 	  tree t = NULL_TREE, array, nthreads;
 	  tree type = get_base_type (var);
@@ -10140,11 +10140,20 @@ process_reduction_data (gimple_seq *body, gimple_seq *in_stmt_seqp,
   gimple stmt;
 
   /* A collapse clause may have inserted a new bind block.  */
-  stmt = gimple_seq_first (*body);
-  if (stmt && gimple_code (stmt) == GIMPLE_BIND)
+  gsi = gsi_start (*body);
+  while (!gsi_end_p (gsi))
 {
-  inner = gimple_bind_body (gimple_seq_first (*body));
-  body = &inner;
+  stmt = gsi_stmt (gsi);
+  if (gimple_code (stmt) == GIMPLE_BIND)
+	{
+	  inner = gimple_bind_body (stmt);
+	  body = &inner;
+	  gsi = gsi_start (*body);
+	}
+  else if (gimple_code (stmt) == GIMPLE_OMP_FOR)
+	break;
+  else
+	gsi_next (&gsi);
 }
 
   for (gsi = gsi_start (*body); !gsi_end_p (gsi); gsi_next (&gsi))
diff --git a/gcc/testsuite/gcc.dg/goacc/collapse.c b/gcc/testsuite/gcc.dg/goacc/collapse.c
new file mode 100644
index 000..1ec20a4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/goacc/collapse.c
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -std=c99" } */
+
+#include 
+
+int
+main (void)
+{
+  int l = 0;
+  int b[3][3];
+
+  memset (b, '\0', sizeof (b));
+
+#pragma acc parallel copy(b[0:3][0:3]) copy(l)
+{
+#pragma acc loop collapse(2) reduction(+:l)
+	for (int i = 0; i < 2; i++)
+	  for (int j = 0; j < 2; j++)
+	if (b[i][j] != 16)
+		  l += 1;
+}
+
+  return 0;
+}


Re: [PATCH] add overlap function to gcov-tool

2014-10-08 Thread Rong Xu
On Tue, Oct 7, 2014 at 9:31 PM, Jan Hubicka  wrote:
>> Hi,
>>
>> This patch adds overlap functionality to gcov-tool. The overlap score
>> estimates the similarity of two profiles. Currently it only computes
>> overlap for arc counters.
>>
>> The overlap score is defined as
>> \sum minimum (p1-counter[i] / p1-sum-all, p2-counter[i] / p2-sum-all)
>> where p1-counter[i] and p2-counter[2] are two matched counter from
>> profile1 and profiler2.
>> p1-sum-all and p2-sum-all are the sum-all counters in profiler1 and
>> profile2, repetitively.
>
> The patch looks fine in general.  My statistics is all rusty, but can't we use
> one of the established techniques like Kullback-Leibler to compare the
> probabilitis distributions?

Interesting. I never thought of using Kullback-Leibler divergence.
It's very easy to switch to KL using this overlap framework -- only a
few lines of change.
The problem is KL divergence assumes absolute continuity (i.e. q(i)
==0 --> p(i) =0, which is
not true in our distribution, I'm not sure how to work around this.).

I did try earth-mover-distance (EMD) in our earlier internal version.
But since I used
uniform distance, the problem can be simplified to distribution diffs.

> It would be also nice to have ability to compare
> branch probabilities in btween train runs.

Do you mean to do the comparison in CFG rather on the raw counters?
We need gcno file to reconstruct the CFG. That needs some work.

-Rong

>
> Honza
>>
>> The resulting score is a value ranging from 0.0 to 1.0 where 0.0 means
>> no match and 1.0 mean a perfect match.
>>
>> This tool can be used in performance triaging and reducing the fdo
>> training set size (where similar inputs can be pruned).
>>
>> Tested with spec2006 profiles.
>>
>> Thanks,
>>
>> -Rong
>
>> 2014-10-07  Rong Xu  
>>
>>   * gcc/gcov-tool.c (profile_overlap): New driver function
>> to compute profile overlap.
>>   (print_overlap_usage_message): New.
>>   (overlap_usage): New.
>>   (do_overlap): New.
>>   (print_usage): Add calls to overlap function.
>>   (main): Ditto.
>>   * libgcc/libgcov-util.c (read_gcda_file): Fix format.
>>   (find_match_gcov_info): Ditto.
>>   (calculate_2_entries): New.
>>   (compute_one_gcov): Ditto.
>>   (gcov_info_count_all_cold): Ditto.
>>   (gcov_info_count_all_zero): Ditto.
>>   (extract_file_basename): Ditto.
>>   (get_file_basename): Ditto.
>>   (set_flag): Ditto.
>>   (matched_gcov_info): Ditto.
>>   (calculate_overlap): Ditto.
>>   (gcov_profile_overlap): Ditto.
>>   * libgcc/libgcov-driver.c (compute_summary): Make
>> it avavilable for external calls.
>>   * gcc/doc/gcov-tool.texi: Add documentation.
>>
>> Index: gcc/gcov-tool.c
>> ===
>> --- gcc/gcov-tool.c   (revision 215981)
>> +++ gcc/gcov-tool.c   (working copy)
>> @@ -39,6 +39,7 @@ see the files COPYING3 and COPYING.RUNTIME respect
>>  #include 
>>
>>  extern int gcov_profile_merge (struct gcov_info*, struct gcov_info*, int, 
>> int);
>> +extern int gcov_profile_overlap (struct gcov_info*, struct gcov_info*);
>>  extern int gcov_profile_normalize (struct gcov_info*, gcov_type);
>>  extern int gcov_profile_scale (struct gcov_info*, float, int, int);
>>  extern struct gcov_info* gcov_read_profile_dir (const char*, int);
>> @@ -368,6 +369,121 @@ do_rewrite (int argc, char **argv)
>>return ret;
>>  }
>>
>> +/* Driver function to computer the overlap score b/w profile D1 and D2.
>> +   Return 1 on error and 0 if OK.  */
>> +
>> +static int
>> +profile_overlap (const char *d1, const char *d2)
>> +{
>> +  struct gcov_info *d1_profile;
>> +  struct gcov_info *d2_profile;
>> +
>> +  d1_profile = gcov_read_profile_dir (d1, 0);
>> +  if (!d1_profile)
>> +return 1;
>> +
>> +  if (d2)
>> +{
>> +  d2_profile = gcov_read_profile_dir (d2, 0);
>> +  if (!d2_profile)
>> +return 1;
>> +
>> +  return gcov_profile_overlap (d1_profile, d2_profile);
>> +}
>> +
>> +  return 1;
>> +}
>> +
>> +/* Usage message for profile overlap.  */
>> +
>> +static void
>> +print_overlap_usage_message (int error_p)
>> +{
>> +  FILE *file = error_p ? stderr : stdout;
>> +
>> +  fnotice (file, "  overlap [options] Compute the 
>> overlap of two profiles\n");
>> +  fnotice (file, "-v, --verbose   Verbose mode\n");
>> +  fnotice (file, "-h, --hotonly   Only print info 
>> for hot objects/functions\n");
>> +  fnotice (file, "-f, --function  Print function 
>> level info\n");
>> +  fnotice (file, "-F, --fullname  Print full 
>> filename\n");
>> +  fnotice (file, "-o, --objectPrint object 
>> level info\n");
>> +  fnotice (file, "-t , --hot_threshold  Set the threshold 
>> for hotness\n");
>> +
>> +}
>> +
>> +static const struct option overlap_options[] =
>> +{
>> +  { "verbose",

[PATCH 0/2] [AARCH64,NEON] Improve vld[234](q?)_lane intrinsics v2

2014-10-08 Thread charles . baylis
From: Charles Baylis 

This patch series converts the vld[234](q?)_lane intrinsics to use builtin
functions instead of the previous inline assembler syntax.

Changes since v1:
. the type-punning to change between the array of vector types and the internal
  builtin types has been removed, as this is a separate, more complex problem.
  (patches 3&4 dropped, patch 2 reworked)
. iterator style cleanups (patch 1)
. removed broken bigendian lane number conversion. (patch 1)

Tested with make check on aarch64-oe-linux with qemu, and also passes clyon's
NEON intrinsics tests.


Charles Baylis (2):
  [AARCH64,NEON] Add patterns + builtins for vld[234](q?)_lane_*
intrinsics
  [AARCH64,NEON] Convert arm_neon.h to use new builtins for
vld[234](q?)_lane_*

 gcc/config/aarch64/aarch64-builtins.c|   5 +
 gcc/config/aarch64/aarch64-simd-builtins.def |   4 +
 gcc/config/aarch64/aarch64-simd.md   |  95 +++
 gcc/config/aarch64/aarch64.md|   3 +
 gcc/config/aarch64/arm_neon.h| 377 ++-
 5 files changed, 362 insertions(+), 122 deletions(-)

-- 
1.9.1



[PATCH 1/2] [AARCH64,NEON] Add patterns + builtins for vld[234](q?)_lane_* intrinsics

2014-10-08 Thread charles . baylis
From: Charles Baylis 

This patch adds new patterns and builtins to represent single lane structure
loads instructions, which will be used to implement the vld[234](q?)_lane_*
intrinsics.

Tested (with the rest of the patch series) with make check on aarch64-oe-linux
with qemu, and also causes no regressions in clyon's NEON intrinsics tests.

  Charles Baylis  
* config/aarch64/aarch64-builtins.c
(aarch64_types_loadstruct_lane_qualifiers): Define.
* config/aarch64/aarch64-simd-builtins.def (ld2_lane, ld3_lane,
ld4_lane): New builtins.
* config/aarch64/aarch64-simd.md (vec_load_lanesoi_lane): New
pattern.
(vec_load_lanesci_lane): Likewise.
(vec_load_lanesxi_lane): Likewise.
(aarch64_ld2_lane): New expand.
(aarch64_ld3_lane): Likewise.
(aarch64_ld4_lane): Likewise.
* config/aarch64/aarch64.md (define_c_enum "unspec"): Add
UNSPEC_LD2_LANE, UNSPEC_LD3_LANE, UNSPEC_LD4_LANE.
---
 gcc/config/aarch64/aarch64-builtins.c|  5 ++
 gcc/config/aarch64/aarch64-simd-builtins.def |  4 ++
 gcc/config/aarch64/aarch64-simd.md   | 95 
 gcc/config/aarch64/aarch64.md|  3 +
 4 files changed, 107 insertions(+)

diff --git a/gcc/config/aarch64/aarch64-builtins.c 
b/gcc/config/aarch64/aarch64-builtins.c
index 3dba1b2..368d3a7 100644
--- a/gcc/config/aarch64/aarch64-builtins.c
+++ b/gcc/config/aarch64/aarch64-builtins.c
@@ -201,6 +201,11 @@ aarch64_types_load1_qualifiers[SIMD_MAX_BUILTIN_ARGS]
   = { qualifier_none, qualifier_const_pointer_map_mode };
 #define TYPES_LOAD1 (aarch64_types_load1_qualifiers)
 #define TYPES_LOADSTRUCT (aarch64_types_load1_qualifiers)
+static enum aarch64_type_qualifiers
+aarch64_types_loadstruct_lane_qualifiers[SIMD_MAX_BUILTIN_ARGS]
+  = { qualifier_none, qualifier_const_pointer_map_mode,
+  qualifier_none, qualifier_none };
+#define TYPES_LOADSTRUCT_LANE (aarch64_types_loadstruct_lane_qualifiers)
 
 static enum aarch64_type_qualifiers
 aarch64_types_bsl_p_qualifiers[SIMD_MAX_BUILTIN_ARGS]
diff --git a/gcc/config/aarch64/aarch64-simd-builtins.def 
b/gcc/config/aarch64/aarch64-simd-builtins.def
index 2367436..348f0d2 100644
--- a/gcc/config/aarch64/aarch64-simd-builtins.def
+++ b/gcc/config/aarch64/aarch64-simd-builtins.def
@@ -83,6 +83,10 @@
   BUILTIN_VQ (LOADSTRUCT, ld2, 0)
   BUILTIN_VQ (LOADSTRUCT, ld3, 0)
   BUILTIN_VQ (LOADSTRUCT, ld4, 0)
+  /* Implemented by aarch64_ld_lane.  */
+  BUILTIN_VQ (LOADSTRUCT_LANE, ld2_lane, 0)
+  BUILTIN_VQ (LOADSTRUCT_LANE, ld3_lane, 0)
+  BUILTIN_VQ (LOADSTRUCT_LANE, ld4_lane, 0)
   /* Implemented by aarch64_st.  */
   BUILTIN_VDC (STORESTRUCT, st2, 0)
   BUILTIN_VDC (STORESTRUCT, st3, 0)
diff --git a/gcc/config/aarch64/aarch64-simd.md 
b/gcc/config/aarch64/aarch64-simd.md
index cab26a3..ff71291 100644
--- a/gcc/config/aarch64/aarch64-simd.md
+++ b/gcc/config/aarch64/aarch64-simd.md
@@ -3991,6 +3991,18 @@
   [(set_attr "type" "neon_load2_2reg")]
 )
 
+(define_insn "vec_load_lanesoi_lane"
+  [(set (match_operand:OI 0 "register_operand" "=w")
+   (unspec:OI [(match_operand: 1 "aarch64_simd_struct_operand" 
"Utv")
+   (match_operand:OI 2 "register_operand" "0")
+   (match_operand:SI 3 "immediate_operand" "i")
+   (unspec:VQ [(const_int 0)] UNSPEC_VSTRUCTDUMMY) ]
+  UNSPEC_LD2_LANE))]
+  "TARGET_SIMD"
+  "ld2\\t{%S0. - %T0.}[%3], %1"
+  [(set_attr "type" "neon_load2_one_lane")]
+)
+
 (define_insn "vec_store_lanesoi"
   [(set (match_operand:OI 0 "aarch64_simd_struct_operand" "=Utv")
(unspec:OI [(match_operand:OI 1 "register_operand" "w")
@@ -4022,6 +4034,18 @@
   [(set_attr "type" "neon_load3_3reg")]
 )
 
+(define_insn "vec_load_lanesci_lane"
+  [(set (match_operand:CI 0 "register_operand" "=w")
+   (unspec:CI [(match_operand: 1 
"aarch64_simd_struct_operand" "Utv")
+   (match_operand:CI 2 "register_operand" "0")
+   (match_operand:SI 3 "immediate_operand" "i")
+   (unspec:VQ [(const_int 0)] UNSPEC_VSTRUCTDUMMY)]
+  UNSPEC_LD3_LANE))]
+  "TARGET_SIMD"
+  "ld3\\t{%S0. - %U0.}[%3], %1"
+  [(set_attr "type" "neon_load3_one_lane")]
+)
+
 (define_insn "vec_store_lanesci"
   [(set (match_operand:CI 0 "aarch64_simd_struct_operand" "=Utv")
(unspec:CI [(match_operand:CI 1 "register_operand" "w")
@@ -4053,6 +4077,18 @@
   [(set_attr "type" "neon_load4_4reg")]
 )
 
+(define_insn "vec_load_lanesxi_lane"
+  [(set (match_operand:XI 0 "register_operand" "=w")
+   (unspec:XI [(match_operand: 1 
"aarch64_simd_struct_operand" "Utv")
+   (match_operand:XI 2 "register_operand" "0")
+   (match_operand:SI 3 "immediate_operand" "i")
+   (unspec:VQ [(const_int 0)] UNSPEC_VSTRUCTDUMMY)]
+  UNSPEC_LD4_LANE))]
+  "TARGET_SIMD"
+  "ld4\\t{%S0. - %V0.}[%3], %1"
+  [(set_attr "type" "neon_load4_one_lane")]
+)
+
 (defin

[PATCH 2/2] [AARCH64,NEON] Convert arm_neon.h to use new builtins for vld[234](q?)_lane_*

2014-10-08 Thread charles . baylis
From: Charles Baylis 

This patch replaces the inline assembler implementations of the
vld[234](q?)_lane_* intrinsics with new versions which exploit the new builtin
functions added in patch 1.

Tested (with the rest of the patch series) with make check on aarch64-oe-linux
with qemu, and also causes no regressions in clyon's NEON intrinsics tests.

  Charles Baylis  

* config/aarch64/arm_neon.h (__LD2_LANE_FUNC): Rewrite using builtins,
update uses to use new macro arguments.
(__LD3_LANE_FUNC): Likewise.
(__LD4_LANE_FUNC): Likewise.

Change-Id: I3bd5934b5c4f6127088193c1ab12848144d5540a
---
 gcc/config/aarch64/arm_neon.h | 377 --
 1 file changed, 255 insertions(+), 122 deletions(-)

diff --git a/gcc/config/aarch64/arm_neon.h b/gcc/config/aarch64/arm_neon.h
index 9b1873f..19ce261 100644
--- a/gcc/config/aarch64/arm_neon.h
+++ b/gcc/config/aarch64/arm_neon.h
@@ -11805,47 +11805,83 @@ __LD2R_FUNC (uint16x8x2_t, uint16x2_t, uint16_t, 8h, 
u16, q)
 __LD2R_FUNC (uint32x4x2_t, uint32x2_t, uint32_t, 4s, u32, q)
 __LD2R_FUNC (uint64x2x2_t, uint64x2_t, uint64_t, 2d, u64, q)
 
-#define __LD2_LANE_FUNC(rettype, ptrtype, regsuffix,   \
-   lnsuffix, funcsuffix, Q)\
-  __extension__ static __inline rettype
\
-  __attribute__ ((__always_inline__))  \
-  vld2 ## Q ## _lane_ ## funcsuffix (const ptrtype *ptr,   \
-rettype b, const int c)\
-  {\
-rettype result;\
-__asm__ ("ld1 {v16." #regsuffix ", v17." #regsuffix "}, %1\n\t"\
-"ld2 {v16." #lnsuffix ", v17." #lnsuffix "}[%3], %2\n\t"   \
-"st1 {v16." #regsuffix ", v17." #regsuffix "}, %0\n\t" \
-: "=Q"(result) \
-: "Q"(b), "Q"(*(const rettype *)ptr), "i"(c)   \
-: "memory", "v16", "v17"); \
-return result; \
-  }
-
-__LD2_LANE_FUNC (int8x8x2_t, uint8_t, 8b, b, s8,)
-__LD2_LANE_FUNC (float32x2x2_t, float32_t, 2s, s, f32,)
-__LD2_LANE_FUNC (float64x1x2_t, float64_t, 1d, d, f64,)
-__LD2_LANE_FUNC (poly8x8x2_t, poly8_t, 8b, b, p8,)
-__LD2_LANE_FUNC (poly16x4x2_t, poly16_t, 4h, h, p16,)
-__LD2_LANE_FUNC (int16x4x2_t, int16_t, 4h, h, s16,)
-__LD2_LANE_FUNC (int32x2x2_t, int32_t, 2s, s, s32,)
-__LD2_LANE_FUNC (int64x1x2_t, int64_t, 1d, d, s64,)
-__LD2_LANE_FUNC (uint8x8x2_t, uint8_t, 8b, b, u8,)
-__LD2_LANE_FUNC (uint16x4x2_t, uint16_t, 4h, h, u16,)
-__LD2_LANE_FUNC (uint32x2x2_t, uint32_t, 2s, s, u32,)
-__LD2_LANE_FUNC (uint64x1x2_t, uint64_t, 1d, d, u64,)
-__LD2_LANE_FUNC (float32x4x2_t, float32_t, 4s, s, f32, q)
-__LD2_LANE_FUNC (float64x2x2_t, float64_t, 2d, d, f64, q)
-__LD2_LANE_FUNC (poly8x16x2_t, poly8_t, 16b, b, p8, q)
-__LD2_LANE_FUNC (poly16x8x2_t, poly16_t, 8h, h, p16, q)
-__LD2_LANE_FUNC (int8x16x2_t, int8_t, 16b, b, s8, q)
-__LD2_LANE_FUNC (int16x8x2_t, int16_t, 8h, h, s16, q)
-__LD2_LANE_FUNC (int32x4x2_t, int32_t, 4s, s, s32, q)
-__LD2_LANE_FUNC (int64x2x2_t, int64_t, 2d, d, s64, q)
-__LD2_LANE_FUNC (uint8x16x2_t, uint8_t, 16b, b, u8, q)
-__LD2_LANE_FUNC (uint16x8x2_t, uint16_t, 8h, h, u16, q)
-__LD2_LANE_FUNC (uint32x4x2_t, uint32_t, 4s, s, u32, q)
-__LD2_LANE_FUNC (uint64x2x2_t, uint64_t, 2d, d, u64, q)
+#define __LD2_LANE_FUNC(intype, vectype, largetype, ptrtype,  \
+mode, ptrmode, funcsuffix, signedtype)\
+__extension__ static __inline intype __attribute__ ((__always_inline__))   \
+vld2_lane_##funcsuffix (const ptrtype * __ptr, intype __b, const int __c)  \
+{ \
+  __builtin_aarch64_simd_oi __o;  \
+  largetype __temp;   \
+  __temp.val[0] = \
+vcombine_##funcsuffix (__b.val[0], vcreate_##funcsuffix (0)); \
+  __temp.val[1] = \
+vcombine_##funcsuffix (__b.val[1], vcreate_##funcsuffix (0)); \
+  __o = __builtin_aarch64_set_qregoi##mode (__o,  \
+  (signedtype) __temp.val[0], \
+  0); \
+  __o = __builtin_aarch64_set_qregoi##mode (__o,  \
+  (signedtype) __temp.val[1], \
+  1); \
+  __o =__builtin_aarch64_ld2_lane##mode (  
 

Re: C++ Patch for c++/60894

2014-10-08 Thread Fabien Chêne
2014-10-07 23:13 GMT+02:00 Jason Merrill :
> On 09/24/2014 05:15 PM, Jason Merrill wrote:
>>
>> On 09/24/2014 05:06 PM, Fabien Chêne wrote:
>>>
>>> Unfortunately, just stripping the USING_DECL in lookup_and_check_tag
>>> does not really work because some diagnotic codes expect the
>>> USING_DECL not to be stripped.
>
> It seems to me that the problem is that lookup_and_check_tag is rejecting a
> USING_DECL rather than returning it.  What if we return the USING_DECL?

If the USING_DECL is returned, the code below will be rejected as
expected, but the error message will not mention the line where the
USING_DECL appears as the previous definition, but at the target
declaration of the USING_DECL instead.

struct J
{
  struct type {};
};

struct L : J
{
  using J::type;
  struct type {};
};

The code doing that is in cp_parser_class_head, after the call to
xref_tag, at this point:

if (type != error_mark_node && COMPLETE_TYPE_P (type))
{
  error_at (type_start_token->location, "redefinition of %q#T",
type);
  error_at (type_start_token->location, "previous definition of %q+#T",
type);
...

Actually, if xref_tag strips the USING_DECL, it finds a type already
complete and the original decl is lost for the diagnostic.
Trying to skip this error does not work because 'type' is really
expected not to be complete.
Hence, I guess the solution, however disgracious it could be,  is to
ignore USING_DECLS from cp_parser_class_head through xref_tag, and
wait for the appropriate diagnostic at finish_struct (in
supplement_binding more precisely).

-- 
Fabien


RE: [Patch, MIPS] Cleanup mips header files.

2014-10-08 Thread Steve Ellcey
Matthew,

I just discovered that I dropped one of the files I changed as part of
my MIPS header file cleanup patch and so it did not get checked in.
This change was part of my testing, I just didn't include it in the
patch I submitted and checked in.  Is this (hopefully obvious) change OK
for checkin?

Steve Ellcey
sell...@mips.com



2014-10-08  Steve Ellcey  

* config/mips/mti-linux.h (DRIVER_SELF_SPECS): Change
LINUX64_DRIVER_SELF_SPECS to LINUX_DRIVER_SELF_SPECS


diff --git a/gcc/config/mips/mti-linux.h b/gcc/config/mips/mti-linux.h
index 318e981..34b64d6 100644
--- a/gcc/config/mips/mti-linux.h
+++ b/gcc/config/mips/mti-linux.h
@@ -43,4 +43,4 @@ along with GCC; see the file COPYING3.  If not see
   BASE_DRIVER_SELF_SPECS   \
\
   /* Use the standard linux specs for everything else.  */ \
-  LINUX64_DRIVER_SELF_SPECS
+  LINUX_DRIVER_SELF_SPECS




Re: [PATCH v2] libstdc++: Add hexfloat/defaultfloat io manipulators.

2014-10-08 Thread Jonathan Wakely

On 08/10/14 16:21 +0200, Rainer Orth wrote:

I'd already tried that patch before you committed it, and unfortunately
it didn't help.


Oh dear. Did you do a clean build, or at least
'touch libstdc++-v3/src/*/*.cc' to ensure the library sources get
rebuilt?  Changes to headers do not trigger everything to be rebuilt,
because we don't have proper dependencies in the makefiles.

If it's still happening I'll have to hope I can reproduce it on one of
the targets I have access to and debug it there.



RFA: AVR: add infrastructure for device packages

2014-10-08 Thread Joern Rennecke
As the steering commitee still hasn't spoken on the maintainership issue,
apparently this still has to go the write-after-approval route.

The purpose of this patch is to make it possible to add support for new
devices (MCUs) to the AVR toolchain, without having to re-build the
entire toolchain.  This capability is desirable because new MCUs are added
fairly frequently.

There are multiple parts of the toolchain involved.
gcc changes multilibbing to key off the new -march option; the -mmcu option
is translated via DRIVER_SELF_SPECS into a -specs option, and the
individual spec files contain the required settings like -march, and various
more detailed settings (some of which are for new options).

binutils provides new relocation and relaxation facilities to allow referring
symbolically to symbol differences and/or I/O addresses.
avr-libc puts the device-specifc header settings in avr/io*.h, and a few
small device-specific likbale functions into a device-specific library.

The other toolchain parts are staged here:
g...@github.com:embecosm/avr-binutils-gdb.git avr-mainline
g...@github.com:embecosm/avr-libc.git avr-libc-embecosm-mainline


Attached is the GCC patch for the basic device package infrastructure.
OK to apply?


I intend to send the patch sets for avrtiny support (modified for device
package support) and for libstdc++-v3 support next, each building on the
previous patch set.  The avrtiny support is also dependent on the
caller-save patch https://gcc.gnu.org/ml/gcc-patches/2014-10/msg00420.html ,
as avr-libc won't build otherwise.
2014-10-08  Joern Rennecke  

* config/avr/avr.opt (mmcu=): Change to have a string value.
(mn-flash=, mskip-bug, march=, mrmw): New options.
(HeaderInclude): New.
(mmcu=): Remove Var / Init clauses.
* config/avr/avr.h (DRIVER_SELF_SPECS): Translate -mmcu into a
-specs option.
(SYMBOL_FLAG_IO, SYMBOL_FLAG_ADDRESS): Define.
(ASM_OUTPUT_ALIGNED_BSS): Use avr_asm_asm_output_aligned_bss.
(SYMBOL_FLAG_IO_LOW): Define.
(avr_device_to_as, avr_device_to_ld): Don't declare.
(avr_device_to_data_start, avr_device_to_startfiles): Likewise.
(avr_device_to_devicelib, avr_device_to_sp8): Likewise.
(EXTRA_SPEC_FUNCTIONS): Don't define.
(ASM_SPEC): Translate -arch= option to -mmcu= option.
(LINK_SPEC): Translate -arch= option to -m= option.
Don't use device_to_ld / device_to_data_start.
(STARTFILE_SPEC): Now empty.
(ASM_SPEC): Add -%{mrelax: --mlink-relax}.
* config/avr/gen-avr-mmcu-specs.c: New file.
* config/avr/t-avr (gen-avr-mmcu-specs$(build_exeext)): New rule.
(s-device-specs): Likewise.
(GCC_PASSES): Add s-device-specs.
(install-driver): Depend on install-device-specs.
(install-device-specs): New rule.
* config/avr/avr.c (avr_option_override): Look up mcu arch by
avr_arch_index and provide fallback initialization for avr_n_flash.
(varasm.h): #include.
(avr_print_operand) : Allow SYMBOL_REF with SYMBOL_FLAG_IO;
(avr_handle_addr_attribute, avr_eval_addr_attrib): New functions.
(avr_attribute_table): Add "io", "address" and "io_low".
(avr_asm_output_aligned_decl_common): Change type of decl to tree.
Add special handling for symbols with "io" and/or "address" attributes.
(avr_asm_asm_output_aligned_bss): New function.
(avr_encode_section_info): Set SYMBOL_FLAG_IO and SYMBOL_FLAG_ADDRESS
as appropriate.  Handle io_low attribute.
(avr_out_sbxx_branch): Handle symbolic io addresses.
(avr_xload_libgcc_p, avr_nonconst_pointer_addrspace): Use
avr_n_flash instead of avr_current_device->n_flash.
(avr_pgm_check_var_decl, avr_insert_attributes): Likewise.
(avr_emit_movmemhi): Likewise.
* config/avr/avr-c.c (avr_cpu_cpp_builtins): Likewise.
Use TARGET_RMW instead of avr_current_device->dev_attributes.
Don't define avr_current_device->macro (that's the specfile's job).
Use TARGET_SKIP_BUG instead of avr_current_device->errata_skip.
* config/avr/avr.c (avr_2word_insn_p): Likewise.
* config/avr/avr.md (*cpse.ne): Likewise.
(mov): Use avr_eval_addr_attrib.
(cbi): Change constraint for low_io_address_operand operand to "i".
(sbi, sbix_branch, sbix_branch_bit7, insv.io, insv.not.io): Likewise.
* config/avr/predicates.md (io_address_operand):
Allow SYMBOL_REF with SYMBOL_FLAG_IO.
(low_io_address_operand): Allow SYMBOL_REF with SYMBOL_FLAG_IO_LOW.
* config/avr/avr-protos.h (avr_asm_output_aligned_decl_common):
Update prototype.
(avr_eval_addr_attrib, avr_asm_asm_output_aligned_bss): Prototype.
* config/avr/genmultilib.awk: Use -march=.
Remove Multilib matches processing.
* config/avr/t-multilib, config/avr/avr-tables.opt: Regenerate.
* conf

Re: [PATCH v2] libstdc++: Add hexfloat/defaultfloat io manipulators.

2014-10-08 Thread Rainer Orth
Jonathan Wakely  writes:

> On 08/10/14 16:21 +0200, Rainer Orth wrote:
>>I'd already tried that patch before you committed it, and unfortunately
>>it didn't help.
>
> Oh dear. Did you do a clean build, or at least
> 'touch libstdc++-v3/src/*/*.cc' to ensure the library sources get
> rebuilt?  Changes to headers do not trigger everything to be rebuilt,
> because we don't have proper dependencies in the makefiles.

Not before, because I didn't realize that the .tcc file is effectively a
header.

> If it's still happening I'll have to hope I can reproduce it on one of
> the targets I have access to and debug it there.

I've now done a clean rebuild (make clean; make) and the failure
remains.

There's been talk about getting Solaris into the compile farm, but I
haven't pursued that yet.

Rainer

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


Re: [RFC: Patch, PR 60102] [4.9/4.10 Regression] powerpc fp-bit ices@dwf_regno

2014-10-08 Thread Ulrich Weigand
rohitarulraj wrote:

> I was able to narrow down the issue.
[snip]
> While emitting the location descriptors of multiple registers (SPE high/low
> part) individually, the GCC hard register number is converted in to DWARF
> register number using "dbx_reg_number" [Statement "A",  "B" & "C" below].

> But statement "C" macro "DBX_REGISTER_NUMBER" gets undefined by statement
> "D" hence the GCC hard register number gets emitted in the debug info
> instead of DWARF register number.  Previously, without this patch for SPE
> high registers the GCC hard register number was same as the DWARF register
> number (1200 onwards), hence we didn't see this issue.
> 
> Removing statement "D"  from "sysv4.h" file so as to generate expected
> DWARF register number does work, but will there be any side effects?

Ah, I had completely forgotten about this issue, sorry ...

The problem with DBX_REGISTER_NUMBER is actually described in detail here:
https://gcc.gnu.org/ml/gcc-patches/2012-11/msg02136.html

At the time, we decided to not remove the #undef DBX_REGISTER_NUMBER to
avoid compatibility issues, but use GCC internal numbers in .debug_frame
and .debug_info on Linux (option (3) in the above mail).  However, this
was never actually implemented.

Looking at the current status, there are three groups of rs6000 targets:

- Some use the DBX_REGISTER_NUMBER definition from rs6000.h:
  These are only AIX and Darwin.

- Some provide their own definition of DBX_REGISTER_NUMBER after the rs6000.h
  one was undefined by sysv4.h:
  These are FreeBSD, NetBSD, and Lynx.

- All other targets do not have DBX_REGISTER_NUMBER because it is undefined
  by sysv4.h, and therefore using GCC internal register numbers:
  These are Linux, rtems, vxworks, and all ELF/EABI targets.


The following patch tries to remove the unfortunate confusion about undefining
and redefining DBX_REGISTER_NUMBER, while keeping the behavior on all targets
unchanged with the following two exceptions:
- fix the SPE problem by always translating high register numbers
- implement option (3) above by not replacing CR2 with CR in .debug_frame
  on targets that do not use the standard DWARF register numbering

The way this works is to have a common, simple implementation of
DBX_REGISTER_NUMBER and DWARF2_FRAME_REG_OUT for all targets that just
calls to the rs6000_dbx_register_number routine, passing an extra format
argument that decides whether the register number is to be used for
.debug_info, .debug_frame, or .eh_frame.   In order to ensure
rs6000_dbx_register_number always gets a GCC internal number as input,
DWARF_FRAME_REGNUM has to be again defined as identity map.

All the logic to decide debug register numbers is now contained in that
single place.  However, in order to maintain current behavior, we still
have to distinguish between platforms that want to use the standard
DWARF register numbering scheme, and those that use GCC internal numbers.
This is now simply done by having the former provide a new define
RS6000_USE_DWARF_NUMBERING in a target header file.

Tested on powerpc64le-linux and powerpc64-linux.

Rohit, could you verify whether this fixes the SPE problem?

David, does this approach look reasonable to you?


Bye,
Ulrich

ChangeLog:

* config/rs6000/rs6000.h (DBX_REGISTER_NUMBER): Pass format argument
to rs6000_dbx_register_number.
(DWARF_FRAME_REGNUM): Redefine as identity map.
(DWARF2_FRAME_REG_OUT): Call rs6000_dbx_register_number.
* config/rs6000/rs6000-protos.h (rs6000_dbx_register_number): Update.
* config/rs6000/rs6000.c (rs6000_dbx_register_number): Add format
argument to handle .debug_frame and .eh_frame directly.  Always
translate SPE high register numbers.  Add special treatment for CR,
but only in .debug_frame.  Respect RS6000_USE_DWARF_NUMBERING.

* config/rs6000/sysv.h (DBX_REGISTER_NUMBER): Do not undefine.
* config/rs6000/freebsd.h (DBX_REGISTER_NUMBER): Remove.
(RS6000_USE_DWARF_NUMBERING): Define.
* config/rs6000/freebsd64.h (DBX_REGISTER_NUMBER): Remove.
(RS6000_USE_DWARF_NUMBERING): Define.
* config/rs6000/netbsd.h (DBX_REGISTER_NUMBER): Remove.
(RS6000_USE_DWARF_NUMBERING): Define.
* config/rs6000/lynx.h (DBX_REGISTER_NUMBER): Remove.
(RS6000_USE_DWARF_NUMBERING): Define.
* config/rs6000/aix.h (RS6000_USE_DWARF_NUMBERING): Define.
* config/rs6000/darwin.h (RS6000_USE_DWARF_NUMBERING): Define.


Index: gcc/config/rs6000/rs6000.h
===
--- gcc/config/rs6000/rs6000.h  (revision 215999)
+++ gcc/config/rs6000/rs6000.h  (working copy)
@@ -947,23 +947,16 @@ enum data_align { align_abi, align_opt, 
   ((r) >= 1200 ? ((r) - 1200 + (DWARF_FRAME_REGISTERS - 32)) : (r))
 
 /* Use standard DWARF numbering for DWARF debugging information.  */
-#define DBX_REGISTER_NUMBER(REGNO) rs6000_dbx_register_number (REGNO)
+#define DBX_REGIS

Re: [RFC: Patch, PR 60102] [4.9/4.10 Regression] powerpc fp-bit ices@dwf_regno

2014-10-08 Thread David Edelsohn
On Wed, Oct 8, 2014 at 2:09 PM, Ulrich Weigand  wrote:
> rohitarulraj wrote:
>
>> I was able to narrow down the issue.
> [snip]
>> While emitting the location descriptors of multiple registers (SPE high/low
>> part) individually, the GCC hard register number is converted in to DWARF
>> register number using "dbx_reg_number" [Statement "A",  "B" & "C" below].
>
>> But statement "C" macro "DBX_REGISTER_NUMBER" gets undefined by statement
>> "D" hence the GCC hard register number gets emitted in the debug info
>> instead of DWARF register number.  Previously, without this patch for SPE
>> high registers the GCC hard register number was same as the DWARF register
>> number (1200 onwards), hence we didn't see this issue.
>>
>> Removing statement "D"  from "sysv4.h" file so as to generate expected
>> DWARF register number does work, but will there be any side effects?
>
> Ah, I had completely forgotten about this issue, sorry ...
>
> The problem with DBX_REGISTER_NUMBER is actually described in detail here:
> https://gcc.gnu.org/ml/gcc-patches/2012-11/msg02136.html
>
> At the time, we decided to not remove the #undef DBX_REGISTER_NUMBER to
> avoid compatibility issues, but use GCC internal numbers in .debug_frame
> and .debug_info on Linux (option (3) in the above mail).  However, this
> was never actually implemented.
>
> Looking at the current status, there are three groups of rs6000 targets:
>
> - Some use the DBX_REGISTER_NUMBER definition from rs6000.h:
>   These are only AIX and Darwin.
>
> - Some provide their own definition of DBX_REGISTER_NUMBER after the rs6000.h
>   one was undefined by sysv4.h:
>   These are FreeBSD, NetBSD, and Lynx.
>
> - All other targets do not have DBX_REGISTER_NUMBER because it is undefined
>   by sysv4.h, and therefore using GCC internal register numbers:
>   These are Linux, rtems, vxworks, and all ELF/EABI targets.
>
>
> The following patch tries to remove the unfortunate confusion about undefining
> and redefining DBX_REGISTER_NUMBER, while keeping the behavior on all targets
> unchanged with the following two exceptions:
> - fix the SPE problem by always translating high register numbers
> - implement option (3) above by not replacing CR2 with CR in .debug_frame
>   on targets that do not use the standard DWARF register numbering
>
> The way this works is to have a common, simple implementation of
> DBX_REGISTER_NUMBER and DWARF2_FRAME_REG_OUT for all targets that just
> calls to the rs6000_dbx_register_number routine, passing an extra format
> argument that decides whether the register number is to be used for
> .debug_info, .debug_frame, or .eh_frame.   In order to ensure
> rs6000_dbx_register_number always gets a GCC internal number as input,
> DWARF_FRAME_REGNUM has to be again defined as identity map.
>
> All the logic to decide debug register numbers is now contained in that
> single place.  However, in order to maintain current behavior, we still
> have to distinguish between platforms that want to use the standard
> DWARF register numbering scheme, and those that use GCC internal numbers.
> This is now simply done by having the former provide a new define
> RS6000_USE_DWARF_NUMBERING in a target header file.
>
> Tested on powerpc64le-linux and powerpc64-linux.
>
> Rohit, could you verify whether this fixes the SPE problem?
>
> David, does this approach look reasonable to you?

This seems like the best solution.  Thanks for untangling this.

- David


Re: [PATCH 2/4] [AARCH64,NEON] Convert arm_neon.h to use new builtins for vld[234](q?)_lane_*

2014-10-08 Thread Charles Baylis
On 26 September 2014 13:47, Tejas Belagod  wrote:
> If we use type-punning, there are unnecessary spills that are generated
> which is also incorrect for BE because of of the way we spill (st1 {v0.16b -
> v1.16b}, [sp]) and restore. The implementation without type-punning seems to
> give a more optimal result. Did your patches improve on the spills for the
> type-punning solution?

OK, this part seems too contentious, so I've respun the vldN_lane
parts without the type punning and reposted them. This issue can be
resolved separately.

Trying an example like this gives good code with type punning, and
poor code without.

void t2(int32_t *p)
{
int32x4x4_t va = vld4q_s32(p);
va = vld4q_lane_s32(p + 500, va, 1);
vst4q_s32(p+1000, va);
}


With type-punning, good code:
t2:
ld4 {v0.4s - v3.4s}, [x0]
add x2, x0, 2000
add x1, x0, 4000
ld4 {v0.s - v3.s}[1], [x2]
st4 {v0.4s - v3.4s}, [x1]
ret

Without type-punning, horrible code:
t2:
ld4 {v0.4s - v3.4s}, [x0]
sub sp, sp, #64
add x14, x0, 2000
add x0, x0, 4000
umovx12, v0.d[0]
umovx13, v0.d[1]
umovx10, v1.d[0]
umovx11, v1.d[1]
umovx8, v2.d[0]
str x12, [sp]
umovx9, v2.d[1]
str x13, [sp, 8]
str q3, [sp, 48]
str x10, [sp, 16]
str x11, [sp, 24]
str x8, [sp, 32]
str x9, [sp, 40]
ld1 {v0.16b - v3.16b}, [sp]
ld4 {v0.s - v3.s}[1], [x14]
umovx10, v0.d[0]
umovx11, v0.d[1]
umovx8, v1.d[0]
umovx9, v1.d[1]
umovx6, v2.d[0]
str x10, [sp]
umovx7, v2.d[1]
str x11, [sp, 8]
str q3, [sp, 48]
str x8, [sp, 16]
str x9, [sp, 24]
str x6, [sp, 32]
str x7, [sp, 40]
ld1 {v0.16b - v3.16b}, [sp]
add sp, sp, 64
st4 {v0.4s - v3.4s}, [x0]
ret

>> Maybe the solution is to pass the NEON
>> intrinsic types directly to the builtins? Is there a reason that it
>> wasn't done that way before?
>
> How do you mean? Do you mean pass a loaded value int32x2x2_t into a
> __builtin? How will that work?
>
> If you mean why we don't pass an int32x2x2_t into a builtin as a structure,
> I don't think that would work as it is struct type which would correspond to
> a  BLK mode, but we need RTL patterns with reg-lists to work with large int
> modes for the regalloc to allocate consecutive regs for the reglists.

OK, that makes sense. However, something needs to be done to create
the __arch64_simd_ objects without register moves. Since the existing
mechanism causes problems because the lifetimes of the inputs overlap
with the lifetimes of the outputs, I think there are these options:

1. represent the construction/deconstruction as a single operation, to
avoid overlapping variable liveness in the source.
2. add a pass or peephole which can combine the existing builtins into
a single operation, so that the lifetimes are normalised.
3. teach the register allocator how to handle overlapping liveness of
a register and a subreg of that register.

Option 1 would require a new builtin interface which somehow handled a
whole int32x2x2_t in one operation. Construction is easy
(__builtin_aarch64_simd_construct(v.val[0], v.val[1]) or similar).
Deconstruction is less obvious

Option 2 sounds like a hack, but would probably be effective,
particularly if it can be done before inlining.

Option 3 would also help with poor code generation for ARM targets
with vget_low_*, vget_high_* and vcombine_*.

What do you think is the best approach?

Thanks
Charles


[PATCH, Pointer Bounds Checker 14/x] Passes [1/n] Expand interfaces

2014-10-08 Thread Ilya Enkovich
Hi,

This patch starts a series which is a result of split of Pointer Bounds Checker 
patch #14 (Pointer Bounds Checker passes).

This patch introduces compiler flags used by checker and helper functions 
mostly used by expand pass.

Thanks,
Ilya
--
2014-10-08  Ilya Enkovich  

* tree-chkp.c: New.
* tree-chkp.h: New.
* rtl-chkp.c: New.
* rtl-chkp.h: New.
* Makefile.in (OBJS): Add rtl-chkp.o and tree-chkp.o.
(GTFILES): Add tree-chkp.c.
* c-family/c.opt (fchkp-check-incomplete-type): New.
(fchkp-zero-input-bounds-for-main): New.
(fchkp-first-field-has-own-bounds): New.
(fchkp-narrow-bounds): New.
(fchkp-narrow-to-innermost-array): New.
(fchkp-optimize): New.
(fchkp-use-fast-string-functions): New.
(fchkp-use-nochk-string-functions): New.
(fchkp-use-static-bounds): New.
(fchkp-use-static-const-bounds): New.
(fchkp-treat-zero-dynamic-size-as-infinite): New.
(fchkp-check-read): New.
(fchkp-check-write): New.
(fchkp-store-bounds): New.
(fchkp-instrument-calls): New.
(fchkp-instrument-marked-only): New.
* cppbuiltin.c (define_builtin_macros_for_compilation_flags): Add
__CHKP__ macro when Pointer Bounds Checker is on.


diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 97b439a..3113a9f 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1328,6 +1328,7 @@ OBJS = \
reload1.o \
reorg.o \
resource.o \
+   rtl-chkp.o \
rtl-error.o \
rtl.o \
rtlhash.o \
@@ -1386,6 +1387,7 @@ OBJS = \
tree-outof-ssa.o \
tree-parloops.o \
tree-phinodes.o \
+   tree-chkp.o \
tree-predcom.o \
tree-pretty-print.o \
tree-profile.o \
@@ -2254,6 +2256,7 @@ GTFILES = $(CPP_ID_DATA_H) $(srcdir)/input.h 
$(srcdir)/coretypes.h \
   $(srcdir)/stringpool.c $(srcdir)/tree.c $(srcdir)/varasm.c \
   $(srcdir)/gimple.h \
   $(srcdir)/gimple-ssa.h \
+  $(srcdir)/tree-chkp.c \
   $(srcdir)/tree-ssanames.c $(srcdir)/tree-eh.c $(srcdir)/tree-ssa-address.c \
   $(srcdir)/tree-cfg.c \
   $(srcdir)/tree-dfa.c \
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 3c5ebc0..1ca5a95 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -955,6 +955,79 @@ Common Report Var(flag_check_pointer_bounds)
 Add Pointer Bounds Checker instrumentation.  fchkp-* flags are used to
 control instrumentation.  Currently available for C, C++ and ObjC.
 
+fchkp-check-incomplete-type
+C ObjC C++ ObjC++ Report Var(flag_chkp_incomplete_type) Init(1)
+Generate pointer bounds checks for variables with incomplete type
+
+fchkp-zero-input-bounds-for-main
+C ObjC C++ ObjC++ Report Var(flag_chkp_zero_input_bounds_for_main) Init(0)
+Use zero bounds for all incoming arguments in 'main' function.  It helps when
+instrumented binaries are used with legacy libs.
+
+fchkp-first-field-has-own-bounds
+C ObjC C++ ObjC++ RejectNegative Report 
Var(flag_chkp_first_field_has_own_bounds)
+Forces Pointer Bounds Checker to use narrowed bounds for address of the first
+field in the structure.  By default pointer to the first field has the same
+bounds as pointer to the whole structure.
+
+fchkp-narrow-bounds
+C ObjC C++ ObjC++ Report Var(flag_chkp_narrow_bounds) Init(1)
+Control how Pointer Bounds Checker handle pointers to object fields.  When
+narrowing is on, field bounds are used.  Otherwise full object bounds are used.
+
+fchkp-narrow-to-innermost-array
+C ObjC C++ ObjC++ RejectNegative Report 
Var(flag_chkp_narrow_to_innermost_arrray)
+Forces Pointer Bounds Checker to use bounds of the innermost arrays in case of
+nested static arryas access.  By default outermost array is used.
+
+fchkp-optimize
+C ObjC C++ ObjC++ LTO Report Var(flag_chkp_optimize) Init(-1)
+Allow Pointer Bounds Checker optimizations.  By default allowed
+on optimization levels >0.
+
+fchkp-use-fast-string-functions
+C ObjC C++ ObjC++ LTO Report Var(flag_chkp_use_fast_string_functions) Init(0)
+Allow to use *_nobnd versions of string functions by Pointer Bounds Checker.
+
+fchkp-use-nochk-string-functions
+C ObjC C++ ObjC++ LTO Report Var(flag_chkp_use_nochk_string_functions) Init(0)
+Allow to use *_nochk versions of string functions by Pointer Bounds Checker.
+
+fchkp-use-static-bounds
+C ObjC C++ ObjC++ Report Var(flag_chkp_use_static_bounds) Init(1)
+Use statically initialized variable for vars bounds instead of
+generating them each time it is required.
+
+fchkp-use-static-const-bounds
+C ObjC C++ ObjC++ Report Var(flag_chkp_use_static_const_bounds) Init(-1)
+Use statically initialized variable for constant bounds instead of
+generating them each time it is required.
+
+fchkp-treat-zero-dynamic-size-as-infinite
+C ObjC C++ ObjC++ Report Var(flag_chkp_zero_dynamic_size_as_infinite) Init(0)
+With this option zero size obtained dynamically for objects with
+incomplete type will be treated as infinite.
+
+fchkp-check-read
+C

[PATCH, Pointer Bounds Checker 14/x] Passes [2/n] IPA passes

2014-10-08 Thread Ilya Enkovich
Hi,

This patch introduces two IPA passes used by Pointer Bounds Checker.  One pass 
creates clones for instrumentation.  The other one transforms unneeded 
functions into thunks.

Thanks,
Ilya
--
2014-10-08  Ilya Enkovich  

* ipa-chkp.c: New.
* ipa-chkp.h: New.
* Makefile.in (OBJS): Add ipa-chkp.o.


diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 3113a9f..d8c8488 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1253,6 +1253,7 @@ OBJS = \
incpath.o \
init-regs.o \
internal-fn.o \
+   ipa-chkp.o \
ipa-cp.o \
ipa-devirt.o \
ipa-split.o \
diff --git a/gcc/ipa-chkp.c b/gcc/ipa-chkp.c
new file mode 100644
index 000..f7ac713
--- /dev/null
+++ b/gcc/ipa-chkp.c
@@ -0,0 +1,622 @@
+/* Pointer Bounds Checker IPA passes.
+   Copyright (C) 2014 Free Software Foundation, Inc.
+   Contributed by Ilya Enkovich (ilya.enkov...@intel.com)
+
+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 "tree-core.h"
+#include "stor-layout.h"
+#include "tree.h"
+#include "tree-pass.h"
+#include "stringpool.h"
+#include "bitmap.h"
+#include "gimple-expr.h"
+#include "function.h"
+#include "tree-chkp.h"
+#include 
+
+/*  Pointer Bounds Checker has two IPA passes to support code instrumentation.
+
+In instrumented code each pointer is provided with bounds.  For input
+pointer parameters it means we also have bounds passed.  For calls it
+means we have additional bounds arguments for pointer arguments.
+
+To have all IPA optimizations working correctly we have to express
+dataflow between passed and received bounds explicitly via additional
+entries in function declaration arguments list and in function type.
+Since we may have both instrumented and not instrumented code at the
+same time, we cannot replace all original functions with their
+instrumented variants.  Therefore we create clones (versions) instead.
+
+Instrumentation clones creation is a separate IPA pass which is a part
+of early local passes.  Clones are created after SSA is built (because
+instrumentation pass works on SSA) and before any transformations
+which may change pointer flow and therefore lead to incorrect code
+instrumentation (possibly causing false bounds check failures).
+
+Instrumentation clones have pointer bounds arguments added right after
+pointer arguments.  Clones have assembler name of the original
+function with suffix added.  New assembler name is in transparent
+alias chain with the original name.  Thus we expect all calls to the
+original and instrumented functions look similar in assembler.
+
+During instrumentation versioning pass we create instrumented versions
+of all function with body and also for all their aliases and thunks.
+Clones for functions with no body are created on demand (usually
+during call instrumentation).
+
+Original and instrumented function nodes are connected with IPA
+reference IPA_REF_CHKP.  It is mostly done to have reachability
+analysis working correctly.  We may have no references to the
+instrumented function in the code but it still should be counted
+as reachable if the original function is reachable.
+
+When original function bodies are not needed anymore we release
+them and transform functions into a special kind of thunks.  Each
+thunk has a call edge to the instrumented version.  These thunks
+help to keep externally visible instrumented functions visible
+when linker reolution files are used.  Linker has no info about
+connection between original and instrumented function and
+therefore we may wrongly decide (due to difference in assember
+names) that instrumented function version is local and can be
+removed.  */
+
+#define CHKP_BOUNDS_OF_SYMBOL_PREFIX "__chkp_bounds_of_"
+
+/* Build a clone of FNDECL with a modified name.  */
+
+static tree
+chkp_build_instrumented_fndecl (tree fndecl)
+{
+  tree new_decl = copy_node (fndecl);
+  tree new_name;
+  std::string s;
+
+  /* We want called_as_built_in recall instrumented calls
+ to instrumented built-in functions.  Therefore use
+ DECL_NAME for cloning instead of DECL_ASSEMBLER_NAME.  */
+  s = IDENTIFIER_POINTER (DECL_NAME (fndecl));
+  s += ".chkp";
+  DECL_NAME (n

[PATCH, Pointer Bounds Checker 14/x] Passes [3/n] Helper functions

2014-10-08 Thread Ilya Enkovich
Hi,

This patch introduces helper functions used by instrumentation.  These helpers 
are used to access local structures, generate typical expressions, vars and 
statements.  I also included local data initializer into this patch.

Thanks,
Ilya
--
2014-10-08  Ilya Enkovich  

* tree-chkp.c (assign_handler): New.
(chkp_get_zero_bounds): New.
(chkp_uintptr_type): New.
(chkp_none_bounds_var): New.
(entry_block): New.
(zero_bounds): New.
(none_bounds): New.
(incomplete_bounds): New.
(tmp_var): New.
(size_tmp_var): New.
(chkp_abnormal_copies): New.
(chkp_invalid_bounds): New.
(chkp_completed_bounds_set): New.
(chkp_reg_bounds): New.
(chkp_bound_vars): New.
(chkp_reg_addr_bounds): New.
(chkp_incomplete_bounds_map): New.
(chkp_static_var_bounds): New.
(in_chkp_pass): New.
(CHKP_BOUND_TMP_NAME): New.
(CHKP_SIZE_TMP_NAME): New.
(CHKP_BOUNDS_OF_SYMBOL_PREFIX): New.
(CHKP_STRING_BOUNDS_PREFIX): New.
(CHKP_VAR_BOUNDS_PREFIX): New.
(CHKP_NONE_BOUNDS_VAR_NAME): New.
(chkp_get_tmp_var): New.
(chkp_get_tmp_reg): New.
(chkp_get_size_tmp_var): New.
(chkp_register_addr_bounds): New.
(chkp_get_registered_addr_bounds): New.
(chkp_mark_completed_bounds): New.
(chkp_completed_bounds): New.
(chkp_erase_completed_bounds): New.
(chkp_register_incomplete_bounds): New.
(chkp_incomplete_bounds): New.
(chkp_erase_incomplete_bounds): New.
(chkp_mark_invalid_bounds): New.
(chkp_valid_bounds): New.
(chkp_mark_invalid_bounds_walker): New.
(chkp_build_addr_expr): New.
(chkp_get_entry_block): New.
(chkp_get_bounds_var): New.
(chkp_get_registered_bounds): New.
(chkp_check_lower): New.
(chkp_check_upper): New.
(chkp_check_mem_access): New.
(chkp_build_component_ref): New.
(chkp_build_array_ref): New.
(chkp_can_be_shared): New.
(chkp_make_bounds): New.
(chkp_get_none_bounds_var): New.
(chkp_get_zero_bounds): New.
(chkp_get_none_bounds): New.
(chkp_get_invalid_op_bounds): New.
(chkp_get_nonpointer_load_bounds): New.
(chkp_get_next_bounds_parm): New.
(chkp_build_bndldx): New.
(chkp_make_static_bounds): New.
(chkp_generate_extern_var_bounds): New.
(chkp_intersect_bounds): New.
(chkp_may_narrow_to_field): New.
(chkp_narrow_bounds_for_field): New.
(chkp_narrow_bounds_to_field): New.
(chkp_walk_pointer_assignments): New.
(chkp_init): New.


diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index 4ab8de6..c65334c 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -65,6 +65,10 @@ along with GCC; see the file COPYING3.  If not see
 #include "rtl.h" /* For MEM_P, assign_temp.  */
 #include "tree-dfa.h"
 
+typedef void (*assign_handler)(tree, tree, void *);
+
+static tree chkp_get_zero_bounds ();
+
 #define chkp_bndldx_fndecl \
   (targetm.builtin_chkp_function (BUILT_IN_CHKP_BNDLDX))
 #define chkp_bndstx_fndecl \
@@ -88,11 +92,37 @@ along with GCC; see the file COPYING3.  If not see
 #define chkp_extract_upper_fndecl \
   (targetm.builtin_chkp_function (BUILT_IN_CHKP_EXTRACT_UPPER))
 
-static GTY (()) tree chkp_zero_bounds_var;
+static GTY (()) tree chkp_uintptr_type;
 
+static GTY (()) tree chkp_zero_bounds_var;
+static GTY (()) tree chkp_none_bounds_var;
+
+static GTY (()) basic_block entry_block;
+static GTY (()) tree zero_bounds;
+static GTY (()) tree none_bounds;
+static GTY (()) tree incomplete_bounds;
+static GTY (()) tree tmp_var;
+static GTY (()) tree size_tmp_var;
+static GTY (()) bitmap chkp_abnormal_copies;
+
+struct hash_set *chkp_invalid_bounds;
+struct hash_set *chkp_completed_bounds_set;
+struct hash_map *chkp_reg_bounds;
+struct hash_map *chkp_bound_vars;
+struct hash_map *chkp_reg_addr_bounds;
+struct hash_map *chkp_incomplete_bounds_map;
 struct hash_map *chkp_bounds_map;
+struct hash_map *chkp_static_var_bounds;
+
+static bool in_chkp_pass;
 
+#define CHKP_BOUND_TMP_NAME "__bound_tmp"
+#define CHKP_SIZE_TMP_NAME "__size_tmp"
+#define CHKP_BOUNDS_OF_SYMBOL_PREFIX "__chkp_bounds_of_"
+#define CHKP_STRING_BOUNDS_PREFIX "__chkp_string_bounds_"
+#define CHKP_VAR_BOUNDS_PREFIX "__chkp_var_bounds_"
 #define CHKP_ZERO_BOUNDS_VAR_NAME "__chkp_zero_bounds"
+#define CHKP_NONE_BOUNDS_VAR_NAME "__chkp_none_bounds"
 
 /* Return 1 if function FNDECL is instrumented by Pointer
Bounds Checker.  */
@@ -172,6 +202,130 @@ chkp_marked_stmt_p (gimple s)
   return gimple_plf (s, GF_PLF_1);
 }
 
+/* Get var to be used for bound temps.  */
+static tree
+chkp_get_tmp_var (void)
+{
+  if (!tmp_var)
+tmp_var = create_tmp_reg (pointer_bounds_type_node, CHKP_BOUND_TMP_NAME);
+
+  return tmp_var;
+}
+
+/* Get SSA_NAME to be used as temp.  */
+stat

[PATCH, Pointer Bounds Checker 14/x] Passes [4/n] Memory accesses instrumentation

2014-10-08 Thread Ilya Enkovich
Hi,

This is the main chunk of instrumentation codes.  This patch introduces 
instrumentation pass which instruments memory accesses.

Thanks,
Ilya
--
2014-10-08  Ilya Enkovich  

* tree-chkp.c (chkp_may_complete_phi_bounds): New.
(chkp_may_finish_incomplete_bounds): New.
(chkp_recompute_phi_bounds): New.
(chkp_find_valid_phi_bounds): New.
(chkp_finish_incomplete_bounds): New.
(chkp_maybe_copy_and_register_bounds): New.
(chkp_build_returned_bound): New.
(chkp_get_bound_for_parm): New.
(chkp_compute_bounds_for_assignment): New.
(chkp_get_bounds_by_definition): New.
(chkp_get_bounds_for_decl_addr): New.
(chkp_get_bounds_for_string_cst): New.
(chkp_parse_array_and_component_ref): New.
(chkp_make_addressed_object_bounds): New.
(chkp_find_bounds_1): New.
(chkp_find_bounds): New.
(chkp_find_bounds_loaded): New.
(chkp_copy_bounds_for_elem): New.
(chkp_process_stmt): New.
(chkp_fix_cfg): New.
(chkp_instrument_function): New.
(chkp_fini): New.
(chkp_execute): New.
(chkp_gate): New.
(pass_data_chkp): New.
(pass_chkp): New.
(make_pass_chkp): New.
diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index c65334c..d297171 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -65,9 +65,278 @@ along with GCC; see the file COPYING3.  If not see
 #include "rtl.h" /* For MEM_P, assign_temp.  */
 #include "tree-dfa.h"
 
+/*  Pointer Bounds Checker instruments code with memory checks to find
+out-of-bounds memory accesses.  Checks are performed by computing
+bounds for each pointer and then comparing address of accessed
+memory before pointer dereferencing.
+
+1. Function clones.
+
+See ipa-chkp.c.
+
+2. Instrumentation.
+
+There are few things to instrument:
+
+a) Memory accesses - add checker calls to check address of accessed memory
+against bounds of dereferenced pointer.  Obviously safe memory
+accesses like static variable access does not have to be instrumented
+with checks.
+
+Example:
+
+  val_2 = *p_1;
+
+  with 4 bytes access is transformed into:
+
+  __builtin___chkp_bndcl (__bound_tmp.1_3, p_1);
+  D.1_4 = p_1 + 3;
+  __builtin___chkp_bndcu (__bound_tmp.1_3, D.1_4);
+  val_2 = *p_1;
+
+  where __bound_tmp.1_3 are bounds computed for pointer p_1,
+  __builtin___chkp_bndcl is a lower bound check and
+  __builtin___chkp_bndcu is an upper bound check.
+
+b) Pointer stores.
+
+When pointer is stored in memory we need to store its bounds.  To
+achieve compatibility of instrumented code with regular codes
+we have to keep data layout and store bounds in special bound tables
+via special checker call.  Implementation of bounds table may vary for
+different platforms.  It has to associate pointer value and its
+location (it is required because we may have two equal pointers
+with different bounds stored in different places) with bounds.
+Another checker builtin allows to get bounds for specified pointer
+loaded from specified location.
+
+Example:
+
+  buf1[i_1] = &buf2;
+
+  is transformed into:
+
+  buf1[i_1] = &buf2;
+  D.1_2 = &buf1[i_1];
+  __builtin___chkp_bndstx (D.1_2, &buf2, __bound_tmp.1_2);
+
+  where __bound_tmp.1_2 are bounds of &buf2.
+
+c) Static initialization.
+
+The special case of pointer store is static pointer initialization.
+Bounds initialization is performed in a few steps:
+  - register all static initializations in front-end using
+  chkp_register_var_initializer
+  - when file compilation finishes we create functions with special
+  attribute 'chkp ctor' and put explicit initialization code
+  (assignments) for all statically initialized pointers.
+  - when checker constructor is compiled checker pass adds required
+  bounds initialization for all statically initialized pointers
+  - since we do not actually need excess pointers initialization
+  in checker constructor we remove such assignments from them
+
+d) Calls.
+
+For each call in the code we add additional arguments to pass
+bounds for pointer arguments.  We determine type of call arguments
+using arguments list from function declaration; if function
+declaration is not available we use function type; otherwise
+(e.g. for unnamed arguments) we use type of passed value. Function
+declaration/type is replaced with the instrumented one.
+
+Example:
+
+  val_1 = foo (&buf1, &buf2, &buf1, 0);
+
+  is translated into:
+
+  val_1 = foo.chkp (&buf1, __bound_tmp.1_2, &buf2, __bound_tmp.1_3,
+&buf1, __bound_tmp.1_2, 0);
+
+e) Returns.
+
+If function returns a pointer value we have to return bounds also.
+A new operand was added for return statement to hold returned 

[PATCH, Pointer Bounds Checker 14/x] Passes [5/n] Replace function pointers

2014-10-08 Thread Ilya Enkovich
Hi,

This patch add function pointers replacement into instrumentation pass.

Thanks,
Ilya
--
2014-10-08  Ilya Enkovich  

* tree-chkp.c: Include ipa-chkp.h.
(chkp_replace_function_pointer): New.
(chkp_replace_function_pointers): New.
(chkp_instrument_function): Call replace function pointers
in all statements with instrumented ones.


diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index d297171..bbb6459 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -64,6 +64,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-walk.h"
 #include "rtl.h" /* For MEM_P, assign_temp.  */
 #include "tree-dfa.h"
+#include "ipa-chkp.h"
 
 /*  Pointer Bounds Checker instruments code with memory checks to find
 out-of-bounds memory accesses.  Checks are performed by computing
@@ -3270,6 +3271,49 @@ chkp_fix_cfg ()
   }
 }
 
+/* Walker callback for chkp_replace_function_pointers.  Replaces
+   function pointer in the specified operand with pointer to the
+   instrumented function version.  */
+static tree
+chkp_replace_function_pointer (tree *op, int *walk_subtrees,
+  void *data ATTRIBUTE_UNUSED)
+{
+  if (TREE_CODE (*op) == FUNCTION_DECL
+  && !lookup_attribute ("bnd_legacy", DECL_ATTRIBUTES (*op))
+  /* Do not replace builtins for now.  */
+  && DECL_BUILT_IN_CLASS (*op) == NOT_BUILT_IN)
+{
+  struct cgraph_node *node = cgraph_node::get_create (*op);
+
+  if (!node->instrumentation_clone)
+   chkp_maybe_create_clone (*op);
+
+  *op = node->instrumented_version->decl;
+  *walk_subtrees = 0;
+}
+
+  return NULL;
+}
+
+/* This function searches for function pointers in statement
+   pointed by GSI and replaces them with pointers to instrumented
+   function versions.  */
+static void
+chkp_replace_function_pointers (gimple_stmt_iterator *gsi)
+{
+  gimple stmt = gsi_stmt (*gsi);
+  /* For calls we want to walk call args only.  */
+  if (gimple_code (stmt) == GIMPLE_CALL)
+{
+  unsigned i;
+  for (i = 0; i < gimple_call_num_args (stmt); i++)
+   walk_tree (gimple_call_arg_ptr (stmt, i),
+  chkp_replace_function_pointer, NULL, NULL);
+}
+  else
+walk_gimple_stmt (gsi, NULL, chkp_replace_function_pointer, NULL);
+}
+
 /* This function instruments all statements working with memory.  */
 static void
 chkp_instrument_function (void)
@@ -3294,6 +3338,8 @@ chkp_instrument_function (void)
  continue;
}
 
+ chkp_replace_function_pointers (&i);
+
   switch (gimple_code (s))
 {
 case GIMPLE_ASSIGN:


Re: [PATCH] Enhance array types debug info. for Ada

2014-10-08 Thread Pierre-Marie de Rodat

On 10/07/2014 10:29 AM, Jakub Jelinek wrote:

But isn't there a risk that you will have PLACEHOLDER_EXPRs (likely for Ada
only) in some trees not constructed by the langhook?
I mean, DW_OP_push_object_address isn't meaningful in all DWARF contexts,
in some it is forbidden, in others there is really no object to push, and as
implemented, you emit DW_OP_push_object_address (which emits the address of
a context related particular object) for any kind of PLACEHOLDER_EXPR with
RECORD_TYPE.


Even with GNAT, this is not _supposed_ to happen. However during the 
development (for instance with LTO) I noticed cases where 
PLACEHOLDER_EXPR nodes were incorrectly used. Thanks to current work on 
the early debug info pass, such cases are doomed to disappear, but I 
completely agree with your point, so thank you for raising it. :-)



Thus, I'd feel safer, even if you decide to use a PLACEHOLDER_EXPR, that
the translation of that to DW_OP_push_object_address would be done only
if the PLACEHOLDER_EXPR is equal to some global variable, normally NULL,
and only changed temporarily while emitting loc for the array descriptor.


This is what the updated (and attached) patch does. Note that upcoming 
patches will enhance loc_list_from_tree (adding another parameter to 
loc_list_from_tree) and make it recurse to generate sub-expressions as 
DWARF procedures. Because of this kind recursion, I added a composite 
argument instead of relying on a global variable (so that "nested" 
contexts can exist at the same time).



But then IMHO a DEBUG_EXPR_DECL is better.
[...]
Also, please verify that with your patch the generated debug info for some
Fortran arrays is the same.


It's fortunate that you asked this since I wrongly assumed there was the 
corresponding testing in the GDB testsuite. As a matter of fact, support 
for Fortran's variable length arrays in GDB is still a work in progress 
so tests are not commited yet. So I used the Fortran example I could 
find there  instead and discovered that my 
patch did break debugging information for Fortran array types.


Fixing it while keeping a PLACEHOLDER_EXPR-based implementation seems a 
too heavy task for my little experience in the Fortran front-end and 
after having a closer look I agree with you: it seems less adapted to 
how things are currently done, there. So I finally leveraged this new 
composite argument to re-introduce the base_decl mechanism. 
DEBUG_EXPR_DECL is back in the Fortran front-end. ;-) Now, the same 
example keeps the same debugging information.


The latest patches bootstrapped well and passed successfully the GCC 
testsuite on x86_64-pc-linux-gnu.


--
Pierre-Marie de Rodat
>From 794cafffae7202cd9ea8156bb7f7433a4e109e6c Mon Sep 17 00:00:00 2001
From: Pierre-Marie de Rodat 
Date: Mon, 9 Jun 2014 15:13:45 +0200
Subject: [PATCH 5/5] dwarf2out.c: do not short-circuit add_bound_info in
 array descr. lang-hook

gcc/
	* dwarf2out.h (struct array_descr_info): Remove the base_decl field.
	* dwarf2out.c (enum dw_scalar_form): New.
	(struct loc_descr_context): New.
	(add_scalar_info): New.
	(add_bound_info): Add a context parameter.  Use add_scalar_info.
	(loc_list_from_tree): Add a context parameter.  Handle PLACEHOLDER_EXPR
	nodes for type-related expressions.  Likewise for base declarations.
	(loc_descriptor_from_tree): Add a context parameter.
	(subrange_type_die): Update calls to add_bound_info.
	(tls_mem_loc_descriptor): Likewise.
	(loc_list_for_address_of_addr_expr_of_indirect_ref): Add a context
	parameter.  Update calls to loc_list_from_tree.
	(add_subscript_info): Update calls to add_bound_info.
	(gen_array_type_die): Update calls to loc_list_from_tree and to
	add_bound_info.
	(descr_info_loc): Remove.
	(add_descr_info_field): Remove.
	(gen_descr_array_type_die): Switch add_descr_info_field calls into
	add_scalar_info/add_bound_info ones.
	(gen_subprogram_die): Update calls to loc_list_from_tree.
	(gen_variable_die): Likewise.
---
 gcc/dwarf2out.c |  569 ---
 1 file changed, 294 insertions(+), 275 deletions(-)

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 3f3bdbb..30f429e 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -2981,6 +2981,15 @@ static bool frame_pointer_fb_offset_valid;
 
 static vec base_types;
 
+/* Flags to represent a set of attribute classes for attributes that represent
+   a scalar value (bounds, pointers, ...).  */
+enum dw_scalar_form
+{
+  dw_scalar_form_constant = 0x01,
+  dw_scalar_form_exprloc = 0x02,
+  dw_scalar_form_reference = 0x04
+};
+
 /* Forward declarations for functions defined in this file.  */
 
 static int is_pseudo_reg (const_rtx);
@@ -3163,8 +3172,11 @@ static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
 	   enum var_init_status);
 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
 	enum var_init_status);
-static dw_loc_list_ref loc_list_from_tree (tree, int);
-static dw_loc_descr_ref loc_d

[PATCH, Pointer Bounds Checker 14/x] Passes [6/n] Instrument calls and returns

2014-10-08 Thread Ilya Enkovich
Hi,

This patch adds intrumentation of calls and returns into instrumentation pass.

Thanks,
Ilya
--
2014-10-08  Ilya Enkovich  

* tree-chkp.c (chkp_add_bounds_to_ret_stmt): New.
(chkp_replace_address_check_builtin): New.
(chkp_replace_extract_builtin): New.
(chkp_find_bounds_for_elem): New.
(chkp_add_bounds_to_call_stmt): New.
(chkp_instrument_function): Instrument rets and calls.


diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index bbb6459..6bbceb0 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -1047,6 +1047,29 @@ chkp_get_registered_bounds (tree ptr)
   return slot ? *slot : NULL_TREE;
 }
 
+/* Add bound retvals to return statement pointed by GSI.  */
+
+static void
+chkp_add_bounds_to_ret_stmt (gimple_stmt_iterator *gsi)
+{
+  gimple ret = gsi_stmt (*gsi);
+  tree retval = gimple_return_retval (ret);
+  tree ret_decl = DECL_RESULT (cfun->decl);
+  tree bounds;
+
+  if (!retval)
+return;
+
+  if (BOUNDED_P (ret_decl))
+{
+  bounds = chkp_find_bounds (retval, gsi);
+  bounds = chkp_maybe_copy_and_register_bounds (ret_decl, bounds);
+  gimple_return_set_retbnd (ret, bounds);
+}
+
+  update_stmt (ret);
+}
+
 /* Force OP to be suitable for using as an argument for call.
New statements (if any) go to SEQ.  */
 static tree
@@ -1169,6 +1192,64 @@ chkp_check_mem_access (tree first, tree last, tree 
bounds,
   chkp_check_upper (last, bounds, iter, location, dirflag);
 }
 
+/* Replace call to _bnd_chk_* pointed by GSI with
+   bndcu and bndcl calls.  DIRFLAG determines whether
+   check is for read or write.  */
+
+void
+chkp_replace_address_check_builtin (gimple_stmt_iterator *gsi,
+   tree dirflag)
+{
+  gimple_stmt_iterator call_iter = *gsi;
+  gimple call = gsi_stmt (*gsi);
+  tree fndecl = gimple_call_fndecl (call);
+  tree addr = gimple_call_arg (call, 0);
+  tree bounds = chkp_find_bounds (addr, gsi);
+
+  if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CHKP_CHECK_PTR_LBOUNDS
+  || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CHKP_CHECK_PTR_BOUNDS)
+chkp_check_lower (addr, bounds, *gsi, gimple_location (call), dirflag);
+
+  if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CHKP_CHECK_PTR_UBOUNDS)
+chkp_check_upper (addr, bounds, *gsi, gimple_location (call), dirflag);
+
+  if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CHKP_CHECK_PTR_BOUNDS)
+{
+  tree size = gimple_call_arg (call, 1);
+  addr = fold_build_pointer_plus (addr, size);
+  addr = fold_build_pointer_plus_hwi (addr, -1);
+  chkp_check_upper (addr, bounds, *gsi, gimple_location (call), dirflag);
+}
+
+  gsi_remove (&call_iter, true);
+}
+
+/* Replace call to _bnd_get_ptr_* pointed by GSI with
+   corresponding bounds extract call.  */
+
+void
+chkp_replace_extract_builtin (gimple_stmt_iterator *gsi)
+{
+  gimple call = gsi_stmt (*gsi);
+  tree fndecl = gimple_call_fndecl (call);
+  tree addr = gimple_call_arg (call, 0);
+  tree bounds = chkp_find_bounds (addr, gsi);
+  gimple extract;
+
+  if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CHKP_GET_PTR_LBOUND)
+fndecl = chkp_extract_lower_fndecl;
+  else if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CHKP_GET_PTR_UBOUND)
+fndecl = chkp_extract_upper_fndecl;
+  else
+gcc_unreachable ();
+
+  extract = gimple_build_call (fndecl, 1, bounds);
+  gimple_call_set_lhs (extract, gimple_call_lhs (call));
+  chkp_mark_stmt (extract);
+
+  gsi_replace (gsi, extract, false);
+}
+
 /* Return COMPONENT_REF accessing FIELD in OBJ.  */
 static tree
 chkp_build_component_ref (tree obj, tree field)
@@ -1247,6 +1328,82 @@ chkp_can_be_shared (tree t)
   return false;
 }
 
+/* Helper function for chkp_add_bounds_to_call_stmt.
+   Fill ALL_BOUNDS output array with created bounds.
+
+   OFFS is used for recursive calls and holds basic
+   offset of TYPE in outer structure in bits.
+
+   ITER points a position where bounds are searched.
+
+   ALL_BOUNDS[i] is filled with elem bounds if there
+   is a field in TYPE which has pointer type and offset
+   equal to i * POINTER_SIZE in bits.  */
+static void
+chkp_find_bounds_for_elem (tree elem, tree *all_bounds,
+  HOST_WIDE_INT offs,
+  gimple_stmt_iterator *iter)
+{
+  tree type = TREE_TYPE (elem);
+
+  if (BOUNDED_TYPE_P (type))
+{
+  if (!all_bounds[offs / POINTER_SIZE])
+   {
+ tree temp = make_temp_ssa_name (type, gimple_build_nop (), "");
+ gimple assign = gimple_build_assign (temp, elem);
+ gimple_stmt_iterator gsi;
+
+ gsi_insert_before (iter, assign, GSI_SAME_STMT);
+ gsi = gsi_for_stmt (assign);
+
+ all_bounds[offs / POINTER_SIZE] = chkp_find_bounds (temp, &gsi);
+   }
+}
+  else if (RECORD_OR_UNION_TYPE_P (type))
+{
+  tree field;
+
+  for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
+   if (TREE_CODE (field) == FIELD_DECL)
+ {
+   tree base = chkp_can_be_shared

[PATCH, Pointer Bounds Checker 14/x] Passes [7/n] Instrument params

2014-10-08 Thread Ilya Enkovich
Hi,

This patch adds bounds initialization for address taken input arguments.

Thanks,
Ilya
--
2014-10-08  Ilya Enkovich  

* tree-chkp.c (chkp_instrument_function): Store bounds for
address taken args.


diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index 6bbceb0..5443950 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -3758,6 +3758,51 @@ chkp_instrument_function (void)
   bb = next;
 }
   while (bb);
+
+  /* Some input params may have bounds and be address taken.  In this case
+ we should store incomping bounds into bounds table.  */
+  tree arg;
+  if (flag_chkp_store_bounds)
+for (arg = DECL_ARGUMENTS (cfun->decl); arg; arg = DECL_CHAIN (arg))
+  if (TREE_ADDRESSABLE (arg))
+   {
+ if (BOUNDED_P (arg))
+   {
+ tree bounds = chkp_get_next_bounds_parm (arg);
+ tree def_ptr = ssa_default_def (cfun, arg);
+ gimple_stmt_iterator iter
+   = gsi_start_bb (chkp_get_entry_block ());
+ chkp_build_bndstx (chkp_build_addr_expr (arg),
+def_ptr ? def_ptr : arg,
+bounds, &iter);
+
+ /* Skip bounds arg.  */
+ arg = TREE_CHAIN (arg);
+   }
+ else if (chkp_type_has_pointer (TREE_TYPE (arg)))
+   {
+ tree orig_arg = arg;
+ bitmap slots = chkp_find_bound_slots (TREE_TYPE (arg));
+ gimple_stmt_iterator iter
+   = gsi_start_bb (chkp_get_entry_block ());
+ bitmap_iterator bi;
+ unsigned bnd_no;
+
+ EXECUTE_IF_SET_IN_BITMAP (slots, 0, bnd_no, bi)
+   {
+ tree bounds = chkp_get_next_bounds_parm (arg);
+ HOST_WIDE_INT offs = bnd_no * POINTER_SIZE / BITS_PER_UNIT;
+ tree addr = chkp_build_addr_expr (orig_arg);
+ tree ptr = build2 (MEM_REF, ptr_type_node, addr,
+build_int_cst (ptr_type_node, offs));
+ chkp_build_bndstx (chkp_build_addr_expr (ptr), ptr,
+bounds, &iter);
+
+ arg = DECL_CHAIN (arg);
+   }
+ BITMAP_FREE (slots);
+   }
+   }
 }
 
 /* Initialize pass.  */


[PATCH, Pointer Bounds Checker 14/x] Passes [8/n] Remove useless builtin calls

2014-10-08 Thread Ilya Enkovich
Hi,

This patch adds removal of user calls to chkp builtins which become useless 
after instrumentation.

Thanks,
Ilya
--
2014-10-08  Ilya Enkovich  

* tree-chkp.c (chkp_remove_useless_builtins): New.
(chkp_execute): Remove useless calls to Pointer Bounds
Checker builtins.


diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index 5443950..b424af8 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -3805,6 +3805,49 @@ chkp_instrument_function (void)
}
 }
 
+/* Find init/null/copy_ptr_bounds calls and replace them
+   with assignments.  It should allow better code
+   optimization.  */
+
+static void
+chkp_remove_useless_builtins ()
+{
+  basic_block bb, next;
+  gimple_stmt_iterator gsi;
+
+  bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb;
+  do
+{
+  next = bb->next_bb;
+  for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
+{
+  gimple stmt = gsi_stmt (gsi);
+ tree fndecl;
+ enum built_in_function fcode;
+
+ /* Find builtins returning first arg and replace
+them with assignments.  */
+ if (gimple_code (stmt) == GIMPLE_CALL
+ && (fndecl = gimple_call_fndecl (stmt))
+ && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
+ && (fcode = DECL_FUNCTION_CODE (fndecl))
+ && (fcode == BUILT_IN_CHKP_INIT_PTR_BOUNDS
+ || fcode == BUILT_IN_CHKP_NULL_PTR_BOUNDS
+ || fcode == BUILT_IN_CHKP_COPY_PTR_BOUNDS
+ || fcode == BUILT_IN_CHKP_SET_PTR_BOUNDS))
+   {
+ tree res = gimple_call_arg (stmt, 0);
+ if (!update_call_from_tree (&gsi, res))
+   gimplify_and_update_call_from_tree (&gsi, res);
+ stmt = gsi_stmt (gsi);
+ update_stmt (stmt);
+   }
+}
+  bb = next;
+}
+  while (bb);
+}
+
 /* Initialize pass.  */
 static void
 chkp_init (void)
@@ -3872,6 +3915,8 @@ chkp_execute (void)
 
   chkp_instrument_function ();
 
+  chkp_remove_useless_builtins ();
+
   chkp_function_mark_instrumented (cfun->decl);
 
   chkp_fix_cfg ();


[PATCH, Pointer Bounds Checker 14/x] Passes [9/n] Static constructors

2014-10-08 Thread Ilya Enkovich
Hi,

This patch introduces functions to handle static pointers and static bounds.

Thanks,
Ilya
--
2014-10-08  Ilya Enkovich  

* tree-chkp.c (MAX_STMTS_IN_STATIC_CHKP_CTOR): New.
(chkp_ctor_stmt_list): New.
(chkp_register_var_initializer): New.
(chkp_add_modification_to_stmt_list): New.
(chkp_output_static_bounds): New.
(chkp_finish_file): New.
(chkp_instrument_function): Remove useless statements
from static bounds constructors.
* tree-chkp.h (chkp_register_var_initializer): New.
(chkp_finish_file): New.


diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index b424af8..4b5a773 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -394,6 +394,27 @@ static bool in_chkp_pass;
 #define CHKP_ZERO_BOUNDS_VAR_NAME "__chkp_zero_bounds"
 #define CHKP_NONE_BOUNDS_VAR_NAME "__chkp_none_bounds"
 
+/* Static checker constructors may become very large and their
+   compilation with optimization may take too much time.
+   Therefore we put a limit to number of statements in one
+   construcor.  Tests with 100 000 statically initialized
+   pointers showed following compilation times on Sandy Bridge
+   server (used -O2):
+   limit100 => ~18 sec.
+   limit300 => ~22 sec.
+   limit   1000 => ~30 sec.
+   limit   3000 => ~49 sec.
+   limit   5000 => ~55 sec.
+   limit  1 => ~76 sec.
+   limit 10 => ~532 sec.  */
+#define MAX_STMTS_IN_STATIC_CHKP_CTOR (optimize > 0 ? 5000 : 10)
+
+struct chkp_ctor_stmt_list
+{
+  tree stmts;
+  int avail;
+};
+
 /* Return 1 if function FNDECL is instrumented by Pointer
Bounds Checker.  */
 bool
@@ -871,6 +892,53 @@ chkp_set_bounds (tree node, tree val)
   chkp_bounds_map->put (node, val);
 }
 
+/* Check if statically initialized variable VAR require
+   static bounds initilization.  If VAR is added into
+   bounds initlization list then 1 is returned. Otherwise
+   return 0.  */
+extern bool
+chkp_register_var_initializer (tree var)
+{
+  if (!flag_check_pointer_bounds)
+return false;
+
+  gcc_assert (TREE_CODE (var) == VAR_DECL);
+  gcc_assert (DECL_INITIAL (var)
+ && DECL_INITIAL (var) != error_mark_node);
+
+  if (TREE_STATIC (var)
+  && chkp_type_has_pointer (TREE_TYPE (var)))
+{
+  varpool_node::get_create (var)->need_bounds_init = 1;
+  return true;
+}
+
+  return false;
+}
+
+/* Helper function for chkp_finish_file.
+
+   Add new modification statement (RHS is assigned to LHS)
+   into list of static initilizer statementes (passed in ARG).
+   If statements list becomes too big, emit checker constructor
+   and start the new one.  */
+static void
+chkp_add_modification_to_stmt_list (tree lhs,
+   tree rhs,
+   void *arg)
+{
+  struct chkp_ctor_stmt_list *stmts = (struct chkp_ctor_stmt_list *)arg;
+  tree modify;
+
+  if (!useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (rhs)))
+rhs = build1 (CONVERT_EXPR, TREE_TYPE (lhs), rhs);
+
+  modify = build2 (MODIFY_EXPR, TREE_TYPE (lhs), lhs, rhs);
+  append_to_statement_list (modify, &stmts->stmts);
+
+  stmts->avail--;
+}
+
 /* Build and return ADDR_EXPR for specified object OBJ.  */
 static tree
 chkp_build_addr_expr (tree obj)
@@ -880,6 +948,64 @@ chkp_build_addr_expr (tree obj)
 : build_fold_addr_expr (obj);
 }
 
+/* Helper function for chkp_finish_file.
+   Initialize bound variable BND_VAR with bounds of variable
+   VAR to statements list STMTS.  If statements list becomes
+   too big, emit checker constructor and start the new one.  */
+static void
+chkp_output_static_bounds (tree bnd_var, tree var,
+  struct chkp_ctor_stmt_list *stmts)
+{
+  tree lb, ub, size;
+
+  if (TREE_CODE (var) == STRING_CST)
+{
+  lb = build1 (CONVERT_EXPR, size_type_node, chkp_build_addr_expr (var));
+  size = build_int_cst (size_type_node, TREE_STRING_LENGTH (var) - 1);
+}
+  else if (DECL_SIZE (var)
+  && !chkp_variable_size_type (TREE_TYPE (var)))
+{
+  /* Compute bounds using statically known size.  */
+  lb = build1 (CONVERT_EXPR, size_type_node, chkp_build_addr_expr (var));
+  size = size_binop (MINUS_EXPR, DECL_SIZE_UNIT (var), size_one_node);
+}
+  else
+{
+  /* Compute bounds using dynamic size.  */
+  tree call;
+
+  lb = build1 (CONVERT_EXPR, size_type_node, chkp_build_addr_expr (var));
+  call = build1 (ADDR_EXPR,
+build_pointer_type (TREE_TYPE (chkp_sizeof_fndecl)),
+chkp_sizeof_fndecl);
+  size = build_call_nary (TREE_TYPE (TREE_TYPE (chkp_sizeof_fndecl)),
+ call, 1, var);
+
+  if (flag_chkp_zero_dynamic_size_as_infinite)
+   {
+ tree max_size, cond;
+
+ max_size = build2 (MINUS_EXPR, size_type_node, size_zero_node, lb);
+ cond = build2 (NE_EXPR, boolean_type_node, size, size_zero_node);
+ size = build3 (COND_EXPR, size_type_node, con

[PATCH, Pointer Bounds Checker 14/x] Passes [10/n] Stores handler

2014-10-08 Thread Ilya Enkovich
Hi,

This patch adds an assignment processing function which is used by lnliner for 
newly generated stores.

Thanks,
Ilya
--
2014-10-08  Ilya Enkovich  

* tree-chkp.c (chkp_copy_bounds_for_assign): New.
* tree-chkp.h (chkp_copy_bounds_for_assign): New.


diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index 4b5a773..6f73699 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -3781,6 +3781,43 @@ chkp_process_stmt (gimple_stmt_iterator *iter, tree node,
 }
 }
 
+/* Add code to copy bounds for all pointers copied
+   in ASSIGN created during inline of EDGE.  */
+void
+chkp_copy_bounds_for_assign (gimple assign, struct cgraph_edge *edge)
+{
+  tree lhs = gimple_assign_lhs (assign);
+  tree rhs = gimple_assign_rhs1 (assign);
+  gimple_stmt_iterator iter = gsi_for_stmt (assign);
+
+  if (!flag_chkp_store_bounds)
+return;
+
+  chkp_walk_pointer_assignments (lhs, rhs, &iter, chkp_copy_bounds_for_elem);
+
+  /* We should create edges for all created calls to bndldx and bndstx.  */
+  while (gsi_stmt (iter) != assign)
+{
+  gimple stmt = gsi_stmt (iter);
+  if (gimple_code (stmt) == GIMPLE_CALL)
+   {
+ tree fndecl = gimple_call_fndecl (stmt);
+ struct cgraph_node *callee = cgraph_node::get_create (fndecl);
+ struct cgraph_edge *new_edge;
+
+ gcc_assert (fndecl == chkp_bndstx_fndecl
+ || fndecl == chkp_bndldx_fndecl
+ || fndecl == chkp_ret_bnd_fndecl);
+
+ new_edge = edge->caller->create_edge (callee, stmt, edge->count,
+   edge->frequency);
+ new_edge->frequency = compute_call_stmt_bb_frequency
+   (edge->caller->decl, gimple_bb (stmt));
+   }
+  gsi_prev (&iter);
+}
+}
+
 /* Some code transformation made during instrumentation pass
may put code into inconsistent state.  Here we find and fix
such flaws.  */
diff --git a/gcc/tree-chkp.h b/gcc/tree-chkp.h
index 81306ba..9a3c55d 100644
--- a/gcc/tree-chkp.h
+++ b/gcc/tree-chkp.h
@@ -46,6 +46,8 @@ extern void chkp_build_bndstx (tree addr, tree ptr, tree 
bounds,
 extern gimple chkp_retbnd_call_by_val (tree val);
 extern bool chkp_function_instrumented_p (tree fndecl);
 extern void chkp_function_mark_instrumented (tree fndecl);
+extern void chkp_copy_bounds_for_assign (gimple assign,
+struct cgraph_edge *edge);
 extern bool chkp_gimple_call_builtin_p (gimple call,
enum built_in_function code);
 extern void chkp_expand_bounds_reset_for_mem (tree mem, tree ptr);


[PATCH, Pointer Bounds Checker 14/x] Passes [11/n] Optimization helpers

2014-10-08 Thread Ilya Enkovich
Hi,

This patch introduces structures and manipulation functions used by simple 
checker optimizations.  Structures are used to hold checks information - type 
of check and checked address in a polinomial form.

Thanks,
Ilya
--
2014-10-08  Ilya Enkovich  

* tree-chkp.c (check_type): New.
(pol_item): New.
(address_t): New.
(check_info): New.
(bb_checks): New.
(chkp_pol_item_compare): New.
(chkp_pol_find): New.
(chkp_extend_const): New.
(chkp_add_addr_item): New.
(chkp_sub_addr_item): New.
(chkp_add_addr_addr): New.
(chkp_sub_addr_addr): New.
(chkp_mult_addr): New.
(chkp_is_constant_addr): New.
(chkp_print_addr): New.
(chkp_collect_addr_value): New.
(chkp_collect_value): New.
(chkp_fill_check_info): New.


diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index 6f73699..aae9681 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -328,10 +328,47 @@ along with GCC; see the file COPYING3.  If not see
 
 typedef void (*assign_handler)(tree, tree, void *);
 
+enum check_type
+{
+  CHECK_LOWER_BOUND,
+  CHECK_UPPER_BOUND
+};
+
+struct pol_item
+{
+  tree cst;
+  tree var;
+};
+
+struct address_t
+{
+  vec pol;
+};
+
+/* Structure to hold check informtation.  */
+struct check_info
+{
+  /* Type of the check.  */
+  check_type type;
+  /* Address used for the check.  */
+  address_t addr;
+  /* Bounds used for the check.  */
+  tree bounds;
+  /* Check statement.  Can be NULL for removed checks.  */
+  gimple stmt;
+};
+
+/* Structure to hold checks information for BB.  */
+struct bb_checks
+{
+  vec checks;
+};
+
 static tree chkp_get_zero_bounds ();
 static tree chkp_find_bounds (tree ptr, gimple_stmt_iterator *iter);
 static tree chkp_find_bounds_loaded (tree ptr, tree ptr_src,
 gimple_stmt_iterator *iter);
+static void chkp_collect_value (tree ssa_name, address_t &res);
 static void chkp_parse_array_and_component_ref (tree node, tree *ptr,
tree *elt, bool *safe,
bool *bitfield,
@@ -4179,6 +4216,357 @@ chkp_gate (void)
 || lookup_attribute ("chkp ctor", DECL_ATTRIBUTES (cfun->decl));
 }
 
+/* Comparator for pol_item structures I1 and I2 to be used
+   to find items with equal var.  Also used for polynomial
+   sorting.  */
+int
+chkp_pol_item_compare (const void *i1, const void *i2)
+{
+  const struct pol_item *p1 = (const struct pol_item *)i1;
+  const struct pol_item *p2 = (const struct pol_item *)i2;
+
+  if (p1->var == p2->var)
+return 0;
+  else if (p1->var > p2->var)
+return 1;
+  else
+return -1;
+}
+
+/* Find plynomial item in ADDR with var equal to VAR
+   and return its index.  Return -1 if item was not
+   found.  */
+int
+chkp_pol_find (address_t &addr, tree var)
+{
+  int left = 0;
+  int right = addr.pol.length () - 1;
+  int n;
+
+  while (right >= left)
+{
+  n = (left + right) / 2;
+
+  if (addr.pol[n].var == var
+ || (var && addr.pol[n].var
+ && TREE_CODE (var) == ADDR_EXPR
+ && TREE_CODE (addr.pol[n].var) == ADDR_EXPR
+ && TREE_OPERAND (var, 0) == TREE_OPERAND (addr.pol[n].var, 0)))
+   return n;
+  else if (addr.pol[n].var > var)
+   right = n - 1;
+  else
+   left = n + 1;
+}
+
+  return -1;
+}
+
+/* Return constant CST extended to size type.  */
+tree
+chkp_extend_const (tree cst)
+{
+  if (TYPE_PRECISION (TREE_TYPE (cst)) < TYPE_PRECISION (size_type_node))
+return build_int_cst_type (size_type_node, tree_to_shwi (cst));
+
+  return cst;
+}
+
+/* Add polynomial item CST * VAR to ADDR.  */
+void
+chkp_add_addr_item (address_t &addr, tree cst, tree var)
+{
+  int n = chkp_pol_find (addr, var);
+
+  cst = chkp_extend_const (cst);
+
+  if (n < 0)
+{
+  struct pol_item item;
+  item.cst = cst;
+  item.var = var;
+
+  addr.pol.safe_push (item);
+  addr.pol.qsort (&chkp_pol_item_compare);
+}
+  else
+{
+  addr.pol[n].cst = fold_build2 (PLUS_EXPR, TREE_TYPE (addr.pol[n].cst),
+addr.pol[n].cst, cst);
+  if (TREE_CODE (addr.pol[n].cst) == INTEGER_CST
+ && integer_zerop (addr.pol[n].cst))
+   addr.pol.ordered_remove (n);
+}
+}
+
+/* Subtract polynomial item CST * VAR from ADDR.  */
+void
+chkp_sub_addr_item (address_t &addr, tree cst, tree var)
+{
+  int n = chkp_pol_find (addr, var);
+
+  cst = chkp_extend_const (cst);
+
+  if (n < 0)
+{
+  struct pol_item item;
+  item.cst = fold_build2 (MINUS_EXPR, TREE_TYPE (cst),
+ integer_zero_node, cst);
+  item.var = var;
+
+  addr.pol.safe_push (item);
+  addr.pol.qsort (&chkp_pol_item_compare);
+}
+  else
+{
+  addr.pol[n].cst = fold_build2 (MINUS_EXPR, TREE_TYPE (addr.pol[n].cst),
+addr.pol[n].cst, cs

[PATCH, Pointer Bounds Checker 14/x] Passes [12/n] Optimize string functions

2014-10-08 Thread Ilya Enkovich
Hi,

This patch introduces simple optimization of string function calls using 
variants with no checks and/or bounds copy when possible.

Thanks,
Ilya
--
2014-10-08  Ilya Enkovich  

* tree-chkp.c (check_infos): New.
(chkp_get_nobnd_fndecl): New.
(chkp_get_nochk_fndecl): New.
(chkp_optimize_string_function_calls): New.
(chkp_opt_init): New.
(chkp_opt_fini): New.
(chkp_opt_execute): New.
(chkp_opt_gate): New.
(pass_data_chkp_opt): New.
(pass_chkp_opt): New.
(make_pass_chkp_opt): New.


diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index aae9681..5230d14 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -399,6 +399,8 @@ static void chkp_parse_array_and_component_ref (tree node, 
tree *ptr,
 #define chkp_extract_upper_fndecl \
   (targetm.builtin_chkp_function (BUILT_IN_CHKP_EXTRACT_UPPER))
 
+static vec check_infos = vNULL;
+
 static GTY (()) tree chkp_uintptr_type;
 
 static GTY (()) tree chkp_zero_bounds_var;
@@ -4567,8 +4569,315 @@ chkp_fill_check_info (gimple stmt, struct check_info 
*ci)
   ci->stmt = stmt;
 }
 
+/* Return fast version of string function FNCODE.  */
+tree
+chkp_get_nobnd_fndecl (enum built_in_function fncode)
+{
+  /* Check if we are allowed to use fast string functions.  */
+  if (!flag_chkp_use_fast_string_functions)
+return NULL_TREE;
+
+  switch (fncode)
+{
+case BUILT_IN_MEMCPY:
+  return builtin_decl_implicit (BUILT_IN_CHKP_MEMCPY_NOBND);
+
+case BUILT_IN_MEMPCPY:
+  return builtin_decl_implicit (BUILT_IN_CHKP_MEMPCPY_NOBND);
+
+case BUILT_IN_MEMMOVE:
+  return builtin_decl_implicit (BUILT_IN_CHKP_MEMMOVE_NOBND);
+
+case BUILT_IN_MEMSET:
+  return builtin_decl_implicit (BUILT_IN_CHKP_MEMSET_NOBND);
+
+case BUILT_IN_CHKP_MEMCPY_NOCHK:
+  return builtin_decl_implicit (BUILT_IN_CHKP_MEMCPY_NOBND_NOCHK);
+
+case BUILT_IN_CHKP_MEMPCPY_NOCHK:
+  return builtin_decl_implicit (BUILT_IN_CHKP_MEMPCPY_NOBND_NOCHK);
+
+case BUILT_IN_CHKP_MEMMOVE_NOCHK:
+  return builtin_decl_implicit (BUILT_IN_CHKP_MEMMOVE_NOBND_NOCHK);
+
+case BUILT_IN_CHKP_MEMSET_NOCHK:
+  return builtin_decl_implicit (BUILT_IN_CHKP_MEMSET_NOBND_NOCHK);
+
+default:
+  return NULL_TREE;
+}
+}
+
+
+/* Return no-check version of string function FNCODE.  */
+tree
+chkp_get_nochk_fndecl (enum built_in_function fncode)
+{
+  /* Check if we are allowed to use fast string functions.  */
+  if (!flag_chkp_use_nochk_string_functions)
+return NULL_TREE;
+
+  switch (fncode)
+{
+case BUILT_IN_MEMCPY:
+  return builtin_decl_implicit (BUILT_IN_CHKP_MEMCPY_NOCHK);
+
+case BUILT_IN_MEMPCPY:
+  return builtin_decl_implicit (BUILT_IN_CHKP_MEMPCPY_NOCHK);
+
+case BUILT_IN_MEMMOVE:
+  return builtin_decl_implicit (BUILT_IN_CHKP_MEMMOVE_NOCHK);
+
+case BUILT_IN_MEMSET:
+  return builtin_decl_implicit (BUILT_IN_CHKP_MEMSET_NOCHK);
+
+case BUILT_IN_CHKP_MEMCPY_NOBND:
+  return builtin_decl_implicit (BUILT_IN_CHKP_MEMCPY_NOBND_NOCHK);
+
+case BUILT_IN_CHKP_MEMPCPY_NOBND:
+  return builtin_decl_implicit (BUILT_IN_CHKP_MEMPCPY_NOBND_NOCHK);
+
+case BUILT_IN_CHKP_MEMMOVE_NOBND:
+  return builtin_decl_implicit (BUILT_IN_CHKP_MEMMOVE_NOBND_NOCHK);
+
+case BUILT_IN_CHKP_MEMSET_NOBND:
+  return builtin_decl_implicit (BUILT_IN_CHKP_MEMSET_NOBND_NOCHK);
+
+default:
+  return NULL_TREE;
+}
+}
+
+/* Find memcpy, mempcpy, memmove and memset calls, perform
+   checks before call and then call no_chk version of
+   functions.  We do it on O2 to enable inlining of these
+   functions during expand.
+
+   Also try to find memcpy, mempcpy, memmove and memset calls
+   which are known to not write pointers to memory and use
+   faster function versions for them.  */
+void
+chkp_optimize_string_function_calls (void)
+{
+  basic_block bb;
+
+  if (dump_file && (dump_flags & TDF_DETAILS))
+fprintf (dump_file, "Searching for replacable string function calls...\n");
+
+  FOR_EACH_BB_FN (bb, cfun)
+{
+  gimple_stmt_iterator i;
+
+  for (i = gsi_start_bb (bb); !gsi_end_p (i); gsi_next (&i))
+{
+ gimple stmt = gsi_stmt (i);
+ tree fndecl;
+
+ if (gimple_code (stmt) != GIMPLE_CALL
+ || !gimple_call_with_bounds_p (stmt))
+   continue;
+
+ fndecl = gimple_call_fndecl (stmt);
+
+ if (!fndecl || DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL)
+   continue;
+
+ if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_MEMCPY
+ || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_MEMPCPY
+ || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_MEMMOVE
+ || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_MEMSET)
+   {
+ tree dst = gimple_call_arg (stmt, 0);
+ tree dst_bnd = gimple_call_arg (stmt, 1);
+ bool is_memset = DECL_FUNCTION_CODE (fndecl) == BUILT_IN_MEMSET;
+ tree size 

[PATCH, Pointer Bounds Checker 14/x] Passes [13/n] Optimize bounds intersections

2014-10-08 Thread Ilya Enkovich
Hi,

This patch adds removal of unnecessary intersections into checker optimizations.

Thanks,
Ilya
--
2014-10-08  Ilya Enkovich  

* tree-chkp.c (chkp_release_check_info): New.
(chkp_init_check_info): New.
(chkp_gather_checks_info): New.
(chkp_get_check_result): New.
(chkp_use_outer_bounds_if_possible): New.
(chkp_remove_excess_intersections): New.
(chkp_opt_execute): Run intersections removal
algorithm.


diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index 5230d14..c9b616b 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -4569,6 +4569,348 @@ chkp_fill_check_info (gimple stmt, struct check_info 
*ci)
   ci->stmt = stmt;
 }
 
+/* Release structures holding check information
+   for current function.  */
+void
+chkp_release_check_info (void)
+{
+  unsigned int n, m;
+
+  if (check_infos.exists ())
+{
+  for (n = 0; n < check_infos.length (); n++)
+   {
+ for (m = 0; m < check_infos[n].checks.length (); m++)
+   if (check_infos[n].checks[m].addr.pol.exists ())
+ check_infos[n].checks[m].addr.pol.release ();
+ check_infos[n].checks.release ();
+   }
+  check_infos.release ();
+}
+}
+
+/* Create structures to hold check information
+   for current function.  */
+void
+chkp_init_check_info (void)
+{
+  struct bb_checks empty_bbc;
+  int n;
+
+  empty_bbc.checks = vNULL;
+
+  chkp_release_check_info ();
+
+  check_infos.create (last_basic_block_for_fn (cfun));
+  for (n = 0; n < last_basic_block_for_fn (cfun); n++)
+{
+  check_infos.safe_push (empty_bbc);
+  check_infos.last ().checks.create (0);
+}
+}
+
+/* Find all checks in current function and store info about them
+   in check_infos.  */
+void
+chkp_gather_checks_info (void)
+{
+  basic_block bb;
+  gimple_stmt_iterator i;
+
+  if (dump_file && (dump_flags & TDF_DETAILS))
+fprintf (dump_file, "Gathering information about checks...\n");
+
+  chkp_init_check_info ();
+
+  FOR_EACH_BB_FN (bb, cfun)
+{
+  struct bb_checks *bbc = &check_infos[bb->index];
+
+  if (dump_file && (dump_flags & TDF_DETAILS))
+   fprintf (dump_file, "Searching checks in BB%d...\n", bb->index);
+
+  for (i = gsi_start_bb (bb); !gsi_end_p (i); gsi_next (&i))
+{
+ gimple stmt = gsi_stmt (i);
+
+ if (gimple_code (stmt) != GIMPLE_CALL)
+   continue;
+
+ if (gimple_call_fndecl (stmt) == chkp_checkl_fndecl
+ || gimple_call_fndecl (stmt) == chkp_checku_fndecl)
+   {
+ struct check_info ci;
+
+ chkp_fill_check_info (stmt, &ci);
+ bbc->checks.safe_push (ci);
+
+ if (dump_file && (dump_flags & TDF_DETAILS))
+   {
+ fprintf (dump_file, "Adding check information:\n");
+ fprintf (dump_file, "  bounds: ");
+ print_generic_expr (dump_file, ci.bounds, 0);
+ fprintf (dump_file, "\n  address: ");
+ chkp_print_addr (ci.addr);
+ fprintf (dump_file, "\n  check: ");
+ print_gimple_stmt (dump_file, stmt, 0, 0);
+   }
+   }
+   }
+}
+}
+
+/* Return 1 if check CI against BOUNDS always pass,
+   -1 if check CI against BOUNDS always fails and
+   0 if we cannot compute check result.  */
+int
+chkp_get_check_result (struct check_info *ci, tree bounds)
+{
+  gimple bnd_def;
+  address_t bound_val;
+  int sign, res = 0;
+
+  if (dump_file && (dump_flags & TDF_DETAILS))
+{
+  fprintf (dump_file, "Trying to compute result of the check\n");
+  fprintf (dump_file, "  check: ");
+  print_gimple_stmt (dump_file, ci->stmt, 0, 0);
+  fprintf (dump_file, "  address: ");
+  chkp_print_addr (ci->addr);
+  fprintf (dump_file, "\n  bounds: ");
+  print_generic_expr (dump_file, bounds, 0);
+  fprintf (dump_file, "\n");
+}
+
+  if (TREE_CODE (bounds) != SSA_NAME)
+{
+  if (dump_file && (dump_flags & TDF_DETAILS))
+   fprintf (dump_file, "  result: bounds tree code is not ssa_name\n");
+  return 0;
+}
+
+  if (bounds == zero_bounds)
+{
+  if (dump_file && (dump_flags & TDF_DETAILS))
+   fprintf (dump_file, "  result: always pass with zero bounds\n");
+  return 1;
+}
+
+  if (bounds == none_bounds)
+{
+  if (dump_file && (dump_flags & TDF_DETAILS))
+   fprintf (dump_file, "  result: always fails with none bounds\n");
+  return -1;
+}
+
+  bnd_def = SSA_NAME_DEF_STMT (bounds);
+  /* Currently we handle cases when bounds are result of bndmk
+ or loaded static bounds var.  */
+  if (gimple_code (bnd_def) == GIMPLE_CALL
+  && gimple_call_fndecl (bnd_def) == chkp_bndmk_fndecl)
+{
+  bound_val.pol.create (0);
+  chkp_collect_value (gimple_call_arg (bnd_def, 0), bound_val);
+  if (ci->type == CHECK_UPPER_BOUND)
+   {
+ address_t size_val;
+ size_val.pol.create (0);
+ 

[PATCH, Pointer Bounds Checker 14/x] Passes [14/n] Optimize constant checks

2014-10-08 Thread Ilya Enkovich
Hi,

This patch adds a removal of checks known to always pass into checker 
optimization.

Thanks,
Ilya
--
2014-10-08  Ilya Enkovich  

* tree-chkp.c (chkp_remove_check_if_pass): New.
(chkp_remove_constant_checks): New.
(chkp_opt_execute): Run constant check removal
algorithm.


diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index c9b616b..ade546b 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -4828,6 +4828,46 @@ chkp_get_check_result (struct check_info *ci, tree 
bounds)
   return res;
 }
 
+/* Try to compare bounds value and address value
+   used in the check CI.  If we can prove that check
+   always pass then remove it.  */
+void
+chkp_remove_check_if_pass (struct check_info *ci)
+{
+  int result = 0;
+
+  if (dump_file && (dump_flags & TDF_DETAILS))
+{
+  fprintf (dump_file, "Trying to remove check: ");
+  print_gimple_stmt (dump_file, ci->stmt, 0, 0);
+}
+
+  result = chkp_get_check_result (ci, ci->bounds);
+
+  if (result == 1)
+{
+  gimple_stmt_iterator i = gsi_for_stmt (ci->stmt);
+
+  if (dump_file && (dump_flags & TDF_DETAILS))
+   fprintf (dump_file, "  action: delete check (always pass)\n");
+
+  gsi_remove (&i, true);
+  unlink_stmt_vdef (ci->stmt);
+  release_defs (ci->stmt);
+  ci->stmt = NULL;
+}
+  else if (result == -1)
+{
+  if (dump_file && (dump_flags & TDF_DETAILS))
+   fprintf (dump_file, "  action: keep check (always fail)\n");
+}
+  else if (result == 0)
+{
+  if (dump_file && (dump_flags & TDF_DETAILS))
+   fprintf (dump_file, "  action: keep check (cannot compute result)\n");
+}
+}
+
 /* For bounds used in CI check if bounds are produced by
intersection and we may use outer bounds instead.  If
transformation is possible then fix check statement and
@@ -4911,6 +4951,27 @@ chkp_remove_excess_intersections (void)
 }
 }
 
+/*  Try to remove all checks which are known to alwyas pass.  */
+void
+chkp_remove_constant_checks (void)
+{
+  basic_block bb;
+
+  if (dump_file && (dump_flags & TDF_DETAILS))
+fprintf (dump_file, "Searching for redundant checks...\n");
+
+  FOR_EACH_BB_FN (bb, cfun)
+{
+  struct bb_checks *bbc = &check_infos[bb->index];
+  unsigned int no;
+
+  /* Iterate throw all found checks in BB.  */
+  for (no = 0; no < bbc->checks.length (); no++)
+   if (bbc->checks[no].stmt)
+ chkp_remove_check_if_pass (&bbc->checks[no]);
+}
+}
+
 /* Return fast version of string function FNCODE.  */
 tree
 chkp_get_nobnd_fndecl (enum built_in_function fncode)
@@ -5194,6 +5255,8 @@ chkp_opt_execute (void)
 
   chkp_remove_excess_intersections ();
 
+  chkp_remove_constant_checks ();
+
   chkp_release_check_info ();
 
   chkp_opt_fini ();


[PATCH, Pointer Bounds Checker 14/x] Passes [15/n] Optimize redundant checks

2014-10-08 Thread Ilya Enkovich
Hi,

This patch adds removal of redundant (covered by other) checks into checker 
optimization.

Thanks,
Ilya
--
2014-10-08  Ilya Enkovich  

* tree-chkp.c (chkp_compare_checks): New.
(chkp_remove_redundant_checks): New.
(chkp_opt_execute): Run redundant checks removal
algorithm.


diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index ade546b..37ab729 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -4972,6 +4972,211 @@ chkp_remove_constant_checks (void)
 }
 }
 
+/* Compare two checks CI1 and CI2 to find redundant one.
+   CI1 is known to dominate CI2.  POSTDOM indicated if
+   CI2 postdominateds CI1.
+
+   Few conditions are checked to find redundant check:
+ 1.  Checks has the same type
+ 2.  Checks use the same bounds
+ 3.  One check fail means other check fail
+ 4.  Stronger check is always executed if weaker one is executed
+
+   If redundant check is found it is removed. If removed check is CI1
+   then CI2 is moved to CI1's position to avoid bound violation happened
+   before check is executed.  */
+void
+chkp_compare_checks (struct check_info *ci1,
+   struct check_info *ci2,
+   bool postdom)
+{
+  address_t delta;
+  int sign;
+
+  if (ci1->type != ci2->type)
+return;
+
+  if (ci1->bounds != ci2->bounds)
+return;
+
+  if (dump_file && (dump_flags & TDF_DETAILS))
+{
+  fprintf (dump_file, "  Comparing checks...\n");
+  fprintf (dump_file, "First check: ");
+  print_gimple_stmt (dump_file, ci1->stmt, 0, 0);
+  fprintf (dump_file, "Second check: ");
+  print_gimple_stmt (dump_file, ci2->stmt, 0, 0);
+}
+
+  delta.pol = ci1->addr.pol.copy ();
+  chkp_sub_addr_addr (delta, ci2->addr);
+
+  if (dump_file && (dump_flags & TDF_DETAILS))
+{
+  fprintf (dump_file, "Delta: ");
+  chkp_print_addr (delta);
+  fprintf (dump_file, "\n");
+}
+
+  if (!chkp_is_constant_addr (delta, &sign))
+{
+  if (dump_file && (dump_flags & TDF_DETAILS))
+   fprintf (dump_file, "Action: skip (delta is not constant)\n");
+}
+  else
+{
+  if (sign)
+   {
+ if ((sign > 0 && ci1->type == CHECK_UPPER_BOUND)
+ || (sign < 0 && ci1->type == CHECK_LOWER_BOUND))
+   {
+ gimple_stmt_iterator i = gsi_for_stmt (ci2->stmt);
+
+ if (dump_file && (dump_flags & TDF_DETAILS))
+   fprintf (dump_file, "Action: delete the second check\n");
+
+ gsi_remove (&i, true);
+ unlink_stmt_vdef (ci2->stmt);
+ release_defs (ci2->stmt);
+ ci2->stmt = NULL;
+   }
+ else if (postdom)
+   {
+ gimple_stmt_iterator i = gsi_for_stmt (ci2->stmt);
+ gimple_seq seq = NULL;
+ tree addr = gimple_call_arg (ci1->stmt, 0);
+ unsigned int n;
+
+ if (dump_file && (dump_flags & TDF_DETAILS))
+   fprintf (dump_file, "Action: replace the first "
+"check with the second one\n");
+
+ gsi_remove (&i, true);
+ unlink_stmt_vdef (ci2->stmt);
+ release_defs (ci2->stmt);
+ ci2->stmt = NULL;
+
+ for (n = 0; n < delta.pol.length (); n++)
+   if (delta.pol[n].var == NULL)
+ {
+   tree tmp = fold_build2 (MINUS_EXPR,
+   TREE_TYPE (delta.pol[n].cst),
+   integer_zero_node,
+   delta.pol[n].cst);
+   addr = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (addr),
+   addr, convert_to_ptrofftype (tmp));
+ }
+   else if (integer_onep (delta.pol[n].cst))
+ {
+   tree tmp = fold_build2 (MINUS_EXPR,
+   TREE_TYPE (delta.pol[n].var),
+   integer_zero_node,
+   delta.pol[n].var);
+   addr = build2 (POINTER_PLUS_EXPR, TREE_TYPE (addr),
+  addr, convert_to_ptrofftype (tmp));
+ }
+   else if (tree_int_cst_compare (delta.pol[n].cst,
+  integer_minus_one_node) == 0)
+ addr = build2 (POINTER_PLUS_EXPR, TREE_TYPE (addr),
+addr, convert_to_ptrofftype 
(delta.pol[n].var));
+   else
+ {
+   tree tmp = fold_build2 (MULT_EXPR,
+   TREE_TYPE (delta.pol[n].var),
+   delta.pol[n].var,
+   delta.pol[n].cst);
+   tmp = fold_build2 (MINUS_EXPR, TREE_TYPE (tmp),
+  integer_zero_no

[PATCH, Pointer Bounds Checker 14/x] Passes [16/n] Reduce bounds lifetime

2014-10-08 Thread Ilya Enkovich
Hi,

This patch adds a bounds lifetime reduction into checker optimization.

Thanks,
Ilya
--
2014-10-08  Ilya Enkovich  

* tree-chkp.c (chkp_reduce_bounds_lifetime): New.
(chkp_opt_execute): Run bounds lifetime reduction
algorithm.


diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index 37ab729..60e4c11 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -5420,6 +5420,155 @@ chkp_optimize_string_function_calls (void)
 }
 }
 
+/* Intrumentation pass inserts most of bounds creation code
+   in the header of the function.  We want to move bounds
+   creation closer to bounds usage to reduce bounds lifetime.
+   We also try to avoid bounds creation code on paths where
+   bounds are not used.  */
+void
+chkp_reduce_bounds_lifetime (void)
+{
+  basic_block bb = FALLTHRU_EDGE (ENTRY_BLOCK_PTR_FOR_FN (cfun))->dest;
+  gimple_stmt_iterator i;
+
+  for (i = gsi_start_bb (bb); !gsi_end_p (i); )
+{
+  gimple dom_use, use_stmt, stmt = gsi_stmt (i);
+  basic_block dom_bb;
+  ssa_op_iter iter;
+  imm_use_iterator use_iter;
+  use_operand_p use_p;
+  tree op;
+  bool want_move = false;
+  bool deps = false;
+
+  if (gimple_code (stmt) == GIMPLE_CALL
+ && gimple_call_fndecl (stmt) == chkp_bndmk_fndecl)
+   want_move = true;
+
+  if (gimple_code (stmt) == GIMPLE_ASSIGN
+ && POINTER_BOUNDS_P (gimple_assign_lhs (stmt))
+ && gimple_assign_rhs_code (stmt) == VAR_DECL)
+   want_move = true;
+
+  if (!want_move)
+   {
+ gsi_next (&i);
+ continue;
+   }
+
+  /* Check we do not increase other values lifetime.  */
+  FOR_EACH_PHI_OR_STMT_USE (use_p, stmt, iter, SSA_OP_USE)
+   {
+ op = USE_FROM_PTR (use_p);
+
+ if (TREE_CODE (op) == SSA_NAME
+ && gimple_code (SSA_NAME_DEF_STMT (op)) != GIMPLE_NOP)
+   deps = true;
+   }
+
+  if (deps)
+   {
+ gsi_next (&i);
+ continue;
+   }
+
+  /* Check all usages of bounds.  */
+  if (gimple_code (stmt) == GIMPLE_CALL)
+   op = gimple_call_lhs (stmt);
+  else
+   {
+ gcc_assert (gimple_code (stmt) == GIMPLE_ASSIGN);
+ op = gimple_assign_lhs (stmt);
+   }
+
+  dom_use = NULL;
+  dom_bb = NULL;
+
+  FOR_EACH_IMM_USE_STMT (use_stmt, use_iter, op)
+   {
+ if (dom_bb &&
+ dominated_by_p (CDI_DOMINATORS,
+ dom_bb, gimple_bb (use_stmt)))
+   {
+ dom_use = use_stmt;
+ dom_bb = NULL;
+   }
+ else if (dom_bb)
+   dom_bb = nearest_common_dominator (CDI_DOMINATORS, dom_bb,
+  gimple_bb (use_stmt));
+ else if (!dom_use)
+   dom_use = use_stmt;
+ else if (stmt_dominates_stmt_p (use_stmt, dom_use))
+   dom_use = use_stmt;
+ else if (!stmt_dominates_stmt_p (dom_use, use_stmt)
+  /* If dom_use and use_stmt are PHI nodes in one BB
+ then it is OK to keep any of them as dom_use.
+ stmt_dominates_stmt_p returns 0 for such
+ combination, so check it here manually.  */
+  && (gimple_code (dom_use) != GIMPLE_PHI
+  || gimple_code (use_stmt) != GIMPLE_PHI
+  || gimple_bb (use_stmt) != gimple_bb (dom_use))
+  )
+   {
+ dom_bb = nearest_common_dominator (CDI_DOMINATORS,
+gimple_bb (use_stmt),
+gimple_bb (dom_use));
+ dom_use = NULL;
+   }
+   }
+
+  /* In case there is a single use, just move bounds
+creation to the use.  */
+  if (dom_use || dom_bb)
+   {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+   {
+ fprintf (dump_file, "Moving creation of ");
+ print_generic_expr (dump_file, op, 0);
+ fprintf (dump_file, " down to its use.\n");
+   }
+
+ if (dom_use && gimple_code (dom_use) == GIMPLE_PHI)
+   {
+ dom_bb = get_immediate_dominator (CDI_DOMINATORS,
+   gimple_bb (dom_use));
+ dom_use = NULL;
+   }
+
+ if (dom_bb == bb
+ || (dom_use && gimple_bb (dom_use) == bb))
+   {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+   fprintf (dump_file, "Cannot move statement bacause there is 
no "
+"suitable dominator block other than entry 
block.\n");
+
+ gsi_next (&i);
+   }
+ else
+   {
+ if (dom_bb)
+   {
+ gimple_stmt_iterator last = gsi_last_bb (dom_bb);
+ if (!gsi_end_p (last) && stmt_ends_bb_p (gsi_stmt (last)))
+   gsi_mo

[PATCH, Pointer Bounds Checker 14/x] Passes [17/n] Add checker passes into passes list

2014-10-08 Thread Ilya Enkovich
Hi,

This patch adds instrumentation passes into passes list.

Thanks,
Ilya
--
gcc/

2014-10-08  Ilya Enkovich  

* passes.def (pass_ipa_chkp_versioning): New.
(pass_early_local_passes): Renamed to pass_build_ssa_passes.
(pass_fixup_cfg): Moved to pass_chkp_instrumentation_passes.
(pass_chkp_instrumentation_passes): New.
(pass_ipa_chkp_produce_thunks): New.
(pass_local_optimization_passes): New.
(pass_chkp_opt): New.
* toplev.c: include tree-chkp.h.
(compile_file): Add chkp_finish_file call.
* tree-pass.h (make_pass_ipa_chkp_versioning): New.
(make_pass_ipa_chkp_produce_thunks): New.
(make_pass_chkp): New.
(make_pass_chkp_opt): New.
(make_pass_early_local_passes): Renamed to ...
(make_pass_build_ssa_passes): This.
(make_pass_chkp_instrumentation_passes): New.
(make_pass_local_optimization_passes): New.
* passes.c (pass_manager::execute_early_local_passes): Execute
early passes in three steps.
(execute_all_early_local_passes): Renamed to ...
(execute_build_ssa_passes): This.
(pass_data_early_local_passes): Renamed to ...
(pass_data_build_ssa_passes): This.
(pass_early_local_passes): Renamed to ...
(pass_build_ssa_passes): This.
(pass_data_chkp_instrumentation_passes): New.
(pass_chkp_instrumentation_passes): New.
(pass_data_local_optimization_passes): New.
(pass_local_optimization_passes): New.
(make_pass_early_local_passes): Renamed to ...
(make_pass_build_ssa_passes): This.
(make_pass_chkp_instrumentation_passes): New.
(make_pass_local_optimization_passes): New.

gcc/testsuite

2014-10-08  Ilya Enkovich  

* gcc.dg/pr37858.c: Replace early_local_cleanups pass name
with build_ssa_passes.


diff --git a/gcc/passes.c b/gcc/passes.c
index 5001c3d..a6c3718 100644
--- a/gcc/passes.c
+++ b/gcc/passes.c
@@ -133,7 +133,9 @@ opt_pass::opt_pass (const pass_data &data, context *ctxt)
 void
 pass_manager::execute_early_local_passes ()
 {
-  execute_pass_list (cfun, pass_early_local_passes_1->sub);
+  execute_pass_list (cfun, pass_build_ssa_passes_1->sub);
+  execute_pass_list (cfun, pass_chkp_instrumentation_passes_1->sub);
+  execute_pass_list (cfun, pass_local_optimization_passes_1->sub);
 }
 
 unsigned int
@@ -325,7 +327,7 @@ finish_optimization_passes (void)
 }
 
 static unsigned int
-execute_all_early_local_passes (void)
+execute_build_ssa_passes (void)
 {
   /* Once this pass (and its sub-passes) are complete, all functions
  will be in SSA form.  Technically this state change is happening
@@ -340,10 +342,10 @@ execute_all_early_local_passes (void)
 
 namespace {
 
-const pass_data pass_data_early_local_passes =
+const pass_data pass_data_build_ssa_passes =
 {
   SIMPLE_IPA_PASS, /* type */
-  "early_local_cleanups", /* name */
+  "build_ssa_passes", /* name */
   OPTGROUP_NONE, /* optinfo_flags */
   TV_EARLY_LOCAL, /* tv_id */
   0, /* properties_required */
@@ -355,11 +357,11 @@ const pass_data pass_data_early_local_passes =
   0, /* todo_flags_finish */
 };
 
-class pass_early_local_passes : public simple_ipa_opt_pass
+class pass_build_ssa_passes : public simple_ipa_opt_pass
 {
 public:
-  pass_early_local_passes (gcc::context *ctxt)
-: simple_ipa_opt_pass (pass_data_early_local_passes, ctxt)
+  pass_build_ssa_passes (gcc::context *ctxt)
+: simple_ipa_opt_pass (pass_data_build_ssa_passes, ctxt)
   {}
 
   /* opt_pass methods: */
@@ -371,17 +373,87 @@ public:
 
   virtual unsigned int execute (function *)
 {
-  return execute_all_early_local_passes ();
+  return execute_build_ssa_passes ();
 }
 
-}; // class pass_early_local_passes
+}; // class pass_build_ssa_passes
+
+const pass_data pass_data_chkp_instrumentation_passes =
+{
+  SIMPLE_IPA_PASS, /* type */
+  "chkp_passes", /* name */
+  OPTGROUP_NONE, /* optinfo_flags */
+  TV_NONE, /* tv_id */
+  0, /* properties_required */
+  0, /* properties_provided */
+  0, /* properties_destroyed */
+  0, /* todo_flags_start */
+  0, /* todo_flags_finish */
+};
+
+class pass_chkp_instrumentation_passes : public simple_ipa_opt_pass
+{
+public:
+  pass_chkp_instrumentation_passes (gcc::context *ctxt)
+: simple_ipa_opt_pass (pass_data_chkp_instrumentation_passes, ctxt)
+  {}
+
+  /* opt_pass methods: */
+  virtual bool gate (function *)
+{
+  /* Don't bother doing anything if the program has errors.  */
+  return (!seen_error () && !in_lto_p);
+}
+
+}; // class pass_chkp_instrumentation_passes
+
+const pass_data pass_data_local_optimization_passes =
+{
+  SIMPLE_IPA_PASS, /* type */
+  "opt_local_passes", /* name */
+  OPTGROUP_NONE, /* optinfo_flags */
+  TV_NONE, /* tv_id */
+  0, /* properties_required */
+  0, /* properties_provided */
+  0, /* properties_destroyed */
+  0, /* todo_flags_start */
+  0, /* todo_flags_finish */
+};
+
+class pass_

Re: [PATCH, Pointer Bounds Checker 14/x] Passes [2/n] IPA passes

2014-10-08 Thread Jan Hubicka
> +/*  Pointer Bounds Checker has two IPA passes to support code 
> instrumentation.
> +
> +In instrumented code each pointer is provided with bounds.  For input
> +pointer parameters it means we also have bounds passed.  For calls it
> +means we have additional bounds arguments for pointer arguments.
> +
> +To have all IPA optimizations working correctly we have to express
> +dataflow between passed and received bounds explicitly via additional
> +entries in function declaration arguments list and in function type.
> +Since we may have both instrumented and not instrumented code at the
> +same time, we cannot replace all original functions with their
> +instrumented variants.  Therefore we create clones (versions) instead.
> +
> +Instrumentation clones creation is a separate IPA pass which is a part
> +of early local passes.  Clones are created after SSA is built (because
> +instrumentation pass works on SSA) and before any transformations
> +which may change pointer flow and therefore lead to incorrect code
> +instrumentation (possibly causing false bounds check failures).
> +
> +Instrumentation clones have pointer bounds arguments added right after
> +pointer arguments.  Clones have assembler name of the original
> +function with suffix added.  New assembler name is in transparent
> +alias chain with the original name.  Thus we expect all calls to the
> +original and instrumented functions look similar in assembler.

Why new alias is created when calling conventions are the same?
> +
> +During instrumentation versioning pass we create instrumented versions
> +of all function with body and also for all their aliases and thunks.
> +Clones for functions with no body are created on demand (usually
> +during call instrumentation).
> +
> +Original and instrumented function nodes are connected with IPA
> +reference IPA_REF_CHKP.  It is mostly done to have reachability
> +analysis working correctly.  We may have no references to the

So you need IPA_REF_CHKP basically to prevent ipa.c from killing the function 
body.
One alternative I can think of is to simply represent it as direct call from 
clone
to original (becuase the functions are the same modulo bounds checking
and thus this is correct for all side effects analysis)

> +instrumented function in the code but it still should be counted
> +as reachable if the original function is reachable.
> +
> +When original function bodies are not needed anymore we release
> +them and transform functions into a special kind of thunks.  Each
> +thunk has a call edge to the instrumented version.  These thunks
> +help to keep externally visible instrumented functions visible
> +when linker reolution files are used.  Linker has no info about
> +connection between original and instrumented function and
> +therefore we may wrongly decide (due to difference in assember
> +names) that instrumented function version is local and can be
> +removed.  */

Can you, please, give me an example what happens here?
Also how this relates to LTO?

Honza
> +
> +#define CHKP_BOUNDS_OF_SYMBOL_PREFIX "__chkp_bounds_of_"
> +
> +/* Build a clone of FNDECL with a modified name.  */
> +
> +static tree
> +chkp_build_instrumented_fndecl (tree fndecl)
> +{
> +  tree new_decl = copy_node (fndecl);
> +  tree new_name;
> +  std::string s;
> +
> +  /* We want called_as_built_in recall instrumented calls
> + to instrumented built-in functions.  Therefore use
> + DECL_NAME for cloning instead of DECL_ASSEMBLER_NAME.  */
> +  s = IDENTIFIER_POINTER (DECL_NAME (fndecl));
> +  s += ".chkp";
> +  DECL_NAME (new_decl) = get_identifier (s.c_str ());
> +
> +  /* References to the original and to the instrumented version
> + should look the same in the output assembly.  And we cannot
> + use the same assembler name for the instrumented version
> + because it conflicts with decl merging algorithms in LTO.
> + Achieve the result by using transparent alias name for the
> + instrumented version.  */
> +  s = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
> +  s += ".chkp";
> +  new_name = get_identifier (s.c_str ());
> +  IDENTIFIER_TRANSPARENT_ALIAS (new_name) = 1;
> +  TREE_CHAIN (new_name) = DECL_ASSEMBLER_NAME (fndecl);
> +  SET_DECL_ASSEMBLER_NAME (new_decl, new_name);
> +
> +  /* For functions with body versioning will make a copy of arguments.
> + For functions with no body we need to do it here.  */
> +  if (!gimple_has_body_p (fndecl))
> +DECL_ARGUMENTS (new_decl) = copy_list (DECL_ARGUMENTS (fndecl));
> +
> +  /* We are going to modify attributes list and therefore should
> + make own copy.  */
> +  DECL_ATTRIBUTES (new_decl) = copy_list (DECL_ATTRIBUTES (fndecl));
> +
> +  return new_decl;
> +}
> +
> +
> +/* Fix operands of attribute from ATTRS list named ATTR_NAME.
> +   Integer operands are replaced with values accor

Re: [PATCH] add overlap function to gcov-tool

2014-10-08 Thread Jan Hubicka
> On Tue, Oct 7, 2014 at 9:31 PM, Jan Hubicka  wrote:
> >> Hi,
> >>
> >> This patch adds overlap functionality to gcov-tool. The overlap score
> >> estimates the similarity of two profiles. Currently it only computes
> >> overlap for arc counters.
> >>
> >> The overlap score is defined as
> >> \sum minimum (p1-counter[i] / p1-sum-all, p2-counter[i] / p2-sum-all)
> >> where p1-counter[i] and p2-counter[2] are two matched counter from
> >> profile1 and profiler2.
> >> p1-sum-all and p2-sum-all are the sum-all counters in profiler1 and
> >> profile2, repetitively.
> >
> > The patch looks fine in general.  My statistics is all rusty, but can't we 
> > use
> > one of the established techniques like Kullback-Leibler to compare the
> > probabilitis distributions?
> 
> Interesting. I never thought of using Kullback-Leibler divergence.
> It's very easy to switch to KL using this overlap framework -- only a
> few lines of change.
> The problem is KL divergence assumes absolute continuity (i.e. q(i)
> ==0 --> p(i) =0, which is
> not true in our distribution, I'm not sure how to work around this.).
> 
> I did try earth-mover-distance (EMD) in our earlier internal version.
> But since I used
> uniform distance, the problem can be simplified to distribution diffs.

I see, well, i guess your metric is easy to underatnd and fits the bill.
> 
> > It would be also nice to have ability to compare
> > branch probabilities in btween train runs.
> 
> Do you mean to do the comparison in CFG rather on the raw counters?
> We need gcno file to reconstruct the CFG. That needs some work.

Yes, I think in longer term we want to have gcov functionality as a
library with resonable API, so it can be used by gcov/gcov-tool
and to implement instrumentation at linktime with LTO (here we will
need to decide on instrumentaiton counter placement without actually
having a function body streamed in, so I think we can have graph abstraction
class and implement the CFG/instrumentation placement/solving around it.
The graph may be either real CFG in compiler or one read from GCDA files.

The patch is OK.
Honza
> 
> -Rong
> 
> >
> > Honza
> >>
> >> The resulting score is a value ranging from 0.0 to 1.0 where 0.0 means
> >> no match and 1.0 mean a perfect match.
> >>
> >> This tool can be used in performance triaging and reducing the fdo
> >> training set size (where similar inputs can be pruned).
> >>
> >> Tested with spec2006 profiles.
> >>
> >> Thanks,
> >>
> >> -Rong
> >
> >> 2014-10-07  Rong Xu  
> >>
> >>   * gcc/gcov-tool.c (profile_overlap): New driver function
> >> to compute profile overlap.
> >>   (print_overlap_usage_message): New.
> >>   (overlap_usage): New.
> >>   (do_overlap): New.
> >>   (print_usage): Add calls to overlap function.
> >>   (main): Ditto.
> >>   * libgcc/libgcov-util.c (read_gcda_file): Fix format.
> >>   (find_match_gcov_info): Ditto.
> >>   (calculate_2_entries): New.
> >>   (compute_one_gcov): Ditto.
> >>   (gcov_info_count_all_cold): Ditto.
> >>   (gcov_info_count_all_zero): Ditto.
> >>   (extract_file_basename): Ditto.
> >>   (get_file_basename): Ditto.
> >>   (set_flag): Ditto.
> >>   (matched_gcov_info): Ditto.
> >>   (calculate_overlap): Ditto.
> >>   (gcov_profile_overlap): Ditto.
> >>   * libgcc/libgcov-driver.c (compute_summary): Make
> >> it avavilable for external calls.
> >>   * gcc/doc/gcov-tool.texi: Add documentation.
> >>
> >> Index: gcc/gcov-tool.c
> >> ===
> >> --- gcc/gcov-tool.c   (revision 215981)
> >> +++ gcc/gcov-tool.c   (working copy)
> >> @@ -39,6 +39,7 @@ see the files COPYING3 and COPYING.RUNTIME respect
> >>  #include 
> >>
> >>  extern int gcov_profile_merge (struct gcov_info*, struct gcov_info*, int, 
> >> int);
> >> +extern int gcov_profile_overlap (struct gcov_info*, struct gcov_info*);
> >>  extern int gcov_profile_normalize (struct gcov_info*, gcov_type);
> >>  extern int gcov_profile_scale (struct gcov_info*, float, int, int);
> >>  extern struct gcov_info* gcov_read_profile_dir (const char*, int);
> >> @@ -368,6 +369,121 @@ do_rewrite (int argc, char **argv)
> >>return ret;
> >>  }
> >>
> >> +/* Driver function to computer the overlap score b/w profile D1 and D2.
> >> +   Return 1 on error and 0 if OK.  */
> >> +
> >> +static int
> >> +profile_overlap (const char *d1, const char *d2)
> >> +{
> >> +  struct gcov_info *d1_profile;
> >> +  struct gcov_info *d2_profile;
> >> +
> >> +  d1_profile = gcov_read_profile_dir (d1, 0);
> >> +  if (!d1_profile)
> >> +return 1;
> >> +
> >> +  if (d2)
> >> +{
> >> +  d2_profile = gcov_read_profile_dir (d2, 0);
> >> +  if (!d2_profile)
> >> +return 1;
> >> +
> >> +  return gcov_profile_overlap (d1_profile, d2_profile);
> >> +}
> >> +
> >> +  return 1;
> >> +}
> >> +
> >> +/* Usage message for profile overlap.  */
> >> +
> >> +static void
> >> +print_ove

Re: [RFC: Patch, PR 60102] [4.9/4.10 Regression] powerpc fp-bit ices@dwf_regno

2014-10-08 Thread Maciej W. Rozycki
Ulrich,

> > While emitting the location descriptors of multiple registers (SPE high/low
> > part) individually, the GCC hard register number is converted in to DWARF
> > register number using "dbx_reg_number" [Statement "A",  "B" & "C" below].
> 
> > But statement "C" macro "DBX_REGISTER_NUMBER" gets undefined by statement
> > "D" hence the GCC hard register number gets emitted in the debug info
> > instead of DWARF register number.  Previously, without this patch for SPE
> > high registers the GCC hard register number was same as the DWARF register
> > number (1200 onwards), hence we didn't see this issue.
> > 
> > Removing statement "D"  from "sysv4.h" file so as to generate expected
> > DWARF register number does work, but will there be any side effects?
> 
> Ah, I had completely forgotten about this issue, sorry ...
> 
> The problem with DBX_REGISTER_NUMBER is actually described in detail here:
> https://gcc.gnu.org/ml/gcc-patches/2012-11/msg02136.html
> 
> At the time, we decided to not remove the #undef DBX_REGISTER_NUMBER to
> avoid compatibility issues, but use GCC internal numbers in .debug_frame
> and .debug_info on Linux (option (3) in the above mail).  However, this
> was never actually implemented.
> 
> Looking at the current status, there are three groups of rs6000 targets:
> 
> - Some use the DBX_REGISTER_NUMBER definition from rs6000.h:
>   These are only AIX and Darwin.
> 
> - Some provide their own definition of DBX_REGISTER_NUMBER after the rs6000.h
>   one was undefined by sysv4.h:
>   These are FreeBSD, NetBSD, and Lynx.
> 
> - All other targets do not have DBX_REGISTER_NUMBER because it is undefined
>   by sysv4.h, and therefore using GCC internal register numbers:
>   These are Linux, rtems, vxworks, and all ELF/EABI targets.
> 
> 
> The following patch tries to remove the unfortunate confusion about undefining
> and redefining DBX_REGISTER_NUMBER, while keeping the behavior on all targets
> unchanged with the following two exceptions:
> - fix the SPE problem by always translating high register numbers
> - implement option (3) above by not replacing CR2 with CR in .debug_frame
>   on targets that do not use the standard DWARF register numbering
> 
> The way this works is to have a common, simple implementation of
> DBX_REGISTER_NUMBER and DWARF2_FRAME_REG_OUT for all targets that just
> calls to the rs6000_dbx_register_number routine, passing an extra format
> argument that decides whether the register number is to be used for
> .debug_info, .debug_frame, or .eh_frame.   In order to ensure
> rs6000_dbx_register_number always gets a GCC internal number as input,
> DWARF_FRAME_REGNUM has to be again defined as identity map.
> 
> All the logic to decide debug register numbers is now contained in that
> single place.  However, in order to maintain current behavior, we still
> have to distinguish between platforms that want to use the standard
> DWARF register numbering scheme, and those that use GCC internal numbers.
> This is now simply done by having the former provide a new define
> RS6000_USE_DWARF_NUMBERING in a target header file.
> 
> Tested on powerpc64le-linux and powerpc64-linux.
> 
> Rohit, could you verify whether this fixes the SPE problem?

 Thanks for your work, I have applied your change to my 4.9 setup, rebuilt 
the compiler and smoke-tested it with gdb.base/store.exp and my e500v2 
multilib only; powerpc-linux-gnu target.  Unfortunately your patch hasn't 
changed anything, the same failures remain.

 Just to be sure I haven't missed anything I reverted your change and 
Rohit's one as well, rebuilt the compiler and rerun this testing and this 
time all failures were gone.  So it looks like your fix didn't completely 
cover the damage Rohit's change caused. :(

  Maciej


[C++ PAtch] More C++11 and C++14 constexpr work

2014-10-08 Thread Paolo Carlini

Hi,

the below tries to make progress on some relatively easy issues I 
noticed while working on c++/55250. At least:

1- We rejected using declarations and using directives in constructors.
2- In C++14 mode we rejected compound-statements both in constructors 
and elsewhere (and in C++11 we provided both the pedwarn and then an 
hard error)

3- In C++14 mode we rejected local variables in constructors.

The patch itself uses quite straightforward strategies: 
check_constexpr_ctor_body is extended via the new 
check_constexpr_ctor_body_1; recursion on BIND_EXPRs takes care of 
compound-statements; the parser is tweaked to suppress the 
"compound-statement in constexpr function" pedwarn in C++14 mode.


Tested x86_64-linux.

Thanks,
Paolo.

//
/cp
2014-10-08  Paolo Carlini  

* semantics.c (check_constexpr_ctor_body_1): New.
(check_constexpr_ctor_body): Use it; add bool parameter.
(build_data_member_initialization): Handle BIND_EXPR and
USING_STMT in the main conditional.
(build_constexpr_constructor_member_initializers): Do not
handle BIND_EXPR here.
(constexpr_fn_retval): Handle BIND_EXPR in the switch.
(massage_constexpr_body): Don't do it here.
* parser.c (cp_parser_ctor_initializer_opt_and_function_body):
Adjust check_constexpr_ctor_body call.
(cp_parser_compound_statement): Do not pedwarn for compound-statement
in constexpr function in C++14 mode.
* cp-tree.h (check_constexpr_ctor_body): Update declaration.

/testsuite
2014-10-08  Paolo Carlini  

* g++.dg/cpp0x/constexpr-using3.C: New.
* g++.dg/cpp1y/constexpr-local-compound1.C: Likewise.
* g++.dg/cpp1y/constexpr-type-def-compound1.C: Likewise.
* g++.dg/cpp1y/constexpr-local1.C: Extend.
* g++.dg/cpp0x/constexpr-compound.C: Specify expected error.
Index: cp/cp-tree.h
===
--- cp/cp-tree.h(revision 216010)
+++ cp/cp-tree.h(working copy)
@@ -5822,7 +5822,7 @@ extern void finish_handler(tree);
 extern void finish_cleanup (tree, tree);
 extern bool literal_type_p (tree);
 extern tree register_constexpr_fundef (tree, tree);
-extern bool check_constexpr_ctor_body (tree, tree);
+extern bool check_constexpr_ctor_body (tree, tree, bool);
 extern tree ensure_literal_type_for_constexpr_object (tree);
 extern bool potential_constant_expression (tree);
 extern bool potential_rvalue_constant_expression (tree);
Index: cp/parser.c
===
--- cp/parser.c (revision 216010)
+++ cp/parser.c (working copy)
@@ -9891,7 +9891,7 @@ cp_parser_compound_statement (cp_parser *parser, t
   if (!cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE))
 return error_mark_node;
   if (DECL_DECLARED_CONSTEXPR_P (current_function_decl)
-  && !function_body)
+  && !function_body && cxx_dialect < cxx14)
 pedwarn (input_location, OPT_Wpedantic,
 "compound-statement in constexpr function");
   /* Begin the compound-statement.  */
@@ -19015,7 +19015,7 @@ cp_parser_ctor_initializer_opt_and_function_body (
   /* Parse the function-body.  */
   cp_parser_function_body (parser, in_function_try_block);
   if (check_body_p)
-check_constexpr_ctor_body (last, list);
+check_constexpr_ctor_body (last, list, /*complain=*/true);
   /* Finish the function body.  */
   finish_function_body (body);
 
Index: cp/semantics.c
===
--- cp/semantics.c  (revision 216010)
+++ cp/semantics.c  (working copy)
@@ -7779,8 +7779,12 @@ build_data_member_initialization (tree t, vec= cxx14)
+   return true;
+  return false;
+
+case CLEANUP_POINT_EXPR:
+  return check_constexpr_ctor_body (last, TREE_OPERAND (list, 0),
+   /*complain=*/false);
+
+case BIND_EXPR:
+   if (!check_constexpr_bind_expr_vars (list)
+  || !check_constexpr_ctor_body (last, BIND_EXPR_BODY (list),
+ /*complain=*/false))
+return false;
+   return true;
+
+case USING_STMT:
+case STATIC_ASSERT:
+  return true;
+
+default:
+  return false;
+}
+}
+
 /* Make sure that there are no statements after LAST in the constructor
body represented by LIST.  */
 
 bool
-check_constexpr_ctor_body (tree last, tree list)
+check_constexpr_ctor_body (tree last, tree list, bool complain)
 {
   bool ok = true;
   if (TREE_CODE (list) == STATEMENT_LIST)
@@ -7867,20 +7905,8 @@ bool
  tree t = tsi_stmt (i);
  if (t == last)
break;
- if (TREE_CODE (t) == BIND_EXPR)
+ if (!check_constexpr_ctor_body_1 (last, t))
{
- if (!check_constexpr_bind_expr_vars (t))
-   {
- ok = false;
-   

RE: [Patch, MIPS] Cleanup mips header files.

2014-10-08 Thread Matthew Fortune
> 2014-10-08  Steve Ellcey  
> 
>   * config/mips/mti-linux.h (DRIVER_SELF_SPECS): Change
>   LINUX64_DRIVER_SELF_SPECS to LINUX_DRIVER_SELF_SPECS

OK. I'd agree with obvious here.

Matthew


[PATCH] PR libstdc++/60132, implement the remaining C++11 is_trivially_* traits

2014-10-08 Thread Ville Voutilainen
Tested on Linux-X64.

Massive thanks to Jason for doing the heavy lifting on the front-end side.

2014-10-08  Ville Voutilainen  

PR libstdc++/60132
* include/std/type_traits (is_trivially_copyable,
is_trivially_constructible, is_trivially_default_constructible,
is_trivially_copy_constructible, is_trivially_move_constructible,
is_trivially_assignable, is_trivially_copy_assignable,
is_trivially_move_assignable): New.
* testsuite/20_util/is_trivially_assignable/requirements/typedefs.cc: New.
* 
testsuite/20_util/is_trivially_assignable/requirements/explicit_instantiation.cc:
New.
* testsuite/20_util/is_trivially_assignable/value.cc: New.
* testsuite/20_util/is_trivially_constructible/requirements/typedefs.cc:
New.
* 
testsuite/20_util/is_trivially_constructible/requirements/explicit_instantiation.cc:
New.
* testsuite/20_util/is_trivially_constructible/value.cc: New.
* testsuite/20_util/is_trivially_copyable/requirements/typedefs.cc: New.
* 
testsuite/20_util/is_trivially_copyable/requirements/explicit_instantiation.cc:
New.
* testsuite/20_util/is_trivially_copyable/value.cc: New.
* testsuite/20_util/is_trivially_copy_assignable/requirements/typedefs.cc:
New.
* 
testsuite/20_util/is_trivially_copy_assignable/requirements/explicit_instantiation.cc:
New.
* testsuite/20_util/is_trivially_copy_assignable/value.cc: New.
* 
testsuite/20_util/is_trivially_copy_constructible/requirements/typedefs.cc:
New.
* 
testsuite/20_util/is_trivially_copy_constructible/requirements/explicit_instantiation.cc:
New.
* testsuite/20_util/is_trivially_copy_constructible/value.cc: New.
* 
testsuite/20_util/is_trivially_default_constructible/requirements/typedefs.cc:
New.
* 
testsuite/20_util/is_trivially_default_constructible/requirements/explicit_instantiation.cc:
New.
* testsuite/20_util/is_trivially_default_constructible/value.cc: New.
* testsuite/20_util/is_trivially_move_assignable/requirements/typedefs.cc:
New.
* 
testsuite/20_util/is_trivially_move_assignable/requirements/explicit_instantiation.cc:
New.
* testsuite/20_util/is_trivially_move_assignable/value.cc: New.
* 
testsuite/20_util/is_trivially_move_constructible/requirements/typedefs.cc:
New.
* 
testsuite/20_util/is_trivially_move_constructible/requirements/explicit_instantiation.cc:
New.
* testsuite/20_util/is_trivially_move_constructible/value.cc: New.
diff --git a/libstdc++-v3/include/std/type_traits 
b/libstdc++-v3/include/std/type_traits
index 6690044..d776efe 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -606,7 +606,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 : public integral_constant
 { };
 
-  // is_trivially_copyable (still unimplemented)
+  // is_trivially_copyable
+  template
+struct is_trivially_copyable
+: public integral_constant
+{ };
 
   /// is_standard_layout
   template
@@ -1282,19 +1286,58 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 : public __is_nt_move_assignable_impl<_Tp>
 { };
 
-  /// is_trivially_constructible (still unimplemented)
+  /// is_trivially_constructible
+  template
+struct is_trivially_constructible
+: public __and_, integral_constant>::type
+{ };
   
-  /// is_trivially_default_constructible (still unimplemented)
-
-  /// is_trivially_copy_constructible (still unimplemented)
+  /// is_trivially_default_constructible
+  template
+struct is_trivially_default_constructible
+: public is_trivially_constructible<_Tp>::type
+{ };
 
-  /// is_trivially_move_constructible (still unimplemented)
+  /// is_trivially_copy_constructible
+  template
+struct is_trivially_copy_constructible
+: public __and_, 
+   integral_constant>::type
+{ };
+  
+  /// is_trivially_move_constructible
+  template
+struct is_trivially_move_constructible
+: public __and_, 
+   integral_constant>::type
+{ };
 
-  /// is_trivially_assignable (still unimplemented)
+  /// is_trivially_assignable
+  template
+struct is_trivially_assignable
+: public __and_, 
+   integral_constant>::type
+{ };
 
-  /// is_trivially_copy_assignable (still unimplemented)
+  /// is_trivially_copy_assignable
+  template
+struct is_trivially_copy_assignable
+: public __and_, 
+   integral_constant>::type
+{ };
 
-  /// is_trivially_move_assignable (still unimplemented)
+  /// is_trivially_move_assignable
+  template
+struct is_trivially_move_assignable
+: public __and_, 
+   integral_constant>::type
+{ };
 
   /// is_trivially_destructible
   template
diff --git 
a/libstdc++-v3/testsuite/20_util/is_trivially_assignable/requirements/explicit_instantiation.cc
 
b/libstdc++-v3/testsuite/20_util/is_trivially_assignable/requirements/explicit_instantiation.cc
new file mode 100644
index 000..cc028ad
--- /dev/null
+++ 
b/libstdc++-v3/testsuite/20_util/is_trivially_assig

constexpr and const qual in C++14

2014-10-08 Thread Marc Glisse

Hello,

another tiny bit for C++14 constexpr. I tested it on x86_64-linux-gnu 
together with another patch, so I'll retest it alone to be sure, but it 
passed. I added 'const' in addition to 'constexpr' for most testcases 
where it was needed, except for 2 where I explicitly check that const is 
implicit in C++11 but not C++14.


2014-10-09  Marc Glisse  

gcc/cp/
* decl.c (grokdeclarator): constexpr only implies const in C++11.
gcc/testsuite/
* g++.dg/cpp0x/constexpr-52892-1.C: Error on missing const in C++14.
* g++.dg/cpp0x/constexpr-array-ptr7.C: Likewise.
* g++.dg/cpp0x/constexpr-diag1.C: Add const.
* g++.dg/cpp0x/constexpr-diag3.C: Likewise.
* g++.dg/cpp0x/constexpr-ex1.C: Likewise.
* g++.dg/cpp0x/constexpr-ex2.C: Likewise.
* g++.dg/cpp0x/constexpr-ex4.C: Likewise.
* g++.dg/cpp0x/constexpr-initlist.C: Likewise.
* g++.dg/cpp0x/constexpr-ptrmem.C: Likewise.
* g++.dg/cpp0x/constexpr-ptrsub.C: Likewise.
* g++.dg/cpp0x/constexpr-ref4.C: Likewise.
* g++.dg/cpp0x/constexpr-static6.C: Likewise.

--
Marc GlisseIndex: cp/decl.c
===
--- cp/decl.c   (revision 216007)
+++ cp/decl.c   (working copy)
@@ -10532,21 +10532,22 @@ grokdeclarator (const cp_declarator *dec
  array_parameter_p = true;
}
   else if (TREE_CODE (type) == FUNCTION_TYPE)
type = build_pointer_type (type);
 }
 
   if (ctype && TREE_CODE (type) == FUNCTION_TYPE && staticp < 2
   && !NEW_DELETE_OPNAME_P (unqualified_id))
 {
   cp_cv_quals real_quals = memfn_quals;
-  if (constexpr_p && sfk != sfk_constructor && sfk != sfk_destructor)
+  if (cxx_dialect < cxx14 && constexpr_p
+ && sfk != sfk_constructor && sfk != sfk_destructor)
real_quals |= TYPE_QUAL_CONST;
   type = build_memfn_type (type, ctype, real_quals, rqual);
 }
 
   {
 tree decl;
 
 if (decl_context == PARM)
   {
decl = cp_build_parm_decl (unqualified_id, type);
Index: testsuite/g++.dg/cpp0x/constexpr-52892-1.C
===
--- testsuite/g++.dg/cpp0x/constexpr-52892-1.C  (revision 216007)
+++ testsuite/g++.dg/cpp0x/constexpr-52892-1.C  (working copy)
@@ -17,12 +17,12 @@ struct Defer {
   }
 };
 
 template 
 constexpr Defer make_deferred(const Function f) {
   return Defer(f);
 }
 
 int main() {
   constexpr auto deferred = make_deferred(&fibonacci);
-  static_assert(deferred(25) == 75025, "Static fibonacci call failed");
+  static_assert(deferred(25) == 75025, "Static fibonacci call failed"); // { 
dg-error "no match for call" "" { target c++14 } }
 }
Index: testsuite/g++.dg/cpp0x/constexpr-array-ptr7.C
===
--- testsuite/g++.dg/cpp0x/constexpr-array-ptr7.C   (revision 216007)
+++ testsuite/g++.dg/cpp0x/constexpr-array-ptr7.C   (working copy)
@@ -10,11 +10,11 @@ struct S
 
 constexpr T
 S::foo ()
 {
   return *(T *) (s1 + 10);
 }
 
 constexpr S s = { 0,1,2,3,4,5,6,7,8,9,10 };
 
 #define SA(X) static_assert ((X), #X)
-SA(s.foo() == 10);
+SA(s.foo() == 10); // { dg-error "discards qualifiers" "" { target c++14 } }
Index: testsuite/g++.dg/cpp0x/constexpr-diag1.C
===
--- testsuite/g++.dg/cpp0x/constexpr-diag1.C(revision 216007)
+++ testsuite/g++.dg/cpp0x/constexpr-diag1.C(working copy)
@@ -1,18 +1,18 @@
 // Test that we explain why a template instantiation isn't constexpr
 // { dg-do compile { target c++11 } }
 
 template 
 struct A
 {
   T t;
-  constexpr int f() { return 42; } // { dg-error "enclosing class" }
+  constexpr int f() const { return 42; } // { dg-error "enclosing class" }
 };
 
 struct B { B(); operator int(); };
 
 constexpr A ai = { 42 };
 constexpr int i = ai.f();
 
 constexpr int b = A().f();  // { dg-error "non-constexpr function" }
 
 template 
Index: testsuite/g++.dg/cpp0x/constexpr-diag3.C
===
--- testsuite/g++.dg/cpp0x/constexpr-diag3.C(revision 216007)
+++ testsuite/g++.dg/cpp0x/constexpr-diag3.C(working copy)
@@ -9,21 +9,21 @@ constexpr T g(T t) { return f(t); } // {
 int main()
 {
   constexpr int i = g(1);  // { dg-error "g.T" }
 }
 
 // 
 
 struct complex // { dg-message "no constexpr 
constructor" }
 {
   complex(double r, double i) : re(r), im(i) { }
-  constexpr double real() { return re; } // { dg-error "not a literal type" }
+  constexpr double real() const { return re; } // { dg-error "not a literal 
type" }
   double imag() const { return im; }
 
 private:
   double re;
   double im;
 };
 
 constexpr complex co1(0, 1);  // { dg-error "not literal" }
 constexpr double dd2 = co1.real(); // { dg-error "non-constexpr function" }
 
Index: testsuite/g++.dg/cpp0x/constexpr-ex1.C
==

  1   2   >