public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/53685] New: surprising warns about transfer with explicit character range
@ 2012-06-15 14:35 ajmay81 at googlemail dot com
  2012-06-15 16:18 ` [Bug fortran/53685] " burnus at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: ajmay81 at googlemail dot com @ 2012-06-15 14:35 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53685

             Bug #: 53685
           Summary: surprising warns about transfer with explicit
                    character range
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ajmay81@googlemail.com


Fortran code:

      subroutine test()
      implicit none
      character(len=4) :: record_type
      integer          :: i
      i=transfer(record_type,i) ! no warning
      i=transfer(record_type(1:4),i) ! warning
      return
      end

gfortran -c -Wsurprising test.f
test.f:6.17:

      i=transfer(record_type(1:4),i) ! warning                          
                 1
Warning: Intrinsic TRANSFER at (1) has partly undefined result: source size 0 <
result size 4

When the string length is explicitly given the compiler thinks it is length 0,
even though it is the same length as the previous instance.

Seen with 4.7.1 built from source.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/53685] surprising warns about transfer with explicit character range
  2012-06-15 14:35 [Bug fortran/53685] New: surprising warns about transfer with explicit character range ajmay81 at googlemail dot com
@ 2012-06-15 16:18 ` burnus at gcc dot gnu.org
  2012-06-15 17:02 ` burnus at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-06-15 16:18 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53685

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-06-15
                 CC|                            |burnus at gcc dot gnu.org
     Ever Confirmed|0                           |1

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-06-15 16:18:36 UTC ---
Confirmed.

The size is determined via target-memory.c's gfc_target_expr_size. There seems
to be two issues:

(a) A minor one that in the second case, the length of "record_type" is
"e->ts->u.cl->length == NULL" instead of 4 (as one could be simply calculated).

b) And the missing error handling for gfc_target_expr_size in
gfc_calculate_transfer_sizes: There, the result size is error checked, namely:
  if (result_elt_size == 0)
    return FAILURE;
But a similar line for source_size is lacking.


Regarding (a): The question is whether one shouldn't set expr->ts.u.cl->length
to expr->ref->next->...->u.ss.length for substrings. I don't know whether that
messes with the CL cleanup or other issues, but it'd make handling substrings
easier than checking whether there is a last_ref(expr)->u.ss.length.


Patch for the second issue.

--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -4003,2 +4003,4 @@ gfc_calculate_transfer_sizes (gfc_expr *source, gfc_expr
*mold, gfc_expr *size,
   *source_size = gfc_target_expr_size (source);
+  if (source_size == 0)
+    return FAILURE;


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/53685] surprising warns about transfer with explicit character range
  2012-06-15 14:35 [Bug fortran/53685] New: surprising warns about transfer with explicit character range ajmay81 at googlemail dot com
  2012-06-15 16:18 ` [Bug fortran/53685] " burnus at gcc dot gnu.org
@ 2012-06-15 17:02 ` burnus at gcc dot gnu.org
  2012-06-16 10:51 ` burnus at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-06-15 17:02 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53685

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-06-15 17:02:44 UTC ---
(In reply to comment #1)
> (a) A minor one that in the second case, the length of "record_type" is
> "e->ts->u.cl->length == NULL" instead of 4 (as one could be simply calculated).

That should be fixed by the following patch (untested). The question is why
e->ref->type == REF_SUBSTRING was excluded if (and only if) it was the first
reference?

The whole condition plus function call was added 2007-08-31 in the big patch
for PR fortran/31879, PR fortran/31197, PR fortran/31258 and PR fortran/32703:
http://gcc.gnu.org/viewcvs?view=revision&revision=127939

--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -6325,4 +6325,3 @@ gfc_resolve_expr (gfc_expr *e)

-      if (e->ts.type == BT_CHARACTER && e->ts.u.cl == NULL && e->ref
-         && e->ref->type != REF_SUBSTRING)
+      if (e->ts.type == BT_CHARACTER && e->ts.u.cl == NULL && e->ref)
        gfc_resolve_substring_charlen (e);


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/53685] surprising warns about transfer with explicit character range
  2012-06-15 14:35 [Bug fortran/53685] New: surprising warns about transfer with explicit character range ajmay81 at googlemail dot com
  2012-06-15 16:18 ` [Bug fortran/53685] " burnus at gcc dot gnu.org
  2012-06-15 17:02 ` burnus at gcc dot gnu.org
@ 2012-06-16 10:51 ` burnus at gcc dot gnu.org
  2012-06-17 19:31 ` burnus at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-06-16 10:51 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53685

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-06-16 10:50:48 UTC ---
That patch of comment 2 fails for:

testsuite/gfortran.dg/string_3.f90:16.15:
  print *, len(s(2_8**32_8+3_8:1))
               1
Error: Result of LEN overflows its kind at (1)

