Compiling some of our software with gpc 20010924 I get the following error message:
label `10' used before containing binding contour
Can anyone explain to me what it means, please? The code is too complicated to reproduce and any simple examples don't have the problem. The code is used on other pascal compilers that do not support Exit so we have a label as the last line in the procedure and use Goto where the Exit would be. The code compiles on Borland pascal and the other compilers that we use.
Theo Carr-Brion
On 15 Oct 2001, at 10:42, Theo Carr-Brion wrote:
Compiling some of our software with gpc 20010924 I get the following error message:
label `10' used before containing binding contour
Can anyone explain to me what it means, please?
I have made a brief examination of the compiler source (the error occurs in gcc/stmt.c), so I will offer an explanation, but note that I haven't investigated thoroughly, so I may be completely wrong! Fair warning given....
A "binding contour" appears to be synonymous with a variable's "scope," or a variable's lifetime within what the Pascal standard calls an "activation." Examples would be the program block and procedure and function blocks (where the variables defined therein are created, exist for the duration of the block, and are destroyed upon block exit). Some languages, e.g., C and Ada, also allow arbitrary blocks to define new variable scopes, although Pascal (at least ISO Pascal and ISO Extended Pascal do not).
GPC also appears to create binding contours for temporary variables created during statement execution that require a run-time stack allocation.
The compiler code in "stmt.c" checks to ensure that a "goto" statement outside of a binding contour does not target a label within that binding contour. The error message means that the label is "used," i.e., in a "goto" statement, from outside of the binding contour that contains the label. In effect, you're trying to jump into the middle of a variable's activation, bypassing the code that allocates the variable but eventually executing the code that deallocates the variable.
As "stmt.c" deals with the internal translation of the parsed syntax tree into the intermediate code that will be used for final code generation, I would suspect that the error arises from an incorrect internal association of the statement label with the intermediate code, i.e., the label is associated with code in the middle of a contour, or with code that is ultimately moved into the middle of a contour, instead of with the end of a contour.
From your description, you're "exiting" a procedure in a manner similar to
this:
procedure x;
label 10;
begin [...] goto 10; [...] 10: end;
If so, then I have a couple of questions:
* Are you using any optimization switches, e.g., -O2 (optimization might rearrange code sequences, potentially moving the label)? If so, does it help if you compile without optimization?
* Are you using the "--stack-checking" switch (which will add extra code)? If so, does it help if you omit that switch?
* Does it help if you change the source to put an explicit null statement at the label, i.e., "10: ;"?
* Does it help if you change the source to put a dummy assignment at the label, i.e., "10: dummy := 0"?
If none of these help, please list the compiler command line you are using.
(Note that I am out at the end of a very long limb with most of my comments! I've spent some time looking at the compiler source, but nowhere near enough to understand fully what is being done. Corrections to my analysis...well, "guesses" really...are welcomed!)
-- Dave