From: Peter Johnson Date: Thu, 1 Mar 2007 07:03:16 +0000 (-0000) Subject: Add option -Wsize-override to turn on warning on multiple operand size X-Git-Tag: v0.6.1~15^2~20 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cb4bd8caee1fbda8c1061218c9afc5c06df49c35;p=yasm Add option -Wsize-override to turn on warning on multiple operand size overrides such as: dword dword [5] or dword word [5]. The warnings for these are disabled by default, as these combinations are intentially legal for use with macros. Suggested by: pingved@gmail.com svn path=/trunk/yasm/; revision=1806 --- diff --git a/frontends/yasm/yasm.c b/frontends/yasm/yasm.c index 02c33bb9..d49fce04 100644 --- a/frontends/yasm/yasm.c +++ b/frontends/yasm/yasm.c @@ -1044,6 +1044,8 @@ opt_warning_handler(char *cmd, /*@unused@*/ char *param, int extra) action(YASM_WARN_ORPHAN_LABEL); else if (strcmp(cmd, "uninit-contents") == 0) action(YASM_WARN_UNINIT_CONTENTS); + else if (strcmp(cmd, "size-override") == 0) + action(YASM_WARN_SIZE_OVERRIDE); else return 1; diff --git a/libyasm/arch.h b/libyasm/arch.h index 7646dc71..4a12884d 100644 --- a/libyasm/arch.h +++ b/libyasm/arch.h @@ -264,7 +264,7 @@ struct yasm_insn_operand { uintptr_t targetmod; /**< Arch target modifier, 0 if none. */ - /** Specified size of the operand, in bytes. 0 if not user-specified. */ + /** Specified size of the operand, in bits. 0 if not user-specified. */ unsigned int size:8; /** Nonzero if dereference. Used for "*foo" in GAS. diff --git a/libyasm/errwarn.h b/libyasm/errwarn.h index d609b9ce..64b73b59 100644 --- a/libyasm/errwarn.h +++ b/libyasm/errwarn.h @@ -41,7 +41,8 @@ typedef enum yasm_warn_class { YASM_WARN_UNREC_CHAR, /**< Unrecognized characters (while tokenizing) */ YASM_WARN_PREPROC, /**< Preprocessor warnings */ YASM_WARN_ORPHAN_LABEL, /**< Label alone on a line without a colon */ - YASM_WARN_UNINIT_CONTENTS /**< Uninitialized space in code/data section */ + YASM_WARN_UNINIT_CONTENTS, /**< Uninitialized space in code/data section */ + YASM_WARN_SIZE_OVERRIDE /**< Double size override */ } yasm_warn_class; /** Error classes. Bitmask-based to support limited subclassing. */ diff --git a/modules/parsers/nasm/nasm-parse.c b/modules/parsers/nasm/nasm-parse.c index 0f6fba44..c2687e91 100644 --- a/modules/parsers/nasm/nasm-parse.c +++ b/modules/parsers/nasm/nasm-parse.c @@ -680,8 +680,25 @@ parse_operand(yasm_parser_nasm *parser_nasm) yasm_arch_get_reg_size(parser_nasm->arch, op->data.reg) != size) yasm_error_set(YASM_ERROR_TYPE, N_("cannot override register size")); - else + else { + /* Silently override others unless a warning is turned on. + * This is to allow overrides such as: + * %define arg1 dword [bp+4] + * cmp word arg1, 2 + * Which expands to: + * cmp word dword [bp+4], 2 + */ + if (op->size != 0) { + if (op->size != size) + yasm_warn_set(YASM_WARN_SIZE_OVERRIDE, + N_("overriding operand size from %u-bit to %u-bit"), + op->size, size); + else + yasm_warn_set(YASM_WARN_SIZE_OVERRIDE, + N_("double operand size override")); + } op->size = size; + } return op; } case TARGETMOD: