> -----Original Message-----
> From: Richard Biener <rguent...@suse.de>
> Sent: Wednesday, March 12, 2025 08:46
> To: gcc-patches@gcc.gnu.org
> Cc: rdub...@symas.com
> Subject: [PATCH] cobol/119229 - fix external variable declaration
> 
> 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?

I just did that thing where you look over your shoulder, spin back around,
point at your own chest, and say, "Who, me?"

I applied the patch, and ran it through our test cases on an x86_64.
Everything worked, which is good enough for us, at this point.

Please apply the patch.

> 
> 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                 |  6 +-----
>  gcc/testsuite/cobol.dg/pr119229.cob | 16 ++++++++++++++++
>  2 files changed, 17 insertions(+), 5 deletions(-)  create mode 100644
> gcc/testsuite/cobol.dg/pr119229.cob
> 
> diff --git a/gcc/cobol/gengen.cc b/gcc/cobol/gengen.cc index
> fc625faecf0..ea0521e0f24 100644
> --- a/gcc/cobol/gengen.cc
> +++ b/gcc/cobol/gengen.cc
> @@ -1013,13 +1013,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
> index 00000000000..e7b500067ee
> --- /dev/null
> +++ b/gcc/testsuite/cobol.dg/pr119229.cob
> @@ -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".
> --
> 2.43.0

Reply via email to