Skip to content

Commit

Permalink
Merge SVN 4104
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeclerck committed Jun 13, 2024
1 parent f90ab9c commit 42ebf2c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
66 changes: 35 additions & 31 deletions cobc/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -5259,40 +5259,39 @@ propagate_table (cb_tree x, int bgn_idx)
&& !f->depending)) {
/* Table size is known at compile time */
/* Generate inline 'memcpy' to propagate the array data */
if (occ > 1) {
output_block_open ();
output_block_open ();
output_prefix ();
output ("cob_u8_ptr b_ptr = ");
output_data(x);
if (bgn_idx > 1) {
output (" + %ld",len * (bgn_idx - 1));
maxlen -= len * (bgn_idx - 1);
}
output (";");
output_newline ();

/* double the chunks each time */
do {
output_prefix ();
output ("cob_u8_ptr b_ptr = ");
output_data(x);
if (bgn_idx > 1) {
output (" + %ld",len * (bgn_idx - 1));
maxlen -= len * (bgn_idx - 1);
}
output (";");
output ("memcpy (b_ptr + %6lu, b_ptr, %6lu);", len, len);
output ("\t/* %s: %6u thru %u */",
f->name, j + bgn_idx, j * 2 + bgn_idx - 1);
output_newline ();
/* double the chunks each time */
do {
output_prefix ();
output ("memcpy (b_ptr + %6lu, b_ptr, %6lu);", len, len);
output ("\t/* %s: %5d thru %d */",
f->name, j + bgn_idx, j * 2 + bgn_idx - 1);
output_newline ();
j = j * 2;
len = len * 2;
} while ((j * 2) < occ);
j = j * 2;
len = len * 2;
} while ((j * 2) < occ);

/* missing piece after last chunk */
if (j < occ
&& maxlen > len) {
output_prefix ();
output ("memcpy (b_ptr + %6lu, b_ptr, %6lu);",
len, maxlen - len);
output ("\t/* %s: %5d thru %d */",
f->name, j + bgn_idx, occ);
output_newline ();
}
output_block_close ();
/* missing piece after last chunk */
if (j < occ
&& maxlen > len) {
output_prefix ();
output ("memcpy (b_ptr + %6lu, b_ptr, %6lu);",
len, maxlen - len);
output ("\t/* %s: %6u thru %u */",
f->name, j + bgn_idx, occ);
output_newline ();
}
output_block_close ();
} else {
/* Table size is only known at run time */
output_prefix ();
Expand Down Expand Up @@ -6089,11 +6088,12 @@ output_initialize_compound (struct cb_initialize *p, cb_tree x)
}
} else {
struct cb_reference *ref = CB_REFERENCE (c);
cb_tree save_length, r2;
cb_tree save_check, save_length, r2;

/* Output initialization for the first record */
output_line ("/* initialize first record for %s */", f->name);
save_length = ref->length;
save_check = ref->check;
/* Output all 'check' first */
for (r2 = ref->check; r2; r2 = CB_CHAIN (r2)) {
output_stmt (CB_VALUE (r2));
Expand Down Expand Up @@ -6123,6 +6123,9 @@ output_initialize_compound (struct cb_initialize *p, cb_tree x)
}
}

/* all exceptions should have been raised above,
so temporarily detach from the reference */
ref->check = NULL;
ref->length = NULL;

for (pf = f; pf && !pf->flag_occurs_values; pf = pf->parent);
Expand All @@ -6134,6 +6137,7 @@ output_initialize_compound (struct cb_initialize *p, cb_tree x)
}

/* restore previous exception-checks for the reference */
ref->check = save_check;
ref->length = save_length;
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/testsuite.src/run_initialize.at
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,9 @@ AT_CHECK([$COMPILE prog.cob], [0], [], [])
AT_CHECK([$COBCRUN_DIRECT ./prog], [0], [], [])
AT_CHECK([$COMPILE prog2.cob], [0], [], [])
AT_CHECK([$COBCRUN_DIRECT ./prog2], [0], [], [])
# CHECKME: that should likely be implied with -std=ibm
#AT_CHECK([$COMPILE -std=ibm prog3.cob], [0], [], [])
#AT_CHECK([$COMPILE -fodoslide prog3.cob], [0], [], [])
#AT_CHECK([$COBCRUN_DIRECT ./prog3], [0], [], [])

AT_CLEANUP
Expand Down

0 comments on commit 42ebf2c

Please sign in to comment.