[committed] Fix mingw bootstrap (PR target/83536)

2017-12-31 Thread Jakub Jelinek
Hi!

These attributes are guarded by preprocessor conditionals and so
my error in the recent patch swapping handler and the bool flag went
unnoticed.

Fixed thusly, tested by building cross to mingw32, committed as obvious.
Sorry for the inconvenience.

2017-12-31  Jakub Jelinek  

PR target/83536
* config/i386/i386.c (ix86_attribute_table): Remove excess
initializer for "shared" attribute.

--- gcc/config/i386/i386.c.jj   2017-12-31 14:22:15.700946330 +0100
+++ gcc/config/i386/i386.c  2017-12-31 14:22:07.046941201 +0100
@@ -44747,7 +44747,7 @@ static const struct attribute_spec ix86_
   { "dllexport", 0, 0, false, false, false, false, handle_dll_attribute,
 NULL },
   { "shared",0, 0, true,  false, false, false,
-ix86_handle_shared_attribute, false, NULL },
+ix86_handle_shared_attribute, NULL },
 #endif
   { "ms_struct", 0, 0, false, false,  false, false,
 ix86_handle_struct_attribute, NULL },

Jakub


[patch, fortran] Implement simplification of minloc and maxloc

2017-12-31 Thread Thomas Koenig

Hello world,

the attached patch implements the simplification for minloc and maxloc.

I had considered using the existing simplify_transformation_to_array and
simplify_transformation_to_scalar functions, but it turned out
that the special casing required for minloc/maxloc was just too
complex, so I wrote new functions (mostly copying the old ones).

This closes a significant hole in F2003 - with this implemented,
only finalization is left as only partially implemented.

Regression-tested. OK for trunk?

Regards

Thomas

2017-12-31  Thomas Koenig  

PR fortran/45689
* intrinsic.c (add_function): Add gfc_simplify_maxloc and
gfc_simplify_minloc to maxloc and minloc, respectively.
* intrinsic.h: Add prototypes for gfc_simplify_minloc
and gfc_simplify_maxloc.
* simplify.c (min_max_chose): Adjust prototype.  Modify function
to have a return value which indicates if the extremum was found.
(...): Fix typo in comment.
(simplify_minmaxloc_to_scalar): New function.
(simplify_minmaxloc_nodim): New function.
(new_array): New function.
(simplify_minmaxloc_to_array): New function.
(gfc_simplify_minmaxloc): New function.
(simplify_minloc): New function.
(simplify_maxloc): New function.

2017-12-31  Thomas Koenig  

PR fortran/45689
* gfortran.dg/minloc_4.f90: New test case.
* gfortran.dg/maxloc_4.f90: New test case.
Index: intrinsic.c
===
--- intrinsic.c	(Revision 255788)
+++ intrinsic.c	(Arbeitskopie)
@@ -2458,7 +2458,7 @@ add_functions (void)
   make_generic ("maxexponent", GFC_ISYM_MAXEXPONENT, GFC_STD_F95);
 
   add_sym_4ml ("maxloc", GFC_ISYM_MAXLOC, CLASS_TRANSFORMATIONAL, ACTUAL_NO, BT_INTEGER, di, GFC_STD_F95,
-	   gfc_check_minloc_maxloc, NULL, gfc_resolve_maxloc,
+	   gfc_check_minloc_maxloc, gfc_simplify_maxloc, gfc_resolve_maxloc,
 	   ar, BT_REAL, dr, REQUIRED, dm, BT_INTEGER, ii, OPTIONAL,
 	   msk, BT_LOGICAL, dl, OPTIONAL, kind, BT_INTEGER, di, OPTIONAL);
 
@@ -2534,7 +2534,7 @@ add_functions (void)
   make_generic ("minexponent", GFC_ISYM_MINEXPONENT, GFC_STD_F95);
 
   add_sym_4ml ("minloc", GFC_ISYM_MINLOC, CLASS_TRANSFORMATIONAL, ACTUAL_NO, BT_INTEGER, di, GFC_STD_F95,
-	   gfc_check_minloc_maxloc, NULL, gfc_resolve_minloc,
+	   gfc_check_minloc_maxloc, gfc_simplify_minloc, gfc_resolve_minloc,
 	   ar, BT_REAL, dr, REQUIRED, dm, BT_INTEGER, ii, OPTIONAL,
 	   msk, BT_LOGICAL, dl, OPTIONAL, kind, BT_INTEGER, di, OPTIONAL);
 
