diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-02-05 18:53:20 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-02-06 14:05:37 +0100 |
| commit | 6894b01b22e848b5fdbb2fafae88e9459232ced2 (patch) | |
| tree | 6bb08be6754e4d481489b7cb01d50c6e706d4ba9 | |
| parent | d36e0de313aa65192eba108dd75135991a42685e (diff) | |
| download | tools.nes-6894b01b22e848b5fdbb2fafae88e9459232ced2.tar.gz tools.nes-6894b01b22e848b5fdbb2fafae88e9459232ced2.zip | |
asan: don't complain on arithmetic with addresses
This was already the case for plain addresses, but it was not being
considered in the case of an arithmetic operation.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
| -rw-r--r-- | lib/xixanta/src/assembler.rs | 21 | ||||
| -rw-r--r-- | tests/bare_accesses.s | 3 | ||||
| -rw-r--r-- | tests/expected/bare_accesses.txt | 2 |
3 files changed, 20 insertions, 6 deletions
diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs index 96fdd01..507f5e1 100644 --- a/lib/xixanta/src/assembler.rs +++ b/lib/xixanta/src/assembler.rs @@ -2948,13 +2948,26 @@ impl<'a> Assembler<'a> { } NodeType::Operation(OperationType::Add) | NodeType::Operation(OperationType::Sub) => { // Get the name of the variable involved. - let left_name = &node.left.as_ref().unwrap().value.value; - let right_name = &node.left.as_ref().unwrap().value.value; - let name = if is_asan_friendly_name(left_name) { + let left_name = &node.left.as_ref().unwrap().value; + let right_name = &node.left.as_ref().unwrap().value; + let name = if is_asan_friendly_name(&left_name.value) { node.left.as_ref().unwrap() - } else if is_asan_friendly_name(right_name) { + } else if is_asan_friendly_name(&right_name.value) { node.right.as_ref().unwrap() } else { + // If everything failed but because it was an address + // (e.g. 'lda palettes + 1, x'), then return early. + if let Ok(var) = self.context.get_variable(left_name, &self.mappings) { + if matches!(var.object_type, ObjectType::Address) { + return Ok(()); + } + } + if let Ok(var) = self.context.get_variable(right_name, &self.mappings) { + if matches!(var.object_type, ObjectType::Address) { + return Ok(()); + } + } + self.warnings.push(Error { line: node.value.line, message: "accessing a memory region without a proper name".to_string(), diff --git a/tests/bare_accesses.s b/tests/bare_accesses.s index 61ae7c6..cebdc10 100644 --- a/tests/bare_accesses.s +++ b/tests/bare_accesses.s @@ -32,9 +32,10 @@ lda zp_used - 1 ldx #0 lda palettes, x +lda palettes + 1, x palettes: - .byte $0F + .byte $0F, $FF lda $200 ; asan:ignore lda $200 diff --git a/tests/expected/bare_accesses.txt b/tests/expected/bare_accesses.txt index 0eab60f..676723f 100644 --- a/tests/expected/bare_accesses.txt +++ b/tests/expected/bare_accesses.txt @@ -1,5 +1,5 @@ warning: accessing a memory region without using a variable (bare_accesses.s: line 22) warning: accessing a memory region without a proper name ('whatever') (bare_accesses.s: line 23) -warning: accessing a memory region without using a variable (bare_accesses.s: line 40) +warning: accessing a memory region without using a variable (bare_accesses.s: line 41) error: out of bounds memory access for 'zp_used' ($00-$01) (bare_accesses.s: line 27) error: out of bounds memory access for 'zp_used' ($00-$01) (bare_accesses.s: line 28) |
