Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional index check in 3.x #191

Open
wants to merge 3 commits into
base: gcos4gnucobol-3.x
Choose a base branch
from

Conversation

ddeclerck
Copy link
Contributor

@ddeclerck ddeclerck commented Oct 9, 2024

This PR attemps to backport SVN commit 4953 4954 & 5358 to 3.x.

cobc/typeck.c Outdated
if (CB_FIELD_PTR (sub)->flag_indexed_by) {
continue;
}
}
if (cb_subscript_check != CB_SUB_CHECK_MAX
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's where I'm wondering if the added lines above interact badly with this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to wonder (my guess is this breaks cb_subscript_check: max) - but a reason to add this into the "enable / disable subscript check with ODO" test (run_subscripts.at) tests, which should get a prog2.cob in any case that uses an index in any case (which should behave identical for the current tests but likely break with the new option [which only makes sense in the prog2.cob test as it only applies to indexes).
... while you at this: please replace the leading tabs in that test's prog.cob.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this was removed from trunk in the subsequent commit (4954).

@ddeclerck ddeclerck requested a review from GitMensch October 10, 2024 09:14
Copy link
Collaborator

@GitMensch GitMensch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new cobc option and should have an entry in the NEWS.

Your guess about the broken combination is likely correct and you'd need to adjust the new code to also include the new dialect option added in the meantime - but the (currently missing) extended test case will show if this is the case.

Note: please reword the help in flag.def, maybe something like "for index-names, don't apply EC-BOUND-SUBSCRIPT on subscript use per ISO rules but but on adjusting the index-name via SET or PERFORM statements, to reduce the amount of checks done".
I also wonder if we should place "index" into that option somewhere...

Please include into cobc/Changelog both Ron's original entry (with a remark "merged on YYYY-MM-DD as new option) and your on-top changes (the option and possibly inclusion into the dialect code) with that date.

cobc/typeck.c Outdated
if (CB_FIELD_PTR (sub)->flag_indexed_by) {
continue;
}
}
if (cb_subscript_check != CB_SUB_CHECK_MAX
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to wonder (my guess is this breaks cb_subscript_check: max) - but a reason to add this into the "enable / disable subscript check with ODO" test (run_subscripts.at) tests, which should get a prog2.cob in any case that uses an index in any case (which should behave identical for the current tests but likely break with the new option [which only makes sense in the prog2.cob test as it only applies to indexes).
... while you at this: please replace the leading tabs in that test's prog.cob.

@ddeclerck
Copy link
Contributor Author

Actually I'm not very confident I could do that quickly enough. I'd rather delegate this so I could focus on the GC3/GC4 merge - the clock's ticking and the days allocated to this task are almost depleted.

@GitMensch
Copy link
Collaborator

I was surprised you took on that backport. The issue that I've now realized is - if you want to merge the dialect option from GC3 to GC4 then this has to be done in any case :-/

@ddeclerck
Copy link
Contributor Author

I was surprised you took on that backport. The issue that I've now realized is - if you want to merge the dialect option from GC3 to GC4 then this has to be done in any case :-/

True indeed ; that dialect option is commit 5087 (so this will be a problem in ~50 commits). Though I'm just realizing now that feature was implemented by Nicolas ; I'm gonna ask him for help.

@ddeclerck ddeclerck force-pushed the index_check branch 2 times, most recently from 02e51ce to e27d944 Compare October 14, 2024 10:29
@GitMensch
Copy link
Collaborator

MSVC CI should be fixed with updating from upstream (I've worked on that before my vacation).

Apart from that: What is the state of this PR?

@ddeclerck
Copy link
Contributor Author

Apart from that: What is the state of this PR?

I'd stay "stale" - waiting for someone else to take over.
In the meantime I made PR #194 to (temporarily) disable that check in GC4 so that I could continue the merge (as discussed in #147 (comment)).

@ddeclerck ddeclerck changed the title Add optional index check Add optional index check in 3.x Oct 21, 2024
Copy link
Collaborator

@GitMensch GitMensch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... oops, forget to send "submit"... so here is my (6 weeks old?) review, requesting changes.

tests/testsuite.src/syn_occurs.at Outdated Show resolved Hide resolved
PROCEDURE DIVISION.
MOVE 5 TO MAXIDX
SET NIDX TO IB1.
DISPLAY "Initial value: " NIDX.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is unrelated - if we haven't tested that yet, then it should be a separate test (run once with std=default and -std=ibm and once with std=mf (output only "bigger than max" as the value will be different with 32/64 bit there)

tests/testsuite.src/run_subscripts.at Show resolved Hide resolved
cobc/typeck.c Outdated Show resolved Hide resolved
Copy link
Collaborator

@GitMensch GitMensch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First: Sorry that the review took so long. I did not submit it before; but that second view now actually brought some more "content" in, so that's possibly not bad.

The non-standard check as possible performance boost while keeping checks enabled are not an actual part of this PR (so far).

Depending on how you want to go on, we could reduce this PR to syntax improvement (parser) and the additional useful warning - and drop the change top flag.def.
Then maybe create a follow-up PR which has the additional move to the non-standard RANGE check (or postpone this for later).

... or: work on this to get this "all in"; but that will definitely be more work for nowö.

@@ -21,6 +21,7 @@


#include "config.h"
#include "libcob/common.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is that included for?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this change come from?

END PROGRAM prog.
])

AT_CHECK([$COMPILE_ONLY -fopt-check-subscript-set prog.cob], [1], [], [prog.cob:22: error: an integer, INDEX, or a POINTER is expected here
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we commonly line-wrap this before the last [ - but that can be postponed until upstream commit

Comment on lines +13746 to +13748
void
cb_check_valid_set_index (cb_tree vars, int hasval, int setval)
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is only used here and should therefore be static (no entry in tree.h)

@@ -186,6 +186,9 @@ CB_FLAG (cb_flag_stack_check, 1, "stack-check",
_(" -fstack-check PERFORM stack checking\n"
" * turned on by --debug/-g"))

CB_FLAG (cb_flag_check_subscript_set, 1, "opt-check-subscript-set",
_(" -fopt-check-subscript-set check subscript in PERFORM/SET"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation has only the check for SET, not for PERFORM - has it?

Comment on lines +13977 to +13979
if (CB_EXCEPTION_ENABLE (COB_EC_RANGE_INDEX)) {
cb_check_valid_set_index (vars, 0, 0);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the check -> warning should be done always here; no check for the range

Comment on lines +13819 to +13822
if (cb_flag_check_subscript_set
&& CB_EXCEPTION_ENABLE (COB_EC_BOUND_SUBSCRIPT)) {
cb_check_valid_set_index (vars, hasval, setval);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as below - the check -> warning part should not be related to the exception

Comment on lines +13767 to +13770
if (emit_exception) {
cb_emit (CB_BUILD_FUNCALL_1 ("cob_set_exception",
cb_int (COB_EC_RANGE_INDEX)));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code around this is definitely useful; the fixed non-standard EC-RANGE exception in the compiled code is only useful when we do the same for common SET (run-time values) and skip the subscript exception runtime check for use of indexes later

@GitMensch
Copy link
Collaborator

Just stumbled over this, maybe the parser change already handles the issues mentioned in https://sourceforge.net/p/gnucobol/bugs/228/ (or can be extended to that)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants