[patch, wwwdocs, committed] Fix option name in gcc15/changes.html

2025-05-03 Thread Thomas Koenig

Hello world,

I just committed the following patch after noticing that an option name
was wrong in the gcc15/changes.html file.

diff --git a/htdocs/gcc-15/changes.html b/htdocs/gcc-15/changes.html
index d851a744..b442b8d9 100644
--- a/htdocs/gcc-15/changes.html
+++ b/htdocs/gcc-15/changes.html
@@ -738,7 +738,7 @@ asm (".text; %cc0: mov %cc2, %%r0; .previous;"
   is not affected, because it provides backwards compatibility 
with the

   older ABI.
   
-The -Wexternal-interface-mismatch option has been
+The -Wexternal-arguments-mismatch option has been
 added.  This checks for mismatches between the argument lists in
 dummy external arguments, and is implied by -Wall
 and -fc-prototypes-external options.



[patch, Fortran] Fix PR 119928, rejects-valid 15/16 regression

2025-05-03 Thread Thomas Koenig

Hello world,

This patch fixes a case where too much was being checked with
-Wexternal-arguments-mismatch with a procedure pointer with an
unlimited polymorphic and an INTEGER argument which was inferred from
an actual argument.I also found some checks which can trigger false
positives, which this patch also excludes from testing.

Regression-tested.

OK for trunk and backport to gcc-15?

Best regards

Thomas

gcc/fortran/ChangeLog:

PR fortran/119928
* interface.cc (gfc_check_dummy_characteristics): Do not issue
error for type if one argument is an unlimited polymorphic entity
and the other one has been generated from an actual argument.
Do not check OPTIONAL, INTENT, ALLOCATABLE, POINTER, TARGET, VALUE,
ASYNCHRONOUS or CONTIGUOUS if one of the arguments has been
generated from an actual argument.

gcc/testsuite/ChangeLog:

PR fortran/119928
* gfortran.dg/interface_60.f90: New test.
diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc
index 1e552a3df86..af955fd2ff9 100644
--- a/gcc/fortran/interface.cc
+++ b/gcc/fortran/interface.cc
@@ -1387,8 +1387,10 @@ gfc_check_dummy_characteristics (gfc_symbol *s1, gfc_symbol *s2,
   /* Check type and rank.  */
   if (type_must_agree)
 {
-  if (!compare_type_characteristics (s1, s2)
-	  || !compare_type_characteristics (s2, s1))
+  if ((!compare_type_characteristics (s1, s2)
+	   || !compare_type_characteristics (s2, s1))
+	  && !((s1->attr.artificial && UNLIMITED_POLY(s2))
+	   || (s2->attr.artificial && UNLIMITED_POLY(s1
 	{
 	  snprintf (errmsg, err_len, "Type mismatch in argument '%s' (%s/%s)",
 		s1->name, gfc_dummy_typename (&s1->ts),
@@ -1403,77 +1405,82 @@ gfc_check_dummy_characteristics (gfc_symbol *s1, gfc_symbol *s2,
 	}
 }
 
-  /* Check INTENT.  */
-  if (s1->attr.intent != s2->attr.intent && !s1->attr.artificial
-  && !s2->attr.artificial)
-{
-  snprintf (errmsg, err_len, "INTENT mismatch in argument '%s'",
-		s1->name);
-  return false;
-}
+  /* A lot of information is missing for artificially generated
+ formal arguments, let's not look into that.  */
 
-  /* Check OPTIONAL attribute.  */
-  if (s1->attr.optional != s2->attr.optional)
+  if (!s1->attr.artificial && !s2->attr.artificial)
 {
-  snprintf (errmsg, err_len, "OPTIONAL mismatch in argument '%s'",
-		s1->name);
-  return false;
-}
+  /* Check INTENT.  */
+  if (s1->attr.intent != s2->attr.intent)
+	{
+	  snprintf (errmsg, err_len, "INTENT mismatch in argument '%s'",
+		s1->name);
+	  return false;
+	}
 
-  /* Check ALLOCATABLE attribute.  */
-  if (s1->attr.allocatable != s2->attr.allocatable)
-{
-  snprintf (errmsg, err_len, "ALLOCATABLE mismatch in argument '%s'",
-		s1->name);
-  return false;
-}
+  /* Check OPTIONAL attribute.  */
+  if (s1->attr.optional != s2->attr.optional)
+	{
+	  snprintf (errmsg, err_len, "OPTIONAL mismatch in argument '%s'",
+		s1->name);
+	  return false;
+	}
 
-  /* Check POINTER attribute.  */
-  if (s1->attr.pointer != s2->attr.pointer)
-{
-  snprintf (errmsg, err_len, "POINTER mismatch in argument '%s'",
-		s1->name);
-  return false;
-}
+  /* Check ALLOCATABLE attribute.  */
+  if (s1->attr.allocatable != s2->attr.allocatable)
+	{
+	  snprintf (errmsg, err_len, "ALLOCATABLE mismatch in argument '%s'",
+		s1->name);
+	  return false;
+	}
 
-  /* Check TARGET attribute.  */
-  if (s1->attr.target != s2->attr.target)
-{
-  snprintf (errmsg, err_len, "TARGET mismatch in argument '%s'",
-		s1->name);
-  return false;
-}
+  /* Check POINTER attribute.  */
+  if (s1->attr.pointer != s2->attr.pointer)
+	{
+	  snprintf (errmsg, err_len, "POINTER mismatch in argument '%s'",
+		s1->name);
+	  return false;
+	}
 
-  /* Check ASYNCHRONOUS attribute.  */
-  if (s1->attr.asynchronous != s2->attr.asynchronous)
-{
-  snprintf (errmsg, err_len, "ASYNCHRONOUS mismatch in argument '%s'",
-		s1->name);
-  return false;
-}
+  /* Check TARGET attribute.  */
+  if (s1->attr.target != s2->attr.target)
+	{
+	  snprintf (errmsg, err_len, "TARGET mismatch in argument '%s'",
+		s1->name);
+	  return false;
+	}
 
-  /* Check CONTIGUOUS attribute.  */
-  if (s1->attr.contiguous != s2->attr.contiguous)
-{
-  snprintf (errmsg, err_len, "CONTIGUOUS mismatch in argument '%s'",
-		s1->name);
-  return false;
-}
+  /* Check ASYNCHRONOUS attribute.  */
+  if (s1->attr.asynchronous != s2->attr.asynchronous)
+	{
+	  snprintf (errmsg, err_len, "ASYNCHRONOUS mismatch in argument '%s'",
+		s1->name);
+	  return false;
+	}
 
-  /* Check VALUE attribute.  */
-  if (s1->attr.value != s2->attr.value)
-{
-  snprintf (errmsg, err_len, "VALUE mismatch in argument '%s'",
-		s1->name);
-  return false;
-}
+  /* Check CONTIGUOUS attribute.  */
+  if (s1->attr.contiguous != s2->attr

Re: [patch, Fortran] Fix PR 119928, rejects-valid 15/16 regression

2025-05-03 Thread Harald Anlauf

Hi Thomas,

I haven't tested your patch very thorougly, but when manually
compiling

% gfc-16 gcc/testsuite/gfortran.dg/proc_ptr_52.f90 
-Wexternal-argument-mismatch && ./a.out

STOP 1

It appears that something is not right and generates wrong code with
the check enabled.  Can you have another look?

Cheers,
Harald

Am 03.05.25 um 11:11 schrieb Thomas Koenig:

Hello world,

This patch fixes a case where too much was being checked with
-Wexternal-arguments-mismatch with a procedure pointer with an
unlimited polymorphic and an INTEGER argument which was inferred from
an actual argument.I also found some checks which can trigger false
positives, which this patch also excludes from testing.

Regression-tested.

OK for trunk and backport to gcc-15?

Best regards

 Thomas

gcc/fortran/ChangeLog:

 PR fortran/119928
 * interface.cc (gfc_check_dummy_characteristics): Do not issue
 error for type if one argument is an unlimited polymorphic entity
 and the other one has been generated from an actual argument.
 Do not check OPTIONAL, INTENT, ALLOCATABLE, POINTER, TARGET, VALUE,
 ASYNCHRONOUS or CONTIGUOUS if one of the arguments has been
 generated from an actual argument.

gcc/testsuite/ChangeLog:

 PR fortran/119928
 * gfortran.dg/interface_60.f90: New test.




Re: [patch, Fortran] Fix PR 119928, rejects-valid 15/16 regression

2025-05-03 Thread Thomas Koenig

Hello Harald,


% gfc-16 gcc/testsuite/gfortran.dg/proc_ptr_52.f90 -Wexternal-argument- 
mismatch && ./a.out

STOP 1

It appears that something is not right and generates wrong code with
the check enabled.  Can you have another look?


I see that too, good catch!

Seems like generating formal arguments from the actual arguments
confuses resolution.

I'll look into it.

Best regards

Thomas




[PATCH] Fortran: array subreferences and components of derived types [PR119986]

2025-05-03 Thread Harald Anlauf

Dear all,

the attached, semi-obvious patch fixes bugging issues with passing of
array subreferences when either an inquiry reference to a complex array
or a substring reference to a character array was involved, and the
array was a component of a derived type.  The obvious cause was always
an early termination of the scan of the reference.

The original PR was about complex issues, but since I was aware of
a similar issue for substrings, I fixed that at the same time.

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

As this is a hideous wrong-code bug, I'd like to backport
to at least 15-branch, if this is ok.

Thanks,
Harald

From 8d49cd9e0fe76d2c45495017cb87588e9b9824cf Mon Sep 17 00:00:00 2001
From: Harald Anlauf 
Date: Sat, 3 May 2025 20:35:57 +0200
Subject: [PATCH] Fortran: array subreferences and components of derived types
 [PR119986]

	PR fortran/119986

gcc/fortran/ChangeLog:

	* expr.cc (is_subref_array): When searching for array references,
	do not terminate early so that inquiry references to complex
	components work.
	* primary.cc (gfc_variable_attr): A substring reference can refer
	to either a scalar or array character variable.  Adjust search
	accordingly.

gcc/testsuite/ChangeLog:

	* gfortran.dg/actual_array_subref.f90: New test.
---
 gcc/fortran/expr.cc   |   1 +
 gcc/fortran/primary.cc|  13 ++-
 .../gfortran.dg/actual_array_subref.f90   | 103 ++
 3 files changed, 113 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/actual_array_subref.f90

diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index 07e9bac37a1..92a9ebdcbe8 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -1194,6 +1194,7 @@ is_subref_array (gfc_expr * e)
 	 what follows cannot be a subreference array, unless there is a
 	 substring reference.  */
   if (!seen_array && ref->type == REF_COMPONENT
+	  && ref->next == NULL
 	  && ref->u.c.component->ts.type != BT_CHARACTER
 	  && ref->u.c.component->ts.type != BT_CLASS
 	  && !gfc_bt_struct (ref->u.c.component->ts.type))
diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc
index 161d4c26964..72ecc7ccf93 100644
--- a/gcc/fortran/primary.cc
+++ b/gcc/fortran/primary.cc
@@ -2893,6 +2893,7 @@ gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts)
   gfc_symbol *sym;
   gfc_component *comp;
   bool has_inquiry_part;
+  bool has_substring_ref = false;
 
   if (expr->expr_type != EXPR_VARIABLE
   && expr->expr_type != EXPR_FUNCTION
@@ -2955,7 +2956,12 @@ gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts)
 
   has_inquiry_part = false;
   for (ref = expr->ref; ref; ref = ref->next)
-if (ref->type == REF_INQUIRY)
+if (ref->type == REF_SUBSTRING)
+  {
+	has_substring_ref = true;
+	optional = false;
+  }
+else if (ref->type == REF_INQUIRY)
   {
 	has_inquiry_part = true;
 	optional = false;
@@ -3003,9 +3009,8 @@ gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts)
 	*ts = comp->ts;
 	/* Don't set the string length if a substring reference
 	   follows.  */
-	if (ts->type == BT_CHARACTER
-		&& ref->next && ref->next->type == REF_SUBSTRING)
-		ts->u.cl = NULL;
+	if (ts->type == BT_CHARACTER && has_substring_ref)
+	  ts->u.cl = NULL;
 	  }
 
 	if (comp->ts.type == BT_CLASS)
diff --git a/gcc/testsuite/gfortran.dg/actual_array_subref.f90 b/gcc/testsuite/gfortran.dg/actual_array_subref.f90
new file mode 100644
index 000..932d7aba121
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/actual_array_subref.f90
@@ -0,0 +1,103 @@
+! { dg-do run }
+! { dg-additional-options "-O2 -fcheck=bounds" }
+!
+! PR fortran/119986
+!
+! Check passing of inquiry references of complex arrays and substring
+! references of character arrays when these are components of derived types.
+!
+! Extended version of report by Neil Carlson.
+
+program main
+  implicit none
+  integer :: j
+
+  complex, parameter  :: z0(*) = [(cmplx(j,-j),j=1,4)]
+  type :: cx
+ real :: re
+ real :: im
+  end type cx
+  type(cx), parameter :: c0(*) = [(cx   (j,-j),j=1,4)]
+
+  type :: my_type
+ complex  :: z(4) = z0
+ type(cx) :: c(4) = c0
+  end type my_type
+  type(my_type) :: x
+
+  character(*), parameter :: s0(*) = ["abcd","efgh","ijkl","mnop"]
+  character(*), parameter :: expect(*) = s0(:)(2:3)
+  character(len(s0))  :: s1(4) = s0
+
+  type :: str1
+ character(len(s0))   :: s(4)  = s0
+  end type str1
+  type(str1) :: string1
+
+  type :: str2
+ character(:), allocatable :: s(:)
+  end type str2
+  type(str2) :: string2
+
+  integer :: stopcode = 0
+
+  if (len(expect) /= 2)stop 1
+  if (expect(4)   /= "no") stop 2
+  if (any(c0 %re  /= [ 1, 2, 3, 4])) stop 3
+  if (any(c0 %im  /= [-1,-2,-3,-4])) stop 4
+
+  stopcode = 10
+  call fubar ( x%z %re, x%z %im)
+  call fubar ( x%c %re, x%c %im)
+
+  stopcode = 20
+  call fubar ((x%z %re), (x%z %im))
+  call fubar ((x%c %re), (x%c %im))
+
+  stopcode = 30
+  call fubar ([x%z %r