Skip to content

Commit f44e6a6

Browse files
Update tests and function name
1 parent e7c9540 commit f44e6a6

File tree

4 files changed

+23
-29
lines changed

4 files changed

+23
-29
lines changed

cobc/tree.h

+1
Original file line numberDiff line numberDiff line change
@@ -2373,6 +2373,7 @@ extern struct cb_program *cb_build_program (struct cb_program *,
23732373

23742374
extern cb_tree cb_check_numeric_value (cb_tree);
23752375
extern size_t cb_check_index_or_handle_p (cb_tree x);
2376+
extern void cb_check_valid_set_index (cb_tree, int, int);
23762377
extern void cb_set_dmax (int scale);
23772378

23782379
extern void cb_set_intr_when_compiled (void);

cobc/typeck.c

+10-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222

2323
#include "config.h"
24+
#include "libcob/common.h"
2425

2526
#include <stdio.h>
2627
#include <stdlib.h>
@@ -13738,8 +13739,10 @@ cb_check_set_to (cb_tree vars, cb_tree x, const int emit_error)
1373813739
}
1373913740

1374013741
void
13741-
cb_emit_check_index (cb_tree vars, int hasval, int setval)
13742+
cb_check_valid_set_index (cb_tree vars, int hasval, int setval)
1374213743
{
13744+
const int emit_exception = cb_flag_check_subscript_set
13745+
&& CB_EXCEPTION_ENABLE(COB_EC_BOUND_SUBSCRIPT);
1374313746
cb_tree l, v;
1374413747
struct cb_field *f, *p;
1374513748
for (l = vars; l; l = CB_CHAIN (l)) {
@@ -13756,8 +13759,10 @@ cb_emit_check_index (cb_tree vars, int hasval, int setval)
1375613759
cb_warning_x (COBC_WARN_FILLER, l,
1375713760
_("SET %s TO %d is out of bounds"),
1375813761
f->name, setval);
13759-
cb_emit (CB_BUILD_FUNCALL_1 ("cob_set_exception",
13760-
cb_int (COB_EC_RANGE_INDEX)));
13762+
if (emit_exception) {
13763+
cb_emit (CB_BUILD_FUNCALL_1 ("cob_set_exception",
13764+
cb_int (COB_EC_RANGE_INDEX)));
13765+
}
1376113766
}
1376213767
if (setval >= p->occurs_min) continue;
1376313768
}
@@ -13808,7 +13813,7 @@ cb_emit_set_to (cb_tree vars, cb_tree src)
1380813813
}
1380913814
if (cb_flag_check_subscript_set
1381013815
&& CB_EXCEPTION_ENABLE (COB_EC_BOUND_SUBSCRIPT)) {
13811-
cb_emit_check_index (vars, hasval, setval);
13816+
cb_check_valid_set_index (vars, hasval, setval);
1381213817
}
1381313818
}
1381413819

@@ -13965,7 +13970,7 @@ cb_emit_set_up_down (cb_tree l, cb_tree flag, cb_tree x)
1396513970
}
1396613971
}
1396713972
if (CB_EXCEPTION_ENABLE (COB_EC_RANGE_INDEX)) {
13968-
cb_emit_check_index (vars, 0, 0);
13973+
cb_check_valid_set_index (vars, 0, 0);
1396913974
}
1397013975
}
1397113976

tests/testsuite.src/run_subscripts.at

