1 /* ----------------------------------------------------------------------- *
3 * Copyright 1996-2018 The NASM Authors - All Rights Reserved
4 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * ----------------------------------------------------------------------- */
35 * error.c - error message handling routines for the assembler
46 * Description of the suppressible warnings for the command line and
47 * the [warning] directive.
49 const struct warning warnings
[ERR_WARN_ALL
+1] = {
50 { "other", "any warning not specifially mentioned below", true },
51 { "macro-params", "macro calls with wrong parameter count", true },
52 { "macro-selfref", "cyclic macro references", false },
53 { "macro-defaults", "macros with more default than optional parameters", true },
54 { "orphan-labels", "labels alone on lines without trailing `:'", true },
55 { "number-overflow", "numeric constant does not fit", true },
56 { "gnu-elf-extensions", "using 8- or 16-bit relocation in ELF32, a GNU extension", false },
57 { "float-overflow", "floating point overflow", true },
58 { "float-denorm", "floating point denormal", false },
59 { "float-underflow", "floating point underflow", false },
60 { "float-toolong", "too many digits in floating-point number", true },
61 { "user", "%warning directives", true },
62 { "lock", "lock prefix on unlockable instructions", true },
63 { "hle", "invalid hle prefixes", true },
64 { "bnd", "invalid bnd prefixes", true },
65 { "zext-reloc", "relocation zero-extended to match output format", true },
66 { "ptr", "non-NASM keyword used in other assemblers", true },
67 { "bad-pragma", "empty or malformed %pragma", false },
68 { "unknown-pragma", "unknown %pragma facility or directive", false },
69 { "not-my-pragma", "%pragma not applicable to this compilation", false },
70 { "unknown-warning", "unknown warning in -W/-w or warning directive", false },
71 { "negative-rep", "regative %rep count", true },
72 { "phase", "phase error during stabilization", false },
74 /* THIS ENTRY MUST COME LAST */
75 { "all", "all possible warnings", false }
78 /* Current state and command-line state, for reset */
79 uint8_t warning_state
[ERR_WARN_ALL
];
80 uint8_t warning_state_init
[ERR_WARN_ALL
];
82 /* Global error handling function */
85 void nasm_error(int severity
, const char *fmt
, ...)
90 nasm_verror(severity
, fmt
, ap
);
94 #define nasm_error_generatorf(__sev, __flags, __fmt) \
96 va_start(__ap, __fmt); \
97 nasm_verror(__sev | __flags, __fmt, __ap)
99 #define nasm_error_generator(__sev, __fmt) \
100 nasm_error_generatorf(__sev, 0, __fmt)
102 void nasm_debug(const char *fmt
, ...)
104 nasm_error_generator(ERR_DEBUG
, fmt
);
107 void nasm_debugf(int flags
, const char *fmt
, ...)
109 nasm_error_generatorf(ERR_DEBUG
, flags
, fmt
);
112 void nasm_warn(const char *fmt
, ...)
114 nasm_error_generator(ERR_WARNING
, fmt
);
117 void nasm_warnf(int flags
, const char *fmt
, ...)
119 nasm_error_generatorf(ERR_WARNING
, flags
, fmt
);
122 void nasm_nonfatal(const char *fmt
, ...)
124 nasm_error_generator(ERR_NONFATAL
, fmt
);
127 void nasm_nonfatalf(int flags
, const char *fmt
, ...)
129 nasm_error_generatorf(ERR_NONFATAL
, flags
, fmt
);
132 fatal_func
nasm_fatal(const char *fmt
, ...)
134 nasm_error_generator(ERR_FATAL
, fmt
);
138 fatal_func
nasm_fatalf(int flags
, const char *fmt
, ...)
140 nasm_error_generatorf(ERR_FATAL
, flags
, fmt
);
144 fatal_func
nasm_panic(const char *fmt
, ...)
146 nasm_error_generator(ERR_PANIC
, fmt
);
150 fatal_func
nasm_panicf(int flags
, const char *fmt
, ...)
152 nasm_error_generatorf(ERR_PANIC
, flags
, fmt
);
156 fatal_func
nasm_panic_from_macro(const char *file
, int line
)
158 nasm_panic("internal error at %s:%d\n", file
, line
);
161 fatal_func
nasm_assert_failed(const char *file
, int line
, const char *msg
)
163 nasm_panic("assertion %s failed at %s:%d", msg
, file
, line
);
166 #undef nasm_error_generator
167 #undef nasm_error_generatorf
170 * This is called when processing a -w or -W option, or a warning directive.
171 * Returns true if if the action was successful.
173 bool set_warning_status(const char *value
)
175 enum warn_action
{ WID_OFF
, WID_ON
, WID_RESET
};
176 enum warn_action action
;
181 value
= nasm_skip_spaces(value
);
197 if (!nasm_strnicmp(value
, "no-", 3)) {
201 } else if (!nasm_stricmp(value
, "none")) {
206 /* else fall through */
212 mask
= WARN_ST_ENABLED
;
214 if (value
&& !nasm_strnicmp(value
, "error", 5)) {
217 mask
= WARN_ST_ERROR
;
221 mask
= WARN_ST_ERROR
;
225 /* Just an accidental prefix? */
230 if (value
&& !nasm_stricmp(value
, "all"))
233 /* This is inefficient, but it shouldn't matter... */
234 for (i
= 0; i
< ERR_WARN_ALL
; i
++) {
235 if (!value
|| !nasm_stricmp(value
, warnings
[i
].name
)) {
236 ok
= true; /* At least one action taken */
239 warning_state
[i
] &= ~mask
;
242 warning_state
[i
] |= mask
;
245 warning_state
[i
] &= ~mask
;
246 warning_state
[i
] |= warning_state_init
[i
] & mask
;