[cc65] Literal cast to pointer generating unnecessary code with [].

From: Brad Smith <rainwarrior1gmail.com>
Date: 2012-10-17 01:53:02
I ran into an interesting case today. This is code produced by the
latest snapshot ( This is with -O, but the same basic
problem appears without it.

; ((unsigned char*)0)[0x1234] = 5;
	jsr     decsp3
	jsr     push0
	lda     #$05
	ldy     #$01
	lda     #$12
	adc     (sp),y
	sta     (sp),y
	ldy     #$34
	jsr     staspidx
; *(unsigned char*)(0 + 0x1234) = 5;
	lda     #$05
	sta     $1234

Specifically, in the former case it ends up doing all the work
necessary to use indirect indexed addressing for the STA, instead of
just using an absolute address. I presume the compiler thinks of
((unsigned char*)0) as a variable pointer, rather than a fixed address
that should be known at compile or link time? Using a global array
seems to generate the compact absolute address STA that is expected.
Similarly I could cast it to a struct * and access that struct's
members and it still generates an absolute address. The problem only
seems to be when I use [] with the cast pointer.

-- Brad Smith
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Wed Oct 17 01:53:19 2012

This archive was generated by hypermail 2.1.8 : 2012-10-17 01:53:23 CEST