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

Fix bug where macro names can be treated as numeric symbols #1653

Merged
merged 1 commit into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/asm/rpn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ void Expression::makeSymbol(std::string const &symName) {
if (Symbol *sym = sym_FindScopedSymbol(symName); sym_IsPC(sym) && !sect_GetSymbolSection()) {
error("PC has no value outside of a section\n");
data = 0;
} else if (sym && !sym->isNumeric() && !sym->isLabel()) {
error("'%s' is not a numeric symbol\n", symName.c_str());
data = 0;
} else if (!sym || !sym->isConstant()) {
isSymbol = true;

Expand Down
11 changes: 11 additions & 0 deletions test/asm/non-numeric-symbol.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
MACRO mac
ENDM

DEF n EQU mac
DEF v = 2 + mac
DEF k RB mac * 2

SECTION "test", ROM0
db mac
dw 2 + mac
dl mac * 2
13 changes: 13 additions & 0 deletions test/asm/non-numeric-symbol.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error: non-numeric-symbol.asm(4):
'mac' is not a numeric symbol
error: non-numeric-symbol.asm(5):
'mac' is not a numeric symbol
error: non-numeric-symbol.asm(6):
'mac' is not a numeric symbol
error: non-numeric-symbol.asm(9):
'mac' is not a numeric symbol
error: non-numeric-symbol.asm(10):
'mac' is not a numeric symbol
error: non-numeric-symbol.asm(11):
'mac' is not a numeric symbol
error: Assembly aborted (6 errors)!
Loading