Skip to content

Commit

Permalink
Specifically if we encounter the PTR keyword
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
H. Peter Anvin committed May 9, 2016
1 parent 934f047 commit 69550ea
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion nasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions nasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 2 additions & 1 deletion nasmlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion stdscan.c
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions test/ptr.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
;; This should warn but still assemble, as the code is correct

mov eax,dword ptr
ptr:
5 changes: 4 additions & 1 deletion tokens.dat
Original file line number Diff line number Diff line change
@@ -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.
##
Expand Down Expand Up @@ -76,6 +76,9 @@ word
yword
zword

% TOKEN_ID, 0, TFLAG_WARN, 0
ptr

% TOKEN_FLOAT, 0, 0, 0
__infinity__
__nan__
Expand Down

0 comments on commit 69550ea

Please sign in to comment.