Skip to content

[Bug Fix] Fixed getcopy() not transferring TCallNode intrinsiccode and TCallParaNode originalindex fields

Summary

This merge request fixes an oversight from !346 (merged) where the new fields in TCallNode and TCallParaNode did not have their values transferred when the nodes were duplicated with getcopy(). Ultimately this caused inefficiencies when inline functions containing Str calls were expanded, since intrinsiccode became zero and the parameter indices weren't preserved for the new GetParaFromIndex() method.

System

  • Processor architecture: All

What is the current bug behavior?

Not all calls to Str and possible future intrinsics would get optimised.

What is the behavior after applying this patch?

Such missed intrinsic calls are now processed.

Relevant logs and/or screenshots

The improvements appear in the compiler itself when tostr is called with a deterministic actual parameter. For example, in pexports, it gets called with the actual parameter low(index), which translates to -2147483648 on x86_64-win64. After the fix, this gets translated into a direct string quote. Before:

	...
	movq	-1344(%rbp),%r13
	leaq	-1312(%rbp),%r8
	movl	$255,%r9d
	movq	$-1,%rdx
	movq	$-2147483648,%rcx
	call	fpc_shortstr_sint
	leaq	-1312(%rbp),%rdx
	leaq	-1352(%rbp),%rcx
	xorl	%r8d,%r8d
	call	fpc_shortstr_to_ansistr
	...

After:

	...
	movq	-1344(%rbp),%r13
	leaq	_$PEXPORTS$_Ld4(%rip),%r8
	leaq	-1312(%rbp),%rcx
	movl	$255,%edx
	call	fpc_shortstr_to_shortstr
	leaq	-1312(%rbp),%rdx
	leaq	-1352(%rbp),%rcx
	xorl	%r8d,%r8d
	call	fpc_shortstr_to_ansistr
	...

The object _$PEXPORTS$_Ld4 is just that number stored as a string:

.globl	_$PEXPORTS$_Ld4
_$PEXPORTS$_Ld4:
	.ascii	"\013-2147483648\000"

.section .rodata.n__$PEXPORTS$_Ld5,"a"
	.balign 8

As explained in !346 (merged), though code size hasn't significantly reduced and data size increases slightly (the storage of the string literal), fpc_shortstr_to_shortstr is significantly simpler than fpc_shortstr_sint, as the latter has to do intricate conversion and validity checks, while the former is just a simple memory transfer.

Merge request reports