Index: intrinsic.h
===
--- intrinsic.h	(Revision 255788)
+++ intrinsic.h	(Arbeitskopie)
@@ -347,8 +347,10 @@ gfc_expr *gfc_simplify_maskr (gfc_expr *, gfc_expr
 gfc_expr *gfc_simplify_merge (gfc_expr *, gfc_expr *, gfc_expr *);
 gfc_expr *gfc_simplify_merge_bits (gfc_expr *, gfc_expr *, gfc_expr *);
 gfc_expr *gfc_simplify_min (gfc_expr *);
+gfc_expr *gfc_simplify_minloc (gfc_expr*, gfc_expr *, gfc_expr *, gfc_expr *);
 gfc_expr *gfc_simplify_minval (gfc_expr *, gfc_expr*, gfc_expr*);
 gfc_expr *gfc_simplify_max (gfc_expr *);
+gfc_expr *gfc_simplify_maxloc (gfc_expr*, gfc_expr *, gfc_expr *, gfc_expr *);
 gfc_expr *gfc_simplify_maxval (gfc_expr *, gfc_expr*, gfc_expr*);
 gfc_expr *gfc_simplify_maxexponent (gfc_expr *);
 gfc_expr *gfc_simplify_minexponent (gfc_expr *);
Index: simplify.c
===
--- simplify.c	(Revision 255788)
+++ simplify.c	(Arbeitskopie)
@@ -31,7 +31,7 @@ along with GCC; see the file COPYING3.  If not see
 
 /* Prototypes.  */
 
-static void min_max_choose (gfc_expr *, gfc_expr *, int);
+static int min_max_choose (gfc_expr *, gfc_expr *, int);
 
 gfc_expr gfc_bad_expr;
 
@@ -230,7 +230,7 @@ convert_boz (gfc_expr *x, int kind)
 }
 
 
-/* Test that the expression is an constant array, simplifying if
+/* Test that the expression is a constant array, simplifying if
we are dealing with a parameter array.  */
 
 static bool
