[Bug fortran/53642] Front-end optimization: Wrong string length for deferred-length strings
burnus at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Jun 12 15:52:00 GMT 2012
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). */
More information about the Gcc-bugs
mailing list