From: Steve Kargl <sgk@troutmask.apl.washington.edu>
To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [PATCH, committed] Fix PR fortran/82884
Date: Wed, 08 Nov 2017 21:01:00 -0000 [thread overview]
Message-ID: <20171108210154.GA51940@troutmask.apl.washington.edu> (raw)
Once the bug is found, the fix is obvious. Briefly,
in a typespec, ts.u.cl and ts.u.pad are in the same
union. When parsing a Hollerith, ts.u.pad is is set
to a nonzero value. Later, when resolving the array
constructor with Hollerith entities, a reference to
ts.u.cl is made which is a mangled non-NULL pointer.
The fix is to clear ts.u.pad in the hollerith to
character conversion function.
Regression tested on x86_64-*-freebsd.
2017-11-08 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/82884
* arith.c (gfc_hollerith2character): Clear pad.
2017-11-08 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/82884
* gfortran.dg/hollerith_character_array_constructor.f90: New test.
Index: gcc/fortran/arith.c
===================================================================
--- gcc/fortran/arith.c (revision 254461)
+++ gcc/fortran/arith.c (working copy)
@@ -2604,6 +2604,7 @@ gfc_hollerith2character (gfc_expr *src, int kind)
result = gfc_copy_expr (src);
result->ts.type = BT_CHARACTER;
result->ts.kind = kind;
+ result->ts.u.pad = 0;
result->value.character.length = result->representation.length;
result->value.character.string
Index: gcc/testsuite/gfortran.dg/hollerith_character_array_constructor.f90
===================================================================
--- gcc/testsuite/gfortran.dg/hollerith_character_array_constructor.f90 (nonexistent)
+++ gcc/testsuite/gfortran.dg/hollerith_character_array_constructor.f90 (working copy)
@@ -0,0 +1,11 @@
+! { dg-do run }
+! { dg-options "-w" }
+! PR fortran/82884
+! Original code contributed by Gerhard Steinmetz
+program p
+ character :: c(4) = [1h(, 1hi, 1h4, 1h)]
+ if (c(1) /= '(') call abort
+ if (c(2) /= 'i') call abort
+ if (c(3) /= '4') call abort
+ if (c(4) /= ')') call abort
+end
--
Steve
reply other threads:[~2017-11-08 21:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171108210154.GA51940@troutmask.apl.washington.edu \
--to=sgk@troutmask.apl.washington.edu \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).