[Bug fortran/49110] Deferred-length character result triggers (false positive) error for pure procedures

2012-05-14 Thread burnus at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49110

Tobias Burnus burnus at gcc dot gnu.org changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||FIXED

--- Comment #17 from Tobias Burnus burnus at gcc dot gnu.org 2012-05-14 
16:46:20 UTC ---
The REPEAT issue has now also been FIXED on the trunk (4.8). Thanks for the
patience.


[Bug fortran/49110] Deferred-length character result triggers (false positive) error for pure procedures

2012-05-14 Thread burnus at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49110

--- Comment #16 from Tobias Burnus burnus at gcc dot gnu.org 2012-05-14 
16:45:31 UTC ---
Author: burnus
Date: Mon May 14 16:45:16 2012
New Revision: 187472

URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=187472
Log:
2012-05-14  Tobias Burnus  bur...@net-b.de

PR fortran/49110
PR fortran/51055
PR fortran/53329
* trans-expr.c (gfc_trans_assignment_1): Fix allocation
handling for assignment of function results to allocatable
deferred-length strings.
* trans-decl.c (gfc_create_string_length): For deferred-length
module variables, include module name in the assembler name.
(gfc_get_symbol_decl): Don't override the assembler name.

2012-05-14  Tobias Burnus  bur...@net-b.de

PR fortran/49110
PR fortran/51055
PR fortran/53329
* gfortran.dg/deferred_type_param_4.f90: New.
* gfortran.dg/deferred_type_param_6.f90: New.


Added:
trunk/gcc/testsuite/gfortran.dg/deferred_type_param_4.f90
trunk/gcc/testsuite/gfortran.dg/deferred_type_param_6.f90
Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/trans-decl.c
trunk/gcc/fortran/trans-expr.c
trunk/gcc/testsuite/ChangeLog


[Bug fortran/49110] Deferred-length character result triggers (false positive) error for pure procedures

2012-05-12 Thread burnus at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49110

--- Comment #14 from Tobias Burnus burnus at gcc dot gnu.org 2012-05-12 
09:54:00 UTC ---
Author: burnus
Date: Sat May 12 09:53:53 2012
New Revision: 187427

URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=187427
Log:
2012-05-12  Tobias Burnus  bur...@net-b.de

PR fortran/49110
PR fortran/52843
* resolve.c (resolve_fl_procedure): Don't regard
character(len=:) as character(*) in the diagnostic.

2012-05-12  Tobias Burnus  bur...@net-b.de

PR fortran/49110
PR fortran/52843
* gfortran.dg/deferred_type_param_5.f90: New.


Added:
trunk/gcc/testsuite/gfortran.dg/deferred_type_param_5.f90
Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/resolve.c
trunk/gcc/testsuite/ChangeLog


[Bug fortran/49110] Deferred-length character result triggers (false positive) error for pure procedures

2012-05-12 Thread burnus at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49110

--- Comment #15 from Tobias Burnus burnus at gcc dot gnu.org 2012-05-12 
09:59:10 UTC ---
The commit of comment 13 fixes the issue with the bogus PURE diagnostic.

Sorry that it took one year to get it fixed - and thanks for the bug report.

 * * *

Regarding the REPEAT issue (cf. comment 9 and PR 51055): A patch solving that
issue has been posted at http://gcc.gnu.org/ml/fortran/2012-05/msg00054.html


[Bug fortran/49110] Deferred-length character result triggers (false positive) error for pure procedures

2012-01-02 Thread burnus at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49110

Tobias Burnus burnus at gcc dot gnu.org changed:

   What|Removed |Added

 CC||burnus at gcc dot gnu.org

