Re: [patch] Fix PR libfortran/95177, ctype.h functions should not be called with char arguments

2021-12-18 Thread Thomas Koenig via Fortran

On 17.12.21 00:34, FX via Fortran wrote:

unrelated PS: I’ve been thinking aloud and benchmarking faster integer I/O for 
libgfortran at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98076
Comments are welcome on the proposed design, I think the current proposal is a 
low-hanging fruit (not risky, much faster).


Quick test integrating the idea into libgfortran, here are the timings to make 
a formatted write of 10 million integers into a string:

- very small value (1), negligible speedup (2.273s to 2.248s)
- small value (1042), speedup of 28% (3.224s to 2.350s)
- huge(0_8), speed up of 50% (5.914s to 2.560s)
- huge(0_16), speed up of 83% (19.46s to 3.31s)

Conclusion: this looks quite interesting!


Yes indeed.

I’m not sure what use cases people have for writing lots of formatted integers, 
but this doesn’t sound too bad.


If there is an obvoius speed-up to be had, we should go for it, for
a) the coolness value and
b) because somebody might need it :-)



Further thought: fast 64-bit itoa() implementations, under the MIT license 
(https://github.com/jeaiii/itoa) promise a speed-up of 2 to 10 times compared 
to naive implementation. That could bring us down further, but we probably 
cannot incorporate that, right?


Not sure about that.  We could reverse-engineer the algorithm,
if necessary (and if we are convinced that it is mathematically
correct :-)



Two questions:

1. This is easy, am I missing something? Some reason why it was never tried 
before?


Round tuits seem to have been lacking :-)


2. Why is gfc_xtoa() in runtime/error.c? We should probably move it.


No idea, and yes.


[PATCH, committed] PR fortran/103412 - [10/11/12 Regression] ICE: Invalid expression in gfc_element_size since r10-2083-g8dc63166e0b85954

2021-12-18 Thread Harald Anlauf via Fortran
Dear all,

committed as obvious after discussion with Steve: SIZEOF() cannot
accept a BOZ argument which has no defined type.

Regtested on x86_64-pc-linux-gnu.

Thanks,
Harald

From fd74a2ee40456a1d1621e88738f8e57536194080 Mon Sep 17 00:00:00 2001
From: Harald Anlauf 
Date: Sat, 18 Dec 2021 23:21:35 +0100
Subject: [PATCH] Fortran: reject BOZ type argument to SIZEOF().

gcc/fortran/ChangeLog:

	PR fortran/103412
	* check.c (gfc_check_sizeof): Reject BOZ type argument.

gcc/testsuite/ChangeLog:

	PR fortran/103412
	* gfortran.dg/illegal_boz_arg_2.f90: New test.
---
 gcc/fortran/check.c | 3 +++
 gcc/testsuite/gfortran.dg/illegal_boz_arg_2.f90 | 6 ++
 2 files changed, 9 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/illegal_boz_arg_2.f90

diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index 3934336df2e..625473c90d1 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -5135,6 +5135,9 @@ gfc_check_sizeof (gfc_expr *arg)
   return false;
 }

+  if (illegal_boz_arg (arg))
+return false;
+
   /* TYPE(*) is acceptable if and only if it uses an array descriptor.  */
   if (arg->ts.type == BT_ASSUMED
   && (arg->symtree->n.sym->as == NULL
diff --git a/gcc/testsuite/gfortran.dg/illegal_boz_arg_2.f90 b/gcc/testsuite/gfortran.dg/illegal_boz_arg_2.f90
new file mode 100644
index 000..3e5f6b6d1d4
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/illegal_boz_arg_2.f90
@@ -0,0 +1,6 @@
+! { dg-do compile }
+! PR fortran/103412
+
+program p
+  integer, parameter :: a = sizeof(z'1') ! { dg-error "cannot be an actual" }
+end
--
2.26.2