adding pointer checks on ecas

This commit is contained in:
Jakub Doka 2024-10-25 16:33:56 +02:00
parent d23d010917
commit faa8dd2e6f
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
3 changed files with 27 additions and 14 deletions

View file

@ -2501,8 +2501,10 @@ impl<'a> Codegen<'a> {
let mut inps = Vc::from([NEVER]); let mut inps = Vc::from([NEVER]);
let arg_base = self.tys.tmp.args.len(); let arg_base = self.tys.tmp.args.len();
let mut has_ptr_arg = false;
for arg in args { for arg in args {
let value = self.expr(arg)?; let value = self.expr(arg)?;
has_ptr_arg |= value.ty.has_pointers(&self.tys);
self.tys.tmp.args.push(value.ty); self.tys.tmp.args.push(value.ty);
debug_assert_ne!(self.ci.nodes[value.id].kind, Kind::Stre); debug_assert_ne!(self.ci.nodes[value.id].kind, Kind::Stre);
self.ci.nodes.lock(value.id); self.ci.nodes.lock(value.id);
@ -2515,6 +2517,7 @@ impl<'a> Codegen<'a> {
self.ci.nodes.unlock(n); self.ci.nodes.unlock(n);
} }
if has_ptr_arg {
inps.push(self.ci.scope.store.value()); inps.push(self.ci.scope.store.value());
self.ci.scope.loads.retain(|&load| { self.ci.scope.loads.retain(|&load| {
if inps.contains(&load) { if inps.contains(&load) {
@ -2527,6 +2530,7 @@ impl<'a> Codegen<'a> {
false false
}); });
}
let alt_value = match ty.loc(&self.tys) { let alt_value = match ty.loc(&self.tys) {
Loc::Reg => None, Loc::Reg => None,
@ -2540,7 +2544,9 @@ impl<'a> Codegen<'a> {
inps[0] = self.ci.ctrl; inps[0] = self.ci.ctrl;
self.ci.ctrl = self.ci.nodes.new_node(ty, Kind::Call { func: ty::ECA, args }, inps); self.ci.ctrl = self.ci.nodes.new_node(ty, Kind::Call { func: ty::ECA, args }, inps);
if has_ptr_arg {
self.store_mem(VOID, ty::Id::VOID, VOID); self.store_mem(VOID, ty::Id::VOID, VOID);
}
alt_value.or(Some(Value::new(self.ci.ctrl).ty(ty))) alt_value.or(Some(Value::new(self.ci.ctrl).ty(ty)))
} }

View file

@ -1,12 +1,12 @@
main: main:
ADDI64 r254, r254, -31d ADDI64 r254, r254, -31d
LI64 r6, 6d
LI64 r5, 5d LI64 r5, 5d
LI64 r7, 20d LI64 r7, 20d
LI64 r2, 1d LI64 r2, 1d
LI64 r9, 10d LI64 r4, 10d
LI64 r6, 6d
ADDI64 r8, r254, 15d ADDI64 r8, r254, 15d
ST r9, r254, 15a, 8h ST r4, r254, 15a, 8h
ST r7, r254, 23a, 8h ST r7, r254, 23a, 8h
LD r3, r8, 0a, 16h LD r3, r8, 0a, 16h
ECA ECA

View file

@ -0,0 +1,7 @@
main:
LI32 r1, 1w
ANDI r1, r1, 4294967295d
JALA r0, r31, 0a
code size: 36
ret: 1
status: Ok(())