Skip to content

Commit f684913

Browse files
committed
fix profiling bug
1 parent 48fdda3 commit f684913

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

cobc/ChangeLog

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11

2-
2022-12-08 Simon Sobisch <[email protected]>
2+
2025-01-03 Fabrice Le Fessant <[email protected]>
3+
4+
* typeck.c (build_evaluate, cb_check_needs_break): fix a bug where
5+
EVALUATE fails in profiling mode. The reason was that a check for
6+
a last GOTO statement is not correctly written, because it was
7+
actually checking either a GOTO or not a statement, which was
8+
evaluates to true for instructions added by profiling. Fixed by
9+
checking only that the last statement is a GOTO. Also modify
10+
cb_check_needs_break that uses the same code.
11+
12+
2024-12-08 Simon Sobisch <[email protected]>
313

414
* cobc.c (process_command_line): fix leak for --copy and -include parsing
515

cobc/typeck.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ static cb_tree
797797
cb_check_needs_break (cb_tree stmt)
798798
{
799799
cb_tree l;
800+
int needs_a_break = 1 ;
800801

801802
/* Check if last statement is GO TO */
802803
for (l = stmt; l; l = CB_CHAIN (l)) {
@@ -806,12 +807,15 @@ cb_check_needs_break (cb_tree stmt)
806807
}
807808
if (l && CB_VALUE (l) && CB_STATEMENT_P (CB_VALUE (l))) {
808809
l = CB_STATEMENT(CB_VALUE(l))->body;
809-
if (l && CB_VALUE (l) && !CB_GOTO_P (CB_VALUE(l))) {
810-
/* Append a break */
811-
l = cb_build_direct ("break;", 0);
812-
return cb_list_add (stmt, l);
810+
if (l && CB_VALUE (l) && CB_GOTO_P (CB_VALUE(l))) {
811+
needs_a_break = 0;
813812
}
814813
}
814+
815+
if (needs_a_break){
816+
l = cb_build_direct ("break;", 0);
817+
return cb_list_add (stmt, l);
818+
}
815819
return stmt;
816820
}
817821

@@ -10019,6 +10023,7 @@ build_evaluate (cb_tree subject_list, cb_tree case_list, cb_tree goto_end_label)
1001910023
cb_source_line = old_line;
1002010024

1002110025
} else {
10026+
int need_end_goto = 1 ;
1002210027
c2 = stmt;
1002310028
/* Check if last statement is GO TO */
1002410029
for (c3 = stmt; c3; c3 = CB_CHAIN (c3)) {
@@ -10028,11 +10033,14 @@ build_evaluate (cb_tree subject_list, cb_tree case_list, cb_tree goto_end_label)
1002810033
}
1002910034
if (c3 && CB_VALUE (c3) && CB_STATEMENT_P (CB_VALUE (c3))) {
1003010035
c3 = CB_STATEMENT (CB_VALUE (c3))->body;
10031-
if (c3 && CB_VALUE (c3) && !CB_GOTO_P (CB_VALUE(c3))) {
10032-
/* Append the jump */
10033-
c2 = cb_list_add (stmt, goto_end_label);
10036+
if (c3 && CB_VALUE (c3) && CB_GOTO_P (CB_VALUE(c3))) {
10037+
need_end_goto = 0 ;
1003410038
}
1003510039
}
10040+
if (need_end_goto){
10041+
/* Append the jump */
10042+
c2 = cb_list_add (stmt, goto_end_label);
10043+
}
1003610044
cb_emit (cb_build_if (cb_build_cond (c1), c2, NULL, STMT_WHEN));
1003710045
build_evaluate (subject_list, CB_CHAIN (case_list), goto_end_label);
1003810046
}

0 commit comments

Comments
 (0)