OCamlPro / gnucobol

A clone of the sourceforge GnuCOBOL compiler from COBOL to C.
https://get-superbol.com
GNU Lesser General Public License v3.0
20 stars 23 forks source link

Fix codegen bug with FD GLOBAL and nested programs #96

Closed lefessan closed 1 year ago

lefessan commented 1 year ago

The program added in the testsuite generates a C error when compiled with earlier versions, for a missing label:

$ cobc -F test2.cob
test2.c: In function ‘NESTED__PROGRAM__1__2_0_’:
test2.c:799:5: error: label ‘l_1’ used but not defined
  799 |     goto l_1;
      |     ^~~~

The reason is that has_global_file is incorrectly unset in nested sub-programs.

This PR fixes this problem by only unsetting it depending on the level at which it was set.

codecov-commenter commented 1 year ago

Codecov Report

Merging #96 (56b0268) into gcos4gnucobol-3.x (fcd562f) will increase coverage by 0.02%. The diff coverage is 88.88%.

:mega: This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@                  Coverage Diff                  @@
##           gcos4gnucobol-3.x      #96      +/-   ##
=====================================================
+ Coverage              65.46%   65.48%   +0.02%     
=====================================================
  Files                     31       31              
  Lines                  57258    57264       +6     
  Branches               15051    15054       +3     
=====================================================
+ Hits                   37482    37501      +19     
+ Misses                 13906    13894      -12     
+ Partials                5870     5869       -1     
Impacted Files Coverage Δ
cobc/codegen.c 74.82% <88.88%> (+0.05%) :arrow_up:

... and 2 files with indirect coverage changes

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

GitMensch commented 1 year ago

@lefessan Could you please add the necessary tests for the following (and rebase)?

if it already works with user-specified error-handling (a DECLARATIVE in the outer program) then we may use the same approach for the default handler; if it doesn't then we should adjust the codegen for both cases (may need a special [=negative] entry point).

lefessan commented 1 year ago

So, actually, the bug is not triggered if USE GLOBAL declaratives are provided in the outer program, because another flag is used (prog->flag_gen_error instead of has_global_file), and the outer declaratives are correctly called from the inner program.

lefessan commented 1 year ago

Is it ready for SVN ?

lefessan commented 1 year ago

@GitMensch It looks like the CI fails on Macosx on test 25, which is related to the diagnostics with caret. Did you test your changes on Macosx ?

GitMensch commented 1 year ago

It should abort if no USE section for the file's EXCEPTION is defined.

GitMensch commented 1 year ago

@GitMensch It looks like the CI fails on Macosx on test 25, which is related to the diagnostics with caret. Did you test your changes on Macosx ?

Nope, I'm not sure how well the MacOSX CI works at all... Could you recheck this, please?

GitMensch commented 1 year ago

ping (approved)

lefessan commented 1 year ago

I updated the comment and merged into SVN.