Emit an error when seeing an invalid condition code in a macro (nasm mode) (#316)
Some checks failed
Build / Build - Ubuntu (push) Failing after 4s
Build / Build - MSVC (push) Has been cancelled
Build / Build - macOS (push) Has been cancelled

make-check: check .errwarn file first if yasm failed
This commit is contained in:
Anonymous Maarten 2026-07-29 02:44:34 +02:00 committed by GitHub
parent 3ec3aa8c33
commit 8c717107dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 51 additions and 14 deletions

View file

@ -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:

View file

@ -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

View file

@ -0,0 +1,9 @@
%macro ret_if_cc 1-*
j%+2 %%skip
ret
j%-2 %%skip
ret
%%skip:
%endmacro
ret_if_cc ne

View file

@ -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

View file

@ -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!'"