Skip to content

Commit 82b76e4

Browse files
Update tests and function name
1 parent f20c582 commit 82b76e4

File tree

4 files changed

+23
-29
lines changed

4 files changed

+23
-29
lines changed

cobc/tree.h

Lines changed: 1 addition & 0 deletions
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

Lines changed: 10 additions & 5 deletions
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>
@@ -13743,8 +13744,10 @@ cb_check_set_to (cb_tree vars, cb_tree x, const int emit_error)
1374313744
}
1374413745

1374513746
void
13746-
cb_emit_check_index (cb_tree vars, int hasval, int setval)
13747+
cb_check_valid_set_index (cb_tree vars, int hasval, int setval)
1374713748
{
13749+
const int emit_exception = cb_flag_check_subscript_set
13750+
&& CB_EXCEPTION_ENABLE(COB_EC_BOUND_SUBSCRIPT);
1374813751
cb_tree l, v;
1374913752
struct cb_field *f, *p;
1375013753
for (l = vars; l; l = CB_CHAIN (l)) {
@@ -13761,8 +13764,10 @@ cb_emit_check_index (cb_tree vars, int hasval, int setval)
1376113764
cb_warning_x (COBC_WARN_FILLER, l,
1376213765
_("SET %s TO %d is out of bounds"),
1376313766
f->name, setval);
13764-
cb_emit (CB_BUILD_FUNCALL_1 ("cob_set_exception",
13765-
cb_int (COB_EC_RANGE_INDEX)));
13767+
if (emit_exception) {
13768+
cb_emit (CB_BUILD_FUNCALL_1 ("cob_set_exception",
13769+
cb_int (COB_EC_RANGE_INDEX)));
13770+
}
1376613771
}
1376713772
if (setval >= p->occurs_min) continue;
1376813773
}
@@ -13813,7 +13818,7 @@ cb_emit_set_to (cb_tree vars, cb_tree src)
1381313818
}
1381413819
if (cb_flag_check_subscript_set
1381513820
&& CB_EXCEPTION_ENABLE (COB_EC_BOUND_SUBSCRIPT)) {
13816-
cb_emit_check_index (vars, hasval, setval);
13821+
cb_check_valid_set_index (vars, hasval, setval);
1381713822
}
1381813823
}
1381913824

@@ -13970,7 +13975,7 @@ cb_emit_set_up_down (cb_tree l, cb_tree flag, cb_tree x)
1397013975
}
1397113976
}
1397213977
if (CB_EXCEPTION_ENABLE (COB_EC_RANGE_INDEX)) {
13973-
cb_emit_check_index (vars, 0, 0);
13978+
cb_check_valid_set_index (vars, 0, 0);
1397413979
}
1397513980
}
1397613981

tests/testsuite.src/run_subscripts.at

Lines changed: 2 additions & 5 deletions
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

Lines changed: 10 additions & 19 deletions
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)