Skip to content

Commit 90d9cdf

Browse files
author
Thomas Koenig
committed
Fix regression with -Wexternal-argument-mismatch.
The attached patch fixes an ICE regresseion where undo state was not handled properly when generating formal from actual arguments, which occurred under certain conditions with the newly introduced -Wexternal-argument-mismatch option. The fix is simple: When we are generating these symbols, we no longer need to undo anything, so we can just remove them. I had considered adding an extra optional argument, but decided against it on code clarity grounds. While looking at the code, I also saw that a member of gfc_symbol introduced with my patch should be a bitfield of width 1. gcc/fortran/ChangeLog: PR fortran/119157 * gfortran.h (gfc_symbol): Make ext_dummy_arglist_mismatch a one-bit bitfield (gfc_pop_undo_symbol): Declare prototype. * symbol.cc (gfc_pop_undo_symbol): New function. * interface.cc (gfc_get_formal_from_actual_arglist): Call it for artificially introduced formal variables. gcc/testsuite/ChangeLog: PR fortran/119157 * gfortran.dg/interface_57.f90: New test.
1 parent 613f8dd commit 90d9cdf

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

gcc/fortran/gfortran.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -2026,7 +2026,7 @@ typedef struct gfc_symbol
20262026
/* Set if an external dummy argument is called with different argument lists.
20272027
This is legal in Fortran, but can cause problems with autogenerated
20282028
C prototypes for C23. */
2029-
unsigned ext_dummy_arglist_mismatch;
2029+
unsigned ext_dummy_arglist_mismatch:1;
20302030

20312031
/* Reference counter, used for memory management.
20322032
@@ -3736,6 +3736,7 @@ void gfc_traverse_user_op (gfc_namespace *, void (*)(gfc_user_op *));
37363736
void gfc_save_all (gfc_namespace *);
37373737

37383738
void gfc_enforce_clean_symbol_state (void);
3739+
void gfc_pop_undo_symbol (void);
37393740

37403741
gfc_gsymbol *gfc_get_gsymbol (const char *, bool bind_c);
37413742
gfc_gsymbol *gfc_find_gsymbol (gfc_gsymbol *, const char *);

gcc/fortran/interface.cc

+2
Original file line numberDiff line numberDiff line change
@@ -5836,6 +5836,8 @@ gfc_get_formal_from_actual_arglist (gfc_symbol *sym,
58365836
{
58375837
snprintf (name, GFC_MAX_SYMBOL_LEN, "_formal_%d", var_num ++);
58385838
gfc_get_symbol (name, gfc_current_ns, &s);
5839+
/* We do not need this in an undo table. */
5840+
gfc_pop_undo_symbol();
58395841
if (a->expr->ts.type == BT_PROCEDURE)
58405842
{
58415843
gfc_symbol *asym = a->expr->symtree->n.sym;

gcc/fortran/symbol.cc

+5
Original file line numberDiff line numberDiff line change
@@ -3898,6 +3898,11 @@ enforce_single_undo_checkpoint (void)
38983898
gcc_checking_assert (single_undo_checkpoint_p ());
38993899
}
39003900

3901+
void
3902+
gfc_pop_undo_symbol ()
3903+
{
3904+
latest_undo_chgset->syms.pop();
3905+
}
39013906

39023907
/* Undoes all the changes made to symbols in the current statement. */
39033908

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
! { dg-do compile }
2+
! { dg-options "-Wexternal-argument-mismatch" }
3+
! PR 119157 - this used to ICE because undo state was not
4+
! correctly handled.
5+
6+
MODULE lmdif_module
7+
implicit none
8+
CONTAINS
9+
SUBROUTINE lmdif (fcn, m)
10+
EXTERNAL fcn
11+
integer m
12+
call fcn (m)
13+
END SUBROUTINE lmdif
14+
END MODULE

0 commit comments

Comments
 (0)