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

Fix decimal constant bug occuring when several programs in a COBOL file #113

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions cobc/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -13926,6 +13926,29 @@ codegen_internal (struct cb_program *prog, const int subsequent_call)
/* Switch to main storage file */
output_target = cb_storage_file;
}

/* Decimal constants */
{
struct literal_list* m;
int comment_gen = 0;
for (m = literal_cache; m; m = m->next) {
if (CB_TREE_CLASS (m->x) == CB_CLASS_NUMERIC
ddeclerck marked this conversation as resolved.
Show resolved Hide resolved
&& m->make_decimal) {
if (!comment_gen) {
comment_gen = 1;
output_local ("\n/* Decimal constants */\n");
}
output_local ("static\tcob_decimal\t%s%d;\n",
CB_PREFIX_DEC_FIELD, m->id);
output_local ("static\tcob_decimal\t*%s%d = NULL;\n",
CB_PREFIX_DEC_CONST, m->id);
}
}
if (comment_gen) {
output_local ("\n");
}
}

}

void
Expand Down Expand Up @@ -13965,28 +13988,6 @@ codegen_finalize (void)
}
}

/* Decimal constants */
{
struct literal_list* m;
int comment_gen = 0;
for (m = literal_cache; m; m = m->next) {
if (CB_TREE_CLASS (m->x) == CB_CLASS_NUMERIC
&& m->make_decimal) {
if (!comment_gen) {
comment_gen = 1;
output_storage ("\n/* Decimal constants */\n");
}
output_storage ("static\tcob_decimal\t%s%d;\n",
CB_PREFIX_DEC_FIELD, m->id);
output_storage ("static\tcob_decimal\t*%s%d = NULL;\n",
CB_PREFIX_DEC_CONST, m->id);
}
}
if (comment_gen) {
output_storage ("\n");
}
}

/* Clean up by clearing these */
attr_cache = NULL;
literal_cache = NULL;
Expand Down
29 changes: 29 additions & 0 deletions tests/testsuite.src/run_misc.at
Original file line number Diff line number Diff line change
Expand Up @@ -14570,3 +14570,32 @@ TST-DECIMAL IS < ZERO-DECIMAL


AT_CLEANUP

AT_SETUP([Decimal constants working after sub-program call])
ddeclerck marked this conversation as resolved.
Show resolved Hide resolved
AT_KEYWORDS([runmisc])

# this used to cause a SIGSEGV
ddeclerck marked this conversation as resolved.
Show resolved Hide resolved

AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 X PIC 9(2).
PROCEDURE DIVISION.
CALL "prog2"
IF X + 42 <> 0
ddeclerck marked this conversation as resolved.
Show resolved Hide resolved
DISPLAY "OK".
ddeclerck marked this conversation as resolved.
Show resolved Hide resolved
STOP RUN.
END PROGRAM prog.

PROGRAM-ID. prog2 INITIAL.
PROCEDURE DIVISION.
EXIT PROGRAM.
ddeclerck marked this conversation as resolved.
Show resolved Hide resolved
END PROGRAM prog2.
])

AT_CHECK([$COMPILE_MODULE prog.cob], [0], [], [])
AT_CHECK([$COBCRUN prog], [0], [OK
], [])
AT_CLEANUP
Loading