* [PATCH] PR 83975 Set character length to 0 if unknown
@ 2018-01-23 9:31 Janne Blomqvist
2018-01-23 16:33 ` Thomas Koenig
0 siblings, 1 reply; 5+ messages in thread
From: Janne Blomqvist @ 2018-01-23 9:31 UTC (permalink / raw)
To: fortran, gcc-patches; +Cc: Janne Blomqvist
When associating a variable of type character, if the length of the
target isn't known, set it to zero rather than leaving it unset. This
is not a complete fix for making associate of characters work
properly, but papers over an ICE in the middle-end. See PR 83344 for
more details.
Regtested on x86_64-pc-linux-gnu, Ok for trunk?
gcc/fortran/ChangeLog:
2018-01-23 Janne Blomqvist <jb@gcc.gnu.org>
PR 83975
PR 83344
* resolve.c (resolve_assoc_var): Set character length to zero if
target length unknown.
gcc/testsuite/ChangeLog:
2018-01-23 Janne Blomqvist <jb@gcc.gnu.org>
PR 83975
PR 83344
* gfortran.dg/associate_31.f90: New test.
---
gcc/fortran/resolve.c | 13 ++++++++-----
gcc/testsuite/gfortran.dg/associate_31.f90 | 8 ++++++++
2 files changed, 16 insertions(+), 5 deletions(-)
create mode 100644 gcc/testsuite/gfortran.dg/associate_31.f90
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index a2b892a..f3fc3ca 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -8634,11 +8634,14 @@ resolve_assoc_var (gfc_symbol* sym, bool resolve_target)
if (!sym->ts.u.cl)
sym->ts.u.cl = target->ts.u.cl;
- if (!sym->ts.u.cl->length && !sym->ts.deferred
- && target->expr_type == EXPR_CONSTANT)
- sym->ts.u.cl->length
- = gfc_get_int_expr (gfc_charlen_int_kind,
- NULL, target->value.character.length);
+ if (!sym->ts.u.cl->length && !sym->ts.deferred)
+ /* TODO: Setting the length to zero if the expression isn't
+ constant is probably not correct, but at this point we
+ don't have any better idea what it should be either. */
+ sym->ts.u.cl->length =
+ gfc_get_int_expr (gfc_charlen_int_kind, NULL,
+ target->expr_type == EXPR_CONSTANT ?
+ target->value.character.length : 0);
}
/* If the target is a good class object, so is the associate variable. */
diff --git a/gcc/testsuite/gfortran.dg/associate_31.f90 b/gcc/testsuite/gfortran.dg/associate_31.f90
new file mode 100644
index 0000000..75774c8
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/associate_31.f90
@@ -0,0 +1,8 @@
+! { dg-do compile }
+! PR 83975, see also PR 83344
+! Testcase contributed by Gerhard Steinmetz
+subroutine s(x)
+ character(*) :: x
+ associate (y => x)
+ end associate
+end subroutine s
--
2.7.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] PR 83975 Set character length to 0 if unknown
2018-01-23 9:31 [PATCH] PR 83975 Set character length to 0 if unknown Janne Blomqvist
@ 2018-01-23 16:33 ` Thomas Koenig
2018-01-23 19:29 ` Janne Blomqvist
0 siblings, 1 reply; 5+ messages in thread
From: Thomas Koenig @ 2018-01-23 16:33 UTC (permalink / raw)
To: Janne Blomqvist, fortran, gcc-patches
Hi Janne,
> When associating a variable of type character, if the length of the
> target isn't known, set it to zero rather than leaving it unset. This
> is not a complete fix for making associate of characters work
> properly, but papers over an ICE in the middle-end. See PR 83344 for
> more details.
>
> Regtested on x86_64-pc-linux-gnu, Ok for trunk?
Does the code which is accepted then execute correctly?
Personally, I would prefer an ICE over a silent wrong-code.
Regards
Thomas
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] PR 83975 Set character length to 0 if unknown
2018-01-23 16:33 ` Thomas Koenig
@ 2018-01-23 19:29 ` Janne Blomqvist
2018-02-01 9:05 ` [PATCH] PR 83975 Associate target with non-constant character length Janne Blomqvist
0 siblings, 1 reply; 5+ messages in thread
From: Janne Blomqvist @ 2018-01-23 19:29 UTC (permalink / raw)
To: Thomas Koenig; +Cc: Fortran List, GCC Patches
On Tue, Jan 23, 2018 at 6:33 PM, Thomas Koenig <tkoenig@netcologne.de> wrote:
> Hi Janne,
>
>> When associating a variable of type character, if the length of the
>> target isn't known, set it to zero rather than leaving it unset. This
>> is not a complete fix for making associate of characters work
>> properly, but papers over an ICE in the middle-end. See PR 83344 for
>> more details.
>>
>> Regtested on x86_64-pc-linux-gnu, Ok for trunk?
>
>
> Does the code which is accepted then execute correctly?
Hmm, prompted by your question I did some investigating, and I present
to you evidence of GFortran being a quantum mechanical compiler
(spooky action at a distance!): Consider the slightly fleshed out
testcase from PR 83975:
program foo
call s("foo")
contains
subroutine s(x)
character(*) :: x
print *, "X:", x, ":ENDX"
print *, "len(x): ", len(x)
! associate (y => x)
! print *, "Y:", y, ":ENDY"
! print *, "len(y): ", len(y)
! end associate
end subroutine s
end program foo
With the associate stuff commented out, it's fairly bog-standard
stuff, and the output is the expected:
X:foo:ENDX
len(x): 3
Now, incorporating the commented out associate block, and the result is:
X::ENDX
len(x): 0
Y::ENDY
len(y): 0
So the associate construct manages to somehow break the variable X in
the outer scope!
--
Janne Blomqvist
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] PR 83975 Associate target with non-constant character length
2018-01-23 19:29 ` Janne Blomqvist
@ 2018-02-01 9:05 ` Janne Blomqvist
2018-02-01 17:36 ` Thomas Koenig
0 siblings, 1 reply; 5+ messages in thread
From: Janne Blomqvist @ 2018-02-01 9:05 UTC (permalink / raw)
To: fortran, gcc-patches; +Cc: Janne Blomqvist
When associating a variable of type character, if the length of the
target isn't known at compile time, generate an error. See PR 83344
for more details.
Regtested on x86_64-pc-linux-gnu, Ok for trunk?
gcc/fortran/ChangeLog:
2018-02-01 Janne Blomqvist <jb@gcc.gnu.org>
PR 83975
PR 83344
* resolve.c (resolve_assoc_var): Generate an error if
target length unknown.
---
gcc/fortran/resolve.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 9c8ba86..60b9bc3 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -8634,11 +8634,16 @@ resolve_assoc_var (gfc_symbol* sym, bool resolve_target)
if (!sym->ts.u.cl)
sym->ts.u.cl = target->ts.u.cl;
- if (!sym->ts.u.cl->length && !sym->ts.deferred
- && target->expr_type == EXPR_CONSTANT)
- sym->ts.u.cl->length
- = gfc_get_int_expr (gfc_charlen_int_kind,
- NULL, target->value.character.length);
+ if (!sym->ts.u.cl->length && !sym->ts.deferred)
+ {
+ if (target->expr_type == EXPR_CONSTANT)
+ sym->ts.u.cl->length =
+ gfc_get_int_expr (gfc_charlen_int_kind, NULL,
+ target->value.character.length);
+ else
+ gfc_error ("Not Implemented: Associate target with type character"
+ " and non-constant length at %L", &target->where);
+ }
}
/* If the target is a good class object, so is the associate variable. */
--
2.7.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] PR 83975 Associate target with non-constant character length
2018-02-01 9:05 ` [PATCH] PR 83975 Associate target with non-constant character length Janne Blomqvist
@ 2018-02-01 17:36 ` Thomas Koenig
0 siblings, 0 replies; 5+ messages in thread
From: Thomas Koenig @ 2018-02-01 17:36 UTC (permalink / raw)
To: Janne Blomqvist, fortran, gcc-patches
Hi Janne,
> When associating a variable of type character, if the length of the
> target isn't known at compile time, generate an error. See PR 83344
> for more details.
>
> Regtested on x86_64-pc-linux-gnu, Ok for trunk?
I think this is the most reasonable course of action,
given the circumstances.
OK for trunk. Thanks!
Regards
Thomas
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-02-01 17:36 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-23 9:31 [PATCH] PR 83975 Set character length to 0 if unknown Janne Blomqvist
2018-01-23 16:33 ` Thomas Koenig
2018-01-23 19:29 ` Janne Blomqvist
2018-02-01 9:05 ` [PATCH] PR 83975 Associate target with non-constant character length Janne Blomqvist
2018-02-01 17:36 ` Thomas Koenig
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).