fix profiling of EVALUATE#208
Conversation
93347f5 to
1d7aadb
Compare
|
please add the test case from the original example to the testsuite, then that's good to upstream |
276e97a to
0867bf3
Compare
|
I added the test, and also fixed the same code for break, though I don't have a test case for that one... |
|
Is it still ok for SVN with the change to the break function ? |
|
I'm not sure yet to get the complete picture, What are the elements of the chain(s) with and what without -fperf? [I'll check fir the break part in the meantime] |
|
For example, in the test, the chain would be [ CALL TestRecurse ] in the non-profiling case, and [ C_CALL "prof_begin_call" ; CALL TestRecurse ; C_CALL "prof_end_call" ] in the profiling case. The C_CALL are not "CB_STATEMENT_P", so the previous test was failing and behaving the same as if it was a GOTO, because the test was not correctly written. I think that, in the case of a GOTO, profiling does not add any information before and after (it adds information to the GOTO itself), so it should be the same as without profiling. |
|
Updated testcase: IDENTIFICATION DIVISION.
PROGRAM-ID. Main.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 STR PIC X(6) VALUE "..-..-".
01 OFFSET BINARY-LONG UNSIGNED.
PROCEDURE DIVISION.
MOVE 1 TO OFFSET
PERFORM UNTIL OFFSET > LENGTH OF STR
CALL "TestRecurse" USING STR OFFSET
END-PERFORM.
END PROGRAM Main.
IDENTIFICATION DIVISION.
PROGRAM-ID. TestRecurse IS RECURSIVE.
DATA DIVISION.
LINKAGE SECTION.
01 LK-STR.
03 LK-CHR PIC X OCCURS 6
>> IF BREAK IS DEFINED
INDEXED BY LK-IDX
>> END-IF
.
01 LK-OFFSET BINARY-LONG UNSIGNED.
PROCEDURE DIVISION USING LK-STR LK-OFFSET.
DISPLAY "LK-OFFSET: " LK-OFFSET
>> IF BREAK IS DEFINED
SET LK-IDX TO LK-OFFSET
SEARCH LK-CHR
AT END
IF LK-OFFSET > 20
GOBACK
END-IF
ADD 1 TO LK-OFFSET
CALL "TestRecurse" USING LK-STR LK-OFFSET
WHEN LK-CHR (LK-IDX) = "."
ADD 1 TO LK-OFFSET
END-SEARCH.
>> ELSE
EVALUATE LK-STR(LK-OFFSET:1)
WHEN "."
ADD 1 TO LK-OFFSET
CALL "TestRecurse" USING LK-STR LK-OFFSET
WHEN OTHER
ADD 1 TO LK-OFFSET
END-EVALUATE.
>> END-IF
END PROGRAM TestRecurse.compile with maybe rename the testcase as "profiling and codegen" or something similar, with keywords Please add both expected profiling results to the testcase as well. |
|
In your example, where is the break supposed to be inserted ? In the WHEN of the SEARCH ? Note that on my computer, this program with -DBREAK fails to compile without profiling, but works ok with profiling... |
|
The break is not inserted with the current svn version: /* Line: 42 : CALL : prof.cob */
#line 42 "prof.cob"
cob_nop ();
#line 448 "prof.c"
cob_procedure_params[0] = COB_SET_DATA (f_36, b_36);
cob_procedure_params[1] = COB_SET_DATA (f_39, b_39);
cob_glob_ptr->cob_call_params = 2;
cob_glob_ptr->cob_stmt_exception = 0;
if (unlikely((cob_glob_ptr->cob_exception_code & 0x0b00) == 0x0b00)) cob_glob_ptr->cob_exception_code = 0;
if (unlikely(call_TestRecurse.funcvoid == NULL || cob_glob_ptr->cob_physical_cancel == 1))
{
call_TestRecurse.funcvoid = cob_resolve_cobol ("TestRecurse", 0, 1);
}
b_21 = ((int (*)(void *, void *))call_TestRecurse.funcint) (b_36, b_39);
cob_prof_exit_procedure (prof_info, 3);
}
/* Line: 43 : WHEN : prof.cob */without: /* Line: 42 : CALL : prof.cob */
#line 42 "prof.cob"
cob_nop ();
#line 425 "prof.c"
cob_procedure_params[0] = COB_SET_DATA (f_36, b_36);
cob_procedure_params[1] = COB_SET_DATA (f_39, b_39);
cob_glob_ptr->cob_call_params = 2;
cob_glob_ptr->cob_stmt_exception = 0;
if (unlikely((cob_glob_ptr->cob_exception_code & 0x0b00) == 0x0b00)) cob_glob_ptr->cob_exception_code = 0;
if (unlikely(call_TestRecurse.funcvoid == NULL || cob_glob_ptr->cob_physical_cancel == 1))
{
call_TestRecurse.funcvoid = cob_resolve_cobol ("TestRecurse", 0, 1);
}
b_21 = ((int (*)(void *, void *))call_TestRecurse.funcint) (b_36, b_39);
break;
}
/* Line: 43 : WHEN : prof.cob */ |
|
If the program fails to compile, then please recode it to just do some addition in the sub-program no recursive calls (at least that would be my guess for the error). This also helps to keep that test to be more focused. rechecked: The compile error got in with GnuCOBOL 3.2 (3.1.2 compiles it clean, 3.3 dev doesn't) - that should get a new upstream bug report (and be fixed until 3.3 final, rc1 would be nice, but not necessary as the error was already released). |
Fix a bug where INDEXED BY in LINKAGE SECTION would cause the variable not to be added to the local include file, causing a compile error of the C code.
0867bf3 to
e259ff7
Compare
|
I think I found the bug with the program: the INDEXED BY appearing in LINKAGE SECTION was not correctly handled by gnucobol, I had to modify parser.y to set its index_type to CB_INT_INDEX, as if it were defined in the LOCAL-STORAGE section. |
|
Thanks for the analysis and fix, which are correct.
Please do the following adjustments to the tests and we should be able to upstream this today:
|
|
I may be able to do the first 2 items tonight, but given my current agenda for this week and the next ones, I won't have time to do more... |
|
OK, let's split the effort, you do what you can and post a note for others to take over. |
|
Hello @GitMensch, |
GitMensch
left a comment
There was a problem hiding this comment.
Sorry for the late getting back to that.
Testsuite needs adjustment, code itself is fine.
| END PROGRAM TestRecurse. | ||
| ]) | ||
|
|
||
| AT_CHECK([$COMPILE --free prog.cob]) |
There was a problem hiding this comment.
no need for --free here (and if, then we should use the "new" variant with free as option), same below
| 01 LK-OFFSET BINARY-LONG UNSIGNED. | ||
|
|
||
| PROCEDURE DIVISION USING LK-STR LK-OFFSET. | ||
| DISPLAY "LK-OFFSET: " LK-OFFSET |
There was a problem hiding this comment.
let's just display 1 + 11 to make that more concise, also adjust the condition for > 10
| GOBACK | ||
| END-IF | ||
| ADD 1 TO LK-OFFSET | ||
| CALL "TestRecurse" USING LK-STR LK-OFFSET |
There was a problem hiding this comment.
no need for recursive calls here, we do that in the next test
| END PROGRAM recurse. | ||
| ]) | ||
|
|
||
| AT_CHECK([$COMPILE --free -fprof prog.cob]) |
There was a problem hiding this comment.
same as above, no need for free, less output if we only display 1 + 5 (maybe even WITH NO ADVANCING and no text...)
| AT_SETUP([INDEXED BY in LINKAGE]) | ||
|
|
||
| AT_KEYWORDS([runmisc OCCURS SEARCH]) |
There was a problem hiding this comment.
get those lines together and add the keyword "profiling"
| AT_SETUP([profiling and codegen]) | ||
| AT_KEYWORDS([EVALUATE]) |
There was a problem hiding this comment.
Shouldn't that be AT_SETUP([profiling EVALUATE])?
... and possibly most of those test include the keyword runmisc?
| PROCEDURE DIVISION. | ||
| MOVE 1 TO OFFSET | ||
| PERFORM UNTIL OFFSET > LENGTH OF STR | ||
| CALL "TestRecurse" USING STR OFFSET |
There was a problem hiding this comment.
I guess one recursive test is enough, if this test should also have it then move the "simple recursive call" up front
Try to fix issue reported in #110 (comment) and meyfa/CobolCraft#214 (comment).