Page 1 of 1

Trap on [code] procedure call

Posted: Mon Oct 05, 2020 7:57 pm
by SovietPony

Code: Select all

MODULE Test;

	IMPORT SYSTEM;

	TYPE
		T = RECORD END;

	VAR
		r: T;

	PROCEDURE [code] Fail (r: T);

BEGIN
	Fail(r)
END Test.

Re: Trap on [code] procedure call

Posted: Tue Oct 06, 2020 12:14 am
by cfbsoftware
For anybody who is interesting in investigating this further, the key points I have found that contribute to the failure are:

1. It is a code procedure
2. The parameter is a record
3. The parameter r is a value, not a VAR parameter

e.g. If the parameter is an INTEGER, or a record passed as a VAR then the compiler does not Trap 0.

The other curious aspects of the example supplied e.g. it is an empty record, there are no code values etc. do not appear to be relevant to the failing condition.

Re: Trap on [code] procedure call

Posted: Wed Oct 07, 2020 2:22 pm
by luowy
the first parameter of code procedure is special, reject non varpar comp type in frontend is a choice solution for this issue.

Re: Trap on [code] procedure call

Posted: Fri Oct 09, 2020 11:41 am
by Josef Templ
the first parameter is passed as register eax but in case of a RECORD value parameter this is not possible.
So it should be rejected.
I would suggest to reject it in the backend, though, because code procedures are highly platform specific.
see DevCPC.Call:
Result(x.obj.link, tag) (* use result load for first parameter *)

Re: Trap on [code] procedure call

Posted: Fri Oct 09, 2020 11:59 am
by cfbsoftware
Josef Templ wrote:the first parameter is passed as register eax but in case of a RECORD value parameter this is not possible.
Additionally, it is not possible in the case of an ARRAY value parameter.

Re: Trap on [code] procedure call

Posted: Sat Oct 10, 2020 4:43 am
by luowy
Josef Templ wrote: I would suggest to reject it in the backend, though, because code procedures are highly platform specific.
see DevCPC.Call:
Result(x.obj.link, tag) (* use result load for first parameter *)
if reject it in the backend, the errpos will be point to the end of the procedure head, instead of the first parameter. that is my concern.

and i also suggest dont use any open array value type parameters in code procedure.

Re: Trap on [code] procedure call

Posted: Mon Oct 12, 2020 9:37 am
by Josef Templ
There would also be the alternative of treating structured value parameters as VAR pars, i.e. to pass the address in eax.