Bug 43136 - Excess copy-in/copy-out with character argument
Summary: Excess copy-in/copy-out with character argument
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: Thomas Koenig
URL:
Keywords: missed-optimization
Depends on:
Blocks: Fortran_character
  Show dependency treegraph
 
Reported: 2010-02-22 05:54 UTC by Paul Thomas
Modified: 2019-01-15 22:21 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-02-22 09:01:52


Attachments
Patch which works, but causes some regressions (713 bytes, patch)
2019-01-15 07:33 UTC, Thomas Koenig
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Thomas 2010-02-22 05:54:32 UTC
After fixing, 43072 and friends, one excess copy-in and copy-out remains, where a substring describes the declared string length.  The testcase is in internal_pack_9.f90:

subroutine foo2
  implicit none
  external foo
  character(len=20) :: str(2) = '1234567890'
  call foo(str(:)(1:20)) ! This is still not fixed.
end

Paul
Comment 1 Thomas Koenig 2010-12-15 21:30:28 UTC
See also PR 31821.
Comment 2 Thomas Koenig 2011-01-08 22:18:31 UTC
We have to watch out for aliasing here; if
foo changes the arguments, we have to have a copy.

Compare PR 47065.
Comment 3 Thomas Koenig 2019-01-14 12:20:51 UTC
Hm, maybe one could simply remove the substring during resolution.
Comment 4 Thomas Koenig 2019-01-15 07:33:14 UTC
Created attachment 45431 [details]
Patch which works, but causes some regressions

Apparently, in argument_checking_13.f90, the test in the last routine

interface
  subroutine rlv3(y)
    character   :: y(3)
  end subroutine rlv3
end interface

character(2)          :: assumed_sh_dummy(:,:,:)
...
call rlv3(assumed_sh_dummy(1,1,1)(1:2)) ! { dg-error "contains too few elements" }

does not trigger the warning if it is replaced by

call rlv3(assumed_sh_dummy(1,1,1))

So, this needs another test.
Comment 5 Thomas Koenig 2019-01-15 22:20:57 UTC
Author: tkoenig
Date: Tue Jan 15 22:20:26 2019
New Revision: 267954

URL: https://gcc.gnu.org/viewcvs?rev=267954&root=gcc&view=rev
Log:
2019-01-15  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/43136
	* resolve.c (resolve_array_ref): Add equal_length argument; set it
	if the length of the substring equals that of the orignal
	variable.
	(resolve_ref): Remove the substring if it is equal in length to
	the original variable, unless it is an EXPR_SUBSTRING).

2019-01-15  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/43136
	* gfortran.dg/actual_array_substr_3.f90: New test.


Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/testsuite/ChangeLog
Comment 6 Thomas Koenig 2019-01-15 22:21:51 UTC
Actually fixed in r267953, the original commit had the wrong PR number.

Closing.