The following code produces three distinct outputs depending on
1) No flag run in GnuCOBOL,
2) -fperform-osvs flag run in GnuCOBOL
3) IBM zOS run on COBOL 6.4.
With no flag, it appears GnuCOBOL builds a perform stack and only returns if the top of stack matches. With the -fperform-osvs flag, GnuCOBOL appears to still build a stack, and pop down the stack to any matching perform. The actual behavior of zOS COBOL is to have a list of places to return to, and if you return to one by reaching the end of a set of paragraphs with an active perform, it will return to that one but leave any other return locations live. So if in Z you perform A THRU C, and in B perform D THRU F, then in E go to C, at the end of C it will return to Z. But then in Z if you GO TO F, it will return to B (in zOS COBOL).
IDENTIFICATION DIVISION.
PROGRAM-ID. GOTOTST.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 X PIC 99 VALUE 0.
01 Y PIC 99.
01 Z PIC 99.
PROCEDURE DIVISION.
PERFORM A THROUGH A-EXIT.
DISPLAY "Done with A".
GO TO C-EXIT.
STOP RUN.
A.
DISPLAY "In A".
PERFORM B THROUGH B-EXIT.
DISPLAY "Back from B".
IF X IS EQUAL TO 1
GO TO A-EXIT.
DISPLAY "A NOT 1".
A-EXIT.
DISPLAY "A-EXIT".
EXIT.
C.
DISPLAY "In C".
IF X IS EQUAL TO 1
COMPUTE X = X + 1
GO TO A-EXIT
ELSE IF X IS EQUAL TO 2
PERFORM A THRU A-EXIT
DISPLAY "Back from A"
END-IF.
C-EXIT.
EXIT.
B.
DISPLAY "In B".
COMPUTE X = X + 1.
PERFORM C THRU C-EXIT.
DISPLAY "Back from C".
B-EXIT.
EXIT.
LAST-ONE.
DISPLAY "LAST ONE".
STOP RUN.
Output 1 (No flag)
In A
In B
In C
A-EXIT
In C
In A
In B
In C
Back from C
Back from B
A NOT 1
A-EXIT
Back from A
Back from C
Back from B
A NOT 1
A-EXIT
Done with A
In B
In C
Back from C
LAST ONE
Output 2 (-fperform-osvs)
In A
In B
In C
A-EXIT
Done with A
In B
In C
Back from C
LAST ONE
Output 3 (IBM zOS COBOL v6.4)
In A
In B
In C
A-EXIT
Done with A
Back from C
Back from B
A NOT 1
A-EXIT
In C
In A
In B
In C
Back from C
Back from B
A NOT 1
A-EXIT
Back from A
In B
In C
Back from C
LAST ONE
Ticket moved from /p/gnucobol/feature-requests/446/
Rechecked MF docs and behavior; the default one is identical like the GC one "uses a stack-based perform handling system", while
PERFORM-TYPE(OSVS)[undocumented] andPERFORM-TYPE(RM)are identical to the output shown to be the case on IBM compilers.MF docs say:
The current help for cobc's
-fperform-osvssays:Also, depending on
-fperform-osvswe provide a compiler constantPERFORM-TYPE(can be checked with$IF) that is set to eitherMForOSVS.Therefore I think we should definitely:
PERFORM-TYPEcompiler directive, handling "MF", "OSVS" and "RM"Just for reference - current single test (that will work after a fix, too):
patches welcome
Last edit: Simon Sobisch 2023-09-19