code: plan9front

Download patch

ref: 40cb72e7f8cda9d21e1b7f738f6281e181c0de9e
parent: 865a0f43f10f9df4e61bf235f95de6fd864d8c93
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Fri May 31 17:04:41 EDT 2024

2c: fix indirect calls

The peeophole optimizer was removing MOVL R0, A0
instructions before BSR (A0) because copyu()
decided all registers are being written (because
function calls clobber the registers).

For indirect calls, the register operand must
be correctly reported as being used (and then
clobbered).

--- a/sys/src/cmd/2c/peep.c
+++ b/sys/src/cmd/2c/peep.c
@@ -147,7 +147,6 @@
 void
 excise(Reg *r)
 {
-
 	p = r->prog;
 	p->as = ANOP;
 	p->from = zprog.from;
@@ -930,6 +929,8 @@
 		return 3;
 
 	case ABSR:	/* funny */
+		if(copyau(&p->to, v))
+			return 4;
 		t = v->type;
 		if(t >= D_R0 && t < D_R0+NREG)
 		if(t-D_R0 > exregoffset)