It also fails for "if (len(t(8:4)) /= 0) call abort" in gfortran.dg/substr_2.f.
And for gfortran.dg/widechar_IO_4.f90 (rt, line 16),
gfortran.dg/widechar_compare_1.f90 (line 9), and
gfortran.dg/widechar_intrinsics_8.f90 (line 24).


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/53685] surprising warns about transfer with explicit character range
  2012-06-15 14:35 [Bug fortran/53685] New: surprising warns about transfer with explicit character range ajmay81 at googlemail dot com
                   ` (2 preceding siblings ...)
  2012-06-16 10:51 ` burnus at gcc dot gnu.org
@ 2012-06-17 19:31 ` burnus at gcc dot gnu.org
  2012-06-22 10:28 ` burnus at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-06-17 19:31 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53685

--- Comment #4 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-06-17 19:30:44 UTC ---
Author: burnus
Date: Sun Jun 17 19:30:29 2012
New Revision: 188708

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=188708
Log:
2012-06-17  Tobias Burnus  <burnus@net-b.de>

        PR fortran/53691
        PR fortran/53685
        * check.c (gfc_calculate_transfer_sizes): Return if
        SIZE= is not constant or source-size cannot be determined.

2012-06-17  Tobias Burnus  <burnus@net-b.de>

        PR fortran/53691
        PR fortran/53685
        * gfortran.dg/transfer_check_3.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/transfer_check_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/check.c
    trunk/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/53685] surprising warns about transfer with explicit character range
  2012-06-15 14:35 [Bug fortran/53685] New: surprising warns about transfer with explicit character range ajmay81 at googlemail dot com
                   ` (3 preceding siblings ...)
  2012-06-17 19:31 ` burnus at gcc dot gnu.org
@ 2012-06-22 10:28 ` burnus at gcc dot gnu.org
  2012-09-24 13:58 ` ajmay81 at googlemail dot com
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-06-22 10:28 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53685

--- Comment #5 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-06-22 10:28:01 UTC ---
Author: burnus
Date: Fri Jun 22 10:27:56 2012
New Revision: 188882

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=188882
Log:
2012-06-22  Tobias Burnus  <burnus@net-b.de>

        Backport from mainline
        2012-06-17  Tobias Burnus  <burnus@net-b.de>

        PR fortran/53691
        PR fortran/53685
        * check.c (gfc_calculate_transfer_sizes): Return if
        SIZE= is not constant or source-size cannot be determined.

2012-06-22  Tobias Burnus  <burnus@net-b.de>

        Backport from mainline
        2012-06-17  Tobias Burnus  <burnus@net-b.de>

        PR fortran/53691
        PR fortran/53685
        * gfortran.dg/transfer_check_3.f90: New.


Added:
    branches/gcc-4_7-branch/gcc/testsuite/gfortran.dg/transfer_check_3.f90
Modified:
    branches/gcc-4_7-branch/gcc/fortran/ChangeLog
    branches/gcc-4_7-branch/gcc/fortran/check.c
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/53685] surprising warns about transfer with explicit character range
  2012-06-15 14:35 [Bug fortran/53685] New: surprising warns about transfer with explicit character range ajmay81 at googlemail dot com
                   ` (4 preceding siblings ...)
  2012-06-22 10:28 ` burnus at gcc dot gnu.org
@ 2012-09-24 13:58 ` ajmay81 at googlemail dot com
  2012-11-29 10:52 ` kloedej at knmi dot nl
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ajmay81 at googlemail dot com @ 2012-09-24 13:58 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53685

--- Comment #6 from Andy May <ajmay81 at googlemail dot com> 2012-09-24 13:57:37 UTC ---
Thanks for fixing this, the GCC 4.7.1 shipping with openSUSE 12.2 does not show
this problem, and a build of GCC 4.7.2 from source doesn't either. Providing
this has also been pushed to trunk and is not causing problems, I think this
bug can be closed.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/53685] surprising warns about transfer with explicit character range
  2012-06-15 14:35 [Bug fortran/53685] New: surprising warns about transfer with explicit character range ajmay81 at googlemail dot com
                   ` (5 preceding siblings ...)
  2012-09-24 13:58 ` ajmay81 at googlemail dot com
