From 69550eac55056ab1fac7bdc1b01da0e68418cd6f Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 9 May 2016 12:05:56 -0700 Subject: [PATCH] Specifically if we encounter the PTR keyword Issue a specific suppressible warning if we encounter the PTR keyword. This usually indicates someone mistakenly using MASM syntax in NASM. This introduces a generic infrastructure for issuing warnings for such keywords. Signed-off-by: H. Peter Anvin --- nasm.c | 2 +- nasm.h | 1 + nasmlib.h | 3 ++- stdscan.c | 7 ++++++- test/ptr.asm | 4 ++++ tokens.dat | 5 ++++- 6 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 test/ptr.asm diff --git a/nasm.c b/nasm.c index bb9e2068..2c7b22ad 100644 --- a/nasm.c +++ b/nasm.c @@ -171,6 +171,7 @@ static const struct warning { {"hle", "invalid hle prefixes", true}, {"bnd", "invalid bnd prefixes", true}, {"zext-reloc", "relocation zero-extended to match output format", true}, + {"ptr", "non-NASM keyword used in other assemblers", true}, }; static bool want_usage; @@ -1958,7 +1959,6 @@ static bool skip_this_pass(int severity) if ((severity & ERR_MASK) > ERR_WARNING) return false; - /* * passn is 1 on the very first pass only. * pass0 is 2 on the code-generation (final) pass only. diff --git a/nasm.h b/nasm.h index 9393e511..aa2409bf 100644 --- a/nasm.h +++ b/nasm.h @@ -421,6 +421,7 @@ enum ccode { /* condition code names */ #define TFLAG_BRC_OPT (1 << 1) /* may or may not have braces. opmasks {k1} */ #define TFLAG_BRC_ANY (TFLAG_BRC | TFLAG_BRC_OPT) #define TFLAG_BRDCAST (1 << 2) /* broadcasting decorator */ +#define TFLAG_WARN (1 << 3) /* warning only, treat as ID */ static inline uint8_t get_cond_opcode(enum ccode c) { diff --git a/nasmlib.h b/nasmlib.h index 96c488a4..d307f777 100644 --- a/nasmlib.h +++ b/nasmlib.h @@ -135,7 +135,8 @@ static inline vefunc nasm_set_verror(vefunc ve) #define ERR_WARN_HLE WARN(13) /* bad HLE prefixes */ #define ERR_WARN_BND WARN(14) /* bad BND prefixes */ #define ERR_WARN_ZEXTRELOC WARN(15) /* relocation zero-extended */ -#define ERR_WARN_MAX 15 /* the highest numbered one */ +#define ERR_WARN_PTR WARN(16) /* not a NASM keyword */ +#define ERR_WARN_MAX 16 /* the highest numbered one */ /* * Wrappers around malloc, realloc and free. nasm_malloc will diff --git a/stdscan.c b/stdscan.c index ea7537dd..d6cf5d5d 100644 --- a/stdscan.c +++ b/stdscan.c @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2009 The NASM Authors - All Rights Reserved + * Copyright 1996-2016 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -167,6 +167,11 @@ int stdscan(void *private_data, struct tokenval *tv) * is it actually a register or instruction name, or what? */ token_type = nasm_token_hash(ourcopy, tv); + if (unlikely(tv->t_flag & TFLAG_WARN)) { + nasm_error(ERR_WARNING|ERR_PASS1|ERR_WARN_PTR, + "%s is not a NASM keyword", tv->t_charptr); + } + if (likely(!(tv->t_flag & TFLAG_BRC))) { /* most of the tokens fall into this case */ return token_type; diff --git a/test/ptr.asm b/test/ptr.asm new file mode 100644 index 00000000..bad32952 --- /dev/null +++ b/test/ptr.asm @@ -0,0 +1,4 @@ + ;; This should warn but still assemble, as the code is correct + + mov eax,dword ptr +ptr: diff --git a/tokens.dat b/tokens.dat index 36b17e28..528f2431 100644 --- a/tokens.dat +++ b/tokens.dat @@ -1,6 +1,6 @@ ## -------------------------------------------------------------------------- ## -## Copyright 1996-2013 The NASM Authors - All Rights Reserved +## Copyright 1996-2016 The NASM Authors - All Rights Reserved ## See the file AUTHORS included with the NASM distribution for ## the specific copyright holders. ## @@ -76,6 +76,9 @@ word yword zword +% TOKEN_ID, 0, TFLAG_WARN, 0 +ptr + % TOKEN_FLOAT, 0, 0, 0 __infinity__ __nan__ -- 2.11.4.GIT