summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/trim_optimize_2.f90
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/gfortran.dg/trim_optimize_2.f90')
-rw-r--r--gcc/testsuite/gfortran.dg/trim_optimize_2.f9037
1 files changed, 37 insertions, 0 deletions
diff --git a/gcc/testsuite/gfortran.dg/trim_optimize_2.f90 b/gcc/testsuite/gfortran.dg/trim_optimize_2.f90
new file mode 100644
index 000000000..b7ae1e3e5
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/trim_optimize_2.f90
@@ -0,0 +1,37 @@
+! { dg-do run }
+! { dg-options "-O -fdump-tree-original" }
+! Optimize unnecessary TRIMs in contained namespaces too.
+module faz
+ implicit none
+contains
+ subroutine bar
+ character(len=3) :: a
+ character(len=4) :: b,c
+ b = 'abcd'
+ a = trim(b)
+ c = trim(trim(a))
+ if (a /= 'abc') call abort
+ if (c /= 'abc') call abort
+ end subroutine bar
+end module faz
+
+program main
+ use faz
+ implicit none
+ call foo
+ call bar
+contains
+ subroutine foo
+ character(len=3) :: a
+ character(len=4) :: b,c
+ b = 'abcd'
+ a = trim(b)
+ c = trim(trim(a))
+ if (a /= 'abc') call abort
+ if (c /= 'abc') call abort
+ end subroutine foo
+end program main
+
+! { dg-final { scan-tree-dump-times "memmove" 4 "original" } }
+! { dg-final { scan-tree-dump-times "string_trim" 0 "original" } }
+! { dg-final { cleanup-tree-dump "original" } }