This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/77680] [5/6/7 Regression] [F03] ICE in ctor_for_folding, at varpool.c:419
- From: "jakub at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 09 Nov 2016 16:58:51 +0000
- Subject: [Bug fortran/77680] [5/6/7 Regression] [F03] ICE in ctor_for_folding, at varpool.c:419
- Auto-submitted: auto-generated
- References: <bug-77680-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77680
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |burnus at gcc dot gnu.org,
| |jakub at gcc dot gnu.org
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Indeed. Not sure what bind(c) should mean on automatic variables. Shall it
force them to be non-automatic (SAVEd), or not?
If not, I bet we want something like the following. Plus the question is
if DECL_COMMON should be added for initialized variables, in C it is just
uninitialized non-automatic variables that are common. Plus, shouldn't it
also depend on -fcommon switch?
--- gcc/fortran/trans-decl.c.jj 2016-10-31 13:28:11.000000000 +0100
+++ gcc/fortran/trans-decl.c 2016-11-09 17:50:33.695988616 +0100
@@ -588,26 +588,6 @@ gfc_finish_var_decl (tree decl, gfc_symb
if (sym->attr.cray_pointee)
return;
- if(sym->attr.is_bind_c == 1 && sym->binding_label)
- {
- /* We need to put variables that are bind(c) into the common
- segment of the object file, because this is what C would do.
- gfortran would typically put them in either the BSS or
- initialized data segments, and only mark them as common if
- they were part of common blocks. However, if they are not put
- into common space, then C cannot initialize global Fortran
- variables that it interoperates with and the draft says that
- either Fortran or C should be able to initialize it (but not
- both, of course.) (J3/04-007, section 15.3). */
- TREE_PUBLIC(decl) = 1;
- DECL_COMMON(decl) = 1;
- if (sym->attr.access == ACCESS_PRIVATE && !sym->attr.public_used)
- {
- DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
- DECL_VISIBILITY_SPECIFIED (decl) = true;
- }
- }
-
/* If a variable is USE associated, it's always external. */
if (sym->attr.use_assoc || sym->attr.used_in_submodule)
{
@@ -635,10 +615,10 @@ gfc_finish_var_decl (tree decl, gfc_symb
initialized variables are SAVE_IMPLICIT and explicitly saved are
SAVE_EXPLICIT. */
if (!sym->attr.use_assoc
- && (sym->attr.save != SAVE_NONE || sym->attr.data
- || (sym->value && sym->ns->proc_name->attr.is_main_program)
- || (flag_coarray == GFC_FCOARRAY_LIB
- && sym->attr.codimension && !sym->attr.allocatable)))
+ && (sym->attr.save != SAVE_NONE || sym->attr.data
+ || (sym->value && sym->ns->proc_name->attr.is_main_program)
+ || (flag_coarray == GFC_FCOARRAY_LIB
+ && sym->attr.codimension && !sym->attr.allocatable)))
TREE_STATIC (decl) = 1;
/* If derived-type variables with DTIO procedures are not made static
@@ -708,6 +688,27 @@ gfc_finish_var_decl (tree decl, gfc_symb
}
}
+ if ((sym->attr.is_bind_c == 1 && sym->binding_label)
+ && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
+ {
+ /* We need to put variables that are bind(c) into the common
+ segment of the object file, because this is what C would do.
+ gfortran would typically put them in either the BSS or
+ initialized data segments, and only mark them as common if
+ they were part of common blocks. However, if they are not put
+ into common space, then C cannot initialize global Fortran
+ variables that it interoperates with and the draft says that
+ either Fortran or C should be able to initialize it (but not
+ both, of course.) (J3/04-007, section 15.3). */
+ TREE_PUBLIC (decl) = 1;
+ DECL_COMMON (decl) = 1;
+ if (sym->attr.access == ACCESS_PRIVATE && !sym->attr.public_used)
+ {
+ DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
+ DECL_VISIBILITY_SPECIFIED (decl) = true;
+ }
+ }
+
/* Handle threadprivate variables. */
if (sym->attr.threadprivate
&& (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))