re PR fortran/71902 (Unneeded temporary on reallocatable character assignment)
2016-09-04 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/71902 * frontend-passes.c (realloc_string_callback): Also check for the lhs being deferred. Name temporary variable "realloc_string". 2016-09-04 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/71902 * gfortran.dg/dependency_47.f90: New test. * gfortran.dg/dependency_49.f90: New test. From-SVN: r239977
This commit is contained in:
parent
abb62d32a1
commit
d6598cf719
3 changed files with 45 additions and 2 deletions
|
@ -164,19 +164,34 @@ realloc_string_callback (gfc_code **c, int *walk_subtrees ATTRIBUTE_UNUSED,
|
|||
gfc_expr *expr1, *expr2;
|
||||
gfc_code *co = *c;
|
||||
gfc_expr *n;
|
||||
gfc_ref *ref;
|
||||
bool found_substr;
|
||||
|
||||
if (co->op != EXEC_ASSIGN)
|
||||
return 0;
|
||||
|
||||
expr1 = co->expr1;
|
||||
if (expr1->ts.type != BT_CHARACTER || expr1->rank != 0
|
||||
|| !expr1->symtree->n.sym->attr.allocatable)
|
||||
|| !gfc_expr_attr(expr1).allocatable
|
||||
|| !expr1->ts.deferred)
|
||||
return 0;
|
||||
|
||||
expr2 = gfc_discard_nops (co->expr2);
|
||||
if (expr2->expr_type != EXPR_VARIABLE)
|
||||
return 0;
|
||||
|
||||
found_substr = false;
|
||||
for (ref = expr2->ref; ref; ref = ref->next)
|
||||
{
|
||||
if (ref->type == REF_SUBSTRING)
|
||||
{
|
||||
found_substr = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found_substr)
|
||||
return 0;
|
||||
|
||||
if (!gfc_check_dependency (expr1, expr2, true))
|
||||
return 0;
|
||||
|
||||
|
@ -190,7 +205,7 @@ realloc_string_callback (gfc_code **c, int *walk_subtrees ATTRIBUTE_UNUSED,
|
|||
current_code = c;
|
||||
inserted_block = NULL;
|
||||
changed_statement = NULL;
|
||||
n = create_var (expr2, "trim");
|
||||
n = create_var (expr2, "realloc_string");
|
||||
co->expr2 = n;
|
||||
return 0;
|
||||
}
|
||||
|
|
14
gcc/testsuite/gfortran.dg/dependency_47.f90
Normal file
14
gcc/testsuite/gfortran.dg/dependency_47.f90
Normal file
|
@ -0,0 +1,14 @@
|
|||
! { dg-do compile }
|
||||
! Make sure there is only one instance of a temporary variable here.
|
||||
! { dg-options "-fdump-tree-original" }
|
||||
|
||||
SUBROUTINE prtdata(ilen)
|
||||
INTEGER :: ilen
|
||||
character(len=ilen), allocatable :: cline(:)
|
||||
allocate(cline(2))
|
||||
cline(1) = 'a'
|
||||
cline(1)(2:3) = cline(1)(1:2)
|
||||
cline(2) = cline(1)
|
||||
print *,c
|
||||
END SUBROUTINE prtdata
|
||||
! { dg-final { scan-tree-dump-not "__var_" "original" } }
|
14
gcc/testsuite/gfortran.dg/dependency_49.f90
Normal file
14
gcc/testsuite/gfortran.dg/dependency_49.f90
Normal file
|
@ -0,0 +1,14 @@
|
|||
! { dg-do compile }
|
||||
! { dg-options "-fdump-tree-original" }
|
||||
! PR fortran/71902 - make sure that component references are followed
|
||||
! for dependency analysis.
|
||||
program main
|
||||
type foo
|
||||
character(len=:), allocatable :: x
|
||||
end type foo
|
||||
type(foo) :: a
|
||||
a%x = 'asdf'
|
||||
a%x = a%x(2:3)
|
||||
print *,a%x
|
||||
end program main
|
||||
! { dg-final { scan-tree-dump-times "__var_1" 4 "original" } }
|
Loading…
Add table
Reference in a new issue