Re: [PATCH] Fix host_size_t_cst_p predicate

2016-10-30 Thread Richard Sandiford
Richard Biener  writes:
> On Thu, Oct 27, 2016 at 5:06 PM, Martin Liška  wrote:
>> On 10/27/2016 03:35 PM, Richard Biener wrote:
>>> On Thu, Oct 27, 2016 at 9:41 AM, Martin Liška  wrote:
 Running simple test-case w/o the proper header file causes ICE:
 strncmp ("a", "b", -1);

 0xe74462 tree_to_uhwi(tree_node const*)
 ../../gcc/tree.c:7324
 0x90a23f host_size_t_cst_p
 ../../gcc/fold-const-call.c:63
 0x90a23f fold_const_call(combined_fn, tree_node*, tree_node*,
 tree_node*, tree_node*)
 ../../gcc/fold-const-call.c:1512
 0x787b01 fold_builtin_3
 ../../gcc/builtins.c:8385
 0x787b01 fold_builtin_n(unsigned int, tree_node*, tree_node**, int, bool)
 ../../gcc/builtins.c:8465
 0x9052b1 fold(tree_node*)
 ../../gcc/fold-const.c:11919
 0x6de2bb c_fully_fold_internal
 ../../gcc/c/c-fold.c:185
 0x6e1f6b c_fully_fold(tree_node*, bool, bool*)
 ../../gcc/c/c-fold.c:90
 0x67cbbf c_process_expr_stmt(unsigned int, tree_node*)
 ../../gcc/c/c-typeck.c:10369
 0x67cfbd c_finish_expr_stmt(unsigned int, tree_node*)
 ../../gcc/c/c-typeck.c:10414
 0x6cb578 c_parser_statement_after_labels
 ../../gcc/c/c-parser.c:5430
 0x6cd333 c_parser_compound_statement_nostart
 ../../gcc/c/c-parser.c:4944
 0x6cdbde c_parser_compound_statement
 ../../gcc/c/c-parser.c:4777
 0x6c93ac c_parser_declaration_or_fndef
 ../../gcc/c/c-parser.c:2176
 0x6d51ab c_parser_external_declaration
 ../../gcc/c/c-parser.c:1574
 0x6d5c09 c_parser_translation_unit
 ../../gcc/c/c-parser.c:1454
 0x6d5c09 c_parse_file()
 ../../gcc/c/c-parser.c:18173
 0x72ffd2 c_common_parse_file()
 ../../gcc/c-family/c-opts.c:1087

 Following patch improves the host_size_t_cst_p predicate.

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

 Ready to be installed?
