-
Notifications
You must be signed in to change notification settings - Fork 25
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
fix implicit overlapping move #193
base: gcos4gnucobol-3.x
Are you sure you want to change the base?
fix implicit overlapping move #193
Conversation
34621d7
to
5a63526
Compare
Please check a bit deeper - the compiler should, depending on the dialect, generate either a move or a move_ibm, and the first should uses memcpy... or does this only happen if the target is numeric and the source isn't? Is there still a different result depending on the move-ibm dialect option? I think that should be also possible to reproduce without a file, just using a "normal" overlapping MOVE, no? |
I won't have time to investigate more, but:
|
To give more details, the program suggested by Fabrice is IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT MY-FILE ASSIGN TO "testfile"
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD MY-FILE.
01 MY-REC PIC 9(5).
PROCEDURE DIVISION.
OPEN INPUT MY-FILE.
READ MY-FILE INTO MY-REC.
DISPLAY MY-REC.
CLOSE MY-FILE.
STOP RUN. generating (for READ): /* Line: 15 : READ : move.cob */
cob_read_next (h_MY_FILE, NULL, 1);
if (unlikely(cob_glob_ptr->cob_exception_code != 0))
{
/* USE PROCEDURE Default Error Handler */
// ...
}
else
{
cob_move (&f_18, &f_17);
} with fields static const cob_field_attr a_1 = {0x21, 0, 0, 0x0000, NULL};
static const cob_field_attr a_2 = {0x10, 5, 0, 0x0000, NULL};
static cob_field f_17 = {5, b_18, &a_2}; /* MY-REC */
static cob_field f_18 = {5, b_18, &a_1}; /* MY-FILE Record */ If I understand correctly, the problem (display of What do you think? |
The first thing to verify is that instead of The second part is the generation of FD MY-FILE.
01 MY-REC.
03 MY-DATA PIC 9(5).
....
READ MY-FILE INTO MY-REC. will again lead to the "expected" result - even without The issue here is that If this is the case then we can adjust the following in if (into) {
// TODO: check if overlapping and if yes, after warning codegen cb_build_move_copy
current_statement->handler3 = cb_build_move (rec, into);
} Note: we possibly have a similar problem the other way around, which we can easily handle specifically in if (from && (!CB_FIELD_P(from) || (CB_FIELD_PTR (from) != CB_FIELD_PTR (record)))) {
// TODO: check if overlapping and if yes, after warning codegen cb_build_move_copy
cb_emit (cb_build_move (from, record));
} As both are nearly identical this possibly can be done in a new @engboris Will you inspect this more and possibly come up with a fix (and some refactoring)? |
No Do you mean we're exepected to use
Yes, I'll take care of this PR. |
Yes, so maybe the overlap checking does not work correctly between "fd record" and "variable" (I haven't checked more details).
Thanks, hope to review it tomorrow, if it would be already by then. |
From what I see, return CB_BUILD_FUNCALL_2 ("cob_move", src, dst); at the end of the function. Here is the code of static cb_tree
cb_build_move_copy (cb_tree src, cb_tree dst)
{
int size;
size = cb_field_size (dst);
if (size == 1) {
return CB_BUILD_FUNCALL_2 ("$F", dst, src);
}
if (cb_move_ibm) {
overlapping = 0;
return CB_BUILD_FUNCALL_3 ("cob_move_ibm",
CB_BUILD_CAST_ADDRESS (dst),
CB_BUILD_CAST_ADDRESS (src),
CB_BUILD_CAST_LENGTH (dst));
} else if (overlapping
|| CB_FIELD_PTR (src)->storage == CB_STORAGE_LINKAGE
|| CB_FIELD_PTR (dst)->storage == CB_STORAGE_LINKAGE
|| CB_FIELD_PTR (src)->flag_item_based
|| CB_FIELD_PTR (dst)->flag_item_based) {
overlapping = 0;
return CB_BUILD_FUNCALL_3 ("memmove",
CB_BUILD_CAST_ADDRESS (dst),
CB_BUILD_CAST_ADDRESS (src),
CB_BUILD_CAST_LENGTH (dst));
} else {
return CB_BUILD_FUNCALL_3 ("memcpy",
CB_BUILD_CAST_ADDRESS (dst),
CB_BUILD_CAST_ADDRESS (src),
CB_BUILD_CAST_LENGTH (dst));
}
} Do you have a suggestion @GitMensch? |
bd3796e
to
4c7b429
Compare
I tried something very naive. It works but I'm not sure this is the right thing to do as I don't have the big picture (I'll add Changelogs after confirmation). |
I ran into a small issue:
READ FILE-FD INTO RECORD
whereRECORD
is declared as theFD
ofFILE-FD
with a numeric type will end up always reading zeroes (because of an overlapping move). The compiler already issues a warning, but I think it is still better to get the correct behavior when possible, so I modified thecob_move_alphanum_to_display
to correctly handle overlaps (the extra cost is only paid in case of overlap).