http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56907
Bug #: 56907 Summary: C_LOC shall not call internal-PACK when an array argument is used Classification: Unclassified Product: gcc Version: 4.9.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: fortran AssignedTo: unassig...@gcc.gnu.org ReportedBy: bur...@gcc.gnu.org Found when looking at gfortran.dg/assumed_type_2.f90. For an array argument, C_LOC should simply take the first element of the array (section). Currently, it invokes internal packing. As Fortran 2008 demands that the argument is contiguous, internal_packing should simply return the original array (section) - hence, there is no wrong-code issue - just a missed optimization. >From the dump: D.1901 = _gfortran_internal_pack (&parm.4); D.1903 = D.1901; Test case: ! { dg-do compile } ! { dg-options "-fdump-tree-original" } ! ! PR fortran/ <<<<<<<<<<< ! subroutine sub(xxx) use iso_c_binding implicit none integer, target :: xxx(:) type(c_ptr) :: ptr ptr = c_loc (xxx) end ! { dg-final { scan-tree-dump-not " _gfortran_internal_pack" "original" } } ! { dg-final { cleanup-tree-dump "optimized" } }