Skip to content

Commit d01ee46

Browse files
Fix the problem involved with compiling multiple files (#271) (#272)
1 parent b36ab07 commit d01ee46

File tree

5 files changed

+66
-2
lines changed

5 files changed

+66
-2
lines changed

cobj/codegen.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5821,6 +5821,12 @@ void codegen(struct cb_program *prog, const int nested, char **program_id_list,
58215821
needs_exit_prog = 0;
58225822
gen_custom = 0;
58235823
call_cache = NULL;
5824+
while (call_parameter_cache) {
5825+
struct call_parameter_list *next = call_parameter_cache->next;
5826+
free(call_parameter_cache);
5827+
call_parameter_cache = next;
5828+
}
5829+
call_parameter_cache = NULL;
58245830
label_cache = NULL;
58255831
local_cache = NULL;
58265832
excp_current_program_id = prog->orig_source_name;

tests/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ misc_DEPENDENCIES = \
188188
misc.src/comp3-compute.at \
189189
misc.src/index-file-status.at \
190190
misc.src/comp-n.at \
191-
misc.src/fd-external.at
191+
misc.src/fd-external.at \
192+
misc.src/compile-multiple-files.at
192193

193194
EXTRA_DIST = $(srcdir)/package.m4 \
194195
$(TESTS) \

tests/Makefile.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,8 @@ misc_DEPENDENCIES = \
729729
misc.src/comp3-compute.at \
730730
misc.src/index-file-status.at \
731731
misc.src/comp-n.at \
732-
misc.src/fd-external.at
732+
misc.src/fd-external.at \
733+
misc.src/compile-multiple-files.at
733734

734735
EXTRA_DIST = $(srcdir)/package.m4 \
735736
$(TESTS) \

tests/misc.at

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ m4_include([comp3-compute.at])
4040
m4_include([index-file-status.at])
4141
m4_include([comp-n.at])
4242
m4_include([fd-external.at])
43+
m4_include([compile-multiple-files.at])
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# With the previous version, compiling the following programs fails because the compiler write
2+
# the declarations of call parameters in multiple times.
3+
# This test checks whether this problem is resolved.
4+
# See Issue #271 (https://github.com/opensourcecobol/opensourcecobol4j/issues/271) for detail.
5+
AT_SETUP([Compile multiple files])
6+
7+
AT_DATA([caller.cbl], [
8+
IDENTIFICATION DIVISION.
9+
PROGRAM-ID. caller.
10+
DATA DIVISION.
11+
WORKING-STORAGE SECTION.
12+
01 W PIC X.
13+
01 X PIC X.
14+
01 Y PIC X.
15+
01 Z PIC X.
16+
PROCEDURE DIVISION.
17+
CALL "callee"
18+
END-CALL.
19+
CALL "callee" USING W
20+
END-CALL.
21+
CALL "callee" USING W X
22+
END-CALL.
23+
CALL "callee" USING W X Y
24+
END-CALL.
25+
CALL "callee" USING W X Y Z
26+
END-CALL.
27+
STOP RUN.
28+
])
29+
30+
AT_DATA([callee.cbl], [
31+
IDENTIFICATION DIVISION.
32+
PROGRAM-ID. callee.
33+
DATA DIVISION.
34+
LINKAGE SECTION.
35+
01 W PIC X.
36+
01 X PIC X.
37+
01 Y PIC X.
38+
01 Z PIC X.
39+
PROCEDURE DIVISION
40+
USING W X Y Z.
41+
DISPLAY NUMBER-OF-CALL-PARAMETERS
42+
END-DISPLAY.
43+
EXIT PROGRAM.
44+
])
45+
46+
AT_CHECK([${COBJ} callee.cbl caller.cbl])
47+
AT_CHECK([java caller], [0],
48+
[+000000000
49+
+000000001
50+
+000000002
51+
+000000003
52+
+000000004
53+
])
54+
55+
AT_CLEANUP

0 commit comments

Comments
 (0)