From faa8dd2e6fabe2e0e4a375e677171856da491c61 Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Fri, 25 Oct 2024 16:33:56 +0200 Subject: [PATCH] adding pointer checks on ecas --- lang/src/son.rs | 28 +++++++++++-------- lang/tests/son_tests_directives.txt | 6 ++-- .../son_tests_signed_to_unsigned_upcast.txt | 7 +++++ 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/lang/src/son.rs b/lang/src/son.rs index 6ef6a54c..697aae13 100644 --- a/lang/src/son.rs +++ b/lang/src/son.rs @@ -2501,8 +2501,10 @@ impl<'a> Codegen<'a> { let mut inps = Vc::from([NEVER]); let arg_base = self.tys.tmp.args.len(); + let mut has_ptr_arg = false; for arg in args { let value = self.expr(arg)?; + has_ptr_arg |= value.ty.has_pointers(&self.tys); self.tys.tmp.args.push(value.ty); debug_assert_ne!(self.ci.nodes[value.id].kind, Kind::Stre); self.ci.nodes.lock(value.id); @@ -2515,18 +2517,20 @@ impl<'a> Codegen<'a> { self.ci.nodes.unlock(n); } - inps.push(self.ci.scope.store.value()); - self.ci.scope.loads.retain(|&load| { - if inps.contains(&load) { - return true; - } + if has_ptr_arg { + inps.push(self.ci.scope.store.value()); + self.ci.scope.loads.retain(|&load| { + if inps.contains(&load) { + return true; + } - if !self.ci.nodes.unlock_remove(load) { - inps.push(load); - } + if !self.ci.nodes.unlock_remove(load) { + inps.push(load); + } - false - }); + false + }); + } let alt_value = match ty.loc(&self.tys) { Loc::Reg => None, @@ -2540,7 +2544,9 @@ impl<'a> Codegen<'a> { inps[0] = self.ci.ctrl; self.ci.ctrl = self.ci.nodes.new_node(ty, Kind::Call { func: ty::ECA, args }, inps); - self.store_mem(VOID, ty::Id::VOID, VOID); + if has_ptr_arg { + self.store_mem(VOID, ty::Id::VOID, VOID); + } alt_value.or(Some(Value::new(self.ci.ctrl).ty(ty))) } diff --git a/lang/tests/son_tests_directives.txt b/lang/tests/son_tests_directives.txt index 37b133c5..9e047250 100644 --- a/lang/tests/son_tests_directives.txt +++ b/lang/tests/son_tests_directives.txt @@ -1,12 +1,12 @@ main: ADDI64 r254, r254, -31d - LI64 r6, 6d LI64 r5, 5d LI64 r7, 20d LI64 r2, 1d - LI64 r9, 10d + LI64 r4, 10d + LI64 r6, 6d ADDI64 r8, r254, 15d - ST r9, r254, 15a, 8h + ST r4, r254, 15a, 8h ST r7, r254, 23a, 8h LD r3, r8, 0a, 16h ECA diff --git a/lang/tests/son_tests_signed_to_unsigned_upcast.txt b/lang/tests/son_tests_signed_to_unsigned_upcast.txt index e69de29b..75c8045e 100644 --- a/lang/tests/son_tests_signed_to_unsigned_upcast.txt +++ b/lang/tests/son_tests_signed_to_unsigned_upcast.txt @@ -0,0 +1,7 @@ +main: + LI32 r1, 1w + ANDI r1, r1, 4294967295d + JALA r0, r31, 0a +code size: 36 +ret: 1 +status: Ok(())