[PATCH] PR fortran/87737 - ICE tree check: expected ssa_name, have addr_expr in remap_gimple_op_r, at tree-inline.c:923

2021-08-27 Thread Harald Anlauf via Fortran
Dear all,

the ICE in the original testcase does no longer occur but leads to an
error in a later stage of compilation, and we accepted invalid code.
(Cross-checked with other compilers, such as Intel and NAG).

F2018 states:

15.6.2.6  ENTRY statement

(3) ... If the characteristics of the result of the function named in the
ENTRY statement are the same as the characteristics of the result of the
function named in the FUNCTION statement, their result names identify the same
entity, although their names need not be the same. Otherwise, they are storage
associated and shall all be nonpointer, nonallocatable scalar variables that
are default integer, default real, double precision real, default complex, or
default logical.

We thus better reject the testcase example during resolution with an
appropriate error message.  (I hope the chosen one is fine enough.)

Regtested on x86_64-pc-linux-gnu.  OK for mainline?

Thanks,
Harald


Fortran - reject function entries with mismatched characteristics

gcc/fortran/ChangeLog:

PR fortran/87737
* resolve.c (resolve_entries): For functions of type CHARACTER
tighten the checks for matching characteristics.

gcc/testsuite/ChangeLog:

PR fortran/87737
* gfortran.dg/entry_24.f90: New test.

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 5b9ba43780e..f641d0d4dae 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -804,6 +804,15 @@ resolve_entries (gfc_namespace *ns)
 	 the same string length, i.e. both len=*, or both len=4.
 	 Having both len= is also possible, but difficult to
 	 check at compile time.  */
