about summary refs log tree commit diff stats
path: root/mu_instructions
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-05-07 21:04:45 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-05-07 21:04:45 -0700
commit888b4cd8eabff44ad10954f26bd4df4497e28617 (patch)
tree6e890232896f4cfdaa51fad4bcd25fd981b0ef2a /mu_instructions
parent61a68452ae84df936e1861e65a331959643ae016 (diff)
downloadmu-888b4cd8eabff44ad10954f26bd4df4497e28617.tar.gz
always check for null in 'index' instructions
Diffstat (limited to 'mu_instructions')
-rw-r--r--mu_instructions12
1 files changed, 9 insertions, 3 deletions
diff --git a/mu_instructions b/mu_instructions
index ea58866e..10d00f10 100644
--- a/mu_instructions
+++ b/mu_instructions
@@ -318,13 +318,17 @@ var/reg: (addr T) <- address var2: T
 
 var/reg: (addr T) <- index arr/rega: (addr array T), idx/regi: int
   | if size-of(T) is 1, 2, 4 or 8
-      => "(__check-mu-array-bounds *" rega " %" regi " " size-of(T) ")"
+      => "81 7/subop/compare %" rega " 0/imm32"
+         "0f 84/jump-if-= __mu-abort-null-index-base-address/disp32"
+         "(__check-mu-array-bounds *" rega " %" regi " " size-of(T) ")"
          "8d/copy-address *(" rega "+" regi "<<" log2(size-of(T)) "+4) " reg "/r32"
 var/reg: (addr T) <- index arr: (array T len), idx/regi: int
   => "(__check-mu-array-bounds *(ebp+" arr.stack-offset ") %" regi " " size-of(T) ")"
      "8d/copy-address *(ebp+" regi "<<" log2(size-of(T)) "+" (arr.stack-offset + 4) ") " reg "/r32"
 var/reg: (addr T) <- index arr/rega: (addr array T), n
-  => "(__check-mu-array-bounds *" rega " " n " " size-of(T) ")"
+  => "81 7/subop/compare %" rega " 0/imm32"
+     "0f 84/jump-if-= __mu-abort-null-index-base-address/disp32"
+     "(__check-mu-array-bounds *" rega " " n " " size-of(T) ")"
      "8d/copy-address *(" rega "+" (n*size-of(T)+4) ") " reg "/r32"
 var/reg: (addr T) <- index arr: (array T len), n
   => "(__check-mu-array-bounds *(ebp+" arr.stack-offset ") " n " " size-of(T) ")"
@@ -335,7 +339,9 @@ var/reg: (offset T) <- compute-offset arr: (addr array T), idx/regi: int  # arr
 var/reg: (offset T) <- compute-offset arr: (addr array T), idx: int       # arr can be in reg or mem
   => "69/multiply *(ebp+" idx.stack-offset ") " size-of(T) "/imm32 " reg "/r32"
 var/reg: (addr T) <- index arr/rega: (addr array T), o/rego: (offset T)
-  => "(__check-mu-array-bounds %" rega " %" rego " 1 \"" function-name "\")"
+  => "81 7/subop/compare %" rega " 0/imm32"
+     "0f 84/jump-if-= __mu-abort-null-index-base-address/disp32"
+     "(__check-mu-array-bounds %" rega " %" rego " 1 \"" function-name "\")"
      "8d/copy-address *(" rega "+" rego "+4) " reg "/r32"
 
 Computing the length of an array is complex.