Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizer breaks the code with accessing data via pointer (6510) #881

Open
zzarko opened this issue Feb 23, 2025 · 0 comments
Open

Optimizer breaks the code with accessing data via pointer (6510) #881

zzarko opened this issue Feb 23, 2025 · 0 comments

Comments

@zzarko
Copy link
Collaborator

zzarko commented Feb 23, 2025

I caught a weird bug, but I am unsure which optimizer option triggers it. I have tried to make a more minimal example, but was unsuccessful, so I trimmed down my current code. Most probably not all of it is needed, but I have no idea what exactly triggers the bug.

The error appears in Stars.tru file, starting in line 33:

	// something weird...
	j -= 1;
	// due to wrong optimization, this code does not work without NOP !!!
	//asm("	nop");	// introduced to fool TRSE optimizer, uncomment to get a working code
	if ScreenUtil::ptr[j] = Config::BlankChar then begin
		ScreenUtil::ptr[j] := Config::StarIdx1;
	end;

Without NOP, this is the code that was generated:

; // something weird...
	; Test Inc dec D
	dec Stars_j
	; LineNumber: 37
	; Binary clause Simplified: EQUALS
	; Load pointer array
	tay ; optimized y, look out for bugs L22 ORG 	ldy Stars_j
	lda (ScreenUtil_ptr),y
	; Compare with pure num / var optimization
	cmp #$fe;keep

Instead of loading Y with current value of variable J, some previous content of A is moved to Y and then completely wrong data is accessed. If NOP line is uncommented, correct sequence is generated:

; // something weird...
	; Test Inc dec D
	dec Stars_j
	; LineNumber: 36
	nop
	; LineNumber: 37
	; Binary clause Simplified: EQUALS
	; Load pointer array
	ldy Stars_j
	lda (ScreenUtil_ptr),y
	; Compare with pure num / var optimization
	cmp #$fe;keep

I am unsure, but seems that origin may be the same as for this bug: #880

ErrorOpt.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant