[PATCH GCC] PR90021 ICE fix

2019-04-09 Thread bin.cheng
Hi,
This patch fixes ICE reported by PR90021.  The issue has been there since loop 
interchange
and recently exposed by patch for PR89725.  As PR comment suggests, we have 
equal access
function {{1, +, 1}_6, +, 1}_4 and _6 is of loop_nest's outer loop.  This patch 
introduces
new parameter loopnum to function evolution_function_is_univariate_p so that 
the above
scev won't be considered as multivariate, i.e, {1, +, 1}_6 is considered as a 
symbol to the
loop_nest.  Note we only change computation of classic dist vector, rather than 
DDR itself. 

Bootstrap and test on x86_64.  Is it ok?

BTW, I wonder if collecting data reference in one loop but computing DDR in an 
inner loop 
is useful in the future, besides loop interchange.

Thanks,
bin

2019-04-10  Bin Cheng  

PR tree-optimization/92001
* tree-chrec.c (evolution_function_is_univariate_p): New parameter
and check univariate against it.
* tree-chrec.h (evolution_function_is_univariate_p): New parameter.
* tree-data-ref.c (add_other_self_distances): Pass new argument.

2018-04-10  Bin Cheng  

PR tree-optimization/92001
* gcc/testsuite/gfortran.dg/pr90021.f90: New test.

0001-pr90021.patch
Description: Binary data


Re: [PATCH] Fix up target_to_host fn in gimple-ssa-sprintf.c (PR c++/90010)

2019-04-09 Thread Richard Biener
On April 9, 2019 11:47:28 PM GMT+02:00, Jakub Jelinek  wrote:
>Hi!
>
>As the following testcase shows, target_to_host handled
>targstr with strlen shorter than hostsz - 4 right (though with wasteful
>clearing of the rest of the buffer when only one '\0' termination is
>enough)
>and similarly also strlen hostsz and more right (making last 4
>characters
>in the buffer "..."), but anything in between resulted in random
>byte(s)
>at the end of the string (strncpy with hostsz - 4 length didn't zero
>terminate and because strlen (targstr) >= hostsz was false, nothing was
>appended).  When some target to host charset adjustment was needed, it
>appended that "..." even to strings that actually didn't need it.
>
>The following patch doesn't use "..." if targstr fits (including the
>zero
>termination), otherwise makes sure last 4 bytes in the buffer are
>"...".
>Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK. 

Richard. 

