Bug 104313 - [10/11/12/13 Regression] ICE verify_gimple failed with -ff2c since r10-2279-ge0af8f52b10385d8
Summary: [10/11/12/13 Regression] ICE verify_gimple failed with -ff2c since r10-2279-g...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 12.0
: P4 normal
Target Milestone: 10.5
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2022-01-31 20:02 UTC by G. Steinmetz
Modified: 2022-07-16 18:50 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2022-02-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description G. Steinmetz 2022-01-31 20:02:42 UTC
Started with r9, changed between 20190728 and 20190811 :


$ cat z1.f90
function f(a)
return
end


$ gfortran-12-20220130 -c z1.f90 -ff2c
z1.f90:1:0:

    1 | function f(a)
      |
Error: non-trivial conversion in 'var_decl'
real(kind=8)
real(kind=4)
D.4216 = __result_f;
z1.f90:1:0: internal compiler error: 'verify_gimple' failed
0xeba38d verify_gimple_in_seq(gimple*)
        ../../gcc/tree-cfg.cc:5211
0xb40ea1 gimplify_body(tree_node*, bool)
        ../../gcc/gimplify.cc:16292
0xb41147 gimplify_function_tree(tree_node*)
        ../../gcc/gimplify.cc:16363
0x952b17 cgraph_node::analyze()
        ../../gcc/cgraphunit.cc:675
0x955dc6 analyze_functions
        ../../gcc/cgraphunit.cc:1240
0x956f9d symbol_table::finalize_compilation_unit()
        ../../gcc/cgraphunit.cc:2500
Comment 1 Martin Liška 2022-02-01 09:09:33 UTC
Started with r10-2279-ge0af8f52b10385d8.
Comment 2 kargls 2022-02-01 15:52:51 UTC
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 6493cc2f6b1..908a4c6d42e 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -6474,7 +6474,7 @@ gfc_generate_return (void)
             NULL_TREE, and a 'return' is generated without a variable.
             The following generates a 'return __result_XXX' where XXX is
             the function name.  */
