https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119883
Bug ID: 119883
Summary: codegen: recursive user-defined functions don't run
recursive
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: cobol
Assignee: unassigned at gcc dot gnu.org
Reporter: simonsobisch at gnu dot org
Target Milestone: ---
Code example:
IDENTIFICATION DIVISION.
FUNCTION-ID. foo.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 ttl PIC 9 VALUE 1.
LOCAL-STORAGE SECTION.
01 num PIC 9.
LINKAGE SECTION.
01 arg PIC 9.
01 ret PIC 9.
PROCEDURE DIVISION USING arg RETURNING ret.
IF arg < 5
ADD 1 TO arg GIVING num END-ADD
MOVE FUNCTION foo (num) TO ret
ELSE
MOVE arg TO ret
END-IF
DISPLAY "Step: " ttl ", Arg: " arg ", Return: " ret
END-DISPLAY
ADD 1 to ttl END-ADD
GOBACK.
END FUNCTION foo.
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
FUNCTION foo.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 num PIC 9 VALUE 1.
PROCEDURE DIVISION.
DISPLAY "Return value '" FUNCTION foo (num) "'"
WITH NO ADVANCING
END-DISPLAY
GOBACK.
END PROGRAM prog.
result (-expected +current head)
-Step: 1, Arg: 5, Return: 5
-Step: 2, Arg: 4, Return: 5
-Step: 3, Arg: 3, Return: 5
-Step: 4, Arg: 2, Return: 5
-Step: 5, Arg: 1, Return: 5
-Return value '5'
+Return value '0'