Skip to content

Commit 7e82d9d

Browse files
author
H. Peter Anvin (Intel)
committed
Add a default-error warning for impossible o64, a64, or a16 prefixes
The o64, a64 and a16 prefixes are only possible in specific modes. It is a lot easier to debug with a more sensible error message. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
1 parent a16571a commit 7e82d9d

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

asm/assemble.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,25 @@ static int64_t calcsize(insn *ins, const struct itemplate * const temp)
14031403
/* Default operand size */
14041404
ins->op_size = bits != 16 ? 32 : 16;
14051405

1406+
if (bits == 64) {
1407+
if (ins->prefixes[PPS_ASIZE] == P_A16) {
1408+
nasm_warn(WARN_PREFIX_BADMODE_A16,
1409+
"a64 prefix invalid in 64-bit mode");
1410+
ins->prefixes[PPS_ASIZE] = 0;
1411+
}
1412+
} else {
1413+
if (ins->prefixes[PPS_OSIZE] == P_O64) {
1414+
nasm_warn(WARN_PREFIX_BADMODE_O64,
1415+
"o64 prefix invalid in %d-bit mode", bits);
1416+
ins->prefixes[PPS_OSIZE] = P_none;
1417+
}
1418+
if (ins->prefixes[PPS_ASIZE] == P_A64) {
1419+
nasm_warn(WARN_PREFIX_BADMODE_A64,
1420+
"a64 prefix invalid in %d-bit mode", bits);
1421+
ins->prefixes[PPS_ASIZE] = P_none;
1422+
}
1423+
}
1424+
14061425
nasm_zero(need_pfx);
14071426

14081427
while (*codes) {

asm/warnings.dat

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,21 @@ pragma-unknown [off] unknown \c{%pragma} facility or directive
254254
Warns about an unknown \c{%pragma} directive.
255255
This is not yet implemented for most cases.
256256

257+
prefix-badmode-a64 [err] a64 prefix invalid in 16/32-bit mode
258+
Warns that an \c{a64} prefix was specified in 16- or 32-bit
259+
mode. If the error is demoted to a warning or suppressed, the
260+
prefix is ignored by the assembler.
261+
262+
prefix-badmode-o64 [err] o64 prefix invalid in 16/32-bit mode
263+
Warns that an \c{a64} prefix was specified in 16- or 32-bit
264+
mode. If the error is demoted to a warning or suppressed, the
265+
prefix is ignored by the assembler.
266+
267+
prefix-badmode-a16 [err] a16 prefix invalid in 64-bit mode
268+
Warns that an \c{a16} prefix was specified in 64-bit mode.
269+
If the error is demoted to a warning or suppressed, the
270+
prefix is ignored by the assembler.
271+
257272
prefix-bnd [on] invalid \c{BND} prefix
258273
=bnd
259274
Warns about ineffective use of the \c{BND} prefix when the

doc/changes.src

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ It is the production version of NASM since 2025.
5353

5454
\b Hopefully fix building with OpenWatcom.
5555

56+
\b Generate a warning, promoted to error by default, on the use of
57+
\c{a64} or \c{o64} prefixes in 16- or 32-bit mode or \c{a16}
58+
prefixes in 64-bit mode. Those prefixes are not encodable; if
59+
demoted to a warning or suppressed the prefix is ignored, but
60+
likely will generate additional, harder to debug, error messages.
61+
5662

5763
\S{cl-3.00} Version 3.00
5864

0 commit comments

Comments
 (0)