[Patch] SFINAE on is_same first in variant's _Tp&& constructor

2017-05-19 Thread Tim Shen via gcc-patches
This fixes PR libstdc++/80737.

I actually can't come up with a minimal test case, because I suspect
that there is a front-end bug in GCC. See discussions in the bug.

Tested on x86_64-linux-gnu.

Thanks!


-- 
Regards,
Tim Shen
commit 6f362991f025069328c4901d95b657d498aad250
Author: Tim Shen 
Date:   Fri May 19 22:26:58 2017 -0700

2017-05-20  Tim Shen  

PR libstdc++/80737
* include/std/variant(variant::variant): SFINAE on is_same first.
* testsuite/20_util/variant/any.cc: test case.

diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 0e04a820d69..b9824a5182c 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -936,9 +936,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   noexcept((is_nothrow_move_constructible_v<_Types> && ...)) = default;
 
   template, variant>>,
 	   typename = enable_if_t<__exactly_once<__accepted_type<_Tp&&>>
-			  && is_constructible_v<__accepted_type<_Tp&&>, _Tp&&>
-			  && !is_same_v, variant>>>
+			  && is_constructible_v<__accepted_type<_Tp&&>, _Tp&&>>>
 	constexpr
 	variant(_Tp&& __t)
 	noexcept(is_nothrow_constructible_v<__accepted_type<_Tp&&>, _Tp&&>)
diff --git a/libstdc++-v3/testsuite/20_util/variant/any.cc b/libstdc++-v3/testsuite/20_util/variant/any.cc
new file mode 100644
index 000..5811d0f055e
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/variant/any.cc
@@ -0,0 +1,31 @@
+// { dg-options "-std=gnu++17" }
+// { dg-do compile }
+
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+#include 
+#include 
+
+struct A { std::variant a; };
+
+void Bar(const A&);
+
+void Foo() {
+  A a;
+  Bar(a);
+}


Re: [PATCH] Limit perf data buffer during profiling

2017-05-19 Thread Jeff Law
On 05/18/2017 02:39 AM, Richard Biener wrote:
> On Thu, May 18, 2017 at 10:35 AM, Aldy Hernandez  wrote:
>> Andi Kleen  writes:
>>
>>> From: Andi Kleen 
>>>
>>> With high -j parallelism the autofdo tests can randomly fail.
>>> autofdo uses Linux perf to record profiling data.
>>> Linux perf uses a locked perf buffer. By default it has
>>> around 516k buffer per uid (/proc/sys/kernel/perf_event_mlock_kb).
>>>
>>> An individual perf record tries to grab the full 516k,
>>> which makes parallel perf record fail.
>>>
>>> This patch limits the perf buffer for individual perf record to 8k.
>>> With the default settings this allows a parallelism of the test
>>> cases of 16, which is hopefully good enough
>>
>> So for -jN > 16 it would silently fail again?
>>
>> I think we should warn when the -jN is sufficiently large such that
>> tests will randomly fail, and perhaps suggest workarounds with
>> ulimit/etc.
> 
> given that make check parallelism is somewhat "explicit" can't we
> simply arrange for the chunks to never get more than, say, 4 tree-prof.exp
> testcases run at the same time?
That would be significantly better than warning.

jeff


Re: MinGW compilation warnings in libiberty's waitpid.c

2017-05-19 Thread DJ Delorie

Please try this patch, since my mingw environment is old:

Index: libiberty/ChangeLog
===
--- libiberty/ChangeLog (revision 248307)
+++ libiberty/ChangeLog (working copy)
@@ -1,3 +1,7 @@
+2017-05-19  Eli Zaretskii 
+
+   * configure.ac (*-*-mingw*): Don't build waitpid.c.
+
 2017-05-02  Iain Buclaw  
 
* d-demangle.c (dlang_hexdigit): New function.
Index: libiberty/configure.ac
===
--- libiberty/configure.ac  (revision 248307)
+++ libiberty/configure.ac  (working copy)
@@ -493,7 +493,6 @@
 AC_LIBOBJ([strnlen])
 AC_LIBOBJ([strverscmp])
 AC_LIBOBJ([vasprintf])
-AC_LIBOBJ([waitpid])
 
 for f in $funcs; do
   case "$f" in



Re: MinGW compilation warnings in libiberty's include/environ.h

2017-05-19 Thread DJ Delorie

Pedro Alves  writes:
> That sounds to me like the root issue that should be fixed,
> so that these fallback definitions don't come into into play at all.
> I.e., why isn't HAVE_ENVIRON_DECL defined on mingw when
> setenv.o is built?  Sounds like a decl check is missing
> in configure.ac.

environ is tricky because it's typically messy on platforms, unlike a
standard C function.  You can't use a generic check if the macro expands
to something that interferes with the check.


Re: MinGW compilation warnings in libiberty's include/environ.h

2017-05-19 Thread DJ Delorie

Fix committed.  As Pedro noted, the correct way to request a change is
to make the change in your local checked out repo, and run "svn diff"
(or "git diff").  That makes sure that the fix is what you intended, and
that you don't have other unexpected changes (especially in regenerated
files, like configure).  It also checks against a patch against a stale
copy of the sources; if your patch doesn't apply that's a hint to the
maintainer that the patch needs to be looked at more closely.

The easier you can make it for the maintainer (me!), the more likely
your patch will get handled quickly.


Re: MinGW compilation warnings in libiberty's xstrndup.c

2017-05-19 Thread DJ Delorie

Pedro Alves  writes:
> Ah, yeah.  AFAICS, all the declaration checks in libiberty.h are 
> HAVE_DECL checks.  This suggests to me that this declaration guard 
> should be HAVE_DECL too [1].

Except the ones in the $funcs list, which includes strnlen.  I think in
the old days, we didn't put in declarations at all... until "char *"
became a different size than "int" and we started needing them.

So some functions in libiberty are HAVE_DECL and others are still HAVE.

Ah, found it, this commit is incomplete:

https://gcc.gnu.org/ml/gcc-patches/2014-06/msg00784.html

It changes gcc's configure but nobody else's (and now we have an answer
to the three-year-old question "why don't we have a more liberal commit
policy?" ;) which breaks both libiberty and libgfortran.

> BTW, I once proposed a new libiberty.m4 file that all libiberty
> clients would source so that these checks are all centralized.

I have no philosophical problem with that type of change, but I have the
usual fear of touching anything in libiberty that's been around this
long ;-)

(this bug being a prime example of how subtle an incorrect change can be)

(and honestly, my upstream attention is elsewhere these days)


Re: [PATCH 2/2] [testsuite] PR 80759 Remove gas extensions from do-test.S, fix other problems

2017-05-19 Thread Daniel Santos

Thanks you for your assistance Rainer!

On 05/19/2017 04:03 AM, Rainer Orth wrote:

unfortunately, it still doesn't, as explained in the PR.  The multilib
support is still wrong/non-existant.


I guess I thought for some reason that would magically appear in 
TEST_ALWAYS_FLAGS. :)  I've explicitly added it for now, but I haven't 
yet found where -m64 gets fed in the normal flow of things and I would 
rather know I'm doing things as closely as possible to how the rest if 
the test harness does it.



(I have SVN write privs now, so I can even commit it myself).

Please always include ChangeLog entries with your patch submissions so
one can easily see what you've change
(cf. https://gcc.gnu.org/contribute.html).

Thanks.
 Rainer


I hate when I forget that!  I'll be sure to remember when I resubmit.


Use of .struct in do_test.S causes breakages when gas isn't the
assembler (e.g., Solaris).  I also wasn't including TEST_ALWAYS_FLAGS in
my CFLAGS resulting in super-ugly log files.  Finally, this patch
eliminates spam of "test unsupported" (limiting it to one printing).

Signed-off-by: Daniel Santos 
---
  .../gcc.target/x86_64/abi/ms-sysv/do-test.S| 26 +-
  .../gcc.target/x86_64/abi/ms-sysv/ms-sysv.c|  7 ++
  .../gcc.target/x86_64/abi/ms-sysv/ms-sysv.exp  | 24 
  3 files changed, 27 insertions(+), 30 deletions(-)

diff --git a/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/do-test.S 
b/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/do-test.S
index 1395235fd1e..967eb959fbc 100644
--- a/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/do-test.S
+++ b/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/do-test.S
@@ -46,22 +46,6 @@ fn:
  #  define MOVAPS movaps
  # endif
  
-/* TODO: Is there a cleaner way to provide these offsets?  */

-   .struct 0
-test_data_save:
-
-   .struct test_data_save + 224
-test_data_input:
-
-   .struct test_data_save + 448
-test_data_output:
-
-   .struct test_data_save + 672
-test_data_fn:
-
-   .struct test_data_save + 680
-test_data_retaddr:
-
.text
  
  regs_to_mem:

@@ -132,23 +116,23 @@ L0:
callregs_to_mem
  
  	# Load register with random data

-   lea test_data + test_data_input(%rip), %rax
+   lea test_data + 224(%rip), %rax
callmem_to_regs
  
  	# Save original return address

pop %rax
-   movq%rax, test_data + test_data_retaddr(%rip)
+   movq%rax, test_data + 680(%rip)
  
  	# Call the test function

-   call*test_data + test_data_fn(%rip)
+   call*test_data + 672(%rip)
  
  	# Restore the original return address

-   movqtest_data + test_data_retaddr(%rip), %rcx
+   movqtest_data + 680(%rip), %rcx
push%rcx
  
  	# Save test function return value and store resulting register values

push%rax
-   lea test_data + test_data_output(%rip), %rax
+   lea test_data + 448(%rip), %rax
callregs_to_mem
  
  	# Restore registers

diff --git a/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.c 
b/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.c
index 2a011f5103d..7cec312c386 100644
--- a/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.c
+++ b/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.c
@@ -346,6 +346,13 @@ int main (int argc, char *argv[])
assert (!((long)_data.regdata[REG_SET_INPUT] & 15));
assert (!((long)_data.regdata[REG_SET_OUTPUT] & 15));
  
+  /* Verify offsets hard-coded into assembly.  */

+  assert (__builtin_offsetof (struct test_data, regdata[REG_SET_SAVE]) == 0);
+  assert (__builtin_offsetof (struct test_data, regdata[REG_SET_INPUT]) == 
224);
+  assert (__builtin_offsetof (struct test_data, regdata[REG_SET_OUTPUT]) == 
448);
+  assert (__builtin_offsetof (struct test_data, fn) == 672);
+  assert (__builtin_offsetof (struct test_data, retaddr) == 680);
+
while ((c = getopt (argc, argv, "s:f")) != -1)
  {
switch (c)

while .struct is a gas extension and doesn't work with the Solaris/x86
/bin/as, having the same (mostly unexplained) constants hardcoded in two
places isn't exactly helpful.  I'd suggest moving them to (say)
ms-sysv.h and include that from both do-test.S (which is preprocessed
assembler after all) and ms-sysv.c.

Rainer


Well, I don't have an ms-sysv.h, but I suppose I can add one.

I'm starting to lean more towards the idea of plucking out the portion 
of asm that uses these offsets, moving that to an inline asm function 
and having the code in do-test.S just jmp to it.  I wish there was some 
sort of "naked" attribute for x86 since I'm not well versed in every way 
that the compiler can change it in a way that wouldn't be friendly.


void __attribute__((optimize ("-O0 -fno-split-stack")))
do_test_body (void)
{
  __asm__ __volatile__ (
"# Save registers\n"
"  lea %0, %%rax\n"
"  callregs_to_mem\n"
"\n"
"  # Load registers with random 

Re: MinGW compilation warnings in libiberty's xstrndup.c

2017-05-19 Thread Pedro Alves
On 05/19/2017 11:31 PM, DJ Delorie wrote:
> 
> Right, I meant, libiberty's configure, gcc's configure, binutils'
> configure, and gdb's configure, all need to agree on whether strnlen is
> a HAVE or a HAVE_DECL type symbol.  If they don't, the header can't
> provide "one" working solution.
> 

Ah, yeah.  AFAICS, all the declaration checks in libiberty.h are 
HAVE_DECL checks.  This suggests to me that this declaration guard 
should be HAVE_DECL too [1].

BTW, I once proposed a new libiberty.m4 file that all libiberty
clients would source so that these checks are all centralized.

Here:
 https://gcc.gnu.org/ml/gcc-patches/2015-02/msg00580.html

And follow up here:
 https://gcc.gnu.org/ml/gcc-patches/2015-02/msg01712.html

Leading to (as, gold, ld, gdb and libiberty/ itself converted):
 https://github.com/palves/gdb/commits/palves/libiberty_m4

I never tried adjusting gcc, but even if it wouldn't
work there, it'd still be a net win.

Wonder what others think of that approach.

Thanks,
Pedro Alves



Re: MinGW compilation warnings in libiberty's xstrndup.c

2017-05-19 Thread DJ Delorie

Right, I meant, libiberty's configure, gcc's configure, binutils'
configure, and gdb's configure, all need to agree on whether strnlen is
a HAVE or a HAVE_DECL type symbol.  If they don't, the header can't
provide "one" working solution.


Re: MinGW compilation warnings in libiberty's xstrndup.c

2017-05-19 Thread Pedro Alves
On 05/19/2017 10:56 PM, DJ Delorie wrote:
> 
> Eli Zaretskii  writes:
>> It should use HAVE_STRNLEN instead, because that's the only
>> strnlen-related macro defined in config.g when strnlen is probed by
>> the configure script.
> 
> Ah, but gcc's configure defines HAVE_DECL_STRNLEN.  Header guards need
> to be coordinated across all the users, not just libiberty.
> 

The "user" in this case is libiberty itself.

Thanks,
Pedro Alves



Re: MinGW compilation warnings in libiberty's xstrndup.c

2017-05-19 Thread DJ Delorie

Eli Zaretskii  writes:
> It should use HAVE_STRNLEN instead, because that's the only
> strnlen-related macro defined in config.g when strnlen is probed by
> the configure script.

Ah, but gcc's configure defines HAVE_DECL_STRNLEN.  Header guards need
to be coordinated across all the users, not just libiberty.


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

2017-05-19 Thread Jason Merrill
On Fri, May 19, 2017 at 4:07 PM, Martin Sebor  wrote:
> On 05/19/2017 01:07 PM, Jason Merrill wrote:
>>
>> On Tue, May 16, 2017 at 5:39 PM, Martin Sebor  wrote:
>>>
>>> On 05/16/2017 01:41 PM, Jason Merrill wrote:
>>>
 I'm still not convinced we need to consider standard-layout at all.
>>>
>>>
>>> I agree.  The patch doesn't make use of is_standard_layout_p().
>>> It defines its own helper called almost_std_layout_p() that
>>> combines trivial_type_p() with tests for non-public members,
>>
>>
>> That's the part that seems unnecessary.  Why do we care about
>> non-public members?
>
> Because modifying them breaks encapsulation.

Not if you're clearing/copying the object as a whole.

> If I take a legacy struct, make some of its members private,
> and define accessors and modifiers to manipulate those members
> and maintain invariants between them, I will want to check and
> adjust all code that changes objects of the struct in ways that
> might violate the invariants.

For a trivial type, worrying about invariants doesn't make sense to
me, since default-initialization won't establish any invariants.  And
bzero or memset(0) will have the same effect as value-initialization
(if zero_init_p (type); we probably want to check that).  If you're
going to establish invariants, I would expect you to write a default
constructor, which would make the class non-trivial.

> What common use case are you concerned about that isn't more
> appropriately expressed using the generated default or copy
> constructor or assignment operator?

None; I am concerned about focusing the warning on code that is
actually likely to be problematic.

Jason


RE: [PATCH][Aarch64] Add support for overflow add and sub operations

2017-05-19 Thread Michael Collison
Christophe,

I had a type in the two test cases: "addcs" should have been "adcs". I caught 
this previously but submitted the previous patch incorrectly. Updated patch 
attached.

Okay for trunk?

-Original Message-
From: Christophe Lyon [mailto:christophe.l...@linaro.org] 
Sent: Friday, May 19, 2017 3:59 AM
To: Michael Collison 
Cc: gcc-patches@gcc.gnu.org; nd 
Subject: Re: [PATCH][Aarch64] Add support for overflow add and sub operations

Hi Michael,


On 19 May 2017 at 07:12, Michael Collison  wrote:
> Hi,
>
> This patch improves code generations for builtin arithmetic overflow 
> operations for the aarch64 backend. As an example for a simple test case such 
> as:
>
> Sure for a simple test case such as:
>
> int
> f (int x, int y, int *ovf)
> {
>   int res;
>   *ovf = __builtin_sadd_overflow (x, y, );
>   return res;
> }
>
> Current trunk at -O2 generates
>
> f:
> mov w3, w0
> mov w4, 0
> add w0, w0, w1
> tbnzw1, #31, .L4
> cmp w0, w3
> blt .L3
> .L2:
> str w4, [x2]
> ret
> .p2align 3
> .L4:
> cmp w0, w3
> ble .L2
> .L3:
> mov w4, 1
> b   .L2
>
>
> With the patch this now generates:
>
> f:
> addsw0, w0, w1
> csetw1, vs
> str w1, [x2]
> ret
>
>
> Original patch from Richard Henderson:
>
> https://gcc.gnu.org/ml/gcc-patches/2016-01/msg01903.html
>
>
> Okay for trunk?
>
> 2017-05-17  Michael Collison  
> Richard Henderson 
>
> * config/aarch64/aarch64-modes.def (CC_V): New.
> * config/aarch64/aarch64-protos.h
> (aarch64_add_128bit_scratch_regs): Declare
> (aarch64_add_128bit_scratch_regs): Declare.
> (aarch64_expand_subvti): Declare.
> (aarch64_gen_unlikely_cbranch): Declare
> * config/aarch64/aarch64.c (aarch64_select_cc_mode): Test
> for signed overflow using CC_Vmode.
> (aarch64_get_condition_code_1): Handle CC_Vmode.
> (aarch64_gen_unlikely_cbranch): New function.
> (aarch64_add_128bit_scratch_regs): New function.
> (aarch64_subv_128bit_scratch_regs): New function.
> (aarch64_expand_subvti): New function.
> * config/aarch64/aarch64.md (addv4, uaddv4): New.
> (addti3): Create simpler code if low part is already known to be 0.
> (addvti4, uaddvti4): New.
> (*add3_compareC_cconly_imm): New.
> (*add3_compareC_cconly): New.
> (*add3_compareC_imm): New.
> (*add3_compareC): Rename from add3_compare1; do not
> handle constants within this pattern.
> (*add3_compareV_cconly_imm): New.
> (*add3_compareV_cconly): New.
> (*add3_compareV_imm): New.
> (add3_compareV): New.
> (add3_carryinC, add3_carryinV): New.
> (*add3_carryinC_zero, *add3_carryinV_zero): New.
> (*add3_carryinC, *add3_carryinV): New.
> (subv4, usubv4): New.
> (subti): Handle op1 zero.
> (subvti4, usub4ti4): New.
> (*sub3_compare1_imm): New.
> (sub3_carryinCV): New.
> (*sub3_carryinCV_z1_z2, *sub3_carryinCV_z1): New.
> (*sub3_carryinCV_z2, *sub3_carryinCV): New.
> * testsuite/gcc.target/arm/builtin_sadd_128.c: New testcase.
> * testsuite/gcc.target/arm/builtin_saddl.c: New testcase.
> * testsuite/gcc.target/arm/builtin_saddll.c: New testcase.
> * testsuite/gcc.target/arm/builtin_uadd_128.c: New testcase.
> * testsuite/gcc.target/arm/builtin_uaddl.c: New testcase.
> * testsuite/gcc.target/arm/builtin_uaddll.c: New testcase.
> * testsuite/gcc.target/arm/builtin_ssub_128.c: New testcase.
> * testsuite/gcc.target/arm/builtin_ssubl.c: New testcase.
> * testsuite/gcc.target/arm/builtin_ssubll.c: New testcase.
> * testsuite/gcc.target/arm/builtin_usub_128.c: New testcase.
> * testsuite/gcc.target/arm/builtin_usubl.c: New testcase.
> * testsuite/gcc.target/arm/builtin_usubll.c: New testcase.

I've tried your patch, and 2 of the new tests FAIL:
gcc.target/aarch64/builtin_sadd_128.c scan-assembler addcs
gcc.target/aarch64/builtin_uadd_128.c scan-assembler addcs

Am I missing something?

Thanks,

Christophe


pr6308v2.patch
Description: pr6308v2.patch


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

2017-05-19 Thread Martin Sebor

On 05/19/2017 01:07 PM, Jason Merrill wrote:

On Tue, May 16, 2017 at 5:39 PM, Martin Sebor  wrote:

On 05/16/2017 01:41 PM, Jason Merrill wrote:


I'm still not convinced we need to consider standard-layout at all.


I agree.  The patch doesn't make use of is_standard_layout_p().
It defines its own helper called almost_std_layout_p() that
combines trivial_type_p() with tests for non-public members,


That's the part that seems unnecessary.  Why do we care about
non-public members?


Because modifying them breaks encapsulation.

If I take a legacy struct, make some of its members private,
and define accessors and modifiers to manipulate those members
and maintain invariants between them, I will want to check and
adjust all code that changes objects of the struct in ways that
might violate the invariants.

What common use case are you concerned about that isn't more
appropriately expressed using the generated default or copy
constructor or assignment operator?

Martin


Re: [config PATCH] --enable-languages

2017-05-19 Thread Mike Stump
On May 19, 2017, at 9:59 AM, Nathan Sidwell  wrote:
> 
> --enable-languages=all confused me, because as RichardB said, 'it really 
> means default'.  So this patch does 2 things
> 1) allow --enable-languages=default to mean what =all does now.
> 2) change =all to mean all available languages.
> 2.1) jit is included in =all if -enable-host-shared is given.  If you don't 
> you get a warning that JIT's not included.
> 
> If you're used to saying =all, then you'll get more languages with this patch 
> than you used to.
> 
> ok?

Can't approve the patch, but I'd endorse it.  I think it is easier to explain.



Re: [PATCH] Prevent extract_muldiv from introducing an overflow (PR sanitizer/80800)

2017-05-19 Thread Alexander Monakov
On Fri, 19 May 2017, Joseph Myers wrote:
> On Fri, 19 May 2017, Alexander Monakov wrote:
> > (to be precise, if the multiplication is done in a signed type and the 
> > middle
> > constant factor was a negated power of two, the sign change needs to remain:
> > 
> > a * -4 * b * 2
> > 
> > needs to be transformed to
> > 
> > a * -1 * b * 8 )
> 
> Shouldn't that only be the case if the middle constant was -1 and the 
> outer constant was 1?  If a * -4 * b is INT_MIN, a * b won't overflow and 
> so a * b * -8 should be a safe transformation.

Indeed, I should have considered the situation more carefully.  Thank you for
the correction.

Alexander


Re: Default std::vector default and move constructor

2017-05-19 Thread François Dumont

Hi

On 15/05/2017 21:31, Marc Glisse wrote:
The __fill_bvector part of the fill overload for vector could do 
with some improvements as well. Looping is unnecessary, one just needs 
to produce the right mask and and or or with it, that shouldn't take 
more than 4 instructions or so.



I have implemented this idear so I would like to amend my patch proposal 
with this additional optimization.


Tested under Linux x86_64 normal mode.

Ok to commit ?

François


diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h
index 37e000a..09683f7 100644
--- a/libstdc++-v3/include/bits/stl_bvector.h
+++ b/libstdc++-v3/include/bits/stl_bvector.h
@@ -388,10 +388,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   { return __x + __n; }
 
   inline void
-  __fill_bvector(_Bit_iterator __first, _Bit_iterator __last, bool __x)
+  __fill_bvector(_Bit_type * __v,
+		 unsigned int __first, unsigned int __last, bool __x)
   {
-for (; __first != __last; ++__first)
-  *__first = __x;
+const _Bit_type __fmask = ~0ul << __first;
+const _Bit_type __lmask = ~0ul >> (_S_word_bit - __last);
+const _Bit_type __mask = __fmask & __lmask;
+
+if (__x)
+  *__v |= __mask;
+else
+  *__v &= ~__mask;
   }
 
   inline void
@@ -399,12 +406,18 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   {
 if (__first._M_p != __last._M_p)
   {
-	std::fill(__first._M_p + 1, __last._M_p, __x ? ~0 : 0);
-	__fill_bvector(__first, _Bit_iterator(__first._M_p + 1, 0), __x);
-	__fill_bvector(_Bit_iterator(__last._M_p, 0), __last, __x);
+	_Bit_type *__first_p = __first._M_p;
+	if (__first._M_offset != 0)
+	  __fill_bvector(__first_p++, __first._M_offset, _S_word_bit, __x);
+
+	__builtin_memset(__first_p, __x ? ~0 : 0,
+			 (__last._M_p - __first_p) * sizeof(_Bit_type));
+
+	if (__last._M_offset != 0)
+	  __fill_bvector(__last._M_p, 0, __last._M_offset, __x);
   }
 else
-  __fill_bvector(__first, __last, __x);
+  __fill_bvector(__first._M_p, __first._M_offset, __last._M_offset, __x);
   }
 
   template
@@ -416,33 +429,66 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 	_Bit_alloc_traits;
   typedef typename _Bit_alloc_traits::pointer _Bit_pointer;
 
-  struct _Bvector_impl
-  : public _Bit_alloc_type
+  struct _Bvector_impl_data
   {
 	_Bit_iterator 	_M_start;
 	_Bit_iterator 	_M_finish;
 	_Bit_pointer 	_M_end_of_storage;
 
+	_Bvector_impl_data() _GLIBCXX_NOEXCEPT
+	: _M_start(), _M_finish(), _M_end_of_storage()
+	{ }
+
+#if __cplusplus >= 201103L
+	_Bvector_impl_data(_Bvector_impl_data&& __x) noexcept
+	: _M_start(__x._M_start), _M_finish(__x._M_finish)
+	, _M_end_of_storage(__x._M_end_of_storage)
+	{ __x._M_reset(); }
+
+	void
+	_M_move_data(_Bvector_impl_data&& __x) noexcept
+	{
+	  this->_M_start = __x._M_start;
+	  this->_M_finish = __x._M_finish;
+	  this->_M_end_of_storage = __x._M_end_of_storage;
+	  __x._M_reset();
+	}
+
+	void
+	_M_reset() noexcept
+	{
+	  this->_M_start = _Bit_iterator();
+	  this->_M_finish = _Bit_iterator();
+	  this->_M_end_of_storage = nullptr;
+	}
+#endif
+  };
+
+  struct _Bvector_impl
+	: public _Bit_alloc_type, public _Bvector_impl_data
+  {
+  public:
+#if __cplusplus >= 201103L
+	_Bvector_impl() = default;
+#else
 	_Bvector_impl()
-	: _Bit_alloc_type(), _M_start(), _M_finish(), _M_end_of_storage()
+	: _Bit_alloc_type()
 	{ }
+#endif
  
 	_Bvector_impl(const _Bit_alloc_type& __a)
-	: _Bit_alloc_type(__a), _M_start(), _M_finish(), _M_end_of_storage()
+	: _Bit_alloc_type(__a)
 	{ }
 
 #if __cplusplus >= 201103L
-	_Bvector_impl(_Bit_alloc_type&& __a)
-	: _Bit_alloc_type(std::move(__a)), _M_start(), _M_finish(),
-	  _M_end_of_storage()
-	{ }
+	_Bvector_impl(_Bvector_impl&&) = default;
 #endif
 
 	_Bit_type*
 	_M_end_addr() const _GLIBCXX_NOEXCEPT
 	{
-	  if (_M_end_of_storage)
-	return std::__addressof(_M_end_of_storage[-1]) + 1;
+	  if (this->_M_end_of_storage)
+	return std::__addressof(this->_M_end_of_storage[-1]) + 1;
 	  return 0;
 	}
   };
@@ -462,23 +508,18 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   get_allocator() const _GLIBCXX_NOEXCEPT
   { return allocator_type(_M_get_Bit_allocator()); }
 
+#if __cplusplus >= 201103L
+  _Bvector_base() = default;
+#else
   _Bvector_base()
   : _M_impl() { }
+#endif
   
   _Bvector_base(const allocator_type& __a)
   : _M_impl(__a) { }
 
 #if __cplusplus >= 201103L
-  _Bvector_base(_Bvector_base&& __x) noexcept
-  : _M_impl(std::move(__x._M_get_Bit_allocator()))
-  {
-	this->_M_impl._M_start = __x._M_impl._M_start;
-	this->_M_impl._M_finish = __x._M_impl._M_finish;
-	this->_M_impl._M_end_of_storage = __x._M_impl._M_end_of_storage;
-	__x._M_impl._M_start = _Bit_iterator();
-	__x._M_impl._M_finish = _Bit_iterator();
-	__x._M_impl._M_end_of_storage = nullptr;
-  }
+  _Bvector_base(_Bvector_base&&) = default;
 #endif
 
   ~_Bvector_base()
@@ -505,6 +546,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 	  }
   }
 
+#if 

c-warn PATCH to silence warnings about std::byte in switch

2017-05-19 Thread Jason Merrill
It doesn't make sense to warn about a switch case not being an
enumerator if the enum type has no enumerators; such a type is being
used as an opaque typedef rather than a true enumerated type.  This
usage makes more sense with C++11 enums with explicitly specified
underlying type, but I don't think it's necessary to limit the patch
to that case.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 673265c3d4cd77c7b0e927cc1547444ef869ad3a
Author: Jason Merrill 
Date:   Thu May 18 22:45:24 2017 -0400

* c-warn.c (match_case_to_enum_1): Don't warn about enums with no
enumerators.

diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c
index e67ffb7..8971156 100644
--- a/gcc/c-family/c-warn.c
+++ b/gcc/c-family/c-warn.c
@@ -1069,6 +1069,10 @@ warnings_for_convert_and_check (location_t loc, tree 
type, tree expr,
 static void
 match_case_to_enum_1 (tree key, tree type, tree label)
 {
+  /* Avoid warning about enums that have no enumerators.  */
+  if (TYPE_VALUES (type) == NULL_TREE)
+return;
+
   char buf[WIDE_INT_PRINT_BUFFER_SIZE];
 
   if (tree_fits_uhwi_p (key))
diff --git a/gcc/testsuite/g++.dg/cpp1z/byte2.C 
b/gcc/testsuite/g++.dg/cpp1z/byte2.C
new file mode 100644
index 000..6a395c1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/byte2.C
@@ -0,0 +1,13 @@
+// { dg-options "-std=c++17 -Wall" }
+
+#include 
+
+bool white_space(std::byte x) {
+  switch (x) {
+  case std::byte{' '}: case std::byte{'\t'}: case std::byte{'\v'}:
+  case std::byte{'\f'}: case std::byte{'\n'}:
+  return true;
+  default:
+return false;
+  }
+}


Re: [PATCH] PR c++/80544 strip cv-quals from cast results

2017-05-19 Thread Jason Merrill
On Thu, Apr 27, 2017 at 12:59 PM, Jonathan Wakely  wrote:
> I also tried to add a warning like EDG's (see the PR) but it gave a
> false positive for direct-list-init of scoped enums (P0138R2, r240449)
> because that code goes through build_c_cast to perform the conversion,
> so looks like a cast to my new warning.

The enum init code could strip the cv-quals when calling build_c_cast
to avoid the warning.

Jason


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

2017-05-19 Thread Jason Merrill
On Tue, May 16, 2017 at 5:39 PM, Martin Sebor  wrote:
> On 05/16/2017 01:41 PM, Jason Merrill wrote:
>
>> I'm still not convinced we need to consider standard-layout at all.
>
> I agree.  The patch doesn't make use of is_standard_layout_p().
> It defines its own helper called almost_std_layout_p() that
> combines trivial_type_p() with tests for non-public members,

That's the part that seems unnecessary.  Why do we care about
non-public members?

Jason


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

2017-05-19 Thread Sheldon Lobo


On 05/19/2017 02:45 PM, Eric Botcazou wrote:


This 4/4 commit needs to contain gcc/config/sparc/sparc.c, gcc/ChangeLog,
gcc/testsuite/gcc.target/sparc/niagara7-align.c and gcc/testsuite/ChangeLog.

The rule is that you put the ChangeLog entry into the ChangeLog file of the
directory where the change is made, or that of the parent directory if there
is none, recursively.  The filename in that ChangeLog file must be relative to
the directory when the ChangeLog file is.



Thanks, Eric. I did do that when I went ahead with the
'svn commit' yesterday. That is, gcc/ChangeLog and
gcc/testsuite/ChangeLog have the correct information.

The gcc source tree is as desired, but I may have made
2 inadvertent process mistakes:
* did not send a revised PATCH to gcc-patches
* made the 4 changes with 1 commit

Apologies,
Sheldon


Re: RFA: PATCH to check for overflow in make_tree_vec_stat

2017-05-19 Thread Jason Merrill
On Fri, May 19, 2017 at 5:14 AM, Richard Biener
 wrote:
> On Fri, May 19, 2017 at 4:32 AM, Jason Merrill  wrote:
>> A patch I've been putting together ran into strange memory corruption
>> issues which turned out to be because the calculation in
>> make_tree_vec_stat was overflowing and allocating a small TREE_VEC
>> instead of a large one.  This assert should work as a simple sanity
>> check.
>
> Hmm, looks like 'length' should be size_t?  Then nothing can overflow anymore
> (on hosts with size_t 64bit and int 32bit)

Sure.  I imagine that anything trying to create a TREE_VEC that large
is going to have a bad time for other reasons, but those will probably
be more obvious.

Applying this:

Jason
commit 2a5c0a40193350e57407165d17afe427a9f42325
Author: Jason Merrill 
Date:   Thu May 18 15:23:53 2017 -0400

* tree.c (make_tree_vec_stat, grow_tree_vec_stat): Use size_t.

diff --git a/gcc/tree.c b/gcc/tree.c
index 7506725..db31620 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -2268,7 +2268,7 @@ tree
 make_tree_vec_stat (int len MEM_STAT_DECL)
 {
   tree t;
-  int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
+  size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
 
   record_node_allocation_statistics (TREE_VEC, length);
 
@@ -2290,8 +2290,8 @@ grow_tree_vec_stat (tree v, int len MEM_STAT_DECL)
   int oldlen = TREE_VEC_LENGTH (v);
   gcc_assert (len > oldlen);
 
-  int oldlength = (oldlen - 1) * sizeof (tree) + sizeof (struct tree_vec);
-  int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
+  size_t oldlength = (oldlen - 1) * sizeof (tree) + sizeof (struct tree_vec);
+  size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
 
   record_node_allocation_statistics (TREE_VEC, length - oldlength);
 


Re: [PATCH] [ARC] Recognise add_n and sub_n in combine again

2017-05-19 Thread Claudiu Zissulescu
Hi
It looks alright. No questions to ask, if you need me to upstream it
please ping me.

Cheers,
Claudiu

On Mon, May 15, 2017 at 7:07 PM, Graham Markall
 wrote:
> Hi Claudiu,
>
> I ran the gcc testsuite with EZsim for NPS-400:
>
> $ ./EZsim_linux_x86_64 --version
> NPS-400 EZsim  - Version 1.9a ( 35b02d7, Nov  3 2015, 20:14:04 )
>
> both with and without the patch, and it did not introduce any new failures.
>
>
> Best regards,
> Graham.
>
> On 15/05/17 17:48, Claudiu Zissulescu wrote:
>> Hi Graham,
>>
>> May I ask if you tested this with gcc's dejagnu?
>>
>> Thanks,
>> Claudiu
>>
>> On Fri, May 12, 2017 at 9:14 PM, Graham Markall
>>  wrote:
>>> Since the combine pass canonicalises shift-add insns using plus and
>>> ashift (as opposed to plus and mult which it previously used to do), it
>>> no longer creates *add_n or *sub_n insns, as the patterns match plus and
>>> mult only. The outcome of this is that some opportunities to generate
>>> add{1,2,3} and sub{1,2,3} instructions are missed.
>>>
>>> This change adds additional *add_n and *sub_n insns that match the
>>> plus-ashift pattern. The original *add_n and *sub_n insns are still left
>>> in, as they are sometimes generated later on by constant propagation.
>>> The idea of adding these insns is modelled on the changes in:
>>>
>>>   https://gcc.gnu.org/ml/gcc-patches/2015-05/msg01882.html
>>>
>>> which addresses a similar issue for the PA target.
>>>
>>> For the small test cases that are added, even if the combine pass misses
>>> the opportunity to generate addN or subN, constant propagation manages
>>> to do so, so the rtl of the combine pass is checked.
>>>
>>> gcc/ChangeLog:
>>>
>>> * config/arc/arc.c (arc_print_operand): Handle constant operands.
>>> (arc_rtx_costs): Add costs for new patterns.
>>> * config/arc/arc.md: Additional *add_n and *sub_n patterns.
>>> * config/arc/predicates.md: Add _1_2_3_operand predicate.
>>>
>>> gcc/testsuite/ChangeLog:
>>>
>>> * gcc.target/arc/add_n-combine.c: New.
>>> * gcc.target/arc/sub_n-combine.c: New.
>>> ---
>>>  gcc/ChangeLog|  7 
>>>  gcc/config/arc/arc.c | 20 +---
>>>  gcc/config/arc/arc.md| 26 +++
>>>  gcc/config/arc/predicates.md |  5 +++
>>>  gcc/testsuite/ChangeLog  |  5 +++
>>>  gcc/testsuite/gcc.target/arc/add_n-combine.c | 48 
>>> 
>>>  gcc/testsuite/gcc.target/arc/sub_n-combine.c | 21 
>>>  7 files changed, 128 insertions(+), 4 deletions(-)
>>>  create mode 100644 gcc/testsuite/gcc.target/arc/add_n-combine.c
>>>  create mode 100644 gcc/testsuite/gcc.target/arc/sub_n-combine.c
>>>
>>> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
>>> index 91c28e7..42730d5 100644
>>> --- a/gcc/config/arc/arc.c
>>> +++ b/gcc/config/arc/arc.c
>>> @@ -3483,6 +3483,14 @@ arc_print_operand (FILE *file, rtx x, int code)
>>>
>>>return;
>>>
>>> +case 'c':
>>> +  if (GET_CODE (x) == CONST_INT)
>>> +fprintf (file, "%d", INTVAL (x) );
>>> +  else
>>> +output_operand_lossage ("invalid operands to %%c code");
>>> +
>>> +  return;
>>> +
>>>  case 'M':
>>>if (GET_CODE (x) == CONST_INT)
>>> fprintf (file, "%d",exact_log2(~INTVAL (x)) );
>>> @@ -4895,8 +4903,10 @@ arc_rtx_costs (rtx x, machine_mode mode, int 
>>> outer_code,
>>> *total = COSTS_N_INSNS (2);
>>>return false;
>>>  case PLUS:
>>> -  if (GET_CODE (XEXP (x, 0)) == MULT
>>> - && _2_4_8_operand (XEXP (XEXP (x, 0), 1), VOIDmode))
>>> +  if ((GET_CODE (XEXP (x, 0)) == ASHIFT
>>> +  && _1_2_3_operand (XEXP (XEXP (x, 0), 1), VOIDmode))
>>> +  || (GET_CODE (XEXP (x, 0)) == MULT
>>> +  && _2_4_8_operand (XEXP (XEXP (x, 0), 1), VOIDmode)))
>>> {
>>>   *total += (rtx_cost (XEXP (x, 1), mode, PLUS, 0, speed)
>>>  + rtx_cost (XEXP (XEXP (x, 0), 0), mode, PLUS, 1, 
>>> speed));
>>> @@ -4904,8 +4914,10 @@ arc_rtx_costs (rtx x, machine_mode mode, int 
>>> outer_code,
>>> }
>>>return false;
>>>  case MINUS:
>>> -  if (GET_CODE (XEXP (x, 1)) == MULT
>>> - && _2_4_8_operand (XEXP (XEXP (x, 1), 1), VOIDmode))
>>> +  if ((GET_CODE (XEXP (x, 1)) == ASHIFT
>>> +  && _1_2_3_operand (XEXP (XEXP (x, 1), 1), VOIDmode))
>>> +  || (GET_CODE (XEXP (x, 1)) == MULT
>>> +  && _2_4_8_operand (XEXP (XEXP (x, 1), 1), VOIDmode)))
>>> {
>>>   *total += (rtx_cost (XEXP (x, 0), mode, PLUS, 0, speed)
>>>  + rtx_cost (XEXP (XEXP (x, 1), 0), mode, PLUS, 1, 
>>> speed));
>>> diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
>>> index edb983f..ec783a0 100644
>>> --- a/gcc/config/arc/arc.md
>>> +++ b/gcc/config/arc/arc.md
>>> @@ -2995,6 +2995,19 @@
>>>
>>>  

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

2017-05-19 Thread Eric Botcazou
> The rule is that you put the ChangeLog entry into the ChangeLog file of the
> directory where the change is made, or that of the parent directory if there
> is none, recursively.  The filename in that ChangeLog file must be relative
> to the directory when the ChangeLog file is.

...where...

-- 
Eric Botcazou


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

2017-05-19 Thread Eric Botcazou
> Just so I am clear, gcc/testsuite/ChangeLog needs to be
> checked into the patch (but gcc/ChangeLog is not)?

This 4/4 commit needs to contain gcc/config/sparc/sparc.c, gcc/ChangeLog, 
gcc/testsuite/gcc.target/sparc/niagara7-align.c and gcc/testsuite/ChangeLog.

The rule is that you put the ChangeLog entry into the ChangeLog file of the 
directory where the change is made, or that of the parent directory if there 
is none, recursively.  The filename in that ChangeLog file must be relative to 
the directory when the ChangeLog file is.

-- 
Eric Botcazou


Re: [PATCH] Prevent extract_muldiv from introducing an overflow (PR sanitizer/80800)

2017-05-19 Thread Joseph Myers
On Fri, 19 May 2017, Alexander Monakov wrote:

> On Fri, 19 May 2017, Marek Polacek wrote:
> > > I think it's possible to keep this folding, note that it's valid to 
> > > transform to
> > > 
> > > (n * 1 * z) * 50
> > > 
> > > (i.e. accumulate multiplications on the outermost factor)
> 
> (to be precise, if the multiplication is done in a signed type and the middle
> constant factor was a negated power of two, the sign change needs to remain:
> 
> a * -4 * b * 2
> 
> needs to be transformed to
> 
> a * -1 * b * 8 )

Shouldn't that only be the case if the middle constant was -1 and the 
outer constant was 1?  If a * -4 * b is INT_MIN, a * b won't overflow and 
so a * b * -8 should be a safe transformation.

(You also need to avoid overflows in accumulating things on the outermost 
factor.)

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


Re: [PATCH] Try harder to fix recently introduced crashes in ggc_collect

2017-05-19 Thread Dominique d'Humières

> Le 19 mai 2017 à 19:26, Bernd Edlinger  a écrit :
> 
> No, unfortunately it looks like incremental does not work in this case.
> 
> You can try to remove gcc/s-gtyp-input, maybe it un-breaks your
> build.  However, I gave up at that point and did a full bootstrap
> instead.
> 
> Bernd.


Quite bad!-( bootstrap takes 2+ hours, incremental update for gfortran ~10 
minutes.

Dominique






Re: MinGW compilation warnings in libiberty's include/environ.h

2017-05-19 Thread Eli Zaretskii
> Cc: gdb-patc...@sourceware.org
> From: Pedro Alves 
> Date: Fri, 19 May 2017 16:51:30 +0100
> 
> So again there's a system header that defines the symbol
> but for some reason libiberty still wants to declare/define
> it is if it weren't?

Yes.  AFAICS, libiberty's configure script doesn't check the
declaration, it only probes the setenv function itself.  You can see
that the cpp directives around the environ declarations are
OS-dependent rather than based on autoconf tests.

> That sounds to me like the root issue that should be fixed,
> so that these fallback definitions don't come into into play at all.
> I.e., why isn't HAVE_ENVIRON_DECL defined on mingw when
> setenv.o is built?  Sounds like a decl check is missing
> in configure.ac.

Most probably, yes.


Re: [PATCH] Try harder to fix recently introduced crashes in ggc_collect

2017-05-19 Thread Bernd Edlinger
On 05/19/17 19:05, Dominique d'Humières wrote:
> Hi Bernd,
> 
> Your patches are causing troubles when I try to do "incremental updates »:
> 
> After revision r248290 it fails with
> 
> ../../work/gcc/cp/init.c:4916:10: fatal error: gt-cp-init.h: No such file or 
> directory
>   #include "gt-cp-init.h »
> 
> and after r248242 with
> 
> ../../work/gcc/c-family/c-format.c:4215:10: fatal error: 
> gt-c-family-c-format.h: No such file or directory
>   #include "gt-c-family-c-format.h »
> 
> Note that after r248242 a full bootstrap succeeded (don’t know yet for 
> r248290).
> 
> Is there a way to fix that?
> 

No, unfortunately it looks like incremental does not work in this case.

You can try to remove gcc/s-gtyp-input, maybe it un-breaks your
build.  However, I gave up at that point and did a full bootstrap
instead.


Bernd.


> TIA
> 
> Dominique
> 
> 


Re: MinGW compilation warnings in libiberty's waitpid.c

2017-05-19 Thread Eli Zaretskii
> Cc: gdb-patc...@sourceware.org
> From: Pedro Alves 
> Date: Fri, 19 May 2017 16:36:46 +0100
> 
> So I wonder whether we could just unconditionally remove the waitpid
> replacement instead.

That's probably the best path forward.


Re: [PATCH] Try harder to fix recently introduced crashes in ggc_collect

2017-05-19 Thread Dominique d'Humières
Hi Bernd,

Your patches are causing troubles when I try to do "incremental updates »:

After revision r248290 it fails with

../../work/gcc/cp/init.c:4916:10: fatal error: gt-cp-init.h: No such file or 
directory
 #include "gt-cp-init.h »

and after r248242 with

../../work/gcc/c-family/c-format.c:4215:10: fatal error: 
gt-c-family-c-format.h: No such file or directory
 #include "gt-c-family-c-format.h »

Note that after r248242 a full bootstrap succeeded (don’t know yet for r248290).

Is there a way to fix that?

TIA

Dominique




[config PATCH] --enable-languages

2017-05-19 Thread Nathan Sidwell
--enable-languages=all confused me, because as RichardB said, 'it really 
means default'.  So this patch does 2 things

1) allow --enable-languages=default to mean what =all does now.
2) change =all to mean all available languages.
2.1) jit is included in =all if -enable-host-shared is given.  If you 
don't you get a warning that JIT's not included.


If you're used to saying =all, then you'll get more languages with this 
patch than you used to.


ok?

nathan
--
Nathan Sidwell
2017-05-19  Nathan Sidwell  

	* configure.ac: Add --enable-languages=default to mean default and
	make --enable-languages=all mean all supported languages.
	* configure: Regenerated.
	gcc/
	* doc/invoke.texi (--enable-languages): Update documentation.

Index: configure.ac
===
--- configure.ac	(revision 248286)
+++ configure.ac	(working copy)
@@ -1766,6 +1766,13 @@ AC_ARG_ENABLE(linker-plugin-flags,
   extra_linker_plugin_flags=)
 AC_SUBST(extra_linker_plugin_flags)
 
+# Enable --enable-host-shared.
+# Checked early to determine whether jit is an 'all' language
+AC_ARG_ENABLE(host-shared,
+[AS_HELP_STRING([--enable-host-shared],
+		[build host code as shared libraries])],
+[host_shared=$enableval], [host_shared=no])
+AC_SUBST(host_shared)
 
 # By default, C and C++ are the only stage 1 languages.
 stage1_languages=,c,
@@ -1784,7 +1791,7 @@ if test -d ${srcdir}/gcc; then
   enable_languages="${LANGUAGES}"
 echo configure.ac: warning: setting LANGUAGES is deprecated, use --enable-languages instead 1>&2
 else
-  enable_languages=all
+  enable_languages=default
 fi
   else
 if test x"${enable_languages}" = x ||
@@ -1836,6 +1843,7 @@ if test -d ${srcdir}/gcc; then
 for other in ${lang_requires} ${lang_requires_boot_languages}; do
   case ,${enable_languages}, in
 	*,$other,*) ;;
+	*,default,*) ;;
 	*,all,*) ;;
 	*,$language,*)
 	  echo " \`$other' language required by \`$language'; enabling" 1>&2
@@ -1847,6 +1855,7 @@ if test -d ${srcdir}/gcc; then
 	  if test "$other" != "c"; then
 	case ,${enable_stage1_languages}, in
 	  *,$other,*) ;;
+	  *,default,*) ;;
 	  *,all,*) ;;
 	  *)
 		case ,${enable_languages}, in
@@ -1884,7 +1893,7 @@ if test -d ${srcdir}/gcc; then
 esac
   fi
 
-  missing_languages=`echo ",$enable_languages," | sed -e s/,all,/,/ -e s/,c,/,/ `
+  missing_languages=`echo ",$enable_languages," | sed -e s/,default,/,/ -e s/,all,/,/ -e s/,c,/,/ `
   potential_languages=,c,
 
   enabled_target_libs=
@@ -1916,21 +1925,27 @@ if test -d ${srcdir}/gcc; then
 	fi
 
 add_this_lang=no
-case ,${enable_languages}, in
-  *,${language},*)
-# Language was explicitly selected; include it
-	# unless it is C, which is enabled by default.
-	if test "$language" != "c"; then
+# C is always enabled, so no need to add it again
+if test "$language" != "c"; then
+  case ,${enable_languages}, in
+*,${language},*)
+  # Language was explicitly selected; include it
 	  add_this_lang=yes
-	fi
-;;
-  *,all,*)
-# 'all' was selected, select it if it is a default language
-	if test "$language" != "c"; then
+  ;;
+	*,all,*)
+	  # All languages are enabled
+	  if test "$language:$host_shared" = "jit:no" ; then
+	AC_MSG_WARN([not enabling language "jit" as --enable-host-shared not specified])
+	  else
+	add_this_lang=yes
+	  fi
+  ;;
+*,default,*)
+  # 'default' was selected, select it if it is a default language
 	  add_this_lang=${build_by_default}
-	fi
-;;
-esac
+  ;;
+  esac
+fi
 
 # Disable languages that need other directories if these aren't available.
 	for i in $subdir_requires; do
@@ -1959,6 +1974,8 @@ if test -d ${srcdir}/gcc; then
 ;;
 esac
 
+# Disable jit if -enable-host-shared not specified
+
 	# Disable a language that is unsupported by the target.
 	case " $unsupported_languages " in
 	  *" $language "*)
@@ -3478,13 +3495,6 @@ fi
 
 AC_SUBST(stage2_werror_flag)
 
-# Enable --enable-host-shared.
-AC_ARG_ENABLE(host-shared,
-[AS_HELP_STRING([--enable-host-shared],
-		[build host code as shared libraries])],
-[host_shared=$enableval], [host_shared=no])
-AC_SUBST(host_shared)
-
 # PR jit/64780: Require the user to explicitly specify
 # --enable-host-shared if the jit is enabled, hinting
 # that they might want to do a separate configure/build of
Index: gcc/doc/install.texi
===
--- gcc/doc/install.texi	(revision 248286)
+++ gcc/doc/install.texi	(working copy)
@@ -1621,14 +1621,17 @@ their runtime libraries should be built.
 grep ^language= */config-lang.in
 @end smallexample
 Currently, you can use any of the 

[PATCH] Remove gen_cell_microcode, warn_cell_microcode

2017-05-19 Thread Segher Boessenkool
-mno-gen-cell-microcode is a pain to handle correctly: it causes
different code generation for some very basic patterns, even patterns
specific to that option.  It also requires marking up many patterns,
which is a pain when adding new patterns or modifying existing ones
(first non-trivial step is finding the Cell BE manual!)

-mwarn-cell-microcode is very expensive, even more so after my recent
fix for PR43763; and it used to ICE for seven years before that fix.

This patch removes both these command line options (it leaves the
positive form of -mgen-cell-microcode, doing nothing, for
compatibility).

Where cc_reg_not_micro_cr0_operand was used, we now get the regular
cc_reg_not_cr0_operand.

One testcase used -mgen-cell-microcode and one its negation; both
are adjusted.

Tested on powerpc64-linux {-m32,-m64}; is this okay for trunk?

Segher


2017-05-19  Segher Boessenkool  

* config/rs6000/predicates.md (cc_reg_not_micro_cr0_operand): Delete.
(lwa_operand): Delete rs6000_gen_cell_microcode test.
* config/rs6000/rs6000.c (rs6000_option_override_internal): Delete
rs6000_gen_cell_microcode code.
(rs6000_final_prescan_insn): Delete.
(rs6000_opt_vars): Delete the "gen-cell-microcode" and
"warn-cell-microcode" entries.
* config/rs6000/rs6000.h (FINAL_PRESCAN_INSN): Delete.
* config/rs6000/rs6000.md: Delete rs6000_gen_cell_microcode tests
throughout.  Change cc_reg_not_micro_cr0_operand to
cc_reg_not_cr0_operand throughout.
(*extendhi2_noload): Delete.
* config/rs6000/rs6000.opt (mgen-cell-microcode): Replace by stub.
(mwarn-cell-microcode): Delete.
* doc/invoke.texi (RS/6000 and PowerPC Options): Delete
-mgen-cell-microcode and -mwarn-cell-microcode.

gcc/testsuite/
* gcc.target/powerpc/shift-dot.c: Delete -mgen-cell-microcode from
dg-options.
* gfortran.dg/pr80107.f: Delete testcase.

---
 gcc/config/rs6000/predicates.md  |  21 -
 gcc/config/rs6000/rs6000.c   |  51 +---
 gcc/config/rs6000/rs6000.h   |   6 --
 gcc/config/rs6000/rs6000.md  | 120 +++
 gcc/config/rs6000/rs6000.opt |   8 +-
 gcc/doc/invoke.texi  |  10 ---
 gcc/testsuite/gcc.target/powerpc/shift-dot.c |   2 +-
 gcc/testsuite/gfortran.dg/pr80107.f  |   6 --
 8 files changed, 54 insertions(+), 170 deletions(-)
 delete mode 100644 gcc/testsuite/gfortran.dg/pr80107.f

diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md
index e211d3d..961b49f 100644
--- a/gcc/config/rs6000/predicates.md
+++ b/gcc/config/rs6000/predicates.md
@@ -530,25 +530,6 @@ (define_predicate "cc_reg_not_cr0_operand"
   return CR_REGNO_NOT_CR0_P (REGNO (op));
 })
 
-;; Return 1 if op is a register that is a condition register field and if 
generating microcode, not cr0.
-(define_predicate "cc_reg_not_micro_cr0_operand"
-  (match_operand 0 "register_operand")
-{
-  if (GET_CODE (op) == SUBREG)
-op = SUBREG_REG (op);
-
-  if (!REG_P (op))
-return 0;
-
-  if (REGNO (op) > LAST_VIRTUAL_REGISTER)
-return 1;
-
-  if (rs6000_gen_cell_microcode)
-return CR_REGNO_NOT_CR0_P (REGNO (op));
-  else
-return CR_REGNO_P (REGNO (op));
-})
-
 ;; Return 1 if op is a constant integer valid for D field
 ;; or non-special register register.
 (define_predicate "reg_or_short_operand"
@@ -1069,8 +1050,6 @@ (define_predicate "lwa_operand"
 return true;
   if (!memory_operand (inner, mode))
 return false;
-  if (!rs6000_gen_cell_microcode)
-return false;
 
   addr = XEXP (inner, 0);
   if (GET_CODE (addr) == PRE_INC
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 2161e56..a017afc 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -4256,16 +4256,9 @@ rs6000_option_override_internal (bool global_init_p)
error ("SPE not supported in this target");
 }
 
-  /* Disable Cell microcode if we are optimizing for the Cell
- and not optimizing for size.  */
-  if (rs6000_gen_cell_microcode == -1)
-rs6000_gen_cell_microcode = !(rs6000_cpu == PROCESSOR_CELL
-  && !optimize_size);
-
-  /* If we are optimizing big endian systems for space and it's OK to
- use instructions that would be microcoded on the Cell, use the
- load/store multiple and string instructions.  */
-  if (BYTES_BIG_ENDIAN && optimize_size && rs6000_gen_cell_microcode)
+  /* If we are optimizing big endian systems for space, use the load/store
+ multiple and string instructions.  */
+  if (BYTES_BIG_ENDIAN && optimize_size)
 rs6000_isa_flags |= ~rs6000_isa_flags_explicit & (OPTION_MASK_MULTIPLE
  | OPTION_MASK_STRING);
 
@@ -39178,38 +39171,6 @@ rs6000_stack_protect_fail (void)
 : 

Re: [PATCH] Prevent extract_muldiv from introducing an overflow (PR sanitizer/80800)

2017-05-19 Thread Richard Biener
On May 19, 2017 5:47:10 PM GMT+02:00, Alexander Monakov  
wrote:
>On Fri, 19 May 2017, Marek Polacek wrote:
>> > I think it's possible to keep this folding, note that it's valid to
>transform to
>> > 
>> > (n * 1 * z) * 50
>> > 
>> > (i.e. accumulate multiplications on the outermost factor)
>
>(to be precise, if the multiplication is done in a signed type and the
>middle
>constant factor was a negated power of two, the sign change needs to
>remain:
>
>a * -4 * b * 2
>
>needs to be transformed to
>
>a * -1 * b * 8 )
>
>> > so would it be possible to adjust things here to remove the
>innermost
>> > multiplication instead?
>> 
>> I think I'd rather not expand this function any more, sorry.
>
>I'd be happy to look into that myself, if the idea sounds feasible and
>desirable.
>I've never looked at this code before, so I'd appreciate a quick
>yay-or-nay
>before diving in.  Richard, can you share your opinion on this point?

I'd rather extend the fold-binary associate: case to handle this, or do this 
via match.pd pattern(s).

Of course in the end we miss to associate signed integer ops in the reassoc 
pass...

Richard.

>Thanks.
>Alexander



[C++ Patch] Replace a few more error + error with error + inform

2017-05-19 Thread Paolo Carlini

Hi,

while looking into some bugs (eg, c++/71464) I noticed a few more of 
those consecutive errors, which I propose to adjust per the below 
patchlet. The second case in add_method is a bit tricky because in 
principle we'd really like to be more specific (eg, clang talks about 
constructors which cannot be redeclared, member functions which cannot 
be redeclared and many more) and avoid verbose diagnostic, but in the 
below I only try to avoid emitting error + error... Tested x86_64-linux.


Thanks, Paolo.

/


/cp
2017-05-19  Paolo Carlini  

* class.c (add_method): Change pair of errors to error + inform.
(handle_using_decl): Likewise.

/testsuite
2017-05-19  Paolo Carlini  

* g++.dg/cpp0x/inh-ctor3.C: Adjust for dg-message vs dg-error.
* g++.dg/diagnostic/variadic1.C: Likewise.
* g++.dg/gomp/udr-3.C: Likewise.
* g++.dg/overload/error1.C: Likewise.
* g++.dg/overload/error2.C: Likewise.
* g++.dg/template/duplicate1.C: Likewise.
* g++.old-deja/g++.benjamin/warn02.C: Likewise.
* g++.old-deja/g++.brendan/arm2.C: Likewise.
* g++.old-deja/g++.other/redecl2.C: Likewise.
* g++.old-deja/g++.other/redecl4.C: Likewise.
* g++.old-deja/g++.pt/memtemp78.C: Likewise.
Index: cp/class.c
===
--- cp/class.c  (revision 248245)
+++ cp/class.c  (working copy)
@@ -1212,10 +1212,11 @@ add_method (tree type, tree method, bool via_using
continue;
}
  error_at (DECL_SOURCE_LOCATION (method),
-   "%q#D", method);
- error_at (DECL_SOURCE_LOCATION (fn),
-   "conflicts with version inherited from %qT",
-   basef);
+   "%q#D conflicts with version inherited from %qT",
+   method, basef);
+ inform (DECL_SOURCE_LOCATION (fn),
+ "version inherited from %qT declared here",
+ basef);
}
  /* Otherwise defer to the other function.  */
  return false;
@@ -1233,8 +1234,10 @@ add_method (tree type, tree method, bool via_using
}
  else
{
- error ("%q+#D cannot be overloaded", method);
- error ("with %q+#D", fn);
+ error_at (DECL_SOURCE_LOCATION (method),
+   "%q#D cannot be overloaded with %q#D", method, fn);
+ inform (DECL_SOURCE_LOCATION (fn),
+ "previous declaration %q#D", fn);
  return false;
}
}
@@ -1366,16 +1369,21 @@ handle_using_decl (tree using_decl, tree t)
   the same name already present in the current class.  */;
   else
{
- error ("%q+D invalid in %q#T", using_decl, t);
- error ("  because of local method %q+#D with same name",
-old_value);
+ error_at (DECL_SOURCE_LOCATION (using_decl), "%qD invalid in %q#T "
+   "because of local method %q#D with same name",
+   using_decl, t, old_value);
+ inform (DECL_SOURCE_LOCATION (old_value),
+ "local method %q#D declared here", old_value);
  return;
}
 }
   else if (!DECL_ARTIFICIAL (old_value))
 {
-  error ("%q+D invalid in %q#T", using_decl, t);
-  error ("  because of local member %q+#D with same name", old_value);
+  error_at (DECL_SOURCE_LOCATION (using_decl), "%qD invalid in %q#T "
+   "because of local member %q#D with same name",
+   using_decl, t, old_value);
+  inform (DECL_SOURCE_LOCATION (old_value),
+ "local member %q#D declared here", old_value);
   return;
 }
 