+	  else if (ts->type == BT_CHARACTER
+		   && (el->sym->result->attr.allocatable
+		   != ns->entries->sym->result->attr.allocatable))
+	{
+	  gfc_error ("Function %s at %L has entry %s with mismatched "
+			 "characteristics", ns->entries->sym->name,
+			 >entries->sym->declared_at, el->sym->name);
+	  return;
+	}
 	  else if (ts->type == BT_CHARACTER && ts->u.cl && fts->u.cl
 		   && (((ts->u.cl->length && !fts->u.cl->length)
 			||(!ts->u.cl->length && fts->u.cl->length))
diff --git a/gcc/testsuite/gfortran.dg/entry_24.f90 b/gcc/testsuite/gfortran.dg/entry_24.f90
new file mode 100644
index 000..9773597f4e1
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/entry_24.f90
@@ -0,0 +1,20 @@
+! { dg-do compile }
+! PR fortran/87737 - improve check on function entry characteristics
+
+function f() ! { dg-error "mismatched characteristics" }
+  character(:), allocatable :: f
+  character(1)  :: g
+  f = 'f'
+  return
+entry g()
+  g = 'g'
+end
+
+function f2() ! { dg-error "mismatched characteristics" }
+  character(1)  :: f2
+  character(1), allocatable :: g2
+  f2 = 'f'
+  return
+entry g2()
+  g2 = 'g'
+end


Fwd: FortranCon 2021

2021-08-27 Thread Thomas König

Hi,

I just received the mail below.  I will not be able to whip up
a presentation this time, but maybe somebody else will be able to -
maybe Tobias on the new OpenMP features?

Best regards

Thomas

 Forwarded Message 
Subject:FortranCon 2021
Date:   Fri, 27 Aug 2021 12:55:01 +
From:   Lazzaro, Alfio 
To: t...@tkoenig.net
CC: 	Muller, Tiziano , Richardson, Harvey 





Dear Fortran developer,

We are directly contacting you because you gave a presentation at the 
FortranCon 2020. The call for abstracts for the 2021 edition is out 
(next deadline is rapidly approaching: September 1^st , but likely we 
will extend it by 3-4 days):


https://tcevents.chem.uzh.ch/event/14/ 



There are still some available slots for presentations following close 
of the first call.


Please consider submitting an abstract if you would like to show an 
update of our activity or if you would like to present a new topic.


Best regards,

Alfio and Tiziano

(Steering committee)



Re: [RFH] ME optimizes variable assignment away / Fortran bind(C) descriptor conversion

2021-08-27 Thread Tobias Burnus

On 27.08.21 17:47, Tobias Burnus wrote at
https://gcc.gnu.org/pipermail/gcc-patches/2021-August/578271.html :


PS: Current GCC (mainline w/o patch) generates the following.
[-> with patch, see a-test.f90.*.original.]


I accidentally attached the original dump created by mainline GCC.

For the patched compiler, I did attach the optimized dumps. For
reference, this email now contains the original dump generated with my
patch applied.

Tobias

-
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
München, HRB 106955
__attribute__((fn spec (". . ")))
integer(kind=4) rank_p (struct CFI_cdesc_t & _this)
{
  struct array15_integer(kind=4) this.0;
  struct array15_integer(kind=4) * this;
  signed char idx.1;
  integer(kind=4) rnk;

  this = 
  this.0.dtype = {.elem_len=4, .type=1};
  this.0.data = _this->base_addr;
  this.0.dtype.rank = _this->rank;
  if (_this->base_addr != 0B)
{
  this.0.span = _this->dim[0].sm % (integer(kind=8)) _this->elem_len != 0 ? 
_this->dim[0].sm : (integer(kind=8)) _this->elem_len;
  this.0.offset = 0;
  idx.1 = 0;
  L.1:;
  if (_this->rank <= idx.1) goto L.2;
  this.0.dim[idx.1].lbound = _this->dim[idx.1].lower_bound;
  this.0.dim[idx.1].ubound = _this->dim[idx.1].extent + 
(this.0.dim[idx.1].lbound + -1);
  this.0.dim[idx.1].stride = _this->dim[idx.1].sm / (integer(kind=8)) 
_this->elem_len;
  this.0.offset = this.0.offset - this.0.dim[idx.1].stride * 
this.0.dim[idx.1].lbound;
  idx.1 = idx.1 + 1;
  goto L.1;
  L.2:;
}
  rnk = (integer(kind=4)) this->dtype.rank;
  return rnk;
}


__attribute__((fn spec (". ")))
void selr_p ()
{
  struct array01_integer(kind=4) intp;
  integer(kind=4) irnk;
  static integer(kind=4) rnk = 1;

  intp.dtype = {.elem_len=4, .rank=1, .type=1};
  intp.span = 0;
  intp.data = 0B;
  {
struct CFI_cdesc_t01 cfi.2;
signed char idx.3;

cfi.2.version = 1;
cfi.2.rank = 1;
cfi.2.type = 1025;
cfi.2.attribute = 0;
cfi.2.base_addr = intp.data;
cfi.2.elem_len = 4;
if (cfi.2.base_addr != 0B)
  {
idx.3 = 0;
L.3:;
if (idx.3 > 0) goto L.4;
cfi.2.dim[idx.3].lower_bound = intp.dim[idx.3].lbound;
cfi.2.dim[idx.3].extent = (intp.dim[idx.3].ubound - 
intp.dim[idx.3].lbound) + 1;
cfi.2.dim[idx.3].sm = intp.dim[idx.3].stride * intp.span;
idx.3 = idx.3 + 1;
goto L.3;
L.4:;
  }
irnk = rank_p ();
  }
  if (irnk != rnk)
{
  _gfortran_stop_numeric (1, 0);
}
  L.5:;
  if (irnk != 1)
{
  _gfortran_stop_numeric (2, 0);
}
  L.6:;
}


__attribute__((externally_visible))
integer(kind=4) main (integer(kind=4) argc, character(kind=1) * * argv)
{
  static integer(kind=4) options.4[7] = {2116, 4095, 0, 1, 1, 0, 31};

  _gfortran_set_args (argc, argv);
  _gfortran_set_options (7, [0]);
  selr_p ();
  return 0;
}




Re: [PATCH] libgfortran : Use the libtool macro to determine libm availability.

2021-08-27 Thread Iain Sandoe



> On 22 Aug 2021, at 09:44, Iain Sandoe  wrote:
> 
> 
> 
>> On 21 Aug 2021, at 23:18, Eric Gallager  wrote:
>> 
>> On Fri, Aug 20, 2021 at 3:53 AM Tobias Burnus  
>> wrote:
>>> 
>>> On 20.08.21 09:34, Richard Biener via Fortran wrote:
>>> 
 On Thu, Aug 19, 2021 at 10:10 PM Iain Sandoe  wrote:
> libm is not needed on Darwin, and should not be added unconditionally
> even if that is (mostly) harmless since it is a symlink to libc.
> 
> tested on x86_64, i686-darwin, x86_64-linux,
> OK for master?
 OK.
 Richard.
>>> 
>>> Looks also good to me – but for completeness and as background, I also
>>> want to remark the following.
>>> 
>>> (At least as I understand it, I did not dig deeper.)
>>> 
 --- a/libgfortran/configure.ac
 +++ b/libgfortran/configure.ac
 ...
 +AC_CHECK_LIBM
>>> 
>>> This CHECK_LIBM has a hard-coded list of targets and for some (like
>>> Darwin) it simply does not set $LIBM.
>> 
>> I thought the proper macro to use was LT_LIB_M ?
> 
> you could well be right, libtool.m4 contains:
> 
> # Old name:
> AU_ALIAS([AC_CHECK_LIBM], [LT_LIB_M])
> 
> I guess the patch can be changed and then do another round of testing …
> … will add this to the TODO, and withdraw the current patch.

this is what I pushed after retesting (with the extras space removed too):

==
libgfortran: Use the libtool macro to determine libm
 availability.

We recently had a report of build failure against a Darwin branch on
the latest OS release.  This was because (temporarily) the symlink
from libm.dylib => libSystem.dylib had been removed/omitted.

libm is not needed on Darwin, and should not be added unconditionally
even if that is (mostly) harmless since it is a symlink to libc.

There could be cases where the addition was not completely harmless
because the presentation of the symlink would cause the symbols exposed
in libSystem to be considered ahead of ones presented in convenience
libraries.

libgfortran/ChangeLog:

* Makefile.am: Use configured libm availability.
* Makefile.in: Regenerate.
* configure: Regenerate.
* configure.ac: Use libtool macro to find libm availability.
* libgfortran.spec.in: Use configured libm availability.
---
 libgfortran/Makefile.am |   2 +-
 libgfortran/Makefile.in |   3 +-
 libgfortran/configure   | 146 +++-
 libgfortran/configure.ac|   1 +
 libgfortran/libgfortran.spec.in |   2 +-
 5 files changed, 149 insertions(+), 5 deletions(-)

diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am
index 8d104321567..6fc4b465c6e 100644
--- a/libgfortran/Makefile.am
+++ b/libgfortran/Makefile.am
@@ -42,7 +42,7 @@ libgfortran_la_LINK = $(LINK) $(libgfortran_la_LDFLAGS)
 libgfortran_la_LDFLAGS = -version-info `grep -v '^\#' 
$(srcdir)/libtool-version` \
$(LTLDFLAGS) $(LIBQUADLIB) ../libbacktrace/libbacktrace.la \
$(HWCAP_LDFLAGS) \
-   -lm $(extra_ldflags_libgfortran) \
+   $(LIBM) $(extra_ldflags_libgfortran) \
$(version_arg) -Wc,-shared-libgcc
 libgfortran_la_DEPENDENCIES = $(version_dep) libgfortran.spec $(LIBQUADLIB_DEP)
  
 
diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac
index 523eb24bca1..a77509801e6 100644
--- a/libgfortran/configure.ac
+++ b/libgfortran/configure.ac
@@ -260,6 +260,7 @@ AC_PROG_INSTALL
 #AC_MSG_NOTICE([== Starting libtool configuration])
 AC_LIBTOOL_DLOPEN
 AM_PROG_LIBTOOL
+LT_LIB_M
 ACX_LT_HOST_FLAGS
 AC_SUBST(enable_shared)
 AC_SUBST(enable_static)
diff --git a/libgfortran/libgfortran.spec.in b/libgfortran/libgfortran.spec.in
index 95aa3f842a3..367d485c230 100644
--- a/libgfortran/libgfortran.spec.in
+++ b/libgfortran/libgfortran.spec.in
@@ -5,4 +5,4 @@
 #
 
 %rename lib liborig
-*lib: @LIBQUADSPEC@ -lm %(libgcc) %(liborig)
+*lib: @LIBQUADSPEC@ @LIBM@ %(libgcc) %(liborig)
-- 
2.24.3 (Apple Git-128)