+2-5
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,6 @@ AT_DATA([prog.cob], [
609609
INDEXED BY IB2.
610610
PROCEDURE DIVISION.
611611
MOVE 5 TO MAXIDX
612-
SET NIDX TO IB1.
613-
DISPLAY "Initial value: " NIDX.
614612
SET IB2 TO 10.
615613
MOVE "A:" TO MYMRK (1)
616614
MOVE "B:" TO MYMRK (2)
@@ -683,8 +681,7 @@ AT_DATA([prog.cob], [
683681
])
684682

685683
AT_CHECK([$COMPILE -fopt-check-subscript-set -Wno-unfinished -Wno-others prog.cob], [0], [], [])
686-
AT_CHECK([$COBCRUN_DIRECT ./prog], [1], [Initial value: +01
687-
Number is +0000000042
684+
AT_CHECK([$COBCRUN_DIRECT ./prog], [1], [Number is +0000000042
688685
Number is +0000000002
689686
Number is +0000000001
690687
Number is +0000000003
@@ -694,7 +691,7 @@ Number is +0000000003
694691
+01: A: Freddy .
695692
+02: B: Barney .
696693
+03: C: Wilma .
697-
], [libcob: prog.cob:71: error: subscript of 'MYMRK' out of bounds: 4
694+
], [libcob: prog.cob:69: error: subscript of 'MYMRK' out of bounds: 4
698695
note: current maximum subscript for 'MYMRK': 3
699696
])
700697

tests/testsuite.src/syn_occurs.at

+10-19
Original file line numberDiff line numberDiff line change
@@ -664,29 +664,20 @@ AT_DATA([prog.cob], [
664664
01 MYIDX USAGE IS INDEX.
665665
01 MAXIDX PIC 9999 VALUE 3 COMP-5.
666666
01 TBL.
667-
05 FILLER PIC X(8) VALUE "Fred".
668-
05 FILLER PIC X(8) VALUE "Barney".
669-
05 FILLER PIC X(8) VALUE "Wilma".
670-
05 FILLER PIC X(8) VALUE "Betty".
671-
01 FILLER REDEFINES TBL.
672-
05 MYNAME PIC X(8) OCCURS 4 INDEXED BY IB1.
667+
05 MYNAME PIC X(8) OCCURS 4
668+
INDEXED BY IB1
669+
VALUES ARE "Fred" "Barney" "Wilma" "Betty".
673670
01 TBL2.
674671
05 MYMRK PIC X(3)
675672
OCCURS 2 TO 5 DEPENDING ON MAXIDX
676-
INDEXED BY IB2.
673+
INDEXED BY IB2
674+
VALUES ARE "A:" "B:" "C:" "D:" "E:".
677675
PROCEDURE DIVISION.
678-
MOVE 5 TO MAXIDX
679676
SET NIDX TO IB1.
680677
DISPLAY "Initial value: " NIDX.
681678
SET IB2 TO 0.2.
682679
SET IB2 TO "fred".
683680
SET IB2 TO 10.
684-
MOVE "A:" TO MYMRK (1)
685-
MOVE "B:" TO MYMRK (2)
686-
MOVE "C:" TO MYMRK (3)
687-
MOVE "D:" TO MYMRK (4)
688-
MOVE "E:" TO MYMRK (5)
689-
MOVE 3 TO MAXIDX.
690681
SET IB1 TO 2.
691682
SET MYIDX TO IB1.
692683
SET IB1 TO 1.
@@ -723,11 +714,11 @@ AT_DATA([prog.cob], [
723714
END PROGRAM prog.
724715
])
725716

726-
AT_CHECK([$COMPILE_ONLY -fopt-check-subscript-set prog.cob], [1], [], [prog.cob:25: error: an integer, INDEX, or a POINTER is expected here
727-
prog.cob:26: error: an integer, INDEX, or a POINTER is expected here
728-
prog.cob:27: warning: SET IB2 TO 10 is out of bounds
729-
prog.cob:45: warning: SET IB1 TO -9 is out of bounds
730-
prog.cob:46: warning: SET IB1 TO 300 is out of bounds
717+
AT_CHECK([$COMPILE_ONLY -fopt-check-subscript-set prog.cob], [1], [], [prog.cob:22: error: an integer, INDEX, or a POINTER is expected here
718+
prog.cob:23: error: an integer, INDEX, or a POINTER is expected here
719+
prog.cob:24: warning: SET IB2 TO 10 is out of bounds
720+
prog.cob:36: warning: SET IB1 TO -9 is out of bounds
721+
prog.cob:37: warning: SET IB1 TO 300 is out of bounds
731722
])
732723

733724
AT_CLEANUP

0 commit comments

Comments
 (0)