Bug 96469 - Compile-time check for change in DO variable in contained procedures
Summary: Compile-time check for change in DO variable in contained procedures
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 11.0
: P3 enhancement
Target Milestone: ---
Assignee: Thomas Koenig
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-08-04 18:33 UTC by Thomas Koenig
Modified: 2020-08-05 18:58 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-08-04 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Koenig 2020-08-04 18:33:41 UTC
What's checked at runtime in do_check_4.f90

PROGRAM test
  IMPLICIT NONE
  INTEGER :: i
  DO i=1,100
    CALL do_something()
  ENDDO
CONTAINS
 SUBROUTINE do_something()
 IMPLICIT NONE
   DO i=1,10
   ENDDO
 END SUBROUTINE do_something
END PROGRAM test

can also be tested at compile-time, with an error issued.

As a matter of fact, I have a patch regtesting right now, I just wanted
put this into bugzilla as an anchor.
Comment 1 GCC Commits 2020-08-05 16:40:01 UTC
The master branch has been updated by Thomas Kथà¤nig <tkoenig@gcc.gnu.org>:

https://gcc.gnu.org/g:27eac9ee6137a6b5ae693b54cafa22bdc0cbcd5a

commit r11-2578-g27eac9ee6137a6b5ae693b54cafa22bdc0cbcd5a
Author: Thomas Koenig <tkoenig@gcc.gnu.org>
Date:   Wed Aug 5 18:37:32 2020 +0200

    Static analysis for definition of DO index variables in contained procedures.
    
    When encountering a procedure call in a DO loop, this patch checks if
    the call is to a contained procedure, and if it is, check for
    changes in the index variable.
    
    gcc/fortran/ChangeLog:
    
            PR fortran/96469
            * frontend-passes.c (doloop_contained_function_call): New
            function.
            (doloop_contained_procedure_code): New function.
            (CHECK_INQ): Macro for inquire checks.
            (doloop_code): Invoke doloop_contained_procedure_code and
            doloop_contained_function_call if appropriate.
            (do_intent): Likewise.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/96469
            * gfortran.dg/do_check_4.f90: Hide change in index variable
            from compile-time analysis.
            * gfortran.dg/do_check_13.f90: New test.
Comment 2 GCC Commits 2020-08-05 18:55:18 UTC
The master branch has been updated by Thomas Kथà¤nig <tkoenig@gcc.gnu.org>:

https://gcc.gnu.org/g:dd30d93f1a3ead7b814c1b179cf7197e4bf1e183

commit r11-2579-gdd30d93f1a3ead7b814c1b179cf7197e4bf1e183
Author: Thomas Koenig <tkoenig@gcc.gnu.org>
Date:   Wed Aug 5 20:53:44 2020 +0200

    Added test case to make sure that legal cases still pass.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/96469
            * gfortran.dg/do_check_14.f90: New test.
Comment 3 Thomas Koenig 2020-08-05 18:58:51 UTC
Fixed on trunk, closing.