As the runtime will always run into the AT END clause (or leave the search) the WHEN should not include cob_check_subscript.
::cobol
IDENTIFICATION DIVISION.
PROGRAM-ID. SEARCHBUG.
DATA DIVISION.
WORKING-STORAGE SECTION.
78 screen-max value 20.
77 screen-akt pic 9(02) comp-5.
*
01 screen-tab.
03 screen-entry occurs 0 to screen-max
depending on screen-akt
ascending key screen-name
indexed by screen-idx.
05 screen-name pic x(02).
05 screen-mode pic 9 value 0.
PROCEDURE DIVISION.
SEARCH ALL screen-entry
AT END
DISPLAY 'END'
*> we currently have cob_check_subscript here:
WHEN screen-name (screen-idx) = 'ABC'
DISPLAY 'FOUND'
END-SEARCH.
The error is the generated check in this part
::c
/* WHEN */
if (((int)(ret = cob_cmp (
(cob_check_subscript (b_10, 1, (*(cob_u8_ptr) (b_7)), "screen-name"),
COB_SET_FLD(f0, 2, b_8 + 3 * (b_10 - 1), &a_1) ), (cob_field *)&c_2)) == 0))
{
Currently not reproducable (the
WHENin this minimal sample does not produce the subscript check), leaving as pending for further investigation.trunk had no test case like you are talking about so that is why nothing fails.
And it does not really fail it is just doing unneeded checking.
Is that the issue?
So I make up a new test case that does:
The the WHEN becomes:
So your idea is to not do checks on the array subscript when the verb was
SEARCH ALL.If it does not say ALL, then it should continue doing the subscript checks.
Do I have this right?
Last edit: Simon Sobisch 2020-11-27
Nearly correct.
Yes: nothing fails here anywhere, this is just a performance issue.
Yes: The last test case does not exist anywhere, it was just to highlight that (all) references to the INDEX of the table that is the target of the SEARCH should not be checked, but other subscripts should.
To give a very special case:
in this case the first should not be checked, but the second should.
This also applies to plain SEARCH, which likely should have a one-time subscript check before the generated loop, but not within.
Simon
Reproduced with the internal testsuite, test "OCCURS INDEXED ASCENDING".
Both trunk (currently test 684) and 3.1 fail in doing the correct thing.
is generated as
Issue:
Line: 70 : WHENshould not include a subscript check for the tablesINDEXfield (in this caseb_19.It still should the subscript for the
DISPLAY(line 71) and it also should check it for a different index, for example with the code:where
REC-NAME-IDXshould not be checked, butREC-NAME-IDXshould.Question @rjnorman74: Do you see an option to omit the subscript check here? Especially when the table is huge: a libcob function call with a check for every entry to be in range (which is not necessary here as the entry is only set be the generated code) is something that has measurable performance effect (the actual memcmp doing the
WHENis resolved to a cpu-optimized function).