The following makes vs_external_reference behave like documented,
declare a variable defined elsewhere which means not setting
TREE_STATIC but DECL_EXTERNAL.
Built on x86_64-unknown-linux-gnu, tested with the cobol.dg
testsuite (which doesn't mean much). The removed comment mentions
'stderr', possibly the NIST testsuite has coverage.
OK for trunk?
Thanks,
Richard.
PR cobol/119229
* gengen.cc (gg_declare_variable): Use DECL_EXTERNAL and
drop TREE_STATIC for vs_external_reference.
* cobol.dg/pr119229.cob: New testcase.
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;
+ DECL_EXTERNAL (var_decl) = 1;
TREE_PUBLIC(var_decl) = 1;
break;
}
--- /dev/null
+*> { dg-do compile }
+*> { dg-options "-flto" { target lto } }
+IDENTIFICATION DIVISION.
+PROGRAM-ID. CobolGreeting.
+*>Program to display COBOL greetings
+DATA DIVISION.
+WORKING-STORAGE SECTION.
+01 IterNum PIC 9 VALUE 5.
+
+PROCEDURE DIVISION.
+BeginProgram.
+ PERFORM DisplayGreeting IterNum TIMES.
+ STOP RUN.
+
+DisplayGreeting.
+ DISPLAY "Greetings from COBOL".