>>>
>>> I believe the wi::min_precision (t, UNSIGNED) <= sizeof (size_t) *
>>> CHAR_BIT test is now redundant.
>>>
>>> OTOH it was probably desired to allow -1 here?  A little looking back
>>> in time should tell.
>>
>> Ok, it started with r229922, where it was changed from:
>>
>>   if (tree_fits_uhwi_p (len) && p1 && p2)
>> {
>>   const int i = strncmp (p1, p2, tree_to_uhwi (len));
>> ...
>>
>> to current version:
>>
>> case CFN_BUILT_IN_STRNCMP:
>>   {
>> bool const_size_p = host_size_t_cst_p (arg2, &s2);
>>
>> Thus I'm suggesting to change to back to it.
>>
>> Ready to be installed?
>
> Let's ask Richard.

The idea with the:

  wi::min_precision (t, UNSIGNED) <= sizeof (size_t) * CHAR_BIT

test was to stop us attempting 64-bit size_t operations on ILP32 hosts.
I think we still want that.

Thanks,
Richard


Re: relax rule for flexible array members in 6.x (78039 - fails to compile glibc tests)

2016-10-30 Thread Martin Sebor

Thanks Jeff.  I'll take care of the nits before I commit the patch
and update the Web page this week.

Jason, assuming you agree that the checking should be relaxed for
6.0, can you please let me know if it's good to commit?

Martin

On 10/24/2016 09:13 AM, Jeff Law wrote:

On 10/21/2016 05:47 PM, Martin Sebor wrote:

Bug 78039 complains that the fix for c++/71912 recently backported
to the GCC 6 branch causes GCC 6 to reject Glibc tests that expect
to be able to define structs with multiple flexible array members,
despite it violating the C standard(*).

The rejected code is unsafe and was intended to be rejected in 6.1
to begin with (i.e., it was a bug I had missed that the code wasn't
rejected in 6.1), and an alternate solution exists, so the backport
seemed appropriate to me.

However, it was pointed out to me that apparently there is a policy
or convention of not backporting to release branches bug fixes that
cause GCC to reject code that was previously accepted, even if the
code is invalid.

To comply with this policy the attached patch adjusts the backported
code to accept the invalid flexible array member with just a pedantic
warning (same as in C mode).  The patch also adds the tests that were
part of the fix for bug 71912 but that were accidentally left out of
the original backport.

Martin

[*] Bug 77650 discusses the background on this.

PS I checked the GCC Development Plan but couldn't find a mention
of this policy.  Since this seems like an important guarantee for
users to know about and for contributors to maintain I suggest to
update the document to reflect it.  If there is are no objections
I'll propose a separate change to mention it.

  https://gcc.gnu.org/develop.html

gcc-78039.diff


PR c++/78039 - fails to compile glibc tests

gcc/cp/ChangeLog:
2016-10-21  Martin Sebor  

PR c++/78039
* class.c (diagnose_flexarrays): Avoid rejecting an invalid flexible
array member with a hard error when it is followed by anbother member

s/anbother/another/


in a different struct, and instead issue just a pedantic warning.

gcc/testsuite/ChangeLog:
2016-10-21  Martin Sebor  

PR c++/78039
* g++.dg/ext/flexary18.C: New test.
* g++.dg/ext/flexary19.C: New test.

Index: gcc/cp/class.c
===
--- gcc/cp/class.c(revision 241433)
+++ gcc/cp/class.c(working copy)
@@ -6960,7 +6960,20 @@ diagnose_flexarrays (tree t, const flexmems_t *fme
   location_t loc = DECL_SOURCE_LOCATION (fmem->array);
   diagd = true;

-  error_at (loc, msg, fmem->array, t);
+  /* For compatibility with GCC 6.2 and 6.1 reject with an error
+ a flexible array member of a plain struct that's followed
+ by another member only if they are both members of the same
+ struct.  Otherwise, issue just a pedantic warning.  See bug
+ 71375 for details.  */

71375?  That bug looks totally unrelated.  Did you mean 71912?



Jason should have final call on the C++ bits.  But figured I'd point out
the nits.

As far as updating the web page to mention the caveat about this aspect
of the backporting policy, please do.

Jeff




Re: [PATCH] enhance buffer overflow warnings (and c/53562)

2016-10-30 Thread Martin Sebor

Attached is an updated patch that adds checks for excessive sizes
and bounds (those in excess of SIZE_MAX / 2), and also enables
the same checking for strcat and strncat).  This version also
fixes an issue with the interpretation of anti-ranges in the
first patch.  The improvements exposed two bugs in the regression
tests.

I'm wondering if it would make sense to either tighten up a bit
the checks for excessive sizes and bounds or add a customization
option to make it possible to specify a lower threshold.  The
patch currently warns on sizes and bounds that exceed
SIZE_MAX / 2.  It's very unlikely that any string or memory
operation will involve anywhere near that much data, and more
likely that such large numbers indicate bugs.  I would expect
even half that to be generous in ILP32, and even less in LP64.
Reducing the threshold for the warning could help find even
more bugs and the risk of false positives is IMO negligible.
Providing an option to specify the threshold would be in line
with other such options, including the -Walloca checker.  Does
anyone have any concerns with going down this path or suggestions?

Martin

On 10/27/2016 08:19 PM, Martin Sebor wrote:

The attached patch enhances the compile-time detection of buffer
overflow in functions like __builtin___memcpy_chk to consider
non-constant lengths known to be in a certain range and warn
when the lower bound of the range doesn't fit in the destination
object.

The patch does the same thing for the non-checking functions like
__builtin_memcpy and issues buffer overflow warnings for those.
For string functions like __builtin_strcpy, the patch also makes
use of ranges of lengths of non-constant strings.

To make reasoning about the warnings easier (and to help with
debugging the problems), the patch also extends the warnings to
print the ranges of lengths and sizes of the operands.  The text
and content of the warning messages is based on those issued by
the -Wformat-length warning pass.

Finally, as requested in bug 53562, the patch adds a new warning
option, -Wstringop-overflow, to control these warnings (the option
is on by default).  I chose a different name for the option than
suggested in the bug to avoid giving the impression that it
actually inserts the checking calls (all it does is warn on
buffer overflows detectable at compile-time).

I was originally going to submit a more modest version of this
patch as part of a bigger project I'm working on (bug 77608) but
then decided to submit this one first because it's independent of
the other.

Possible enhancements include letting the option accept a level
argument and at level 2 using the upper bound of the size or
string length ranges similarly to the -Wformat-length option.
With that, the following could be diagnosed as a potential
buffer overflow:

  char d[5];
  strcpy (d, x ? "123" : "123456");

Thanks
Martin


PR c/53562 - Add -Werror= support for -D_FORTIFY_SOURCE / __builtin___memcpy_chk

gcc/c-family/ChangeLog:
2016-10-30  Martin Sebor  

	PR c/53562
	* c.opt (-Wstringop-overflow): New option.

gcc/ChangeLog:
2016-10-30  Martin Sebor  

	PR c/53562
	* builtins.c (expand_builtin_strcat, expand_builtin_strncat): New
	functions.
	(get_size_range, check_sizes, check_strncat_sizes): Same.
	(expand_builtin_memcpy): Call check sizes.
	(expand_builtin_mempcpy): Same.
	(expand_builtin_strcpy): Same.
	(expand_builtin_strncpy): Same.
	(expand_builtin_memset): Same,
	(expand_builtin_bzero): Same.
	(expand_builtin_memory_chk): Same.
	(maybe_emit_sprintf_chk_warning): Same.
	(expand_builtin): Handle strcat and strncat.
	* doc/invoke.texi (Warning Options): Document -Wstringop-overflow.

gcc/testsuite/ChangeLog:
2016-10-30  Martin Sebor  

	PR c/53562
	* c-c++-common/Wsizeof-pointer-memaccess2.c: Adjust expected diagnostic.
	* g++.dg/ext/builtin-object-size3.C (bar): Same.
	* g++.dg/ext/strncpy-chk1.C: Same.
	* g++.dg/torture/Wsizeof-pointer-memaccess1.C: Same.
	* gcc.c-torture/compile/pr55569.c: Disable -Wstringop-overflow.
	* gcc.dg/Wobjsize-1.c: Adjust expected diagnostic.
	* gcc.dg/attr-alloc_size.c: Same.
	* gcc.dg/builtin-stringop-chk-1.c: Adjust expected diagnostic.
	* gcc.dg/builtin-stringop-chk-2.c: Same.
	* gcc.dg/builtin-stringop-chk-4.c: New test.
	* gcc.dg/builtin-strncat-chk-1.c: Adjust expected diagnostic..
	* gcc.dg/memcpy-2.c: Same.
	* gcc.dg/pr40340-1.c: Same.
	* gcc.dg/pr40340-2.c (main): Same.
	* gcc.dg/pr40340-5.c (main): Same.
	* gcc.dg/torture/Wsizeof-pointer-memaccess1.c: Same.
	* gcc.dg/torture/pr71132.c: Disable -Wstringop-overflow.

diff --git a/gcc/builtins.c b/gcc/builtins.c
index facecd3..f505ec2 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -67,7 +67,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "internal-fn.h"
 #include "case-cfn-macros.h"
 #include "gimple-fold.h"
-
+#include "intl.h"
 
 struct target_builtins default_target_builtins;
 #if SWITCHABLE_TARGET
@@ -125,9 +125,11 @@ static rtx expand_builtin_mempcpy (tree, rtx, machine_mode);

Re: [patch, libgfortran] Bug 78123 - Short reads with T edit descriptor not padding correctly

2016-10-30 Thread Thomas Koenig

Hi Jerry,


See patch below which is very simple. We were handling the case where we
tabbed left of current position in the record by clearing the seen_eor
flag. We were not handling the case where we tab toward the right and so
are still at eor.

New test case attached. Regression tested on x86-64-linux.

OK to commit?

This is a regression relative to g77. Its simple enough I think it
should go to 5 and 6 as well.


I think so too.  OK for all affected branches.

Thanks for the patch!

Thomas



Re: [patch, libgfortran] Bug 78123 - Short reads with T edit descriptor not padding correctly

2016-10-30 Thread Steve Kargl
On Sun, Oct 30, 2016 at 01:21:41PM -0700, Jerry DeLisle wrote:
> See patch below which is very simple. We were handling the case
> where we tabbed left of current position in the record by clearing
> the seen_eor flag. We were not handling the case where we tab
> toward the right and so are still at eor.
> 
> New test case attached. Regression tested on x86-64-linux.
> 
> OK to commit?
> 

OK for all branches.

-- 
Steve


[patch, libgfortran] Bug 78123 - Short reads with T edit descriptor not padding correctly

2016-10-30 Thread Jerry DeLisle
See patch below which is very simple. We were handling the case where we tabbed 
left of current position in the record by clearing the seen_eor flag. We were 
not handling the case where we tab toward the right and so are still at eor.


New test case attached. Regression tested on x86-64-linux.

OK to commit?

This is a regression relative to g77. Its simple enough I think it should go to 
5 and 6 as well.


Regards,

Jerry

2016-10-30  Jerry DeLisle  

PR fortran/79123
* io/transfer.c (formatted_transfer_scalar_read): Clear seen_eor
only if we have tabbed to left of current position.


diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c
index b8eb5ed..5830362 100644
--- a/libgfortran/io/transfer.c
+++ b/libgfortran/io/transfer.c
@@ -1579,7 +1579,8 @@ formatted_transfer_scalar_read (st_parameter_dt *dtp, bt 
type, void *p, int kind

   dtp->u.p.current_unit->bytes_left -= dtp->u.p.sf_seen_eor;
   dtp->u.p.skips -= dtp->u.p.sf_seen_eor;
  bytes_used = pos;
- dtp->u.p.sf_seen_eor = 0;
+ if (dtp->u.p.pending_spaces == 0)
+   dtp->u.p.sf_seen_eor = 0;
}
  if (dtp->u.p.skips < 0)
{
! { dg-options "-ffixed-line-length-none -std=gnu" }
! { dg-do run }
! PR78123 Short reads with T edit descriptor not padding correctly
  PROGRAM tformat
C
  INTEGER  MXFLTL
  PARAMETER (MXFLTL = 9)
  INTEGER   IFLGHT, NFLCYC, IFLTSQ(MXFLTL), IDXBLK, LMAX, LMIN, I
C
  OPEN(29, status='scratch')
  WRITE(29, '(a)') "   1   1   1  T  72  122 4"
  WRITE(29, '(a)') ""
  WRITE(29, '(a)') "  451   402012011201120112011200120112011201120112011201120111971201120112011201120112011201"
  WRITE(29, '(a)') "  451   4020 866 866 866 866 866 866 866 866 865 866 865 866 866 866 866 866 866 866 865 866"
  REWIND(29)
C The error occurs in the following loop:
 10   CONTINUE
 READ(29,1010   )  IDXBLK, LMAX, LMIN
1010 FORMAT(8X,I4,T51,2I5) ! wrong if this format is used
c write(6,fmt='("IDXBLK,LMAX,LMIN=",3I5)')IDXBLK,LMAX,LMIN
 IF (IDXBLK .EQ. 0)  GO TO 20
  GO TO 10
C
 20   CONTINUE
  READ(29,1040,END=100)  IFLGHT, NFLCYC,
 &  (IFLTSQ(I), I=1,NFLCYC)
1040  FORMAT(I5,I5,2X,(T13,20I4))
c  write(6,fmt='(2i6)') IFLGHT,NFLCYC
c  write(6,fmt='(20I4)') (IFLTSQ(I), I=1,NFLCYC)
c  write(6,*) "Program is correct"
  close(29)
  if (IFLGHT.ne.451) call abort
  if (NFLCYC.ne.40) call abort
  stop
C
 100  CONTINUE
C  write(6,*) "End of file encountered (wrong)"
  close (29)
  call abort
  STOP
  END


Re: [PATCH] Add -Wshadow-local and -Wshadow-compatible-local.

2016-10-30 Thread Mark Wielaard
On Tue, Oct 25, 2016 at 01:57:09AM +0200, Mark Wielaard wrote:
> I think the only thing "blocking" the patch from going in is that
> nobody made a decission on how the actual warning option should be
> named. I think the suggestion for -Wshadow=[global|local|compatible-local]
> is the right one. With -Wshadow being an alias for -Wshadow=global.
> But since there are already gcc versions out there that accept
> -Wshadow-local and -Wshadow-compatible-local (and you can find some
> configure scripts that already check for those options) it would be
> good to have those as (hidden) aliases.
> 
> If people, some maintainer, agrees with that then we can do the .opt
> file hacking to make it so.

Nobody objected, nor did anybody say this is a great idea. But I think
it is. So I just implemented the options this way.

I made one small diagnostic change to fix a regression pointed out by
gcc/testsuite/gcc.dg/pr48062.c. It should still be possible to ignore
all shadow warnings with #pragma GCC diagnostic ignored "-Wshadow" when
-Wshadow was given, but not the new -Wshadow=(local|compatible-local).
So we now set warning_code = OPT_Wshadow when -Wshadow was given.

The documentation and code comments were updated to refer to the
new -Wshadow=... variants.

OK to commit the attached patch?

Thanks,

Mark
>From 390697e924926d7f8e451d39114de4903db07325 Mon Sep 17 00:00:00 2001
From: Mark Wielaard 
Date: Sun, 11 Sep 2016 14:20:33 +0200
Subject: [PATCH] Add -Wshadow=global -Wshadow=local and
 -Wshadow=compatible-local.

This patch from Le-Chun Wu adds two new shadow warning flags for
C and C++:

  -Wshadow=local which warns if a local variable shadows another local
  variable or parameter,

  -Wshadow=compatible-local which warns if a local variable shadows
  another local variable or parameter whose type is compatible with
  that of the shadowing variable.

It is already on the google/main branch (Google ref 39127) and was
previously submitted by Diego Novillo and reviewed on
http://codereview.appspot.com/4452058

I addressed the review comments and made the following changes:
- Add -Wshadow=global (the default alias for -Wshadow).
- Make the documented options -Wshadow=global, -Wshadow=local
  and -Wshadow=compatible-local (with hidden undocumented aliases
  -Wshadow-local and -Wshadow-compatible-local for compatibility).
- The -Wshadow=global, -Wshadow=local and -Wshadow=compatible-local
  relationships are expressed in common.opt instead of in opts.c
  and documented in invoke.texi.
- The "previous declaration" warnings were turned into notes and use
  the (now) existing infrastructure instead of duplicating the warnings.
  The testcases have been adjusted to expect the notes.
- The conditional change in name-lookup.c for non-locals (where we
  don't want to change the warnings, but just check the global ones)
  has been dropped.
- Use warning_at in c-decl.c (warn_if_shadowing).

gcc/ChangeLog:
2016-10-30  Le-Chun Wu  
Mark Wielaard  

   * doc/invoke.texi: Document Wshadow-local and Wshadow-compatible-local.
   * common.opt (Wshadow=global): New option. Default for -Wshadow.
   (Wshadow=local): New option.
   (Wshadow-local): Hidden alias for -Wshadow=local.
   (Wshadow=compatible-local): New option.
   (Wshadow-compatible-local): Hidden alias for
   -Wshadow=compatible-local.
   * doc/invoke.texi: Document Wshadow=global, Wshadow=local and
   Wshadow=compatible-local.

gcc/c/ChangeLog:
2016-10-30  Le-Chun Wu  
Mark Wielaard  

   * c-decl.c (warn_if_shadowing): Use the warning code corresponding
   to the given -Wshadow= variant. Use warning_at.

gcc/cp/ChangeLog:
2016-10-30  Le-Chun Wu  
Mark Wielaard  

   * name-lookup.c (pushdecl_maybe_friend): When emitting a
   shadowing warning, use the code corresponding to the
   given -Wshadow= variant.

gcc/testsuite/ChangeLog
2016-10-30  Le-Chun Wu  
Mark Wielaard  

   * gcc.dg/Wshadow-compatible-local-1.c: New test.
   * gcc.dg/Wshadow-local-1.c: Likewise.
   * gcc.dg/Wshadow-local-2.c: Likewise.
   * g++.dg/warn/Wshadow-compatible-local-1.C: Likewise.
   * g++.dg/warn/Wshadow-local-1.C: Likewise.
   * g++.dg/warn/Wshadow-local-2.C: Likewise.
---
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 136f304..3e1b7a4 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -2735,7 +2735,9 @@ warn_if_shadowing (tree new_decl)
   struct c_binding *b;
 
   /* Shadow warnings wanted?  */
-  if (!warn_shadow
+  if (!(warn_shadow
+|| warn_shadow_local
+|| warn_shadow_compatible_local)
   /* No shadow warnings for internally generated vars.  */
   || DECL_IS_BUILTIN (new_decl)
   /* No shadow warnings for vars made for inlining.  */
@@ -2759,9 +2761,23 @@ warn_if_shadowing (tree new_decl)
break;
  }
else if (TREE_CODE (old_decl) == PARM_DECL)
- warned = warning (OPT_Wshadow,
- 

Re: [PATCH] DWARF5 .debug_info headers, .debug_types -> .debug_info DW_UT_type

2016-10-30 Thread Jan Kratochvil
On Fri, 21 Oct 2016 21:32:42 +0200, Jakub Jelinek wrote:
> This patch changes the .debug_info headers to follow the current
> specification (I still hope the useless padding1/padding2 fields will be
> removed), and also changes the -gsplit-dwarf stuff to move dwo_id into
> the header and use DW_UT_{skeleton,split_*}.

During GDB consumer patch testing I needed this fix on top of your patch.


Jan


diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 7c6a9e9..1c0ca35 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -2977,7 +2977,8 @@ skeleton_chain_node;
 
 /* Fixed size portion of the DWARF compilation unit header.  */
 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
-  (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
+  (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE \
+   + (dwarf_version < 5 ? 3 : 4 + 8 + DWARF_OFFSET_SIZE))
 
 /* Fixed size portion of the DWARF comdat type unit header.  */
 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \


[PATCH] bb-reorder: Improve compgotos pass (PR71785)

2016-10-30 Thread Segher Boessenkool
For code like the testcase in PR71785 GCC factors all the indirect branches
to a single dispatcher that then everything jumps to.  This is because
having many indirect branches with each many jump targets does not scale
in large parts of the compiler.  Very late in the pass pipeline (right
before peephole2) the indirect branches are then unfactored again, by
the duplicate_computed_gotos pass.

This pass works by replacing branches to such a common dispatcher by a
copy of the dispatcher.  For code like this testcase this does not work
so well: most cases do a single addition instruction right before the
dispatcher, but not all, and we end up with only two indirect jumps: the
one without the addition, and the one with the addition in its own basic
block, and now everything else jumps _there_.

This patch solves this problem by simply running the duplicate_computed_gotos
pass again, as long as it does any work.  The patch looks much bigger than
it is, because I factored out two routines to simplify the control flow.

Tested on powerpc64-linux {-m32,-m64}, and on the testcase, and on a version
of the testcase that has 2000 cases instead of 4.  Is this okay for trunk?


Segher


2016-10-30  Segher Boessenkool  

PR rtl-optimization/71785
* bb-reorder.c (duplicate_computed_gotos_find_candidates,
duplicate_computed_gotos_do_duplicate): New functions, factored out
from...
(pass_duplicate_computed_gotos::execute): Here.  Rerun the pass as
long as it makes changes.

---
 gcc/bb-reorder.c | 216 ++-
 1 file changed, 119 insertions(+), 97 deletions(-)

diff --git a/gcc/bb-reorder.c b/gcc/bb-reorder.c
index 85bc569..b69c3b2 100644
--- a/gcc/bb-reorder.c
+++ b/gcc/bb-reorder.c
@@ -2593,6 +2593,97 @@ make_pass_reorder_blocks (gcc::context *ctxt)
which can seriously pessimize code with many computed jumps in the source
code, such as interpreters.  See e.g. PR15242.  */
 
+/* Look for blocks that end in a computed jump in function FUN, and see if
+   such blocks are suitable for unfactoring.  If a block is a candidate for
+   unfactoring, mark it in the CANDIDATES.  A block bigger than MAX_SIZE is
+   not suitable.  */
+static void
+duplicate_computed_gotos_find_candidates (function *fun, bitmap candidates,
+ int max_size)
+{
+  basic_block bb;
+  FOR_EACH_BB_FN (bb, fun)
+{
+  /* Obviously the block has to end in a computed jump.  */
+  if (!computed_jump_p (BB_END (bb)))
+   continue;
+
+  /* Only consider blocks that can be duplicated.  */
+  if (CROSSING_JUMP_P (BB_END (bb))
+ || !can_duplicate_block_p (bb))
+   continue;
+
+  /* Make sure that the block is small enough.  */
+  int size = 0;
+  rtx_insn *insn;
+  FOR_BB_INSNS (bb, insn)
+   if (INSN_P (insn))
+ {
+   size += get_attr_min_length (insn);
+   if (size > max_size)
+  break;
+ }
+  if (size > max_size)
+   continue;
+
+  /* Final check: there must not be any incoming abnormal edges.  */
+  int all_flags = 0;
+  edge e;
+  edge_iterator ei;
+  FOR_EACH_EDGE (e, ei, bb->preds)
+   all_flags |= e->flags;
+  if (all_flags & EDGE_COMPLEX)
+   continue;
+
+  bitmap_set_bit (candidates, bb->index);
+}
+}
+
+/* For every jump in FUN to a block in CANDIDATES try to unfactor that block
+   (i.e. duplicate it and jump to the copy instead).  Return whether any
+   change is made.  */
+static bool
+duplicate_computed_gotos_do_duplicate (function *fun, bitmap candidates)
+{
+  bool changed = false;
+
+  basic_block bb;
+  FOR_EACH_BB_FN (bb, fun)
+{
+  if (bb->flags & BB_VISITED)
+   continue;
+
+  bb->flags |= BB_VISITED;
+
+  /* BB must have one outgoing edge.  That edge must not lead to
+the exit block or the next block.
+The destination must have more than one predecessor.  */
+  if (!single_succ_p (bb)
+ || single_succ (bb) == EXIT_BLOCK_PTR_FOR_FN (fun)
+ || single_succ (bb) == bb->next_bb
+ || single_pred_p (single_succ (bb)))
+   continue;
+
+  /* The successor block has to be a duplication candidate.  */
+  if (!bitmap_bit_p (candidates, single_succ (bb)->index))
+   continue;
+
+  /* Don't duplicate a partition crossing edge, which requires difficult
+ fixup.  */
+  if (JUMP_P (BB_END (bb)) && CROSSING_JUMP_P (BB_END (bb)))
+   continue;
+
+  basic_block new_bb = duplicate_block (single_succ (bb),
+   single_succ_edge (bb), bb);
+  new_bb->aux = bb->aux;
+  bb->aux = new_bb;
+  new_bb->flags |= BB_VISITED;
+  changed = true;
+}
+
+  return changed;
+}
+
 namespace {
 
 const pass_data pass_data_duplicate_computed_gotos =
@@ -2634,125 +2725,56 @@ pass_duplicate_computed_gotos::gate (function *fun)
 unsigned int

[C++ PATCH] Add tests for a const member and a reference member for launder.

2016-10-30 Thread Ville Voutilainen
So, how about adding these? They should give us regression tests
that make sure launder does the right in in case some optimizations
attempt to reuse const/reference members.

Tested on Linux-x64.

2016-10-30  Ville Voutilainen  

Add tests for a const member and a reference member for launder.
* g++.dg/cpp1z/launder3.C: New.
* g++.dg/cpp1z/launder4.C: Likewise.
diff --git a/gcc/testsuite/g++.dg/cpp1z/launder3.C 
b/gcc/testsuite/g++.dg/cpp1z/launder3.C
new file mode 100644
index 000..2a2afc5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/launder3.C
@@ -0,0 +1,38 @@
+// { dg-do run { target c++11 } }
+// { dg-additional-options "-O2" }
+
+#include 
+
+void *
+operator new (decltype (sizeof (0)), void *p)
+{
+  return p;
+}
+
+namespace std
+{
+  template 
+  T *
+  launder (T *p)
+  {
+return __builtin_launder (p);
+  }
+}
+
+struct A
+{
+  const int x;
+};
+
+struct B
+{
+  A a;
+};
+
+int
+main ()
+{
+  B b{{42}};
+  new (&b.a) A{666};
+  assert(std::launder(&b.a)->x == 666);
+}
diff --git a/gcc/testsuite/g++.dg/cpp1z/launder4.C 
b/gcc/testsuite/g++.dg/cpp1z/launder4.C
new file mode 100644
index 000..3a65eb2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/launder4.C
@@ -0,0 +1,40 @@
+// { dg-do run { target c++11 } }
+// { dg-additional-options "-O2" }
+
+#include 
+
+void *
+operator new (decltype (sizeof (0)), void *p)
+{
+  return p;
+}
+
+namespace std
+{
+  template 
+  T *
+  launder (T *p)
+  {
+return __builtin_launder (p);
+  }
+}
+
+struct A
+{
+  int& x;
+};
+
+struct B
+{
+  A a;
+};
+
+int
+main ()
+{
+  int x = 42;
+  B b{{x}};
+  int y = 666;
+  new (&b.a) A{y};
+  assert(std::launder(&b.a)->x == 666);
+}


Re: [patch, fortran] Fix PR 67219, erroneous warning

2016-10-30 Thread Steve Kargl
On Sun, Oct 30, 2016 at 05:32:52PM +0100, Thomas Koenig wrote:
> 
> the regression in question was caused by issuing a conversion
> warning for a complex constant too early, when the statement would be
> rejected later.
> 
> The solution is to throw away the warning if we do not find that
> comma.
> 
> Regression-tested.  OK for trunk and 6-branch?
> 

OK.

-- 
Steve


Go patch committed: Fix slice/array evaluation order bug

2016-10-30 Thread Ian Lance Taylor
This patch to the Go frontend by Than McIntosh fixes an
order-of-evaluation bug in slice/array composite literals.  There was
a phase ordering issue in the handling of "keyed" array literal
expressions: the lowering phase was canonicalizing the indices/vals
before the phase that fixed evaluation order, meaning that the
evaluation order was incorrect. The fix is to capture the original
ordering and use that ordering when doing traversals (there is already
something similar being done for struct literal expressions).

This fixes https://golang.org/issue/17640.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
Index: gcc/go/gofrontend/MERGE
===
--- gcc/go/gofrontend/MERGE (revision 241687)
+++ gcc/go/gofrontend/MERGE (working copy)
@@ -1,4 +1,4 @@
-4ca21c94f00c620bfde2f924e214c78fe2e1ff69
+c353ffbe18d1538cac7f2a3fcefb846dbf1a6591
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: gcc/go/gofrontend/expressions.cc
===
--- gcc/go/gofrontend/expressions.cc(revision 241667)
+++ gcc/go/gofrontend/expressions.cc(working copy)
@@ -12202,12 +12202,10 @@ Expression::make_allocation(Type* type,
   return new Allocation_expression(type, location);
 }
 
-// Class Struct_construction_expression.
-
-// Traversal.
+// Class Ordered_value_list.
 
 int
-Struct_construction_expression::do_traverse(Traverse* traverse)
+Ordered_value_list::traverse_vals(Traverse* traverse)
 {
   if (this->vals_ != NULL)
 {
@@ -12218,8 +12216,8 @@ Struct_construction_expression::do_trave
}
   else
{
- for (std::vector::const_iterator p =
-this->traverse_order_->begin();
+ for (std::vector::const_iterator p =
+  this->traverse_order_->begin();
   p != this->traverse_order_->end();
   ++p)
{
@@ -12229,6 +12227,18 @@ Struct_construction_expression::do_trave
}
}
 }
+  return TRAVERSE_CONTINUE;
+}
+
+// Class Struct_construction_expression.
+
+// Traversal.
+
+int
+Struct_construction_expression::do_traverse(Traverse* traverse)
+{
+  if (this->traverse_vals(traverse) == TRAVERSE_EXIT)
+return TRAVERSE_EXIT;
   if (Type::traverse(this->type_, traverse) == TRAVERSE_EXIT)
 return TRAVERSE_EXIT;
   return TRAVERSE_CONTINUE;
@@ -12239,10 +12249,10 @@ Struct_construction_expression::do_trave
 bool
 Struct_construction_expression::is_constant_struct() const
 {
-  if (this->vals_ == NULL)
+  if (this->vals() == NULL)
 return true;
-  for (Expression_list::const_iterator pv = this->vals_->begin();
-   pv != this->vals_->end();
+  for (Expression_list::const_iterator pv = this->vals()->begin();
+   pv != this->vals()->end();
++pv)
 {
   if (*pv != NULL
@@ -12270,10 +12280,10 @@ Struct_construction_expression::is_const
 bool
 Struct_construction_expression::do_is_immutable() const
 {
-  if (this->vals_ == NULL)
+  if (this->vals() == NULL)
 return true;
-  for (Expression_list::const_iterator pv = this->vals_->begin();
-   pv != this->vals_->end();
+  for (Expression_list::const_iterator pv = this->vals()->begin();
+   pv != this->vals()->end();
++pv)
 {
   if (*pv != NULL && !(*pv)->is_immutable())
@@ -12287,15 +12297,15 @@ Struct_construction_expression::do_is_im
 void
 Struct_construction_expression::do_determine_type(const Type_context*)
 {
-  if (this->vals_ == NULL)
+  if (this->vals() == NULL)
 return;
   const Struct_field_list* fields = this->type_->struct_type()->fields();
-  Expression_list::const_iterator pv = this->vals_->begin();
+  Expression_list::const_iterator pv = this->vals()->begin();
   for (Struct_field_list::const_iterator pf = fields->begin();
pf != fields->end();
++pf, ++pv)
 {
-  if (pv == this->vals_->end())
+  if (pv == this->vals()->end())
return;
   if (*pv != NULL)
{
@@ -12305,7 +12315,7 @@ Struct_construction_expression::do_deter
 }
   // Extra values are an error we will report elsewhere; we still want
   // to determine the type to avoid knockon errors.
-  for (; pv != this->vals_->end(); ++pv)
+  for (; pv != this->vals()->end(); ++pv)
 (*pv)->determine_type_no_context();
 }
 
@@ -12314,24 +12324,24 @@ Struct_construction_expression::do_deter
 void
 Struct_construction_expression::do_check_types(Gogo*)
 {
-  if (this->vals_ == NULL)
+  if (this->vals() == NULL)
 return;
 
   Struct_type* st = this->type_->struct_type();
-  if (this->vals_->size() > st->field_count())
+  if (this->vals()->size() > st->field_count())
 {
   this->report_error(_("too many expressions for struct"));
   return;
 }
 
   const Struct_field_list* fields = st->fields();
-  Expression_list::const_iterator pv = this->vals_->begin();
+ 

libgo patch committed: Use GNU make to eliminate duplication in Makefile.am

2016-10-30 Thread Ian Lance Taylor
This patch to libgo uses GNU make features to eliminate a lot of
duplication in libgo/Makefile.am.  Bootstrapped and ran Go testsuite
on x86_64-pc-linux-gnu.  Committed to mainline.

The attached patch, generated by `svn diff`, doesn't seem to correctly
reflect the fact that libgo/runtime/runtime.c was renamed to
libgo/runtime/runtime_c.c using `svn mv`.

Ian
Index: gcc/go/gofrontend/MERGE
===
--- gcc/go/gofrontend/MERGE (revision 241667)
+++ gcc/go/gofrontend/MERGE (working copy)
@@ -1,4 +1,4 @@
-fe38baff61b9b9426a4f60ff078cf3c8722bf94d
+4ca21c94f00c620bfde2f924e214c78fe2e1ff69
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/Makefile.am
===
--- libgo/Makefile.am   (revision 241667)
+++ libgo/Makefile.am   (working copy)
@@ -105,7 +105,7 @@ toolexeclib_LTLIBRARIES = libgo-llgo.la
 toolexeclib_LIBRARIES = libgobegin-llgo.a
 else
 toolexeclib_LTLIBRARIES = libgo.la
-toolexeclib_LIBRARIES = libgobegin.a libgolibbegin.a libnetgo.a
+toolexeclib_LIBRARIES = libgobegin.a libgolibbegin.a
 endif
 
 toolexeclibgo_DATA = \
@@ -479,7 +479,7 @@ runtime_files = \
runtime/parfor.c \
runtime/print.c \
runtime/proc.c \
-   runtime/runtime.c \
+   runtime/runtime_c.c \
runtime/signal_unix.c \
runtime/thread.c \
$(runtime_thread_files) \
@@ -572,6 +572,16 @@ s-runtime_sysinfo: $(srcdir)/mkrsysinfo.
$(SHELL) $(srcdir)/mvifdiff.sh tmp-runtime_sysinfo.go runtime_sysinfo.go
$(STAMP) $@
 
+runtime.inc: s-runtime-inc; @true
+s-runtime-inc: runtime.lo Makefile
+   rm -f runtime.inc.tmp2
+   grep -v "#define _" runtime.inc.tmp | grep -v "#define c0 " | grep -v 
"#define c1 " > runtime.inc.tmp2
+   for pattern in '_G[a-z]' '_P[a-z]' _Max _Lock _Sig _Trace _MHeap _Num; 
do \
+ grep "#define $$pattern" runtime.inc.tmp >> runtime.inc.tmp2; \
+   done
+   $(SHELL) $(srcdir)/mvifdiff.sh runtime.inc.tmp2 runtime.inc
+   $(STAMP) $@
+
 noinst_DATA = zstdpkglist.go
 
 # Generate the list of go std packages that were included in libgo
@@ -581,7 +591,7 @@ s-zstdpkglist: Makefile
echo 'package main' > zstdpkglist.go.tmp
echo "" >> zstdpkglist.go.tmp
echo 'var stdpkg = map[string]bool{' >> zstdpkglist.go.tmp
-   echo $(libgo_go_objs) 'unsafe.lo' 'runtime/cgo.lo' | sed 's/\.lo /\": 
true,\n/g' | sed 's/\.lo/\": true,/' | sed 's/-go//' | grep -v _c | sed 
's/^/\t\"/' | sort | uniq >> zstdpkglist.go.tmp
+   echo $(libgo_go_objs) 'unsafe.lo' 'runtime/cgo.lo' | sed 's/\.lo /\": 
true,\n/g' | sed 's/\.lo/\": true,/' | grep -v _c | sed 's/^/\t\"/' | sort | 
uniq >> zstdpkglist.go.tmp
echo '}' >> zstdpkglist.go.tmp
$(SHELL) $(srcdir)/mvifdiff.sh zstdpkglist.go.tmp zstdpkglist.go
$(STAMP) $@
@@ -592,12 +602,6 @@ else
 syscall_epoll_file =
 endif
 
-extra_go_files_syscall = \
-   libcalls.go \
-   sysinfo.go \
-   syscall_arch.go \
-   $(syscall_epoll_file)
-
 libcalls.go: s-libcalls; @true
 s-libcalls: libcalls-list go/syscall/mksyscall.awk $(srcdir)/go/syscall/*.go
rm -f libcalls.go.tmp
@@ -678,175 +682,178 @@ else
 syscall_lib_clone_lo =
 endif
 
+PACKAGES = \
+   archive/tar \
+   archive/zip \
+   bufio \
+   bytes \
+   compress/bzip2 \
+   compress/flate \
+   compress/gzip \
+   compress/lzw \
+   compress/zlib \
+   container/heap \
+   container/list \
+   container/ring \
+   context \
+   crypto \
+   crypto/aes \
+   crypto/cipher \
+   crypto/des \
+   crypto/dsa \
+   crypto/ecdsa \
+   crypto/elliptic \
+   crypto/hmac \
+   crypto/md5 \
+   crypto/rand \
+   crypto/rc4 \
+   crypto/rsa \
+   crypto/sha1 \
+   crypto/sha256 \
+   crypto/sha512 \
+   crypto/subtle \
+   crypto/tls \
+   crypto/x509 \
+   crypto/x509/pkix \
+   database/sql \
+   database/sql/driver \
+   debug/dwarf \
+   debug/elf \
+   debug/gosym \
+   debug/macho \
+   debug/pe \
+   debug/plan9obj \
+   encoding \
+   encoding/ascii85 \
+   encoding/asn1 \
+   encoding/base32 \
+   encoding/base64 \
+   encoding/binary \
+   encoding/csv \
+   encoding/gob \
+   encoding/hex \
+   encoding/json \
+   encoding/pem \
+   encoding/xml \
+   errors \
+   exp/proxy \
+   exp/terminal \
+   expvar \
+   flag \
+   fmt \
+   go/ast \
+   go/build \
+   go/constant \
+   go/doc \
+   go/format \
+   go/importer \
+   go/internal/gccgoimporter \
+   go/internal/gcimporter \
+   go/parser \
+   go/printer \
+   go/scanner \
+   go/token \
+   go/types \
+   golang_org/x/net/http2/hpack \
+   golang

[patch, fortran] Fix PR 67219, erroneous warning

2016-10-30 Thread Thomas Koenig

Hello world,

the regression in question was caused by issuing a conversion
warning for a complex constant too early, when the statement would be
rejected later.

The solution is to throw away the warning if we do not find that
comma.

Regression-tested.  OK for trunk and 6-branch?

Regards

Thomas

2016-10-30  Thomas Koenig  

PR fortran/67219
* arith.c (gfc_int2real):  Change gfc_warning_now
to gfc_warning.
* primary.c (match_complex_constant):  If there
is no comma, throw away any warning which might have
been issued by gfc_int2real.

2016-10-30  Thomas Koenig  

PR fortran/67219
* gfortran.dg/pr67219.f90:  New test.
Index: arith.c
===
--- arith.c	(Revision 241590)
+++ arith.c	(Arbeitskopie)
@@ -2072,11 +2072,11 @@ gfc_int2real (gfc_expr *src, int kind)
 
   if (warn_conversion
   && wprecision_int_real (src->value.integer, result->value.real))
-gfc_warning_now (OPT_Wconversion, "Change of value in conversion "
-		 "from %qs to %qs at %L",
-		 gfc_typename (&src->ts),
-		 gfc_typename (&result->ts),
-		 &src->where);
+gfc_warning (OPT_Wconversion, "Change of value in conversion "
+		 "from %qs to %qs at %L",
+		 gfc_typename (&src->ts),
+		 gfc_typename (&result->ts),
+		 &src->where);
 
   return result;
 }
Index: primary.c
===
--- primary.c	(Revision 241590)
+++ primary.c	(Arbeitskopie)
@@ -1353,6 +1353,10 @@ match_complex_constant (gfc_expr **result)
 
   if (gfc_match_char (',') == MATCH_NO)
 {
+  /* It is possible that gfc_int2real issued a warning when
+	 converting an integer to real.  Throw this away here.  */
+
+  gfc_clear_warning ();
   gfc_pop_error (&old_error);
   m = MATCH_NO;
   goto cleanup;
! { dg-do compile }
! PR 67149 - this used to throw a spurious error.
function foo(bar)
   integer(8) :: foo
   integer(4), intent(in) :: bar
   integer(4), parameter  :: huge_4 = huge(0_4)
   foo = (huge_4 - int(bar,kind=8))
end function