>2019-04-09  Jakub Jelinek  
>
>   PR c++/90010
>   * gimple-ssa-sprintf.c (target_to_host): Fix handling of targstr
>   with strlen in between hostsz-3 and hostsz-1 inclusive when no
>   translation is needed, and when translation is needed, only append
>   ... if the string length is hostsz or more bytes long.  Avoid using
>   strncpy or strcat.
>
>   * gcc.dg/pr90010.c: New test.
>
>--- gcc/gimple-ssa-sprintf.c.jj2019-04-09 12:25:41.0 +0200
>+++ gcc/gimple-ssa-sprintf.c   2019-04-09 14:01:04.875445413 +0200
>@@ -383,9 +383,14 @@ target_to_host (char *hostr, size_t host
>  overlong strings just like the translated strings are.  */
>   if (target_to_host_charmap['\0'] == 1)
> {
>-  strncpy (hostr, targstr, hostsz - 4);
>-  if (strlen (targstr) >= hostsz)
>-  strcpy (hostr + hostsz - 4, "...");
>+  size_t len = strlen (targstr);
>+  if (len >= hostsz)
>+  {
>+memcpy (hostr, targstr, hostsz - 4);
>+strcpy (hostr + hostsz - 4, "...");
>+  }
>+  else
>+  memcpy (hostr, targstr, len + 1);
>   return hostr;
> }
> 
>@@ -399,10 +404,9 @@ target_to_host (char *hostr, size_t host
>   if (!*targstr)
>   break;
> 
>-  if (size_t (ph - hostr) == hostsz - 4)
>+  if (size_t (ph - hostr) == hostsz)
>   {
>-*ph = '\0';
>-strcat (ph, "...");
>+strcpy (ph - 4, "...");
> break;
>   }
> }
>--- gcc/testsuite/gcc.dg/pr90010.c.jj  2019-04-09 14:22:14.795791124
>+0200
>+++ gcc/testsuite/gcc.dg/pr90010.c 2019-04-09 14:26:10.274961523 +0200
>@@ -0,0 +1,27 @@
>+/* PR c++/90010 */
>+/* { dg-do compile } */
>+/* { dg-options "-Wall" } */
>+
>+char b[4096] = "abc";
>+void bar (char *);
>+
>+void
>+foo ()
>+{
>+  char d[4096];
>+  __builtin_snprintf (d, sizeof d, "%sfoobarbazquxquuxquuzthudfred",
>b);/* { dg-warning "'foobarbazquxquuxquuzthudfred' directive output
>may be truncated writing 28 bytes into a region of size between 1 and
>4096" } */
>+  /* { dg-message "'__builtin_snprintf' output between 29 and 4124
>bytes into a destination of size 4096" "" { target *-*-* } .-1 } */
>+  bar (d);
>+  __builtin_snprintf (d, sizeof d, "%sfoobarbazquxquuxquuzcorgefred",
>b);/* { dg-warning "'foobarbazquxquuxquuzcorgefred' directive output
>may be truncated writing 29 bytes into a region of size between 1 and
>4096" } */
>+  /* { dg-message "'__builtin_snprintf' output between 30 and 4125
>bytes into a destination of size 4096" "" { target *-*-* } .-1 } */
>+  bar (d);
>+  __builtin_snprintf (d, sizeof d, "%sfoobarbazquxquuxquuzcorgewaldo",
>b);/* { dg-warning "'foobarbazquxquuxquuzcorgewaldo' directive output
>may be truncated writing 30 bytes into a region of size between 1 and
>4096" } */
>+  /* { dg-message "'__builtin_snprintf' output between 31 and 4126
>bytes into a destination of size 4096" "" { target *-*-* } .-1 } */
>+  bar (d);
>+  __builtin_snprintf (d, sizeof d,
>"%sfoobarbazquxquuxquuzcorgegarply", b);   /* { dg-warning
>"'foobarbazquxquuxquuzcorgegarply' directive output may be truncated
>writing 31 bytes into a region of size between 1 and 4096" } */
>+  /* { dg-message "'__builtin_snprintf' output between 32 and 4127
>bytes into a destination of size 4096" "" { target *-*-* } .-1 } */
>+  bar (d);
>+  __builtin_snprintf (d, sizeof d,
>"%sfoobarfredquxquuxquuzcorgegarply", b);  /* { dg-warning
>"'foobarfredquxquuxquuzcorgega\.\.\.' directive output may be truncated
>writing 32 bytes into a region of size between 1 and 4096" } */
>+  /* { dg-message "'__builtin_snprintf' output between 33 and 4128
>bytes into a destination of size 4096" "" { target *-*-* } .-1 } */
>+  bar (d);
>+}
>
>   Jakub



Re: [Patch, fortran] PRs 89843 and 90022 - C Fortran Interop fixes.

2019-04-09 Thread Steve Kargl
On Tue, Apr 09, 2019 at 11:18:11AM +0100, Paul Richard Thomas wrote:
> 
> This patch is safe for trunk, even at this late stage, because its
> effects are barricaded behind the tests for CFI descriptors. I believe
> that it appropriately rewards the bug reporters to have this feature
> work as well as possible at release.
> 

I cannot look at this until Saturday, if no one reviews
by then I'll give it a quick glance.

-- 
Steve
20170425 https://www.youtube.com/watch?v=VWUpyCsUKR4
20161221 https://www.youtube.com/watch?v=IbCHE-hONow


Re: [PATCH] D support for RISC-V

2019-04-09 Thread Jim Wilson
On Tue, Apr 9, 2019 at 10:36 AM Iain Buclaw  wrote:
> Any objection if I upstream the non-asm bits?

Doesn't all of it, except maybe the configure.tgt patch need to go
upstream first?  And do you need some paperwork or button click from
David for D language patches for the copyright assignment?

Is there a problem with the asm bits?  The fenv.h functions like
fegetenv could be used for this, assuming you can include a C header
file in D code.  But if this is the D language implementation of
fenv.h, then you probably can't avoid the assembly code.

Otherwise I don't have an opinion on this.  I haven't tried testing D
language support yet.

Jim


Re: [PATCH, rs6000] PR87532: Bad results from vec_extract (unsigned char, foo) dependent upon function inline

2019-04-09 Thread Segher Boessenkool
Hi Kelvin,

On Tue, Apr 09, 2019 at 08:15:31AM -0500, Kelvin Nilsen wrote:
> This new patch addresses the code generation problems that were uncovered by 
> these failing tests.  Additionally, this new patch corrects some of the 
> expected instruction counts for certain previously existing regression tests 
> on certain targets to adjust for changes in the generated code.

Is the newly generated code better though?  Worse?  More expected?  It isn't
clear to me.

> This new patch has been bootstrapped and tested without regressions on 
> powerpcle-unknown-linux (both P8 and P9) and on powerpc-linux (P7 and P8, 
> both -m32 and -m64).

powerpcle-linux is a very different configuration than the powerpc64le-linux
you mean (powerpc64-linux and powerpc-linux are biarch to each other, but
the LE variants are not).  Very minor...  It's just that powerpcle-linux
makes me cringe.

>   * gcc.target/powerpc/fold-vec-extract-short.p8.c: Likewise.:

(stray colon)

> +// P8 LE variable offset: rldicl, subfic, sldi, mtvsrd, xxpermdi, vslo, 
> mfvsrd, sradi, rlwin, (extsb)

rlwinm

> -/* { dg-final { scan-assembler-times {\mrlwinm\M} 2 { target lp64} } } */
> +/* { dg-final { scan-assembler-times {\mrlwinm\M} 4 { target lp64} } } */

Put a space after lp64 while you're here?  Or remove the one before target,
whichever you like best.


I'm a bit worried that these tests change instruction counts so often, what
that means for maintainability.  But, okay for trunk, and for backports (but
please make sure they generate the correct counts for all targets there :-/ )


Segher


Re: [Patch, fortran] PRs 89843 and 90022 - C Fortran Interop fixes.

2019-04-09 Thread Paul Richard Thomas
Many thanks, sir! I will look into it.

Paul

On Tue, 9 Apr 2019 at 17:43, Dominique d'Humières  wrote:
>
> Hi Paul,
>
> With your patch the test gfortran.dg/ISO_Fortran_binding_9.f90 fails in the 
> 32 bit mode, due to the errors
>
> /opt/gcc/work/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.f90:24:6: 
> Error: Type mismatch in argument 'expected' at (1); passed INTEGER(4) to 
> INTEGER(8)
> /opt/gcc/work/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.f90:25:6: 
> Error: Type mismatch in argument 'expected' at (1); passed INTEGER(4) to 
> INTEGER(8)
> /opt/gcc/work/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.f90:26:6: 
> Error: Type mismatch in argument 'expected' at (1); passed INTEGER(4) to 
> INTEGER(8)
> /opt/gcc/work/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.f90:27:6: 
> Error: Type mismatch in argument 'expected' at (1); passed INTEGER(4) to 
> INTEGER(8)
>
> Note that LOC is a gnu extension.
>
> The patch also fixes pr89846 for -m64, but not for -m32
>
> % gfc pr89846.c pr89846.f90 -m32
> % a.out
>  FAIL 2:
>  FAIL 4:
> % gfc pr89846.c pr89846.f90
> % a.out
>  OK
>  OK
>
> TIA
>
> Dominique
>


-- 
"If you can't explain it simply, you don't understand it well enough"
- Albert Einstein


[PATCH] Replace direct PSTL uses of assert() with a macro

2019-04-09 Thread Thomas Rodgers
This also replaces calls to __TBB_ASSERT so that there are two macro
definitions provided by c++config -
__PSTL_ASSERT(_Condition)
__PSTL_ASSERT_MSG(_Condition, _Message)

* include/bits/c++config:
Add definition for __PSTL_ASSERT.
Add definition for __PSTL_ASSERT_MSG.
* include/pstl/algorithm_impl.h: Replace use of assert().
* include/pstl/numeric_impl.h: Replace use of assert().
* include/pstl/parallel_backend_tbb.h:
Replace use of assert().
Replace use of __TBB_ASSERT().

* include/pstl/parallel_backend_utils.h: Replace use of assert().

>From d95934a0f325e0934ada829378c3c0dfd6b3628c Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Fri, 5 Apr 2019 15:27:35 -0700
Subject: [PATCH] Replace direct PSTL uses of assert() with a macro

This also replaces calls to __TBB_ASSERT so that there are two macro
definitions provided by c++config -
	__PSTL_ASSERT(_Condition)
	__PSTL_ASSERT_MSG(_Condition, _Message)

	* include/bits/c++config:
	Add definition for __PSTL_ASSERT.
	Add definition for __PSTL_ASSERT_MSG.
	* include/pstl/algorithm_impl.h: Replace use of assert().
	* include/pstl/numeric_impl.h: Replace use of assert().
	* include/pstl/parallel_backend_tbb.h:
	Replace use of assert().
	Replace use of __TBB_ASSERT().

	* include/pstl/parallel_backend_utils.h: Replace use of assert().
---
 libstdc++-v3/include/bits/c++config   |  4 
 libstdc++-v3/include/pstl/algorithm_impl.h| 14 +++---
 libstdc++-v3/include/pstl/numeric_impl.h  |  8 
 libstdc++-v3/include/pstl/parallel_backend_tbb.h  | 11 ++-
 .../include/pstl/parallel_backend_utils.h | 15 +++
 5 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
index 66420a9a3f2..8dd04f218b4 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -690,6 +690,10 @@ namespace std
 #  undef __PSTL_PAR_BACKEND_TBB
 # endif
 
+# define __PSTL_ASSERT(_Condition) (__glibcxx_assert(_Condition))
+# define __PSTL_ASSERT_MSG(_Condition, _Message) (__glibcxx_assert(_Condition))
+
+
 # define __PSTL_PRAGMA(x) _Pragma (#x)
 
 # define __PSTL_STRING_AUX(x) #x
diff --git a/libstdc++-v3/include/pstl/algorithm_impl.h b/libstdc++-v3/include/pstl/algorithm_impl.h
index e06bf60151e..a42d3993d1b 100644
--- a/libstdc++-v3/include/pstl/algorithm_impl.h
+++ b/libstdc++-v3/include/pstl/algorithm_impl.h
@@ -1309,7 +1309,7 @@ __pattern_unique_copy(_ExecutionPolicy&& __exec, _RandomAccessIterator __first,
 return __internal::__except_handler([&__exec, __n, __first, __result, __pred, __is_vector, &__mask_buf]() {
 bool* __mask = __mask_buf.get();
 _DifferenceType __m{};
-__par_backend::parallel_strict_scan(
+__par_backend::__parallel_strict_scan(
 std::forward<_ExecutionPolicy>(__exec), __n, _DifferenceType(0),
 [=](_DifferenceType __i, _DifferenceType __len) -> _DifferenceType { // Reduce
 _DifferenceType __extra = 0;
@@ -2731,8 +2731,8 @@ __pattern_includes(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _Forwa
  return !__internal::__parallel_or(
 std::forward<_ExecutionPolicy>(__exec), __first2, __last2,
 [__first1, __last1, __first2, __last2, &__comp](_ForwardIterator2 __i, _ForwardIterator2 __j) {
-assert(__j > __i);
-//assert(__j - __i > 1);
+__PSTL_ASSERT(__j > __i);
+//__PSTL_ASSERT(__j - __i > 1);
 
 //1. moving boundaries to "consume" subsequence of equal elements
 auto __is_equal = [&__comp](_ForwardIterator2 __a, _ForwardIterator2 __b) -> bool {
@@ -2756,8 +2756,8 @@ __pattern_includes(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _Forwa
 //2. testing is __a subsequence of the second range included into the first range
 auto __b = std::lower_bound(__first1, __last1, *__i, __comp);
 
-assert(!__comp(*(__last1 - 1), *__b));
-assert(!__comp(*(__j - 1), *__i));
+__PSTL_ASSERT(!__comp(*(__last1 - 1), *__b));
+__PSTL_ASSERT(!__comp(*(__j - 1), *__i));
 return !std::includes(__b, __last1, __i, __j, __comp);
 });
 });
@@ -2801,7 +2801,7 @@ __parallel_set_op(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _Forwar
 __internal::__brick_move(__buffer + __s.__buf_pos, __buffer + (__s.__buf_pos + __s.__len), __result + __s.__pos,
  __is_vector);
 };
-__par_backend::parallel_strict_scan(
+__par_backend::__parallel_strict_scan(
 

Re: [PATCH] Add PSTL internal namespace qualifications

2019-04-09 Thread Thomas Rodgers


Committed to trunk.

Thomas Rodgers writes:

> This patch adds additional internal namespace qualifications to the pstl
> implementation.
>
> From 35dba02035ebb5fd44ac0f06e25a81dfef05898f Mon Sep 17 00:00:00 2001
> From: Thomas Rodgers 
> Date: Thu, 28 Mar 2019 17:23:49 -0700
> Subject: [PATCH] Add namespace qualification for pstl-internal symbols
>
> Prevent ADL related weirdness.
>
>   * include/pstl/algorithm_impl.h: Add namespace qualification.
>   * include/pstl/execution_defs.h: Add namespace qualification.
>   * include/pstl/execution_impl.h: Add namespace qualification.
>   * include/pstl/numeric_impl.h: Add namespace qualification.
>   * include/pstl/parallel_backend_tbb.h: Add namespace qualification.
>   * include/pstl/unseq_backend_simd.h: Add namespace qualification.
>   * include/pstl/parallel_backend_utils.h: Include .
> ---
>  libstdc++-v3/include/pstl/algorithm_impl.h| 427 +-
>  libstdc++-v3/include/pstl/execution_defs.h|  10 +-
>  libstdc++-v3/include/pstl/execution_impl.h|  22 +-
>  libstdc++-v3/include/pstl/numeric_impl.h  |  30 +-
>  .../include/pstl/parallel_backend_tbb.h   |  49 +-
>  .../include/pstl/parallel_backend_utils.h |   1 +
>  .../include/pstl/unseq_backend_simd.h |   8 +-
>  7 files changed, 275 insertions(+), 272 deletions(-)
>
> diff --git a/libstdc++-v3/include/pstl/algorithm_impl.h 
> b/libstdc++-v3/include/pstl/algorithm_impl.h
> index 9d8242873ab..e06bf60151e 100644
> --- a/libstdc++-v3/include/pstl/algorithm_impl.h
> +++ b/libstdc++-v3/include/pstl/algorithm_impl.h
> @@ -18,6 +18,7 @@
>  
>  #include "execution_impl.h"
>  #include "memory_impl.h"
> +#include "parallel_backend_utils.h"
>  #include "unseq_backend_simd.h"
>  
>  #if __PSTL_USE_PAR_POLICIES
> @@ -55,7 +56,7 @@ bool
>  __pattern_any_of(_ExecutionPolicy&&, _ForwardIterator __first, 
> _ForwardIterator __last, _Pred __pred,
>   _IsVector __is_vector, /*parallel=*/std::false_type) 
> noexcept
>  {
> -return __brick_any_of(__first, __last, __pred, __is_vector);
> +return __internal::__brick_any_of(__first, __last, __pred, __is_vector);
>  }
>  
>  #if __PSTL_USE_PAR_POLICIES
> @@ -64,10 +65,10 @@ bool
>  __pattern_any_of(_ExecutionPolicy&& __exec, _ForwardIterator __first, 
> _ForwardIterator __last, _Pred __pred,
>   _IsVector __is_vector, /*parallel=*/std::true_type)
>  {
> -return __except_handler([&]() {
> -return __parallel_or(std::forward<_ExecutionPolicy>(__exec), 
> __first, __last,
> +return __internal::__except_handler([&]() {
> +   return 
> __internal::__parallel_or(std::forward<_ExecutionPolicy>(__exec), __first, 
> __last,
>   [__pred, __is_vector](_ForwardIterator __i, 
> _ForwardIterator __j) {
> - return __brick_any_of(__i, __j, __pred, 
> __is_vector);
> + return __internal::__brick_any_of(__i, __j, 
> __pred, __is_vector);
>   });
>  });
>  }
> @@ -111,7 +112,7 @@ __pattern_walk1(_ExecutionPolicy&&, _ForwardIterator 
> __first, _ForwardIterator _
>  _IsVector __is_vector,
>  /*parallel=*/std::false_type) noexcept
>  {
> -__brick_walk1(__first, __last, __f, __is_vector);
> +__internal::__brick_walk1(__first, __last, __f, __is_vector);
>  }
>  
>  #if __PSTL_USE_PAR_POLICIES
> @@ -121,10 +122,10 @@ __pattern_walk1(_ExecutionPolicy&& __exec, 
> _ForwardIterator __first, _ForwardIte
>  _IsVector __is_vector,
>  /*parallel=*/std::true_type)
>  {
> -__except_handler([&]() {
> +__internal::__except_handler([&]() {
>  
> __par_backend::__parallel_for(std::forward<_ExecutionPolicy>(__exec), 
> __first, __last,
>[__f, __is_vector](_ForwardIterator 
> __i, _ForwardIterator __j) {
> -  __brick_walk1(__i, __j, __f, 
> __is_vector);
> +  __internal::__brick_walk1(__i, 
> __j, __f, __is_vector);
>});
>  });
>  }
> @@ -144,7 +145,7 @@ void
>  __pattern_walk_brick(_ExecutionPolicy&& __exec, _ForwardIterator __first, 
> _ForwardIterator __last, _Brick __brick,
>   /*parallel=*/std::true_type)
>  {
> -__except_handler([&]() {
> +__internal::__except_handler([&]() {
>  
> __par_backend::__parallel_for(std::forward<_ExecutionPolicy>(__exec), 
> __first, __last,
>[__brick](_ForwardIterator __i, 
> _ForwardIterator __j) { __brick(__i, __j); });
>  });
> @@ -158,7 +159,7 @@ template  _Function>
>  _ForwardIterator
>  __brick_walk1_n(_ForwardIterator __first, _Size __n, _Function __f, 
> /*_IsVectorTag=*/std::false_type)
>  {
> -return __for_each_n_it_serial(__first, __n,
> +return 

[PATCH] Fix up target_to_host fn in gimple-ssa-sprintf.c (PR c++/90010)

2019-04-09 Thread Jakub Jelinek
Hi!

As the following testcase shows, target_to_host handled
targstr with strlen shorter than hostsz - 4 right (though with wasteful
clearing of the rest of the buffer when only one '\0' termination is enough)
and similarly also strlen hostsz and more right (making last 4 characters
in the buffer "..."), but anything in between resulted in random byte(s)
at the end of the string (strncpy with hostsz - 4 length didn't zero
terminate and because strlen (targstr) >= hostsz was false, nothing was
appended).  When some target to host charset adjustment was needed, it
appended that "..." even to strings that actually didn't need it.

The following patch doesn't use "..." if targstr fits (including the zero
termination), otherwise makes sure last 4 bytes in the buffer are "...".
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2019-04-09  Jakub Jelinek  

PR c++/90010
* gimple-ssa-sprintf.c (target_to_host): Fix handling of targstr
with strlen in between hostsz-3 and hostsz-1 inclusive when no
translation is needed, and when translation is needed, only append
... if the string length is hostsz or more bytes long.  Avoid using
strncpy or strcat.

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

--- gcc/gimple-ssa-sprintf.c.jj 2019-04-09 12:25:41.0 +0200
+++ gcc/gimple-ssa-sprintf.c2019-04-09 14:01:04.875445413 +0200
@@ -383,9 +383,14 @@ target_to_host (char *hostr, size_t host
  overlong strings just like the translated strings are.  */
   if (target_to_host_charmap['\0'] == 1)
 {
-  strncpy (hostr, targstr, hostsz - 4);
-  if (strlen (targstr) >= hostsz)
-   strcpy (hostr + hostsz - 4, "...");
+  size_t len = strlen (targstr);
+  if (len >= hostsz)
+   {
+ memcpy (hostr, targstr, hostsz - 4);
+ strcpy (hostr + hostsz - 4, "...");
+   }
+  else
+   memcpy (hostr, targstr, len + 1);
   return hostr;
 }
 
@@ -399,10 +404,9 @@ target_to_host (char *hostr, size_t host
   if (!*targstr)
break;
 
-  if (size_t (ph - hostr) == hostsz - 4)
+  if (size_t (ph - hostr) == hostsz)
{
- *ph = '\0';
- strcat (ph, "...");
+ strcpy (ph - 4, "...");
  break;
}
 }
--- gcc/testsuite/gcc.dg/pr90010.c.jj   2019-04-09 14:22:14.795791124 +0200
+++ gcc/testsuite/gcc.dg/pr90010.c  2019-04-09 14:26:10.274961523 +0200
@@ -0,0 +1,27 @@
+/* PR c++/90010 */
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+
+char b[4096] = "abc";
+void bar (char *);
+
+void
+foo ()
+{
+  char d[4096];
+  __builtin_snprintf (d, sizeof d, "%sfoobarbazquxquuxquuzthudfred", b);   
/* { dg-warning "'foobarbazquxquuxquuzthudfred' directive output may be 
truncated writing 28 bytes into a region of size between 1 and 4096" } */
+  /* { dg-message "'__builtin_snprintf' output between 29 and 4124 bytes into 
a destination of size 4096" "" { target *-*-* } .-1 } */
+  bar (d);
+  __builtin_snprintf (d, sizeof d, "%sfoobarbazquxquuxquuzcorgefred", b);  
/* { dg-warning "'foobarbazquxquuxquuzcorgefred' directive output may be 
truncated writing 29 bytes into a region of size between 1 and 4096" } */
+  /* { dg-message "'__builtin_snprintf' output between 30 and 4125 bytes into 
a destination of size 4096" "" { target *-*-* } .-1 } */
+  bar (d);
+  __builtin_snprintf (d, sizeof d, "%sfoobarbazquxquuxquuzcorgewaldo", b); 
/* { dg-warning "'foobarbazquxquuxquuzcorgewaldo' directive output may be 
truncated writing 30 bytes into a region of size between 1 and 4096" } */
+  /* { dg-message "'__builtin_snprintf' output between 31 and 4126 bytes into 
a destination of size 4096" "" { target *-*-* } .-1 } */
+  bar (d);
+  __builtin_snprintf (d, sizeof d, "%sfoobarbazquxquuxquuzcorgegarply", b);
/* { dg-warning "'foobarbazquxquuxquuzcorgegarply' directive output may be 
truncated writing 31 bytes into a region of size between 1 and 4096" } */
+  /* { dg-message "'__builtin_snprintf' output between 32 and 4127 bytes into 
a destination of size 4096" "" { target *-*-* } .-1 } */
+  bar (d);
+  __builtin_snprintf (d, sizeof d, "%sfoobarfredquxquuxquuzcorgegarply", b);   
/* { dg-warning "'foobarfredquxquuxquuzcorgega\.\.\.' directive output may be 
truncated writing 32 bytes into a region of size between 1 and 4096" } */
+  /* { dg-message "'__builtin_snprintf' output between 33 and 4128 bytes into 
a destination of size 4096" "" { target *-*-* } .-1 } */
+  bar (d);
+}

Jakub


[C/C++ PATCH] Fix promoted switch condition out of range diagnostics (PR c/89888, take 2)

2019-04-09 Thread Jakub Jelinek
On Tue, Apr 09, 2019 at 09:06:33AM +0200, Jakub Jelinek wrote:
> Alternatively, I believe we could remove from the patch the in-place
> replacement of CASE_LABEL_EXPRs with LABEL_EXPRs if we want to remove,
> just splay_tree_remove those, because by my reading of
> preprocess_case_label_vec_for_gimple we also ignore the fully out of range
> CASE_LABEL_EXPRs there, shall I tweak the patch and rebootstrap?

Here is a version of the patch that doesn't overwrite those CASE_LABEL_EXPRs
as gimplifier handles those, just removes them from the splay tree.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2019-04-09  Jakub Jelinek  

PR c/89888
* c-common.h (c_add_case_label): Remove orig_type and outside_range_p
arguments.
(c_do_switch_warnings): Remove outside_range_p argument.
* c-common.c (check_case_bounds): Removed.
(c_add_case_label): Remove orig_type and outside_range_p arguments.
Don't call check_case_bounds.  Fold low_value as well as high_value.
* c-warn.c (c_do_switch_warnings): Remove outside_range_p argument.
Check for case labels outside of range of original type here and
adjust them.
c/
* c-typeck.c (struct c_switch): Remove outside_range_p member.
(c_start_case): Don't clear it.
(do_case): Adjust c_add_case_label caller.
(c_finish_case): Adjust c_do_switch_warnings caller.
cp/
* decl.c (struct cp_switch): Remove outside_range_p member.
(push_switch): Don't clear it.
(pop_switch): Adjust c_do_switch_warnings caller.
(finish_case_label): Adjust c_add_case_label caller.
testsuite/
* c-c++-common/pr89888.c: New test.
* g++.dg/torture/pr40335.C: Change dg-bogus into dg-warning.
Don't expect -Wswitch-unreachable warning.

--- gcc/c-family/c-common.h.jj  2019-03-20 12:24:57.320308115 +0100
+++ gcc/c-family/c-common.h 2019-04-08 19:02:28.522104090 +0200
@@ -988,8 +988,7 @@ extern tree boolean_increment (enum tree
 
 extern int case_compare (splay_tree_key, splay_tree_key);
 
-extern tree c_add_case_label (location_t, splay_tree, tree, tree, tree, tree,
- bool *);
+extern tree c_add_case_label (location_t, splay_tree, tree, tree, tree);
 extern bool c_switch_covers_all_cases_p (splay_tree, tree);
 
 extern tree build_function_call (location_t, tree, tree);
@@ -1291,8 +1290,7 @@ extern void sizeof_pointer_memaccess_war
  bool (*) (tree, tree));
 extern void check_main_parameter_types (tree decl);
 extern void warnings_for_convert_and_check (location_t, tree, tree, tree);
-extern void c_do_switch_warnings (splay_tree, location_t, tree, tree, bool,
- bool);
+extern void c_do_switch_warnings (splay_tree, location_t, tree, tree, bool);
 extern void warn_for_omitted_condop (location_t, tree);
 extern bool warn_for_restrict (unsigned, tree *, unsigned);
 extern void warn_for_address_or_pointer_of_packed_member (tree, tree);
--- gcc/c-family/c-common.c.jj  2019-03-26 08:52:54.938604825 +0100
+++ gcc/c-family/c-common.c 2019-04-09 01:28:01.199754481 +0200
@@ -314,8 +314,6 @@ const struct fname_var_t fname_vars[] =
 struct visibility_flags visibility_options;
 
 static tree check_case_value (location_t, tree);
-static bool check_case_bounds (location_t, tree, tree, tree *, tree *,
-  bool *);
 
 
 static void check_nonnull_arg (void *, tree, unsigned HOST_WIDE_INT);
@@ -2103,86 +2101,6 @@ check_case_value (location_t loc, tree v
   return value;
 }
 
-/* See if the case values LOW and HIGH are in the range of the original
-   type (i.e. before the default conversion to int) of the switch testing
-   expression.
-   TYPE is the promoted type of the testing expression, and ORIG_TYPE is
-   the type before promoting it.  CASE_LOW_P is a pointer to the lower
-   bound of the case label, and CASE_HIGH_P is the upper bound or NULL
-   if the case is not a case range.
-   The caller has to make sure that we are not called with NULL for
-   CASE_LOW_P (i.e. the default case).  OUTSIDE_RANGE_P says whether there
-   was a case value that doesn't fit into the range of the ORIG_TYPE.
-   Returns true if the case label is in range of ORIG_TYPE (saturated or
-   untouched) or false if the label is out of range.  */
-
-static bool
-check_case_bounds (location_t loc, tree type, tree orig_type,
-  tree *case_low_p, tree *case_high_p,
-  bool *outside_range_p)
-{
-  tree min_value, max_value;
-  tree case_low = *case_low_p;
-  tree case_high = case_high_p ? *case_high_p : case_low;
-
-  /* If there was a problem with the original type, do nothing.  */
-  if (orig_type == error_mark_node)
-return true;
-
-  min_value = TYPE_MIN_VALUE (orig_type);
-  max_value = TYPE_MAX_VALUE (orig_type);
-
-  /* We'll really need integer constants here.  */
-  case_low = fold (case_low);
-  

Re: [wwwdocs] gcc-9/changes.html - Mention new OpenRISC backend

2019-04-09 Thread Stafford Horne
Committed.

On Tue, Apr 02, 2019 at 01:03:35PM +0900, Stafford Horne wrote:
> Hello,
> 
> I was reading through some things and found this was missing.
> 
> As before, I don't seem to have CVS access, if its OK and someone can commit 
> it
> would be helpful.

It turns out I do have CVS access, which is granted along with SVN access.

> -Stafford
> 
> Index: htdocs/gcc-9/changes.html
> ===
> RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-9/changes.html,v
> retrieving revision 1.56
> diff -u -r1.56 changes.html
> --- htdocs/gcc-9/changes.html 1 Apr 2019 14:55:53 -   1.56
> +++ htdocs/gcc-9/changes.html 2 Apr 2019 03:59:42 -
> @@ -827,6 +827,13 @@
>  
>  
>  
> +OpenRISC
> +
> +  
> +A new back end targeting OpenRISC processors has been contributed to GCC.
> +  
> +
> +
>  
>  
>  


Re: [RFC, doc] Note variable shadowing at max macro using statement expression

2019-04-09 Thread Sandra Loosemore

On 4/8/19 5:38 AM, Tom de Vries wrote:

Hi,

When suggesting to rewrite the unsafe (with respect to multiple evaluation of
arguments) macro definition:
...
   #define max(a,b) ((a) > (b) ? (a) : (b))
...
into the safe macro definition:
...
   #define maxint(a,b) \
 ({int _a = (a), _b = (b); _a > _b ? _a : _b; })
...
mention the variable shadowing problem for:
...
   #define maxint3(a, b, c) \
 ({int _a = (a), _b = (b), _c = (c); maxint (maxint (_a, _b), _c); })
...

Any comments?


The content looks reasonable, but I have some copy-editing nits.


diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 8e0deac26c3..27ed0fb014f 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -143,13 +143,34 @@ follows:
  But this definition computes either @var{a} or @var{b} twice, with bad
  results if the operand has side effects.  In GNU C, if you know the
  type of the operands (here taken as @code{int}), you can define
-the macro safely as follows:
+the macro safe (from evaluating operands more than once) as follows:


That doesn't read well.  I suggest

...you can avoid this problem by defining the macro as follows:

  
  @smallexample

  #define maxint(a,b) \
(@{int _a = (a), _b = (b); _a > _b ? _a : _b; @})
  @end smallexample
  
+Note that introducing variable declarations (as we do in maxint) can


@code{maxint}


+cause variable shadowing, so while this example using the max macro will


@code{max}


+produce correct results:


s/will produce/produces/


+@smallexample
+int _a = 1, _b = 2, c;
+c = max (_a, _b);
+@end smallexample




+this example using maxint will not:


@noindent
this example using @code{maxint} does not:


+@smallexample
+int _a = 1, _b = 2, c;
+c = maxint (_a, _b);
+@end smallexample
+
+This problem may for instance occur when we use this pattern recursively, like
+so:
+
+@smallexample
+#define maxint3(a, b, c) \
+  (@{int _a = (a), _b = (b), _c = (c); maxint (maxint (_a, _b), _c); @})
+@end smallexample
+
  Embedded statements are not allowed in constant expressions, such as
  the value of an enumeration constant, the width of a bit-field, or
  the initial value of a static variable.



-Sandra


[PATCH] PR libstdc++/89851 Add testcase for std::variant equality

2019-04-09 Thread Jonathan Wakely

Add a test for the regression introduced with r269422 and fixed with
r270056.

PR libstdc++/89851
* testsuite/20_util/variant/89851.cc: New test.

Tested x86_64-linux, committed to trunk.

commit 429d850417840c18a5a1e90ee085f474395a7117
Author: Jonathan Wakely 
Date:   Tue Apr 9 20:46:47 2019 +0100

PR libstdc++/89851 Add testcase for std::variant equality

Add a test for the regression introduced with r269422 and fixed with
r270056.

PR libstdc++/89851
* testsuite/20_util/variant/89851.cc: New test.

diff --git a/libstdc++-v3/testsuite/20_util/variant/89851.cc 
b/libstdc++-v3/testsuite/20_util/variant/89851.cc
new file mode 100644
index 000..f4993556ab2
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/variant/89851.cc
@@ -0,0 +1,40 @@
+// Copyright (C) 2019 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++17 } }
+
+#include 
+#include 
+
+// PR libstdc++/89851
+
+void
+test01()
+{
+  using V = std::variant;
+  V v1{std::in_place_index<0>, 0};
+  V v2{std::in_place_index<1>, 0};
+  VERIFY(   v1 != v2  );
+  VERIFY( !(v1 == v2) );
+}
+
+int
+main()
+{
+  test01();
+}


Re: [libphobos] Work around Solaris ld bug linking __tls_get_addr on 64-bit x86

2019-04-09 Thread Rainer Orth
Rainer Orth  writes:

> Here's the patch I mentioned in
>
>   https://gcc.gnu.org/ml/gcc-patches/2019-01/msg01661.html
>
> to work around an amd64 Solaris ld bug.  I'm just posting it for
> reference now: until it's clear if a fix will make it into Solaris 11.5
> or not, there's no point in applying it yet.
>
> Still, review comments are appreciated.

With the revised patch for non-dlpi_tls_modid versions of Solaris

https://gcc.gnu.org/ml/gcc-patches/2019-04/msg00354.html

__tls_get_addr will always be called and thus this workaround is needed
unconditionally, even should the ld bug be fixed in Solaris 11.5.

This revision adjusts the patch accordingly and was tested together with
the other one on Solaris 11.[345]/x86.

Ok for mainline?

Rainer

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


2019-01-28  Rainer Orth  

* m4/druntime/os.m4 (DRUNTIME_OS_LINK_SPEC): New macro.
* configure.ac: Call it.
* configure: Regenerate.
* src/libgphobos.spec.in (*link): Append OS_LINK_SPEC.

# HG changeset patch
# Parent  bfb51574f91b2eaceb6cc39883f8c6bd7cf7f885
Work around Solaris ld bug linking __tls_get_addr on 64-bit x86

diff --git a/libphobos/configure.ac b/libphobos/configure.ac
--- a/libphobos/configure.ac
+++ b/libphobos/configure.ac
@@ -126,6 +126,7 @@ DRUNTIME_OS_SOURCES
 DRUNTIME_OS_THREAD_MODEL
 DRUNTIME_OS_ARM_EABI_UNWINDER
 DRUNTIME_OS_MINFO_BRACKETING
+DRUNTIME_OS_LINK_SPEC
 DRUNTIME_LIBRARIES_CLIB
 
 WITH_LOCAL_DRUNTIME([
diff --git a/libphobos/m4/druntime/os.m4 b/libphobos/m4/druntime/os.m4
--- a/libphobos/m4/druntime/os.m4
+++ b/libphobos/m4/druntime/os.m4
@@ -183,3 +183,25 @@ AC_DEFUN([DRUNTIME_OS_MINFO_BRACKETING],
   AM_CONDITIONAL([DRUNTIME_OS_MINFO_BRACKETING], [test "$DCFG_MINFO_BRACKETING" = "true"])
   AC_LANG_POP([C])
 ])
+
+# DRUNTIME_OS_LINK_SPEC
+# -
+# Add target-specific link options to link_spec.
+AC_DEFUN([DRUNTIME_OS_LINK_SPEC],
+[
+  case $target in
+i?86-*-solaris2.* | x86_64-*-solaris2.*)
+  # 64-bit Solaris/x86 ld breaks calls to __tls_get_addr with non-TLS
+  # relocs.  Work around by disabling TLS transitions.  Not necessary
+  # on 32-bit x86, but cannot be distinguished reliably in specs.
+  druntime_ld_prog=`$CC -print-prog-name=ld`
+  if test -n "$druntime_ld_prog" \
+ && $druntime_ld_prog -v 2>&1 | grep GNU > /dev/null 2>&1; then
+:
+  else
+OS_LINK_SPEC='-z relax=transtls'
+  fi
+  ;;
+  esac
+  AC_SUBST(OS_LINK_SPEC)
+])
diff --git a/libphobos/src/libgphobos.spec.in b/libphobos/src/libgphobos.spec.in
--- a/libphobos/src/libgphobos.spec.in
+++ b/libphobos/src/libgphobos.spec.in
@@ -6,5 +6,8 @@
 
 @DRTSTUFF_SPEC@
 
+%rename link linkorig_gdc_renamed
+*link: %(linkorig_gdc_renamed) @OS_LINK_SPEC@
+
 %rename lib liborig_gdc_renamed
 *lib: %{debuglib|defaultlib|nophoboslib: ; :@SPEC_PHOBOS_DEPS@} %(liborig_gdc_renamed)


[Ada] Fix wrong translation of C++ virtual destructor

2019-04-09 Thread Eric Botcazou
This is a regression present on all active branches: -fdump-ada-spec no longer 
generates a declaration for the (implicit) deleting destructor in a class, 
which is problematic if it's virtual because it has a slot in the vtable.

Tested on x86_64-suse-linux, applied on all active branches.


2019-04-09  Eric Botcazou  

c-family/
* c-ada-spec.c (print_destructor): Deal with deleting destructors.
(dump_ada_declaration) : Likewise.

-- 
Eric BotcazouIndex: c-ada-spec.c
===
--- c-ada-spec.c	(revision 270188)
+++ c-ada-spec.c	(working copy)
@@ -2676,6 +2676,8 @@ print_destructor (pretty_printer *buffer
   tree decl_name = DECL_NAME (TYPE_NAME (type));
 
   pp_string (buffer, "Delete_");
+  if (strncmp (IDENTIFIER_POINTER (DECL_NAME (t)), "__dt_del", 8) == 0)
+pp_string (buffer, "And_Free_");
   pp_ada_tree_identifier (buffer, decl_name, t, false);
 }
 
@@ -2946,9 +2948,10 @@ dump_ada_declaration (pretty_printer *bu
 	  if (DECL_ARTIFICIAL (t))
 	return 0;
 
-	  /* Only consider constructors/destructors for complete objects.  */
+	  /* Only consider complete constructors and deleting destructors.  */
 	  if (strncmp (IDENTIFIER_POINTER (decl_name), "__ct_comp", 9) != 0
-	  && strncmp (IDENTIFIER_POINTER (decl_name), "__dt_comp", 9) != 0)
+	  && strncmp (IDENTIFIER_POINTER (decl_name), "__dt_comp", 9) != 0
+	  && strncmp (IDENTIFIER_POINTER (decl_name), "__dt_del", 8) != 0)
 	return 0;
 	}
 


Re: [libphobos] Work around lack of dlpi_tls_modid before Solaris 11.5

2019-04-09 Thread Rainer Orth
Rainer Orth  writes:

> Before Solaris 11.5, struct dl_phdr_info lacked the dlpi_tls_modid
> member.  While the support might be backported to Solaris 11.4, it
> certainly won't to previous Solaris releases.  To work around this, I've
> used the following patch.  Again, it's pretty straightforward.
>
> Point of note:
>
> * On Solaris, FreeBSD and NetBSD, dl_phdr_info is always visible in
>   , while on Linux one needs to define _GNU_SOURCE.
>   AC_USE_SYSTEM_EXTENSION takes care of this, but needs to be called
>   early (i.e. not in DRUNTIME_OS_DLPI_TLS_MODID) to avoid an autoconf
>   warning:
>
> configure.ac:129: warning: AC_COMPILE_IFELSE was called before 
> AC_USE_SYSTEM_EXTENSIONS
> m4/druntime/os.m4:190: DRUNTIME_OS_DLPI_TLS_MODID is expanded from...
> configure.ac:129: the top level
>
> Tested on i386-pc-solaris2.11 (Solaris 11.4) and x86_64-pc-linux-gnu.
>
> Not unexpectedly, there are a couple of regressions compared to the
> Solaris 11.5/x86 results:
>
> +FAIL: gdc.test/runnable/testaa.d   execution test
> +FAIL: gdc.test/runnable/testaa.d -fPIC   execution test
> +FAIL: gdc.test/runnable/testaa.d -fPIC -shared-libphobos   execution test
> +FAIL: gdc.test/runnable/testaa.d -shared-libphobos   execution test
>
>   32 and 64-bit
>
> +FAIL: gdc.test/runnable/xtest55.d   execution test
> +FAIL: gdc.test/runnable/xtest55.d -shared-libphobos   execution test
>
>   64-bit only
>
> +FAIL: libphobos.shared/link_linkdep.d 
> -I/vol/gcc/src/hg/trunk/local/libphobos/t
> estsuite/libphobos.shared liblinkdep.so lib.so -shared-libphobos execution 
> test
>
> +FAIL: libphobos.shared/load_linkdep.d -shared-libphobos -ldl execution test
> +FAIL: libphobos.shared/load_loaddep.d -shared-libphobos -ldl execution test
>
> +FAIL: libphobos.shared/linkDR.c -shared-libphobos -ldl -pthread execution 
> test
> +FAIL: libphobos.shared/host.c -ldl -pthread execution test
> +FAIL: libphobos.shared/loadDR.c -ldl -pthread -g execution test
>
>   32 and 64-bit
>
> +FAIL: libphobos.shared/link.d 
> -I/vol/gcc/src/hg/trunk/local/libphobos/testsuite/libphobos.shared lib.so 
> -shared-libphobos execution test
>
>   64-bit only
>
> I haven't looked much closer yet, just posting this to see if anything
> along those lines could be acceptable at all.

Fortunately, Iain just discovered a way better way to work around the
lack of dlpi_tls_modid: dlinfo(RTLD_DI_LINKMAP) returns not only a
pointer to a Link_map * as documented in the man page, but rather a
pointer to a struct Rt_map which also includes a rt_tlsmodid member.
It has been this way since at least Solaris 9 and the Solaris/Illumos
sources ($SRC/cmd/sgs/include/rtld.h) explicitly have a comment around
the start of the structure stateing

Exposed to rtld_db - don't move, don't delete

which pretty much guarantees that this can be relied on.

The only other quirk of note is that before dlpi_tls_modid got added,
tlsmodid started at 0 for the main executable, not 1 as the glibc spec
required and libdruntime assumes.  I account for this by adjusting
_tlsMod on dlinfo and undoing the adjustment before passing it to
__tls_get_adddr, the only consumer.

With the revised patch below, I get clean gdc testresults on Solaris
11.3 and 11.4 (and still on 11.5 which uses the dlpi_tls_modid path),
and almost identical libphobos testresults on all three versions.

I hope this is good to go in (the sections_elf_shared.d part via
upstream, the rest directly) now?

Thanks a lot to Iain for discovering this.

Rainer

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


2019-01-22  Rainer Orth  
Iain Buclaw  

PR d/88150
* m4/druntime/os.m4 (DRUNTIME_OS_DLPI_TLS_MODID): New macro.
* configure.ac: Use it.
Call AC_USE_SYSTEM_EXTENSIONS.
* configure: Regenerate.
* Makefile.in, libdruntime/Makefile.in, src/Makefile.in,
testsuite/Makefile.in: Regenerate.
* libdruntime/gcc/config.d.in (OS_Have_Dlpi_Tls_Modid): Define.
* libdruntime/rt/sections_elf_shared.d (scanSegments) :
[OS_Have_Dlpi_Tls_Modid]: Use dlpi_tls_modid.
[Solaris]: Use dlinfo(RTLD_DI_LINKMAP) to get rt_tlsmodid.
Otherwise clear pdso._tlsMod, pdso._tlsSize.
(getTLSRange) [Solaris && !OS_Have_Dlpi_Tls_Modid]: Readjust mod.

# HG changeset patch
# Parent  3b397b651aecb48e300966e0d709ac6e5cf0c3b8
Work around lack of dlpi_tls_modid before Solaris 11.5

diff --git a/libphobos/configure.ac b/libphobos/configure.ac
--- a/libphobos/configure.ac
+++ b/libphobos/configure.ac
@@ -32,6 +32,7 @@ AC_CONFIG_HEADERS(config.h)
 
 AM_ENABLE_MULTILIB(, ..)
 AC_CANONICAL_SYSTEM
+AC_USE_SYSTEM_EXTENSIONS
 
 target_alias=${target_alias-$target}
 AC_SUBST(target_alias)
@@ -126,6 +127,7 @@ DRUNTIME_OS_SOURCES
 DRUNTIME_OS_THREAD_MODEL
 DRUNTIME_OS_ARM_EABI_UNWINDER
 DRUNTIME_OS_MINFO_BRACKETING
+DRUNTIME_OS_DLPI_TLS_MODID
 DRUNTIME_OS_LINK_SPEC
 

[PATCH 3/3] Add comments and style fixes to

2019-04-09 Thread Jonathan Wakely

* include/std/variant: Adjust whitespace. Add comments.
(_Multi_array): Leave primary template undefined.
(_Multi_array<_Tp>): Define partial specialization for base case of
recursion.
(__gen_vtable_impl, __gen_vtable): Remove redundant && from type
which is always a reference.
(__gen_vtable::_S_apply()): Remove function, inline body into
default member initializer.
* testsuite/20_util/variant/visit.cc: Test with noncopyable types.

Tested powerpc64le-linux, committed to trunk.


commit fa2a3fe062ea41d2545ee425cdf0816ee1bd6b36
Author: Jonathan Wakely 
Date:   Tue Apr 9 12:26:02 2019 +0100

Add comments and style fixes to 

* include/std/variant: Adjust whitespace. Add comments.
(_Multi_array): Leave primary template undefined.
(_Multi_array<_Tp>): Define partial specialization for base case of
recursion.
(__gen_vtable_impl, __gen_vtable): Remove redundant && from type
which is always a reference.
(__gen_vtable::_S_apply()): Remove function, inline body into
default member initializer.
* testsuite/20_util/variant/visit.cc: Test with noncopyable types.

diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 43e8d1d1706..22b0c3d5c22 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -145,7 +145,8 @@ namespace __variant
 __do_visit(_Visitor&& __visitor, _Variants&&... __variants);
 
   template 
-decltype(auto) __variant_cast(_Tp&& __rhs)
+decltype(auto)
+__variant_cast(_Tp&& __rhs)
 {
   if constexpr (is_lvalue_reference_v<_Tp>)
 	{
@@ -197,9 +198,10 @@ namespace __variant
 struct _Uninitialized<_Type, true>
 {
   template
-  constexpr _Uninitialized(in_place_index_t<0>, _Args&&... __args)
-  : _M_storage(std::forward<_Args>(__args)...)
-  { }
+	constexpr
+	_Uninitialized(in_place_index_t<0>, _Args&&... __args)
+	: _M_storage(std::forward<_Args>(__args)...)
+	{ }
 
   constexpr const _Type& _M_get() const &
   { return _M_storage; }
@@ -220,11 +222,12 @@ namespace __variant
 struct _Uninitialized<_Type, false>
 {
   template
-  constexpr _Uninitialized(in_place_index_t<0>, _Args&&... __args)
-  {
-	::new ((void*)std::addressof(_M_storage))
-	  _Type(std::forward<_Args>(__args)...);
-  }
+	constexpr
+	_Uninitialized(in_place_index_t<0>, _Args&&... __args)
+	{
+	  ::new ((void*)std::addressof(_M_storage))
+	_Type(std::forward<_Args>(__args)...);
+	}
 
   const _Type& _M_get() const &
   { return *_M_storage._M_ptr(); }
@@ -360,15 +363,14 @@ namespace __variant
 struct _Variant_storage;
 
   template 
-  using __select_index =
-typename __select_int::_Select_int_base::type::value_type;
+using __select_index =
+  typename __select_int::_Select_int_base::type::value_type;
 
   template
 struct _Variant_storage
 {
-
   constexpr _Variant_storage() : _M_index(variant_npos) { }
 
   template
@@ -387,7 +389,7 @@ namespace __variant
 	  std::_Destroy(std::__addressof(__this_mem));
 	return {};
 	  }, __variant_cast<_Types...>(*this));
-	}
+  }
 
   void _M_reset()
   {
@@ -472,7 +474,7 @@ namespace __variant
 		 -> __detail::__variant::__variant_cookie
 {
 	  __variant_construct_single(std::forward<_Tp>(__lhs),
- std::forward(__rhs_mem));
+	  std::forward( __rhs_mem));
 	  return {};
 	}, __variant_cast<_Types...>(std::forward(__rhs)));
 }
@@ -573,6 +575,7 @@ namespace __variant
 	  __variant_construct_single(*this,
  std::forward<_Up>(__rhs));
 	}
+
   template
 void _M_destructive_copy(unsigned short __rhs_index, const _Up& __rhs)
 {
@@ -708,8 +711,7 @@ namespace __variant
 
   template
 using _Move_assign_alias =
-	_Move_assign_base<_Traits<_Types...>::_S_trivial_move_assign,
-			  _Types...>;
+  _Move_assign_base<_Traits<_Types...>::_S_trivial_move_assign, _Types...>;
 
   template
 struct _Variant_base : _Move_assign_alias<_Types...>
@@ -812,9 +814,13 @@ namespace __variant
 	&& !_Variant_never_valueless<__remove_cvref_t<_Variant>>::value;
 };
 
-  // Used for storing multi-dimensional vtable.
+  // Used for storing a multi-dimensional vtable.
   template
-struct _Multi_array
+struct _Multi_array;
+
+  // Partial specialization with rank zero, stores a single _Tp element.
+  template
+struct _Multi_array<_Tp>
 {
   constexpr const _Tp&
   _M_access() const
@@ -823,6 +829,7 @@ namespace __variant
   _Tp _M_data;
 };
 
+  // Partial specialization with rank >= 1.
   template::type;
+
   static constexpr int __do_cookie =
 	_Extra_visit_slot_needed<_Ret, _Variant>::value ? 1 : 0;
+
   using _Tp = _Ret(*)(_Visitor, _Variants...);
+
   template
 	constexpr const _Tp&
 	_M_access(size_t __first_index, _Args... 

Re: [PATCH 2/3] Fix std::visit to support arbitrary callables

2019-04-09 Thread Jonathan Wakely

The __visitor_result_type helper didn't use std::invoke and so didn't
compile when the visitor was a pointer-to-member rather than a function
object. Use std::invoke_result instead.
   
	* include/std/variant (__variant_idx_cookie): Add member type.

(__visitor_result_type): Remove.
(__do_visit): Use invoke_result instead of __visitor_result_type.
* testsuite/20_util/variant/visit.cc: New test.

Tested powerpc64le-linux, committed to trunk.


commit d0166594867b89afa636b65f4dcd583f06f55220
Author: Jonathan Wakely 
Date:   Tue Apr 9 11:16:23 2019 +0100

Fix std::visit to support arbitrary callables

The __visitor_result_type helper didn't use std::invoke and so didn't
compile when the visitor was a pointer-to-member rather than a function
object. Use std::invoke_result instead.

* include/std/variant (__variant_idx_cookie): Add member type.
(__visitor_result_type): Remove.
(__do_visit): Use invoke_result instead of __visitor_result_type.
* testsuite/20_util/variant/visit.cc: New test.

diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 603b6be0934..43e8d1d1706 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -178,7 +178,7 @@ namespace __variant
   // used for raw visitation
   struct __variant_cookie {};
   // used for raw visitation with indices passed in
-  struct __variant_idx_cookie {};
+  struct __variant_idx_cookie { using type = __variant_idx_cookie; };
   // a more explanatory name than 'true'
   inline constexpr auto __visit_with_index = bool_constant{};
 
@@ -1613,27 +1613,18 @@ namespace __variant
   return __detail::__variant::__get<_Np>(std::move(__v));
 }
 
-  template
-decltype(auto)
-__visitor_result_type(_Visitor&& __visitor, _Variants&&... __variants)
-{
-  if constexpr(__use_index)
-return __detail::__variant::__variant_idx_cookie{};
-  else
-	return std::forward<_Visitor>(__visitor)(
-	  std::get<0>(std::forward<_Variants>(__variants))...);
-}
-
   template
 constexpr decltype(auto)
 __do_visit(_Visitor&& __visitor, _Variants&&... __variants)
 {
-  using _Result_type =
-	decltype(__visitor_result_type<__use_index>(
-	   std::forward<_Visitor>(__visitor),
-	   std::forward<_Variants>(__variants)...));
+  using _Deduced_type = std::invoke_result<_Visitor,
+	decltype(std::get<0>(std::declval<_Variants>()))...>;
+
+  using _Result_type = typename std::conditional_t<__use_index,
+	__detail::__variant::__variant_idx_cookie,
+	_Deduced_type>::type;
 
   constexpr auto& __vtable = __detail::__variant::__gen_vtable<
 	__same_return_types,
@@ -1663,7 +1654,6 @@ namespace __variant
   if ((__variants.valueless_by_exception() || ...))
 	__throw_bad_variant_access("Unexpected index");
 
-
   if constexpr (std::is_void_v<_Res>)
 (void) __do_visit(std::forward<_Visitor>(__visitor),
 	std::forward<_Variants>(__variants)...);
diff --git a/libstdc++-v3/testsuite/20_util/variant/visit.cc b/libstdc++-v3/testsuite/20_util/variant/visit.cc
new file mode 100644
index 000..5bd5b3d11f7
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/variant/visit.cc
@@ -0,0 +1,73 @@
+// Copyright (C) 2019 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++17 } }
+
+#include 
+#include 
+#include 
+
+// N.B. there are more std::visit tests in ./compile.cc and ./run.cc
+
+void
+test01()
+{
+  // Verify that visitation uses INVOKE and supports arbitrary callables.
+
+  struct X
+  {
+int sum(int i) const { return i + n; }
+int product(int i) const { return i * n; }
+int n;
+  };
+
+  std::variant> vobj{X{1}};
+  int res = std::visit(::n, vobj);
+  VERIFY( res == 1 );
+
+  std::variant varg{2};
+  res = std::visit(::sum, vobj, varg);
+  VERIFY( res == 3 );
+
+  X x{4};
+  vobj = 
+  res = std::visit(::n, vobj);
+  VERIFY( res == 4 );
+
+  varg.emplace(5);
+  res = std::visit(::sum, vobj, varg);
+  VERIFY( res == 9 );
+
+  x.n = 6;
+  res = std::visit(::product, vobj, varg);
+  VERIFY( res == 30 );
+
+  vobj = std::ref(x);
+  x.n = 7;
+  res = std::visit(::n, vobj);
+  VERIFY( res == 7 );
+

[PATCH 1/3] PR libstdc++/90008 remove unused capture from variant rel ops

2019-04-09 Thread Jonathan Wakely

PR libstdc++/90008
* include/std/variant (_VARIANT_RELATION_FUNCTION_TEMPLATE): Remove
unused capture.
* testsuite/20_util/variant/90008.cc: New test.

Teted powerpc64le-linux, committed to trunk.

commit 89a4191807ed2409f0e6f510ea8349392c43d9da
Author: Jonathan Wakely 
Date:   Tue Apr 9 09:36:29 2019 +0100

PR libstdc++/90008 remove unused capture from variant rel ops

PR libstdc++/90008
* include/std/variant (_VARIANT_RELATION_FUNCTION_TEMPLATE): Remove
unused capture.
* testsuite/20_util/variant/90008.cc: New test.

diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 7bab47231e7..603b6be0934 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -1160,7 +1160,7 @@ namespace __variant
 { \
   bool __ret = true; \
   __do_visit<__detail::__variant::__visit_with_index>( \
-[&__ret, &__lhs, __rhs] \
+[&__ret, &__lhs] \
 (auto&& __rhs_mem, auto __rhs_index) mutable \
   -> __detail::__variant::__variant_idx_cookie \
 { \
diff --git a/libstdc++-v3/testsuite/20_util/variant/90008.cc 
b/libstdc++-v3/testsuite/20_util/variant/90008.cc
new file mode 100644
index 000..53fd35db201
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/variant/90008.cc
@@ -0,0 +1,37 @@
+// Copyright (C) 2019 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 compile { target c++17 } }
+
+#include 
+
+struct NoCopy
+{
+  NoCopy();
+  NoCopy(const NoCopy&) = delete;
+};
+
+bool operator==(const NoCopy&, const NoCopy&);
+
+using V = std::variant;
+
+bool
+test01(const V& lhs, const V& rhs)
+{
+  return lhs == rhs;
+}


[PATCH, testsuite]: Fix FAIL: gcc.target/i386/ifcvt-onecmpl-abs-1.c scan-assembler cltd

2019-04-09 Thread Uros Bizjak
Look for a message of a successful ifcvt in the relevant RTL dump
instead of scanning asm dump.

2019-04-09  Uroš Bizjak  

* gcc.target/i386/ifcvt-onecmpl-abs-1.c
(dg-options): Use -O2 -fdump-rtl-ce1.
(dg-final): Scan ce1 RTL dump instead of asm dump.

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

Uros.
Index: gcc.target/i386/ifcvt-onecmpl-abs-1.c
===
--- gcc.target/i386/ifcvt-onecmpl-abs-1.c   (revision 270230)
+++ gcc.target/i386/ifcvt-onecmpl-abs-1.c   (working copy)
@@ -1,9 +1,5 @@
 /* { dg-do compile } */
-/* This test checks for if-conversion of one's complement
- * abs function.  */
-/* { dg-options "-O -mtune=generic" } */
-/* { dg-final { scan-assembler "cltd" } } */
-/* { dg-final { scan-assembler "xor" } } */
+/* { dg-options "-O2 -fdump-rtl-ce1" } */
 
 /* Check code generation for one's complement version of abs */
 
@@ -13,3 +9,5 @@ int onecmplabs(int x)
 x = ~x;
   return x;
 }
+
+/* { dg-final { scan-rtl-dump "succeeded through noce_try_abs" "ce1" } } */


Re: [PATCH] [ARC] PR 88409: miscompilation due to missing cc clobber in longlong.h macros

2019-04-09 Thread Claudiu Zissulescu
Done.

On Wed, Apr 3, 2019 at 8:28 PM Vineet Gupta  wrote:
>
> On 4/3/19 2:53 AM, Claudiu Zissulescu wrote:
> > Pushed, thank you for your contribution,
> > Claudiu
>
> Thx, can this be backported to gcc-8-stable please which is what glibc folks 
> use
> for testing !
>
> -Vineet
>
> >
> > On Tue, Apr 2, 2019 at 9:27 PM Vineet Gupta  
> > wrote:
> >> simple test such as below was failing.
> >>
> >> | void main(int argc, char *argv[])
> >> | {
> >> |size_t total_time = 115424;   // expected 115.424
> >> |double secs = (double)total_time/(double)1000;
> >> |printf("%s %d %lf\n", "secs", total_time, secs);  // prints 113.504
> >> |printf("%d\n", (size_t)secs);
> >> | }
> >>
> >> The printf eventually called into glibc stdlib/divrem.c:__mpn_divrem()
> >> which uses the __arc__ specific inline asm macros from longlong.h which
> >> were causing miscompilation.
> >>
> >> include/
> >> 2019-03-28  Vineet Gupta 
> >>
> >> PR 89877
> >>
> >> * longlong.h [__arc__] (add_ss): Add cc clobber
> >> (sub_ddmmss): Likewise.
> >>
> >> Signed-off-by: Vineet Gupta 
> >> ---
> >>  include/ChangeLog  | 7 +++
> >>  include/longlong.h | 6 --
> >>  2 files changed, 11 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/include/ChangeLog b/include/ChangeLog
> >> index be08141deeb9..96d967d10a52 100644
> >> --- a/include/ChangeLog
> >> +++ b/include/ChangeLog
> >> @@ -1,3 +1,10 @@
> >> +2019-03-28  Vineet Gupta 
> >> +
> >> +   PR 89877
> >> +
> >> +   * longlong.h [__arc__] (add_ss): Add cc clobber
> >> +   (sub_ddmmss): Likewise.
> >> +
> >>  2019-02-11  Philippe Waroquiers  
> >>
> >> * splay-tree.h (splay_tree_delete_key_fn): Update comment.
> >> diff --git a/include/longlong.h b/include/longlong.h
> >> index 3dd8dc3aa80c..1f0ce4204255 100644
> >> --- a/include/longlong.h
> >> +++ b/include/longlong.h
> >> @@ -199,7 +199,8 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, 
> >> UDItype, UDItype);
> >>: "%r" ((USItype) (ah)), \
> >>  "rICal" ((USItype) (bh)),  \
> >>  "%r" ((USItype) (al)), \
> >> -"rICal" ((USItype) (bl)))
> >> +"rICal" ((USItype) (bl))   \
> >> +  : "cc")
> >>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
> >>__asm__ ("sub.f  %1, %4, %5\n\tsbc   %0, %2, %3" \
> >>: "=r" ((USItype) (sh)), \
> >> @@ -207,7 +208,8 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, 
> >> UDItype, UDItype);
> >>: "r" ((USItype) (ah)),  \
> >>  "rICal" ((USItype) (bh)),  \
> >>  "r" ((USItype) (al)),  \
> >> -"rICal" ((USItype) (bl)))
> >> +"rICal" ((USItype) (bl))   \
> >> +  : "cc")
> >>
> >>  #define __umulsidi3(u,v) ((UDItype)(USItype)u*(USItype)v)
> >>  #ifdef __ARC_NORM__
> >> --
> >> 2.7.4
> >>
>


Re: [PATCH] D support for RISC-V

2019-04-09 Thread Iain Buclaw
On Tue, 9 Apr 2019 at 11:53, David Abdurachmanov
 wrote:
>
> This patch has been in Fedora/RISCV for the last couple of months.
> I have tested simple applications (e.g. word count example), which
> worked without a problem.
>
> I believe Iain Buclaw did run GCC testsuite using Fedora/RISCV
> build and QEMU. The patch has not changed since that.
>

I've got a change in method to the way the unittests are ran, I'll
re-run with that and check the results.

> @@ -671,7 +674,16 @@ version (Shared)
>  if (dyn.d_tag == DT_STRTAB)
>  {
>  version (linux)
> -strtab = cast(const(char)*)dyn.d_un.d_ptr;
> +{
> +// This might change in future glibc releases (after 
> 2.29) as dynamic sections
> +// are not required to be read-only on RISC-V. This was 
> copy & pasted from MIPS while
> +// upstreaming RISC-V support. Otherwise MIPS is the 
> only arch which sets in glibc:
> +// #define DL_RO_DYN_SECTION 1
> +version (RISCV_Any)
> +strtab = cast(const(char)*)(info.dlpi_addr + 
> dyn.d_un.d_ptr); // relocate

I guess we'll pre-emptively need to add MIPS_Any here as well.

> diff --git 
> a/libphobos/src/std/experimental/allocator/building_blocks/region.d 
> b/libphobos/src/std/experimental/allocator/building_blocks/region.d
> index dfcecce72bd..cafe059a61f 100644
> --- a/libphobos/src/std/experimental/allocator/building_blocks/region.d
> +++ b/libphobos/src/std/experimental/allocator/building_blocks/region.d
> @@ -391,7 +391,8 @@ struct InSituRegion(size_t size, size_t minAlign = 
> platformAlignment)
>  else version (PPC) enum growDownwards = Yes.growDownwards;
>  else version (PPC64) enum growDownwards = Yes.growDownwards;
>  else version (MIPS32) enum growDownwards = Yes.growDownwards;
> -else version (MIPS64) enum growDownwards = Yes.growDownwards;
> +else version (RISCV32) enum growDownwards = Yes.growDownwards;
> +else version (RISCV64) enum growDownwards = Yes.growDownwards;
>  else version (SPARC) enum growDownwards = Yes.growDownwards;
>  else version (SystemZ) enum growDownwards = Yes.growDownwards;
>  else static assert(0, "Dunno how the stack grows on this architecture.");
> diff --git a/libphobos/src/std/math.d b/libphobos/src/std/math.d
> index e98e746a856..9fe746501a4 100644
> --- a/libphobos/src/std/math.d
> +++ b/libphobos/src/std/math.d
> @@ -162,6 +162,8 @@ version (AArch64)   version = ARM_Any;
>  version (ARM)   version = ARM_Any;
>  version (SPARC) version = SPARC_Any;
>  version (SPARC64)   version = SPARC_Any;
> +version (RISCV32)   version = RISCV_Any;
> +version (RISCV64)   version = RISCV_Any;
>

Any objection if I upstream the non-asm bits?

-- 
Iain


Merge from trunk to gccgo branch

2019-04-09 Thread Ian Lance Taylor
I merged trunk revision 270220 to the gccgo branch.

Ian


Re: [Patch, fortran] PRs 89843 and 90022 - C Fortran Interop fixes.

2019-04-09 Thread Dominique d'Humières
Hi Paul,

With your patch the test gfortran.dg/ISO_Fortran_binding_9.f90 fails in the 32 
bit mode, due to the errors

/opt/gcc/work/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.f90:24:6: Error: 
Type mismatch in argument 'expected' at (1); passed INTEGER(4) to INTEGER(8)
/opt/gcc/work/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.f90:25:6: Error: 
Type mismatch in argument 'expected' at (1); passed INTEGER(4) to INTEGER(8)
/opt/gcc/work/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.f90:26:6: Error: 
Type mismatch in argument 'expected' at (1); passed INTEGER(4) to INTEGER(8)
/opt/gcc/work/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.f90:27:6: Error: 
Type mismatch in argument 'expected' at (1); passed INTEGER(4) to INTEGER(8)

Note that LOC is a gnu extension.

The patch also fixes pr89846 for -m64, but not for -m32

% gfc pr89846.c pr89846.f90 -m32
% a.out
 FAIL 2: 
 FAIL 4: 
% gfc pr89846.c pr89846.f90 
% a.out
 OK
 OK

TIA

Dominique



Re: [PATCH] netbsd EABI support

2019-04-09 Thread Richard Earnshaw (lists)
On 09/04/2019 16:04, Jeff Law wrote:
> On 4/8/19 9:17 AM, co...@sdf.org wrote:
>> Pinging again in the hope of getting the patch in, I'd like to have
>> less outstanding patches :) (I have quite a few and new releases
>> can become painful!)
>>
>> gcc/ChangeLog
>>
>> config.gcc (arm*-*-netbsdelf*) Add support for EABI configuration
>> config.host (arm*-*-netbsd*): Build driver-arm.o
>> config/arm/netbsd-eabi.h: New file.
>> config/arm/netbsd-elf.h
>> config/netbsd-elf.h: Define SUBTARGET_EXTRA_SPECS.
>>
>> libgcc/ChangeLog
>>
>> config.host (arm*-*-netbsdelf*): Add support for EABI configuration
>> config/arm/t-netbsd: LIB1ASMFUNCS: Append to existing set.
>>   HOST_LIBGCC2_CFLAGS: workaround possible bug
>> config/arm/t-netbsd-eabi: New file.
> So we're well into stage4 which means technically it's too late for
> something like this.  However, given it's limited scope I won't object
> if the ARM port maintainers want to go forward.  Otherwise I'll queue it
> for gcc-10.
> 
> jeff
> 

I was about to approve this (modulo removing the now obsolete
FPU_DEFAULT macro), until I noticed that it also modifies the generic
NetBSD code as well.  I'm certainly not willing to approve that myself
at this late stage, but if one of the NetBSD OS maintainers wants to
step up and do so, I'll happily take the Arm back-end code as that's not
a primary or secondary target.

R.


Negative arguments in OpenMP 'num_threads' clause etc. (was: [Patch 4/5] OpenACC tile clause support, Fortran front-end parts)

2019-04-09 Thread Thomas Schwinge
Hi Jakub!

On Tue, 29 Nov 2016 17:47:08 -0800, Cesar Philippidis  
wrote:
> One notable difference between the trunk and gomp4 implementation of the
> tile clause is that gomp4 errors on negative value tile arguments,
> whereas trunk issues warnings.

I'm picking up these changes, which have been posted a few times, and
have been rejected (at least in their current incarnation) a few times,
too.  ;-\

> Is there a reason why the fortran FE
> generally emits a warning, on say num_threads(-5), instead of an error?

Same for the C/C++ front ends, which I'm looking into first.

Jakub, is the reason that even if the user is clearly doing something
"strage" there, the compiler doesn't have a problem to continue
compilation for 'num_threads(-5)', so it just emits a warning, but for
example for 'collapse(-5)' is has to stop with an error, because it can't
continue compilation in that case?  Or, is there a different reason for
the many 'warning_at ([...], "[...] must be positive"' (C front end, for
example), instead of using 'error_at' for these?


Grüße
 Thomas


signature.asc
Description: PGP signature


[PATCH] S/390: Fix PR89952 incorrect CFI

2019-04-09 Thread Andreas Krebbel
This patch fixes a cases where inconsistent CFI is generated.

After restoring the hard frame pointer (r11) from an FPR we have to
set the CFA register.  In order to be able to set it back to the stack
pointer (r15) we have to make sure that r15 has been restored already.

gcc/ChangeLog:

2019-04-09  Andreas Krebbel  

PR target/89952
* config/s390/s390.c (s390_restore_gprs_from_fprs): Restore GPRs
from FPRs in reverse order.  Generate REG_CFA_DEF_CFA note also
for restored hard frame pointer.

gcc/testsuite/ChangeLog:

2019-04-09  Andreas Krebbel  

PR target/89952
* gcc.target/s390/pr89952.c: New test.
---
 gcc/config/s390/s390.c  | 14 --
 gcc/testsuite/gcc.target/s390/pr89952.c | 12 
 2 files changed, 24 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/s390/pr89952.c

diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index e0b62b7..e95ea5b 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -10685,7 +10685,11 @@ s390_restore_gprs_from_fprs (void)
   if (!TARGET_Z10 || !TARGET_HARD_FLOAT || !crtl->is_leaf)
 return;
 
-  for (i = 6; i < 16; i++)
+  /* Restore the GPRs starting with the stack pointer.  That way the
+ stack pointer already has its original value when it comes to
+ restoring the hard frame pointer.  So we can set the cfa reg back
+ to the stack pointer.  */
+  for (i = STACK_POINTER_REGNUM; i >= 6; i--)
 {
   rtx_insn *insn;
 
@@ -10701,7 +10705,13 @@ s390_restore_gprs_from_fprs (void)
 
   df_set_regs_ever_live (i, true);
   add_reg_note (insn, REG_CFA_RESTORE, gen_rtx_REG (DImode, i));
-  if (i == STACK_POINTER_REGNUM)
+
+  /* If either the stack pointer or the frame pointer get restored
+set the CFA value to its value at function start.  Doing this
+for the frame pointer results in .cfi_def_cfa_register 15
+what is ok since if the stack pointer got modified it has
+been restored already.  */
+  if (i == STACK_POINTER_REGNUM || i == HARD_FRAME_POINTER_REGNUM)
add_reg_note (insn, REG_CFA_DEF_CFA,
  plus_constant (Pmode, stack_pointer_rtx,
 STACK_POINTER_OFFSET));
diff --git a/gcc/testsuite/gcc.target/s390/pr89952.c 
b/gcc/testsuite/gcc.target/s390/pr89952.c
new file mode 100644
index 000..9f48e08
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/pr89952.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-march=zEC12 -fno-omit-frame-pointer -Os" } */
+
+
+extern void j(int);
+
+void
+d(int e, long f, int g, int h, int i) {
+  if (h == 5 && i >= 4 && i <= 7)
+h = e;
+  j(h);
+}
-- 
2.7.4



Re: RFA: Fix uninitialized memory use in sched_macro_fuse_insns

2019-04-09 Thread Jeff Law
On 4/5/19 8:47 AM, Richard Sandiford wrote:
> Joern Rennecke  writes:
>> On Fri, 5 Apr 2019 at 11:07, Richard Sandiford
>>  wrote:
>>
>>
 2019-04-04  Joern Rennecke  

   * sched-deps.c (sched_macro_fuse_insns): Check return value of
   targetm.fixed_condition_code_regs.
>>>
>>> OK, thanks.
>>
>> Thanks for the review.
>>
>> Is that OK restricted to delayed applying once the gcc 9 branch has
>> been cut and gcc 10 stage 1 opened (because the bug is not a
>> regression unless going back to 2013)
>> or also OK to apply to the current 9.0.0 trunk (since this should be a
>> safe patch and leaving the bug in might hinder debugging to find
>> actual regressions) ?
> 
> OK now IMO.  A regression from 2013 is still a regression, and like
> you say, it should be very safe.  I think arm is the only affected
> in-tree port, and it's only going to help there.
Agreed.  Even if we didn't have an active regression, this kind of error
is painful enough to debug that I'd rather have it squashed now :-)

jeff


Re: [PATCH] claim ifunc support on several NetBSD architectures

2019-04-09 Thread Jeff Law
On 4/7/19 7:31 AM, co...@sdf.org wrote:
> architecture list from netbsd src/tests/libexec/ld.elf_so/t_ifunc.c
> (quick reference: 
> https://github.com/NetBSD/src/blob/trunk/tests/libexec/ld.elf_so/t_ifunc.c#L38
>  )
> tested on netbsd/amd64.
> 
> ifuncs worked anyway, but I can't use target_clones without this change.
> that is one very cool feature I'd like to use :)
> 
> gcc/ChangeLog:
> 2019-04-07Maya Rashish
>   * config.gcc (default_gnu_indirect_function): Default to yes
>   for arm*-*-netbsd*, i[34567]86-*-netbsd*, powerpc*-*-netbsd*,
>   sparc*-*-netbsd*, x86_64-*-netbsd*
This falls into a similar bucket as the prior patch -- though I'm not
sure if we've got anyone that can say conclusively that all the
supported NetBSD releases have ifuncs.   I'd prefer to defer this to gcc-10.

jeff


Re: [PATCH] netbsd EABI support

2019-04-09 Thread Jeff Law
On 4/8/19 9:17 AM, co...@sdf.org wrote:
> Pinging again in the hope of getting the patch in, I'd like to have
> less outstanding patches :) (I have quite a few and new releases
> can become painful!)
> 
> gcc/ChangeLog
> 
> config.gcc (arm*-*-netbsdelf*) Add support for EABI configuration
> config.host (arm*-*-netbsd*): Build driver-arm.o
> config/arm/netbsd-eabi.h: New file.
> config/arm/netbsd-elf.h
> config/netbsd-elf.h: Define SUBTARGET_EXTRA_SPECS.
> 
> libgcc/ChangeLog
> 
> config.host (arm*-*-netbsdelf*): Add support for EABI configuration
> config/arm/t-netbsd: LIB1ASMFUNCS: Append to existing set.
>HOST_LIBGCC2_CFLAGS: workaround possible bug
> config/arm/t-netbsd-eabi: New file.
So we're well into stage4 which means technically it's too late for
something like this.  However, given it's limited scope I won't object
if the ARM port maintainers want to go forward.  Otherwise I'll queue it
for gcc-10.

jeff


[PATCH] Fix PR90020

2019-04-09 Thread Richard Biener


This fixes issues in GIMPLE and RTL code-hoisting which ignore
const/pure calls when determining whether it is safe to hoist
a possibly trapping memory reference across it.

The GIMPLE side of the fix handles this similar to regular
operations where we avoid hoisting possibly trapping ones
over a call that might not return.

The RTL side of the fix makes sure to not handle
RTL_LOOPING_CONST_OR_PURE_CALL_P like pure or const calls
but mark blocks with such calls in block_with_calls.

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

Richard.

2019-04-09  Richard Biener  

PR tree-optimization/90020
* tree-ssa-sccvn.c (vn_reference_may_trap): New function.
* tree-ssa-sccvn.h (vn_reference_may_trap): Declare.
* tree-ssa-pre.c (compute_avail): Use it to not put
possibly trapping references after a call that might not
return into EXP_GEN.
* gcse.c (compute_hash_table_work): Do not elide
marking a block containing a call if the call might not
return.

* gcc.dg/torture/pr90020.c: New testcase.

Index: gcc/tree-ssa-sccvn.c
===
--- gcc/tree-ssa-sccvn.c(revision 270223)
+++ gcc/tree-ssa-sccvn.c(working copy)
@@ -4766,6 +4766,57 @@ vn_nary_may_trap (vn_nary_op_t nary)
   return false;
 }
 
+/* Return true if the reference operation REF may trap.  */
+
+bool
+vn_reference_may_trap (vn_reference_t ref)
+{
+  switch (ref->operands[0].opcode)
+{
+case MODIFY_EXPR:
+case CALL_EXPR:
+  /* We do not handle calls.  */
+case ADDR_EXPR:
+  /* And toplevel address computations never trap.  */
+  return false;
+default:;
+}
+
+  vn_reference_op_t op;
+  unsigned i;
+  FOR_EACH_VEC_ELT (ref->operands, i, op)
+{
+  switch (op->opcode)
+   {
+   case WITH_SIZE_EXPR:
+   case TARGET_MEM_REF:
+ /* Always variable.  */
+ return true;
+   case COMPONENT_REF:
+ if (op->op1 && TREE_CODE (op->op1) == SSA_NAME)
+   return true;
+ break;
+   case ARRAY_RANGE_REF:
+   case ARRAY_REF:
+ if (TREE_CODE (op->op0) == SSA_NAME)
+   return true;
+ break;
+   case MEM_REF:
+ /* Nothing interesting in itself, the base is separate.  */
+ break;
+   /* The following are the address bases.  */
+   case SSA_NAME:
+ return true;
+   case ADDR_EXPR:
+ if (op->op0)
+   return tree_could_trap_p (TREE_OPERAND (op->op0, 0));
+ return false;
+   default:;
+   }
+}
+  return false;
+}
+
 eliminate_dom_walker::eliminate_dom_walker (cdi_direction direction,
bitmap inserted_exprs_)
   : dom_walker (direction), do_pre (inserted_exprs_ != NULL),
Index: gcc/tree-ssa-sccvn.h
===
--- gcc/tree-ssa-sccvn.h(revision 270223)
+++ gcc/tree-ssa-sccvn.h(working copy)
@@ -243,6 +243,7 @@ vn_reference_t vn_reference_insert_piece
 bool vn_nary_op_eq (const_vn_nary_op_t const vno1,
const_vn_nary_op_t const vno2);
 bool vn_nary_may_trap (vn_nary_op_t);
+bool vn_reference_may_trap (vn_reference_t);
 bool vn_reference_eq (const_vn_reference_t const, const_vn_reference_t const);
 unsigned int get_max_value_id (void);
 unsigned int get_next_value_id (void);
Index: gcc/tree-ssa-pre.c
===
--- gcc/tree-ssa-pre.c  (revision 270223)
+++ gcc/tree-ssa-pre.c  (working copy)
@@ -3931,6 +3931,13 @@ compute_avail (void)
  continue;
}
 
+ /* If the REFERENCE traps and there was a preceding
+point in the block that might not return avoid
+adding the reference to EXP_GEN.  */
+ if (BB_MAY_NOTRETURN (block)
+ && vn_reference_may_trap (ref))
+   continue;
+
  /* If the value of the reference is not invalidated in
 this block until it is computed, add the expression
 to EXP_GEN.  */
Index: gcc/gcse.c
===
--- gcc/gcse.c  (revision 270223)
+++ gcc/gcse.c  (working copy)
@@ -1532,7 +1532,8 @@ compute_hash_table_work (struct gcse_has
  0, regno, hrsi)
record_last_reg_set_info (insn, regno);
 
- if (! RTL_CONST_OR_PURE_CALL_P (insn))
+ if (! RTL_CONST_OR_PURE_CALL_P (insn)
+ || RTL_LOOPING_CONST_OR_PURE_CALL_P (insn))
record_last_mem_set_info (insn);
}
 
Index: gcc/testsuite/gcc.dg/torture/pr90020.c
===
--- 

[PATCH] Remove unused DR_GROUP_SAME_DR_STMT

2019-04-09 Thread Richard Biener


While looking at PR90018 I figured DR_GROUP_SAME_DR_STMT is never
set since GCC 4.9.  The following removes it to confuse the
occasional reader of the vectorizer code less.

Bootstrap / regtest in progress on x86_64-unknown-linux-gnu.

Richard.

2019-04-09  Richard Biener  

* tree-vectorizer.h (_stmt_vec_info): Remove same_dr_stmt
member.
(DR_GROUP_SAME_DR_STMT): Remove.
* tree-vect-stmts.c (vectorizable_load): Remove unreachable code.
* tree-vect-data-refs.c (vect_analyze_group_access_1): Likewise,
replace with assert.
(vect_record_grouped_load_vectors): Remove unreachable code.

Index: gcc/tree-vectorizer.h
===
--- gcc/tree-vectorizer.h   (revision 270223)
+++ gcc/tree-vectorizer.h   (working copy)
@@ -872,9 +872,6 @@ struct _stmt_vec_info {
   stmt_vec_info first_element;
   /* Pointer to the next element in the group.  */
   stmt_vec_info next_element;
-  /* For data-refs, in case that two or more stmts share data-ref, this is the
- pointer to the previously detected stmt with the same dr.  */
-  stmt_vec_info same_dr_stmt;
   /* The size of the group.  */
   unsigned int size;
   /* For stores, number of stores from this group seen. We vectorize the last
@@ -1044,8 +1041,6 @@ STMT_VINFO_BB_VINFO (stmt_vec_info stmt_
   (gcc_checking_assert ((S)->dr_aux.dr), (S)->store_count)
 #define DR_GROUP_GAP(S) \
   (gcc_checking_assert ((S)->dr_aux.dr), (S)->gap)
-#define DR_GROUP_SAME_DR_STMT(S) \
-  (gcc_checking_assert ((S)->dr_aux.dr), (S)->same_dr_stmt)
 
 #define REDUC_GROUP_FIRST_ELEMENT(S) \
   (gcc_checking_assert (!(S)->dr_aux.dr), (S)->first_element)
Index: gcc/tree-vect-stmts.c
===
--- gcc/tree-vect-stmts.c   (revision 270223)
+++ gcc/tree-vect-stmts.c   (working copy)
@@ -7704,19 +7727,6 @@ vectorizable_load (stmt_vec_info stmt_in
 "group loads with negative dependence distance\n");
  return false;
}
-
-  /* Similarly when the stmt is a load that is both part of a SLP
- instance and a loop vectorized stmt via the same-dr mechanism
-we have to give up.  */
-  if (DR_GROUP_SAME_DR_STMT (stmt_info)
- && (STMT_SLP_TYPE (stmt_info)
- != STMT_SLP_TYPE (DR_GROUP_SAME_DR_STMT (stmt_info
-   {
- if (dump_enabled_p ())
-   dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
-"conflicting SLP types for CSEd load\n");
- return false;
-   }
 }
   else
 group_size = 1;
Index: gcc/tree-vect-data-refs.c
===
--- gcc/tree-vect-data-refs.c   (revision 270223)
+++ gcc/tree-vect-data-refs.c   (working copy)
@@ -2529,32 +2529,9 @@ vect_analyze_group_access_1 (dr_vec_info
   /* By construction, all group members have INTEGER_CST DR_INITs.  */
   while (next)
 {
-  /* Skip same data-refs.  In case that two or more stmts share
- data-ref (supported only for loads), we vectorize only the first
- stmt, and the rest get their vectorized loads from the first
- one.  */
-  if (!tree_int_cst_compare (DR_INIT (data_ref),
-DR_INIT (STMT_VINFO_DATA_REF (next
-{
-  if (DR_IS_WRITE (data_ref))
-{
-  if (dump_enabled_p ())
-dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
- "Two store stmts share the same dr.\n");
-  return false;
-}
-
- if (dump_enabled_p ())
-   dump_printf_loc (MSG_NOTE, vect_location,
-"Two or more load stmts share the same dr.\n");
-
- /* For load use the same data-ref load.  */
- DR_GROUP_SAME_DR_STMT (next) = prev;
-
- prev = next;
- next = DR_GROUP_NEXT_ELEMENT (next);
- continue;
-}
+  /* We never have the same DR multiple times.  */
+  gcc_assert (tree_int_cst_compare (DR_INIT (data_ref),
+   DR_INIT (STMT_VINFO_DATA_REF (next))) != 0);
 
  prev = next;
  data_ref = STMT_VINFO_DATA_REF (next);
@@ -6329,12 +6306,14 @@ vect_record_grouped_load_vectors (stmt_v
correspond to the gaps.  */
   if (next_stmt_info != first_stmt_info
  && gap_count < DR_GROUP_GAP (next_stmt_info))
-  {
-gap_count++;
-continue;
-  }
+   {
+ gap_count++;
+ continue;
+   }
 
-  while (next_stmt_info)
+  /* ???  The following needs cleanup after the removal of
+ DR_GROUP_SAME_DR_STMT.  */
+  if (next_stmt_info)
 {
  stmt_vec_info new_stmt_info = vinfo->lookup_def 

Re: [PATCH] Remove some further trailing whitespaces from diagnostic messages (PR translation/90011)

2019-04-09 Thread Jakub Jelinek
On Tue, Apr 09, 2019 at 10:05:00AM -0400, David Malcolm wrote:
> > Thinking aloud, maybe c-format.c could check for some of
> > these?  (provided they're at a suitable callsite).
> > 
> > We're already statically checking for valid format codes/types for
> > strings at callsites of decls with ATTRIBUTE_GCC_DIAG; maybe that
> > test
> > could also check for things like trailing whitespace within the
> > string?
> > 
> > Wouldn't help for the LINK_SPEC things, though.
> 
> FWIW, I *think* the substring location stuff retains enough information
> for such an extension of c-format.c to detect bad concatenation cases
> like:
> 
> "word"
> "another word"

I guess you're right.  The question is if something like this would be
useful even for other users.  In that case, as a style warning, it probably
shouldn't be in -Wall or -Wextra (talking about the no or double spaces on
string concatenations from separate lines).
For the no period at the end of diagnostics it would need to be keyed on
gcc-internal-format only of course.

Jakub


Re: [PATCH] Remove some further trailing whitespaces from diagnostic messages (PR translation/90011)

2019-04-09 Thread David Malcolm
On Tue, 2019-04-09 at 10:01 -0400, David Malcolm wrote:
> On Tue, 2019-04-09 at 09:21 +0200, Jakub Jelinek wrote:
> > Hi!
> > 
> > Several further spots with trailing whitespace, only
> > bootstrapped/regtested
> > on x86_64-linux and i686-linux (so the ipa-devirt.c change is
> > covered),
> > the rest is just by eyeballing gcc.pot.
> > 
> > Ok for trunk?
> > 
> > I wonder where and how we could check for this kind of errors,
> > unfortunately
> > the strings are extracted by xgettext which we can't easily patch
> > for
> > our
> > purposes (say to emit warnings about
> > "word"
> > "another word"
> > or
> > "word "
> > " another word"
> > or for this trailing whitespace (this one could be done even on
> > gcc.pot itself
> > by looking for ' "\nmsgstr', but unfortunately we have various
> > cases
> > where
> > we intentionally do want those: one category is usually when it
> > ends
> > with
> > ": ", like:
> > msgid "invalid 'asm': "
> > msgstr ""
> > (many cases), but there are even
> > "Go ahead? (y or n) "
> > msgstr ""
> > or
> > msgid "The following options are specific to just the language "
> > msgstr ""
> > "%s\tcompiled by GNU C version %s, "
> > msgstr ""
> > msgid "vtable for "
> > msgstr ""
> > msgid "%r%s:%d:%d:%R   "
> > msgstr ""
> > etc., so it is hard to do this programmatically, unless we had some
> > white
> > list.
> 
> 
> Thinking aloud, maybe c-format.c could check for some of
> these?  (provided they're at a suitable callsite).
> 
> We're already statically checking for valid format codes/types for
> strings at callsites of decls with ATTRIBUTE_GCC_DIAG; maybe that
> test
> could also check for things like trailing whitespace within the
> string?
> 
> Wouldn't help for the LINK_SPEC things, though.

FWIW, I *think* the substring location stuff retains enough information
for such an extension of c-format.c to detect bad concatenation cases
like:

"word"
"another word"

> 
> Dave
> 
> [...snip...]


Re: [PATCH] Remove some further trailing whitespaces from diagnostic messages (PR translation/90011)

2019-04-09 Thread David Malcolm
On Tue, 2019-04-09 at 09:21 +0200, Jakub Jelinek wrote:
> Hi!
> 
> Several further spots with trailing whitespace, only
> bootstrapped/regtested
> on x86_64-linux and i686-linux (so the ipa-devirt.c change is
> covered),
> the rest is just by eyeballing gcc.pot.
> 
> Ok for trunk?
> 
> I wonder where and how we could check for this kind of errors,
> unfortunately
> the strings are extracted by xgettext which we can't easily patch for
> our
> purposes (say to emit warnings about
> "word"
> "another word"
> or
> "word "
> " another word"
> or for this trailing whitespace (this one could be done even on
> gcc.pot itself
> by looking for ' "\nmsgstr', but unfortunately we have various cases
> where
> we intentionally do want those: one category is usually when it ends
> with
> ": ", like:
> msgid "invalid 'asm': "
> msgstr ""
> (many cases), but there are even
> "Go ahead? (y or n) "
> msgstr ""
> or
> msgid "The following options are specific to just the language "
> msgstr ""
> "%s\tcompiled by GNU C version %s, "
> msgstr ""
> msgid "vtable for "
> msgstr ""
> msgid "%r%s:%d:%d:%R   "
> msgstr ""
> etc., so it is hard to do this programmatically, unless we had some
> white
> list.


Thinking aloud, maybe c-format.c could check for some of
these?  (provided they're at a suitable callsite).

We're already statically checking for valid format codes/types for
strings at callsites of decls with ATTRIBUTE_GCC_DIAG; maybe that test
could also check for things like trailing whitespace within the string?

Wouldn't help for the LINK_SPEC things, though.

Dave

[...snip...]


Re: [PATCH][stage1] Support profile (BB counts and edge probabilities) in GIMPLE FE.

2019-04-09 Thread Jan Hubicka
> Hi.
> 
> There's updated version that supports profile quality for both counts
> and probabilities. I'm wondering whether ENTRY and EXIT BBs needs to
> have set probability. Apparently, I haven't seen any verifier that
> would complain.

Well, you do not need to define it but then several cases will
degenerate. In particular BB frequencies (for callgraph profile or
hot/cold decisions) are calculated as ratios of entry BB and given BB
count. If entry BB is undefined you will get those undefined and
heuristics will resort to conservative answers.

I do not think we use exit block count.

Honza


Re: [C++ PATCH] Remove trailing space from diagnostics for narrowing conv (PR translation/90011)

2019-04-09 Thread Marek Polacek
On Tue, Apr 09, 2019 at 09:09:55AM +0200, Jakub Jelinek wrote:
> Hi!
> 
> In r263523 check_narrowing changed in this spot:
> pedwarn (loc, OPT_Wnarrowing,
> -"narrowing conversion of %qE from %qH to %qI "
> -"inside { }", init, ftype, type);
> +"narrowing conversion of %qE from %qH to %qI ",
> +init, ftype, type);
> where the trailing space on one line was desirable before to separate
> %qI from inside { }, but now it doesn't make sense.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> 2019-04-09  Jakub Jelinek  
> 
>   PR translation/90011
>   * typeck2.c (check_narrowing): Remove trailing space from diagnostics.

I think this is obvious :).

Marek


[PATCH, rs6000] PR87532: Bad results from vec_extract (unsigned char, foo) dependent upon function inline

2019-04-09 Thread Kelvin Nilsen
A patch to address this problem report was committed on 3/15/2019.  Some of the 
new regressions tests submitted with that initial patch failed on P8 big-endian 
and on P9 little-endian.

This new patch addresses the code generation problems that were uncovered by 
these failing tests.  Additionally, this new patch corrects some of the 
expected instruction counts for certain previously existing regression tests on 
certain targets to adjust for changes in the generated code.

This new patch has been bootstrapped and tested without regressions on 
powerpcle-unknown-linux (both P8 and P9) and on powerpc-linux (P7 and P8, both 
-m32 and -m64).

Is this ok for trunk and backports?

Thanks.

gcc/ChangeLog:

2019-04-09  Kelvin Nilsen  

PR target/87532
* config/rs6000/rs6000.c (rs6000_split_vec_extract_var): Use inner
mode of vector rather than mode of destination for move instruction.
* config/rs6000/vsx.md (*vsx_extract__mode_var):
Use QI inner mode with V16QI vector mode.

gcc/testsuite/ChangeLog:

2019-04-09  Kelvin Nilsen  

PR target/87532
* gcc.target/powerpc/fold-vec-extract-char.p8.c: Adjust expected
instruction counts.
* gcc.target/powerpc/fold-vec-extract-int.p8.c: Likewise.
* gcc.target/powerpc/fold-vec-extract-short.p8.c: Likewise.:

Index: gcc/config/rs6000/rs6000.c
===
--- gcc/config/rs6000/rs6000.c  (revision 270127)
+++ gcc/config/rs6000/rs6000.c  (working copy)
@@ -7167,7 +7167,7 @@
  rtx tmp_altivec)
 {
   machine_mode mode = GET_MODE (src);
-  machine_mode scalar_mode = GET_MODE (dest);
+  machine_mode scalar_mode = GET_MODE_INNER (GET_MODE (src));
   unsigned scalar_size = GET_MODE_SIZE (scalar_mode);
   int byte_shift = exact_log2 (scalar_size);
 
Index: gcc/config/rs6000/vsx.md
===
--- gcc/config/rs6000/vsx.md(revision 270127)
+++ gcc/config/rs6000/vsx.md(working copy)
@@ -3739,9 +3739,9 @@
   DONE;
 })
 
-(define_insn_and_split "*vsx_extract___var"
-  [(set (match_operand:SDI 0 "gpc_reg_operand" "=r,r,r")
-   (zero_extend:SDI
+(define_insn_and_split "*vsx_extract__mode_var"
+  [(set (match_operand: 0 "gpc_reg_operand" "=r,r,r")
+   (zero_extend:
 (unspec:
  [(match_operand:VSX_EXTRACT_I 1 "input_operand" "wK,v,m")
   (match_operand:DI 2 "gpc_reg_operand" "r,r,r")]
@@ -3753,7 +3753,7 @@
   "&& reload_completed"
   [(const_int 0)]
 {
-  machine_mode smode = mode;
+  machine_mode smode = mode;
   rs6000_split_vec_extract_var (gen_rtx_REG (smode, REGNO (operands[0])),
operands[1], operands[2],
operands[3], operands[4]);
Index: gcc/testsuite/gcc.target/powerpc/fold-vec-extract-char.p8.c
===
--- gcc/testsuite/gcc.target/powerpc/fold-vec-extract-char.p8.c (revision 
270127)
+++ gcc/testsuite/gcc.target/powerpc/fold-vec-extract-char.p8.c (working copy)
@@ -6,9 +6,9 @@
 /* { dg-options "-mdejagnu-cpu=power8 -O2" } */
 
 // six tests total. Targeting P8LE / P8BE.
-// P8 LE variable offset: rldicl, subfic, sldi, mtvsrd, xxpermdi, vslo, 
mfvsrd, sradi, (extsb)
+// P8 LE variable offset: rldicl, subfic, sldi, mtvsrd, xxpermdi, vslo, 
mfvsrd, sradi, rlwin, (extsb)
 // P8 LE constant offset: vspltb, mfvsrd, rlwinm, (extsb)
-// P8 BE variable offset: sldi, mtvsrd, xxpermdi, vslo, 
mfvsrd, sradi, (extsb)
+// P8 BE variable offset: sldi, mtvsrd, xxpermdi, vslo, 
mfvsrd, sradi, rlwinm, (extsb)
 // P8 BE constant offset: vspltb, mfvsrd, rlwinm, (extsb)
 
 /* { dg-final { scan-assembler-times {\mrldicl\M} 3 { target { le } } } } */
@@ -21,7 +21,7 @@
 /* { dg-final { scan-assembler-times {\msrdi\M} 3 { target lp64 } } } */
 /* { dg-final { scan-assembler-times "extsb" 2 } } */
 /* { dg-final { scan-assembler-times {\mvspltb\M} 3 { target lp64 } } } */
-/* { dg-final { scan-assembler-times {\mrlwinm\M} 2 { target lp64} } } */
+/* { dg-final { scan-assembler-times {\mrlwinm\M} 4 { target lp64} } } */
 
 /* multiple codegen variations for -m32. */
 /* { dg-final { scan-assembler-times {\mrlwinm\M} 3 { target ilp32} } } */
Index: gcc/testsuite/gcc.target/powerpc/fold-vec-extract-int.p8.c
===
--- gcc/testsuite/gcc.target/powerpc/fold-vec-extract-int.p8.c  (revision 
270127)
+++ gcc/testsuite/gcc.target/powerpc/fold-vec-extract-int.p8.c  (working copy)
@@ -7,14 +7,14 @@
 
 // Targeting P8 (LE) and (BE).  6 tests total.
 // P8 LE constant:  vspltw, mfvsrwz, (1:extsw/2:rldicl)
-// P8 LE variables: rldicl, subfic,  sldi, mtvsrd, xxpermdi, vslo, mfvsrd, 
sradi, (1:extsw)
+// P8 LE variables: subfic,  sldi, mtvsrd, xxpermdi, vslo, mfvsrd, sradi, 
(1:extsw/5:rldicl))
 // P8 BE constant:  vspltw, mfvsrwz, (1:extsw/2:rldicl)
-// P8 

Re: [PATCH][stage1] Support profile (BB counts and edge probabilities) in GIMPLE FE.

2019-04-09 Thread Martin Liška
On 4/8/19 3:35 PM, Martin Liška wrote:
> On 4/8/19 11:11 AM, Richard Biener wrote:
>> On Fri, Apr 5, 2019 at 2:32 PM Martin Liška  wrote:
>>>
>>> Hi.
>>>
>>> The patch adds support for profile for GIMPLE FE. That can be useful
>>> in the future.
>>>
>>> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>>>
>>> Ready to be installed after stage1 opens?
>>
>> Hmm, I guess to be useful we need the profile quality indicators as well
>> (and think about a proper syntax here since it seems related).
> 
> I wanted to make it easy, buy yes. We should implement that.
> 
>>
>> Btw, do BB counts and edge probabilities not have a relation?
> 
> Yes, they should match. But you have optimizations that make some 
> discrepancies.
> So that I would implement support for both of them.
> 
>>  If so why
>> do we need both?  In predict.c we also look at ENTRY_BLOCK->count
>> so we need a place to set that as well.  We should probably set
>> edge probabilities of fallthru edges properly during our "CFG build".
>>
>> +goto __BB3(44739243);
>>
>> since we eventually want to add other flags this syntactically
>> should maybe be goto __BB3(guessed(44739243)); and similar
>> for the __BB count case (just s/count/quality/).
> 
> The syntax works for me.
> 
>>
>> The entry block count could be sticked to __GIMPLE (ssa,guessed(N))
>> for example.  There's also the exit block, not sure if we ever look at
>> its count, so __GIMPLE (ssa,guessed(N[,M])) might be a possibility
>> if we always have the same quality here (probably not...).
> 
> I'll check it.
> 
>>
>> Otherwise thanks for trying ;)
>>
>> Richard.
>>
>>> Thanks,
>>> Martin
>>>
>>> gcc/ChangeLog:
>>>
>>> 2019-04-05  Martin Liska  
>>>
>>> * gimple-pretty-print.c (dump_gimple_bb_header):
>>> Dump BB count.
>>> (pp_cfg_jump): Dump edge probability.
>>> * profile-count.h (get_raw_value): New function.
>>> (from_raw_value): Likewise.
>>>
>>> gcc/c/ChangeLog:
>>>
>>> 2019-04-05  Martin Liska  
>>>
>>> * gimple-parser.c (struct gimple_parser): Add frequency
>>> for gimple_parser_edge.
>>> (gimple_parser::push_edge): Add new argument frequency.
>>> (c_parser_gimple_parse_bb_spec): Parse also frequency
>>> if present.
>>> (c_parser_parse_gimple_body): Set edge probability.
>>> (c_parser_gimple_compound_statement): Consume token
>>> before calling c_parser_gimple_goto_stmt.
>>> Parse BB counts.
>>> (c_parser_gimple_statement): Pass new argument.
>>> (c_parser_gimple_goto_stmt): Likewise.
>>> (c_parser_gimple_if_stmt): Likewise.
>>>
>>> gcc/testsuite/ChangeLog:
>>>
>>> 2019-04-05  Martin Liska  
>>>
>>> * gcc.dg/gimplefe-37.c: New test.
>>> ---
>>>  gcc/c/gimple-parser.c  | 116 +++--
>>>  gcc/gimple-pretty-print.c  |   8 ++
>>>  gcc/profile-count.h|  15 
>>>  gcc/testsuite/gcc.dg/gimplefe-37.c |  27 +++
>>>  4 files changed, 144 insertions(+), 22 deletions(-)
>>>  create mode 100644 gcc/testsuite/gcc.dg/gimplefe-37.c
>>>
>>>
> 

Hi.

There's updated version that supports profile quality for both counts
and probabilities. I'm wondering whether ENTRY and EXIT BBs needs to
have set probability. Apparently, I haven't seen any verifier that
would complain.

Martin
>From 8a2fed046a9a951ded01b3be1a9ce82ed5ab7496 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Thu, 4 Apr 2019 14:46:15 +0200
Subject: [PATCH] Support profile (BB counts and edge probabilities) in GIMPLE
 FE.

gcc/ChangeLog:

2019-04-05  Martin Liska  

	* gimple-pretty-print.c (dump_gimple_bb_header):
	Dump BB count.
	(pp_cfg_jump): Dump edge probability.
	* profile-count.c (profile_quality_as_string): Simplify
	with a static array.
	(parse_profile_quality): New function.
	(profile_count::dump): Simplify with a static array.
	(profile_count::from_gcov_type): Add new argument.
	* profile-count.h (parse_profile_quality): Likewise.

gcc/c/ChangeLog:

2019-04-05  Martin Liska  

	* gimple-parser.c (struct gimple_parser): Add probability.
	for gimple_parser_edge.
	(gimple_parser::push_edge): Add new argument probability.
	(c_parser_gimple_parse_bb_spec): Parse also probability
	if present.
	(c_parser_parse_gimple_body): Set edge probability.
	(c_parser_gimple_compound_statement): Consume token
	before calling c_parser_gimple_goto_stmt.
	Parse BB counts.
	(c_parser_gimple_statement): Pass new argument.
	(c_parser_gimple_goto_stmt): Likewise.
	(c_parser_gimple_if_stmt): Likewise.
	(c_parser_gimple_or_rtl_pass_list): Parse hot_bb_threshold.
	* c-parser.c (c_parser_declaration_or_fndef): Pass
	hot_bb_threshold argument.
	* c-tree.h (struct c_declspecs): Add hot_bb_threshold
	field.

gcc/testsuite/ChangeLog:

2019-04-05  Martin Liska  

	* gcc.dg/gimplefe-37.c: New test.
	* gcc.dg/gimplefe-33.c: Likewise.
---
 gcc/c/c-parser.c   |   3 +-
 gcc/c/c-tree.h |   2 +
 

Re: [PATCH] D support for RISC-V

2019-04-09 Thread David Abdurachmanov
On Tue, Apr 9, 2019 at 12:22 PM Andreas Schwab  wrote:
>
> On Apr 09 2019, David Abdurachmanov  wrote:
>
> > diff --git 
> > a/libphobos/src/std/experimental/allocator/building_blocks/region.d 
> > b/libphobos/src/std/experimental/allocator/building_blocks/region.d
> > index dfcecce72bd..cafe059a61f 100644
> > --- a/libphobos/src/std/experimental/allocator/building_blocks/region.d
> > +++ b/libphobos/src/std/experimental/allocator/building_blocks/region.d
> > @@ -391,7 +391,8 @@ struct InSituRegion(size_t size, size_t minAlign = 
> > platformAlignment)
> >  else version (PPC) enum growDownwards = Yes.growDownwards;
> >  else version (PPC64) enum growDownwards = Yes.growDownwards;
> >  else version (MIPS32) enum growDownwards = Yes.growDownwards;
> > -else version (MIPS64) enum growDownwards = Yes.growDownwards;
> > +else version (RISCV32) enum growDownwards = Yes.growDownwards;
> > +else version (RISCV64) enum growDownwards = Yes.growDownwards;
>
> Why do you remove the MIPS64 case?

Good catch. It's a mistake. Will be fixed in v2.

david

> Andreas.
>
> --
> Andreas Schwab, SUSE Labs, sch...@suse.de
> GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
> "And now for something completely different."


Re: [PATCH] D support for RISC-V

2019-04-09 Thread Andreas Schwab
On Apr 09 2019, David Abdurachmanov  wrote:

> diff --git 
> a/libphobos/src/std/experimental/allocator/building_blocks/region.d 
> b/libphobos/src/std/experimental/allocator/building_blocks/region.d
> index dfcecce72bd..cafe059a61f 100644
> --- a/libphobos/src/std/experimental/allocator/building_blocks/region.d
> +++ b/libphobos/src/std/experimental/allocator/building_blocks/region.d
> @@ -391,7 +391,8 @@ struct InSituRegion(size_t size, size_t minAlign = 
> platformAlignment)
>  else version (PPC) enum growDownwards = Yes.growDownwards;
>  else version (PPC64) enum growDownwards = Yes.growDownwards;
>  else version (MIPS32) enum growDownwards = Yes.growDownwards;
> -else version (MIPS64) enum growDownwards = Yes.growDownwards;
> +else version (RISCV32) enum growDownwards = Yes.growDownwards;
> +else version (RISCV64) enum growDownwards = Yes.growDownwards;

Why do you remove the MIPS64 case?

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


Re: [PATCH] Remove some further trailing whitespaces from diagnostic messages (PR translation/90011)

2019-04-09 Thread Richard Biener
On Tue, 9 Apr 2019, Jakub Jelinek wrote:

> Hi!
> 
> Several further spots with trailing whitespace, only bootstrapped/regtested
> on x86_64-linux and i686-linux (so the ipa-devirt.c change is covered),
> the rest is just by eyeballing gcc.pot.
> 
> Ok for trunk?

OK.

Richard.

> I wonder where and how we could check for this kind of errors, unfortunately
> the strings are extracted by xgettext which we can't easily patch for our
> purposes (say to emit warnings about
> "word"
> "another word"
> or
> "word "
> " another word"
> or for this trailing whitespace (this one could be done even on gcc.pot itself
> by looking for ' "\nmsgstr', but unfortunately we have various cases where
> we intentionally do want those: one category is usually when it ends with
> ": ", like:
> msgid "invalid 'asm': "
> msgstr ""
> (many cases), but there are even
> "Go ahead? (y or n) "
> msgstr ""
> or
> msgid "The following options are specific to just the language "
> msgstr ""
> "%s\tcompiled by GNU C version %s, "
> msgstr ""
> msgid "vtable for "
> msgstr ""
> msgid "%r%s:%d:%d:%R   "
> msgstr ""
> etc., so it is hard to do this programmatically, unless we had some white
> list.
> 
> 2019-04-09  Jakub Jelinek  
> 
>   PR translation/90011
>   * ipa-devirt.c (compare_virtual_tables): Remove two trailing spaces
>   from diagnostics.
>   * config/arm/freebsd.h (LINK_SPEC): Remove trailing space from -p
>   diagnostics.
>   * config/riscv/freebsd.h (LINK_SPEC): Likewise.
>   * config/aarch64/aarch64-freebsd.h (FBSD_TARGET_LINK_SPEC): Likewise.
>   * config/darwin.h (DRIVER_SELF_SPECS, ASM_FINAL_SPEC): Remove
>   trailing space from -gsplit-dwarf diagnostics.
> 
> --- gcc/ipa-devirt.c.jj   2019-03-08 11:52:17.0 +0100
> +++ gcc/ipa-devirt.c  2019-04-08 21:31:32.903689600 +0200
> @@ -874,7 +874,7 @@ compare_virtual_tables (varpool_node *pr
>   (TYPE_NAME (DECL_CONTEXT (vtable->decl))),
> OPT_Wodr,
> "virtual table of type %qD violates "
> -   "one definition rule  ",
> +   "one definition rule",
> DECL_CONTEXT (vtable->decl)))
>   {
> inform (DECL_SOURCE_LOCATION
> --- gcc/config/arm/freebsd.h.jj   2019-01-01 12:37:28.089795586 +0100
> +++ gcc/config/arm/freebsd.h  2019-04-08 21:26:40.917347492 +0200
> @@ -46,7 +46,7 @@
>  
>  #undef   LINK_SPEC
>  #define LINK_SPEC "  \
> -  %{p:%nconsider using `-pg' instead of `-p' with gprof (1) }
> \
> +  %{p:%nconsider using `-pg' instead of `-p' with gprof (1)} \
>%{v:-V}\
>%{assert*} %{R*} %{rpath*} %{defsym*}  
> \
>%{shared:-Bshareable %{h*} %{soname*}} \
> --- gcc/config/riscv/freebsd.h.jj 2019-01-01 12:37:30.086762821 +0100
> +++ gcc/config/riscv/freebsd.h2019-04-08 21:25:48.212188263 +0200
> @@ -41,7 +41,7 @@ along with GCC; see the file COPYING3.
>  #undef LINK_SPEC
>  #define LINK_SPEC "  \
>-melf" XLEN_SPEC "lriscv   \
> -  %{p:%nconsider using `-pg' instead of `-p' with gprof (1) }\
> +  %{p:%nconsider using `-pg' instead of `-p' with gprof (1)} \
>%{v:-V}\
>%{assert*} %{R*} %{rpath*} %{defsym*}  \
>%{shared:-Bshareable %{h*} %{soname*}} \
> --- gcc/config/aarch64/aarch64-freebsd.h.jj   2019-01-01 12:37:38.460625430 
> +0100
> +++ gcc/config/aarch64/aarch64-freebsd.h  2019-04-08 21:26:16.311740011 
> +0200
> @@ -34,7 +34,7 @@
>  
>  #undef  FBSD_TARGET_LINK_SPEC
>  #define FBSD_TARGET_LINK_SPEC " \
> -%{p:%nconsider using `-pg' instead of `-p' with gprof (1) } \
> +%{p:%nconsider using `-pg' instead of `-p' with gprof (1)}  \
>  %{v:-V} \
>  %{assert*} %{R*} %{rpath*} %{defsym*}   \
>  %{shared:-Bshareable %{h*} %{soname*}}  \
> --- gcc/config/darwin.h.jj2019-01-01 12:37:22.137893242 +0100
> +++ gcc/config/darwin.h   2019-04-08 21:25:15.260713922 +0200
> @@ -123,7 +123,7 @@ extern GTY(()) int darwin_ms_struct;
>"%{gused:-g -feliminate-unused-debug-symbols} %"%{fapple-kext|mkernel:-static}",  \
>"%{shared:-Zdynamiclib} % -  "%{gsplit-dwarf:%ngsplit-dwarf is not supported on this platform } \
> +  "%{gsplit-dwarf:%ngsplit-dwarf is not supported on this platform} \
>   %  
>  #define DARWIN_CC1_SPEC  
> \
> @@ -424,7 +424,7 @@ extern GTY(()) int darwin_ms_struct;
>  
>  #define 

Re: [PATCH] Fix s{,n}printf folding ICEs with slightly bogus prototypes (PR tree-optimization/89998)

2019-04-09 Thread Richard Biener
On Tue, 9 Apr 2019, Jakub Jelinek wrote:

> Hi!
> 
> If there are major differences in argument or return types of builtin
> prototypes, we already don't mark them as builtins, but if there are smaller
> differences like signedness changes of integral types with the same
> precision, we still accept them (with warning).
> 
> The following patch makes sure we don't ICE in those cases by using the lhs
> type where possible instead of hardcoding that s{,n}printf return always
> int.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Richard.

> 2019-04-09  Jakub Jelinek  
> 
>   PR tree-optimization/89998
>   * gimple-ssa-sprintf.c (try_substitute_return_value): Use lhs type
>   instead of integer_type_node if possible, don't add ranges if return
>   type is not compatible with int.
>   * gimple-fold.c (gimple_fold_builtin_sprintf,
>   gimple_fold_builtin_snprintf): Use lhs type instead of hardcoded
>   integer_type_node.
> 
>   * gcc.c-torture/compile/pr89998-1.c: New test.
>   * gcc.c-torture/compile/pr89998-2.c: New test.
> 
> --- gcc/gimple-ssa-sprintf.c.jj   2019-03-05 09:42:23.867092470 +0100
> +++ gcc/gimple-ssa-sprintf.c  2019-04-08 11:23:43.568301945 +0200
> @@ -3692,10 +3692,10 @@ try_substitute_return_value (gimple_stmt
>are badly declared.  */
>&& !stmt_ends_bb_p (info.callstmt))
>  {
> -  tree cst = build_int_cst (integer_type_node, retval[0]);
> +  tree cst = build_int_cst (lhs ? TREE_TYPE (lhs) : integer_type_node,
> + retval[0]);
>  
> -  if (lhs == NULL_TREE
> -   && info.nowrite)
> +  if (lhs == NULL_TREE && info.nowrite)
>   {
> /* Remove the call to the bounded function with a zero size
>(e.g., snprintf(0, 0, "%i", 123)) if there is no lhs.  */
> @@ -3736,7 +3736,7 @@ try_substitute_return_value (gimple_stmt
>   }
>   }
>  }
> -  else if (lhs)
> +  else if (lhs && types_compatible_p (TREE_TYPE (lhs), integer_type_node))
>  {
>bool setrange = false;
>  
> --- gcc/gimple-fold.c.jj  2019-03-07 20:07:20.292011398 +0100
> +++ gcc/gimple-fold.c 2019-04-08 11:10:45.380940700 +0200
> @@ -3231,11 +3231,10 @@ gimple_fold_builtin_sprintf (gimple_stmt
>   gimple_set_no_warning (repl, true);
>  
>gimple_seq_add_stmt_without_update (, repl);
> -  if (gimple_call_lhs (stmt))
> +  if (tree lhs = gimple_call_lhs (stmt))
>   {
> -   repl = gimple_build_assign (gimple_call_lhs (stmt),
> -   build_int_cst (integer_type_node,
> -  strlen (fmt_str)));
> +   repl = gimple_build_assign (lhs, build_int_cst (TREE_TYPE (lhs),
> +   strlen (fmt_str)));
> gimple_seq_add_stmt_without_update (, repl);
> gsi_replace_with_seq_vops (gsi, stmts);
> /* gsi now points at the assignment to the lhs, get a
> @@ -3285,12 +3284,12 @@ gimple_fold_builtin_sprintf (gimple_stmt
>   gimple_set_no_warning (repl, true);
>  
>gimple_seq_add_stmt_without_update (, repl);
> -  if (gimple_call_lhs (stmt))
> +  if (tree lhs = gimple_call_lhs (stmt))
>   {
> -   if (!useless_type_conversion_p (integer_type_node,
> +   if (!useless_type_conversion_p (TREE_TYPE (lhs),
> TREE_TYPE (orig_len)))
> - orig_len = fold_convert (integer_type_node, orig_len);
> -   repl = gimple_build_assign (gimple_call_lhs (stmt), orig_len);
> + orig_len = fold_convert (TREE_TYPE (lhs), orig_len);
> +   repl = gimple_build_assign (lhs, orig_len);
> gimple_seq_add_stmt_without_update (, repl);
> gsi_replace_with_seq_vops (gsi, stmts);
> /* gsi now points at the assignment to the lhs, get a
> @@ -3370,10 +3369,10 @@ gimple_fold_builtin_snprintf (gimple_stm
>gimple_seq stmts = NULL;
>gimple *repl = gimple_build_call (fn, 2, dest, fmt);
>gimple_seq_add_stmt_without_update (, repl);
> -  if (gimple_call_lhs (stmt))
> +  if (tree lhs = gimple_call_lhs (stmt))
>   {
> -   repl = gimple_build_assign (gimple_call_lhs (stmt),
> -   build_int_cst (integer_type_node, len));
> +   repl = gimple_build_assign (lhs,
> +   build_int_cst (TREE_TYPE (lhs), len));
> gimple_seq_add_stmt_without_update (, repl);
> gsi_replace_with_seq_vops (gsi, stmts);
> /* gsi now points at the assignment to the lhs, get a
> @@ -3422,12 +3421,12 @@ gimple_fold_builtin_snprintf (gimple_stm
>gimple_seq stmts = NULL;
>gimple *repl = gimple_build_call (fn, 2, dest, orig);
>gimple_seq_add_stmt_without_update (, repl);
> -  if (gimple_call_lhs (stmt))
> +  if (tree lhs = gimple_call_lhs (stmt))
>   {
> -   if (!useless_type_conversion_p 

[Patch, fortran] PRs 89843 and 90022 - C Fortran Interop fixes.

2019-04-09 Thread Paul Richard Thomas
The most part of this patch is concerned with implementing calls from
C of of fortran bind c procedures with assumed shape or assumed rank
dummies to completely fix PR89843. The conversion of the descriptors
from CFI to gfc occur on entry to and reversed on exit from the
procedure.

This patch is safe for trunk, even at this late stage, because its
effects are barricaded behind the tests for CFI descriptors. I believe
that it appropriately rewards the bug reporters to have this feature
work as well as possible at release.

Between comments and the ChangeLogs, this patch is self explanatory.

Bootstrapped and regtested on FC29/x86_64 - OK for trunk?

Paul

2019-04-09  Paul Thomas  

PR fortran/89843
* trans-decl.c (gfc_get_symbol_decl): Assumed shape and assumed
rank dummies of bind C procs require deferred initialization.
(convert_CFI_desc): New procedure to convert incoming CFI
descriptors to gfc types and back again.
(gfc_trans_deferred_vars): Call it.
* trans-expr.c (gfc_conv_gfc_desc_to_cfi_desc): Null the CFI
descriptor pointer. Free the descriptor in all cases.

PR fortran/90022
* trans-decl.c (gfc_get_symbol_decl): Make sure that the se
expression is a pointer type before converting it to the symbol
backend_decl type.

2019-04-09  Paul Thomas  

PR fortran/89843
* gfortran.dg/ISO_Fortran_binding_4.f90: Modify the value of x
in ctg. Test the conversion of the descriptor types in the main
program.
* gfortran.dg/ISO_Fortran_binding_10.f90: New test.
* gfortran.dg/ISO_Fortran_binding_10.c: Called by it.

PR fortran/90022
* gfortran.dg/ISO_Fortran_binding_1.c: Correct the indexing for
the computation of 'ans'. Also, change the expected results for
CFI_is_contiguous to comply with standard.
* gfortran.dg/ISO_Fortran_binding_1.f90: Correct the expected
results for CFI_is_contiguous to comply with standard.
* gfortran.dg/ISO_Fortran_binding_9.f90: New test.
* gfortran.dg/ISO_Fortran_binding_9.c: Called by it.

2019-04-09  Paul Thomas  

PR fortran/89843
* runtime/ISO_Fortran_binding.c (cfi_desc_to_gfc_desc): Only
return immediately if the source pointer is null. Bring
forward the extraction of the gfc type. Extract the kind so
that the element size can be correctly computed for sections
and components of derived type arrays. Remove the free of the
CFI descriptor since this is now done in trans-expr.c.
(gfc_desc_to_cfi_desc): Only allocate the CFI descriptor if it
is not null.
(CFI_section): Normalise the difference between the upper and
lower bounds by the stride to correctly calculate the extents
of the section.

PR fortran/90022
* runtime/ISO_Fortran_binding.c (CFI_is_contiguous) : Return
1 for true and 0 otherwise to comply with the standard. Correct
the contiguity check for rank 3 and greater by using the stride
measure of the lower dimension rather than the element length.
Index: gcc/fortran/trans-decl.c
===
*** gcc/fortran/trans-decl.c	(revision 270149)
--- gcc/fortran/trans-decl.c	(working copy)
*** gfc_get_symbol_decl (gfc_symbol * sym)
*** 1494,1499 
--- 1494,1506 
&& sym->attr.dummy)
  gfc_defer_symbol_init (sym);
  
+   if (sym->attr.dummy
+   && sym->ns->proc_name->attr.is_bind_c
+   && sym->attr.dimension
+   && (sym->as->type == AS_ASSUMED_SHAPE
+ 	  || sym->as->type == AS_ASSUMED_RANK))
+ gfc_defer_symbol_init (sym);
+ 
/* All deferred character length procedures need to retain the backend
   decl, which is a pointer to the character length in the caller's
   namespace and to declare a local character length.  */
*** gfc_null_and_pass_deferred_len (gfc_symb
*** 4268,4273 
--- 4275,4353 
  }
  
  
+ /* Convert CFI descriptor dummies into gfc types and back again.  */
+ static void
+ convert_CFI_desc (gfc_wrapped_block * block, gfc_symbol *sym)
+ {
+   tree gfc_desc;
+   tree gfc_desc_ptr;
+   tree CFI_desc;
+   tree CFI_desc_ptr;
+   tree dummy_ptr;
+   tree tmp;
+   tree incoming;
+   tree outgoing;
+   stmtblock_t tmpblock;
+ 
+   /* dummy_ptr will be the pointer to the passed array descriptor,
+  while CFI_desc is the descriptor itself.  */
+   dummy_ptr = sym->backend_decl;
+   CFI_desc = sym->backend_decl;
+   if (POINTER_TYPE_P (TREE_TYPE (CFI_desc)))
+ CFI_desc = build_fold_indirect_ref_loc (input_location, CFI_desc);
+   if (!GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (CFI_desc)))
+ {
+   if (DECL_LANG_SPECIFIC (sym->backend_decl))
+ 	CFI_desc = GFC_DECL_SAVED_DESCRIPTOR (sym->backend_decl);
+   else
+ 	CFI_desc = NULL;
+   dummy_ptr = CFI_desc;
+ }
+ 
+   if (CFI_desc)
+ {
+   if (POINTER_TYPE_P (TREE_TYPE (CFI_desc)))
+ 	CFI_desc = build_fold_indirect_ref_loc (input_location, CFI_desc);
+ 
+   /* The compiler will have given CFI_desc the 

[PATCH] D support for RISC-V

2019-04-09 Thread David Abdurachmanov
This patch has been in Fedora/RISCV for the last couple of months.
I have tested simple applications (e.g. word count example), which
worked without a problem.

I believe Iain Buclaw did run GCC testsuite using Fedora/RISCV
build and QEMU. The patch has not changed since that.

Signed-off-by: David Abdurachmanov 
---
 libphobos/configure.tgt   |  2 +
 libphobos/libdruntime/core/atomic.d   |  6 +-
 .../libdruntime/rt/sections_elf_shared.d  | 14 -
 .../allocator/building_blocks/region.d|  3 +-
 libphobos/src/std/math.d  | 59 +++
 5 files changed, 79 insertions(+), 5 deletions(-)

diff --git a/libphobos/configure.tgt b/libphobos/configure.tgt
index 0471bfd816b..811fdfa21a7 100644
--- a/libphobos/configure.tgt
+++ b/libphobos/configure.tgt
@@ -32,6 +32,8 @@ case "${target}" in
;;
   x86_64-*-netbsd* | i?86-*-netbsd*)
;;
+  riscv*-*-linux*)
+   ;;
   *)
UNSUPPORTED=1
;;
diff --git a/libphobos/libdruntime/core/atomic.d 
b/libphobos/libdruntime/core/atomic.d
index 0b39cddb6c9..5a6c4b854c7 100644
--- a/libphobos/libdruntime/core/atomic.d
+++ b/libphobos/libdruntime/core/atomic.d
@@ -1353,7 +1353,7 @@ else version (GNU)
 
 private bool casImpl(T,V1,V2)( shared(T)* here, V1 ifThis, V2 writeThis ) 
pure nothrow @nogc @trusted
 {
-static assert(GNU_Have_Atomics, "cas() not supported on this 
architecture");
+static assert(GNU_Have_Atomics || GNU_Have_LibAtomic, "cas() not 
supported on this architecture");
 bool res = void;
 
 static if (T.sizeof == byte.sizeof)
@@ -1406,7 +1406,7 @@ else version (GNU)
 {
 static assert(ms != MemoryOrder.rel, "Invalid MemoryOrder for 
atomicLoad");
 static assert(__traits(isPOD, T), "argument to atomicLoad() must be 
POD");
-static assert(GNU_Have_Atomics, "atomicLoad() not supported on this 
architecture");
+static assert(GNU_Have_Atomics || GNU_Have_LibAtomic, "atomicLoad() 
not supported on this architecture");
 
 static if (T.sizeof == ubyte.sizeof)
 {
@@ -1444,7 +1444,7 @@ else version (GNU)
 {
 static assert(ms != MemoryOrder.acq, "Invalid MemoryOrder for 
atomicStore");
 static assert(__traits(isPOD, T), "argument to atomicLoad() must be 
POD");
-static assert(GNU_Have_Atomics, "atomicStore() not supported on this 
architecture");
+static assert(GNU_Have_Atomics || GNU_Have_LibAtomic, "atomicStore() 
not supported on this architecture");
 
 static if (T.sizeof == ubyte.sizeof)
 {
diff --git a/libphobos/libdruntime/rt/sections_elf_shared.d 
b/libphobos/libdruntime/rt/sections_elf_shared.d
index d4e1ff07699..45c1dcbc7f3 100644
--- a/libphobos/libdruntime/rt/sections_elf_shared.d
+++ b/libphobos/libdruntime/rt/sections_elf_shared.d
@@ -10,6 +10,9 @@
 
 module rt.sections_elf_shared;
 
+version (RISCV32) version = RISCV_Any;
+version (RISCV64) version = RISCV_Any;
+
 version (CRuntime_Glibc) enum SharedELF = true;
 else version (FreeBSD) enum SharedELF = true;
 else version (NetBSD) enum SharedELF = true;
@@ -671,7 +674,16 @@ version (Shared)
 if (dyn.d_tag == DT_STRTAB)
 {
 version (linux)
-strtab = cast(const(char)*)dyn.d_un.d_ptr;
+{
+// This might change in future glibc releases (after 2.29) 
as dynamic sections
+// are not required to be read-only on RISC-V. This was 
copy & pasted from MIPS while
+// upstreaming RISC-V support. Otherwise MIPS is the only 
arch which sets in glibc:
+// #define DL_RO_DYN_SECTION 1
+version (RISCV_Any)
+strtab = cast(const(char)*)(info.dlpi_addr + 
dyn.d_un.d_ptr); // relocate
+else
+strtab = cast(const(char)*)dyn.d_un.d_ptr;
+}
 else version (FreeBSD)
 strtab = cast(const(char)*)(info.dlpi_addr + 
dyn.d_un.d_ptr); // relocate
 else version (NetBSD)
diff --git a/libphobos/src/std/experimental/allocator/building_blocks/region.d 
b/libphobos/src/std/experimental/allocator/building_blocks/region.d
index dfcecce72bd..cafe059a61f 100644
--- a/libphobos/src/std/experimental/allocator/building_blocks/region.d
+++ b/libphobos/src/std/experimental/allocator/building_blocks/region.d
@@ -391,7 +391,8 @@ struct InSituRegion(size_t size, size_t minAlign = 
platformAlignment)
 else version (PPC) enum growDownwards = Yes.growDownwards;
 else version (PPC64) enum growDownwards = Yes.growDownwards;
 else version (MIPS32) enum growDownwards = Yes.growDownwards;
-else version (MIPS64) enum growDownwards = Yes.growDownwards;
+else version (RISCV32) enum growDownwards = Yes.growDownwards;
+else version (RISCV64) enum growDownwards = Yes.growDownwards;
 else version (SPARC) 

[Patch AArch64] Add __ARM_FEATURE_ATOMICS

2019-04-09 Thread Ramana Radhakrishnan
This keeps coming up repeatedly and the ACLE has finally added 
__ARM_FEATURE_ATOMICS for the LSE feature in GCC. This is now part of 
the latest ACLE release 
(https://developer.arm.com/docs/101028/latest/5-feature-test-macros)


I know it's late for GCC-9 but this is a simple macro which need not 
wait  for another year.


Ok for trunk and to backport to all release branches ?

Tested with a simple build and a smoke test.


regards
Ramana

* config/aarch64/aarch64-c.c (aarch64_update_cpp_builtins): Define 
__ARM_FEATURE_ATOMICS
diff --git a/gcc/config/aarch64/aarch64-c.c b/gcc/config/aarch64/aarch64-c.c
index fcb1e80177d..6d5acb02fc6 100644
--- a/gcc/config/aarch64/aarch64-c.c
+++ b/gcc/config/aarch64/aarch64-c.c
@@ -147,6 +147,7 @@ aarch64_update_cpp_builtins (cpp_reader *pfile)
   builtin_define_with_int_value ("__ARM_FEATURE_SVE_BITS", bits);
 }
 
+  aarch64_def_or_undef (TARGET_LSE, "__ARM_FEATURE_ATOMICS", pfile);
   aarch64_def_or_undef (TARGET_AES, "__ARM_FEATURE_AES", pfile);
   aarch64_def_or_undef (TARGET_SHA2, "__ARM_FEATURE_SHA2", pfile);
   aarch64_def_or_undef (TARGET_SHA3, "__ARM_FEATURE_SHA3", pfile);


Re: C++ PATCH for c++/89214 - ICE when initializing aggregates with bases

2019-04-09 Thread Andreas Schwab
On Apr 08 2019, Marek Polacek  wrote:

> Thanks, committed.  Andreas -- I hope the failure is fixed now.

Yes, all tests of aggr-base[89].C are passing.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


[PATCH] Remove some further trailing whitespaces from diagnostic messages (PR translation/90011)

2019-04-09 Thread Jakub Jelinek
Hi!

Several further spots with trailing whitespace, only bootstrapped/regtested
on x86_64-linux and i686-linux (so the ipa-devirt.c change is covered),
the rest is just by eyeballing gcc.pot.

Ok for trunk?

I wonder where and how we could check for this kind of errors, unfortunately
the strings are extracted by xgettext which we can't easily patch for our
purposes (say to emit warnings about
"word"
"another word"
or
"word "
" another word"
or for this trailing whitespace (this one could be done even on gcc.pot itself
by looking for ' "\nmsgstr', but unfortunately we have various cases where
we intentionally do want those: one category is usually when it ends with
": ", like:
msgid "invalid 'asm': "
msgstr ""
(many cases), but there are even
"Go ahead? (y or n) "
msgstr ""
or
msgid "The following options are specific to just the language "
msgstr ""
"%s\tcompiled by GNU C version %s, "
msgstr ""
msgid "vtable for "
msgstr ""
msgid "%r%s:%d:%d:%R   "
msgstr ""
etc., so it is hard to do this programmatically, unless we had some white
list.

2019-04-09  Jakub Jelinek  

PR translation/90011
* ipa-devirt.c (compare_virtual_tables): Remove two trailing spaces
from diagnostics.
* config/arm/freebsd.h (LINK_SPEC): Remove trailing space from -p
diagnostics.
* config/riscv/freebsd.h (LINK_SPEC): Likewise.
* config/aarch64/aarch64-freebsd.h (FBSD_TARGET_LINK_SPEC): Likewise.
* config/darwin.h (DRIVER_SELF_SPECS, ASM_FINAL_SPEC): Remove
trailing space from -gsplit-dwarf diagnostics.

--- gcc/ipa-devirt.c.jj 2019-03-08 11:52:17.0 +0100
+++ gcc/ipa-devirt.c2019-04-08 21:31:32.903689600 +0200
@@ -874,7 +874,7 @@ compare_virtual_tables (varpool_node *pr
(TYPE_NAME (DECL_CONTEXT (vtable->decl))),
  OPT_Wodr,
  "virtual table of type %qD violates "
- "one definition rule  ",
+ "one definition rule",
  DECL_CONTEXT (vtable->decl)))
{
  inform (DECL_SOURCE_LOCATION
--- gcc/config/arm/freebsd.h.jj 2019-01-01 12:37:28.089795586 +0100
+++ gcc/config/arm/freebsd.h2019-04-08 21:26:40.917347492 +0200
@@ -46,7 +46,7 @@
 
 #undef LINK_SPEC
 #define LINK_SPEC "\
-  %{p:%nconsider using `-pg' instead of `-p' with gprof (1) }  \
+  %{p:%nconsider using `-pg' instead of `-p' with gprof (1)}   \
   %{v:-V}  \
   %{assert*} %{R*} %{rpath*} %{defsym*}
\
   %{shared:-Bshareable %{h*} %{soname*}}   \
--- gcc/config/riscv/freebsd.h.jj   2019-01-01 12:37:30.086762821 +0100
+++ gcc/config/riscv/freebsd.h  2019-04-08 21:25:48.212188263 +0200
@@ -41,7 +41,7 @@ along with GCC; see the file COPYING3.
 #undef LINK_SPEC
 #define LINK_SPEC "\
   -melf" XLEN_SPEC "lriscv \
-  %{p:%nconsider using `-pg' instead of `-p' with gprof (1) }  \
+  %{p:%nconsider using `-pg' instead of `-p' with gprof (1)}   \
   %{v:-V}  \
   %{assert*} %{R*} %{rpath*} %{defsym*}\
   %{shared:-Bshareable %{h*} %{soname*}}   \
--- gcc/config/aarch64/aarch64-freebsd.h.jj 2019-01-01 12:37:38.460625430 
+0100
+++ gcc/config/aarch64/aarch64-freebsd.h2019-04-08 21:26:16.311740011 
+0200
@@ -34,7 +34,7 @@
 
 #undef  FBSD_TARGET_LINK_SPEC
 #define FBSD_TARGET_LINK_SPEC " \
-%{p:%nconsider using `-pg' instead of `-p' with gprof (1) } \
+%{p:%nconsider using `-pg' instead of `-p' with gprof (1)}  \
 %{v:-V} \
 %{assert*} %{R*} %{rpath*} %{defsym*}   \
 %{shared:-Bshareable %{h*} %{soname*}}  \
--- gcc/config/darwin.h.jj  2019-01-01 12:37:22.137893242 +0100
+++ gcc/config/darwin.h 2019-04-08 21:25:15.260713922 +0200
@@ -123,7 +123,7 @@ extern GTY(()) int darwin_ms_struct;
   "%{gused:-g -feliminate-unused-debug-symbols} %

[C++ PATCH] Remove trailing space from diagnostics for narrowing conv (PR translation/90011)

2019-04-09 Thread Jakub Jelinek
Hi!

In r263523 check_narrowing changed in this spot:
  pedwarn (loc, OPT_Wnarrowing,
-  "narrowing conversion of %qE from %qH to %qI "
-  "inside { }", init, ftype, type);
+  "narrowing conversion of %qE from %qH to %qI ",
+  init, ftype, type);
where the trailing space on one line was desirable before to separate
%qI from inside { }, but now it doesn't make sense.

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

2019-04-09  Jakub Jelinek  

PR translation/90011
* typeck2.c (check_narrowing): Remove trailing space from diagnostics.

--- gcc/cp/typeck2.c.jj 2019-04-08 10:11:28.199226055 +0200
+++ gcc/cp/typeck2.c2019-04-08 21:09:56.082464190 +0200
@@ -1019,7 +1019,7 @@ check_narrowing (tree type, tree init, t
  int savederrorcount = errorcount;
  global_dc->pedantic_errors = 1;
  pedwarn (loc, OPT_Wnarrowing,
-  "narrowing conversion of %qE from %qH to %qI ",
+  "narrowing conversion of %qE from %qH to %qI",
   init, ftype, type);
  if (errorcount == savederrorcount)
ok = true;

Jakub


[C/C++ PATCH] Fix promoted switch condition out of range diagnostics (PR c/89888)

2019-04-09 Thread Jakub Jelinek
Hi!

As mentioned in the PR, check_case_bounds warns about case labels on
switches with promoted condition where the values lie fully (or partially
when using ...) outside of the range of the original, non-promoted, type
and adjusts (or doesn't create at all) the CASE_LABEL_EXPRs too early,
so that we don't actually error for duplicate cases.

The following patch defers that warning until later
(c_finish_case/pop_switch), so that we diagnose errors first and only
then adjust/remove them.

Alternatively, I believe we could remove from the patch the in-place
replacement of CASE_LABEL_EXPRs with LABEL_EXPRs if we want to remove,
just splay_tree_remove those, because by my reading of
preprocess_case_label_vec_for_gimple we also ignore the fully out of range
CASE_LABEL_EXPRs there, shall I tweak the patch and rebootstrap?

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

2019-04-09  Jakub Jelinek  

PR c/89888
* c-common.h (c_add_case_label): Remove orig_type and outside_range_p
arguments.
(c_do_switch_warnings): Remove outside_range_p argument.
* c-common.c (check_case_bounds): Removed.
(c_add_case_label): Remove orig_type and outside_range_p arguments.
Don't call check_case_bounds.  Fold low_value as well as high_value.
* c-warn.c (c_do_switch_warnings): Remove outside_range_p argument.
Check for case labels outside of range of original type here and
adjust them or overwrite with LABEL_EXPR.
c/
* c-typeck.c (struct c_switch): Remove outside_range_p member.
(c_start_case): Don't clear it.
(do_case): Adjust c_add_case_label caller.
(c_finish_case): Adjust c_do_switch_warnings caller.
cp/
* decl.c (struct cp_switch): Remove outside_range_p member.
(push_switch): Don't clear it.
(pop_switch): Adjust c_do_switch_warnings caller.
(finish_case_label): Adjust c_add_case_label caller.
testsuite/
* c-c++-common/pr89888.c: New test.
* g++.dg/torture/pr40335.C: Change dg-bogus into dg-warning.
Don't expect -Wswitch-unreachable warning.

--- gcc/c-family/c-common.h.jj  2019-03-20 12:24:57.320308115 +0100
+++ gcc/c-family/c-common.h 2019-04-08 19:02:28.522104090 +0200
@@ -988,8 +988,7 @@ extern tree boolean_increment (enum tree
 
 extern int case_compare (splay_tree_key, splay_tree_key);
 
-extern tree c_add_case_label (location_t, splay_tree, tree, tree, tree, tree,
- bool *);
+extern tree c_add_case_label (location_t, splay_tree, tree, tree, tree);
 extern bool c_switch_covers_all_cases_p (splay_tree, tree);
 
 extern tree build_function_call (location_t, tree, tree);
@@ -1291,8 +1290,7 @@ extern void sizeof_pointer_memaccess_war
  bool (*) (tree, tree));
 extern void check_main_parameter_types (tree decl);
 extern void warnings_for_convert_and_check (location_t, tree, tree, tree);
-extern void c_do_switch_warnings (splay_tree, location_t, tree, tree, bool,
- bool);
+extern void c_do_switch_warnings (splay_tree, location_t, tree, tree, bool);
 extern void warn_for_omitted_condop (location_t, tree);
 extern bool warn_for_restrict (unsigned, tree *, unsigned);
 extern void warn_for_address_or_pointer_of_packed_member (tree, tree);
--- gcc/c-family/c-common.c.jj  2019-03-26 08:52:54.938604825 +0100
+++ gcc/c-family/c-common.c 2019-04-09 01:28:01.199754481 +0200
@@ -314,8 +314,6 @@ const struct fname_var_t fname_vars[] =
 struct visibility_flags visibility_options;
 
 static tree check_case_value (location_t, tree);
-static bool check_case_bounds (location_t, tree, tree, tree *, tree *,
-  bool *);
 
 
 static void check_nonnull_arg (void *, tree, unsigned HOST_WIDE_INT);
@@ -2103,86 +2101,6 @@ check_case_value (location_t loc, tree v
   return value;
 }
 
-/* See if the case values LOW and HIGH are in the range of the original
-   type (i.e. before the default conversion to int) of the switch testing
-   expression.
-   TYPE is the promoted type of the testing expression, and ORIG_TYPE is
-   the type before promoting it.  CASE_LOW_P is a pointer to the lower
-   bound of the case label, and CASE_HIGH_P is the upper bound or NULL
-   if the case is not a case range.
-   The caller has to make sure that we are not called with NULL for
-   CASE_LOW_P (i.e. the default case).  OUTSIDE_RANGE_P says whether there
-   was a case value that doesn't fit into the range of the ORIG_TYPE.
-   Returns true if the case label is in range of ORIG_TYPE (saturated or
-   untouched) or false if the label is out of range.  */
-
-static bool
-check_case_bounds (location_t loc, tree type, tree orig_type,
-  tree *case_low_p, tree *case_high_p,
-  bool *outside_range_p)
-{
-  tree min_value, max_value;
-  tree case_low = *case_low_p;
-  tree case_high = case_high_p ? *case_high_p : 

[PATCH] Fix s{,n}printf folding ICEs with slightly bogus prototypes (PR tree-optimization/89998)

2019-04-09 Thread Jakub Jelinek
Hi!

If there are major differences in argument or return types of builtin
prototypes, we already don't mark them as builtins, but if there are smaller
differences like signedness changes of integral types with the same
precision, we still accept them (with warning).

The following patch makes sure we don't ICE in those cases by using the lhs
type where possible instead of hardcoding that s{,n}printf return always
int.

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

2019-04-09  Jakub Jelinek  

PR tree-optimization/89998
* gimple-ssa-sprintf.c (try_substitute_return_value): Use lhs type
instead of integer_type_node if possible, don't add ranges if return
type is not compatible with int.
* gimple-fold.c (gimple_fold_builtin_sprintf,
gimple_fold_builtin_snprintf): Use lhs type instead of hardcoded
integer_type_node.

* gcc.c-torture/compile/pr89998-1.c: New test.
* gcc.c-torture/compile/pr89998-2.c: New test.

--- gcc/gimple-ssa-sprintf.c.jj 2019-03-05 09:42:23.867092470 +0100
+++ gcc/gimple-ssa-sprintf.c2019-04-08 11:23:43.568301945 +0200
@@ -3692,10 +3692,10 @@ try_substitute_return_value (gimple_stmt
 are badly declared.  */
   && !stmt_ends_bb_p (info.callstmt))
 {
-  tree cst = build_int_cst (integer_type_node, retval[0]);
+  tree cst = build_int_cst (lhs ? TREE_TYPE (lhs) : integer_type_node,
+   retval[0]);
 
-  if (lhs == NULL_TREE
- && info.nowrite)
+  if (lhs == NULL_TREE && info.nowrite)
{
  /* Remove the call to the bounded function with a zero size
 (e.g., snprintf(0, 0, "%i", 123)) if there is no lhs.  */
@@ -3736,7 +3736,7 @@ try_substitute_return_value (gimple_stmt
}
}
 }
-  else if (lhs)
+  else if (lhs && types_compatible_p (TREE_TYPE (lhs), integer_type_node))
 {
   bool setrange = false;
 
--- gcc/gimple-fold.c.jj2019-03-07 20:07:20.292011398 +0100
+++ gcc/gimple-fold.c   2019-04-08 11:10:45.380940700 +0200
@@ -3231,11 +3231,10 @@ gimple_fold_builtin_sprintf (gimple_stmt
gimple_set_no_warning (repl, true);
 
   gimple_seq_add_stmt_without_update (, repl);
-  if (gimple_call_lhs (stmt))
+  if (tree lhs = gimple_call_lhs (stmt))
{
- repl = gimple_build_assign (gimple_call_lhs (stmt),
- build_int_cst (integer_type_node,
-strlen (fmt_str)));
+ repl = gimple_build_assign (lhs, build_int_cst (TREE_TYPE (lhs),
+ strlen (fmt_str)));
  gimple_seq_add_stmt_without_update (, repl);
  gsi_replace_with_seq_vops (gsi, stmts);
  /* gsi now points at the assignment to the lhs, get a
@@ -3285,12 +3284,12 @@ gimple_fold_builtin_sprintf (gimple_stmt
gimple_set_no_warning (repl, true);
 
   gimple_seq_add_stmt_without_update (, repl);
-  if (gimple_call_lhs (stmt))
+  if (tree lhs = gimple_call_lhs (stmt))
{
- if (!useless_type_conversion_p (integer_type_node,
+ if (!useless_type_conversion_p (TREE_TYPE (lhs),
  TREE_TYPE (orig_len)))
-   orig_len = fold_convert (integer_type_node, orig_len);
- repl = gimple_build_assign (gimple_call_lhs (stmt), orig_len);
+   orig_len = fold_convert (TREE_TYPE (lhs), orig_len);
+ repl = gimple_build_assign (lhs, orig_len);
  gimple_seq_add_stmt_without_update (, repl);
  gsi_replace_with_seq_vops (gsi, stmts);
  /* gsi now points at the assignment to the lhs, get a
@@ -3370,10 +3369,10 @@ gimple_fold_builtin_snprintf (gimple_stm
   gimple_seq stmts = NULL;
   gimple *repl = gimple_build_call (fn, 2, dest, fmt);
   gimple_seq_add_stmt_without_update (, repl);
-  if (gimple_call_lhs (stmt))
+  if (tree lhs = gimple_call_lhs (stmt))
{
- repl = gimple_build_assign (gimple_call_lhs (stmt),
- build_int_cst (integer_type_node, len));
+ repl = gimple_build_assign (lhs,
+ build_int_cst (TREE_TYPE (lhs), len));
  gimple_seq_add_stmt_without_update (, repl);
  gsi_replace_with_seq_vops (gsi, stmts);
  /* gsi now points at the assignment to the lhs, get a
@@ -3422,12 +3421,12 @@ gimple_fold_builtin_snprintf (gimple_stm
   gimple_seq stmts = NULL;
   gimple *repl = gimple_build_call (fn, 2, dest, orig);
   gimple_seq_add_stmt_without_update (, repl);
-  if (gimple_call_lhs (stmt))
+  if (tree lhs = gimple_call_lhs (stmt))
{
- if (!useless_type_conversion_p (integer_type_node,
+ if (!useless_type_conversion_p (TREE_TYPE (lhs),
  TREE_TYPE (orig_len)))
-   orig_len = fold_convert 

Re: [PATCH] Fix PR90006

2019-04-09 Thread Richard Biener
On April 8, 2019 10:59:49 PM GMT+02:00, Richard Sandiford 
 wrote:
>Richard Biener  writes:
>> The following fixes SLP vectorization to properly consider
>> calls like lrint demoting on ilp32 targets.
>>
>> Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
>>
>> Richard.
>>
>> 2019-04-08  Richard Biener  
>>
>>  PR tree-optimization/90006
>>  * tree-vect-data-refs.c (vect_get_smallest_scalar_type): Handle
>>  calls like lrint.
>>
>>  * gcc.dg/vect/bb-slp-pr90006.c: New testcase.
>>
>> Index: gcc/tree-vect-data-refs.c
>> ===
>> --- gcc/tree-vect-data-refs.c(revision 270202)
>> +++ gcc/tree-vect-data-refs.c(working copy)
>> @@ -144,6 +144,15 @@ vect_get_smallest_scalar_type (gimple *s
>>if (rhs < lhs)
>>  scalar_type = rhs_type;
>>  }
>> +  else if (is_gimple_call (stmt)
>> +   && gimple_call_num_args (stmt) > 0)
>> +{
>> +  tree rhs_type = TREE_TYPE (gimple_call_arg (stmt, 0));
>> +
>> +  rhs = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (rhs_type));
>> +  if (rhs < lhs)
>> +scalar_type = rhs_type;
>> +}
>>  
>>*lhs_size_unit = lhs;
>>*rhs_size_unit = rhs;
>
>Looks like this causes a few regressions on SVE.  One is that we reach
>here before doing much sanity checking, so for SLP we can see
>vectorised
>calls with variable-length parameters.  That's easily fixed with the
>same tree_fits_uhwi_p as for lhs.
>
>The more difficult one is that we have various internal functions
>whose first parameter isn't interesting for finding vector types.
>E.g. for conditional internal functions like IFN_COND_DIV, the first
>parameter is the boolean condition.  Using that here meant we ended up
>thinking we needed vectors of 8-bit data, and so had multiple copies
>for
>wider elements.  (The idea instead is that the condition width adapts
>to match the data.)
>
>I think the same thing could happen for masked loads and stores,
>where the first parameter is a pointer.  E.g. if we have a 64-bit
>load or store on an ILP32 target, we might end up thinking that we
>need vectors of 32-bit elements when we don't.

EH... 

>The patch below fixes the cases caught by the testsuite, but I'm
>not sure whether there are others lurking.  I guess the problem is
>that returning a narrower type than necessary is really a QoI thing:
>we just end up unrolling/interleaving the loop more times than
>necessary, and most tests wouldn't pick that up.  (Given the PRs
>about unrolling, it might accidentally be a good thing. :-))
>
>Tested on aarch64-linux-gnu (with and without SVE) and
>x86_64-linux-gnu.
>OK to install?

OK. 

Richard. 

>Richard
>
>
>2019-04-08  Richard Sandiford  
>
>gcc/
>   * tree-vect-data-refs.c (vect_get_smallest_scalar_type): Always
>   use gimple_expr_type for load and store calls.  Skip over the
>   condition argument in a conditional internal function.
>   Protect use of TREE_INT_CST_LOW.
>
>Index: gcc/tree-vect-data-refs.c
>===
>--- gcc/tree-vect-data-refs.c  2019-04-08 21:55:28.062370229 +0100
>+++ gcc/tree-vect-data-refs.c  2019-04-08 21:55:34.382348514 +0100
>@@ -145,14 +145,29 @@ vect_get_smallest_scalar_type (stmt_vec_
>   if (rhs < lhs)
> scalar_type = rhs_type;
> }
>-  else if (is_gimple_call (stmt_info->stmt)
>- && gimple_call_num_args (stmt_info->stmt) > 0)
>+  else if (gcall *call = dyn_cast  (stmt_info->stmt))
> {
>-  tree rhs_type = TREE_TYPE (gimple_call_arg (stmt_info->stmt,
>0));
>-
>-  rhs = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (rhs_type));
>-  if (rhs < lhs)
>-scalar_type = rhs_type;
>+  unsigned int i = 0;
>+  if (gimple_call_internal_p (call))
>+  {
>+internal_fn ifn = gimple_call_internal_fn (call);
>+if (internal_load_fn_p (ifn) || internal_store_fn_p (ifn))
>+  /* gimple_expr_type already picked the type of the loaded
>+ or stored data.  */
>+  i = ~0U;
>+else if (internal_fn_mask_index (ifn) == 0)
>+  i = 1;
>+  }
>+  if (i < gimple_call_num_args (call))
>+  {
>+tree rhs_type = TREE_TYPE (gimple_call_arg (call, i));
>+if (tree_fits_uhwi_p (TYPE_SIZE_UNIT (rhs_type)))
>+  {
>+rhs = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (rhs_type));
>+if (rhs < lhs)
>+  scalar_type = rhs_type;
>+  }
>+  }
> }
> 
>   *lhs_size_unit = lhs;



[committed] Fix typo in riscv diagnostics (PR target/90015)

2019-04-09 Thread Jakub Jelinek
Hi!

The following patch fixes a typo in diagnostics as well as removes
trailing dot.  Tested by Jim and also preapproved by him in the PR,
committed to trunk.

2019-04-09  Jakub Jelinek  

PR target/90015
* config/riscv/riscv.c (riscv_get_interrupt_type): Fix comment typo.
(riscv_merge_decl_attributes): Fix typo in diagnostics.  Remove
trailing period from it too.

* gcc.target/riscv/interrupt-conflict-mode.c (foo): Adjust expected
diagnostics.

--- gcc/config/riscv/riscv.c.jj 2019-03-27 12:41:41.369556065 +0100
+++ gcc/config/riscv/riscv.c2019-04-08 21:44:02.053600490 +0200
@@ -4736,7 +4736,7 @@ riscv_function_ok_for_sibcall (tree decl
   return true;
 }
 
-/* Get the intterupt type, return UNKNOWN_MODE if it's not
+/* Get the interrupt type, return UNKNOWN_MODE if it's not
interrupt function. */
 static enum riscv_privilege_levels
 riscv_get_interrupt_type (tree decl)
@@ -4822,7 +4822,7 @@ riscv_merge_decl_attributes (tree olddec
   if ((old_interrupt_type != UNKNOWN_MODE)
   && (new_interrupt_type != UNKNOWN_MODE)
   && (old_interrupt_type != new_interrupt_type))
-error ("%qs function cannot have different intterupt type.", "interrupt");
+error ("%qs function cannot have different interrupt type", "interrupt");
 
   /* Create combined attributes.  */
   combined_attrs = merge_attributes (DECL_ATTRIBUTES (olddecl),
--- gcc/testsuite/gcc.target/riscv/interrupt-conflict-mode.c.jj 2018-07-16 
09:42:22.772983004 +0200
+++ gcc/testsuite/gcc.target/riscv/interrupt-conflict-mode.c2019-04-08 
21:45:44.116948950 +0200
@@ -6,5 +6,5 @@ foo(void);
 
 void __attribute__ ((interrupt ("machine")))
 foo (void)
-{ /* { dg-error "function cannot have different intterupt type." } */
+{ /* { dg-error "function cannot have different interrupt type" } */
 }

Jakub