From 177a3abfac11017cd65729fa4dd870ee2b366def Mon Sep 17 00:00:00 2001 From: Rangi <35663410+Rangi42@users.noreply.github.com> Date: Sat, 8 Feb 2025 23:03:21 +0100 Subject: [PATCH] Fix bug where macro names can be treated as numeric symbols (#1653) --- src/asm/rpn.cpp | 3 +++ test/asm/non-numeric-symbol.asm | 11 +++++++++++ test/asm/non-numeric-symbol.err | 13 +++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 test/asm/non-numeric-symbol.asm create mode 100644 test/asm/non-numeric-symbol.err diff --git a/src/asm/rpn.cpp b/src/asm/rpn.cpp index 9a7cb906..cb56765d 100644 --- a/src/asm/rpn.cpp +++ b/src/asm/rpn.cpp @@ -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; diff --git a/test/asm/non-numeric-symbol.asm b/test/asm/non-numeric-symbol.asm new file mode 100644 index 00000000..d2096459 --- /dev/null +++ b/test/asm/non-numeric-symbol.asm @@ -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 diff --git a/test/asm/non-numeric-symbol.err b/test/asm/non-numeric-symbol.err new file mode 100644 index 00000000..17a31e79 --- /dev/null +++ b/test/asm/non-numeric-symbol.err @@ -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)!