Index: testsuite/g++.dg/cpp0x/inh-ctor3.C
===
--- testsuite/g++.dg/cpp0x/inh-ctor3.C  (revision 248244)
+++ testsuite/g++.dg/cpp0x/inh-ctor3.C  (working copy)
@@ -8,7 +8,7 @@ struct B2 {
   B2(int);
 };
 struct D1 : B1, B2 {
-  using B1::B1;// { dg-error "inherited" }
+  using B1::B1;// { dg-message "declared" }
   using B2::B2;// { dg-error "inherited" }
 };// ill-formed: attempts to declare D1(int) twice
 struct D2 : B1, B2 {
Index: testsuite/g++.dg/diagnostic/variadic1.C
===
--- testsuite/g++.dg/diagnostic/variadic1.C (revision 248244)
+++ testsuite/g++.dg/diagnostic/variadic1.C (working copy)
@@ -4,6 +4,6 @@
 template struct B { };
 template struct A
 {
-  B f(); // { dg-error "sizeof\\.\\.\\." }
+  B f(); // { dg-message "sizeof\\.\\.\\." }
   B<42> f();

Re: libbacktrace patch: fix memory allocation buglet on DWARF line table with zero dirs

2017-05-19 Thread Ian Lance Taylor via gcc-patches
On Fri, May 19, 2017 at 6:18 AM, Than McIntosh  wrote:
>
> I wrote:
> == The attached patch to libbacktrace is intended to fix a memory
> == allocation bug involving reading of line table information.
>
> I've revised my previous patch to include a new test ("edtest") that
> verifies the fix.

Thanks.

I changed the use of mvifdiff to use ../move-if-change.  (We use
mvifdiff in libgo to make it less dependent on GCC infrastructure.)

Committed to mainline.

Ian


Re: MinGW compilation warnings in libiberty's xstrndup.c

2017-05-19 Thread Pedro Alves
On 05/19/2017 04:40 PM, Eli Zaretskii wrote:
>> Cc: gdb-patc...@sourceware.org, Thomas Schwinge 
>> From: Pedro Alves 
>> Date: Fri, 19 May 2017 16:22:55 +0100
>>
>> But then, xstrndup.c has at the top:
>>
>> #ifdef HAVE_STRING_H
>> #include 
>> #else
>> # ifdef HAVE_STRINGS_H
>> #  include 
>> # endif
>> #endif
>>
>> So I would expect your build to pick the strnlen declaration from
>> one of the string.h or strings.h mingw headers.  Why didn't it?
> 
> Because MinGW doesn't have it, not unless you build a program that
> will require one of the newer versions of the Windows C runtime
> library.  That's why libiberty's strnlen is being compiled in the
> MinGW build in the first place.

OK, I didn't realize there was a strnlen replacement too.

> 
> Specifically, the MinGW headers do provide a prototype for strnlen if
> the program defines __MSVCRT_VERSION__ to be a high enough version, or
> defines _POSIX_C_SOURCE >= 200809L, but none of these is set by
> default, and is not a good idea, as explained above, for a program
> that needs to run on a wide variety of OS versions.
> 
> IOW, libiberty shouldn't rely on the system headers to provide a
> strnlen prototype when libiberty's strnlen is being included in the
> library as a replacement.

OK, I guess then we're up to figuring out which direction to go.
Either an AC_CHECK_DECL is missing on libiberty's configure,
or the original patch really wanted AC_CHECK_FUNC instead of 
AC_CHECK_DECL.  Or something else, I only look at libiberty's
configury every couple of years and forget how this is all
supposed to work in between.

Thanks,
Pedro Alves



[PATCH GCC]Check tieable TRUNCATE only if inner rtx is register

2017-05-19 Thread Bin Cheng
Hi,
Revision 247881 possibly exposes bug in RTL or ARM backend, while the change 
itself
may be incomplete too.  Given a TRUNCATE rtx with complicated sub-rtx, backend 
may
want to know the complicated sub-rtx happens in context of TRUNCATE in order to 
give
different costs.  This patch adds restriction only checking tieable TRUNCATE if 
its operand
is register.  This is enough for middle-end, it builds up (truncate:SI 
(reg:DI)) in order to setup
conversion cost for GIMPLE optimizations.  On the other hand, targets like 
i386/arm don't
handle register truncation at the moment.

Note, this patch minimize the impact of cost change and workaround PR80754 for 
now.
So far the effect of change in r247881 is to allow smulsi3_highpart_v6 pattern 
to be used
rather than smullsidi, which means it actually gives RA more free in choosing 
registers.
If it's because of the cost change that smulsi3_highpart_v6 is now preferred, 
it could be
suggesting that r247881 is good.  Anyway, it's just my guess before looking 
into rtl passes.

Bootstrap and test ongoing.  Is it OK?

2017-05-13  Bin Cheng  

* rtlanal.c (rtx_cost): Check tieable TRUNCATE only if inner rtx
is register.diff --git a/gcc/rtlanal.c b/gcc/rtlanal.c
index d9f57c3..b211efb 100644
--- a/gcc/rtlanal.c
+++ b/gcc/rtlanal.c
@@ -4165,7 +4165,10 @@ rtx_cost (rtx x, machine_mode mode, enum rtx_code 
outer_code,
   break;
 
 case TRUNCATE:
-  if (MODES_TIEABLE_P (mode, GET_MODE (XEXP (x, 0
+  /* If inner rtx isn't register, fall through and call target hook.
+Backend may want to know that sub-rtx is in truncate.  */
+  if (REG_P (XEXP (x, 0))
+ && MODES_TIEABLE_P (mode, GET_MODE (XEXP (x, 0
{
  total = 0;
  break;


Re: [patch, fortran] PR80333 Namelist dtio write of array of class does not traverse the array

2017-05-19 Thread Jerry DeLisle

On 05/18/2017 07:06 PM, Steve Kargl wrote:

On Thu, May 18, 2017 at 05:16:45PM -0700, Jerry DeLisle wrote:


2017-05-18  Paul Thomas  

PR fortran/80333
* trans-io.c (nml_get_addr_expr): If we are dealing with class
type data set tmp tree to get that address.
(transfer_namelist_element): Set the array spec to point to the
the class data.

2017-05-18  Paul Thomas  
Jerry DeLisle  

PR fortran/80333
* list_read.c (nml_read_obj): Compute pointer into class/type
arrays from the nl->dim information. Update it for each iteration
of the loop for the given object.


Looks ok to me.  A few style comments below.




Agreed on style changes. Fixed those, recompiled, retested, and ...
Committed r248293
A   gcc/testsuite/gfortran.dg/dtio_30.f03
M   gcc/testsuite/ChangeLog
M   gcc/fortran/ChangeLog
M   gcc/fortran/trans-io.c
M   libgfortran/ChangeLog
M   libgfortran/io/list_read.c

Thanks for review.

Jerry


Re: MinGW compilation warnings in libiberty's include/environ.h

2017-05-19 Thread Pedro Alves
On 05/08/2017 04:25 PM, Eli Zaretskii wrote:
> When compiling libiberty (as part of GDB) with MinGW on MS-Windows, I
> see the following warning:
> 
>  gcc -c -DHAVE_CONFIG_H -O2 -gdwarf-4 -g3 -D__USE_MINGW_ACCESS  -I. 
> -I./../include   -W -Wall -Wwrite-strings -Wc++-compat -Wstrict-prototypes 
> -pedantic  -D_GNU_SOURCE ./setenv.c -o setenv.o
>  In file included from ./setenv.c:64:0:
>  ./../include/environ.h:30:1: warning: function declaration isn't a 
> prototype [-Wstrict-prototypes]
>   extern char **environ;
>   ^
> 
> This was already reported 4 years ago, here:
> 
>   https://gcc.gnu.org/ml/gcc-patches/2013-03/msg00471.html
> 
> and was solved back then.  But it looks like the offending code was
> copied to include/environ.h without the fix, and the warning is thus
> back.
> 
> The problem is with this code in environ.h:
> 
>   #ifndef HAVE_ENVIRON_DECL
>   #  ifdef __APPLE__
>   # include 
>   # define environ (*_NSGetEnviron ())
>   #  else
>   extern char **environ;
>   #  endif
>   #  define HAVE_ENVIRON_DECL
>   #endif
> 
> which causes the MinGW compiler to see the declaration of environ,
> whereas MinGW's stdlib.h has this:
> 
>   #ifdef __MSVCRT__
>   # define _environ  (*__p__environ())
>   extern _CRTIMP __cdecl __MINGW_NOTHROW  char ***__p__environ(void);
>   # define _wenviron  (*__p__wenviron())
>   extern _CRTIMP __cdecl __MINGW_NOTHROW  wchar_t ***__p__wenviron(void);
> 
>   #else  /* ! __MSVCRT__ */
>   # ifndef __DECLSPEC_SUPPORTED
>   # define _environ (*_imp___environ_dll)
>   extern char ***_imp___environ_dll;
> 
>   # else  /* __DECLSPEC_SUPPORTED */
>   # define _environ  _environ_dll
>   __MINGW_IMPORT char ** _environ_dll;
>   # endif  /* __DECLSPEC_SUPPORTED */
>   #endif  /* ! __MSVCRT__ */
> 
>   #define environ _environ

So again there's a system header that defines the symbol
but for some reason libiberty still wants to declare/define
it is if it weren't?

That sounds to me like the root issue that should be fixed,
so that these fallback definitions don't come into into play at all.
I.e., why isn't HAVE_ENVIRON_DECL defined on mingw when
setenv.o is built?  Sounds like a decl check is missing
in configure.ac.

Thanks,
Pedro Alves



Re: [PATCH] Prevent extract_muldiv from introducing an overflow (PR sanitizer/80800)

2017-05-19 Thread Alexander Monakov
On Fri, 19 May 2017, Marek Polacek wrote:
> > I think it's possible to keep this folding, note that it's valid to 
> > transform to
> > 
> > (n * 1 * z) * 50
> > 
> > (i.e. accumulate multiplications on the outermost factor)

(to be precise, if the multiplication is done in a signed type and the middle
constant factor was a negated power of two, the sign change needs to remain:

a * -4 * b * 2

needs to be transformed to

a * -1 * b * 8 )

> > so would it be possible to adjust things here to remove the innermost
> > multiplication instead?
> 
> I think I'd rather not expand this function any more, sorry.

I'd be happy to look into that myself, if the idea sounds feasible and 
desirable.
I've never looked at this code before, so I'd appreciate a quick yay-or-nay
before diving in.  Richard, can you share your opinion on this point?

Thanks.
Alexander


Re: MinGW compilation warnings in libiberty's xstrndup.c

2017-05-19 Thread Eli Zaretskii
> Cc: gdb-patc...@sourceware.org, Thomas Schwinge 
> From: Pedro Alves 
> Date: Fri, 19 May 2017 16:22:55 +0100
> 
> But then, xstrndup.c has at the top:
> 
> #ifdef HAVE_STRING_H
> #include 
> #else
> # ifdef HAVE_STRINGS_H
> #  include 
> # endif
> #endif
> 
> So I would expect your build to pick the strnlen declaration from
> one of the string.h or strings.h mingw headers.  Why didn't it?

Because MinGW doesn't have it, not unless you build a program that
will require one of the newer versions of the Windows C runtime
library.  That's why libiberty's strnlen is being compiled in the
MinGW build in the first place.

Specifically, the MinGW headers do provide a prototype for strnlen if
the program defines __MSVCRT_VERSION__ to be a high enough version, or
defines _POSIX_C_SOURCE >= 200809L, but none of these is set by
default, and is not a good idea, as explained above, for a program
that needs to run on a wide variety of OS versions.

IOW, libiberty shouldn't rely on the system headers to provide a
strnlen prototype when libiberty's strnlen is being included in the
library as a replacement.


Re: MinGW compilation warnings in libiberty's waitpid.c

2017-05-19 Thread Pedro Alves
On 05/08/2017 04:27 PM, Eli Zaretskii wrote:
> When compiling libiberty (as part of GDB) with MinGW on MS-Windows, I
> see the following warning:
> 
>  gcc -c -DHAVE_CONFIG_H -O2 -gdwarf-4 -g3 -D__USE_MINGW_ACCESS  -I. 
> -I./../include   -W -Wall -Wwrite-strings -Wc++-compat -Wstrict-prototypes 
> -pedantic  -D_GNU_SOURCE ./waitpid.c -o waitpid.o
>  ./waitpid.c: In function 'waitpid':
>  ./waitpid.c:31:18: warning: implicit declaration of function 'wait' 
> [-Wimplicit-function-declaration]
>   int wpid = wait(stat_loc);
>  ^
> 
> The file waitpid.c should not be built on MinGW, as it is not needed
> on Windows, and will not work if the function is called (because
> there's no 'wait' function on MS-Windows).
> 

Makes sense, but did you check whether there's an obvious place such
a change could be done in configure.ac?  

I wonder what code relies on this replacement, actually.  In liberty,
the only waitpid calls are in pex-unix.c, but those are all guarded
by HAVE_WAITPID.
Maybe it was used at some point when libiberty was a target library?

So I wonder whether we could just unconditionally remove the waitpid
replacement instead.

Thanks,
Pedro Alves



Re: [PATCH] Prevent extract_muldiv from introducing an overflow (PR sanitizer/80800)

2017-05-19 Thread Marek Polacek
On Fri, May 19, 2017 at 01:57:24PM +0300, Alexander Monakov wrote:
> On Fri, 19 May 2017, Richard Biener wrote:
> 
> > On Fri, 19 May 2017, Marek Polacek wrote:
> > 
> > > On Fri, May 19, 2017 at 09:58:45AM +0200, Richard Biener wrote:
> > > > On Fri, 19 May 2017, Marek Polacek wrote:
> > > > 
> > > > > extract_muldiv folds 
> > > > > 
> > > > >   (n * 1 * z) * 50
> > > > > 
> > > > > to
> > > > > 
> > > > >   (n * 50) * z
> > > > > 
> > > > > which is a wrong transformation to do, because it may introduce an 
> > > > > overflow.
> > > > > This resulted in a ubsan false positive.  So we should just disable 
> > > > > this
> > > > > folding altogether.  Does the approach I took make sense?
> 
> I think it's possible to keep this folding, note that it's valid to transform 
> to
> 
> (n * 1 * z) * 50
> 
> (i.e. accumulate multiplications on the outermost factor)
> 
> > > > > 
> > > > > Bootstrapped/regtested on x86_64-linux, ok for trunk?
> > > > 
> > > > Didn't dig very far to identify extract_muldiv, but I guess it's either
> > > > of the following recursions that trigger?
> > > > 
> > > >   /* If we can extract our operation from the LHS, do so and return 
> > > > a
> > > >  new operation.  Likewise for the RHS from a MULT_EXPR.  
> > > > Otherwise,
> > > >  do something only if the second operand is a constant.  */
> > > >   if (same_p
> > > >   && (t1 = extract_muldiv (op0, c, code, wide_type,
> > > >strict_overflow_p)) != 0)
> > > > return fold_build2 (tcode, ctype, fold_convert (ctype, t1),
> > > > fold_convert (ctype, op1));
> > > >   else if (tcode == MULT_EXPR && code == MULT_EXPR
> > > >&& (t1 = extract_muldiv (op1, c, code, wide_type,
> > > > strict_overflow_p)) != 0)
> > > > return fold_build2 (tcode, ctype, fold_convert (ctype, op0),
> > > > fold_convert (ctype, t1));
> > > 
> > > Exactly.  extract_muldiv first gets (n * 1 * z) * 50 so it tries
> > > to fold 50 with (subexpressions) of (n * 1 * z).  So it then tries
> > > (n * 1) * 50, and then n * 50 and then 1 * 50 which finally
> > > works out, so it uses 5 and removes the outermost multiplication.
> 
> so would it be possible to adjust things here to remove the innermost
> multiplication instead?

I think I'd rather not expand this function any more, sorry.

Marek


Re: MinGW compilation warnings in libiberty's xstrndup.c

2017-05-19 Thread Pedro Alves
[Adding Thomas]

On 05/08/2017 04:30 PM, Eli Zaretskii wrote:
> When compiling libiberty (as part of GDB) with MinGW on MS-Windows, I
> see the following warning:
> 
>  gcc -c -DHAVE_CONFIG_H -O2 -gdwarf-4 -g3 -D__USE_MINGW_ACCESS  -I. 
> -I./../include   -W -Wall -Wwrite-strings -Wc++-compat -Wstrict-prototypes 
> -pedantic  -D_GNU_SOURCE ./xstrndup.c -o xstrndup.o
>  ./xstrndup.c: In function 'xstrndup':
>  ./xstrndup.c:51:16: warning: implicit declaration of function 'strnlen' 
> [-Wimplicit-function-declaration]
>   size_t len = strnlen (s, n);
>^
> 
> This happens because libiberty.h uses incorrect guards for the
> prototype of strnlen:
> 
>   #if defined (HAVE_DECL_STRNLEN) && !HAVE_DECL_STRNLEN
>   extern size_t strnlen (const char *, size_t);
>   #endif
> 
> It should use HAVE_STRNLEN instead, because that's the only
> strnlen-related macro defined in config.g when strnlen is probed by
> the configure script.

Looks like the declaration check got added to gcc's configure, but not
elsewhere, with:

commit d968efeac356364c01445013a1a3660e5087cb15
Author: tschwinge 
AuthorDate: Tue Jun 10 09:45:00 2014 +

[PR lto/61334] Declare prototype for strnlen, if needed.

include/
* libiberty.h [defined (HAVE_DECL_STRNLEN) &&
!HAVE_DECL_STRNLEN] (strnlen): New prototype.
gcc/
* configure.ac: Use gcc_AC_CHECK_DECLS to check for strnlen
prototype.
* config.in: Regenerate.
* configure: Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@211401 
138bc75d-0d04-0410-961f-82ee72b054a4


But then, xstrndup.c has at the top:

#ifdef HAVE_STRING_H
#include 
#else
# ifdef HAVE_STRINGS_H
#  include 
# endif
#endif

So I would expect your build to pick the strnlen declaration from
one of the string.h or strings.h mingw headers.  Why didn't it?

Thanks,
Pedro Alves



Re: [PATCH] Introduce symtab_node::dump_{asm_,}name functions.

2017-05-19 Thread Jan Hubicka
> Hello.
> 
> We repeat all over following patterns:
> 
> fprintf (dump_file, "Removing speculative call %s/%i => %s/%i\n",
>  xstrdup_for_dump (edge->caller->name ()),
>  edge->caller->order,
>  xstrdup_for_dump (e2->callee->name ()),
>  e2->callee->order);
> 
> As we already wrap name() and asm_name() with xstrdup_for_dump and the pattern
> of 'name/order' is very common, I suggest to come up with helper functions 
> that
> do that.
> 
> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

We used to have fixed size cyclic buffer for those strings, so it was safe
to invoke name/asm_name few times and still expect the result to be there.
I wonder what happened to those?  Using ggc is bit ugly here, but I suppose
it is OK for debug output...

Honza
> 
> Ready to be installed?
> Martin

> >From 42a746e3db58e24cbd3a4b45ab3f9150fad44928 Mon Sep 17 00:00:00 2001
> From: marxin 
> Date: Fri, 19 May 2017 14:09:25 +0200
> Subject: [PATCH] Introduce symtab_node::dump_{asm_,}name functions.
> 
> gcc/ChangeLog:
> 
> 2017-05-19  Martin Liska  
> 
>   * cgraph.c (cgraph_node::get_create): Use symtab_node::dump_{asm_,}name
>   functions.
>   (cgraph_edge::make_speculative): Likewise.
>   (cgraph_edge::resolve_speculation): Likewise.
>   (cgraph_edge::redirect_call_stmt_to_callee): Likewise.
>   (cgraph_node::dump): Likewise.
>   * cgraph.h: Likewise.
>   * cgraphunit.c (analyze_functions): Likewise.
>   (symbol_table::compile): Likewise.
>   * ipa-cp.c (print_all_lattices): Likewise.
>   (determine_versionability): Likewise.
>   (initialize_node_lattices): Likewise.
>   (ipcp_verify_propagated_values): Likewise.
>   (estimate_local_effects): Likewise.
>   (update_profiling_info): Likewise.
>   (create_specialized_node): Likewise.
>   (perhaps_add_new_callers): Likewise.
>   (decide_about_value): Likewise.
>   (decide_whether_version_node): Likewise.
>   (identify_dead_nodes): Likewise.
>   (ipcp_store_bits_results): Likewise.
>   * ipa-devirt.c (dump_targets): Likewise.
>   (ipa_devirt): Likewise.
>   * ipa-icf.c (sem_item::dump): Likewise.
>   (sem_function::equals): Likewise.
>   (sem_variable::equals): Likewise.
>   (sem_item_optimizer::read_section): Likewise.
>   (sem_item_optimizer::execute): Likewise.
>   (congruence_class::dump): Likewise.
>   * ipa-inline-analysis.c (dump_ipa_call_summary): Likewise.
>   (dump_inline_summary): Likewise.
>   (estimate_node_size_and_time): Likewise.
>   (inline_analyze_function): Likewise.
>   * ipa-inline-transform.c (inline_call): Likewise.
>   * ipa-inline.c (report_inline_failed_reason): Likewise.
>   (want_early_inline_function_p): Likewise.
>   (edge_badness): Likewise.
>   (update_edge_key): Likewise.
>   (inline_small_functions): Likewise.
>   * ipa-profile.c (ipa_profile): Likewise.
>   * ipa-prop.c (ipa_print_node_jump_functions): Likewise.
>   (ipa_make_edge_direct_to_target): Likewise.
>   (remove_described_reference): Likewise.
>   (ipa_impossible_devirt_target): Likewise.
>   (propagate_controlled_uses): Likewise.
>   (ipa_print_node_params): Likewise.
>   (ipcp_transform_function): Likewise.
>   * ipa-pure-const.c (pure_const_read_summary): Likewise.
>   (propagate_pure_const): Likewise.
>   * ipa-reference.c (generate_summary): Likewise.
>   (read_write_all_from_decl): Likewise.
>   (propagate): Likewise.
>   (ipa_reference_read_optimization_summary): Likewise.
>   * ipa-utils.c (ipa_merge_profiles): Likewise.
>   * ipa.c (walk_polymorphic_call_targets): Likewise.
>   (symbol_table::remove_unreachable_nodes): Likewise.
>   (ipa_single_use): Likewise.
>   * passes.c (execute_todo): Likewise.
>   * predict.c (drop_profile): Likewise.
>   * symtab.c (symtab_node::get_dump_name): New function.
>   (symtab_node::dump_name): Likewise.
>   (symtab_node::dump_asm_name): Likewise.
>   (symtab_node::dump_references): Likewise.
>   (symtab_node::dump_referring): Likewise.
>   (symtab_node::dump_base): Likewise.
>   (symtab_node::debug_symtab): Likewise.
>   * tree-sra.c (convert_callers_for_node): Likewise.
>   * tree-ssa-structalias.c (ipa_pta_execute): Likewise.
>   * value-prof.c (init_node_map): Likewise.
> 
> gcc/lto/ChangeLog:
> 
> 2017-05-19  Martin Liska  
> 
>   * lto-symtab.c (lto_cgraph_replace_node): Use
>   symtab_node::dump_{asm_,}name functions.
>   * lto.c (read_cgraph_and_symbols): Likewise.
>   (do_whole_program_analysis): Likewise.
> ---
>  gcc/cgraph.c   | 75 ++
>  gcc/cgraph.h   | 11 +-
>  gcc/ipa-cp.c   | 51 

Re: [PATCH] Avoid signed overflow in num_get::_M_extract_int (PR libstdc++/67214)

2017-05-19 Thread Jonathan Wakely

On 18/05/17 19:10 +0800, Xi Ruoyao wrote:

This UB has been hiding so long...


Indeed! Thanks for the patch.


2017-03-11  Xi Ruoyao  

PR libstdc++/67214
* include/bits/locale_facets.tcc (_M_extract_int):
  Add explicit conversion to avoid signed overflow.
---
 libstdc++-v3/include/bits/locale_facets.tcc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/locale_facets.tcc 
b/libstdc++-v3/include/bits/locale_facets.tcc
index 351190c..5f85d15 100644
--- a/libstdc++-v3/include/bits/locale_facets.tcc
+++ b/libstdc++-v3/include/bits/locale_facets.tcc
@@ -470,7 +470,8 @@ _GLIBCXX_BEGIN_NAMESPACE_LDBL
    bool __testoverflow = false;
    const __unsigned_type __max =
      (__negative && __gnu_cxx::__numeric_traits<_ValueT>::__is_signed)
-     ? -__gnu_cxx::__numeric_traits<_ValueT>::__min
+     ? -static_cast<__unsigned_type>(__gnu_cxx::
+    __numeric_traits<_ValueT>::__min)


Do we need to keep the negation, or can we just cast to
__unsigned_type?



Re: [PATCH] Move symtab_node::dump_table to symbol_table::dump

2017-05-19 Thread Jan Hubicka
> Hello.
> 
> Following mechanical change moves the function to symbol_table where one would
> expect such a function.
> 
> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
> 
> Ready to be installed?
OK,
thanks!
Honza
> Martin

> >From f12a6fc831eb0d78d57572b8fcbb9f170d84d773 Mon Sep 17 00:00:00 2001
> From: marxin 
> Date: Mon, 13 Feb 2017 15:10:07 +0100
> Subject: [PATCH] Move symtab_node::dump_table to symbol_table::dump
> 
> gcc/ChangeLog:
> 
> 2017-02-13  Martin Liska  
> 
>   * cgraph.h: Move symtab_node::dump_table to symbol_table::dump
>   and symtab_node::debug_symtab to symbol_table::debug.
>   * cgraphunit.c (analyze_functions): Use the renamed function.
>   (symbol_table::compile): Likewise.
>   * ipa-cp.c (ipcp_verify_propagated_values): Likewise.
>   * ipa-icf.c (sem_item_optimizer::execute): Likewise.
>   * passes.c (execute_todo): Likewise.
>   * symtab.c (symbol_table::dump): New function.
>   * tree-ssa-structalias.c (ipa_pta_execute): Use the renamed function.
> 
> gcc/lto/ChangeLog:
> 
> 2017-02-13  Martin Liska  
> 
>   * lto.c (read_cgraph_and_symbols): Use the renamed function.
>   (do_whole_program_analysis): Use the renamed function.
> ---
>  gcc/cgraph.h   | 15 +--
>  gcc/cgraphunit.c   |  8 
>  gcc/ipa-cp.c   |  2 +-
>  gcc/ipa-icf.c  |  2 +-
>  gcc/lto/lto.c  |  6 +++---
>  gcc/passes.c   |  2 +-
>  gcc/symtab.c   | 13 +
>  gcc/tree-ssa-structalias.c |  2 +-
>  8 files changed, 21 insertions(+), 29 deletions(-)
> 
> diff --git a/gcc/cgraph.h b/gcc/cgraph.h
> index be4eaee71e2..c630b9e623a 100644
> --- a/gcc/cgraph.h
> +++ b/gcc/cgraph.h
> @@ -411,12 +411,6 @@ public:
>   Return NULL if there's no such node.  */
>static symtab_node *get_for_asmname (const_tree asmname);
>  
> -  /* Dump symbol table to F.  */
> -  static void dump_table (FILE *);
> -
> -  /* Dump symbol table to stderr.  */
> -  static void DEBUG_FUNCTION debug_symtab (void);
> -
>/* Verify symbol table for internal consistency.  */
>static DEBUG_FUNCTION void verify_symtab_nodes (void);
>  
> @@ -2178,6 +2172,15 @@ public:
>/* Set the DECL_ASSEMBLER_NAME and update symtab hashtables.  */
>void change_decl_assembler_name (tree decl, tree name);
>  
> +  /* Dump symbol table to F.  */
> +  void dump (FILE *f);
> +
> +  /* Dump symbol table to stderr.  */
> +  inline DEBUG_FUNCTION void debug (void)
> +  {
> +dump (stderr);
> +  }
> +
>/* Return true if assembler names NAME1 and NAME2 leads to the same symbol
>   name.  */
>static bool assembler_names_equal_p (const char *name1, const char *name2);
> diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
> index 4a949ca9d73..6ec5223c568 100644
> --- a/gcc/cgraphunit.c
> +++ b/gcc/cgraphunit.c
> @@ -1200,7 +1200,7 @@ analyze_functions (bool first_time)
>if (symtab->dump_file)
>  {
>fprintf (symtab->dump_file, "\n\nInitial ");
> -  symtab_node::dump_table (symtab->dump_file);
> +  symtab->dump (symtab->dump_file);
>  }
>  
>if (first_time)
> @@ -1270,7 +1270,7 @@ analyze_functions (bool first_time)
>if (symtab->dump_file)
>  {
>fprintf (symtab->dump_file, "\n\nReclaimed ");
> -  symtab_node::dump_table (symtab->dump_file);
> +  symtab->dump (symtab->dump_file);
>  }
>bitmap_obstack_release (NULL);
>ggc_collect ();
> @@ -2477,7 +2477,7 @@ symbol_table::compile (void)
>if (dump_file)
>  {
>fprintf (dump_file, "Optimized ");
> -  symtab_node:: dump_table (dump_file);
> +  symtab->dump (dump_file);
>  }
>if (post_ipa_mem_report)
>  {
> @@ -2543,7 +2543,7 @@ symbol_table::compile (void)
>if (dump_file)
>  {
>fprintf (dump_file, "\nFinal ");
> -  symtab_node::dump_table (dump_file);
> +  symtab->dump (dump_file);
>  }
>if (!flag_checking)
>  return;
> diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
> index b97d7af854f..676f555718e 100644
> --- a/gcc/ipa-cp.c
> +++ b/gcc/ipa-cp.c
> @@ -1399,7 +1399,7 @@ ipcp_verify_propagated_values (void)
>   {
> if (dump_file)
>   {
> -   symtab_node::dump_table (dump_file);
> +   symtab->dump (dump_file);
> fprintf (dump_file, "\nIPA lattices after constant "
>  "propagation, before gcc_unreachable:\n");
> print_all_lattices (dump_file, true, false);
> diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c
> index b9a5b4f2546..92b93b53b85 100644
> --- a/gcc/ipa-icf.c
> +++ b/gcc/ipa-icf.c
> @@ -2643,7 +2643,7 @@ sem_item_optimizer::execute (void)
>bool merged_p = merge_classes (prev_class_count);
>  
>if (dump_file && (dump_flags & TDF_DETAILS))
> -symtab_node::dump_table (dump_file);
> +symtab->dump (dump_file);
>  
>return 

[PATCH] Introduce symtab_node::dump_{asm_,}name functions.

2017-05-19 Thread Martin Liška
Hello.

We repeat all over following patterns:

  fprintf (dump_file, "Removing speculative call %s/%i => %s/%i\n",
   xstrdup_for_dump (edge->caller->name ()),
   edge->caller->order,
   xstrdup_for_dump (e2->callee->name ()),
   e2->callee->order);

As we already wrap name() and asm_name() with xstrdup_for_dump and the pattern
of 'name/order' is very common, I suggest to come up with helper functions that
do that.

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

Ready to be installed?
Martin
>From 42a746e3db58e24cbd3a4b45ab3f9150fad44928 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Fri, 19 May 2017 14:09:25 +0200
Subject: [PATCH] Introduce symtab_node::dump_{asm_,}name functions.

gcc/ChangeLog:

2017-05-19  Martin Liska  

	* cgraph.c (cgraph_node::get_create): Use symtab_node::dump_{asm_,}name
	functions.
	(cgraph_edge::make_speculative): Likewise.
	(cgraph_edge::resolve_speculation): Likewise.
	(cgraph_edge::redirect_call_stmt_to_callee): Likewise.
	(cgraph_node::dump): Likewise.
	* cgraph.h: Likewise.
	* cgraphunit.c (analyze_functions): Likewise.
	(symbol_table::compile): Likewise.
	* ipa-cp.c (print_all_lattices): Likewise.
	(determine_versionability): Likewise.
	(initialize_node_lattices): Likewise.
	(ipcp_verify_propagated_values): Likewise.
	(estimate_local_effects): Likewise.
	(update_profiling_info): Likewise.
	(create_specialized_node): Likewise.
	(perhaps_add_new_callers): Likewise.
	(decide_about_value): Likewise.
	(decide_whether_version_node): Likewise.
	(identify_dead_nodes): Likewise.
	(ipcp_store_bits_results): Likewise.
	* ipa-devirt.c (dump_targets): Likewise.
	(ipa_devirt): Likewise.
	* ipa-icf.c (sem_item::dump): Likewise.
	(sem_function::equals): Likewise.
	(sem_variable::equals): Likewise.
	(sem_item_optimizer::read_section): Likewise.
	(sem_item_optimizer::execute): Likewise.
	(congruence_class::dump): Likewise.
	* ipa-inline-analysis.c (dump_ipa_call_summary): Likewise.
	(dump_inline_summary): Likewise.
	(estimate_node_size_and_time): Likewise.
	(inline_analyze_function): Likewise.
	* ipa-inline-transform.c (inline_call): Likewise.
	* ipa-inline.c (report_inline_failed_reason): Likewise.
	(want_early_inline_function_p): Likewise.
	(edge_badness): Likewise.
	(update_edge_key): Likewise.
	(inline_small_functions): Likewise.
	* ipa-profile.c (ipa_profile): Likewise.
	* ipa-prop.c (ipa_print_node_jump_functions): Likewise.
	(ipa_make_edge_direct_to_target): Likewise.
	(remove_described_reference): Likewise.
	(ipa_impossible_devirt_target): Likewise.
	(propagate_controlled_uses): Likewise.
	(ipa_print_node_params): Likewise.
	(ipcp_transform_function): Likewise.
	* ipa-pure-const.c (pure_const_read_summary): Likewise.
	(propagate_pure_const): Likewise.
	* ipa-reference.c (generate_summary): Likewise.
	(read_write_all_from_decl): Likewise.
	(propagate): Likewise.
	(ipa_reference_read_optimization_summary): Likewise.
	* ipa-utils.c (ipa_merge_profiles): Likewise.
	* ipa.c (walk_polymorphic_call_targets): Likewise.
	(symbol_table::remove_unreachable_nodes): Likewise.
	(ipa_single_use): Likewise.
	* passes.c (execute_todo): Likewise.
	* predict.c (drop_profile): Likewise.
	* symtab.c (symtab_node::get_dump_name): New function.
	(symtab_node::dump_name): Likewise.
	(symtab_node::dump_asm_name): Likewise.
	(symtab_node::dump_references): Likewise.
	(symtab_node::dump_referring): Likewise.
	(symtab_node::dump_base): Likewise.
	(symtab_node::debug_symtab): Likewise.
	* tree-sra.c (convert_callers_for_node): Likewise.
	* tree-ssa-structalias.c (ipa_pta_execute): Likewise.
	* value-prof.c (init_node_map): Likewise.

gcc/lto/ChangeLog:

2017-05-19  Martin Liska  

	* lto-symtab.c (lto_cgraph_replace_node): Use
	symtab_node::dump_{asm_,}name functions.
	* lto.c (read_cgraph_and_symbols): Likewise.
	(do_whole_program_analysis): Likewise.
---
 gcc/cgraph.c   | 75 ++
 gcc/cgraph.h   | 11 +-
 gcc/ipa-cp.c   | 51 +++---
 gcc/ipa-devirt.c   | 15 
 gcc/ipa-icf.c  | 31 ++--
 gcc/ipa-inline-analysis.c  | 15 
 gcc/ipa-inline-transform.c |  8 ++---
 gcc/ipa-inline.c   | 63 ++--
 gcc/ipa-profile.c  |  6 ++--
 gcc/ipa-prop.c | 90 +++---
 gcc/ipa-pure-const.c   | 15 +++-
 gcc/ipa-reference.c| 27 ++
 gcc/ipa-utils.c|  5 ++-
 gcc/ipa.c  | 20 +--
 gcc/lto/lto-symtab.c   |  7 ++--
 gcc/predict.c  | 14 
 gcc/symtab.c   | 42 --
 gcc/tree-sra.c |  7 ++--
 gcc/value-prof.c   | 19 --
 19 files changed, 229 insertions(+), 292 deletions(-)

diff --git a/gcc/cgraph.c 

[PATCH] Move symtab_node::dump_table to symbol_table::dump

2017-05-19 Thread Martin Liška
Hello.

Following mechanical change moves the function to symbol_table where one would
expect such a function.

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

Ready to be installed?
Martin
>From f12a6fc831eb0d78d57572b8fcbb9f170d84d773 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Mon, 13 Feb 2017 15:10:07 +0100
Subject: [PATCH] Move symtab_node::dump_table to symbol_table::dump

gcc/ChangeLog:

2017-02-13  Martin Liska  

	* cgraph.h: Move symtab_node::dump_table to symbol_table::dump
	and symtab_node::debug_symtab to symbol_table::debug.
	* cgraphunit.c (analyze_functions): Use the renamed function.
	(symbol_table::compile): Likewise.
	* ipa-cp.c (ipcp_verify_propagated_values): Likewise.
	* ipa-icf.c (sem_item_optimizer::execute): Likewise.
	* passes.c (execute_todo): Likewise.
	* symtab.c (symbol_table::dump): New function.
	* tree-ssa-structalias.c (ipa_pta_execute): Use the renamed function.

gcc/lto/ChangeLog:

2017-02-13  Martin Liska  

	* lto.c (read_cgraph_and_symbols): Use the renamed function.
	(do_whole_program_analysis): Use the renamed function.
---
 gcc/cgraph.h   | 15 +--
 gcc/cgraphunit.c   |  8 
 gcc/ipa-cp.c   |  2 +-
 gcc/ipa-icf.c  |  2 +-
 gcc/lto/lto.c  |  6 +++---
 gcc/passes.c   |  2 +-
 gcc/symtab.c   | 13 +
 gcc/tree-ssa-structalias.c |  2 +-
 8 files changed, 21 insertions(+), 29 deletions(-)

diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index be4eaee71e2..c630b9e623a 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -411,12 +411,6 @@ public:
  Return NULL if there's no such node.  */
   static symtab_node *get_for_asmname (const_tree asmname);
 
-  /* Dump symbol table to F.  */
-  static void dump_table (FILE *);
-
-  /* Dump symbol table to stderr.  */
-  static void DEBUG_FUNCTION debug_symtab (void);
-
   /* Verify symbol table for internal consistency.  */
   static DEBUG_FUNCTION void verify_symtab_nodes (void);
 
@@ -2178,6 +2172,15 @@ public:
   /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables.  */
   void change_decl_assembler_name (tree decl, tree name);
 
+  /* Dump symbol table to F.  */
+  void dump (FILE *f);
+
+  /* Dump symbol table to stderr.  */
+  inline DEBUG_FUNCTION void debug (void)
+  {
+dump (stderr);
+  }
+
   /* Return true if assembler names NAME1 and NAME2 leads to the same symbol
  name.  */
   static bool assembler_names_equal_p (const char *name1, const char *name2);
diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index 4a949ca9d73..6ec5223c568 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -1200,7 +1200,7 @@ analyze_functions (bool first_time)
   if (symtab->dump_file)
 {
   fprintf (symtab->dump_file, "\n\nInitial ");
-  symtab_node::dump_table (symtab->dump_file);
+  symtab->dump (symtab->dump_file);
 }
 
   if (first_time)
@@ -1270,7 +1270,7 @@ analyze_functions (bool first_time)
   if (symtab->dump_file)
 {
   fprintf (symtab->dump_file, "\n\nReclaimed ");
-  symtab_node::dump_table (symtab->dump_file);
+  symtab->dump (symtab->dump_file);
 }
   bitmap_obstack_release (NULL);
   ggc_collect ();
@@ -2477,7 +2477,7 @@ symbol_table::compile (void)
   if (dump_file)
 {
   fprintf (dump_file, "Optimized ");
-  symtab_node:: dump_table (dump_file);
+  symtab->dump (dump_file);
 }
   if (post_ipa_mem_report)
 {
@@ -2543,7 +2543,7 @@ symbol_table::compile (void)
   if (dump_file)
 {
   fprintf (dump_file, "\nFinal ");
-  symtab_node::dump_table (dump_file);
+  symtab->dump (dump_file);
 }
   if (!flag_checking)
 return;
diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index b97d7af854f..676f555718e 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -1399,7 +1399,7 @@ ipcp_verify_propagated_values (void)
 	{
 	  if (dump_file)
 		{
-		  symtab_node::dump_table (dump_file);
+		  symtab->dump (dump_file);
 		  fprintf (dump_file, "\nIPA lattices after constant "
 			   "propagation, before gcc_unreachable:\n");
 		  print_all_lattices (dump_file, true, false);
diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c
index b9a5b4f2546..92b93b53b85 100644
--- a/gcc/ipa-icf.c
+++ b/gcc/ipa-icf.c
@@ -2643,7 +2643,7 @@ sem_item_optimizer::execute (void)
   bool merged_p = merge_classes (prev_class_count);
 
   if (dump_file && (dump_flags & TDF_DETAILS))
-symtab_node::dump_table (dump_file);
+symtab->dump (dump_file);
 
   return merged_p;
 }
diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
index a7d5e450ea0..94fd165b3e0 100644
--- a/gcc/lto/lto.c
+++ b/gcc/lto/lto.c
@@ -2927,7 +2927,7 @@ read_cgraph_and_symbols (unsigned nfiles, const char **fnames)
   if (symtab->dump_file)
 {
   fprintf (symtab->dump_file, "Before merging:\n");
-  symtab_node::dump_table (symtab->dump_file);
+  symtab->dump (symtab->dump_file);
 }
   if (!flag_ltrans)
 {
@@ 

Re: [PATCH] Try harder to fix recently introduced crashes in ggc_collect

2017-05-19 Thread Bernd Edlinger
On 05/19/17 16:10, Nathan Sidwell wrote:
> On 05/19/2017 10:05 AM, Bernd Edlinger wrote:
> 
>> hwi cannot be the root cause of the problem,
>> because it can only be long_integer_type_node
>> or long_long_integer_type_node, otherwise
>> an error would be triggered.
> 
> that's the error I made with the static fns.  PCH moves things around, 
> so anything that can be streamed via PCH must be GTY marked.  Also, I'm 
> not sure if the current GC is a compacting GC (given PCH can compact 
> things?)
> 
> Nathan

I did three boot-straps with this patch on the 0515-snapshot, and
the results are not yet completely stable:

One time stage 3 failed as:
lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o lto/lto-partition.o 
lto/lto-symtab.o libbackend.a main.o libcommon-target.a libcommon.a 
../libcpp/libcpp.a ../libdecnumber/libdecnumber.a 
-L/home/ed/gnu/gcc-build/./isl/.libs  -lisl 
-L/home/ed/gnu/gcc-build/./gmp/.libs -L/home/ed/gnu/gcc-build/./mpfr/src/.libs 
-L/home/ed/gnu/gcc-build/./mpc/src/.libs -lmpc -lmpfr -lgmp -rdynamic -ldl  
-L./../zlib -lz libcommon.a ../libcpp/libcpp.a   
../libbacktrace/.libs/libbacktrace.a ../libiberty/libiberty.a 
../libdecnumber/libdecnumber.a
tree-tailcall.o:(.debug_info+0x142b0): relocation truncated to fit: R_X86_64_8 
against `.debug_str'
collect2: Fehler: ld gab 1 als Ende-Status zurück
make[3]: *** [lto1] Fehler 1
make[3]: *** Warte auf noch nicht beendete Prozesse...
rm fsf-funding.pod gcov.pod gfdl.pod cpp.pod gpl.pod gcc.pod gcov-tool.pod 
gcov-dump.pod gfortran.pod gccgo.pod
make[3]: Verlasse Verzeichnis '/home/ed/gnu/gcc-build/gcc'
make[2]: *** [all-stage3-gcc] Fehler 2
make[2]: Verlasse Verzeichnis '/home/ed/gnu/gcc-build'
make[1]: *** [stage3-bubble] Fehler 2
make[1]: Verlasse Verzeichnis '/home/ed/gnu/gcc-build'
make: *** [all] Fehler 2

No idea if this is caused by gcc or binutils, I use binutils-2.28.
Two times boot-strap succeeded, but once in the test suite I saw this:

FAIL: gfortran.dg/minloc_3.f90   -O1  (internal compiler error)
FAIL: gfortran.dg/minloc_3.f90   -O1  (test for excess errors)
Excess errors:
/home/ed/gnu/gcc-8-20170514/gcc/testsuite/gfortran.dg/minloc_3.f90:48:0: 
internal compiler error: tree check: expected class 'type', have 'exceptional' 
(error_mark) in create_tmp_var, at gimple-expr.c:474
0xe90a67 tree_class_check_failed(tree_node const*, tree_code_class, char 
const*, int, char const*)
../../gcc-8-20170514/gcc/tree.c:9911
0x943bbd tree_class_check(tree_node*, tree_code_class, char const*, int, char 
const*)
../../gcc-8-20170514/gcc/tree.h:3206
0x943bbd create_tmp_var(tree_node*, char const*)
../../gcc-8-20170514/gcc/gimple-expr.c:474
0x967ccc voidify_wrapper_expr(tree_node*, tree_node*)
../../gcc-8-20170514/gcc/gimplify.c:1073
0x96f841 gimplify_statement_list
../../gcc-8-20170514/gcc/gimplify.c:1712
0x96f841 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), 
int)
../../gcc-8-20170514/gcc/gimplify.c:11686
0x973ec8 gimplify_stmt(tree_node**, gimple**)
../../gcc-8-20170514/gcc/gimplify.c:6517
0x97935e gimplify_cond_expr
../../gcc-8-20170514/gcc/gimplify.c:3991
0x96ffe8 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), 
int)
../../gcc-8-20170514/gcc/gimplify.c:11215
0x973ec8 gimplify_stmt(tree_node**, gimple**)
../../gcc-8-20170514/gcc/gimplify.c:6517
0x96f87b gimplify_statement_list
../../gcc-8-20170514/gcc/gimplify.c:1718
0x96f87b gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), 
int)
../../gcc-8-20170514/gcc/gimplify.c:11686
0x973ec8 gimplify_stmt(tree_node**, gimple**)
../../gcc-8-20170514/gcc/gimplify.c:6517
0x97033c gimplify_and_add(tree_node*, gimple**)
../../gcc-8-20170514/gcc/gimplify.c:435
0x97033c gimplify_loop_expr
../../gcc-8-20170514/gcc/gimplify.c:1692
0x97033c gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), 
int)
../../gcc-8-20170514/gcc/gimplify.c:11462
0x973ec8 gimplify_stmt(tree_node**, gimple**)
../../gcc-8-20170514/gcc/gimplify.c:6517
0x96f87b gimplify_statement_list
../../gcc-8-20170514/gcc/gimplify.c:1718
0x96f87b gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), 
int)
../../gcc-8-20170514/gcc/gimplify.c:11686
0x973ec8 gimplify_stmt(tree_node**, gimple**)
../../gcc-8-20170514/gcc/gimplify.c:6517


Anyway, I am going to commit my changes now, as at least the crashes which
go thru gt_ggc_mx_cxx_binding have stopped.


Bernd.

[C++ PATCH] OVERLOAD iterators #8

2017-05-19 Thread Nathan Sidwell
This patch gets the remaining stragglers outside of name-lookup. 
Nothing particularly exciting here.


Remaining patches will be primarily in name-lookup.c, with a few in 
cp-tree.h, tree.c and the parser.  These will be the patches that are 
the significant changes (all this lot was just ground work!)


nathan
--
Nathan Sidwell
2017-05-19  Nathan Sidwell  

	* call.c (add_list_candidates): Use OVL_FIRST.
	(build_new_method_call_1): Likewise.
	* cp-tree.h (OVL_SINGLE_P): New.
	(TYPE_HIDDEN_P): New.
	* decl.c (xref_tag_1): Use TYPE_HIDDEN_P.
	* dump.c (cp_tump_tree): Adjust overload dumping.
	* error.c (dump_decl): Use OVL_SINGLE_P, simplify context
	printing.
	* method.c (lazily_declare_fn): Assert we added it.
	* parser.c (cp_parser_nested_name_specifier): Use OVL_SINGLE_P,
	OVL_FIRST.
	(cp_parser_template_name): Use lkp_iterator.
	* pt.c (begin_template_parm_list): Fixup comment.
	(instantiate_class_template_1): Use TYPE_HIDDEN_P.
	* tree.c (ovl_iterator::remove_node): Cope with inherited ctors.
	(ovl_scope): Use lkp_iterator.

Index: call.c
===
--- call.c	(revision 248265)
+++ call.c	(working copy)
@@ -3666,7 +3666,7 @@ add_list_candidates (tree fns, tree firs
  avoid the copy constructor call for copy-list-initialization.  */
   flags |= LOOKUP_NO_NARROWING;
 
-  unsigned nart = num_artificial_parms_for (get_first_fn (fns)) - 1;
+  unsigned nart = num_artificial_parms_for (OVL_FIRST (fns)) - 1;
   tree init_list = (*args)[nart];
 
   /* Always use the default constructor if the list is empty (DR 990).  */
@@ -8539,7 +8539,7 @@ build_new_method_call_1 (tree instance,
   gcc_assert (TREE_CODE (fns) == FUNCTION_DECL
 	  || TREE_CODE (fns) == TEMPLATE_DECL
 	  || TREE_CODE (fns) == OVERLOAD);
-  fn = get_first_fn (fns);
+  fn = OVL_FIRST (fns);
   name = DECL_NAME (fn);
 
   basetype = TYPE_MAIN_VARIANT (TREE_TYPE (instance));
@@ -8708,7 +8708,7 @@ build_new_method_call_1 (tree instance,
 	  tree errname = name;
 	  if (IDENTIFIER_CTOR_OR_DTOR_P (errname))
 		{
-		  tree fn = DECL_ORIGIN (get_first_fn (fns));
+		  tree fn = DECL_ORIGIN (OVL_FIRST (fns));
 		  errname = DECL_NAME (fn);
 		}
 	  if (explicit_targs)
Index: cp-tree.h
===
--- cp-tree.h	(revision 248265)
+++ cp-tree.h	(working copy)
@@ -655,6 +655,10 @@ typedef struct ptrmem_cst * ptrmem_cst_t
 /* The name of the overload set.  */
 #define OVL_NAME(NODE) DECL_NAME (OVL_FIRST (NODE))
 
+/* Whether this is a single member overload.  */
+#define OVL_SINGLE_P(NODE) \
+  (TREE_CODE (NODE) != OVERLOAD || !OVL_CHAIN (NODE))
+
 struct GTY(()) tree_overload {
   struct tree_common common;
   tree function;
@@ -3750,6 +3754,11 @@ more_aggr_init_expr_args_p (const aggr_i
   (DECL_LANG_SPECIFIC (TYPE_FUNCTION_OR_TEMPLATE_DECL_CHECK (NODE)) \
->u.base.anticipated_p)
 
+/* True if this is a hidden class type.*/
+#define TYPE_HIDDEN_P(NODE) \
+  (DECL_LANG_SPECIFIC (TYPE_NAME (NODE)) \
+   && DECL_ANTICIPATED (TYPE_NAME (NODE)))
+
 /* True for artificial decls added for OpenMP privatized non-static
data members.  */
 #define DECL_OMP_PRIVATIZED_MEMBER(NODE) \
Index: decl.c
===
--- decl.c	(revision 248265)
+++ decl.c	(working copy)
@@ -13636,16 +13636,18 @@ xref_tag_1 (enum tag_types tag_code, tre
 	}
 
   /* Make injected friend class visible.  */
-  if (scope != ts_within_enclosing_non_class
-	  && hidden_name_p (TYPE_NAME (t)))
+  if (scope != ts_within_enclosing_non_class && TYPE_HIDDEN_P (t))
 	{
-	  DECL_ANTICIPATED (TYPE_NAME (t)) = 0;
-	  DECL_FRIEND_P (TYPE_NAME (t)) = 0;
+	  tree decl = TYPE_NAME (t);
+
+	  DECL_ANTICIPATED (decl) = false;
+	  DECL_FRIEND_P (decl) = false;
 
 	  if (TYPE_TEMPLATE_INFO (t))
 	{
-	  DECL_ANTICIPATED (TYPE_TI_TEMPLATE (t)) = 0;
-	  DECL_FRIEND_P (TYPE_TI_TEMPLATE (t)) = 0;
+	  tree tmpl = TYPE_TI_TEMPLATE (t);
+	  DECL_ANTICIPATED (tmpl) = false;
+	  DECL_FRIEND_P (tmpl) = false;
 	}
 	}
 }
Index: dump.c
===
--- dump.c	(revision 248265)
+++ dump.c	(working copy)
@@ -364,8 +364,10 @@ cp_dump_tree (void* dump_info, tree t)
   break;
 
 case OVERLOAD:
-  dump_child ("crnt", OVL_CURRENT (t));
-  dump_child ("chan", OVL_CHAIN (t));
+  dump_child ("name", OVL_NAME (t));
+  if (!dump_flag (di, TDF_SLIM, t))
+	for (lkp_iterator iter (t); iter; ++iter)
+	  dump_child ("chld", *iter);
   break;
 
 case TRY_BLOCK:
Index: error.c
===
--- error.c	(revision 248265)
+++ error.c	(working copy)
@@ -1189,17 +1189,16 @@ dump_decl (cxx_pretty_printer *pp, tree
   break;
 
 case OVERLOAD:
-  if (OVL_CHAIN (t))
+  if (!OVL_SINGLE_P (t))
 	{
-	  t = OVL_CURRENT (t);
-	  if 

Re: [PATCH] Try harder to fix recently introduced crashes in ggc_collect

2017-05-19 Thread Nathan Sidwell

On 05/19/2017 10:05 AM, Bernd Edlinger wrote:


hwi cannot be the root cause of the problem,
because it can only be long_integer_type_node
or long_long_integer_type_node, otherwise
an error would be triggered.


that's the error I made with the static fns.  PCH moves things around, 
so anything that can be streamed via PCH must be GTY marked.  Also, I'm 
not sure if the current GC is a compacting GC (given PCH can compact 
things?)


nathan
--
Nathan Sidwell


Re: [PATCH] Try harder to fix recently introduced crashes in ggc_collect

2017-05-19 Thread Bernd Edlinger
On 05/19/17 09:51, Richard Biener wrote:
> On Thu, 18 May 2017, Bernd Edlinger wrote:
> 
>> Hi,
>>
>> unfortunately the first patch was still insufficient.  I identified many
>> more relatively new places where static tree objects are invisible to
>> GC.
>>
>> Nathan, whatever you are doing, please do it a bit more slowly, thanks.
>>
>> Bootstrap and reg-testing on x86_64-pc-linux-gnu in progress.
>> Is it OK after successful reg-testing?
> 
> Index: gcc/c-family/c-format.c
> ===
> --- gcc/c-family/c-format.c (revision 248242)
> +++ gcc/c-family/c-format.c (working copy)
> @@ -55,6 +55,8 @@ struct function_format_info
>   
>   /* Initialized in init_dynamic_diag_info.  */
>   static GTY(()) tree local_tree_type_node;
> +static GTY(()) tree hwi;
> +static GTY(()) tree locus;
>   
>   static bool decode_format_attr (tree, function_format_info *, int);
>   static int decode_format_type (const char *);
> @@ -3675,8 +3677,6 @@ find_length_info_modifier_index (const format_leng
>   static void
>   init_dynamic_asm_fprintf_info (void)
>   {
> -  static tree hwi;
> -
> if (!hwi)
>   {
> format_length_info *new_asm_fprintf_length_specs;
> @@ -3734,8 +3734,6 @@ init_dynamic_asm_fprintf_info (void)
>   static void
>   init_dynamic_gfc_info (void)
>   {
> -  static tree locus;
> -
> if (!locus)
>   {
> static format_char_info *gfc_fci;
> @@ -3828,8 +3826,6 @@ init_dynamic_diag_info (void)
>  local_tree_type_node = void_type_node;
>   }
>   
> -  static tree hwi;
> -
> 
> you are commoning 'hwi' here.   Also a bad (very short) name for a global
> (even if static).
> 
> I'll leave review to Nathan anyway.
> 
> Richard.
> 

Hmm, yes, I'll drop the 'hwi' change, thus only
move 'locus' because:

hwi cannot be the root cause of the problem,
because it can only be long_integer_type_node
or long_long_integer_type_node, otherwise
an error would be triggered.


>>
>> Thanks
>> Bernd.
>>
>>
>> On 05/18/17 17:33, Richard Biener wrote:
>>> On May 18, 2017 5:15:43 PM GMT+02:00, Bernd Edlinger 
>>>  wrote:
 Hi,


 this attempts to fix occasional segmentation faults that are present in
 the current snapshot, while previous snapshot was stable.

 I observed numerous crashes but all were non-reproducible,
 like the following example:

 In file included from
 /home/ed/gnu/gcc-build-1/x86_64-pc-linux-gnu/libstdc++-v3/include/string:52:0,
from
 /home/ed/gnu/gcc-8-20170514-1/gcc/testsuite/g++.dg/asan/asan_test_config.h:19,
from
 /home/ed/gnu/gcc-8-20170514-1/gcc/testsuite/g++.dg/asan/asan_test_utils.h:17,
from
 /home/ed/gnu/gcc-8-20170514-1/gcc/testsuite/g++.dg/asan/asan_globals_test.cc:12,
from
 /home/ed/gnu/gcc-8-20170514-1/gcc/testsuite/g++.dg/asan/asan_globals_test-wrapper.cc:2:
 /home/ed/gnu/gcc-build-1/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.h:6277:22:

 internal compiler error: Segmentation fault
 0xd7e17f crash_signal
   ../../gcc-8-20170514-1/gcc/toplev.c:337
 0x8f23fe ggc_set_mark(void const*)
   ../../gcc-8-20170514-1/gcc/ggc-page.c:1546
 0x7e6a5f gt_ggc_mx_lang_tree_node(void*)
   ./gt-cp-tree.h:133
 0x7e8c7a gt_ggc_mx_lang_tree_node(void*)
   ./gt-cp-tree.h:235
 0x7e8882 gt_ggc_mx_lang_tree_node(void*)
   ./gt-cp-tree.h:365
 0x81b26d gt_ggc_mx_cp_binding_level(void*)
   ./gt-cp-name-lookup.h:72
 0x7e6d85 gt_ggc_mx_lang_tree_node(void*)
   ./gt-cp-tree.h:648
 0x7e8ad2 gt_ggc_mx_lang_tree_node(void*)
   ./gt-cp-tree.h:221
 0x7e8eeb gt_ggc_mx_lang_tree_node(void*)
   ./gt-cp-tree.h:337
 0x7e8a3c gt_ggc_mx_lang_tree_node(void*)
   ./gt-cp-tree.h:441
 0x7e7304 gt_ggc_mx_lang_tree_node(void*)
   ./gt-cp-tree.h:606
 0x81b352 gt_ggc_mx_cxx_binding(void*)
   ./gt-cp-name-lookup.h:60
 0x7e6d85 gt_ggc_mx_lang_tree_node(void*)
   ./gt-cp-tree.h:648
 0x7e8ef5 gt_ggc_mx_lang_tree_node(void*)
   ./gt-cp-tree.h:336
 0x7e8a3c gt_ggc_mx_lang_tree_node(void*)
   ./gt-cp-tree.h:441
 0xb2edbe void gt_ggc_mx(vec*)
   ../../gcc-8-20170514-1/gcc/vec.h:1110
 0xb2edbe gt_ggc_mx_vec_tree_va_gc_(void*)
   /home/ed/gnu/gcc-build-1/gcc/gtype-desc.c:1737
 0xac59f5 ggc_mark_root_tab
   ../../gcc-8-20170514-1/gcc/ggc-common.c:77
 0xac5c50 ggc_mark_roots()
   ../../gcc-8-20170514-1/gcc/ggc-common.c:94
 0x8f2de7 ggc_collect()
   ../../gcc-8-20170514-1/gcc/ggc-page.c:2206
 Please submit a full bug report,
 with preprocessed source if appropriate.
 Please include the 

Re: OpenACC 2.5 default (present) clause

2017-05-19 Thread Thomas Schwinge
Hi!

On Wed, 10 May 2017 17:48:36 +0200, Jakub Jelinek  wrote:
> On Fri, Apr 07, 2017 at 05:08:55PM +0200, Thomas Schwinge wrote:
> > OpenACC 2.5 added a default (present) clause, which "causes all arrays or
> > variables of aggregate data type used in the compute construct that have
> > implicitly determined data attributes to be treated as if they appeared
> > in a present clause".  [...] OK for trunk in next stage 1?

> > @@ -6897,6 +6900,7 @@ omp_default_clause (struct gimplify_omp_ctx *ctx, 
> > tree decl,
> >  found_outer:
> >break;
> >  
> > +case OMP_CLAUSE_DEFAULT_PRESENT:
> >  default:
> >gcc_unreachable ();
> >  }
> 
> What is the point of this hunk?  Document that present clause is not in
> OpenMP?

Right.

> I don't think that is needed.

As you please.

> > +   case 0 | GOVD_MAP_FORCE:
> > + kind = GOMP_MAP_TOFROM | GOMP_MAP_FLAG_FORCE;
> > + break;
> 
> Please drop the "0 | ".

Removed; I thought that was a good way to relate this "case" to the
"case 0" just above.

> > @@ -357,7 +357,9 @@ enum omp_clause_code {
> >/* OpenMP clause: ordered [(constant-integer-expression)].  */
> >OMP_CLAUSE_ORDERED,
> >  
> > -  /* OpenMP clause: default.  */
> > +  /* OpenACC clause: default ( none | present ).
> > +
> > + OpenMP clause: default ( firstprivate | none | private | shared ). */
> >OMP_CLAUSE_DEFAULT,
> >  
> >/* OpenACC/OpenMP clause: collapse (constant-integer-expression).  */
> 
> I think this hunk isn't needed (plus it is not accurate anyway).

Now you got me curious: why isn't it accurate?  Anyway, I changed that to
just say "OpenACC/OpenMP clause: default".

> Otherwise LGTM.

Thanks.  Committed to trunk in r248280:

commit 6acf639f20cb088fbc81b465c924c66d152af288
Author: tschwinge 
Date:   Fri May 19 13:32:48 2017 +

OpenACC 2.5 default (present) clause

gcc/c/
* c-parser.c (c_parser_omp_clause_default): Handle
"OMP_CLAUSE_DEFAULT_PRESENT".
gcc/cp/
* parser.c (cp_parser_omp_clause_default): Handle
"OMP_CLAUSE_DEFAULT_PRESENT".
gcc/fortran/
* gfortran.h (enum gfc_omp_default_sharing): Add
"OMP_DEFAULT_PRESENT".
* dump-parse-tree.c (show_omp_clauses): Handle it.
* openmp.c (gfc_match_omp_clauses): Likewise.
* trans-openmp.c (gfc_trans_omp_clauses): Likewise.
gcc/
* tree-core.h (enum omp_clause_default_kind): Add
"OMP_CLAUSE_DEFAULT_PRESENT".
* tree-pretty-print.c (dump_omp_clause): Handle it.
* gimplify.c (enum gimplify_omp_var_data): Add
"GOVD_MAP_FORCE_PRESENT".
(gimplify_adjust_omp_clauses_1): Map it to
"GOMP_MAP_FORCE_PRESENT".
(oacc_default_clause): Handle "OMP_CLAUSE_DEFAULT_PRESENT".
gcc/testsuite/
* c-c++-common/goacc/default-1.c: Update.
* c-c++-common/goacc/default-2.c: Likewise.
* c-c++-common/goacc/default-4.c: Likewise.
* gfortran.dg/goacc/default-1.f95: Likewise.
* gfortran.dg/goacc/default-4.f: Likewise.
* c-c++-common/goacc/default-5.c: New file.
* gfortran.dg/goacc/default-5.f: Likewise.
libgomp/
* testsuite/libgomp.oacc-c++/template-reduction.C: Update.
* testsuite/libgomp.oacc-c-c++-common/nested-2.c: Update.
* testsuite/libgomp.oacc-fortran/data-4-2.f90: Likewise.
* testsuite/libgomp.oacc-fortran/default-1.f90: Likewise.
* testsuite/libgomp.oacc-fortran/non-scalar-data.f90: Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@248280 
138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog  |  9 
 gcc/c/ChangeLog|  5 +++
 gcc/c/c-parser.c   | 14 --
 gcc/cp/ChangeLog   |  3 ++
 gcc/cp/parser.c| 14 --
 gcc/fortran/ChangeLog  |  8 
 gcc/fortran/dump-parse-tree.c  |  1 +
 gcc/fortran/gfortran.h |  3 +-
 gcc/fortran/openmp.c   | 20 ++---
 gcc/fortran/trans-openmp.c |  3 ++
 gcc/gimplify.c | 52 ++
 gcc/testsuite/ChangeLog|  8 
 gcc/testsuite/c-c++-common/goacc/default-1.c   |  5 +++
 gcc/testsuite/c-c++-common/goacc/default-2.c   | 28 ++--
 gcc/testsuite/c-c++-common/goacc/default-4.c   | 21 +
 gcc/testsuite/c-c++-common/goacc/default-5.c   | 20 +
 gcc/testsuite/gfortran.dg/goacc/default-1.f95  |  5 +++
 gcc/testsuite/gfortran.dg/goacc/default-4.f| 18 
 

Re: OpenACC 2.5 default (present) clause

2017-05-19 Thread Thomas Schwinge
Hi!

On Wed, 10 May 2017 17:48:36 +0200, Jakub Jelinek  wrote:
> On Fri, Apr 07, 2017 at 05:08:55PM +0200, Thomas Schwinge wrote:
> > OpenACC 2.5 added a default (present) clause, which "causes all arrays or
> > variables of aggregate data type used in the compute construct that have
> > implicitly determined data attributes to be treated as if they appeared
> > in a present clause".  Preceded by the following cleanup patch (see
> >  for its
> > origin), OK for trunk in next stage 1?

> > Clarify gcc/gimplify.c:oacc_default_clause

> [...] LGTM.

As posted, committed to trunk in r248279:

commit f7c10d53cac5a46d06d23177526aa36c021e135c
Author: tschwinge 
Date:   Fri May 19 13:32:30 2017 +

Clarify gcc/gimplify.c:oacc_default_clause

gcc/
* gimplify.c (oacc_default_clause): Clarify.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@248279 
138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog  |  4 
 gcc/gimplify.c | 40 ++--
 2 files changed, 26 insertions(+), 18 deletions(-)

diff --git gcc/ChangeLog gcc/ChangeLog
index 44ff617..8f63902 100644
--- gcc/ChangeLog
+++ gcc/ChangeLog
@@ -1,3 +1,7 @@
+2017-05-19  Thomas Schwinge  
+
+   * gimplify.c (oacc_default_clause): Clarify.
+
 2017-05-19  Nathan Sidwell  
 
LANG_HOOK_REGISTER_DUMPS
diff --git gcc/gimplify.c gcc/gimplify.c
index acaab8b..0c02ee4 100644
--- gcc/gimplify.c
+++ gcc/gimplify.c
@@ -6952,30 +6952,34 @@ oacc_default_clause (struct gimplify_omp_ctx *ctx, tree 
decl, unsigned flags)
 
   switch (ctx->region_type)
 {
-default:
-  gcc_unreachable ();
-
 case ORT_ACC_KERNELS:
-  /* Scalars are default 'copy' under kernels, non-scalars are default
-'present_or_copy'.  */
-  flags |= GOVD_MAP;
-  if (!AGGREGATE_TYPE_P (type))
-   flags |= GOVD_MAP_FORCE;
-
   rkind = "kernels";
+
+  if (AGGREGATE_TYPE_P (type))
+   /* Aggregates default to 'present_or_copy'.  */
+   flags |= GOVD_MAP;
+  else
+   /* Scalars default to 'copy'.  */
+   flags |= GOVD_MAP | GOVD_MAP_FORCE;
+
   break;
 
 case ORT_ACC_PARALLEL:
-  {
-   if (on_device || AGGREGATE_TYPE_P (type) || declared)
- /* Aggregates default to 'present_or_copy'.  */
- flags |= GOVD_MAP;
-   else
- /* Scalars default to 'firstprivate'.  */
- flags |= GOVD_FIRSTPRIVATE;
-   rkind = "parallel";
-  }
+  rkind = "parallel";
+
+  if (on_device || declared)
+   flags |= GOVD_MAP;
+  else if (AGGREGATE_TYPE_P (type))
+   /* Aggregates default to 'present_or_copy'.  */
+   flags |= GOVD_MAP;
+  else
+   /* Scalars default to 'firstprivate'.  */
+   flags |= GOVD_FIRSTPRIVATE;
+
   break;
+
+default:
+  gcc_unreachable ();
 }
 
   if (DECL_ARTIFICIAL (decl))


Grüße
 Thomas


Re: OpenACC default clause maintenance

2017-05-19 Thread Thomas Schwinge
Hi!

On Wed, 29 Mar 2017 00:19:30 +0200, Jakub Jelinek  wrote:
> On Tue, Mar 28, 2017 at 11:35:35AM +0200, Thomas Schwinge wrote:
> > I noticed that in C++, for a directive like:
> > 
> > #pragma acc parallel default (hello)
> > 
> > ... we currently print two error messages for the same location:
> > 
> > [...]:35:30: error: expected 'none' before 'hello'
> > [...]:35:30: error: expected ')' before 'hello'
> > 
> > I think it should be enough to just print the first syntax error (which
> > is what we do for C).  I also generally beefed up testing of the OpenACC
> > default clause in C, C++, Fortran.  OK for trunk [...]?

> > OpenACC default clause maintenance
> > 
> > gcc/cp/
> > * parser.c (cp_parser_omp_clause_default): Avoid printing more
> > than one syntax error message.
> > gcc/testsuite/
> > * c-c++-common/goacc/data-default-1.c: Remove file.
> > * c-c++-common/goacc/default-1.c: New file.
> > * c-c++-common/goacc/default-2.c: Likewise.
> > * c-c++-common/goacc/default-3.c: Likewise.
> > * c-c++-common/goacc/default-4.c: Likewise.
> > * gfortran.dg/goacc/default.f95: Remove file.
> > * gfortran.dg/goacc/default-1.f95: New file.
> > * gfortran.dg/goacc/default-2.f: Likewise.
> > * gfortran.dg/goacc/default-3.f95: Likewise.
> > * gfortran.dg/goacc/default-4.f: Likewise.
> 
> The parser.c change is fine for stage1

Thanks!

> but I wonder why are you removing
> the tests.  If you want to rename them and perhaps update, state so in the
> ChangeLog and svn mv them, but the removals + addition without any link looks
> weird.

I'm certainly not removing tests, or reducing test coverage; quite to the
contrary.  I edited the ChangeLog snippet.

Without other changes, committed to trunk in r248278:

commit 23e84ab684d7df69b89debea4cf1cccef5e12951
Author: tschwinge 
Date:   Fri May 19 13:32:19 2017 +

OpenACC default clause maintenance

gcc/cp/
* parser.c (cp_parser_omp_clause_default): Avoid printing more
than one syntax error message.
gcc/testsuite/
* c-c++-common/goacc/default-1.c: New file.
* c-c++-common/goacc/default-2.c: Likewise.
* c-c++-common/goacc/data-default-1.c: Remove file, including its
test cases in...
* c-c++-common/goacc/default-3.c: ... this new file, and...
* c-c++-common/goacc/default-4.c: ... this new file.
* gfortran.dg/goacc/default.f95: Remove file, including its test
cases in...
* gfortran.dg/goacc/default-1.f95: ... this new file, and...
* gfortran.dg/goacc/default-2.f: ... this new file.
* gfortran.dg/goacc/default-3.f95: New file.
* gfortran.dg/goacc/default-4.f: Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@248278 
138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/cp/ChangeLog  |  5 ++
 gcc/cp/parser.c   |  3 +-
 gcc/testsuite/ChangeLog   | 15 ++
 gcc/testsuite/c-c++-common/goacc/data-default-1.c | 37 --
 gcc/testsuite/c-c++-common/goacc/default-1.c  |  9 
 gcc/testsuite/c-c++-common/goacc/default-2.c  | 59 ++
 gcc/testsuite/c-c++-common/goacc/default-3.c  | 18 +++
 gcc/testsuite/c-c++-common/goacc/default-4.c  | 45 +
 gcc/testsuite/gfortran.dg/goacc/default-1.f95 | 10 
 gcc/testsuite/gfortran.dg/goacc/default-2.f   | 60 +++
 gcc/testsuite/gfortran.dg/goacc/default-3.f95 | 18 +++
 gcc/testsuite/gfortran.dg/goacc/default-4.f   | 39 +++
 gcc/testsuite/gfortran.dg/goacc/default.f95   | 17 ---
 13 files changed, 280 insertions(+), 55 deletions(-)

diff --git gcc/cp/ChangeLog gcc/cp/ChangeLog
index 09c8269..c89f719 100644
--- gcc/cp/ChangeLog
+++ gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2017-05-19  Thomas Schwinge  
+
+   * parser.c (cp_parser_omp_clause_default): Avoid printing more
+   than one syntax error message.
+
 2017-05-19  Nathan Sidwell  
 
* class.c (class_dump_id): Define.
diff --git gcc/cp/parser.c gcc/cp/parser.c
index 7a87a5e..6453397 100644
--- gcc/cp/parser.c
+++ gcc/cp/parser.c
@@ -31504,7 +31504,8 @@ cp_parser_omp_clause_default (cp_parser *parser, tree 
list,
cp_parser_error (parser, "expected % or %");
 }
 
-  if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+  if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED
+  || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
 cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
  

ping [PATCH] [MSP430] Fix PR78849: ICE on initialization of global struct containing __int20 array

2017-05-19 Thread Jozef Lawrynowicz
Original post: https://gcc.gnu.org/ml/gcc-patches/2017-04/msg01030.html

The attached patch fixes an issue for the msp430 target where the TYPE_SIZE of
the __int20 type was set using the precision (20 bits) instead of the in-memory
size (32 bits) of the type. This bug caused an ICE as reported in PR78849:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78849

The patch passed bootstrap and regression testing with no regressions
on recent trunk (r247020) for x86_64-pc-linux-gnu.

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

If the patch is acceptable I would appreciate if someone could commit it for me
as I don't have write access.


0001-Use-GET_MODE_BITSIZE-when-setting-TYPE_SIZE.patch
Description: Binary data


Re: [HSA, PATCH] Load an HSA runtime via dlopen mechanism

2017-05-19 Thread Thomas Schwinge
Hi!

On Sun, 9 Apr 2017 18:22:00 +0200, Martin Jambor  wrote:
> On Wed, Apr 05, 2017 at 10:11:34AM +0200, Thomas Schwinge wrote:
> > I ran into a case where the libgomp hsa plugin wouldn't load.  The
> > following patch helped me to quickly diagnose and then fix that.  OK for
> > trunk?
> 
> Yes, thanks.

Thanks, now finally, as posted, committed to trunk in r248277:

commit b7d6170b96407c80b3e21dd6a665ebff7715d62e
Author: tschwinge 
Date:   Fri May 19 13:32:04 2017 +

libgomp hsa plugin: debug output for HSA runtime library loading failure

libgomp/
* plugin/plugin-hsa.c (DLSYM_FN, init_hsa_runtime_functions):
Debug output for failure.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@248277 
138bc75d-0d04-0410-961f-82ee72b054a4
---
 libgomp/ChangeLog   | 5 +
 libgomp/plugin/plugin-hsa.c | 8 ++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git libgomp/ChangeLog libgomp/ChangeLog
index 083cb85..84d1c839 100644
--- libgomp/ChangeLog
+++ libgomp/ChangeLog
@@ -1,3 +1,8 @@
+2017-05-19  Thomas Schwinge  
+
+   * plugin/plugin-hsa.c (DLSYM_FN, init_hsa_runtime_functions):
+   Debug output for failure.
+
 2017-05-12  Rainer Orth  
 
* testsuite/lib/libgomp.exp: Load scanlang.exp.
diff --git libgomp/plugin/plugin-hsa.c libgomp/plugin/plugin-hsa.c
index 9cc243d..90ca247 100644
--- libgomp/plugin/plugin-hsa.c
+++ libgomp/plugin/plugin-hsa.c
@@ -491,14 +491,14 @@ static struct hsa_context_info hsa_context;
 #define DLSYM_FN(function) \
   hsa_fns.function##_fn = dlsym (handle, #function); \
   if (hsa_fns.function##_fn == NULL) \
-return false;
+goto dl_fail;
 
 static bool
 init_hsa_runtime_functions (void)
 {
   void *handle = dlopen (hsa_runtime_lib, RTLD_LAZY);
   if (handle == NULL)
-return false;
+goto dl_fail;
 
   DLSYM_FN (hsa_status_string)
   DLSYM_FN (hsa_agent_get_info)
@@ -530,6 +530,10 @@ init_hsa_runtime_functions (void)
   DLSYM_FN (hsa_ext_program_destroy)
   DLSYM_FN (hsa_ext_program_finalize)
   return true;
+
+ dl_fail:
+  HSA_DEBUG ("while loading %s: %s\n", hsa_runtime_lib, dlerror ());
+  return false;
 }
 
 /* Find kernel for an AGENT by name provided in KERNEL_NAME.  */


Grüße
 Thomas


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

2017-05-19 Thread Jan Hubicka
> 
> * LTO and memory management
> This is a general question about LTO and memory management.
> IIUC the following sequence takes place during normal LTO:
> LGEN: generate_summary, write_summary
> WPA: read_summary, execute ipa passes, write_opt_summary
> 
> So I assumed it was OK in LGEN to allocate return_callees_map in
> generate_summary and free it in write_summary and during WPA, allocate
> return_callees_map in read_summary and free it after execute (since
> write_opt_summary does not require return_callees_map).
> 
> However with fat LTO, it seems the sequence changes for LGEN with
> execute phase takes place after write_summary. However since
> return_callees_map is freed in pure_const_write_summary and
> propagate_malloc() accesses it in execute stage, it results in
> segmentation fault.
> 
> To work around this, I am using the following hack in 
> pure_const_write_summary:
> // FIXME: Do not free if -ffat-lto-objects is enabled.
> if (!global_options.x_flag_fat_lto_objects)
>   free_return_callees_map ();
> Is there a better approach for handling this ?

I think most passes just do not free summaries with -flto.  We probably want
to fix it to make it possible to compile multiple units i.e. from plugin by
adding release_summaries method...
So I would say it is OK to do the same as others do and leak it with -flto.
> diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c
> index e457166ea39..724c26e03f6 100644
> --- a/gcc/ipa-pure-const.c
> +++ b/gcc/ipa-pure-const.c
> @@ -56,6 +56,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "tree-scalar-evolution.h"
>  #include "intl.h"
>  #include "opts.h"
> +#include "ssa.h"
>  
>  /* Lattice values for const and pure functions.  Everything starts out
> being const, then may drop to pure and then neither depending on
> @@ -69,6 +70,15 @@ enum pure_const_state_e
>  
>  const char *pure_const_names[3] = {"const", "pure", "neither"};
>  
> +enum malloc_state_e
> +{
> +  PURE_CONST_MALLOC_TOP,
> +  PURE_CONST_MALLOC,
> +  PURE_CONST_MALLOC_BOTTOM
> +};

It took me a while to work out what PURE_CONST means here :)
I would just call it something like STATE_MALLOC_TOP... or so.
ipa_pure_const is outdated name from the time pass was doing only
those two.
> @@ -109,6 +121,10 @@ typedef struct funct_state_d * funct_state;
>  
>  static vec funct_state_vec;
>  
> +/* A map from node to subset of callees. The subset contains those callees
> + * whose return-value is returned by the node. */
> +static hash_map< cgraph_node *, vec* > *return_callees_map;
> +

Hehe, a special case of return jump function.  We ought to support those more 
generally.
How do you keep it up to date over callgraph changes?
> @@ -921,6 +1055,23 @@ end:
>if (TREE_NOTHROW (decl))
>  l->can_throw = false;
>  
> +  if (ipa)
> +{
> +  vec v = vNULL;
> +  l->malloc_state = PURE_CONST_MALLOC_BOTTOM;
> +  if (DECL_IS_MALLOC (decl))
> + l->malloc_state = PURE_CONST_MALLOC;
> +  else if (malloc_candidate_p (DECL_STRUCT_FUNCTION (decl), v))
> + {
> +   l->malloc_state = PURE_CONST_MALLOC_TOP;
> +   vec *callees_p = new vec (vNULL);
> +   for (unsigned i = 0; i < v.length (); ++i)
> + callees_p->safe_push (v[i]);
> +   return_callees_map->put (fn, callees_p);
> + }
> +  v.release ();
> +}
> +

I would do non-ipa variant, too.  I think most attributes can be detected that 
way
as well.

The patch generally makes sense to me.  It would be nice to make it easier to 
write such
a basic propagators across callgraph (perhaps adding a template doing the basic
propagation logic). Also I think you need to solve the problem with keeping your
summaries up to date across callgraph node removal and duplications.

Honza


Re: libbacktrace patch: fix memory allocation buglet on DWARF line table with zero dirs

2017-05-19 Thread Than McIntosh via gcc-patches
Hi again,

I wrote:
== The attached patch to libbacktrace is intended to fix a memory
== allocation bug involving reading of line table information.

I've revised my previous patch to include a new test ("edtest") that
verifies the fix.

Thanks, Than

---

Patch (take 2):

diff --git a/Makefile.am b/Makefile.am
index ec494c4..d236261 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -96,6 +96,17 @@ stest_LDADD = libbacktrace.la

 check_PROGRAMS += stest

+edtest_SOURCES = edtest.c edtest2_build.c
+edtest_LDADD = libbacktrace.la
+
+check_PROGRAMS += edtest
+
+edtest2_build.c: gen_edtest2_build; @true
+gen_edtest2_build: $(srcdir)/edtest2.c
+ cat $(srcdir)/edtest2.c > tmp-edtest2_build.c
+ $(SHELL) $(srcdir)/mvifdiff.sh tmp-edtest2_build.c edtest2_build.c
+ echo timestamp > $@
+
 endif NATIVE

 # We can't use automake's automatic dependency tracking, because it
@@ -126,5 +137,6 @@ read.lo: config.h backtrace.h internal.h
 simple.lo: config.h backtrace.h internal.h
 sort.lo: config.h backtrace.h internal.h
 stest.lo: config.h backtrace.h internal.h
+edtest.lo: config.h backtrace.h internal.h
 state.lo: config.h backtrace.h backtrace-supported.h internal.h
 unknown.lo: config.h backtrace.h internal.h
diff --git a/Makefile.in b/Makefile.in
index f3a7a42..04c6689 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -85,7 +85,7 @@ build_triplet = @build@
 host_triplet = @host@
 target_triplet = @target@
 check_PROGRAMS = $(am__EXEEXT_1)
-@NATIVE_TRUE@am__append_1 = btest stest
+@NATIVE_TRUE@am__append_1 = btest stest edtest
 subdir = .
 DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
  $(top_srcdir)/configure $(am__configure_deps) \
@@ -135,13 +135,18 @@ am__DEPENDENCIES_1 =
 am_libbacktrace_la_OBJECTS = atomic.lo dwarf.lo fileline.lo posix.lo \
  print.lo sort.lo state.lo
 libbacktrace_la_OBJECTS = $(am_libbacktrace_la_OBJECTS)
-@NATIVE_TRUE@am__EXEEXT_1 = btest$(EXEEXT) stest$(EXEEXT)
+@NATIVE_TRUE@am__EXEEXT_1 = btest$(EXEEXT) stest$(EXEEXT) \
+@NATIVE_TRUE@ edtest$(EXEEXT)
 @NATIVE_TRUE@am_btest_OBJECTS = btest-btest.$(OBJEXT)
 btest_OBJECTS = $(am_btest_OBJECTS)
 @NATIVE_TRUE@btest_DEPENDENCIES = libbacktrace.la
 btest_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
  --mode=link $(CCLD) $(btest_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
  $(LDFLAGS) -o $@
+@NATIVE_TRUE@am_edtest_OBJECTS = edtest.$(OBJEXT) \
+@NATIVE_TRUE@ edtest2_build.$(OBJEXT)
+edtest_OBJECTS = $(am_edtest_OBJECTS)
+@NATIVE_TRUE@edtest_DEPENDENCIES = libbacktrace.la
 @NATIVE_TRUE@am_stest_OBJECTS = stest.$(OBJEXT)
 stest_OBJECTS = $(am_stest_OBJECTS)
 @NATIVE_TRUE@stest_DEPENDENCIES = libbacktrace.la
@@ -158,7 +163,7 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS)
$(LIBTOOLFLAGS) \
  --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
  $(LDFLAGS) -o $@
 SOURCES = $(libbacktrace_la_SOURCES) $(EXTRA_libbacktrace_la_SOURCES) \
- $(btest_SOURCES) $(stest_SOURCES)
+ $(btest_SOURCES) $(edtest_SOURCES) $(stest_SOURCES)
 MULTISRCTOP =
 MULTIBUILDTOP =
 MULTIDIRS =
@@ -350,6 +355,8 @@ TESTS = $(check_PROGRAMS)
 @NATIVE_TRUE@btest_LDADD = libbacktrace.la
 @NATIVE_TRUE@stest_SOURCES = stest.c
 @NATIVE_TRUE@stest_LDADD = libbacktrace.la
+@NATIVE_TRUE@edtest_SOURCES = edtest.c edtest2_build.c
+@NATIVE_TRUE@edtest_LDADD = libbacktrace.la
 all: config.h
  $(MAKE) $(AM_MAKEFLAGS) all-am

@@ -452,6 +459,9 @@ clean-checkPROGRAMS:
 btest$(EXEEXT): $(btest_OBJECTS) $(btest_DEPENDENCIES)
$(EXTRA_btest_DEPENDENCIES)
  @rm -f btest$(EXEEXT)
  $(btest_LINK) $(btest_OBJECTS) $(btest_LDADD) $(LIBS)
+edtest$(EXEEXT): $(edtest_OBJECTS) $(edtest_DEPENDENCIES)
$(EXTRA_edtest_DEPENDENCIES)
+ @rm -f edtest$(EXEEXT)
+ $(LINK) $(edtest_OBJECTS) $(edtest_LDADD) $(LIBS)
 stest$(EXEEXT): $(stest_OBJECTS) $(stest_DEPENDENCIES)
$(EXTRA_stest_DEPENDENCIES)
  @rm -f stest$(EXEEXT)
  $(LINK) $(stest_OBJECTS) $(stest_LDADD) $(LIBS)
@@ -801,6 +811,12 @@ uninstall-am: uninstall-includeHEADERS
uninstall-libLTLIBRARIES
  uninstall-am uninstall-includeHEADERS uninstall-libLTLIBRARIES


+@NATIVE_TRUE@edtest2_build.c: gen_edtest2_build; @true
+@NATIVE_TRUE@gen_edtest2_build: $(srcdir)/edtest2.c
+@NATIVE_TRUE@ cat $(srcdir)/edtest2.c > tmp-edtest2_build.c
+@NATIVE_TRUE@ $(SHELL) $(srcdir)/mvifdiff.sh tmp-edtest2_build.c
edtest2_build.c
+@NATIVE_TRUE@ echo timestamp > $@
+
 # We can't use automake's automatic dependency tracking, because it
 # breaks when using bootstrap-lean.  Automatic dependency tracking
 # with GCC bootstrap will cause some of the objects to depend on
@@ -829,6 +845,7 @@ read.lo: config.h backtrace.h internal.h
 simple.lo: config.h backtrace.h internal.h
 sort.lo: config.h backtrace.h internal.h
 stest.lo: config.h backtrace.h internal.h
+edtest.lo: config.h backtrace.h internal.h
 state.lo: config.h backtrace.h backtrace-supported.h internal.h
 unknown.lo: config.h backtrace.h internal.h

diff --git a/dwarf.c b/dwarf.c
index b182567..c1bfbf5 100644
--- a/dwarf.c
+++ b/dwarf.c
@@ -1648,16 +1648,15 @@ add_line (struct backtrace_state *state,
struct 

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

2017-05-19 Thread Richard Biener
On Fri, May 19, 2017 at 2:56 PM, Martin Liška  wrote:
> On 05/19/2017 01:24 PM, Richard Biener wrote:
>> On Wed, May 17, 2017 at 10:45 AM, Martin Liška  wrote:
>>> Hi.
>>>
>>> As discussed on IRC some time ago, there are configurations that produce 
>>> -Werror=maybe-uninitialized
>>> and other warnings that break bootstrap. So that, the patch makes -Werror 
>>> just for default (boostrap-debug)
>>> configuration.
>>>
>>> Ready for trunk?
>>
>> Hmm, this enables werror on release branches.  I think we also want to
>> enable Werror for
>> --without-build-config (or =yes and =no), thus regular bootstrap
>> without bootstrap-debug.
>
> Ok, fixed in attached patch v2.

Looks good to me.

Thanks,
Richard.

> Martin
>
>>
>> Richard.
>>
>>> Martin
>


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

2017-05-19 Thread Jan Hubicka
> >   struct D: B {
> > char buf[32];
> > virtual void* f (unsigned n) {
> >   if (n < 32)
> >   return n <= 32 ? buf : B::f (n);
> > }
> > 
> > Breaking foo's attribute malloc constraint.
> > 
> > In other words, I think virtual functions need to be excluded
> > from the list (unless they're defined in a class marked final,
> > or unless we know they're not overridden to break the constraint
> > like above).
> 
> But we are annotating the actual decl, not the type in the class
> struct.

Yep and we will be able to use the information in case we devirtualize
the call.  So this seems OK to me.

Honza
> 
> Richard.


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

2017-05-19 Thread Martin Liška
On 05/19/2017 01:24 PM, Richard Biener wrote:
> On Wed, May 17, 2017 at 10:45 AM, Martin Liška  wrote:
>> Hi.
>>
>> As discussed on IRC some time ago, there are configurations that produce 
>> -Werror=maybe-uninitialized
>> and other warnings that break bootstrap. So that, the patch makes -Werror 
>> just for default (boostrap-debug)
>> configuration.
>>
>> Ready for trunk?
> 
> Hmm, this enables werror on release branches.  I think we also want to
> enable Werror for
> --without-build-config (or =yes and =no), thus regular bootstrap
> without bootstrap-debug.

Ok, fixed in attached patch v2.

Martin

> 
> Richard.
> 
>> Martin

>From d7ad1fbd517f0f61be6c2e1d2770d44a37e90c4c Mon Sep 17 00:00:00 2001
From: marxin 
Date: Fri, 19 May 2017 14:54:19 +0200
Subject: [PATCH] Enable by default -Werror just for bootstrap-debug.mk and
 default build.

ChangeLog:

2017-05-19  Martin Liska  

	* configure.ac: Add --enable-werror-always just for
	bootstrap-debug (or none build config) and do not add it
	when we are on a release branch.
	* configure: Regenerated.
---
 configure| 16 ++--
 configure.ac | 17 +++--
 2 files changed, 21 insertions(+), 12 deletions(-)

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



Re: [PATCH GCC8][31/33]Set range information for niter bound of vectorized loop

2017-05-19 Thread Richard Biener
On Mon, May 15, 2017 at 5:58 PM, Bin.Cheng  wrote:
> On Thu, May 11, 2017 at 12:02 PM, Richard Biener
>  wrote:
>> On Tue, Apr 18, 2017 at 12:54 PM, Bin Cheng  wrote
>>> Hi,
>>> Based on vect_peeling algorithm, we know for sure that vectorized loop must 
>>> iterates at least once.
>>> This patch sets range information for niter bounds of vectorized loop.  
>>> This helps niter analysis,
>>> so iv elimination too.
>>> Is it OK?
>>
>>niters_vector = force_gimple_operand (niters_vector, , true, 
>> var);
>>gsi_insert_seq_on_edge_immediate (pe, stmts);
>> +  /* Peeling algorithm guarantees that vector loop bound is at least 
>> ONE,
>> +we set range information to make niters analyzer's life easier.  */
>> +  if (TREE_CODE (niters_vector) == SSA_NAME)
>> +   set_range_info (niters_vector, VR_RANGE, build_int_cst (type, 1),
>> +   fold_build2 (RSHIFT_EXPR, type,
>> +TYPE_MAX_VALUE (type), log_vf));
>>
>> if all of niters_vector folds to an original SSA name then
>> niters_vector after gimplification
>> is not a new SSA name and thus you can't set range-info on it.
>>
>> Likewise for the other case where LOOP_VINFO_NITERS is just an SSA name.
> Hi,
> This is updated patch.  It checks whether the result ssa name is newly
> created tmp and only sets range information if so.
>
> Is it OK?

A better way to check whether the SSA name is new is to see if 'stmts'
filled by force_gimple_operand is non-empty.

Richard.

> Thanks,
> bin
>
> 2017-04-11  Bin Cheng  
>
> * tree-vectorizer.h (vect_build_loop_niters): New parameter.
> * tree-vect-loop-manip.c (vect_build_loop_niters): New parameter.
> Set true to new parameter if new ssa variable is defined.
> (vect_gen_vector_loop_niters): Refactor.  Set range information
> for the new vector loop bound variable.
> (vect_do_peeling): Ditto.
>
>>
>> Richard.
>>
>>> Thanks,
>>> bin
>>> 2017-04-11  Bin Cheng  
>>>
>>> * tree-vect-loop-manip.c (vect_gen_vector_loop_niters): Refactor.
>>> Set range information for vector loop bound variable.
>>> (vect_do_peeling): Ditto.


Re: [PING][PATCH, GCC/ARM] Only test tls-disable-literal-pool.c if target supports native TLS

2017-05-19 Thread Kyrill Tkachov

Hi Prakhar,

On 19/05/17 13:29, Prakhar Bahuguna wrote:

On 11/05/2017 14:54:37, Prakhar Bahuguna wrote:

tls-disable-literal-pool.c should only be run if the toolchain and target
support native thread-local storage rather than emulated TLS. This patch also
improves the matching of the error message.

testsuite/ChangeLog:

2017-05-11  Prakhar Bahuguna  

* gcc.target/arm/tls-disable-literal-pool.c: Change
require-effective-target to tls_native.
Move dg-error to return statement line and change to dg-message.

Testing done: Regression testing for ARMv7-M with a TLS-enabled toolchain and a
TLS-disabled toolchain.

Okay for stage1?


Ok.
Thanks,
Kyrill



--

Prakhar Bahuguna
 From 84837978d480a1abcebe7b4d2ac21af0eb6645b4 Mon Sep 17 00:00:00 2001
From: Prakhar Bahuguna 
Date: Thu, 11 May 2017 13:24:39 +0100
Subject: [PATCH] Only test tls-disable-literal-pool.c if target supports
  native TLS

This test should only be run if the toolchain and target support native
thread-local storage rather than emulated TLS.
---
  gcc/testsuite/gcc.target/arm/tls-disable-literal-pool.c | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.target/arm/tls-disable-literal-pool.c 
b/gcc/testsuite/gcc.target/arm/tls-disable-literal-pool.c
index fe14a6b132c..283201fdd97 100644
--- a/gcc/testsuite/gcc.target/arm/tls-disable-literal-pool.c
+++ b/gcc/testsuite/gcc.target/arm/tls-disable-literal-pool.c
@@ -1,5 +1,5 @@
  /* { dg-do compile } */
-/* { dg-require-effective-target tls } */
+/* { dg-require-effective-target tls_native } */
  /* { dg-require-effective-target arm_cortex_m } */
  /* { dg-require-effective-target arm_thumb2_ok } */
  /* { dg-options "-mslow-flash-data" } */
@@ -9,7 +9,6 @@ __thread int x = 0;
  int
  bar ()
  {
-  return x;
+  return x; /* { dg-message "sorry, unimplemented: accessing thread-local storage 
is not currently supported with -mpure-code or -mslow-flash-data" } */
  }
  
-/* { dg-error "accessing thread-local storage is not currently supported with -mpure-code or -mslow-flash-data" "" { target *-*-* } 12 } */

--
2.11.0


Ping.





Re: Turn inline_edge_summary into ipa_call_summary

2017-05-19 Thread Jan Hubicka
> 
> and way way more (C, Ada, ...).  Assuming that the ipa-predicate.[ch]
> patch was really only cosmetic, this only leaves your patch in this rev
> range.
> 
> Please fix.
Hi,
I apologize for the breakage. I already commited a fix before lunch but seems my
email did not get through.  I am attaching it.  I amanged to bundle into patch 
a local
change which turn call_stmt_size/time unsigned and confuses one comparsion in
want_inline_small_function_p.

Honza

* ipa-inline.h (ipa_call_summary): Turn sizes into signed;
add ctor.
* ipa-inline.c (want_inline_small_function_p): Do not cast to
unsigned.
Index: ipa-inline.h
===
--- ipa-inline.h(revision 248262)
+++ ipa-inline.h(working copy)
@@ -189,10 +189,18 @@ struct ipa_call_summary
   /* Vector indexed by parameters.  */
   vec param;
   /* Estimated size and time of the call statement.  */
-  unsigned int call_stmt_size;
-  unsigned int call_stmt_time;
+  int call_stmt_size;
+  int call_stmt_time;
   /* Depth of loop nest, 0 means no nesting.  */
   unsigned int loop_depth;
+  
+  /* Keep all field empty so summary dumping works during its computation.
+ This is useful for debugging.  */
+  ipa_call_summary ()
+: predicate (NULL), param (vNULL), call_stmt_size (0), call_stmt_time (0),
+  loop_depth (0)
+{
+}
 };
 
 class ipa_call_summary_t: public call_summary 
Index: ipa-inline.c
===
--- ipa-inline.c(revision 248262)
+++ ipa-inline.c(working copy)
@@ -723,7 +723,7 @@ want_inline_small_function_p (struct cgr
   && (!e->count || !e->maybe_hot_p ()))
   && inline_summaries->get (callee)->min_size
- ipa_call_summaries->get (e)->call_stmt_size
- > (unsigned)MAX (MAX_INLINE_INSNS_SINGLE, MAX_INLINE_INSNS_AUTO))
+ > MAX (MAX_INLINE_INSNS_SINGLE, MAX_INLINE_INSNS_AUTO))
 {
   e->inline_failed = CIF_MAX_INLINE_INSNS_AUTO_LIMIT;
   want_inline = false;
@@ -731,7 +731,7 @@ want_inline_small_function_p (struct cgr
   else if ((DECL_DECLARED_INLINE_P (callee->decl) || e->count)
   && inline_summaries->get (callee)->min_size
- ipa_call_summaries->get (e)->call_stmt_size
- > (unsigned)16 * MAX_INLINE_INSNS_SINGLE)
+ > 16 * MAX_INLINE_INSNS_SINGLE)
 {
   e->inline_failed = (DECL_DECLARED_INLINE_P (callee->decl)
  ? CIF_MAX_INLINE_INSNS_SINGLE_LIMIT


Re: [PATCH][C fam] Fix PR80593, bogus strict-aliasing warnings

2017-05-19 Thread Richard Biener
On Fri, 19 May 2017, Marek Polacek wrote:

> On Thu, May 18, 2017 at 01:00:39PM +0200, Richard Biener wrote:
> > 
> > The following reverts an earlier change of mine (2008) to explicitely
> > warn about accessing alias-set zero memory with alias-set non-zero.
> > That was supposed to catch the case in g++.dg/warn/Wstrict-aliasing-6.C
> > which is
> > 
> > int foo ()
> > {
> >   char buf[8];
> >   return *((int *)buf); /* { dg-warning "strict-aliasing" } */
> > }
> > 
> > but at least since the typeless storage work this is considered valid
> > and thus this warning is really bogus.
> > 
> > Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
> > 
> > Ok for trunk and GCC 7 branch?
> 
> I think this is fine.

Thanks.

Committed to trunk sofar.

Richard.


[PING][PATCH, GCC/ARM] Only test tls-disable-literal-pool.c if target supports native TLS

2017-05-19 Thread Prakhar Bahuguna
On 11/05/2017 14:54:37, Prakhar Bahuguna wrote:
> tls-disable-literal-pool.c should only be run if the toolchain and target
> support native thread-local storage rather than emulated TLS. This patch also
> improves the matching of the error message.
> 
> testsuite/ChangeLog:
> 
> 2017-05-11  Prakhar Bahuguna  
> 
>   * gcc.target/arm/tls-disable-literal-pool.c: Change
>   require-effective-target to tls_native.
>   Move dg-error to return statement line and change to dg-message.
> 
> Testing done: Regression testing for ARMv7-M with a TLS-enabled toolchain and 
> a
> TLS-disabled toolchain.
> 
> Okay for stage1?
> 
> -- 
> 
> Prakhar Bahuguna

> From 84837978d480a1abcebe7b4d2ac21af0eb6645b4 Mon Sep 17 00:00:00 2001
> From: Prakhar Bahuguna 
> Date: Thu, 11 May 2017 13:24:39 +0100
> Subject: [PATCH] Only test tls-disable-literal-pool.c if target supports
>  native TLS
> 
> This test should only be run if the toolchain and target support native
> thread-local storage rather than emulated TLS.
> ---
>  gcc/testsuite/gcc.target/arm/tls-disable-literal-pool.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/gcc/testsuite/gcc.target/arm/tls-disable-literal-pool.c 
> b/gcc/testsuite/gcc.target/arm/tls-disable-literal-pool.c
> index fe14a6b132c..283201fdd97 100644
> --- a/gcc/testsuite/gcc.target/arm/tls-disable-literal-pool.c
> +++ b/gcc/testsuite/gcc.target/arm/tls-disable-literal-pool.c
> @@ -1,5 +1,5 @@
>  /* { dg-do compile } */
> -/* { dg-require-effective-target tls } */
> +/* { dg-require-effective-target tls_native } */
>  /* { dg-require-effective-target arm_cortex_m } */
>  /* { dg-require-effective-target arm_thumb2_ok } */
>  /* { dg-options "-mslow-flash-data" } */
> @@ -9,7 +9,6 @@ __thread int x = 0;
>  int
>  bar ()
>  {
> -  return x;
> +  return x; /* { dg-message "sorry, unimplemented: accessing thread-local 
> storage is not currently supported with -mpure-code or -mslow-flash-data" } */
>  }
>  
> -/* { dg-error "accessing thread-local storage is not currently supported 
> with -mpure-code or -mslow-flash-data" "" { target *-*-* } 12 } */
> -- 
> 2.11.0
> 

Ping.

-- 

Prakhar Bahuguna


Re: [PATCH][C fam] Fix PR80593, bogus strict-aliasing warnings

2017-05-19 Thread Marek Polacek
On Thu, May 18, 2017 at 01:00:39PM +0200, Richard Biener wrote:
> 
> The following reverts an earlier change of mine (2008) to explicitely
> warn about accessing alias-set zero memory with alias-set non-zero.
> That was supposed to catch the case in g++.dg/warn/Wstrict-aliasing-6.C
> which is
> 
> int foo ()
> {
>   char buf[8];
>   return *((int *)buf); /* { dg-warning "strict-aliasing" } */
> }
> 
> but at least since the typeless storage work this is considered valid
> and thus this warning is really bogus.
> 
> Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
> 
> Ok for trunk and GCC 7 branch?

I think this is fine.

Marek


Re: [PATCH] [Aarch64] Variable shift count truncation issues

2017-05-19 Thread Wilco Dijkstra
Richard Sandiford wrote:

> Insn patterns shouldn't check can_create_pseudo_p, because there's no
> guarantee that the associated split happens before RA.  In this case it
> should be safe to reuse operand 0 after RA if you change it to:

The goal is to only create and split this pattern before register allocation.
It's a transient pattern, combine creates it, and it is split immediately after.

Maybe !reload_completed is clearer as that is what several other
define_insn_and_split patterns do?

Wilco


[PATCH] PR libstdc++/80796 Add new std::search overload for C++17

2017-05-19 Thread Jonathan Wakely

When I copied the searchers from std::experimental to std I forgot to
add the new std::search overload.

PR libstdc++/80796
* include/bits/stl_algo.h (search): Add new overload for C++17.
* testsuite/25_algorithms/search/searcher.cc: New.

Tested powerpc64le-linux, committed to trunk. Backport to gcc-7-branch
coming.

commit bdb31910b79767f12fdfedd953413c98a0b357c3
Author: redi 
Date:   Fri May 19 12:11:31 2017 +

PR libstdc++/80796 Add new std::search overload for C++17

PR libstdc++/80796
* include/bits/stl_algo.h (search): Add new overload for C++17.
* testsuite/25_algorithms/search/searcher.cc: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@248266 
138bc75d-0d04-0410-961f-82ee72b054a4

diff --git a/libstdc++-v3/include/bits/stl_algo.h 
b/libstdc++-v3/include/bits/stl_algo.h
index aaa4eef..246193f 100644
--- a/libstdc++-v3/include/bits/stl_algo.h
+++ b/libstdc++-v3/include/bits/stl_algo.h
@@ -4258,6 +4258,20 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
__gnu_cxx::__ops::__iter_comp_val(__binary_pred, __val));
 }
 
+#if __cplusplus > 201402L
+  /** @brief Search a sequence using a Searcher object.
+   *
+   *  @param  __firstA forward iterator.
+   *  @param  __last A forward iterator.
+   *  @param  __searcher A callable object.
+   *  @return @p __searcher(__first,__last).first
+  */
+  template
+inline _ForwardIterator
+search(_ForwardIterator __first, _ForwardIterator __last,
+  const _Searcher& __searcher)
+{ return __searcher(__first, __last).first; }
+#endif
 
   /**
*  @brief Perform an operation on a sequence.
diff --git a/libstdc++-v3/testsuite/25_algorithms/search/searcher.cc 
b/libstdc++-v3/testsuite/25_algorithms/search/searcher.cc
new file mode 100644
index 000..794cdb9
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/search/searcher.cc
@@ -0,0 +1,47 @@
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+// { dg-options "-std=gnu++17" }
+// { dg-do run { target c++1z } }
+
+#include 
+#include 
+
+struct nocopy
+{
+  nocopy() = default;
+  nocopy(const nocopy&) = delete;
+  nocopy& operator=(const nocopy&) = delete;
+
+  struct P { int* first; };
+
+  P operator()(int* f, int* l) const { return {f}; }
+};
+
+void
+test01()
+{
+  int i[] = { 1, 2 };
+  auto res = std::search(i, i + 2, nocopy{});
+  VERIFY( res == i );
+}
+
+int
+main()
+{
+  test01();
+}


Re: Turn inline_edge_summary into ipa_call_summary

2017-05-19 Thread Rainer Orth
Hi Jan,

> this patch makes edge summaries to use call_summary template and renames them
> as they are not inliner specific for few years.
>
> Bootstrapped/regtested x86_64-linux.
>
> Honza
>
>   * ipa-inline-analysis.c (cgraph_2edge_hook_list, cgraph_edge_hook_list,
>   inline_edge_removal_hook, inline_edge_duplication_hook): Remove.
>   (inline_edge_summary_vec): Turn into ...
>   (ipa_call_summaries): ... this one.
>   (redirect_to_unreachable, edge_set_predicate,
>   evaluate_properties_for_edge, inline_summary_alloc,
>   reset_ipa_call_summary, reset_inline_summary,
>   inline_summary_t::duplicate): Update.
>   (inline_edge_duplication_hook): Turn to ...
>   (ipa_call_summary_t::duplicate): ... this one.
>   (inline_edge_removal_hook): Turn to ...
>   (ipa_call_summary_t::remove): ... this one.
>   (dump_inline_edge_summary): Turn to ...
>   (dump_ipa_call_summary): ... this one.
>   (estimate_function_body_sizes): Update.
>   (inline_update_callee_summaries): Update.
>   (remap_edge_change_prob): Update.
>   (remap_edge_summaries): Update.
>   (inline_merge_summary): Update.
>   (do_estimate_edge_time): Update.
>   (inline_generate_summary): Update.
>   (inline_read_section): Update.
>   (inline_read_summary): Update.
>   (inline_free_summary): Update.
>   * ipa-inline.c (can_inline_edge_p): Update.
>   (compute_inlined_call_time): Update.
>   (want_inline_small_function_p): Update.
>   (edge_badness): Update.
>   (early_inliner): Update.
>   * ipa-inline.h (inline_edge_summary): Turn to ...
>   (ipa_call_summary): ... this one.
>   (ipa_call_summary_t): New class.
>   (inline_edge_summary_t, inline_edge_summary_vec): Remove.
>   (ipa_call_summaries): New.
>   (inline_edge_summary): Remove.
>   (estimate_edge_growth): Update.
>   * ipa-profile.c (ipa_propagate_frequency_1): Update.
>   * ipa-prop.c (ipa_make_edge_direct_to_target): Update.
>   * ipa-split.c (execute_split_functions): Update.
>   * ipa.c (symbol_table::remove_unreachable_nodes): Update.

between r248242 and r248262, a very large number of IPA-related
testsuite regressions occured, e.g. on x86_64-pc-linux-gnu, but also on
sparc-sun-solaris2.12:

+FAIL: g++.dg/ipa/devirt-42.C  -std=gnu++11  scan-ipa-dump-times inline 
"Discovered a virtual call to a known target" 2
+FAIL: g++.dg/ipa/devirt-42.C  -std=gnu++11  scan-tree-dump-times optimized 
"return 2" 3
+FAIL: g++.dg/ipa/devirt-42.C  -std=gnu++14  scan-ipa-dump-times inline 
"Discovered a virtual call to a known target" 2
+FAIL: g++.dg/ipa/devirt-42.C  -std=gnu++14  scan-tree-dump-times optimized 
"return 2" 3
+FAIL: g++.dg/ipa/devirt-42.C  -std=gnu++98  scan-ipa-dump-times inline 
"Discovered a virtual call to a known target" 2
+FAIL: g++.dg/ipa/devirt-42.C  -std=gnu++98  scan-tree-dump-times optimized 
"return 2" 3
+FAIL: g++.dg/ipa/devirt-45.C  -std=gnu++11  scan-ipa-dump-times inline 
"Discovered a virtual call to a known target[^n]*A::foo" 1
+FAIL: g++.dg/ipa/devirt-45.C  -std=gnu++14  scan-ipa-dump-times inline 
"Discovered a virtual call to a known target[^n]*A::foo" 1
+FAIL: g++.dg/ipa/devirt-45.C  -std=gnu++98  scan-ipa-dump-times inline 
"Discovered a virtual call to a known target[^n]*A::foo" 1
+FAIL: g++.dg/ipa/inline-1.C  -std=gnu++11  scan-ipa-dump-times inline 
"Considering void inline_me(" 1
+FAIL: g++.dg/ipa/inline-1.C  -std=gnu++11  scan-ipa-dump-times inline 
"Considering void inline_me_too(" 1
+FAIL: g++.dg/ipa/inline-1.C  -std=gnu++14  scan-ipa-dump-times inline 
"Considering void inline_me(" 1
+FAIL: g++.dg/ipa/inline-1.C  -std=gnu++14  scan-ipa-dump-times inline 
"Considering void inline_me_too(" 1
+FAIL: g++.dg/ipa/inline-1.C  -std=gnu++98  scan-ipa-dump-times inline 
"Considering void inline_me(" 1
+FAIL: g++.dg/ipa/inline-1.C  -std=gnu++98  scan-ipa-dump-times inline 
"Considering void inline_me_too(" 1
+FAIL: g++.dg/ipa/inline-2.C  -std=gnu++11  scan-ipa-dump-times inline 
"Considering void inline_me(" 1
+FAIL: g++.dg/ipa/inline-2.C  -std=gnu++11  scan-ipa-dump-times inline 
"Considering void inline_me_too(" 1
+FAIL: g++.dg/ipa/inline-2.C  -std=gnu++14  scan-ipa-dump-times inline 
"Considering void inline_me(" 1
+FAIL: g++.dg/ipa/inline-2.C  -std=gnu++14  scan-ipa-dump-times inline 
"Considering void inline_me_too(" 1
+FAIL: g++.dg/ipa/inline-2.C  -std=gnu++98  scan-ipa-dump-times inline 
"Considering void inline_me(" 1
+FAIL: g++.dg/ipa/inline-2.C  -std=gnu++98  scan-ipa-dump-times inline 
"Considering void inline_me_too(" 1
+FAIL: g++.dg/ipa/inline-3.C  -std=gnu++11  scan-ipa-dump-times inline 
"Considering void inline_me(" 1
+FAIL: g++.dg/ipa/inline-3.C  -std=gnu++11  scan-ipa-dump-times inline 
"Considering void inline_me_too(" 1
+FAIL: g++.dg/ipa/inline-3.C  -std=gnu++14  scan-ipa-dump-times inline 
"Considering void 

[PATCH] rs6000: Make constant formation a tiny bit better

2017-05-19 Thread Segher Boessenkool
If we cannot load a constant into a register in one insn, and that
constant is a valid mask (for rotate instructions), we currently
prefer to load -1 and then mask it.  This patch makes us not do that if
instead we could use two add or or instructions, since those are
sometimes faster on certain CPUs (and never are slower).

Tested on powerpc64-linux {-m32,-m64}, committing to trunk.


Segher


2017-05-19  Segher Boessenkool  

* config/rs6000/rs6000.md (splitter to load of -1 and mask): Don't
use this splitter if two add or or instructions would also work for
the constant we want to generate.

---
 gcc/config/rs6000/rs6000.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 0a806b3..b7eedf2 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -8704,6 +8704,7 @@ (define_split
(match_operand:DI 1 "const_int_operand"))]
   "TARGET_POWERPC64
&& num_insns_constant (operands[1], DImode) > 1
+   && !IN_RANGE (INTVAL (operands[1]), -0x8000, 0x)
&& rs6000_is_valid_and_mask (operands[1], DImode)"
   [(set (match_dup 0)
(const_int -1))
-- 
1.9.3



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

2017-05-19 Thread Richard Biener
On Wed, May 17, 2017 at 10:45 AM, Martin Liška  wrote:
> Hi.
>
> As discussed on IRC some time ago, there are configurations that produce 
> -Werror=maybe-uninitialized
> and other warnings that break bootstrap. So that, the patch makes -Werror 
> just for default (boostrap-debug)
> configuration.
>
> Ready for trunk?

Hmm, this enables werror on release branches.  I think we also want to
enable Werror for
--without-build-config (or =yes and =no), thus regular bootstrap
without bootstrap-debug.

Richard.

> Martin


[PATCH] Fix PR80821

2017-05-19 Thread Richard Biener

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

Richard.

2017-05-19  Richard Biener  

PR build/80821
* genmatch.c (dt_node::gen_kids_1): Add missing scope around
predicate evaluation.

Index: gcc/genmatch.c
===
--- gcc/genmatch.c  (revision 248263)
+++ gcc/genmatch.c  (working copy)
@@ -3005,6 +3013,8 @@ dt_node::gen_kids_1 (FILE *f, int indent
   expr *e = as_a  (preds[i]->op);
   predicate_id *p = as_a  (e->operation);
   preds[i]->get_name (kid_opname);
+  fprintf_indent (f, indent, "{\n");
+  indent += 2;
   fprintf_indent (f, indent, "tree %s_pops[%d];\n", kid_opname, p->nargs);
   fprintf_indent (f, indent, "if (%s_%s (%s, %s_pops%s))\n",
   gimple ? "gimple" : "tree",
@@ -3020,6 +3030,8 @@ dt_node::gen_kids_1 (FILE *f, int indent
}
   preds[i]->gen_kids (f, indent + 4, gimple);
   fprintf (f, "}\n");
+  indent -= 2;
+  fprintf_indent (f, indent, "}\n");
 }
 
   for (unsigned i = 0; i < others.length (); ++i)



Re: Remove unused "default_kind" member from gcc/omp-low.c's "struct omp_context"

2017-05-19 Thread Thomas Schwinge
Hi!

Ping.

On Fri, 31 Mar 2017 17:05:29 +0200, I wrote:
> It would appear that ever since the first version of gcc/omp-low.c got
> committed to GCC trunk (more than ten years ago), it extraced OpenMP
> default clause data that it doesn't actually use for anything.  OK to
> commit the following cleanup to trunk in next stage 1?
> 
> commit cd157ff348694009f4043b84f47de8c62774931f
> Author: Thomas Schwinge 
> Date:   Fri Mar 31 15:26:55 2017 +0200
> 
> Remove unused "default_kind" member from gcc/omp-low.c's "struct 
> omp_context"
> 
> gcc/
> * omp-low.c (struct omp_context): Remove "default_kind" member.
> Adjust all users.
> ---
>  gcc/omp-low.c | 12 +---
>  1 file changed, 1 insertion(+), 11 deletions(-)
> 
> diff --git gcc/omp-low.c gcc/omp-low.c
> index 253dc85..d794e00 100644
> --- gcc/omp-low.c
> +++ gcc/omp-low.c
> @@ -112,10 +112,6 @@ struct omp_context
>   otherwise.  */
>gimple *simt_stmt;
>  
> -  /* What to do with variables with implicitly determined sharing
> - attributes.  */
> -  enum omp_clause_default_kind default_kind;
> -
>/* Nesting depth of this context.  Used to beautify error messages re
>   invalid gotos.  The outermost ctx is depth 1, with depth 0 being
>   reserved for the main body of the function.  */
> @@ -1162,10 +1158,6 @@ scan_sharing_clauses (tree clauses, omp_context *ctx,
> install_var_field (decl, by_ref, 3, ctx);
> break;
>  
> - case OMP_CLAUSE_DEFAULT:
> -   ctx->default_kind = OMP_CLAUSE_DEFAULT_KIND (c);
> -   break;
> -
>   case OMP_CLAUSE_FINAL:
>   case OMP_CLAUSE_IF:
>   case OMP_CLAUSE_NUM_THREADS:
> @@ -1332,6 +1324,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx,
>   case OMP_CLAUSE_SEQ:
>   case OMP_CLAUSE_TILE:
>   case OMP_CLAUSE__SIMT_:
> + case OMP_CLAUSE_DEFAULT:
> break;
>  
>   case OMP_CLAUSE_ALIGNED:
> @@ -1826,7 +1819,6 @@ scan_omp_parallel (gimple_stmt_iterator *gsi, 
> omp_context *outer_ctx)
>if (taskreg_nesting_level > 1)
>  ctx->is_nested = true;
>ctx->field_map = splay_tree_new (splay_tree_compare_pointers, 0, 0);
> -  ctx->default_kind = OMP_CLAUSE_DEFAULT_SHARED;
>ctx->record_type = lang_hooks.types.make_type (RECORD_TYPE);
>name = create_tmp_var_name (".omp_data_s");
>name = build_decl (gimple_location (stmt),
> @@ -1873,7 +1865,6 @@ scan_omp_task (gimple_stmt_iterator *gsi, omp_context 
> *outer_ctx)
>if (taskreg_nesting_level > 1)
>  ctx->is_nested = true;
>ctx->field_map = splay_tree_new (splay_tree_compare_pointers, 0, 0);
> -  ctx->default_kind = OMP_CLAUSE_DEFAULT_SHARED;
>ctx->record_type = lang_hooks.types.make_type (RECORD_TYPE);
>name = create_tmp_var_name (".omp_data_s");
>name = build_decl (gimple_location (stmt),
> @@ -2360,7 +2351,6 @@ scan_omp_target (gomp_target *stmt, omp_context 
> *outer_ctx)
>  
>ctx = new_omp_context (stmt, outer_ctx);
>ctx->field_map = splay_tree_new (splay_tree_compare_pointers, 0, 0);
> -  ctx->default_kind = OMP_CLAUSE_DEFAULT_SHARED;
>ctx->record_type = lang_hooks.types.make_type (RECORD_TYPE);
>name = create_tmp_var_name (".omp_data_t");
>name = build_decl (gimple_location (stmt),


Grüße
 Thomas


Re: OpenACC 2.5 kernels construct: num_gangs, num_workers, vector_length clauses

2017-05-19 Thread Thomas Schwinge
Hi!

Ping.

On Thu, 11 May 2017 14:26:51 +0200, I wrote:
> [...] support the num_gangs, num_workers, vector_length
> clauses for the OpenACC 2.5 kernels construct.  OK for trunk?
> 
> commit a689c52cde71960bc08ae30c3f88980f66fdd0b8
> Author: Thomas Schwinge 
> Date:   Thu May 11 13:43:28 2017 +0200
> 
> OpenACC 2.5 kernels construct: num_gangs, num_workers, vector_length 
> clauses
> 
> gcc/c/
> * c-parser.c (OACC_KERNELS_CLAUSE_MASK): Add
> "PRAGMA_OACC_CLAUSE_NUM_GANGS", "PRAGMA_OACC_CLAUSE_NUM_WORKERS",
> "VECTOR_LENGTH".
> gcc/cp/
> * parser.c (OACC_KERNELS_CLAUSE_MASK): Add
> "PRAGMA_OACC_CLAUSE_NUM_GANGS", "PRAGMA_OACC_CLAUSE_NUM_WORKERS",
> "VECTOR_LENGTH".
> gcc/fortran/
> * openmp.c (OACC_KERNELS_CLAUSES): Add "OMP_CLAUSE_NUM_GANGS",
> "OMP_CLAUSE_NUM_WORKERS", "OMP_CLAUSE_VECTOR_LENGTH".
> gcc/
> * omp-offload.c (execute_oacc_device_lower): Remove the
> parallelism dimensions function attributes for unparallelized
> OpenACC kernels constructs.
> gcc/testsuite/
> * c-c++-common/goacc/parallel-dims-1.c: Update.
> * c-c++-common/goacc/parallel-dims-2.c: Likewise.
> * c-c++-common/goacc/routine-1.c: Likewise.
> * c-c++-common/goacc/uninit-dim-clause.c: Likewise.
> * g++.dg/goacc/template.C: Likewise.
> * gfortran.dg/goacc/kernels-tree.f95: Likewise.
> * gfortran.dg/goacc/routine-3.f90: Likewise.
> * gfortran.dg/goacc/sie.f95: Likewise.
> * gfortran.dg/goacc/uninit-dim-clause.f95: Likewise.
> libgomp/
> * testsuite/libgomp.oacc-c-c++-common/kernels-loop-2.c: Update.
> * testsuite/libgomp.oacc-c-c++-common/parallel-dims.c: Likewise.
> * testsuite/libgomp.oacc-fortran/kernels-loop-2.f95: Likewise.
> ---
>  gcc/c/c-parser.c   |   3 +
>  gcc/cp/parser.c|   3 +
>  gcc/fortran/openmp.c   |   3 +-
>  gcc/omp-offload.c  |   9 ++
>  gcc/testsuite/c-c++-common/goacc/parallel-dims-1.c |   3 +
>  gcc/testsuite/c-c++-common/goacc/parallel-dims-2.c | 152 
> +++--
>  gcc/testsuite/c-c++-common/goacc/routine-1.c   |   7 +
>  .../c-c++-common/goacc/uninit-dim-clause.c |  20 ++-
>  gcc/testsuite/g++.dg/goacc/template.C  |   4 +
>  gcc/testsuite/gfortran.dg/goacc/kernels-tree.f95   |   6 +-
>  gcc/testsuite/gfortran.dg/goacc/routine-3.f90  |   6 +
>  gcc/testsuite/gfortran.dg/goacc/sie.f95|  86 +++-
>  .../gfortran.dg/goacc/uninit-dim-clause.f95|  18 ++-
>  .../libgomp.oacc-c-c++-common/kernels-loop-2.c |  21 ++-
>  .../libgomp.oacc-c-c++-common/parallel-dims.c  |  35 +
>  .../libgomp.oacc-fortran/kernels-loop-2.f95|  13 +-
>  16 files changed, 358 insertions(+), 31 deletions(-)
> 
> diff --git gcc/c/c-parser.c gcc/c/c-parser.c
> index 90d2d17..c0d733c 100644
> --- gcc/c/c-parser.c
> +++ gcc/c/c-parser.c
> @@ -13978,11 +13978,14 @@ c_parser_oacc_loop (location_t loc, c_parser 
> *parser, char *p_name,
>   | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
>   | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR)   \
>   | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)  \
> + | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS)   \
> + | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
>   | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
>   | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
>   | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN)   \
>   | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT)  \
>   | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE)   \
> + | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH)   \
>   | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
>  
>  #define OACC_PARALLEL_CLAUSE_MASK\
> diff --git gcc/cp/parser.c gcc/cp/parser.c
> index 17d2679..0578e81 100644
> --- gcc/cp/parser.c
> +++ gcc/cp/parser.c
> @@ -36438,11 +36438,14 @@ cp_parser_oacc_loop (cp_parser *parser, cp_token 
> *pragma_tok, char *p_name,
>   | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
>   | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR)   \
>   | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)  \
> + | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS)   \
> + | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
>   | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
>   | (OMP_CLAUSE_MASK_1 << 

Re: [PATCH] Try harder to fix recently introduced crashes in ggc_collect

2017-05-19 Thread Nathan Sidwell

On 05/19/2017 03:51 AM, Richard Biener wrote:


you are commoning 'hwi' here.   Also a bad (very short) name for a global
(even if static).

I'll leave review to Nathan anyway.


IMHO the C FE changes are obvious, with the fixing of the hwi name I 
guess.  I'll go rename fn1..6 in the C++ FE once this lands.


nathan

--
Nathan Sidwell


Re: Runtime checking of OpenACC parallelism dimensions clauses

2017-05-19 Thread Thomas Schwinge
Hi!

Ping.

On Thu, 11 May 2017 14:24:05 +0200, I wrote:
> OK for trunk?
> 
> commit 0ba48b4faf85420fbe12971afdd6e0afe70778bb
> Author: Thomas Schwinge 
> Date:   Fri May 5 16:41:59 2017 +0200
> 
> Runtime checking of OpenACC parallelism dimensions clauses
> 
> libgomp/
> * testsuite/libgomp.oacc-c-c++-common/parallel-dims.c: Rewrite.
> * testsuite/lib/libgomp.exp
> (check_effective_target_openacc_nvidia_accel_configured): New
> proc.
> * testsuite/libgomp.oacc-c++/c++.exp (check_effective_target_c)
> (check_effective_target_c++): New procs.
> * testsuite/libgomp.oacc-c/c.exp (check_effective_target_c)
> (check_effective_target_c++): Likewise.
> ---
>  libgomp/testsuite/lib/libgomp.exp  |  12 +
>  libgomp/testsuite/libgomp.oacc-c++/c++.exp |   7 +
>  .../libgomp.oacc-c-c++-common/parallel-dims.c  | 523 
> -
>  libgomp/testsuite/libgomp.oacc-c/c.exp |   7 +
>  4 files changed, 537 insertions(+), 12 deletions(-)
> 
> diff --git libgomp/testsuite/lib/libgomp.exp libgomp/testsuite/lib/libgomp.exp
> index 5e47872..62ee2e3 100644
> --- libgomp/testsuite/lib/libgomp.exp
> +++ libgomp/testsuite/lib/libgomp.exp
> @@ -358,6 +358,18 @@ proc check_effective_target_offload_device_shared_as { } 
> {
>  } ]
>  }
>  
> +# Return 1 if configured for nvptx offloading.
> +
> +proc check_effective_target_openacc_nvidia_accel_configured { } {
> +global offload_targets
> +if { ![string match "*,nvptx,*" ",$offload_targets,"] } {
> +return 0
> +}
> +# PR libgomp/65099: Currently, we only support offloading in 64-bit
> +# configurations.
> +return [is-effective-target lp64]
> +}
> +
>  # Return 1 if at least one nvidia board is present.
>  
>  proc check_effective_target_openacc_nvidia_accel_present { } {
> diff --git libgomp/testsuite/libgomp.oacc-c++/c++.exp 
> libgomp/testsuite/libgomp.oacc-c++/c++.exp
> index 608b298..9beadd6 100644
> --- libgomp/testsuite/libgomp.oacc-c++/c++.exp
> +++ libgomp/testsuite/libgomp.oacc-c++/c++.exp
> @@ -4,6 +4,13 @@ load_lib libgomp-dg.exp
>  load_gcc_lib gcc-dg.exp
>  load_gcc_lib torture-options.exp
>  
> +proc check_effective_target_c { } {
> +return 0
> +}
> +proc check_effective_target_c++ { } {
> +return 1
> +}
> +
>  global shlib_ext
>  
>  set shlib_ext [get_shlib_extension]
> diff --git libgomp/testsuite/libgomp.oacc-c-c++-common/parallel-dims.c 
> libgomp/testsuite/libgomp.oacc-c-c++-common/parallel-dims.c
> index f5766a4..d8af546 100644
> --- libgomp/testsuite/libgomp.oacc-c-c++-common/parallel-dims.c
> +++ libgomp/testsuite/libgomp.oacc-c-c++-common/parallel-dims.c
> @@ -1,25 +1,524 @@
> -/* { dg-do run { target openacc_nvidia_accel_selected } } */
> +/* OpenACC parallelism dimensions clauses: num_gangs, num_workers,
> +   vector_length.  */
> +
> +#include 
> +#include 
> +
> +/* TODO: "(int) acc_device_*" casts because of the C++ acc_on_device wrapper
> +   not behaving as expected for -O0.  */
> +#pragma acc routine seq
> +static unsigned int __attribute__ ((optimize ("O2"))) acc_gang ()
> +{
> +  if (acc_on_device ((int) acc_device_host))
> +return 0;
> +  else if (acc_on_device ((int) acc_device_nvidia))
> +{
> +  unsigned int r;
> +  asm volatile ("mov.u32 %0,%%ctaid.x;" : "=r" (r));
> +  return r;
> +}
> +  else
> +__builtin_abort ();
> +}
> +
> +#pragma acc routine seq
> +static unsigned int __attribute__ ((optimize ("O2"))) acc_worker ()
> +{
> +  if (acc_on_device ((int) acc_device_host))
> +return 0;
> +  else if (acc_on_device ((int) acc_device_nvidia))
> +{
> +  unsigned int r;
> +  asm volatile ("mov.u32 %0,%%tid.y;" : "=r" (r));
> +  return r;
> +}
> +  else
> +__builtin_abort ();
> +}
> +
> +#pragma acc routine seq
> +static unsigned int __attribute__ ((optimize ("O2"))) acc_vector ()
> +{
> +  if (acc_on_device ((int) acc_device_host))
> +return 0;
> +  else if (acc_on_device ((int) acc_device_nvidia))
> +{
> +  unsigned int r;
> +  asm volatile ("mov.u32 %0,%%tid.x;" : "=r" (r));
> +  return r;
> +}
> +  else
> +__builtin_abort ();
> +}
>  
> -/* Worker and vector size checks.  Picked an outrageously large
> -   value. */
>  
>  int main ()
>  {
> -  int dummy[10];
> +  acc_init (acc_device_default);
>  
> -#pragma acc parallel num_workers (2<<20) /* { dg-error "using num_workers" } 
> */
> +  /* Non-positive value.  */
> +
> +  /* GR, WS, VS.  */
> +  {
> +#define GANGS 0 /* { dg-warning "'num_gangs' value must be positive" "" { 
> target c } } */
> +int gangs_actual = GANGS;
> +int gangs_min, gangs_max, workers_min, workers_max, vectors_min, 
> vectors_max;
> +gangs_min = workers_min = vectors_min = INT_MAX;
> +gangs_max = workers_max = vectors_max = INT_MIN;
> +#pragma acc parallel copy (gangs_actual) \
> +  reduction 

Re: [PATCH] [Aarch64] Variable shift count truncation issues

2017-05-19 Thread Christophe Lyon
Hi Michael,


On 19 May 2017 at 09:21, Richard Sandiford  wrote:
> Thanks for doing this.  Just a couple of comments about the .md stuff:
>
> Michael Collison  writes:
>> diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
>> index 5adc5ed..c6ae670 100644
>> --- a/gcc/config/aarch64/aarch64.md
>> +++ b/gcc/config/aarch64/aarch64.md
>> @@ -3999,6 +3999,92 @@
>>}
>>  )
>>
>> +;; When the LSL, LSR, ASR, ROR instructions operate on all register 
>> arguments
>> +;; they truncate the shift/rotate amount by the size of the registers they
>> +;; operate on: 32 for W-regs, 63 for X-regs.  This allows us to optimise 
>> away
>> +;; such redundant masking instructions.  GCC can do that automatically when
>> +;; SHIFT_COUNT_TRUNCATED is true, but we can't enable it for TARGET_SIMD
>> +;; because some of the SISD shift alternatives don't perform this 
>> truncations.
>> +;; So this pattern exists to catch such cases.
>> +
>> +(define_insn "*aarch64__reg_3_mask1"
>> +  [(set (match_operand:GPI 0 "register_operand" "=r")
>> + (SHIFT:GPI
>> +   (match_operand:GPI 1 "register_operand" "r")
>> +   (subreg:QI (and:GPI
>> +   (match_operand:GPI 2 "register_operand" "r")
>> +   (match_operand 3 "const_int_operand" "n")) 0)))]
>> +  "(~INTVAL (operands[3]) & (GET_MODE_BITSIZE (mode)-1)) == 0"
>> +  "\t%0, %1, %2"
>> +  [(set_attr "type" "shift_reg")]
>> +)
>
> (subreg:QI (...) 0) is only correct for little endian.  For big endian
> it needs to be 3 for SI or 7 for DI.  You could probably handle that
> using something like:
>
>   (match_operator:QI 2 "lowpart_subreg"
> [(and:GPI ...)])
>
> and defining a lowpart_subreg predicate that checks the SUBREG_BYTE.
> Or just leave the subreg as-is and add !BYTES_BIG_ENDIAN to the insn
> condition.
>

I can confirm that the new tests pass on little-endian, but fail on big.

Thanks,

Christophe


>> +(define_insn_and_split "*aarch64_reg_3_neg_mask2"
>> +  [(set (match_operand:GPI 0 "register_operand" "=r")
>> + (SHIFT:GPI
>> +   (match_operand:GPI 1 "register_operand" "r")
>> +   (subreg:QI (neg:SI (and:SI
>> +   (match_operand:SI 2 "register_operand" "r")
>> +   (match_operand 3 "const_int_operand" "n"))) 0)))]
>> +  "((~INTVAL (operands[3]) & (GET_MODE_BITSIZE (mode)-1)) == 0)
>> +   && can_create_pseudo_p ()"
>> +  "#"
>> +  "&& true"
>> +  [(const_int 0)]
>> +  {
>> +rtx tmp = gen_reg_rtx (SImode);
>> +
>> +emit_insn (gen_negsi2 (tmp, operands[2]));
>> +rtx tmp2 = simplify_gen_subreg (QImode, tmp, SImode, 0);
>> +emit_insn (gen_3 (operands[0], operands[1], tmp2));
>> +DONE;
>> +  }
>> +)
>
> Insn patterns shouldn't check can_create_pseudo_p, because there's no
> guarantee that the associated split happens before RA.  In this case it
> should be safe to reuse operand 0 after RA if you change it to:
>
>   [(set (match_operand:GPI 0 "register_operand" "=")
> ...)]
>
> and then:
>
>   rtx tmp = (can_create_pseudo_p ()
>  ? gen_reg_rtx (SImode)
>  : gen_lowpart (SImode, operands[0]));
>
> Thanks,
> Richard


Re: [PATCH][Aarch64] Add support for overflow add and sub operations

2017-05-19 Thread Christophe Lyon
Hi Michael,


On 19 May 2017 at 07:12, Michael Collison  wrote:
> Hi,
>
> This patch improves code generations for builtin arithmetic overflow 
> operations for the aarch64 backend. As an example for a simple test case such 
> as:
>
> Sure for a simple test case such as:
>
> int
> f (int x, int y, int *ovf)
> {
>   int res;
>   *ovf = __builtin_sadd_overflow (x, y, );
>   return res;
> }
>
> Current trunk at -O2 generates
>
> f:
> mov w3, w0
> mov w4, 0
> add w0, w0, w1
> tbnzw1, #31, .L4
> cmp w0, w3
> blt .L3
> .L2:
> str w4, [x2]
> ret
> .p2align 3
> .L4:
> cmp w0, w3
> ble .L2
> .L3:
> mov w4, 1
> b   .L2
>
>
> With the patch this now generates:
>
> f:
> addsw0, w0, w1
> csetw1, vs
> str w1, [x2]
> ret
>
>
> Original patch from Richard Henderson:
>
> https://gcc.gnu.org/ml/gcc-patches/2016-01/msg01903.html
>
>
> Okay for trunk?
>
> 2017-05-17  Michael Collison  
> Richard Henderson 
>
> * config/aarch64/aarch64-modes.def (CC_V): New.
> * config/aarch64/aarch64-protos.h
> (aarch64_add_128bit_scratch_regs): Declare
> (aarch64_add_128bit_scratch_regs): Declare.
> (aarch64_expand_subvti): Declare.
> (aarch64_gen_unlikely_cbranch): Declare
> * config/aarch64/aarch64.c (aarch64_select_cc_mode): Test
> for signed overflow using CC_Vmode.
> (aarch64_get_condition_code_1): Handle CC_Vmode.
> (aarch64_gen_unlikely_cbranch): New function.
> (aarch64_add_128bit_scratch_regs): New function.
> (aarch64_subv_128bit_scratch_regs): New function.
> (aarch64_expand_subvti): New function.
> * config/aarch64/aarch64.md (addv4, uaddv4): New.
> (addti3): Create simpler code if low part is already known to be 0.
> (addvti4, uaddvti4): New.
> (*add3_compareC_cconly_imm): New.
> (*add3_compareC_cconly): New.
> (*add3_compareC_imm): New.
> (*add3_compareC): Rename from add3_compare1; do not
> handle constants within this pattern.
> (*add3_compareV_cconly_imm): New.
> (*add3_compareV_cconly): New.
> (*add3_compareV_imm): New.
> (add3_compareV): New.
> (add3_carryinC, add3_carryinV): New.
> (*add3_carryinC_zero, *add3_carryinV_zero): New.
> (*add3_carryinC, *add3_carryinV): New.
> (subv4, usubv4): New.
> (subti): Handle op1 zero.
> (subvti4, usub4ti4): New.
> (*sub3_compare1_imm): New.
> (sub3_carryinCV): New.
> (*sub3_carryinCV_z1_z2, *sub3_carryinCV_z1): New.
> (*sub3_carryinCV_z2, *sub3_carryinCV): New.
> * testsuite/gcc.target/arm/builtin_sadd_128.c: New testcase.
> * testsuite/gcc.target/arm/builtin_saddl.c: New testcase.
> * testsuite/gcc.target/arm/builtin_saddll.c: New testcase.
> * testsuite/gcc.target/arm/builtin_uadd_128.c: New testcase.
> * testsuite/gcc.target/arm/builtin_uaddl.c: New testcase.
> * testsuite/gcc.target/arm/builtin_uaddll.c: New testcase.
> * testsuite/gcc.target/arm/builtin_ssub_128.c: New testcase.
> * testsuite/gcc.target/arm/builtin_ssubl.c: New testcase.
> * testsuite/gcc.target/arm/builtin_ssubll.c: New testcase.
> * testsuite/gcc.target/arm/builtin_usub_128.c: New testcase.
> * testsuite/gcc.target/arm/builtin_usubl.c: New testcase.
> * testsuite/gcc.target/arm/builtin_usubll.c: New testcase.

I've tried your patch, and 2 of the new tests FAIL:
gcc.target/aarch64/builtin_sadd_128.c scan-assembler addcs
gcc.target/aarch64/builtin_uadd_128.c scan-assembler addcs

Am I missing something?

Thanks,

Christophe


Re: [PATCH] Prevent extract_muldiv from introducing an overflow (PR sanitizer/80800)

2017-05-19 Thread Alexander Monakov
On Fri, 19 May 2017, Richard Biener wrote:

> On Fri, 19 May 2017, Marek Polacek wrote:
> 
> > On Fri, May 19, 2017 at 09:58:45AM +0200, Richard Biener wrote:
> > > On Fri, 19 May 2017, Marek Polacek wrote:
> > > 
> > > > extract_muldiv folds 
> > > > 
> > > >   (n * 1 * z) * 50
> > > > 
> > > > to
> > > > 
> > > >   (n * 50) * z
> > > > 
> > > > which is a wrong transformation to do, because it may introduce an 
> > > > overflow.
> > > > This resulted in a ubsan false positive.  So we should just disable this
> > > > folding altogether.  Does the approach I took make sense?

I think it's possible to keep this folding, note that it's valid to transform to

(n * 1 * z) * 50

(i.e. accumulate multiplications on the outermost factor)

> > > > 
> > > > Bootstrapped/regtested on x86_64-linux, ok for trunk?
> > > 
> > > Didn't dig very far to identify extract_muldiv, but I guess it's either
> > > of the following recursions that trigger?
> > > 
> > >   /* If we can extract our operation from the LHS, do so and return a
> > >  new operation.  Likewise for the RHS from a MULT_EXPR.  
> > > Otherwise,
> > >  do something only if the second operand is a constant.  */
> > >   if (same_p
> > >   && (t1 = extract_muldiv (op0, c, code, wide_type,
> > >strict_overflow_p)) != 0)
> > > return fold_build2 (tcode, ctype, fold_convert (ctype, t1),
> > > fold_convert (ctype, op1));
> > >   else if (tcode == MULT_EXPR && code == MULT_EXPR
> > >&& (t1 = extract_muldiv (op1, c, code, wide_type,
> > > strict_overflow_p)) != 0)
> > > return fold_build2 (tcode, ctype, fold_convert (ctype, op0),
> > > fold_convert (ctype, t1));
> > 
> > Exactly.  extract_muldiv first gets (n * 1 * z) * 50 so it tries
> > to fold 50 with (subexpressions) of (n * 1 * z).  So it then tries
> > (n * 1) * 50, and then n * 50 and then 1 * 50 which finally
> > works out, so it uses 5 and removes the outermost multiplication.

so would it be possible to adjust things here to remove the innermost
multiplication instead?

Alexander


Re: [PATCH] Prevent extract_muldiv from introducing an overflow (PR sanitizer/80800)

2017-05-19 Thread Richard Biener
On Fri, 19 May 2017, Marek Polacek wrote:

> On Fri, May 19, 2017 at 09:58:45AM +0200, Richard Biener wrote:
> > On Fri, 19 May 2017, Marek Polacek wrote:
> > 
> > > extract_muldiv folds 
> > > 
> > >   (n * 1 * z) * 50
> > > 
> > > to
> > > 
> > >   (n * 50) * z
> > > 
> > > which is a wrong transformation to do, because it may introduce an 
> > > overflow.
> > > This resulted in a ubsan false positive.  So we should just disable this
> > > folding altogether.  Does the approach I took make sense?
> > > 
> > > Bootstrapped/regtested on x86_64-linux, ok for trunk?
> > 
> > Didn't dig very far to identify extract_muldiv, but I guess it's either
> > of the following recursions that trigger?
> > 
> >   /* If we can extract our operation from the LHS, do so and return a
> >  new operation.  Likewise for the RHS from a MULT_EXPR.  
> > Otherwise,
> >  do something only if the second operand is a constant.  */
> >   if (same_p
> >   && (t1 = extract_muldiv (op0, c, code, wide_type,
> >strict_overflow_p)) != 0)
> > return fold_build2 (tcode, ctype, fold_convert (ctype, t1),
> > fold_convert (ctype, op1));
> >   else if (tcode == MULT_EXPR && code == MULT_EXPR
> >&& (t1 = extract_muldiv (op1, c, code, wide_type,
> > strict_overflow_p)) != 0)
> > return fold_build2 (tcode, ctype, fold_convert (ctype, op0),
> > fold_convert (ctype, t1));
> 
> Exactly.  extract_muldiv first gets (n * 1 * z) * 50 so it tries
> to fold 50 with (subexpressions) of (n * 1 * z).  So it then tries
> (n * 1) * 50, and then n * 50 and then 1 * 50 which finally
> works out, so it uses 5 and removes the outermost multiplication.
> 
> > thus I'd simply guard them with TYPE_OVERFLOW_WRAPS ().
> 
> That works, too.  I was afraid it'd disable too much folding.
> 
> > In the end I think the whole extract_muldiv mess should be truncated
> > down to what its name suggest - identifying and removing mul-div
> > cancellations.
> 
> Would be nice.  I had trouble wrapping my head around it.

Yeah, happens everytime I need to chase a bug in it...

> > It's for example not clear whether the recursion above assumes
> > TYPE_OVERFLOW_UNDEFINED (it passes a wide_type .. widening is only
> > ok if there's no overflow).
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?

Ok.

Thanks,
Richard.

> 2017-05-19  Marek Polacek  
> 
>   PR sanitizer/80800
>   * fold-const.c (extract_muldiv_1) : Add
>   TYPE_OVERFLOW_WRAPS checks.
> 
>   * c-c++-common/ubsan/pr80800.c: New test.
>   * c-c++-common/Wduplicated-branches-1.c: Adjust an expression.
> 
> 
> diff --git gcc/fold-const.c gcc/fold-const.c
> index 19aa722..736552c 100644
> --- gcc/fold-const.c
> +++ gcc/fold-const.c
> @@ -6281,11 +6281,13 @@ extract_muldiv_1 (tree t, tree c, enum tree_code 
> code, tree wide_type,
>new operation.  Likewise for the RHS from a MULT_EXPR.  Otherwise,
>do something only if the second operand is a constant.  */
>if (same_p
> +   && TYPE_OVERFLOW_WRAPS (ctype)
> && (t1 = extract_muldiv (op0, c, code, wide_type,
>  strict_overflow_p)) != 0)
>   return fold_build2 (tcode, ctype, fold_convert (ctype, t1),
>   fold_convert (ctype, op1));
>else if (tcode == MULT_EXPR && code == MULT_EXPR
> +&& TYPE_OVERFLOW_WRAPS (ctype)
>  && (t1 = extract_muldiv (op1, c, code, wide_type,
>   strict_overflow_p)) != 0)
>   return fold_build2 (tcode, ctype, fold_convert (ctype, op0),
> diff --git gcc/testsuite/c-c++-common/Wduplicated-branches-1.c 
> gcc/testsuite/c-c++-common/Wduplicated-branches-1.c
> index c0b93fc..7c5062d 100644
> --- gcc/testsuite/c-c++-common/Wduplicated-branches-1.c
> +++ gcc/testsuite/c-c++-common/Wduplicated-branches-1.c
> @@ -89,7 +89,7 @@ f (int i, int *p)
>if (i == 8) /* { dg-warning "this condition has identical branches" } */
>  return i * 8 * i * 8;
>else
> -return 8 * i * 8 * i;
> +return i * 8 * i * 8;
>  
>  
>if (i == 9) /* { dg-warning "this condition has identical branches" } */
> diff --git gcc/testsuite/c-c++-common/ubsan/pr80800.c 
> gcc/testsuite/c-c++-common/ubsan/pr80800.c
> index e69de29..992c136 100644
> --- gcc/testsuite/c-c++-common/ubsan/pr80800.c
> +++ gcc/testsuite/c-c++-common/ubsan/pr80800.c
> @@ -0,0 +1,25 @@
> +/* PR sanitizer/80800 */
> +/* { dg-do run } */
> +/* { dg-options "-fsanitize=undefined -fsanitize-undefined-trap-on-error" } 
> */
> +
> +int n = 2;
> +int z = 0;
> +
> +int
> +fn1 (void)
> +{
> +  return (n * 1 * z) * 50;
> +}
> +
> +int
> +fn2 (void)
> +{
> +  return (1 * n * z) * 50;
> +}
> +
> +int
> +main ()
> +{
> +  fn1 ();
> +  fn2 ();
> +}
> 
>   Marek
> 
> 


[PATCH][2/2] early LTO debug, main part

2017-05-19 Thread Richard Biener

This is a repost of the main part of the early LTO debug support.
The only changes relative to the last post is in the dwarf2out.c
pieces due to Jasons review and Jakubs introduction of
DW_OP_GNU_variable_value.

I've also adjusted testcases for fallout (the asan backtraces do
give files / line numbers because libbacktrace doesn't understand
the DWARF) plus added a -flto run over the libstdc++ pretty printer
testsuite -- after all the goal was to make those work with LTO,
and they now nicely do.

[LTO-]bootstrapped and tested on x86_64-unknown-linux-gnu.

I've also tested with -flto -g and compared to before the patch and
the outcome doesn't contain any surprises.

I've also ran the gdb testsuite with no differences (but I guess
it doesn't exercise LTO).

I've also built SPEC 2k6 with -flto -g.

I've also debugged optimized LTO bootstrapped cc1 a bit - not that
debugging (LTO) optimized cc1 is a pleasant experience, but at least
gdb doesn't crash.

Ok for trunk?

Both darwin and mingw maintainers were not concerned about LTO with -g
being broken for them.

This patch allows us to go forward with freeing more stuff after
the frontend finished, in particular remove LTO streaming of a lot
of type information that is referenced from trees (and, as a first
step, enable free-lang-data for non-LTO compiles).

Thanks,
Richard.

2017-05-19  Richard Biener  

* debug.h (struct gcc_debug_hooks): Add die_ref_for_decl and
register_external_die hooks.
(debug_false_tree_charstarstar_uhwistar): Declare.
(debug_nothing_tree_charstar_uhwi): Likewise.
* debug.c (do_nothing_debug_hooks): Adjust.
(debug_false_tree_charstarstar_uhwistar): New do nothing.
(debug_nothing_tree_charstar_uhwi): Likewise.
* dbxout.c (dbx_debug_hooks): Adjust.
(xcoff_debug_hooks): Likewise.
* sdbout.c (sdb_debug_hooks): Likewise.
* vmsdbgout.c (vmsdbg_debug_hooks): Likewise.

* dwarf2out.c (macinfo_label_base): New global.
(dwarf2out_register_external_die): New function for the
register_external_die hook.
(dwarf2out_die_ref_for_decl): Likewise for die_ref_for_decl.
(dwarf2_debug_hooks): Use them.
(dwarf2_lineno_debug_hooks): Adjust.
(struct die_struct): Add with_offset flag.
(DEBUG_LTO_DWO_INFO_SECTION, DEBUG_LTO_INFO_SECTION,
DEBUG_LTO_DWO_ABBREV_SECTION, DEBUG_LTO_ABBREV_SECTION,
DEBUG_LTO_DWO_MACINFO_SECTION, DEBUG_LTO_MACINFO_SECTION,
DEBUG_LTO_DWO_MACRO_SECTION, DEBUG_LTO_MACRO_SECTION,
DEBUG_LTO_LINE_SECTION, DEBUG_LTO_DWO_STR_OFFSETS_SECTION,
DEBUG_LTO_STR_DWO_SECTION, DEBUG_STR_LTO_SECTION): New macros
defining section names for the early LTO debug variants.
(reset_indirect_string): New helper.
(add_AT_external_die_ref): Helper for dwarf2out_register_external_die.
(print_dw_val): Add support for offsetted symbol references.
(compute_section_prefix_1): Split out worker to distinguish
the comdat from the LTO case.
(compute_section_prefix): Wrap old comdat case here.
(output_die): Skip DIE symbol output for the LTO added one.
Handle DIE symbol references with offset.
(output_comp_unit): Guard section name mangling properly.
For LTO debug sections emit a symbol at the section beginning
which we use to refer to its DIEs.
(add_abstract_origin_attribute): For DIEs registered via
dwarf2out_register_external_die directly refer to the early
DIE rather than indirectly through the shadow one we created.
(gen_array_type_die): When generating early LTO debug do
not emit DW_AT_string_length.
(gen_formal_parameter_die): Do not re-create DIEs for PARM_DECLs
late when in LTO.
(gen_subprogram_die): Adjust the check for whether we face
a concrete instance DIE for an inline we can reuse for the
late LTO case.  Likewise avoid another specification DIE
for early built declarations/definitions for the late LTO case.
(gen_variable_die): Add type references for late duplicated VLA dies
when in late LTO.
(gen_inlined_subroutine_die): Do not call dwarf2out_abstract_function,
we have the abstract instance already.
(process_scope_var): Adjust decl DIE contexts in LTO which
first puts them in limbo.
(gen_decl_die): Do not generate type DIEs late apart from
types for VLAs or for decls we do not yet have a DIE.
(dwarf2out_early_global_decl): Make sure to create DIEs
for abstract instances of a decl first.
(dwarf2out_late_global_decl): Adjust comment.
(output_macinfo_op): With multiple macro sections use
macinfo_label_base to distinguish labels.
(output_macinfo): Likewise.  Update macinfo_label_base.
Pass in the line info label.
(note_variable_value_in_expr): 

Re: [PATCH] Prevent extract_muldiv from introducing an overflow (PR sanitizer/80800)

2017-05-19 Thread Marek Polacek
On Fri, May 19, 2017 at 09:58:45AM +0200, Richard Biener wrote:
> On Fri, 19 May 2017, Marek Polacek wrote:
> 
> > extract_muldiv folds 
> > 
> >   (n * 1 * z) * 50
> > 
> > to
> > 
> >   (n * 50) * z
> > 
> > which is a wrong transformation to do, because it may introduce an overflow.
> > This resulted in a ubsan false positive.  So we should just disable this
> > folding altogether.  Does the approach I took make sense?
> > 
> > Bootstrapped/regtested on x86_64-linux, ok for trunk?
> 
> Didn't dig very far to identify extract_muldiv, but I guess it's either
> of the following recursions that trigger?
> 
>   /* If we can extract our operation from the LHS, do so and return a
>  new operation.  Likewise for the RHS from a MULT_EXPR.  
> Otherwise,
>  do something only if the second operand is a constant.  */
>   if (same_p
>   && (t1 = extract_muldiv (op0, c, code, wide_type,
>strict_overflow_p)) != 0)
> return fold_build2 (tcode, ctype, fold_convert (ctype, t1),
> fold_convert (ctype, op1));
>   else if (tcode == MULT_EXPR && code == MULT_EXPR
>&& (t1 = extract_muldiv (op1, c, code, wide_type,
> strict_overflow_p)) != 0)
> return fold_build2 (tcode, ctype, fold_convert (ctype, op0),
> fold_convert (ctype, t1));

Exactly.  extract_muldiv first gets (n * 1 * z) * 50 so it tries
to fold 50 with (subexpressions) of (n * 1 * z).  So it then tries
(n * 1) * 50, and then n * 50 and then 1 * 50 which finally
works out, so it uses 5 and removes the outermost multiplication.

> thus I'd simply guard them with TYPE_OVERFLOW_WRAPS ().

That works, too.  I was afraid it'd disable too much folding.

> In the end I think the whole extract_muldiv mess should be truncated
> down to what its name suggest - identifying and removing mul-div
> cancellations.

Would be nice.  I had trouble wrapping my head around it.

> It's for example not clear whether the recursion above assumes
> TYPE_OVERFLOW_UNDEFINED (it passes a wide_type .. widening is only
> ok if there's no overflow).

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

2017-05-19  Marek Polacek  

PR sanitizer/80800
* fold-const.c (extract_muldiv_1) : Add
TYPE_OVERFLOW_WRAPS checks.

* c-c++-common/ubsan/pr80800.c: New test.
* c-c++-common/Wduplicated-branches-1.c: Adjust an expression.


diff --git gcc/fold-const.c gcc/fold-const.c
index 19aa722..736552c 100644
--- gcc/fold-const.c
+++ gcc/fold-const.c
@@ -6281,11 +6281,13 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, 
tree wide_type,
 new operation.  Likewise for the RHS from a MULT_EXPR.  Otherwise,
 do something only if the second operand is a constant.  */
   if (same_p
+ && TYPE_OVERFLOW_WRAPS (ctype)
  && (t1 = extract_muldiv (op0, c, code, wide_type,
   strict_overflow_p)) != 0)
return fold_build2 (tcode, ctype, fold_convert (ctype, t1),
fold_convert (ctype, op1));
   else if (tcode == MULT_EXPR && code == MULT_EXPR
+  && TYPE_OVERFLOW_WRAPS (ctype)
   && (t1 = extract_muldiv (op1, c, code, wide_type,
strict_overflow_p)) != 0)
return fold_build2 (tcode, ctype, fold_convert (ctype, op0),
diff --git gcc/testsuite/c-c++-common/Wduplicated-branches-1.c 
gcc/testsuite/c-c++-common/Wduplicated-branches-1.c
index c0b93fc..7c5062d 100644
--- gcc/testsuite/c-c++-common/Wduplicated-branches-1.c
+++ gcc/testsuite/c-c++-common/Wduplicated-branches-1.c
@@ -89,7 +89,7 @@ f (int i, int *p)
   if (i == 8) /* { dg-warning "this condition has identical branches" } */
 return i * 8 * i * 8;
   else
-return 8 * i * 8 * i;
+return i * 8 * i * 8;
 
 
   if (i == 9) /* { dg-warning "this condition has identical branches" } */
diff --git gcc/testsuite/c-c++-common/ubsan/pr80800.c 
gcc/testsuite/c-c++-common/ubsan/pr80800.c
index e69de29..992c136 100644
--- gcc/testsuite/c-c++-common/ubsan/pr80800.c
+++ gcc/testsuite/c-c++-common/ubsan/pr80800.c
@@ -0,0 +1,25 @@
+/* PR sanitizer/80800 */
+/* { dg-do run } */
+/* { dg-options "-fsanitize=undefined -fsanitize-undefined-trap-on-error" } */
+
+int n = 2;
+int z = 0;
+
+int
+fn1 (void)
+{
+  return (n * 1 * z) * 50;
+}
+
+int
+fn2 (void)
+{
+  return (1 * n * z) * 50;
+}
+
+int
+main ()
+{
+  fn1 ();
+  fn2 ();
+}

Marek


[PATCH 7/7] [ARC] Test against frame_pointer_needed in arc_can_eliminate.

2017-05-19 Thread Claudiu Zissulescu
arc_can_eliminate is using arc_frmae_pointer_required() which is wrong
as the frame_pointer_needed can be set on different conditions. Fix it
by calling arc_frame_pointer_needed().

gcc/
2017-01-09  Claudiu Zissulescu  

* config/arc/arc.c (arc_can_eliminate): Test against
arc_frame_pointer_needed.
---
 gcc/config/arc/arc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
index 0c4c901..aac1952 100644
--- a/gcc/config/arc/arc.c
+++ b/gcc/config/arc/arc.c
@@ -4733,7 +4733,7 @@ arc_final_prescan_insn (rtx_insn *insn, rtx *opvec 
ATTRIBUTE_UNUSED,
 static bool
 arc_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
 {
-  return to == FRAME_POINTER_REGNUM || !arc_frame_pointer_required ();
+  return ((to == FRAME_POINTER_REGNUM) || !arc_frame_pointer_needed ());
 }
 
 /* Define the offset between two registers, one to be eliminated, and
-- 
1.9.1



[PATCH 5/7] [ARC] Update (non)commutative_binary_comparison patterns.

2017-05-19 Thread Claudiu Zissulescu
gcc/
2016-12-20  Claudiu Zissulescu  

* config/arc/arc.md (commutative_binary_comparison): Remove 'I'
constraint. It is not valid for the pattern.
(noncommutative_binary_comparison): Likewise.
---
 gcc/config/arc/arc.md | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
index c0ad86c..743a844 100644
--- a/gcc/config/arc/arc.md
+++ b/gcc/config/arc/arc.md
@@ -948,15 +948,15 @@
   [(set (match_operand:CC_ZN 0 "cc_set_register" "")
(match_operator:CC_ZN 5 "zn_compare_operator"
  [(match_operator:SI 4 "commutative_operator"
-[(match_operand:SI 1 "register_operand" "%c,c,c")
- (match_operand:SI 2 "nonmemory_operand" "cL,I,?Cal")])
+[(match_operand:SI 1 "register_operand" "%c,c")
+ (match_operand:SI 2 "nonmemory_operand" "cL,Cal")])
   (const_int 0)]))
-   (clobber (match_scratch:SI 3 "=X,1,X"))]
+   (clobber (match_scratch:SI 3 "=X,X"))]
   ""
   "%O4.f 0,%1,%2"
   [(set_attr "type" "compare")
(set_attr "cond" "set_zn")
-   (set_attr "length" "4,4,8")])
+   (set_attr "length" "4,8")])
 
 ; for flag setting 'add' instructions like if (a+b) { ...}
 ; the combiner needs this pattern
@@ -1050,15 +1050,15 @@
   [(set (match_operand:CC_ZN 0 "cc_set_register" "")
(match_operator:CC_ZN 5 "zn_compare_operator"
  [(match_operator:SI 4 "noncommutative_operator"
-[(match_operand:SI 1 "register_operand" "c,c,c")
- (match_operand:SI 2 "nonmemory_operand" "cL,I,?Cal")])
+[(match_operand:SI 1 "register_operand" "c,c")
+ (match_operand:SI 2 "nonmemory_operand" "cL,Cal")])
   (const_int 0)]))
-   (clobber (match_scratch:SI 3 "=X,1,X"))]
+   (clobber (match_scratch:SI 3 "=X,X"))]
   "TARGET_BARREL_SHIFTER || GET_CODE (operands[4]) == MINUS"
   "%O4.f 0,%1,%2"
   [(set_attr "type" "compare")
(set_attr "cond" "set_zn")
-   (set_attr "length" "4,4,8")])
+   (set_attr "length" "4,8")])
 
 (define_expand "bic_f_zn"
   [(parallel
-- 
1.9.1



[PATCH][1/2] Early LTO debug, simple-object part

2017-05-19 Thread Richard Biener

This is a repost (unchanged) of the simple-object ELF support for
early LTO debug transfer from IL object to a separate debug-only object 
file.

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

Richard.

2017-05-19  Richard Biener  

include/
* simple-object.h (simple_object_copy_lto_debug_sections): New
function.

libiberty/
* simple-object-common.h (struct simple_object_functions): Add
copy_lto_debug_sections hook.
* simple-object.c: Include fcntl.h.
(handle_lto_debug_sections): New helper function.
(simple_object_copy_lto_debug_sections): New function copying
early LTO debug sections to regular debug sections in a new file.
(simple_object_start_write): Handle NULL segment_name.
* simple-object-coff.c (simple_object_coff_functions): Adjust
for not implemented copy_lto_debug_sections hook.
* simple-object-mach-o.c (simple_object_mach_o_functions): Likewise.
* simple-object-xcoff.c (simple_object_xcoff_functions): Likewise.
* simple-object-elf.c (SHT_NULL, SHT_SYMTAB, SHT_RELA, SHT_REL,
SHT_GROUP): Add various sectopn header types.
(SHF_EXCLUDE): Add flag.
(Elf32_External_Sym, Elf64_External_Sym): Add symbol struct.
(ELF_ST_BIND, ELF_ST_TYPE, ELF_ST_INFO): Add accessors.
(STT_OBJECT, STT_FUNC, STT_TLS, STT_GNU_IFUNC): Add Symbol types.
(STV_DEFAULT): Add symbol visibility.
(SHN_COMMON): Add special section index name.
(struct simple_object_elf_write): New.
(simple_object_elf_start_write): Adjust for new private data.
(simple_object_elf_write_shdr): Pass in values for all fields
we write.
(simple_object_elf_write_to_file): Adjust.  Copy from recorded
section headers if requested.
(simple_object_elf_release_write): Release private data.
(simple_object_elf_copy_lto_debug_sections): Copy and rename sections
as denoted by PFN and all their dependences, symbols and relocations
to the empty destination file.
(simple_object_elf_functions): Adjust for copy_lto_debug_sections hook.

Index: early-lto-debug/include/simple-object.h
===
--- early-lto-debug.orig/include/simple-object.h2016-10-19 
13:19:58.012326431 +0200
+++ early-lto-debug/include/simple-object.h 2016-10-20 10:51:49.861722998 
+0200
@@ -197,6 +197,14 @@ simple_object_write_to_file (simple_obje
 extern void
 simple_object_release_write (simple_object_write *);
 
+/* Copy LTO debug sections from SRC_OBJECT to DEST.
+   If an error occurs, return the errno value in ERR and an error string.  */
+
+extern const char *
+simple_object_copy_lto_debug_sections (simple_object_read *src_object,
+  const char *dest,
+  int *err);
+
 #ifdef __cplusplus
 }
 #endif
Index: early-lto-debug/libiberty/simple-object-common.h
===
--- early-lto-debug.orig/libiberty/simple-object-common.h   2016-10-19 
13:19:58.012326431 +0200
+++ early-lto-debug/libiberty/simple-object-common.h2016-10-20 
10:51:49.865723045 +0200
@@ -141,6 +141,12 @@ struct simple_object_functions
 
   /* Release the private data for an simple_object_write.  */
   void (*release_write) (void *);
+
+  /* Copy LTO debug sections.  */
+  const char *(*copy_lto_debug_sections) (simple_object_read *sobj,
+ simple_object_write *dobj,
+ int (*pfn) (const char **),
+ int *err);
 };
 
 /* The known object file formats.  */
Index: early-lto-debug/libiberty/simple-object-elf.c
===
--- early-lto-debug.orig/libiberty/simple-object-elf.c  2016-10-19 
13:19:58.012326431 +0200
+++ early-lto-debug/libiberty/simple-object-elf.c   2016-10-20 
10:51:49.865723045 +0200
@@ -183,8 +183,55 @@ typedef struct {
 
 /* Values for sh_type field.  */
 
+#define SHT_NULL   0   /* Section header table entry unused */
 #define SHT_PROGBITS   1   /* Program data */
+#define SHT_SYMTAB 2   /* Link editing symbol table */
 #define SHT_STRTAB 3   /* A string table */
+#define SHT_RELA   4   /* Relocation entries with addends */
+#define SHT_REL9   /* Relocation entries, no 
addends */
+#define SHT_GROUP  17  /* Section contains a section group */
+
+/* Values for sh_flags field.  */
+
+#define SHF_EXCLUDE0x8000  /* Link editor is to exclude this
+  section from executable and
+  shared library that it builds
+   

[PATCH 6/7] [ARC] Prevent moving stores to the frame before the stack adjustment.

2017-05-19 Thread Claudiu Zissulescu
From: Claudiu Zissulescu 

If the stack pointer is needed, emit a special barrier that will prevent
the scheduler from moving stores to the frame before the stack adjustment.

2017-01-03  Claudiu Zissulescu  

* config/arc/arc.c (arc_expand_prologue): Emit a special barrier
to prevent store reordering.
* config/arc/arc.md (UNSPEC_ARC_STKTIE): Define.
(type): Add block type.
(stack_tie): Define special instruction to be used in
expand_prologue.
---
 gcc/config/arc/arc.c  | 10 +-
 gcc/config/arc/arc.md | 15 ++-
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
index ff86f6c..0c4c901 100644
--- a/gcc/config/arc/arc.c
+++ b/gcc/config/arc/arc.c
@@ -3030,7 +3030,15 @@ arc_expand_prologue (void)
   frame_size_to_allocate -= first_offset;
   /* Allocate the stack frame.  */
   if (frame_size_to_allocate > 0)
-frame_stack_add ((HOST_WIDE_INT) 0 - frame_size_to_allocate);
+{
+  frame_stack_add ((HOST_WIDE_INT) 0 - frame_size_to_allocate);
+  /* If the frame pointer is needed, emit a special barrier that
+will prevent the scheduler from moving stores to the frame
+before the stack adjustment.  */
+  if (arc_frame_pointer_needed ())
+   emit_insn (gen_stack_tie (stack_pointer_rtx,
+ hard_frame_pointer_rtx));
+}
 
   /* Setup the gp register, if needed.  */
   if (crtl->uses_pic_offset_table)
diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
index 743a844..6cd192a 100644
--- a/gcc/config/arc/arc.md
+++ b/gcc/config/arc/arc.md
@@ -135,6 +135,7 @@
   UNSPEC_ARC_VMAC2HU
   UNSPEC_ARC_VMPY2H
   UNSPEC_ARC_VMPY2HU
+  UNSPEC_ARC_STKTIE
   ])
 
 (define_c_enum "vunspec" [
@@ -205,7 +206,7 @@
simd_vcompare, simd_vpermute, simd_vpack, simd_vpack_with_acc,
simd_valign, simd_valign_with_acc, simd_vcontrol,
simd_vspecial_3cycle, simd_vspecial_4cycle, simd_dma, mul16_em, div_rem,
-   fpu"
+   fpu, block"
   (cond [(eq_attr "is_sfunc" "yes")
 (cond [(match_test "!TARGET_LONG_CALLS_SET && (!TARGET_MEDIUM_CALLS || 
GET_CODE (PATTERN (insn)) != COND_EXEC)") (const_string "call")
(match_test "flag_pic") (const_string "sfunc")]
@@ -6547,6 +6548,18 @@
   (set_attr "predicable" "yes,no,no,yes,no")
   (set_attr "cond" "canuse,nocond,nocond,canuse_limm,nocond")])
 
+(define_insn "stack_tie"
+  [(set (mem:BLK (scratch))
+   (unspec:BLK [(match_operand:SI 0 "register_operand" "rb")
+(match_operand:SI 1 "register_operand" "rb")]
+   UNSPEC_ARC_STKTIE))]
+  ""
+  ""
+  [(set_attr "length" "0")
+   (set_attr "iscompact" "false")
+   (set_attr "type" "block")]
+  )
+
 ;; include the arc-FPX instructions
 (include "fpx.md")
 
-- 
1.9.1



[PATCH 2/7] [ARC] Avoid use of hard registers before reg-alloc.

2017-05-19 Thread Claudiu Zissulescu
gcc/
2017-04-10  Claudiu Zissulescu  

* config/arc/arc.md (mulsi3): Avoid use of hard registers before
reg-alloc when having mul64 or mul32x16 instructions.
(mulsidi3): Likewise.
(umulsidi3): Likewise.
(mulsi32x16): New pattern.
(mulsi64): Likewise.
(mulsidi64): Likewise.
(umulsidi64): Likewise.
(MUL32x16_REG): Define.
(mul64_600): Use MUL32x16_REG.
(mac64_600): Likewise.
(umul64_600): Likewise.
(umac64_600): Likewise.
---
 gcc/config/arc/arc.md | 168 +++---
 1 file changed, 119 insertions(+), 49 deletions(-)

diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
index db5867c..c0ad86c 100644
--- a/gcc/config/arc/arc.md
+++ b/gcc/config/arc/arc.md
@@ -176,6 +176,7 @@
(ILINK2_REGNUM 30)
(RETURN_ADDR_REGNUM 31)
(MUL64_OUT_REG 58)
+   (MUL32x16_REG 56)
(ARCV2_ACC 58)
 
(LP_COUNT 60)
@@ -1940,29 +1941,17 @@
 }
   else if (TARGET_MUL64_SET)
 {
-  emit_insn (gen_mulsi_600 (operands[1], operands[2],
-   gen_mlo (), gen_mhi ()));
-  emit_move_insn (operands[0], gen_mlo ());
-  DONE;
+ rtx tmp = gen_reg_rtx (SImode);
+ emit_insn (gen_mulsi64 (tmp, operands[1], operands[2]));
+ emit_move_insn (operands[0], tmp);
+ DONE;
 }
   else if (TARGET_MULMAC_32BY16_SET)
 {
-  if (immediate_operand (operands[2], SImode)
- && INTVAL (operands[2]) >= 0
- && INTVAL (operands[2]) <= 65535)
-   {
- emit_insn (gen_umul_600 (operands[1], operands[2],
-gen_acc2 (), gen_acc1 ()));
- emit_move_insn (operands[0], gen_acc2 ());
- DONE;
-   }
-  operands[2] = force_reg (SImode, operands[2]);
-  emit_insn (gen_umul_600 (operands[1], operands[2],
-  gen_acc2 (), gen_acc1 ()));
-  emit_insn (gen_mac_600 (operands[1], operands[2],
-  gen_acc2 (), gen_acc1 ()));
-  emit_move_insn (operands[0], gen_acc2 ());
-  DONE;
+ rtx tmp = gen_reg_rtx (SImode);
+ emit_insn (gen_mulsi32x16 (tmp, operands[1], operands[2]));
+ emit_move_insn (operands[0], tmp);
+ DONE;
 }
   else
 {
@@ -1974,6 +1963,35 @@
 }
 })
 
+(define_insn_and_split "mulsi32x16"
+ [(set (match_operand:SI 0 "register_operand""=w")
+   (mult:SI (match_operand:SI 1 "register_operand"  "%c")
+(match_operand:SI 2 "nonmemory_operand" "ci")))
+  (clobber (reg:DI MUL32x16_REG))]
+ "TARGET_MULMAC_32BY16_SET"
+ "#"
+ "TARGET_MULMAC_32BY16_SET && reload_completed"
+ [(const_int 0)]
+ {
+  if (immediate_operand (operands[2], SImode)
+&& INTVAL (operands[2]) >= 0
+&& INTVAL (operands[2]) <= 65535)
+ {
+  emit_insn (gen_umul_600 (operands[1], operands[2],
+  gen_acc2 (), gen_acc1 ()));
+  emit_move_insn (operands[0], gen_acc2 ());
+  DONE;
+ }
+   emit_insn (gen_umul_600 (operands[1], operands[2],
+  gen_acc2 (), gen_acc1 ()));
+   emit_insn (gen_mac_600 (operands[1], operands[2],
+  gen_acc2 (), gen_acc1 ()));
+   emit_move_insn (operands[0], gen_acc2 ());
+   DONE;
+  }
+ [(set_attr "type" "multi")
+  (set_attr "length" "8")])
+
 ; mululw conditional execution without a LIMM clobbers an input register;
 ; we'd need a different pattern to describe this.
 ; To make the conditional execution valid for the LIMM alternative, we
@@ -2011,6 +2029,24 @@
(set_attr "predicable" "no, no, yes")
(set_attr "cond" "nocond, canuse_limm, canuse")])
 
+(define_insn_and_split "mulsi64"
+ [(set (match_operand:SI 0 "register_operand""=w")
+   (mult:SI (match_operand:SI 1 "register_operand"  "%c")
+(match_operand:SI 2 "nonmemory_operand" "ci")))
+  (clobber (reg:DI MUL64_OUT_REG))]
+ "TARGET_MUL64_SET"
+ "#"
+ "TARGET_MUL64_SET && reload_completed"
+  [(const_int 0)]
+{
+  emit_insn (gen_mulsi_600 (operands[1], operands[2],
+   gen_mlo (), gen_mhi ()));
+  emit_move_insn (operands[0], gen_mlo ());
+  DONE;
+}
+  [(set_attr "type" "multi")
+   (set_attr "length" "8")])
+
 (define_insn "mulsi_600"
   [(set (match_operand:SI 2 "mlo_operand" "")
(mult:SI (match_operand:SI 0 "register_operand"  "%Rcq#q,c,c,c")
@@ -2155,8 +2191,7 @@
(mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" ""))
 (sign_extend:DI (match_operand:SI 2 "nonmemory_operand" ""]
   "TARGET_ANY_MPY"
-"
-{
+  {
   if (TARGET_PLUS_MACD)
 {
  if (CONST_INT_P (operands[2]))
@@ -2189,18 +2224,37 @@
 }
   else if (TARGET_MULMAC_32BY16_SET)
 {
-  rtx result_hi = gen_highpart(SImode, operands[0]);
-  rtx result_low = gen_lowpart(SImode, operands[0]);
-
-  emit_insn (gen_mul64_600 (operands[1], operands[2]));
-  

[PATCH 1/7] [ARC] Make mulsi for A700 pattern commutative.

2017-05-19 Thread Claudiu Zissulescu
gcc/
2016-11-10  Claudiu Zissulescu  

* config/arc/arc.md (mulsi3_700): Make it commutative.
---
 gcc/config/arc/arc.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
index 71d076c..db5867c 100644
--- a/gcc/config/arc/arc.md
+++ b/gcc/config/arc/arc.md
@@ -2127,7 +2127,7 @@
 ; like MPY or MPYU.
 (define_insn "mulsi3_700"
  [(set (match_operand:SI 0 "mpy_dest_reg_operand""=Rcr,r,r,Rcr,r")
-   (mult:SI (match_operand:SI 1 "register_operand"  " 0,c,0,0,c")
+   (mult:SI (match_operand:SI 1 "register_operand"  "%0,c,0,0,c")
 (match_operand:SI 2 "nonmemory_operand" "cL,cL,I,Cal,Cal")))]
  "TARGET_ARC700_MPY"
   "mpyu%? %0,%1,%2"
-- 
1.9.1



[PATCH 4/7] [ARC] Change predicate movv2hi to avoid scaled addresses.

2017-05-19 Thread Claudiu Zissulescu
From: Claudiu Zissulescu 

2016-12-17  Claudiu Zissulescu  

* config/arc/simdext.md (movv2hi_insn): Change predicate to avoid
scaled addresses.
---
 gcc/config/arc/simdext.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/arc/simdext.md b/gcc/config/arc/simdext.md
index 5253033..6c102d3 100644
--- a/gcc/config/arc/simdext.md
+++ b/gcc/config/arc/simdext.md
@@ -1356,7 +1356,7 @@
}")
 
 (define_insn_and_split "*movv2hi_insn"
-  [(set (match_operand:V2HI 0 "nonimmediate_operand" "=r,r,r,m")
+  [(set (match_operand:V2HI 0 "move_dest_operand" "=r,r,r,m")
(match_operand:V2HI 1 "general_operand"   "i,r,m,r"))]
   "(register_operand (operands[0], V2HImode)
 || register_operand (operands[1], V2HImode))"
-- 
1.9.1



[PATCH 3/7] [ARC] Allow r30 to be used by the reg-alloc.

2017-05-19 Thread Claudiu Zissulescu
gcc/
2016-12-12  Claudiu Zissulescu  

* config/arc/arc.c (arc_conditional_register_usage): Allow r30 to
be used by the reg-alloc.
---
 gcc/config/arc/arc.c | 9 -
 gcc/config/arc/arc.h | 3 ++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
index fd4bf2c..ff86f6c 100644
--- a/gcc/config/arc/arc.c
+++ b/gcc/config/arc/arc.c
@@ -1551,7 +1551,14 @@ arc_conditional_register_usage (void)
   /* For ARCv2 the core register set is changed.  */
   strcpy (rname29, "ilink");
   strcpy (rname30, "r30");
-  fixed_regs[30] = call_used_regs[30] = 1;
+  call_used_regs[30] = 1;
+  fixed_regs[30] = 0;
+
+  arc_regno_reg_class[30] = WRITABLE_CORE_REGS;
+  SET_HARD_REG_BIT (reg_class_contents[WRITABLE_CORE_REGS], 30);
+  SET_HARD_REG_BIT (reg_class_contents[CHEAP_CORE_REGS], 30);
+  SET_HARD_REG_BIT (reg_class_contents[GENERAL_REGS], 30);
+  SET_HARD_REG_BIT (reg_class_contents[MPY_WRITABLE_CORE_REGS], 30);
}
 
   if (TARGET_MUL64_SET)
diff --git a/gcc/config/arc/arc.h b/gcc/config/arc/arc.h
index 0a4c745..fbc1195 100644
--- a/gcc/config/arc/arc.h
+++ b/gcc/config/arc/arc.h
@@ -641,7 +641,8 @@ extern enum reg_class arc_regno_reg_class[];
   ((REGNO) < 29 || ((REGNO) == ARG_POINTER_REGNUM) || ((REGNO) == 63)  \
|| ((unsigned) reg_renumber[REGNO] < 29)\
|| ((unsigned) (REGNO) == (unsigned) arc_tp_regno)  \
-   || (fixed_regs[REGNO] == 0 && IN_RANGE (REGNO, 32, 59)))
+   || (fixed_regs[REGNO] == 0 && IN_RANGE (REGNO, 32, 59)) \
+   || ((REGNO) == 30 && fixed_regs[REGNO] == 0))
 
 #define REGNO_OK_FOR_INDEX_P(REGNO) REGNO_OK_FOR_BASE_P(REGNO)
 
-- 
1.9.1



[PATCH 0/7] [ARC] Patterns update and fixes

2017-05-19 Thread Claudiu Zissulescu
From: claziss 

Hi Andrew,

Please fing a set of 7 small patches which are upgrating/fixing wrong
patterns.  Please let me know if you need more info.

Cheers,
Claudiu

Claudiu Zissulescu (7):
  [ARC] Make mulsi for A700 pattern commutative.
  [ARC] Avoid use of hard registers before reg-alloc.
  [ARC] Allow r30 to be used by the reg-alloc.
  [ARC] Change predicate movv2hi to avoid scaled addresses.
  [ARC] Update (non)commutative_binary_comparison patterns.
  [ARC] Prevent moving stores to the frame before the stack adjustment.
  [ARC] Test against frame_pointer_needed in arc_can_eliminate.

 gcc/config/arc/arc.c  |  21 -
 gcc/config/arc/arc.h  |   3 +-
 gcc/config/arc/arc.md | 201 --
 gcc/config/arc/simdext.md |   2 +-
 4 files changed, 163 insertions(+), 64 deletions(-)

-- 
1.9.1



Re: [PING][PATCH][2/2] Early LTO debug -- main part

2017-05-19 Thread Richard Biener
Late response now that I'm finished refreshing the patches.

On Mon, Nov 28, 2016 at 6:20 PM, Jason Merrill  wrote:
> On Thu, Nov 24, 2016 at 8:50 AM, Richard Biener  wrote:
>>> > +  /* ???  We can't annotate types late, but for LTO we may not
>>> > +generate a location early either (gfortran.dg/save_5.f90).
>>> > +The proper way is to handle it like VLAs though it is told
>>> > +that DW_AT_string_length does not support this.  */
>>>
>>> I think go ahead and handle it like VLAs, this is an obvious generalization
>>> and should go into the spec soon enough.  This can happen later.
>>
>> Ok, note that VLAs are now handled by re-emitting types late to avoid
>> some guality regressions.  With inlining VLA types also get copied
>> so we'd need to re-design how we handle them a bit.
>> I'll see what the DWARF people come up with.
>
> Does the discussion in
> https://sourceware.org/bugzilla/show_bug.cgi?id=20426 cover the issue?

This covers the VLA issue, yes.  With the DW_OP_GNU_variable_value extension
we might be able to handle those better though gdb still lacks support.

For the Fortran case quoted above it might be possible to use
DW_OP_GNU_variable_value
as well but I'll leave that for followup improvements (handling it
"like VLAs" without
this extension isn't possible Jakub told me).

I've removed the reference to VLAs in the comment, added a -flto -g variant of
save_5.f90 to the testsuite and refer to that.

>
>>> > + /* ???  This all (and above) should probably be simply
>>> > +a ! early_dwarf check somehow.  */
>>> > +  && ((DECL_ARTIFICIAL (decl) || in_lto_p)
>>> >|| (get_AT_file (old_die, DW_AT_decl_file) == file_index
>>> >&& (get_AT_unsigned (old_die, DW_AT_decl_line)
>>> >== (unsigned) s.line
>>>
>>> Why doesn't the existing source position check handle the LTO case? Also the
>>> extra parens aren't necessary.
>>
>> Because in LTRANS we do not see those attributes anymore but they are
>> present in the early created DIEs.
>
> Ah, OK.  But the comment seems wrong, since we go through here in
> early dwarf for local class methods.

Changed the comment to

/* ???  In LTO we do not see any of the location attributes.  */

>>> > +init_sections_and_labels (bool early_lto_debug)
>>>
>>> You're changing this function to do the same thing in four slightly 
>>> different
>>> ways rather than two.  I'd rather control each piece as appropriate; we 
>>> ought
>>> to make SECTION_DEBUG or SECTION_DEBUG|SECTION_EXCLUDE a local variable, and
>>> select between *_SECTION and the DWO variant at each statement rather than 
>>> in
>>> different blocks.
>>
>> Note that the section names change between LTO, LTO_DWO, DWO and
>> regular section names.  It's basically modeled after what we have now
>> which switches between regular and DWO section names.  We might
>> be able to refactor this with a new array
>>
>> enum section_kind { NORMAL, DWO, LTO, LTO_DWO };
>> char **section_names[section_kind][] = { { DEBUG_INFO_SECTION, ... },
>> { DEBUG_DWO_INFO_SECTION, ... },
>> { DEBUG_LTO_INFO_SECTION, ... },
>> { DEBUG_LTO_DWO_INFO_SECTION, .. } };
>>
>> would you prefer that?
>
> That sounds better, thanks.

I tried a few variants but they all end up even more awkward ...

Given the ugliness is isolated in init_sections_and_labels I think
keeping it the
way it is is best.

Updated patches posted separately (I posted the diff to the previous
state already).

Thanks,
Richard.

>
> Jason


Re: [PATCH 2/3] Simplify wrapped binops

2017-05-19 Thread Richard Biener
On Fri, May 19, 2017 at 12:13 PM, Bin.Cheng  wrote:
> On Fri, May 19, 2017 at 11:09 AM, Robin Dapp  wrote:
>>> I can guess what is happening here.  It's a 40 bits unsigned long long
>>> field, (s.b-8) will be like:
>>> _1 = s.b
>>> _2 = _1 + 0xf8
>>> Also get_range_info returns value range [0, 0xFF] for _1.
>>> You'd need to check if _1(with range [0, 0xFF]) + 0xf8
>>> overflows against precision of the bit-field which is 40 bits
>>> precision.  The failure might because overflowness is checked against
>>> unsigned long long's precision which is 64 bits.
>>
 Also, is there a possibility to know if there was an "ok" overflow or
 not from get_range_info ()'s output? Would I have to compare the result
 with the involved variable's range?
>>> I think you have to check it manually against max/min value of that
>>> type precision.
>>
>> Currently, extract_... () does that all that for me, is it really too
>> expensive to call? I guess, using get_range_info first and calling
>> extract when get_range_info returns a VR_RANGE is not really a favorable
>> thing to do either? :)
> Not only the cost, we should avoid introducing more interfaces while
> old ones can do the work.  Anyway, it's Richard's call here.

Using get_range_info and wi:: is prefered, I didn't look into the issue you
are running into but wi:: do have proper bit-precision tracking.  Maybe
the overflow checks are not implemented correctly there though.

Richard.

> Thanks,
> bin
>>
>> Regards
>>  Robin
>>


Re: [PATCH 2/3] Simplify wrapped binops

2017-05-19 Thread Bin.Cheng
On Fri, May 19, 2017 at 11:09 AM, Robin Dapp  wrote:
>> I can guess what is happening here.  It's a 40 bits unsigned long long
>> field, (s.b-8) will be like:
>> _1 = s.b
>> _2 = _1 + 0xf8
>> Also get_range_info returns value range [0, 0xFF] for _1.
>> You'd need to check if _1(with range [0, 0xFF]) + 0xf8
>> overflows against precision of the bit-field which is 40 bits
>> precision.  The failure might because overflowness is checked against
>> unsigned long long's precision which is 64 bits.
>
>>> Also, is there a possibility to know if there was an "ok" overflow or
>>> not from get_range_info ()'s output? Would I have to compare the result
>>> with the involved variable's range?
>> I think you have to check it manually against max/min value of that
>> type precision.
>
> Currently, extract_... () does that all that for me, is it really too
> expensive to call? I guess, using get_range_info first and calling
> extract when get_range_info returns a VR_RANGE is not really a favorable
> thing to do either? :)
Not only the cost, we should avoid introducing more interfaces while
old ones can do the work.  Anyway, it's Richard's call here.

Thanks,
bin
>
> Regards
>  Robin
>


Re: [PATCH 2/3] Simplify wrapped binops

2017-05-19 Thread Robin Dapp
> I can guess what is happening here.  It's a 40 bits unsigned long long
> field, (s.b-8) will be like:
> _1 = s.b
> _2 = _1 + 0xf8
> Also get_range_info returns value range [0, 0xFF] for _1.
> You'd need to check if _1(with range [0, 0xFF]) + 0xf8
> overflows against precision of the bit-field which is 40 bits
> precision.  The failure might because overflowness is checked against
> unsigned long long's precision which is 64 bits.

>> Also, is there a possibility to know if there was an "ok" overflow or
>> not from get_range_info ()'s output? Would I have to compare the result
>> with the involved variable's range?
> I think you have to check it manually against max/min value of that
> type precision.

Currently, extract_... () does that all that for me, is it really too
expensive to call? I guess, using get_range_info first and calling
extract when get_range_info returns a VR_RANGE is not really a favorable
thing to do either? :)

Regards
 Robin



Re: RFA: PATCH to check for overflow in make_tree_vec_stat

2017-05-19 Thread Richard Biener
On Fri, May 19, 2017 at 4:32 AM, Jason Merrill  wrote:
> A patch I've been putting together ran into strange memory corruption
> issues which turned out to be because the calculation in
> make_tree_vec_stat was overflowing and allocating a small TREE_VEC
> instead of a large one.  This assert should work as a simple sanity
> check.

Hmm, looks like 'length' should be size_t?  Then nothing can overflow anymore
(on hosts with size_t 64bit and int 32bit)

> Tested x86_64-pc-linux-gnu, OK for trunk?

Thanks,
Richard.


  1   2   >