-         if (sym == sym->result && sym->attr.function)
+         if (sym == sym->result && sym->attr.function && !flag_f2c)
            {
              result = gfc_get_fake_result_decl (sym, 0);
              result = fold_build2_loc (input_location, MODIFY_EXPR,
Comment 3 Steve Kargl 2022-02-01 15:59:33 UTC
On Tue, Feb 01, 2022 at 03:52:51PM +0000, kargl at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104313
> 
> --- Comment #2 from kargl at gcc dot gnu.org ---
> diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
> index 6493cc2f6b1..908a4c6d42e 100644
> --- a/gcc/fortran/trans-decl.cc
> +++ b/gcc/fortran/trans-decl.cc
> @@ -6474,7 +6474,7 @@ gfc_generate_return (void)
>              NULL_TREE, and a 'return' is generated without a variable.
>              The following generates a 'return __result_XXX' where XXX is
>              the function name.  */
> -         if (sym == sym->result && sym->attr.function)
> +         if (sym == sym->result && sym->attr.function && !flag_f2c)
>             {
>               result = gfc_get_fake_result_decl (sym, 0);
>               result = fold_build2_loc (input_location, MODIFY_EXPR,
> 

Passes regression testing.
Comment 4 Richard Biener 2022-05-27 09:47:15 UTC
GCC 9 branch is being closed
Comment 5 Jakub Jelinek 2022-06-28 10:47:54 UTC
GCC 10.4 is being released, retargeting bugs to GCC 10.5.
Comment 6 Steve Kargl 2022-06-28 15:04:29 UTC
On Tue, Jun 28, 2022 at 10:47:54AM +0000, jakub at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104313
> 
> Jakub Jelinek <jakub at gcc dot gnu.org> changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>    Target Milestone|10.4                        |10.5
> 
> --- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
> GCC 10.4 is being released, retargeting bugs to GCC 10.5.
> 

The patch in comment 2 fixes the issue.  It was submitted
13 hours after the initial report.
Comment 7 anlauf 2022-07-15 17:59:08 UTC
(In reply to Steve Kargl from comment #6)
> The patch in comment 2 fixes the issue.  It was submitted
> 13 hours after the initial report.

Steve, if you like, I can commit your patch under your name.
It's pretty obvious.

How about the following testcase?

! { dg-do compile }
! { dg-additional-options "-ff2c -fdump-tree-original" }
!
! PR fortran/104313 - ICE verify_gimple failed with -ff2c
! Contributed by G.Steinmetz

      function f(a)
      return
      end

! { dg-final { scan-tree-dump-times "return" 1 "original" } }
Comment 8 kargls 2022-07-15 18:59:35 UTC
(In reply to anlauf from comment #7)
> (In reply to Steve Kargl from comment #6)
> > The patch in comment 2 fixes the issue.  It was submitted
> > 13 hours after the initial report.
> 
> Steve, if you like, I can commit your patch under your name.
> It's pretty obvious.
> 
> How about the following testcase?
> 
> ! { dg-do compile }
> ! { dg-additional-options "-ff2c -fdump-tree-original" }
> !
> ! PR fortran/104313 - ICE verify_gimple failed with -ff2c
> ! Contributed by G.Steinmetz
> 
>       function f(a)
>       return
>       end
> 
> ! { dg-final { scan-tree-dump-times "return" 1 "original" } }

LGTM.

Whether my name appears or not isn't important to me.  A working compiler is.  The patch itself seems obvious, and I suspect you would have eventually found it. So commit as yo see fit.
Comment 9 GCC Commits 2022-07-15 20:08:58 UTC
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:517fb1a78102df43f052c6934c27dd51d786aff7

commit r13-1715-g517fb1a78102df43f052c6934c27dd51d786aff7
Author: Steve Kargl <kargl@gcc.gnu.org>
Date:   Fri Jul 15 22:07:15 2022 +0200

    Fortran: do not generate conflicting results under -ff2c [PR104313]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/104313
            * trans-decl.cc (gfc_generate_return): Do not generate conflicting
            fake results for functions with no result variable under -ff2c.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/104313
            * gfortran.dg/pr104313.f: New test.
Comment 10 GCC Commits 2022-07-16 18:30:44 UTC
The releases/gcc-12 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

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

commit r12-8572-gc1b0037bcc26019a87935e5634b6d448e9773193
Author: Steve Kargl <kargl@gcc.gnu.org>
Date:   Fri Jul 15 22:07:15 2022 +0200

    Fortran: do not generate conflicting results under -ff2c [PR104313]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/104313
            * trans-decl.cc (gfc_generate_return): Do not generate conflicting
            fake results for functions with no result variable under -ff2c.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/104313
            * gfortran.dg/pr104313.f: New test.
    
    (cherry picked from commit 517fb1a78102df43f052c6934c27dd51d786aff7)
Comment 11 GCC Commits 2022-07-16 18:39:59 UTC
The releases/gcc-11 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:663ac94cf02b18c9c89a2ada9d3c7cded08e29d6

commit r11-10150-g663ac94cf02b18c9c89a2ada9d3c7cded08e29d6
Author: Steve Kargl <kargl@gcc.gnu.org>
Date:   Fri Jul 15 22:07:15 2022 +0200

    Fortran: do not generate conflicting results under -ff2c [PR104313]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/104313
            * trans-decl.c (gfc_generate_return): Do not generate conflicting
            fake results for functions with no result variable under -ff2c.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/104313
            * gfortran.dg/pr104313.f: New test.
    
    (cherry picked from commit 517fb1a78102df43f052c6934c27dd51d786aff7)
Comment 12 GCC Commits 2022-07-16 18:48:49 UTC
The releases/gcc-10 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:168a1ae79bb86bdfe482c7c80ea742d40cc414c5

commit r10-10898-g168a1ae79bb86bdfe482c7c80ea742d40cc414c5
Author: Steve Kargl <kargl@gcc.gnu.org>
Date:   Fri Jul 15 22:07:15 2022 +0200

    Fortran: do not generate conflicting results under -ff2c [PR104313]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/104313
            * trans-decl.c (gfc_generate_return): Do not generate conflicting
            fake results for functions with no result variable under -ff2c.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/104313
            * gfortran.dg/pr104313.f: New test.
    
    (cherry picked from commit 517fb1a78102df43f052c6934c27dd51d786aff7)
Comment 13 anlauf 2022-07-16 18:50:09 UTC
Fixed.

Thanks for the report!