@ 2012-11-29 10:52 ` kloedej at knmi dot nl
  2013-04-22 19:23 ` janus at gcc dot gnu.org
  2013-04-26 22:50 ` janus at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: kloedej at knmi dot nl @ 2012-11-29 10:52 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53685

Jos de Kloe <kloedej at knmi dot nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kloedej at knmi dot nl

--- Comment #7 from Jos de Kloe <kloedej at knmi dot nl> 2012-11-29 10:52:32 UTC ---
I see a very similar problem with a slightly modified piece of testcode on
version 4.7.2. Not sure if it is exactly the same, but probably related to the
already patched issue. My testcode:

program testtransfer

  integer, parameter :: r8_ = Selected_Real_Kind(15,307)  ! = real*8
  integer, parameter :: nbytes_r8_ = 8
  real(r8_) :: val
  character(len=1), dimension(16) :: byte_array

  byte_array(:) = ' '
  call mytest(byte_array,val)
  print *,"val: ",val
contains
  subroutine mytest(byte_array,val)
    character(len=1), dimension(16), intent(in) :: byte_array
    real(r8_),intent(out) :: val
    val = transfer(byte_array(1:nbytes_r8_),val)    
  end subroutine mytest
end program testtransfer

Results:

>gfortran -Wall  -o transfer_problem transfer_problem.F90
transfer_problem.F90:15.19:

    val = transfer(byte_array(1:nbytes_r8_),val)    
                   1
Warning: Intrinsic TRANSFER at (1) has partly undefined result: source size 1 <
result size 8
>

This occurs for this version:
>gfortran --version | head -1
GNU Fortran (GCC) 4.7.2 20120921 (Red Hat 4.7.2-2)
on my Fedora17 system. (package gcc-gfortran-4.7.2-2.fc17.x86_64)

The problem is not present in:
>gfortran --version | head -1
GNU Fortran (GCC) 4.6.3 20120306 (Red Hat 4.6.3-2)
on a Fedora16 system. (package gcc-gfortran-4.6.3-2.fc16.x86_64)


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/53685] surprising warns about transfer with explicit character range
  2012-06-15 14:35 [Bug fortran/53685] New: surprising warns about transfer with explicit character range ajmay81 at googlemail dot com
                   ` (6 preceding siblings ...)
  2012-11-29 10:52 ` kloedej at knmi dot nl
@ 2013-04-22 19:23 ` janus at gcc dot gnu.org
  2013-04-26 22:50 ` janus at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: janus at gcc dot gnu.org @ 2013-04-22 19:23 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53685

--- Comment #8 from janus at gcc dot gnu.org 2013-04-22 19:23:37 UTC ---
Comment 7 is fixed on 4.9 trunk with the following commit:

Author: janus
Date: Mon Apr 22 19:14:22 2013
New Revision: 198155

URL: http://gcc.gnu.org/viewcvs?rev=198155&root=gcc&view=rev
Log:
2013-04-22  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/53685
    PR fortran/57022
    * check.c (gfc_calculate_transfer_sizes): Fix for array-valued SOURCE
    expressions.
    * simplify.c (gfc_simplify_sizeof,gfc_simplify_storage_size): Get rid
    of special treatment for EXPR_ARRAY.
    * target-memory.h (gfc_element_size): New prototype.
    * target-memory.c (size_array): Remove.
    (gfc_element_size): New function.
    (gfc_target_expr_size): Modified to always return the full size of the
    expression.


2013-04-22  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/53685
    PR fortran/57022
    * gfortran.dg/transfer_check_4.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/transfer_check_4.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/check.c
    trunk/gcc/fortran/simplify.c
    trunk/gcc/fortran/target-memory.c
    trunk/gcc/fortran/target-memory.h
    trunk/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/53685] surprising warns about transfer with explicit character range
  2012-06-15 14:35 [Bug fortran/53685] New: surprising warns about transfer with explicit character range ajmay81 at googlemail dot com
                   ` (7 preceding siblings ...)
  2013-04-22 19:23 ` janus at gcc dot gnu.org
@ 2013-04-26 22:50 ` janus at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: janus at gcc dot gnu.org @ 2013-04-26 22:50 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53685

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #9 from janus at gcc dot gnu.org 2013-04-26 22:50:35 UTC ---
(In reply to comment #8)
> Comment 7 is fixed on 4.9 trunk with the following commit:

which has also been backported to 4.8 and 4.7:

http://gcc.gnu.org/viewcvs?rev=198345&root=gcc&view=rev
http://gcc.gnu.org/viewcvs?rev=198348&root=gcc&view=rev


I think we can close this bug.


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-04-26 22:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-15 14:35 [Bug fortran/53685] New: surprising warns about transfer with explicit character range ajmay81 at googlemail dot com
2012-06-15 16:18 ` [Bug fortran/53685] " burnus at gcc dot gnu.org
2012-06-15 17:02 ` burnus at gcc dot gnu.org
2012-06-16 10:51 ` burnus at gcc dot gnu.org
2012-06-17 19:31 ` burnus at gcc dot gnu.org
2012-06-22 10:28 ` burnus at gcc dot gnu.org
2012-09-24 13:58 ` ajmay81 at googlemail dot com
2012-11-29 10:52 ` kloedej at knmi dot nl
2013-04-22 19:23 ` janus at gcc dot gnu.org
2013-04-26 22:50 ` janus at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).