@@ -4414,25 +4414,34 @@ gfc_simplify_merge_bits (gfc_expr *i, gfc_expr *j,
 
 /* Selects between current value and extremum for simplify_min_max
and simplify_minval_maxval.  */
-static void
+static int
 min_max_choose (gfc_expr *arg, gfc_expr *extremum, int sign)
 {
+  int ret;
+
   switch (arg->ts.type)
 {
   case BT_INTEGER:
-	if (mpz_cmp (arg->value.integer,
-			extremum->value.integer) * sign > 0)
-	mpz_set (extremum->value.integer, arg->value.integer);
+	ret = mpz_cmp (arg->value.integer,
+		   extremum->value.integer) * sign;
+	if (ret > 0)
+	  mpz_set (extremum->value.integer, arg->value.integer);
 	break;
 
   case BT_REAL:
-	/* We need to use mpfr_min and mpfr_max to treat NaN properly.  */
-	if (sign > 0)
-	  mpfr_max (extremum->value.real, extremum->value.real,
-		  arg->value.real, GFC_RND_MODE);
+	if (mpfr_nan_p (extremum->value.real))
+	  {
+

Re: [PATCH] PR 78534 Change character length from int to size_t

2017-12-31 Thread Thomas Koenig

Hi Janne,


FWIW, by changing your example to use unformatted I/O, it works
correctly.


Not for me (again, on gcc110):

program main
  character(len=2_8**33), parameter :: a = ""
  write (10) a
end program main

with strace results in

open("fort.10", O_RDWR|O_CREAT|O_CLOEXEC, 0666) = 3
fstat(3, {st_mode=S_IFREG|0664, st_size=8, ...}) = 0
write(3, "\0\0\0\0\0\0\0\0", 8) = 8
ftruncate(3, 8) = 0
close(3)= 0

Regards

Thomas


Re: [C PATCH] Fix error recovery ICEs (PR c/83595)

2017-12-31 Thread Marek Polacek
On Sat, Dec 30, 2017 at 08:37:25PM +0100, Jakub Jelinek wrote:
> Hi!
> 
> As the patch shows, in lots of spots the C FE can return a c_expr
> with error_mark_node value, but uninitialized locations, so if something
> calls expr.get_location (), it can ICE.
> 
> Other spots are already using the set_error method which sets the value
> to error_mark_node and in addition to that clears the locations.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok.

Marek


Re: [PATCH] avoid using %lli et al.

2017-12-31 Thread Martin Sebor

Ping:

  https://gcc.gnu.org/ml/gcc-patches/2017-12/msg01399.html

On 12/20/2017 05:28 PM, Martin Sebor wrote:

On 12/20/2017 05:07 PM, Richard Sandiford wrote:

Martin Sebor  writes:

The attached patch replaces use of %lli and %llu with
HOST_WIDE_INT_PRINT_DEC and HOST_WIDE_INT_PRINT_UNSIGNED
for portability, and also replaces wide_int::to_shwi() with
offset_int::from().


Thanks for doing this.  I think you need to remove the (long long)
casts too though, so that the format stays in sync with the types.


Doh!  Thanks!  Had I waited for stage 2 bootstrap I suspect I would
have found out when it broke due to -Wformat complaining that
HOST_WIDE_INT_PRINT_DEC (%ld on my system) not matching the long
long argument.

Attached is the patch with the casts removed (still bootstrapping).

Martin




Re: [nvptx, committed] Disable -gstatement-frontiers for nvptx

2017-12-31 Thread Alexandre Oliva
On Dec 29, 2017, Tom de Vries  wrote:

> On 12/29/2017 05:12 AM, Alexandre Oliva wrote:
>> On Dec 27, 2017, Tom de Vries  wrote:
>> 
>>> .loc file_index line_number column_position
>> 
>>> so this causes ptxas errors when compiling something for nvptx with
>>> -g, which breaks the nvptx build.
>> 
>> What do the errors look like?

> 16  .loc 1 15 1 is_stmt 0

Oh, is_stmt is not a new assembler feature, nor is it one that's
introduced by SFN, but SFN does indeed get GCC to exercise it in cases
it didn't before, and that completely escaped me when I was surprised by
your previous email.  Thanks for the data, it clears it all up for me.

> If you point me to the location of a configure test that is supposed
> to file, I can try to find out why it passes.

Thanks, even the configure test for '.loc ... view' support is in the
LVU patch yet to be reviewed and installed.

Now, perhaps it would be wise to introduce a test for is_stmt support in
.loc directives, now that we know there are assemblers that don't
support it.

-- 
Alexandre Oliva, freedom fighterhttp://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer


Fix Bug 83566 - cyl_bessel_j returns wrong result for x>1000 for high orders

2017-12-31 Thread Michele Pezzutti

Hi.

This patch intends to fix Bug 83566 - cyl_bessel_j returns wrong result 
for x>1000 for high orders.

Seehttps://gcc.gnu.org/bugzilla/show_bug.cgi?id=83566 forissue description.

    * libstdc++-v3/include/tr1/bessel_function.tcc
  Series expansion in __cyl_bessel_jn_asymp() shall not be 
truncated at the first terms.
  At least nu/2 terms shall be added, in order to have a guaranteed 
error bound.


    * 
libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc

  Testcase for x > 1000 added.

    * 
libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/11_cyl_neumann/check_value.cc

Testcase for x > 1000 added.


diff --git a/libstdc++-v3/include/tr1/bessel_function.tcc 
b/libstdc++-v3/include/tr1/bessel_function.tcc

index 7ac733d..852a31e 100644
--- a/libstdc++-v3/include/tr1/bessel_function.tcc
+++ b/libstdc++-v3/include/tr1/bessel_function.tcc
@@ -359,15 +359,32 @@ namespace tr1
 __cyl_bessel_jn_asymp(_Tp __nu, _Tp __x, _Tp & __Jnu, _Tp & __Nnu)
 {
   const _Tp __mu   = _Tp(4) * __nu * __nu;
-  const _Tp __mum1 = __mu - _Tp(1);
-  const _Tp __mum9 = __mu - _Tp(9);
-  const _Tp __mum25 = __mu - _Tp(25);
-  const _Tp __mum49 = __mu - _Tp(49);
-  const _Tp __xx = _Tp(64) * __x * __x;
-  const _Tp __P = _Tp(1) - __mum1 * __mum9 / (_Tp(2) * __xx)
-    * (_Tp(1) - __mum25 * __mum49 / (_Tp(12) * __xx));
-  const _Tp __Q = __mum1 / (_Tp(8) * __x)
-    * (_Tp(1) - __mum9 * __mum25 / (_Tp(6) * __xx));
+  const _Tp __8x = _Tp(8) * __x;
+
+  _Tp __P = _Tp(1);
+  _Tp __Q = _Tp(0);
+
+  _Tp __eps = std::numeric_limits<_Tp>::epsilon();
+
+  _Tp __term = _Tp(1);
+  _Tp __epsP = _Tp(0);
+  _Tp __epsQ = _Tp(0);
+
+  unsigned long __2k;
+  for (unsigned long k = 1; k < 1000; k+=2) {
+  __2k = 2 * k;
+
+  __term *= (__mu - _Tp((__2k - 1) * (__2k - 1))) / (k * __8x);
+  __Q += __term;
+  __epsQ = std::abs(__term) < std::abs(__eps * __Q);
+
+  __term *= -(__mu - _Tp((__2k + 1) * (__2k + 1)))/ (_Tp(k + 1) 
* __8x);

+  __P += __term;
+  __epsP = std::abs(__term) < std::abs(__eps * __P);
+
+  if (__epsP && __epsQ && k > __nu / 2.)
+    break;
+  }

   const _Tp __chi = __x - (__nu + _Tp(0.5L))
 * __numeric_constants<_Tp>::__pi_2();


diff --git 
a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc 
b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc

index 26f4dd3..e340b78 100644
--- 
a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc
+++ 
b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc

@@ -698,6 +698,26 @@ data026[21] =
 };
 const double toler026 = 1.0006e-11;

+// Test data for nu=100.00.
+// max(|f - f_GSL|): 2.5857788132910287e-14
+// max(|f - f_GSL| / |f_GSL|): 1.6767662425535933e-11
+const testcase_cyl_bessel_j
+data027[11] =
+{
+  { 0.0116761350077845, 100., 1000. },
+  {-0.0116998547780258, 100., 1100. },
+  {-0.0228014834050837, 100., 1200. },
+  {-0.0169735007873739, 100., 1300. },
+  {-0.0014154528803530, 100., 1400. },
+  { 0.017265844988, 100., 1500. },
+  { 0.0198025620201474, 100., 1600. },
+  { 0.0161297712798388, 100., 1700. },
+  { 0.0053753369281577, 100., 1800. },
+  {-0.0069238868725646, 100., 1900. },
+  {-0.0154878717200738, 100., 2000. },
+};
+const double toler027 = 1.0006e-10;
+
 template
   void
   test(const testcase_cyl_bessel_j (&data)[Num], Ret toler)
@@ -748,5 +768,6 @@ main()
   test(data024, toler024);
   test(data025, toler025);
   test(data026, toler026);
+  test(data027, toler027);
   return 0;
 }


diff --git 
a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/11_cyl_neumann/check_value.cc 
b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/11_cyl_neumann/check_value.cc

index 5579149..9caf836 100644
--- 
a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/11_cyl_neumann/check_value.cc
+++ 
b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/11_cyl_neumann/check_value.cc

@@ -742,6 +742,26 @@ data028[20] =
 };
 const double toler028 = 1.0006e-11;

+// Test data for nu=100.00.
+// max(|f - f_GSL|): 3.1049815496508870e-14
+// max(|f - f_GSL| / |f_GSL|): 1.6767662425535933e-11
+const testcase_cyl_neumann
+data029[11] =
+{
+  {