public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "burnus at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/53642] Front-end optimization: Wrong string length for deferred-length strings Date: Tue, 12 Jun 2012 15:52:00 -0000 [thread overview] Message-ID: <bug-53642-4-OuQsVB54Vq@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-53642-4@http.gcc.gnu.org/bugzilla/> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53642 Tobias Burnus <burnus at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |burnus at gcc dot gnu.org --- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-06-12 15:52:34 UTC --- I was thinking about the following patch - namely, doing in optimize_assignment the remove_trim only if "!lhs->ts.deferred". * * * However, that does not work; seemingly, a = trim(b) is replaced by a = b(1:len_trim(b)) in such a way, that len(a) == 0 instead of 3. The same issue occurs for a manual: trimmed = string(1:len_trim(string)) Thus, the follow-up issue is not a FE optimization issue but rather a trans*.c issue. The generated code is [some casting removed]: trimmed = __builtin_malloc (MAX_EXPR <NON_LVALUE_EXPR <D.1861>, 0>); .trimmed = MAX_EXPR <NON_LVALUE_EXPR <D.1861>, 0>; D.1861 = _gfortran_string_len_trim (4, &string); Which shows the wrong ordering, similar to bug 45170 comment 34, which is fixed by the patch at bug 45170 comment 34. That patch also solves the len_trim issue above. --- a/gcc/fortran/frontend-passes.c +++ b/gcc/fortran/frontend-passes.c @@ -738 +738 @@ optimize_assignment (gfc_code * c) - if (lhs->ts.type == BT_CHARACTER) + if (lhs->ts.type == BT_CHARACTER && !lhs->ts.deferred) @@ -740 +740 @@ optimize_assignment (gfc_code * c) - /* Optimize away a = trim(b), where a is a character variable. */ + /* Optimize a = trim(b) to a = b. */ @@ -743,4 +743,2 @@ optimize_assignment (gfc_code * c) - /* Replace a = ' ' by a = '' to optimize away a memcpy, but only - for strings with non-deferred length (otherwise we would - reallocate the length. */ - if (empty_string(rhs) && ! lhs->ts.deferred) + /* Replace a = ' ' by a = '' to optimize away a memcpy. */ + if (empty_string(rhs)) @@ -1174 +1172 @@ optimize_trim (gfc_expr *e) - /* Build the function call to len_trim(x, gfc_defaul_integer_kind). */ + /* Build the function call to len_trim(x, gfc_default_integer_kind). */
next prev parent reply other threads:[~2012-06-12 15:52 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-06-12 8:09 [Bug fortran/53642] New: " burnus at gcc dot gnu.org 2012-06-12 15:52 ` burnus at gcc dot gnu.org [this message] 2012-06-16 18:13 ` [Bug fortran/53642] " burnus at gcc dot gnu.org 2012-06-16 18:16 ` burnus at gcc dot gnu.org
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=bug-53642-4-OuQsVB54Vq@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@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: linkBe 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).