[PATCH, OpenACC, Fortran] Fix PR77371, ICE on allocatable

2016-10-02 Thread Chung-Lin Tang
Hi Jakub,
This patch fixes the two ICEs listed on PR77371.
One is due to the Fortran omp_privatize_by_reference hook returning true
for types like 'character(kind=1)[1:XX] *', causing them to be processed
by the path intended for C++ reference types.

The other one is simply not setting 'remove = true' while error_at() was 
already called.

Tested without regressions, committed on gomp-4_0-branch,
is this okay for trunk as well?

Thanks,
Chung-Lin

PR fortran/77371
* omp-low.c (lower_omp_target): Avoid reference-type processing
on pointers for firstprivate clause.
* gimplify.c (gimplify_adjust_omp_clauses): Add 'remove = true'
when emitting error on private/firstprivate reductions.

testsuite/
* gfortran.dg/goacc/pr77371-1.f90: New test.
* gfortran.dg/goacc/pr77371-2.f90: New test.
Index: omp-low.c
===
--- omp-low.c   (revision 240699)
+++ omp-low.c   (working copy)
@@ -16238,7 +16238,8 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
  {
gcc_assert (is_gimple_omp_oacc (ctx->stmt));
-   if (is_reference (new_var))
+   if (is_reference (new_var)
+   && TREE_CODE (TREE_TYPE (new_var)) != POINTER_TYPE)
  {
/* Create a local object to hold the instance
   value.  */
Index: gimplify.c
===
--- gimplify.c  (revision 240699)
+++ gimplify.c  (working copy)
@@ -8351,13 +8351,16 @@ gimplify_adjust_omp_clauses (gimple_seq *pre_p, gi
case OMP_CLAUSE_REDUCTION:
  decl = OMP_CLAUSE_DECL (c);
  /* OpenACC reductions need a present_or_copy data clause.
-Add one if necessary.  Error is the reduction is private.  */
+Add one if necessary.  Emit error when the reduction is private.  
*/
  if (ctx->region_type == ORT_ACC_PARALLEL)
{
  n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
  if (n->value & (GOVD_PRIVATE | GOVD_FIRSTPRIVATE))
-   error_at (OMP_CLAUSE_LOCATION (c), "invalid private "
- "reduction on %qE", DECL_NAME (decl));
+   {
+ remove = true;
+ error_at (OMP_CLAUSE_LOCATION (c), "invalid private "
+   "reduction on %qE", DECL_NAME (decl));
+   }
  else if ((n->value & GOVD_MAP) == 0)
{
  tree next = OMP_CLAUSE_CHAIN (c);
Index: testsuite/gfortran.dg/goacc/pr77371-1.f90
===
--- testsuite/gfortran.dg/goacc/pr77371-1.f90   (revision 0)
+++ testsuite/gfortran.dg/goacc/pr77371-1.f90   (revision 0)
@@ -0,0 +1,9 @@
+! PR fortran/77371
+! { dg-do compile }
+program p
+  character(:), allocatable :: z
+  !$acc parallel
+  z = 'abc' 
+  !$acc end parallel
+  print *, z
+end
Index: testsuite/gfortran.dg/goacc/pr77371-2.f90
===
--- testsuite/gfortran.dg/goacc/pr77371-2.f90   (revision 0)
+++ testsuite/gfortran.dg/goacc/pr77371-2.f90   (revision 0)
@@ -0,0 +1,7 @@
+! PR fortran/77371
+! { dg-do compile }
+program p
+   integer, allocatable :: n
+!$acc parallel reduction (+:n) private(n) ! { dg-error "invalid private 
reduction" }
+!$acc end parallel
+end


Re: [PATCH][RTL ifcvt] Transform (X == CST) ? -CST : Y into (X == CST) ? -X : Y when conditional negation is available

2016-10-02 Thread Andreas Schwab
This miscompiles the stage2 ada compiler.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Re: [PATCH] Machine-readable RTL dumps: print_rtx_function

2016-10-02 Thread Segher Boessenkool
On Thu, Sep 29, 2016 at 11:36:29AM -0600, Jeff Law wrote:
> On 09/29/2016 11:25 AM, Bernd Schmidt wrote:
> >On 09/29/2016 07:47 PM, David Malcolm wrote:
> >>This patch adds a new function, print_rtx_function, intended for use
> >>for generating function dumps suitable for parsing by the RTL frontend,
> >>but also intended to be human-readable, and human-authorable.
> >
> >> (note 1 0 4 (nil) NOTE_INSN_DELETED)
> >> (note 4 1 2 2 [bb 2] NOTE_INSN_BASIC_BLOCK)
> >> (insn 2 4 3 2 (set (mem/c:SI (plus:DI (reg/f:DI 82
> >>virtual-stack-vars)
> >> (const_int -4 [0xfffc])) [1 i+0
> >>S4 A32])
> >> (reg:SI 5 di [ i ])) t.c:2 -1
> >>  (nil))
> >
> >I think it might be a good idea to get rid of redundant information like
> >insn numbers for such a dump format. But that can be left for followup
> >patches.
> I would make the same suggestion.  The insn # and backend pattern name 
> (if any) should be omitted in machine-readable dump format.  I'm fine 
> with that as a follow-up as well.

You need the insn id for (at least) code_label.


Segher


[PATCHv2] Cleanup of input.c

2016-10-02 Thread Bernd Edlinger
Hi Dave,

here is the new version of the input.c patch:

I have updated the comments, and revised the test case as requested.
I have additionally done a bootstrap with build config=bootstrap-asan.


Bootstrap and reg-testing on x86_64-pc-linux-gnu.
Is it OK for trunk?


Thanks
Bernd.
2016-09-26  Bernd Edlinger  

	PR preprocessor/77699
	* input.c (maybe_grow): Don't allocate one byte extra headroom.
	(get_next_line): Return false on error.
	(read_next_line): Removed, use get_next_line instead.
	(read_line_num): Don't copy the line.
	(location_get_source_line): Don't use static data.
	(test_reading_source_line): Add more test cases.


Index: gcc/input.c
===
--- gcc/input.c	(revision 240693)
+++ gcc/input.c	(working copy)
@@ -432,7 +432,7 @@ maybe_grow (fcache *c)
 return;
 
   size_t size = c->size == 0 ? fcache_buffer_size : c->size * 2;
-  c->data = XRESIZEVEC (char, c->data, size + 1);
+  c->data = XRESIZEVEC (char, c->data, size);
   c->size = size;
 }
 
@@ -472,14 +472,13 @@ maybe_read_data (fcache *c)
 
 /* Read a new line from file FP, using C as a cache for the data
coming from the file.  Upon successful completion, *LINE is set to
-   the beginning of the line found.  Space for that line has been
-   allocated in the cache thus *LINE has the same life time as C.
+   the beginning of the line found.  *LINE points directly in the
+   line cache and is only valid until the next call of get_next_line.
*LINE_LEN is set to the length of the line.  Note that the line
does not contain any terminal delimiter.  This function returns
true if some data was read or process from the cache, false
-   otherwise.  Note that subsequent calls to get_next_line return the
-   next lines of the file and might overwrite the content of
-   *LINE.  */
+   otherwise.  Note that subsequent calls to get_next_line might
+   make the content of *LINE invalid.  */
 
 static bool
 get_next_line (fcache *c, char **line, ssize_t *line_len)
@@ -534,7 +533,7 @@ get_next_line (fcache *c, char **line, ssize_t *li
 }
 
   if (ferror (c->fp))
-return -1;
+return false;
 
   /* At this point, we've found the end of the of line.  It either
  points to the '\n' or to one byte after the last byte of the
@@ -597,36 +596,6 @@ get_next_line (fcache *c, char **line, ssize_t *li
   return true;
 }
 
-/* Reads the next line from FILE into *LINE.  If *LINE is too small
-   (or NULL) it is allocated (or extended) to have enough space to
-   containe the line.  *LINE_LENGTH must contain the size of the
-   initial*LINE buffer.  It's then updated by this function to the
-   actual length of the returned line.  Note that the returned line
-   can contain several zero bytes.  Also note that the returned string
-   is allocated in static storage that is going to be re-used by
-   subsequent invocations of read_line.  */
-
-static bool
-read_next_line (fcache *cache, char ** line, ssize_t *line_len)
-{
-  char *l = NULL;
-  ssize_t len = 0;
-
-  if (!get_next_line (cache, &l, &len))
-return false;
-
-  if (*line == NULL)
-*line = XNEWVEC (char, len);
-  else
-if (*line_len < len)
-	*line = XRESIZEVEC (char, *line, len);
-
-  memcpy (*line, l, len);
-  *line_len = len;
-
-  return true;
-}
-
 /* Consume the next bytes coming from the cache (or from its
underlying file if there are remaining unread bytes in the file)
until we reach the next end-of-line (or end-of-file).  There is no
@@ -643,15 +612,15 @@ goto_next_line (fcache *cache)
 }
 
 /* Read an arbitrary line number LINE_NUM from the file cached in C.
-   The line is copied into *LINE.  *LINE_LEN must have been set to the
-   length of *LINE.  If *LINE is too small (or NULL) it's extended (or
-   allocated) and *LINE_LEN is adjusted accordingly.  *LINE ends up
-   with a terminal zero byte and can contain additional zero bytes.
+   If the line was read successfully, *LINE points to the beginning
+   of the line in the file cache and *LINE_LEN is the length of the
+   line.  *LINE is not nul-terminated, but may contain zero bytes.
+   *LINE is only valid until the next call of read_line_num.
This function returns bool if a line was read.  */
 
 static bool
 read_line_num (fcache *c, size_t line_num,
-	   char ** line, ssize_t *line_len)
+	   char **line, ssize_t *line_len)
 {
   gcc_assert (line_num > 0);
 
@@ -705,12 +674,8 @@ read_line_num (fcache *c, size_t line_num,
 	{
 	  /* We have the start/end of the line.  Let's just copy
 		 it again and we are done.  */
-	  ssize_t len = i->end_pos - i->start_pos + 1;
-	  if (*line_len < len)
-		*line = XRESIZEVEC (char, *line, len);
-	  memmove (*line, c->data + i->start_pos, len);
-	  (*line)[len - 1] = '\0';
-	  *line_len = --len;
+	  *line = c->data + i->start_pos;
+	  *line_len = i->end_pos - i->start_pos;
 	  return true;
 	}
 
@@ -735,21 +700,22 @@ read_line_num (fcache *c, si

Re: [PATCH] Delete GCJ

2016-10-02 Thread Andreas Schwab
Things we may want to remove:

- references to java in contrib (download_ecj, gcc_update,
  patch_tester.sh, update-copyright.py)
- GCJ, GCJ_FOR_BUILD, GCJ_FOR_TARGET in Makefiles.tpl and configure.ac
- LIBGCJ_SONAME in config/i386/{cygwin.h,mingw32.h}
- references to java in install.texi

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Re: [PATCH][RTL ifcvt] Transform (X == CST) ? -CST : Y into (X == CST) ? -X : Y when conditional negation is available

2016-10-02 Thread Jeff Law

On 10/02/2016 04:48 AM, Andreas Schwab wrote:

This miscompiles the stage2 ada compiler.

No target identified.
jeff


Re: [PATCH] Delete GCJ

2016-10-02 Thread Andrew Haley
On 02/10/16 14:27, Andreas Schwab wrote:
> Things we may want to remove:
> 
> - references to java in contrib (download_ecj, gcc_update,
>   patch_tester.sh, update-copyright.py)
> - GCJ, GCJ_FOR_BUILD, GCJ_FOR_TARGET in Makefiles.tpl and configure.ac
> - LIBGCJ_SONAME in config/i386/{cygwin.h,mingw32.h}
> - references to java in install.texi

Yes, that's true.  Thanks for doing the search.

Andrew.



Re: [PATCH] Make -Wint-in-bool-context warn on suspicious shift ops

2016-10-02 Thread Jason Merrill
OK.

On Fri, Sep 30, 2016 at 1:07 AM, Bernd Edlinger
 wrote:
> On 09/29/16 22:38, Jason Merrill wrote:
>> On Thu, Sep 29, 2016 at 3:58 PM, Bernd Edlinger
>>  wrote:
>>> Unfortunately, without that exception there is a false positive:
>>>
>>> In file included from ../../gcc-trunk/gcc/ada/gcc-interface/decl.c:30:0:
>>> ../../gcc-trunk/gcc/ada/gcc-interface/decl.c: In function 'int
>>> adjust_packed(tree, tree, int)':
>>> ../../gcc-trunk/gcc/tree.h:1874:22: error: << on signed integer in
>>> boolean context [-Werror=int-in-bool-context]
>>> ? ((unsigned)1) << ((NODE)->type_common.align - 1) : 0)
>>>   ~~^~
>>
>> Ah, this issue again: the shift isn't in boolean context, it's in
>> integer context.  I think we want to be a lot more conservative about
>> these warnings in the arms of a COND_EXPR.  In fact, I think the
>> entire
>>
>>/* Distribute the conversion into the arms of a COND_EXPR.  */
>>
>> section is wrong now that we're doing delayed folding.
>>
>
> Could you take care of this ?
>
>
> For the warning, I think I can suppress it just while
> the recursing into the condition arms.
>
> As in this updated patch.
>
> Is it OK?
>
>
> Bernd.


Re: Implement P0001R1 - C++17 removal of register storage class specifier

2016-10-02 Thread Jason Merrill
OK.

On Fri, Sep 30, 2016 at 7:28 PM, Jakub Jelinek  wrote:
> On Fri, Sep 30, 2016 at 05:32:31PM -0400, Jason Merrill wrote:
>> On Fri, Sep 30, 2016 at 4:10 AM, Jakub Jelinek  wrote:
>> > On Thu, Sep 29, 2016 at 10:57:07PM +, Joseph Myers wrote:
>> >> This is missing documentation of the new -Wregister option in invoke.texi.
>> >
>> > While I had it in my head when working on the patch, I forgot to do that 
>> > in the end.
>> > Fixed thusly, ok for trunk?
>>
>> OK.  But also, the patch has introduced several check-c++1z failures:
>>
>> > FAIL: g++.dg/charset/asm2.c  -std=c++1z (test for excess errors)
>> > FAIL: g++.dg/ext/asm3.C  -std=c++1z (test for excess errors)
>> > FAIL: g++.dg/tls/diag-2.C  -std=c++1z (test for excess errors)
>> > FAIL: g++.dg/tls/diag-4.C  -std=c++1z (test for excess errors)
>> > FAIL: g++.old-deja/g++.brendan/warnings4.C  -std=c++1z (test for excess 
>> > errors)
>> > FAIL: g++.old-deja/g++.eh/ia64-1.C  -std=gnu++1z (test for excess errors)
>> > FAIL: g++.old-deja/g++.jason/enum3.C  -std=gnu++1z (test for excess errors)
>> > FAIL: g++.old-deja/g++.mike/net31.C  -std=c++1z (test for excess errors)
>> > FAIL: g++.old-deja/g++.mike/p700.C  -std=gnu++1z (test for excess errors)
>> > FAIL: g++.old-deja/g++.other/regstack.C  -std=gnu++1z (test for excess 
>> > errors)
>
> Oops, I've been planning to do check-c++-all after the bootstrap/regtest,
> but apparently forgot to do that in the end.
>
> The following patch should fix that, ok for trunk?
>
> 2016-10-01  Jakub Jelinek  
>
> * g++.dg/ext/asm3.C (two): Only use register keyword for C++14 and
> earlier.
> * g++.dg/charset/asm2.c (memmove): Likewise.
> * g++.dg/tls/diag-2.C (foo): Expect -Wregister error for C++17.
> * g++.dg/tls/diag-4.C (foo): Likewise.
> * c-c++-common/vector-subscript-2.c (vf): Change dg-error to
> dg-warning, fix up regex.
> * g++.old-deja/g++.brendan/warnings4.C: Limit to c++14_down targets.
> * g++.old-deja/g++.mike/p700.C: Add -Wno-register.
> * g++.old-deja/g++.mike/net31.C: Likewise.
> * g++.old-deja/g++.other/regstack.C (foo): Expect -Wregister warning
> for C++17.
> * g++.old-deja/g++.jason/enum3.C: Add -Wno-register.
> * g++.old-deja/g++.eh/ia64-1.C: Likewise.
>
> --- gcc/testsuite/g++.dg/ext/asm3.C.jj  2014-09-25 15:02:34.0 +0200
> +++ gcc/testsuite/g++.dg/ext/asm3.C 2016-10-01 01:00:53.107415429 +0200
> @@ -7,9 +7,12 @@
>
>  int two(int in)
>  {
> -  register int out;
> +#if __cplusplus <= 201402L
> +  register
> +#endif
> +  int out;
>__asm__ ("" : "r" (out) : "r" (in));
>return out;
>  }
>
> -// { dg-message "error:" "" { target *-*-* } 11 }
> +// { dg-message "error:" "" { target *-*-* } 14 }
> --- gcc/testsuite/g++.dg/charset/asm2.c.jj  2014-09-25 15:02:36.0 
> +0200
> +++ gcc/testsuite/g++.dg/charset/asm2.c 2016-10-01 00:58:59.594839475 +0200
> @@ -10,7 +10,10 @@
>  void *
>  memmove (void *__dest, __const void *__src, size_t __n)
>  {
> -  register unsigned long int __d0, __d1, __d2;
> +#if __cplusplus <= 201402L
> +  register
> +#endif
> +  unsigned long int __d0, __d1, __d2;
>if (__dest < __src)
>  __asm__ __volatile__
>("cld\n\t"
> --- gcc/testsuite/g++.dg/tls/diag-2.C.jj2014-09-25 15:02:36.0 
> +0200
> +++ gcc/testsuite/g++.dg/tls/diag-2.C   2016-10-01 01:03:03.002785384 +0200
> @@ -12,7 +12,7 @@ void foo()
>auto __thread int l2;/* { dg-error "multiple storage 
> classes|data types" } */
>__thread extern int l3;  /* { dg-error "'__thread' before 'extern'" } 
> */
>register __thread int l4;/* { dg-error "multiple storage classes" } */
> -}
> +}  /* { dg-error "ISO C\\+\\+1z does not allow 
> 'register' storage class specifier" "" { target c++1z } .-1 } */
>
>  __thread void f1 ();   /* { dg-error "invalid for function" } */
>  extern __thread void f2 ();/* { dg-error "invalid for function" } */
> --- gcc/testsuite/g++.dg/tls/diag-4.C.jj2014-09-25 15:02:36.0 
> +0200
> +++ gcc/testsuite/g++.dg/tls/diag-4.C   2016-10-01 01:03:28.986458585 +0200
> @@ -7,4 +7,4 @@ void foo()
>  {
>__thread auto int l2;/* { dg-error "multiple storage 
> classes|data types" } */
>__thread register int l4;/* { dg-error "multiple storage classes" } */
> -}
> +}  /* { dg-error "ISO C\\+\\+1z does not allow 
> 'register' storage class specifier" "" { target c++1z } .-1 } */
> --- gcc/testsuite/c-c++-common/vector-subscript-2.c.jj  2016-09-30 
> 18:40:58.335979346 +0200
> +++ gcc/testsuite/c-c++-common/vector-subscript-2.c 2016-10-01 
> 01:22:19.577245968 +0200
> @@ -7,6 +7,6 @@
>
>  float vf(int i)
>  {
> -  register vector float a; // { dg-error "ISO C++1z does not allow 
> 'register' storage class specifier" "" { target c++1z } }
> +  register vector float a; // { dg-warning "ISO C\\+

Re: PATCH to fix bogus -Wimplicit-fallthrough warning (PR c++/77803)

2016-10-02 Thread Jason Merrill
On Sat, Oct 1, 2016 at 10:17 AM, Marek Polacek  wrote:
> +   && (last_eval == NULL
> +   || !gimple_call_internal_p (last_eval, IFN_FALLTHROUGH))

Isn't this still assuming that non-null last_eval must be a gcall, so
we'll get a checking ICE if it's something else?

Jason


Re: C/C++ PATCH to implement -Wpointer-compare warning (PR c++/64767)

2016-10-02 Thread Jason Merrill
OK, thanks.

On Sat, Oct 1, 2016 at 10:16 AM, Marek Polacek  wrote:
> On Fri, Sep 30, 2016 at 05:48:03PM -0400, Jason Merrill wrote:
>> On Fri, Sep 30, 2016 at 12:43 PM, Marek Polacek  wrote:
>> > On Fri, Sep 23, 2016 at 10:31:33AM -0400, Jason Merrill wrote:
>> >> On Fri, Sep 23, 2016 at 9:15 AM, Marek Polacek  wrote:
>> >> > On Wed, Sep 21, 2016 at 03:52:09PM -0400, Jason Merrill wrote:
>> >> >> On Mon, Sep 19, 2016 at 2:49 PM, Jason Merrill  
>> >> >> wrote:
>> >> >> > I suppose that an INTEGER_CST of character type is necessarily a
>> >> >> > character constant, so adding a check for !char_type_p ought to do 
>> >> >> > the
>> >> >> > trick.
>> >> >>
>> >> >> Indeed it does.  I'm checking this in:
>> >> >
>> >> > Nice, thanks.  What about the original patch?  We still need to warn
>> >> > (or error for C++11) for pointer comparisons.
>> >>
>> >> If we still accept pointer comparisons in C++, that's another bug with
>> >> treating \0 as a null pointer constant.  This seems to be because
>> >> ocp_convert of \0 to int produces an INTEGER_CST indistinguishable
>> >> from literal 0.
>> >
>> > I was trying to fix this in ocp_convert, by using NOP_EXPRs, but that 
>> > wasn't
>> > successful.  But since we're interested in ==/!=, I think this can be fixed
>> > easily in cp_build_binary_op.  Actually, all that seems to be needed is 
>> > using
>> > orig_op as the argument to null_ptr_cst_p, but that wouldn't give the 
>> > correct
>> > diagnostics, so I did this.  By checking orig_op we can see if the 
>> > operands are
>> > character literals or not, because orig_op is an operand before the default
>> > conversions.
>>
>> What is wrong about the diagnostic from just using orig_op?  "ISO C++
>> forbids comparison between pointer and integer" seems fine to me, and
>> will help the user to realize that they need to index off the pointer.
>>
>> I see that some of the calls to null_ptr_cst_p in cp_build_binary_op
>> have already been changed to check orig_op*, but not all.  Let's
>> update the remaining calls, that should do the trick without adding a
>> new error.
>
> Here you go:
>
> Bootstrapped/regtested on x86_64-linux and ppc64-linux, ok for trunk?
>
> 2016-10-01  Marek Polacek  
>
> Core 903
> * typeck.c (cp_build_binary_op): Pass original operands to
> null_ptr_cst_p, not those after the default conversions.
>
> * g++.dg/cpp0x/nullptr37.C: New test.
>
> diff --git gcc/cp/typeck.c gcc/cp/typeck.c
> index 617ca55..8b780be 100644
> --- gcc/cp/typeck.c
> +++ gcc/cp/typeck.c
> @@ -4573,7 +4573,7 @@ cp_build_binary_op (location_t location,
>   || code1 == COMPLEX_TYPE || code1 == ENUMERAL_TYPE))
> short_compare = 1;
>else if (((code0 == POINTER_TYPE || TYPE_PTRDATAMEM_P (type0))
> -   && null_ptr_cst_p (op1))
> +   && null_ptr_cst_p (orig_op1))
>/* Handle, eg, (void*)0 (c++/43906), and more.  */
>|| (code0 == POINTER_TYPE
>&& TYPE_PTR_P (type1) && integer_zerop (op1)))
> @@ -4587,7 +4587,7 @@ cp_build_binary_op (location_t location,
>   warn_for_null_address (location, op0, complain);
> }
>else if (((code1 == POINTER_TYPE || TYPE_PTRDATAMEM_P (type1))
> -   && null_ptr_cst_p (op0))
> +   && null_ptr_cst_p (orig_op0))
>/* Handle, eg, (void*)0 (c++/43906), and more.  */
>|| (code1 == POINTER_TYPE
>&& TYPE_PTR_P (type0) && integer_zerop (op0)))
> @@ -4604,7 +4604,7 @@ cp_build_binary_op (location_t location,
>|| (TYPE_PTRDATAMEM_P (type0) && TYPE_PTRDATAMEM_P (type1)))
> result_type = composite_pointer_type (type0, type1, op0, op1,
>   CPO_COMPARISON, complain);
> -  else if (null_ptr_cst_p (op0) && null_ptr_cst_p (op1))
> +  else if (null_ptr_cst_p (orig_op0) && null_ptr_cst_p (orig_op1))
> /* One of the operands must be of nullptr_t type.  */
>  result_type = TREE_TYPE (nullptr_node);
>else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
> @@ -4623,7 +4623,7 @@ cp_build_binary_op (location_t location,
>else
>  return error_mark_node;
> }
> -  else if (TYPE_PTRMEMFUNC_P (type0) && null_ptr_cst_p (op1))
> +  else if (TYPE_PTRMEMFUNC_P (type0) && null_ptr_cst_p (orig_op1))
> {
>   if (TARGET_PTRMEMFUNC_VBIT_LOCATION
>   == ptrmemfunc_vbit_in_delta)
> @@ -4664,7 +4664,7 @@ cp_build_binary_op (location_t location,
> }
>   result_type = TREE_TYPE (op0);
> }
> -  else if (TYPE_PTRMEMFUNC_P (type1) && null_ptr_cst_p (op0))
> +  else if (TYPE_PTRMEMFUNC_P (type1) && null_ptr_cst_p (orig_op0))
> return cp_build_binary_op (location, code, op1, op0, complain);
>else if (TYPE_PTRMEMFUNC_P (type0) && TYPE_PTRMEMFUNC_P (type1))
> {
> @@ -4877,21 +4877,21 @@ cp_build_b

Re: [BUILDROBOT] dwarf2out_do_cfi_startproc(bool)’: may write a terminating nul past the end of the destination

2016-10-02 Thread Jason Merrill
OK.

On Sat, Oct 1, 2016 at 4:30 PM, Jakub Jelinek  wrote:
> On Fri, Sep 30, 2016 at 08:59:52PM +0200, Jakub Jelinek wrote:
>> Ok if it passes bootstrap/regtest?
>
> Passed bootstrap/regtest on x86_64-linux and i686-linux.
>>
>> 2016-09-30  Jakub Jelinek  
>>
>>   * dwarf2out.c (output_fde, output_call_frame_info,
>>   dwarf2out_do_cfi_startproc, set_indirect_string,
>>   gen_internal_sym, output_die, output_line_info): Use
>>   MAX_ARTIFICIAL_LABEL_BYTES as char array sizes for
>>   ASM_GENERATE_INTERNAL_LABEL output.
>
> Jakub


Re: [PATCH][RTL ifcvt] Transform (X == CST) ? -CST : Y into (X == CST) ? -X : Y when conditional negation is available

2016-10-02 Thread Andrew Pinski
On Sun, Oct 2, 2016 at 7:50 AM, Jeff Law  wrote:
> On 10/02/2016 04:48 AM, Andreas Schwab wrote:
>>
>> This miscompiles the stage2 ada compiler.
>
> No target identified.


He reported it in a bug report, aarch64-linux-gnu.

Thanks,
Andrew

> jeff


[C++ PATCH] Delete GCJ - C++ part

2016-10-02 Thread Jakub Jelinek
On Sun, Oct 02, 2016 at 03:27:09PM +0200, Andreas Schwab wrote:
> Things we may want to remove:
> 
> - references to java in contrib (download_ecj, gcc_update,
>   patch_tester.sh, update-copyright.py)
> - GCJ, GCJ_FOR_BUILD, GCJ_FOR_TARGET in Makefiles.tpl and configure.ac
> - LIBGCJ_SONAME in config/i386/{cygwin.h,mingw32.h}
> - references to java in install.texi

There is another thing, the Java extensions in the C++ FE, which are IMNSHO
no longer needed after GCJ removal.

Here is a C++ patch that removes that part, bootstrapped/regtested on
x86_64-linux and i686-linux, ok for trunk?

2016-10-02  Jakub Jelinek  

* doc/extend.texi (Java Exceptions): Remove.
(java_interface): Remove.
cp/
* cp-tree.h (enum cp_tree_index): Remove CPTI_JAVA_*,
CPTI_LANG_NAME_JAVA and CPTI_JCLASS.
(java_byte_type_node, java_short_type_node, java_int_type_node,
java_long_type_node, java_float_type_node, java_double_type_node,
java_char_type_node, java_boolean_type_node, lang_name_java,
jclass_node): Remove.
(enum languages): Remove lang_java.
(TYPE_FOR_JAVA): Remove.
(struct lang_type_class): Remove java_interface bit-field.
(TYPE_JAVA_INTERFACE): Remove.
(pragma_java_exceptions): Remove.
(check_java_method, build_java_class_ref): Remove prototypes.
* name-lookup.c (pushtag_1): Don't set TYPE_FOR_JAVA.
* decl2.c (acceptable_java_type, check_java_method): Remove.
(import_export_decl): Remove TYPE_FOR_JAVA handling.
(build_java_method_aliases): Remove.
(c_parse_final_cleanups): Don't call build_java_method_aliases.
(possibly_inlined_p): Don't test pragma_java_exceptions.
* init.c (build_new_1): Remove TYPE_FOR_JAVA handling.
(build_java_class_ref): Remove.
* pt.c (maybe_new_partial_specialization, lookup_template_class_1,
instantiate_class_template_1): Don't copy TYPE_FOR_JAVA.
* except.c (eh_type_info): Remove java type handling.
(decl_is_java_type, choose_personality_routine): Remove.
(initialize_handler_parm): Don't call choose_personality_routine.
(expand_start_catch_block): Don't handle java types.
(build_throw): Likewise.
* cp-lang.c (cp_eh_personality): Don't handle pragma_java_exceptions.
* typeck.c (structural_comptypes): Don't compare TYPE_FOR_JAVA.
* call.c (build_over_call): Don't handle TYPE_JAVA_INTERFACE.
(java_iface_lookup_fn): Remove.
(build_java_interface_fn_ref): Remove.
* tree.c (cxx_attribute_table): Remove java_interface.
(handle_java_interface_attribute): Remove.
* lex.c (pragma_java_exceptions): Remove.
(init_cp_pragma): Don't register GCC java_exceptions pragma.
(handle_pragma_java_exceptions): Remove.
(retrofit_lang_decl): Don't handle lang_name_java.
* method.c (implicitly_declare_fn): Don't handle TYPE_FOR_JAVA.
* error.c (language_to_string): Don't handle lang_java.
* decl.c (record_builtin_java_type): Remove.
(initialize_predefined_identifiers): Remove Java.
(cxx_init_decl_processing): Remove java_*_type_node.
(cp_finish_decl): Don't handle TYPE_FOR_JAVA.
(grokfndecl): Likewise.
(check_special_function_return_type): Likewise.
(grokdeclarator): Don't set TYPE_FOR_JAVA.
(grokparms): Don't handle TYPE_FOR_JAVA.
(xref_basetypes): Likewise.
(check_function_type): Likewise.
(finish_constructor_body): Likewise.
* mangle.c (write_builtin_type): Don't handle TYPE_FOR_JAVA
and java_*_type_node.
(write_bare_function_type): Don't handle TYPE_FOR_JAVA.
(write_java_integer_type_codes): Remove.
* class.c (add_method): Don't handle TYPE_FOR_JAVA.
(add_implicitly_declared_members, determine_key_method,
finish_struct_1): Likewise.
(push_lang_context): Don't handle lang_name_java.
testsuite/
* g++.dg/other/java3.C: Remove.
* g++.dg/other/java1.C: Remove.
* g++.dg/other/error12.C: Remove.
* g++.dg/other/java2.C: Remove.
* g++.dg/warn/Wnvdtor.C: Remove.
* g++.dg/lookup/java1.C: Remove.
* g++.dg/lookup/java2.C: Remove.
* g++.dg/ext/pr34829.C: Remove.
* g++.dg/ext/java-3.C: Remove.
* g++.dg/ext/java-1.C: Remove.
* g++.dg/ext/java-2.C: Remove.
* g++.old-deja/g++.oliva/dwarf2.C: Remove.

--- gcc/doc/extend.texi.jj  2016-09-29 22:53:11.0 +0200
+++ gcc/doc/extend.texi 2016-10-02 19:27:25.315410894 +0200
@@ -21392,7 +21392,6 @@ Predefined Macros,cpp,The GNU C Preproce
 * Namespace Association:: Strong using-directives for namespace association.
 * Type Traits:: Compiler support for type traits.
 * C++ Concepts::Improved support for generic programming.
-* Java Exceptions:: Tweaking exception handling to work with Java.
 

[PATCH] fix outstanding -Wformat-length failures (pr77735 et al.)

2016-10-02 Thread Martin Sebor

The attached patch fixes a number of outstanding test failures
and ILP32-related bugs in the gimple-ssa-sprintf pattch pointed
out in bug 77676 and 77735).  The patch also fixes c_strlen to
correctly handle wide strings (previously it accepted them but
treated them as nul-terminated byte sequences), and adjusts the
handling of "%a" to avoid assuming a specific number of decimal
digits (this is likely a defect in C11 that I'm pursuing with
WG14).

Tested on powerpc64le, i386, and x86_64.

There is one outstanding failure in the builtin-sprintf-warn-1.c
test on powerpc64le that looks like it might be due to the
printf_pointer_format target hook not having been set up entirely
correctly.  I'll look into that separately, along with pr77819.

Martin
PR middle-end/77735 - FAIL: gcc.dg/tree-ssa/builtin-sprintf-warn-1.c

gcc/ChangeLog:
2016-10-02  Martin Sebor  

	PR middle-end/77735
	* builtins.c (string_length): New function.
	(c_strlen): Use string_length.  Correctly handle wide strings.
	* gimple-ssa-sprintf.c (target_max_value, target_size_max): New
	functions.
	(target_int_max): Call target_max_value.
	(format_result::knownrange): New data member.
	(fmtresult::fmtresult): Define default constructor.
	(format_integer): Use it and set format_result::knownrange.
	Handle global constants.
	(format_floating_max): Add third argument.
	(format_floating): Recompute maximum value for %a for each argument.
	(get_string_length): Use fmtresult default ctor.
	(format_string): Set format_result::knownrange.
	(format_directive): Check format_result::knownrange.
	(add_bytes): Same.  Correct caret placement in diagnostics.
	(pass_sprintf_length::compute_format_length): Set
	format_result::knownrange.
	(pass_sprintf_length::handle_gimple_call): Use target_size_max.

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

	PR middle-end/77735
	* gcc.dg/tree-ssa/builtin-sprintf-2.c: Add test cases.
	* gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: Same.
	* gcc.dg/tree-ssa/builtin-sprintf-warn-2.c: Same.
	* gcc.dg/tree-ssa/builtin-sprintf-warn-3.c: Adjust/relax.
	* gcc.dg/tree-ssa/builtin-sprintf-warn-4.c: Add test cases.
	* gcc.dg/tree-ssa/builtin-sprintf-warn-6.c: XFAIL for LP64 only.
	* gcc.dg/tree-ssa/builtin-sprintf.c: Add test cases.

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 35cb109..7f6dc54 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -508,9 +508,44 @@ get_pointer_alignment (tree exp)
   return align;
 }
 
-/* Compute the length of a C string.  TREE_STRING_LENGTH is not the right
-   way, because it could contain a zero byte in the middle.
-   TREE_STRING_LENGTH is the size of the character array, not the string.
+/* Return the number of non-zero elements in the sequence
+   [ PTR, PTR + MAXELTS ) where each element's size is ELTSIZE bytes.
+   ELTSIZE must be a power of 2 less than 8.  Used by c_strlen.  */
+
+static unsigned
+string_length (const void *ptr, unsigned eltsize, unsigned maxelts)
+{
+  gcc_checking_assert (eltsize == 1 || eltsize == 2 || eltsize == 4);
+
+  unsigned n;
+
+  if (eltsize == 1)
+{
+  /* Optimize the common case of plain char.  */
+  for (n = 0; n < maxelts; n++)
+	{
+	  const char *elt = (const char*) ptr + n;
+	  if (!*elt)
+	break;
+	}
+}
+  else
+{
+  for (n = 0; n < maxelts; n++)
+	{
+	  const char *elt = (const char*) ptr + n * eltsize;
+	  if (!memcmp (elt, "\0\0\0\0", eltsize))
+	break;
+	}
+}
+  return n;
+}
+
+/* Compute the length of a null-terminated character string or wide
+   character string handling character sizes of 1, 2, and 4 bytes.
+   TREE_STRING_LENGTH is not the right way because it evaluates to
+   the size of the character array in bytes (as opposed to characters)
+   and because it can contain a zero byte in the middle.
 
ONLY_VALUE should be nonzero if the result is not going to be emitted
into the instruction stream and zero if it is going to be expanded.
@@ -531,12 +566,6 @@ get_pointer_alignment (tree exp)
 tree
 c_strlen (tree src, int only_value)
 {
-  tree offset_node;
-  HOST_WIDE_INT offset;
-  int max;
-  const char *ptr;
-  location_t loc;
-
   STRIP_NOPS (src);
   if (TREE_CODE (src) == COND_EXPR
   && (only_value || !TREE_SIDE_EFFECTS (TREE_OPERAND (src, 0
@@ -553,25 +582,36 @@ c_strlen (tree src, int only_value)
   && (only_value || !TREE_SIDE_EFFECTS (TREE_OPERAND (src, 0
 return c_strlen (TREE_OPERAND (src, 1), only_value);
 
-  loc = EXPR_LOC_OR_LOC (src, input_location);
+  location_t loc = EXPR_LOC_OR_LOC (src, input_location);
 
-  src = string_constant (src, &offset_node);
+  /* Offset from the beginning of the string in bytes.  */
+  tree byteoff;
+  src = string_constant (src, &byteoff);
   if (src == 0)
 return NULL_TREE;
 
-  max = TREE_STRING_LENGTH (src) - 1;
-  ptr = TREE_STRING_POINTER (src);
+  /* Determine the size of the string element.  */
+  unsigned eltsize
+= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (src;
+
+  /* Set MAXELTS to sizeof (S

RE: Fix PR tree-optimization/77808, ICE in duplicate_ssa_name_ptr_info, at tree-ssanames.c:630 starting with r240439

2016-10-02 Thread Doug Gilmore
Hi Christophe,

> From: Christophe Lyon [christophe.l...@linaro.org]
> Sent: Saturday, October 01, 2016 7:57 AM
> To: Doug Gilmore
> Cc: gcc-patches@gcc.gnu.org
> Subject: Re: Fix PR tree-optimization/77808, ICE in 
> duplicate_ssa_name_ptr_info, at tree-ssanames.c:630 starting with r240439
> 
> Hi Doug,
>
> ...
> I can confirm that your patch fixes the ICE I was seeing.
> 
> However, the new testcase does not pass on low end
> architectures:
> cc1: warning: -fprefetch-loop-arrays not supported for this target
> (try -march switches)
> 
> Can you add a guard?
> 
> Thanks,
> 
> Christophe
I updated the test to only run on X86, MIPS and AARCH64.  Is that OK?

Thanks,

Doug


0001-Fix-PR-tree-optimization-77808.patch
Description: 0001-Fix-PR-tree-optimization-77808.patch


Re: PATCH to fix bogus -Wimplicit-fallthrough warning (PR c++/77803)

2016-10-02 Thread Jakub Jelinek
On Sun, Oct 02, 2016 at 02:42:23PM -0400, Jason Merrill wrote:
> On Sat, Oct 1, 2016 at 10:17 AM, Marek Polacek  wrote:
> > +   && (last_eval == NULL
> > +   || !gimple_call_internal_p (last_eval, IFN_FALLTHROUGH))
> 
> Isn't this still assuming that non-null last_eval must be a gcall, so
> we'll get a checking ICE if it's something else?

This is the 2 operand gimple_call_internal_p, which is
  return (is_gimple_call (gs)
  && gimple_call_internal_p (gs)
  && gimple_call_internal_fn (gs) == fn);
and thus should be fine for non-NULL last_eval.

Jakub


[PATCH] add uClibc target hook (PR bootstrap/77819)

2016-10-02 Thread Martin Sebor

The attached patch adds a uclibc_printf_pointer_format target
hook equivalent to the linux glibc_printf_pointer_format hook.
I couldn't find a good uclibc-only file where to put the new
definition of the hook so I conditionally added it to
targethooks.c.

I tested the new hook by bootstrapping GCC for tic6x-uclinux
and bfin-uclinux targets on x86_64.

Martin
PR bootstrap/77819 - undefined reference to gnu_libc_printf_pointer_format with uClibc

gcc/ChangeLog:
2016-10-02  Martin Sebor  

	PR bootstrap/77819
	* config/linux.h [DEFAULT_LIBC == LIBC_UCLIBC) && SINGLE_LIBC]
	(TARGET_PRINTF_POINTER_FORMAT): Define macro.
	* targhooks.c [DEFAULT_LIBC == LIBC_UCLIBC) && SINGLE_LIBC]
	(default_printf_pointer_format): Define function.
	* targhooks.h (default_printf_pointer_format): Declare.

diff --git a/gcc/config/linux.h b/gcc/config/linux.h
index 3ff005b..1649b01 100644
--- a/gcc/config/linux.h
+++ b/gcc/config/linux.h
@@ -200,6 +200,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 # undef TARGET_LIBC_HAS_FUNCTION
 # define TARGET_LIBC_HAS_FUNCTION no_c99_libc_has_function
 
+/* The format string to which "%p" corresponds.  */
+#  undef TARGET_PRINTF_POINTER_FORMAT
+#  define TARGET_PRINTF_POINTER_FORMAT uclibc_printf_pointer_format
+
 #else /* !uClinux, i.e., normal Linux */
 
 /* Determine what functions are present at the runtime;
@@ -207,8 +211,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 # undef TARGET_LIBC_HAS_FUNCTION
 # define TARGET_LIBC_HAS_FUNCTION linux_libc_has_function
 
-#endif
-
 /* The format string to which "%p" corresponds.  */
-#undef TARGET_PRINTF_POINTER_FORMAT
-#define TARGET_PRINTF_POINTER_FORMAT gnu_libc_printf_pointer_format
+#  undef TARGET_PRINTF_POINTER_FORMAT
+#  define TARGET_PRINTF_POINTER_FORMAT gnu_libc_printf_pointer_format
+
+#endif
diff --git a/gcc/targhooks.c b/gcc/targhooks.c
index d75650f..77b4a18 100644
--- a/gcc/targhooks.c
+++ b/gcc/targhooks.c
@@ -1523,6 +1523,26 @@ default_printf_pointer_format (tree, const char **flags)
   return "%zx";
 }
 
+#if (DEFAULT_LIBC == LIBC_UCLIBC) && defined (SINGLE_LIBC) /* uClinux */
+
+/* For *uclibc* targets only, define the hook here because otherwise
+   it would have to be duplicated in each target's .c file (such as
+   in bfin/bfin.c and c6x/c6x.c, etc.)
+   uClibc (and Glibc) format pointers as if by "%zx" except for the null
+   pointer which outputs "(nil)".  It ignores the pound ('#') format
+   flag but interprets the space and plus flags the same as in the integer
+   directive.  */
+
+const char*
+uclibc_printf_pointer_format (tree arg, const char **flags)
+{
+  *flags = " +";
+
+  return arg && integer_zerop (arg) ? "(nil)" : "%#zx";
+}
+
+#endif
+
 tree
 default_builtin_tm_load_store (tree ARG_UNUSED (type))
 {
diff --git a/gcc/targhooks.h b/gcc/targhooks.h
index 3356f0a..52d36e0 100644
--- a/gcc/targhooks.h
+++ b/gcc/targhooks.h
@@ -194,6 +194,7 @@ extern bool gnu_libc_has_function (enum function_class);
 extern const char* default_printf_pointer_format (tree, const char **);
 extern const char* gnu_libc_printf_pointer_format (tree, const char **);
 extern const char* solaris_printf_pointer_format (tree, const char **);
+extern const char* uclibc_printf_pointer_format (tree, const char **);
 
 extern tree default_builtin_tm_load_store (tree);
 


[PATCH, Fortran] Fix ICE due to comparison between UNION components

2016-10-02 Thread Fritz Reese
All,

The attached fixes an[other] ICE in the comparison between UNIONs.
This time the ICE is due to a BT_UNION component comparing itself to a
BT_DERIVED component, thus considering their FL_STRUCT and FL_UNION
typenodes to be equal. This is very similar to PR fortran/77782,
except it is an error in the comparison of _components_ from
gfc_compare_types, instead of an error comparing the _type symbols_
from gfc_compare_derived. The patch makes sure that BT_UNION compared
to anything other than BT_UNION is _not_ equal, while still comparing
two union components with gfc_compare_union_types.

Will commit soon with no complaints. Maybe this patch will finally get
type comparison right for unions.

---
Fritz Reese

2016-10-02  Fritz Reese  

Fix ICE due to comparison between UNION components.

* gcc/fortran/interface.c (gfc_compare_types): Don't compare BT_UNION
components until we know they're both UNIONs.

* gcc/testsuite/gfortran.dg/dec_union_9.f90: New testcase.
diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c
index 04ad0e2..441cc00 100644
--- a/gcc/fortran/interface.c
+++ b/gcc/fortran/interface.c
@@ -694,13 +694,14 @@ gfc_compare_types (gfc_typespec *ts1, gfc_typespec *ts2)
   && (ts1->u.derived->attr.sequence || ts1->u.derived->attr.is_bind_c))
 return 1;
 
-  if (ts1->type == BT_UNION && ts2->type == BT_UNION)
-return gfc_compare_union_types (ts1->u.derived, ts2->u.derived);
-
   if (ts1->type != ts2->type
-  && ((!gfc_bt_struct (ts1->type) && ts1->type != BT_CLASS)
-	  || (!gfc_bt_struct (ts2->type) && ts2->type != BT_CLASS)))
+  && ((ts1->type != BT_DERIVED && ts1->type != BT_CLASS)
+	  || (ts2->type != BT_DERIVED && ts2->type != BT_CLASS)))
 return 0;
+
+  if (ts1->type == BT_UNION)
+return gfc_compare_union_types (ts1->u.derived, ts2->u.derived);
+
   if (ts1->type != BT_DERIVED && ts1->type != BT_CLASS)
 return (ts1->kind == ts2->kind);
 
diff --git a/gcc/testsuite/gfortran.dg/dec_union_9.f90 b/gcc/testsuite/gfortran.dg/dec_union_9.f90
new file mode 100644
index 000..2cb38fc
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec_union_9.f90
@@ -0,0 +1,26 @@
+! { dg-do compile }
+! { dg-options "-fdec-structure" }
+!
+! Test a regression where union components could compare equal to structure/map
+! components, causing an ICE in gfc_conv_component_ref.
+!
+
+implicit none
+
+structure /s1/
+  integer(4) i
+end structure
+
+structure /s2/
+  union
+map
+  record /s1/ r
+end map
+  end union
+end structure
+
+record /s2/ x
+
+x.r.i = 0
+
+end