--- Comment #13 from Tobias Burnus burnus at gcc dot gnu.org 2012-01-02 
18:53:47 UTC ---
(In reply to comment #9)
 ! character, intent(in) :: s(5)   ! Compiles and runs
  character, intent(in) :: s(:)! Compiles and segfaults
  character(len=:), allocatable :: a
  a = repeat('a', size(s))

For that example, try:
  a = ( repeat('a', size(s)) )
Cf. PR 51055.


[Bug fortran/49110] Deferred-length character result triggers (false positive) error for pure procedures

2011-05-22 Thread jwmwalrus at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49110

--- Comment #1 from John jwmwalrus at gmail dot com 2011-05-22 16:13:49 UTC 
---
Created attachment 24327
  -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=24327
Test case


[Bug fortran/49110] Deferred-length character result triggers (false positive) error for pure procedures

2011-05-22 Thread kargl at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49110

kargl at gcc dot gnu.org changed:

   What|Removed |Added

 CC||kargl at gcc dot gnu.org

--- Comment #2 from kargl at gcc dot gnu.org 2011-05-22 16:32:51 UTC ---
This patch allows your code to compile, but I 
don't know if it works correctly.  Do you have
a complete self-contained small testcase?

Index: resolve.c
===
--- resolve.c   (revision 173757)
+++ resolve.c   (working copy)
@@ -10305,7 +10305,7 @@ resolve_fl_procedure (gfc_symbol *sym, i
  actual length; (ii) To declare a named constant; or (iii) External
  function - but length must be declared in calling scoping unit.  */
   if (sym-attr.function
-   sym-ts.type == BT_CHARACTER
+   sym-ts.type == BT_CHARACTER  !sym-ts.deferred
sym-ts.u.cl  sym-ts.u.cl-length == NULL)
 {
   if ((sym-as  sym-as-rank) || (sym-attr.pointer)


[Bug fortran/49110] Deferred-length character result triggers (false positive) error for pure procedures

2011-05-22 Thread jwmwalrus at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49110

--- Comment #4 from John jwmwalrus at gmail dot com 2011-05-22 16:46:32 UTC 
---
(In reply to comment #2)
 This patch allows your code to compile, but I 
 don't know if it works correctly.  Do you have
 a complete self-contained small testcase?
 
 Index: resolve.c
 ===
 --- resolve.c   (revision 173757)
 +++ resolve.c   (working copy)
 @@ -10305,7 +10305,7 @@ resolve_fl_procedure (gfc_symbol *sym, i
   actual length; (ii) To declare a named constant; or (iii) External
   function - but length must be declared in calling scoping unit.  */
if (sym-attr.function
 -   sym-ts.type == BT_CHARACTER
 +   sym-ts.type == BT_CHARACTER  !sym-ts.deferred
 sym-ts.u.cl  sym-ts.u.cl-length == NULL)
  {
if ((sym-as  sym-as-rank) || (sym-attr.pointer)

The module shown is self-contained (it only depends on iso_c_binding, which is
an intrinsic module).  I've added the corresponding source file to this bug as
an attachment.


[Bug fortran/49110] Deferred-length character result triggers (false positive) error for pure procedures

2011-05-22 Thread jwmwalrus at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49110

--- Comment #3 from John jwmwalrus at gmail dot com 2011-05-22 16:45:09 UTC 
---
(In reply to comment #2)
 This patch allows your code to compile, but I 
 don't know if it works correctly.  Do you have
 a complete self-contained small testcase?
 
 Index: resolve.c
 ===
 --- resolve.c   (revision 173757)
 +++ resolve.c   (working copy)
 @@ -10305,7 +10305,7 @@ resolve_fl_procedure (gfc_symbol *sym, i
   actual length; (ii) To declare a named constant; or (iii) External
   function - but length must be declared in calling scoping unit.  */
if (sym-attr.function
 -   sym-ts.type == BT_CHARACTER
 +   sym-ts.type == BT_CHARACTER  !sym-ts.deferred
 sym-ts.u.cl  sym-ts.u.cl-length == NULL)
  {
if ((sym-as  sym-as-rank) || (sym-attr.pointer)

The module shown is self-contained (it only depends on iso_c_binding, which is
an intrinsic module).  I've added the corresponding source file to this bug as
an attachment.


[Bug fortran/49110] Deferred-length character result triggers (false positive) error for pure procedures

2011-05-22 Thread jwmwalrus at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49110

--- Comment #5 from John jwmwalrus at gmail dot com 2011-05-22 16:57:02 UTC 
---
Created attachment 24331
  -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=24331
Test case with main unit


[Bug fortran/49110] Deferred-length character result triggers (false positive) error for pure procedures

2011-05-22 Thread sgk at troutmask dot apl.washington.edu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49110

--- Comment #6 from Steve Kargl sgk at troutmask dot apl.washington.edu 
2011-05-22 17:11:03 UTC ---
On Sun, May 22, 2011 at 04:57:44PM +, jwmwalrus at gmail dot com wrote:
  This patch allows your code to compile, but I 
  don't know if it works correctly.  Do you have
  a complete self-contained small testcase?
  
 
 The module shown is self-contained (it only depends on iso_c_binding, which is
 an intrinsic module).  I've added the corresponding source file to this bug as
 an attachment.
 

That's no what I meant.  Obviously, I already stated
the patch allowed me compile your code.

Do you have a COMPLETE self-contained testcase?  As in

program foo
   use mod1
   DO SOMETHING HERE TO USE c2fstring()
end program foo


[Bug fortran/49110] Deferred-length character result triggers (false positive) error for pure procedures

2011-05-22 Thread jwmwalrus at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49110

--- Comment #7 from John jwmwalrus at gmail dot com 2011-05-22 17:24:07 UTC 
---
(In reply to comment #6)
 On Sun, May 22, 2011 at 04:57:44PM +, jwmwalrus at gmail dot com wrote:
   This patch allows your code to compile, but I 
   don't know if it works correctly.  Do you have
   a complete self-contained small testcase?
   
  
  The module shown is self-contained (it only depends on iso_c_binding, which 
  is
  an intrinsic module).  I've added the corresponding source file to this bug 
  as
  an attachment.
  
 
 That's no what I meant.  Obviously, I already stated
 the patch allowed me compile your code.
 
 Do you have a COMPLETE self-contained testcase?  As in
 
 program foo
use mod1
DO SOMETHING HERE TO USE c2fstring()
 end program foo

Sorry for the double post (I now know the effect of the refresh button on
Bugzilla).

As I said, the source code is attached (the label is Test case with main
unit, the name of the file is test_gfortran_pure_main.f90).


[Bug fortran/49110] Deferred-length character result triggers (false positive) error for pure procedures

2011-05-22 Thread kargl at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49110

--- Comment #8 from kargl at gcc dot gnu.org 2011-05-22 18:35:37 UTC ---
I think the subject line is incorrect.  The following testcase
that gets rid of the C interop garbage, works for an input
array of characters with an explicit-shape, but fails with
an assumed-shape array.

program foo

   implicit none

   character s(5)

   s = ['a', 'b', 'c', 'd', 'e']
   print *, bar(s)

   contains

  pure function bar(s) result(a)
! character, intent(in) :: s(5)   ! Compiles and runs
 character, intent(in) :: s(:)! Compiles and segfaults
 character(len=:), allocatable :: a
 integer i
 a = repeat('a', size(s))
 do i = 1, size(s)
a(i:i) = s(i)
 end do
  end function bar

end program foo

The following workaround allows the original code to compile and
run.


   function c2fstring(cbuffer) result(string)

  character(:), allocatable :: string
  character(KIND = C_CHAR), intent(IN) :: cbuffer(255)

  character(len=255) s
  integer :: i

  s = ''
  do i = 1, SIZE(cbuffer)
 if (cbuffer(i) == C_NULL_CHAR) exit
 s(i:i) = cbuffer(i)
  end do
  string = TRIM(s)

end function


[Bug fortran/49110] Deferred-length character result triggers (false positive) error for pure procedures

2011-05-22 Thread kargl at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49110

--- Comment #9 from kargl at gcc dot gnu.org 2011-05-22 19:00:06 UTC ---
Note the routine need not be pure to invoke the segfault.  Here's
an even  shorter test case.

program foo
   implicit none
   character s(5)
   s = ['a', 'b', 'c', 'd', 'e']
   print *, bar(s)
   contains
  function bar(s) result(a)
! character, intent(in) :: s(5)   ! Compiles and runs
 character, intent(in) :: s(:)! Compiles and segfaults
 character(len=:), allocatable :: a
 a = repeat('a', size(s))
  end function bar
end program foo


[Bug fortran/49110] Deferred-length character result triggers (false positive) error for pure procedures

2011-05-22 Thread jwmwalrus at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49110

--- Comment #10 from John jwmwalrus at gmail dot com 2011-05-22 19:36:33 UTC 
---
(In reply to comment #9)
 Note the routine need not be pure to invoke the segfault.  Here's
 an even  shorter test case.
 
 program foo
implicit none
character s(5)
s = ['a', 'b', 'c', 'd', 'e']
print *, bar(s)
contains
   function bar(s) result(a)
 ! character, intent(in) :: s(5)   ! Compiles and runs
  character, intent(in) :: s(:)! Compiles and segfaults
  character(len=:), allocatable :: a
  a = repeat('a', size(s))
   end function bar
 end program foo

My bug report is actually about the fact that the pure attribute triggers an
(incorrect) error, and that error is associated to the deferred-length
character result.  The code compiles just fine by removing the pure attribute
from the original code... Or by changing character(:), allocatable :: string
to something like character(2047) :: string.

So I guess the subject line is fine.

The reason why I used interoperability with C, is because the module is just a
reduced version of the actual, practical case that triggered the error ---sorry
if it's garbage to you.


[Bug fortran/49110] Deferred-length character result triggers (false positive) error for pure procedures

2011-05-22 Thread dominiq at lps dot ens.fr
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49110

--- Comment #11 from Dominique d'Humieres dominiq at lps dot ens.fr 
2011-05-22 20:46:56 UTC ---
This PR seems related to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45170#c9 .


[Bug fortran/49110] Deferred-length character result triggers (false positive) error for pure procedures

2011-05-22 Thread sgk at troutmask dot apl.washington.edu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49110

--- Comment #12 from Steve Kargl sgk at troutmask dot apl.washington.edu 
2011-05-22 21:30:07 UTC ---
On Sun, May 22, 2011 at 08:03:32PM +, jwmwalrus at gmail dot com wrote:
 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49110
 
 --- Comment #10 from John jwmwalrus at gmail dot com 2011-05-22 19:36:33 
 UTC ---
 (In reply to comment #9)
  Note the routine need not be pure to invoke the segfault.  Here's
  an even  shorter test case.
  
  program foo
 implicit none
 character s(5)
 s = ['a', 'b', 'c', 'd', 'e']
 print *, bar(s)
 contains
function bar(s) result(a)
  ! character, intent(in) :: s(5)   ! Compiles and runs
   character, intent(in) :: s(:)! Compiles and segfaults
   character(len=:), allocatable :: a
   a = repeat('a', size(s))
end function bar
  end program foo
 
 My bug report is actually about the fact that the pure attribute
 triggers an (incorrect) error, and that error is associated to the
 deferred-length character result.

Sigh.  I already told you that my patch in Comment #2 
fixes the errant error message.  That does not fix the
more important bug that is exposed when the errant
error message is suppressed.  With my patch in Comment #2,
and without touching your source code, I get

laptop:kargl[228] gfc4x -o z -fno-backtrace test_gfortran_pure_main.f90  ./z
Segmentation fault (core dumped)

 The reason why I used interoperability with C, is because the
 module is just a reduced version of the actual, practical case
  that triggered the error ---sorry if it's garbage to you.

The C interop stuff is garbage in that it makes it much
more difficult to diagnosis and fix the real bug.

Your free to apply my patch gcc, build new gfortran, and use it
to compile and run your code.

I shalt spend anymore time on this PR.