https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118896
--- Comment #2 from Mikael Morin <mikael at gcc dot gnu.org> --- This area of the code has an interesting history. TREE_READONLY was introduced for virtual tables with r0-114543 together with the fix for PR51809 diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index 0761ebb26d1d438c1e3b8570fdf5ea00b9744453..e8e54c77b79c5b94c664977a62a7b8500fb6bff0 100644 (file) --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -1485,7 +1485,10 @@ gfc_get_symbol_decl (gfc_symbol * sym) if (sym->attr.vtab || (sym->name[0] == '_' && strncmp ("__def_init", sym->name, 10) == 0)) - GFC_DECL_PUSH_TOPLEVEL (decl) = 1; + { + TREE_READONLY (decl) = 1; + GFC_DECL_PUSH_TOPLEVEL (decl) = 1; + } return decl; } Then TREE_READONLY was removed in favor of DECL_ARTIFICIAL in r10-3606 to fix PR84487 diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index a113f08e26be87be7783c802c5b1129d64548801..b701f4934401a00341178bba846566ea790c6eac 100644 (file) --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -1911,9 +1911,13 @@ gfc_get_symbol_decl (gfc_symbol * sym) if (sym->attr.associate_var) GFC_DECL_ASSOCIATE_VAR_P (decl) = 1; + /* We no longer mark __def_init as read-only so it does not take up + space in the read-only section and dan go into the BSS instead, + see PR 84487. Marking this as artificial means that OpenMP will + treat this as predetermined shared. */ if (sym->attr.vtab || (sym->name[0] == '_' && gfc_str_startswith (sym->name, "__def_init"))) - TREE_READONLY (decl) = 1; + DECL_ARTIFICIAL (decl) = 1; return decl; } And finally TREE_READONLY was restored for __def_init variables with initializer with r10-4319 to fix PR92113. diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index 630682cbac7210e25b5254a3792f17712baec053..ffa61111316c29d423e40e9f48c2e7e0b3d698a5 100644 (file) --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -1904,13 +1904,20 @@ gfc_get_symbol_decl (gfc_symbol * sym) if (sym->attr.associate_var) GFC_DECL_ASSOCIATE_VAR_P (decl) = 1; - /* We no longer mark __def_init as read-only so it does not take up - space in the read-only section and dan go into the BSS instead, - see PR 84487. Marking this as artificial means that OpenMP will - treat this as predetermined shared. */ - if (sym->attr.vtab - || (sym->name[0] == '_' && gfc_str_startswith (sym->name, "__def_init"))) - DECL_ARTIFICIAL (decl) = 1; + /* We only longer mark __def_init as read-only if it actually has an + initializer, it does not needlessly take up space in the + read-only section and can go into the BSS instead, see PR 84487. + Marking this as artificial means that OpenMP will treat this as + predetermined shared. */ + + bool def_init = gfc_str_startswith (sym->name, "__def_init"); + + if (sym->attr.vtab || def_init) + { + DECL_ARTIFICIAL (decl) = 1; + if (def_init && sym->value) + TREE_READONLY (decl) = 1; + } return decl; } But the latter patch has a different condition guarding TREE_READONLY from the one that was submitted to the list ( https://gcc.gnu.org/pipermail/fortran/2019-November/053368.html ) and used for backports ( r9-7960 and r8-9817 ). The condition in the submitted patch is: if (sym->attr.vtab || sym->value) which is equivalent to comment #1.