From 8c717107dd1235fcf74e279b915837905b6918a5 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Wed, 29 Jul 2026 02:44:34 +0200 Subject: [PATCH] Emit an error when seeing an invalid condition code in a macro (nasm mode) (#316) make-check: check .errwarn file first if yasm failed --- modules/preprocs/nasm/nasm-pp.c | 46 +++++++++++++------ modules/preprocs/nasm/tests/Makefile.inc | 2 + .../preprocs/nasm/tests/nasmpp-invalidcc.asm | 9 ++++ .../nasm/tests/nasmpp-invalidcc.errwarn | 4 ++ out_test.sh | 4 +- 5 files changed, 51 insertions(+), 14 deletions(-) create mode 100644 modules/preprocs/nasm/tests/nasmpp-invalidcc.asm create mode 100644 modules/preprocs/nasm/tests/nasmpp-invalidcc.errwarn diff --git a/modules/preprocs/nasm/nasm-pp.c b/modules/preprocs/nasm/nasm-pp.c index 512f02c3..8b7ab572 100644 --- a/modules/preprocs/nasm/nasm-pp.c +++ b/modules/preprocs/nasm/nasm-pp.c @@ -3950,8 +3950,7 @@ expand_mmac_params(Token * tline) n = (n + mac->rotate) % mac->nparam; tt = mac->params[n]; } - cc = find_cc(tt); - if (cc == -1) + if (!tt) { error(ERR_NONFATAL, "macro parameter %d is not a condition code", @@ -3960,18 +3959,29 @@ expand_mmac_params(Token * tline) } else { - type = TOK_ID; - if (inverse_ccs[cc] == -1) + cc = find_cc(tt); + if (cc == -1) { error(ERR_NONFATAL, - "condition code `%s' is not invertible", - conditions[cc]); + "macro parameter %d is not a condition code", + n + 1); text = NULL; } else - text = - nasm_strdup(conditions[inverse_ccs - [cc]]); + { + type = TOK_ID; + if (inverse_ccs[cc] == -1) + { + error(ERR_NONFATAL, + "condition code `%s' is not invertible", + conditions[cc]); + text = NULL; + } + else + text = + nasm_strdup(conditions[inverse_ccs + [cc]]); + } } break; case '+': @@ -3984,8 +3994,7 @@ expand_mmac_params(Token * tline) n = (n + mac->rotate) % mac->nparam; tt = mac->params[n]; } - cc = find_cc(tt); - if (cc == -1) + if (!tt) { error(ERR_NONFATAL, "macro parameter %d is not a condition code", @@ -3994,8 +4003,19 @@ expand_mmac_params(Token * tline) } else { - type = TOK_ID; - text = nasm_strdup(conditions[cc]); + cc = find_cc(tt); + if (cc == -1) + { + error(ERR_NONFATAL, + "macro parameter %d is not a condition code", + n + 1); + text = NULL; + } + else + { + type = TOK_ID; + text = nasm_strdup(conditions[cc]); + } } break; default: diff --git a/modules/preprocs/nasm/tests/Makefile.inc b/modules/preprocs/nasm/tests/Makefile.inc index 2d624eb5..3a6a8b60 100644 --- a/modules/preprocs/nasm/tests/Makefile.inc +++ b/modules/preprocs/nasm/tests/Makefile.inc @@ -15,6 +15,8 @@ EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp-bigint.asm EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp-bigint.hex EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp-decimal.asm EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp-decimal.hex +EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp-invalidcc.asm +EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp-invalidcc.errwarn EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp-nested.asm EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp-nested.errwarn EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp-nested.hex diff --git a/modules/preprocs/nasm/tests/nasmpp-invalidcc.asm b/modules/preprocs/nasm/tests/nasmpp-invalidcc.asm new file mode 100644 index 00000000..989fc3c8 --- /dev/null +++ b/modules/preprocs/nasm/tests/nasmpp-invalidcc.asm @@ -0,0 +1,9 @@ +%macro ret_if_cc 1-* + j%+2 %%skip + ret + j%-2 %%skip + ret + %%skip: +%endmacro + +ret_if_cc ne diff --git a/modules/preprocs/nasm/tests/nasmpp-invalidcc.errwarn b/modules/preprocs/nasm/tests/nasmpp-invalidcc.errwarn new file mode 100644 index 00000000..37670af2 --- /dev/null +++ b/modules/preprocs/nasm/tests/nasmpp-invalidcc.errwarn @@ -0,0 +1,4 @@ +-:9: error: (ret_if_cc:1) macro parameter 2 is not a condition code +-:9: error: instruction expected after label +-:9: error: (ret_if_cc:3) macro parameter 2 is not a condition code +-:9: error: instruction expected after label diff --git a/out_test.sh b/out_test.sh index b9698e50..c5f6efc2 100755 --- a/out_test.sh +++ b/out_test.sh @@ -28,8 +28,10 @@ do og=`echo ${asm} | sed 's,.asm$,.hex,'` e=${a}.ew eg=`echo ${asm} | sed 's,.asm$,.errwarn,'` + egp=1 if test \! -f ${eg}; then eg=/dev/null + egp=0 fi # Run within a subshell to prevent signal messages from displaying. @@ -42,7 +44,7 @@ do failedct=`expr $failedct + 1` elif test $status -gt 0; then echo ${asm} | grep err >/dev/null - if test $? -gt 0; then + if test \( $? -gt 0 \) -a \( \! $egp \); then # YASM detected errors but shouldn't have! echo $ECHO_N "E$ECHO_C" eval "failed$failedct='E: ${a} returned an error code!'"