]> granicus.if.org Git - yasm/commitdiff
Add option -Wsize-override to turn on warning on multiple operand size
authorPeter Johnson <peter@tortall.net>
Thu, 1 Mar 2007 07:03:16 +0000 (07:03 -0000)
committerPeter Johnson <peter@tortall.net>
Thu, 1 Mar 2007 07:03:16 +0000 (07:03 -0000)
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

frontends/yasm/yasm.c
libyasm/arch.h
libyasm/errwarn.h
modules/parsers/nasm/nasm-parse.c

index 02c33bb9f3dc97232ac4930ade98452f6b800b61..d49fce04214e62bf02d038222599925b0df6ac9c 100644 (file)
@@ -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;
 
index 7646dc715b6537b62f50121f0e1117c49bf36881..4a12884d78902458ffe0da2e2101980605962b11 100644 (file)
@@ -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.
index d609b9ce2e32ba4f060749f31ebb436cd323cc5d..64b73b59930a57a596b3f8ab32ca2f23da14b479 100644 (file)
@@ -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. */
index 0f6fba44c0ba1601e64a2fac56d02cabf120311b..c2687e910b5ae04659eb4112c05421c5913d7ed8 100644 (file)
@@ -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: