fbc currently allows forward references to be used for Byref parameters in procedure declarations.
This is a problem, because the parser doesn't (and can't with its current design) verify the argument while the parameter type is incomplete. Thus it allows passing incompatible things which results in bad code being generated.
type UDT as UDT_
declare sub f(byref x as UDT)
f(1) '' This should be disallowed
f(1.0) '' This should be disallowed
type UDT_
as double a, b
end type
dim x as UDT = (123, 456)
f(x)
sub f(byref x as UDT)
print x.a, x.b
end sub
mov byte ptr [ebp-20], 1 # integer 1, but byte ptr!?
lea eax, [ebp-20]
push eax
call F
mov byte ptr [ebp-36], 4607182418800017408 # double 1.0, but byte ptr!?
lea eax, [ebp-36]
push eax
call F
The procedure expects an argument of type UDT, not integer/double, but fbc does
not diagnose the problem. It looks like -gen gas falls back to byte ptr in case of FB_DATATYPE_FWDREF.
Similar problems with -gen gcc (bad C code generated, does not compile).
Diff: