Skip to content

[Bug]: AND with a constant-folded first operand emits an orphan pop af → stack corruption (v1.18.7, -O1…-O4) #1096

Description

@Menyiques

Contact Details

@Menyiques

Compiler version

v1.18.7

What happened?

Compiling:
Dim a as uByte
Dim s as uByte
a = 1
s = 10
If a and s >= 6 Then s = 2
print s

with zxbc -O 2 bug.bas -o bug.asm -A
(O=1,2,3,4)
generates:

.core.MAIN_PROGRAM:
ld a, 1
ld (_a), a
ld a, 10
ld (_s), a
sub 6
ccf
sbc a, a
ld h, a
pop af ; <<< orphan: no matching "push af" anywhere
or a
jr z, .LABEL.__LABEL2
ld a, h
.LABEL.__LABEL2:
or a
jp z, .LABEL.__LABEL1

Error and Warning messages

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Labels

Type

Fields

No fields configured for Bug.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions