https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119229
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
We have in gg_declare_variable:
case vs_external:
// This is for defining variables with global scope
DECL_CONTEXT (var_decl) = gg_trans_unit.trans_unit_decl;
TREE_USED(var_decl) = 1;
TREE_STATIC(var_decl) = 1;
TREE_PUBLIC(var_decl) = 1;
seen[unique_name] = var_decl;
break;
case vs_external_reference:
// This is for referencing variables defined elsewhere
// TODO: Figure out why this is working. For accessing "stderr", it
// doesn't matter if TREE_PUBLIC is on, but TREE_STATIC has to be on.
This
// does *not* match what is seen when compiling a C program that accesses
// "stderr".
DECL_CONTEXT (var_decl) = gg_trans_unit.trans_unit_decl;
TREE_USED(var_decl) = 1;
TREE_STATIC(var_decl) = 1;
TREE_PUBLIC(var_decl) = 1;
break;
the description is not matching the implementation - a variable defined
elsewhere would _not_ be TREE_STATIC but DECL_EXTERNAL - the following
fixes the ICE and trivial testcases continue to work (I don't have a way
to do NIST tests yet).
diff --git a/gcc/cobol/gengen.cc b/gcc/cobol/gengen.cc
index fc625faecf0..02999546f70 100644
--- a/gcc/cobol/gengen.cc
+++ b/gcc/cobol/gengen.cc
@@ -1019,7 +1019,7 @@ gg_declare_variable(tree type_decl,
// "stderr".
DECL_CONTEXT (var_decl) = gg_trans_unit.trans_unit_decl;
TREE_USED(var_decl) = 1;
- TREE_STATIC(var_decl) = 1;
+ DECL_EXTERNAL (var_decl) = 1;
TREE_PUBLIC(var_decl) = 1;
break;
}