From: Waldek Hebisch hebisch@math.uni.wroc.pl Subject: Re: string literal as const var parameter To: "Jay Michael" jmichael_ll@yahoo.com Cc: gpc@gnu.de Date: Monday, July 9, 2012, 8:15 AM Jay Michael wrote:
procedure enabler( const s : string ) ; procedure rejecter( const var s : string ) ;
enabler( 'lit2' ) ; rejecter( 'literal' ) ;
Why did compiling the call to "enabler" first result in the compiler accepting the call to "rejecter"?
Plain bug: compiler got wrong internal bookkeeping and compiling enabler overwrote info about parameter list of rejecter.
Is this bookkeeping error fixed by the patch
you posted? Is there a separate patch you did not post?
The patch should fix both problems. gpc uses code generator from gcc -- the part taken from gcc is usually called backend. To compile Pascal program gpc first builds appropriate data structures describing (in machine-indpendent way) code which should be generated. Layout of such data structures is defined by backend. Also backend provides several functions which create and transform data structures. To save space and usualsy also execution time backend tries to share the same data structures between parts of program. Apparently in case ouf your program backend decided that it can use the same data structure to describe properties of parameters to 'enabler' and 'rejecter'. Previous gpc code called backed function 'build_type_variant' which allows backed to re-use its input argument if there are no change and it seems that backend decided that the change done by gpc is a no-op and reused the data. The patch uses 'build_type_copy' function which disalows sharing in this case. Conseqently, this elliminates sharing of parameter description between 'enabler' and 'rejecter' and prevents overwriting.