* [Patch] Fortran: Fix func decl mismatch [PR93660]
@ 2021-03-11 17:15 Tobias Burnus
2021-03-14 11:04 ` Early ping: " Tobias Burnus
2021-03-23 14:43 ` Paul Richard Thomas
0 siblings, 2 replies; 4+ messages in thread
From: Tobias Burnus @ 2021-03-11 17:15 UTC (permalink / raw)
To: gcc-patches, fortran
[-- Attachment #1: Type: text/plain, Size: 407 bytes --]
This fixes an ICE with OpenMP 'omp decare simd' but is a generic bug.
Namely TREE_TYPE(fndecl) has a mismatch to the arglist chain,
missing some hidden arguments with -fcoarray=lib.
OK for mainline and GCC 10?
Tobias
-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf
[-- Attachment #2: fndecl.diff --]
[-- Type: text/x-patch, Size: 4152 bytes --]
Fortran: Fix func decl mismatch [PR93660]
gcc/fortran/ChangeLog:
PR fortran/93660
* trans-decl.c (build_function_decl): Add comment;
increment hidden_typelist for caf_token/caf_offset.
* trans-types.c (gfc_get_function_type): Add comment;
add missing caf_token/caf_offset args.
gcc/testsuite/ChangeLog:
PR fortran/93660
* gfortran.dg/gomp/declare-simd-coarray-lib.f90: New test.
gcc/fortran/trans-decl.c | 6 +++++-
gcc/fortran/trans-types.c | 21 ++++++++++++++++++++-
.../gfortran.dg/gomp/declare-simd-coarray-lib.f90 | 12 ++++++++++++
3 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index 6a4ed9bbfdd..34a0d49bae7 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -2488,7 +2488,9 @@ build_function_decl (gfc_symbol * sym, bool global)
}
-/* Create the DECL_ARGUMENTS for a procedure. */
+/* Create the DECL_ARGUMENTS for a procedure.
+ NOTE: The arguments added here must match the argument type created by
+ gfc_get_function_type (). */
static void
create_function_arglist (gfc_symbol * sym)
@@ -2807,6 +2809,7 @@ create_function_arglist (gfc_symbol * sym)
DECL_ARG_TYPE (token) = TREE_VALUE (typelist);
TREE_READONLY (token) = 1;
hidden_arglist = chainon (hidden_arglist, token);
+ hidden_typelist = TREE_CHAIN (hidden_typelist);
gfc_finish_decl (token);
offset = build_decl (input_location, PARM_DECL,
@@ -2832,6 +2835,7 @@ create_function_arglist (gfc_symbol * sym)
DECL_ARG_TYPE (offset) = TREE_VALUE (typelist);
TREE_READONLY (offset) = 1;
hidden_arglist = chainon (hidden_arglist, offset);
+ hidden_typelist = TREE_CHAIN (hidden_typelist);
gfc_finish_decl (offset);
}
diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c
index ccdc4687c39..bc7aac1f3d9 100644
--- a/gcc/fortran/trans-types.c
+++ b/gcc/fortran/trans-types.c
@@ -3011,6 +3011,10 @@ create_fn_spec (gfc_symbol *sym, tree fntype)
return build_type_attribute_variant (fntype, tmp);
}
+
+/* NOTE: The returned function type must match the argument list created by
+ create_function_arglist. */
+
tree
gfc_get_function_type (gfc_symbol * sym, gfc_actual_arglist *actual_args,
const char *fnspec)
@@ -3119,10 +3123,11 @@ gfc_get_function_type (gfc_symbol * sym, gfc_actual_arglist *actual_args,
}
}
- /* Add hidden string length parameters. */
+ /* Add hidden arguments. */
for (f = gfc_sym_get_dummy_args (sym); f; f = f->next)
{
arg = f->sym;
+ /* Add hidden string length parameters. */
if (arg && arg->ts.type == BT_CHARACTER && !sym->attr.is_bind_c)
{
if (!arg->ts.deferred)
@@ -3145,6 +3150,20 @@ gfc_get_function_type (gfc_symbol * sym, gfc_actual_arglist *actual_args,
&& arg->ts.type != BT_CLASS
&& !gfc_bt_struct (arg->ts.type))
vec_safe_push (typelist, boolean_type_node);
+ /* Coarrays which are descriptorless or assumed-shape pass with
+ -fcoarray=lib the token and the offset as hidden arguments. */
+ else if (arg
+ && flag_coarray == GFC_FCOARRAY_LIB
+ && ((arg->ts.type != BT_CLASS
+ && arg->attr.codimension
+ && !arg->attr.allocatable)
+ || (arg->ts.type == BT_CLASS
+ && CLASS_DATA (arg)->attr.codimension
+ && !CLASS_DATA (arg)->attr.allocatable)))
+ {
+ vec_safe_push (typelist, pvoid_type_node); /* caf_token. */
+ vec_safe_push (typelist, gfc_array_index_type); /* caf_offset. */
+ }
}
if (!vec_safe_is_empty (typelist)
diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-simd-coarray-lib.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-simd-coarray-lib.f90
new file mode 100644
index 00000000000..1f74da76ffe
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/declare-simd-coarray-lib.f90
@@ -0,0 +1,12 @@
+! { dg-additional-options "-fcoarray=lib" }
+!
+! PR fortran/93660
+!
+! Failed as TREE_TYPE(fndecl) did not include the
+! hidden caf_token/caf_offset arguments.
+!
+integer function f(x)
+ integer :: x[*]
+ !$omp declare simd
+ f = x[1]
+end
^ permalink raw reply [flat|nested] 4+ messages in thread
* Early ping: Re: [Patch] Fortran: Fix func decl mismatch [PR93660]
2021-03-11 17:15 [Patch] Fortran: Fix func decl mismatch [PR93660] Tobias Burnus
@ 2021-03-14 11:04 ` Tobias Burnus
2021-03-18 8:56 ` *PING*: " Tobias Burnus
2021-03-23 14:43 ` Paul Richard Thomas
1 sibling, 1 reply; 4+ messages in thread
From: Tobias Burnus @ 2021-03-14 11:04 UTC (permalink / raw)
To: gcc-patches, fortran
Early ping – and minor post script:
+ hidden_typelist = TREE_CHAIN (hidden_typelist);
This change is to avoid running into the ICE:
gcc_assert (hidden_typelist == NULL_TREE
|| TREE_VALUE (hidden_typelist) == void_type_node);
The purpose of this assert is to check that the TREE_TYPE (fndecl)
arg list and the one created by
create_function_arglist (gfc_symbol * sym)
are the same (at least in terms of the number of arguments). Namely:
typelist = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
...
hidden_typelist = typelist;
Tobias
On 11.03.21 18:15, Tobias Burnus wrote:
> This fixes an ICE with OpenMP 'omp decare simd' but is a generic bug.
>
> Namely TREE_TYPE(fndecl) has a mismatch to the arglist chain,
> missing some hidden arguments with -fcoarray=lib.
>
> OK for mainline and GCC 10?
>
> Tobias
>
> -----------------
> Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München
> Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung,
> Frank Thürauf
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: *PING*: Re: [Patch] Fortran: Fix func decl mismatch [PR93660]
2021-03-14 11:04 ` Early ping: " Tobias Burnus
@ 2021-03-18 8:56 ` Tobias Burnus
0 siblings, 0 replies; 4+ messages in thread
From: Tobias Burnus @ 2021-03-18 8:56 UTC (permalink / raw)
To: gcc-patches, fortran, Paul Richard Thomas
*PING* of my 11.03.21 18:15 CET patch.
The issue is that the TREE_TYPE of the fndecl does not match its arglist.
In some cases, the middle end looks at the function type – and then it
goes wrong.
The issue only occurs for -fcoarray=lib as other hidden arguments are
properly handled.
Solution: Add the missing args to the fndecl (in gfc_get_function_type)
– and increment hidden_typelist in build_function_decl – the latter is
used in a gcc_assert which was supposed to check for this mismatch ...
Tobias
On 14.03.21 12:04, Tobias Burnus wrote:
> Early ping – and minor post script:
>
> + hidden_typelist = TREE_CHAIN (hidden_typelist);
>
> This change is to avoid running into the ICE:
>
> gcc_assert (hidden_typelist == NULL_TREE
> || TREE_VALUE (hidden_typelist) == void_type_node);
>
> The purpose of this assert is to check that the TREE_TYPE (fndecl)
> arg list and the one created by
> create_function_arglist (gfc_symbol * sym)
> are the same (at least in terms of the number of arguments). Namely:
> typelist = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
> ...
> hidden_typelist = typelist;
>
> Tobias
>
>
> On 11.03.21 18:15, Tobias Burnus wrote:
>> This fixes an ICE with OpenMP 'omp decare simd' but is a generic bug.
>>
>> Namely TREE_TYPE(fndecl) has a mismatch to the arglist chain,
>> missing some hidden arguments with -fcoarray=lib.
>>
>> OK for mainline and GCC 10?
>>
>> Tobias
>>
>> -----------------
>> Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München
>> Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung,
>> Frank Thürauf
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Patch] Fortran: Fix func decl mismatch [PR93660]
2021-03-11 17:15 [Patch] Fortran: Fix func decl mismatch [PR93660] Tobias Burnus
2021-03-14 11:04 ` Early ping: " Tobias Burnus
@ 2021-03-23 14:43 ` Paul Richard Thomas
1 sibling, 0 replies; 4+ messages in thread
From: Paul Richard Thomas @ 2021-03-23 14:43 UTC (permalink / raw)
To: Tobias Burnus; +Cc: gcc-patches, fortran
Hi Tobias,
The patch looks fine to me. OK for 10- and 11-branches. I am not convinced
that a delay is needed for the backport.
Thanks
Paul
On Thu, 11 Mar 2021 at 18:19, Tobias Burnus <tobias@codesourcery.com> wrote:
> This fixes an ICE with OpenMP 'omp decare simd' but is a generic bug.
>
> Namely TREE_TYPE(fndecl) has a mismatch to the arglist chain,
> missing some hidden arguments with -fcoarray=lib.
>
> OK for mainline and GCC 10?
>
> Tobias
>
> -----------------
> Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München
> Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank
> Thürauf
>
--
"If you can't explain it simply, you don't understand it well enough" -
Albert Einstein
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-03-23 14:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-11 17:15 [Patch] Fortran: Fix func decl mismatch [PR93660] Tobias Burnus
2021-03-14 11:04 ` Early ping: " Tobias Burnus
2021-03-18 8:56 ` *PING*: " Tobias Burnus
2021-03-23 14:43 ` Paul Richard Thomas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).