]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cobol/119229 - fix external variable declaration
authorRichard Biener <rguenther@suse.de>
Wed, 12 Mar 2025 12:46:14 +0000 (13:46 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 13 Mar 2025 08:16:01 +0000 (09:16 +0100)
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.

gcc/cobol/gengen.cc
gcc/testsuite/cobol.dg/pr119229.cob [new file with mode: 0644]

index c39af0b45d837083948a34594db0245a71bfd939..4fc0a830c1ed4118a657f7345da666464122b6ce 100644 (file)
@@ -1012,13 +1012,9 @@ gg_declare_variable(tree type_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;
+      DECL_EXTERNAL (var_decl) = 1;
       TREE_PUBLIC(var_decl) = 1;
       break;
     }
diff --git a/gcc/testsuite/cobol.dg/pr119229.cob b/gcc/testsuite/cobol.dg/pr119229.cob
new file mode 100644 (file)
index 0000000..e7b5000
--- /dev/null
@@ -0,0 +1,16 @@
+*> { 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".