summary refs log tree commit diff
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin@c9x.me>2023-04-02 19:20:13 +0200
committerQuentin Carbonneaux <quentin@c9x.me>2023-04-02 19:21:16 +0200
commita3dfbb9c0449109e6fb6accbe7ffe0d6f4e48b2f (patch)
treec6310c7b7afd229423e5039e20c2c46f067b5684
parenteda2db573741eef29f4d1f1e759a83e7cd468a94 (diff)
downloadroux-a3dfbb9c0449109e6fb6accbe7ffe0d6f4e48b2f.tar.gz
amd64_apple: one more thread-local symbols fix
We now treat thread-local
symbols in Mems properly.
-rw-r--r--amd64/isel.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/amd64/isel.c b/amd64/isel.c
index 214dbec..3d5d5a9 100644
--- a/amd64/isel.c
+++ b/amd64/isel.c
@@ -58,6 +58,21 @@ rslot(Ref r, Fn *fn)
 	return fn->tmp[r.val].slot;
 }
 
+static int
+hascon(Ref r, Con **pc, Fn *fn)
+{
+	switch (rtype(r)) {
+	case RCon:
+		*pc = &fn->con[r.val];
+		return 1;
+	case RMem:
+		*pc = &fn->mem[r.val].offset;
+		return 1;
+	default:
+		return 0;
+	}
+}
+
 static void
 fixarg(Ref *r, int k, Ins *i, Fn *fn)
 {
@@ -100,9 +115,8 @@ fixarg(Ref *r, int k, Ins *i, Fn *fn)
 		r1 = newtmp("isel", Kl, fn);
 		emit(Oaddr, Kl, r1, SLOT(s), R);
 	}
-	else if (T.apple && rtype(r0) == RCon
-	&& (c = &fn->con[r0.val])->type == CAddr
-	&& c->sym.type == SThr) {
+	else if (T.apple && hascon(r0, &c, fn)
+	&& c->type == CAddr && c->sym.type == SThr) {
 		r1 = newtmp("isel", Kl, fn);
 		if (c->bits.i) {
 			r2 = newtmp("isel", Kl, fn);
@@ -122,6 +136,12 @@ fixarg(Ref *r, int k, Ins *i, Fn *fn)
 		cc.bits.i = 0;
 		r3 = newcon(&cc, fn);
 		emit(Oload, Kl, r2, r3, R);
+		if (rtype(r0) == RMem) {
+			m = &fn->mem[r0.val];
+			m->offset.type = CUndef;
+			m->base = r1;
+			r1 = r0;
+		}
 	}
 	else if (!(isstore(op) && r == &i->arg[1])
 	&& !isload(op) && op != Ocall && rtype(r0) == RCon