%+ tokens can end up next to each other, or at the beginning or the
end of an expansion if we try to paste the output of empty
macros. This is perhaps particularly likely to happen in %[]
expressions.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
1. Error messages would issue with the line number of %endrep.
2. Debug line information would ignore both macros and reps.
This is doubly wrong; macros are semantically equivalent to
inline functions, and it is expected that debuggers trace
into these functions.
These changes finishes the last parts of moving all responsibility for
the listing enable/disable into the preprocessor, so remove the
way over-complicated macro inhibit facility from the listing module
entirely.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
In preproc-only mode, we only ever execute a single pass, so we need
to still issue error messages created during that pass, otherwise we
don't even generate %warning or %error messages...
Reported-by: Jason Hood <jadoxa@yahoo.com.au>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The autoconf process automatically generates macros for function
attributes, including empty placeholders. Said empty placeholders also
propagate automatically into config/unconfig.h for the compilers which
don't support autoconf.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Fix the handling of %{:} macro operands. Use the same code for
expanding the subarguments as for normal arguments.
This (hopefully) resolves the following bug reports:
BR 3392611, BR 3392686, BR 3392688
Reported-by: <coconutfaistoslimeregistry@gmail.com>
Reported-by: Jasper Lievisse Adriaanse <r+nasm@jasper.la>
Reported-by: Jason Hood <jadoxa@yahoo.com.au>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
clang, unlike gcc, will warn on inline functions which are
unused. This can happen if a function is either intended to be used in
the future, or it is only used under certain config options. Mark
those functions with the "unused" attribute; not only does it quiet
the warning, but it also documents it for the user.
Shuffle around the warning options in configure and add a few more
that are specific to clang.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The name UNUSED is too generic and may conflict with future
macro definitions. This is machine-generated code anyway, so
rename UNUSED to UNUSED_HASH_ENTRY.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
<res ...> can get rather annoying when mixed in with data, as can
happen with the MASM-like db syntax. List shorter blocks (8 bytes or
less) as ?? instead; 8 bytes avoids line breaks for a single
statement.
This is probably more readable anyway...
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
When a warning documentation message contains more than one paragraph,
we have to indent the subsequent paragraphs using \> unless they are a
code paragraph (\c).
Improve a few warnings doc messages.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The a64 instruction patterns would incorrectly force REX to zero at a
point where REX prefixes have already been assigned. This is not only
incorrect in case of instructions which can use high registers, but it
causes an assertion failure. It happened to work for J*CXZ and LOOP*.
Reported-by: Philip Lantz <philip.lantz@intel.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Haiku apparently wants to include <float.h> rather than
"float.h". Rename float.[ch] to floats.[ch] to avoid unnecessary
namespace confusion.
Reported-by: <alaviss0+nasm@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Filenames with double spaces need to be quoted; the preprocessor will
otherwise collapse spaces into one.
When comparing for control characters and spaces, use an unsigned
compare.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
%line directives really need to be preprocessed early, before normal
directive processing. In particular, they are *not* affected by such
thing as smacro expansion, or deferred into an mmacro expansion.
The %line directive is special because it is explicitly indented to be
inserted by an external preprocessor, which can happen at any point.
For mmacro and rep expansions, store the current file and line for
each expansion line. Similarly, let each istk entry contain such
information.
Don't emit empty lines in preprocessing-only mode when we are
already required to issue a %line directive anyway. This cuts down on
clutter a fair bit.
Quote filenames in %line directives (and accept quoted filenames in
%line directives) if and only if it is necessary for
disambiguation. This is required if:
1. The filename contains control characters;
2. The filename begins or ends with whitespace or a quotation mark;
3. The filename is empty.
Otherwise issue the filename as-is, for backwards compatibility.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
tok_set_text() and tok_set_text_free() take a length argument, which
could at least theoretically mean that we don't have a null-terminated
string. Directly enforce a null-terminated string in all cases.
In the future this means that it is legal to intentionally use these
functions to tokenize a substring.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
In tok_set_text() and tok_set_text_free(), don't trust that
the caller has given us a zero-terminated string.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Legacy multi-line macro argument expansion really is very
complicated. With these changes, all legacy tests seem to pass, and
the only differences with NASM 2.14.xx are that some macros which
should have been expanded and were not now are.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The handling of empty arguments in NASM 2.14 and below was at best
"interesting"; a single whitespace token expansion, which can happen
during macro expansion, would sometimes be counted as an argument and
sometimes not.
One really weird effect of this was that %0 doesn't always match the
permitted range in the macro specification!
Add some backwards compatibility code to make x264/ffmpeg compile.
Add override via:
%pragma preproc sane_empty_expansion true
Add support for %clear to clear specific subsets of the macro
definitions. In particular:
%clear defalias
... can be used to wipe the __FOO__ backwards macro compatibility
aliases which may interfere with the C namespace.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
mstk.mstk reflects %rep conditions as well as actual expanded
macros. However, in_progress is undefined for %rep loops; we instead
want to look at the underlying mmacro, if there is one.
Discovered trying to compile x264.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
%ifdef should accept any argument count. However, requiring
a macro structure return means we have to use the wildcard
argument number (-1), not 0 meaning exactly 0 arguments.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Legacy NASM behavior is (quite frankly the sane one) that a comma
inside a set of parentheses do not split smacro arguments, unless
explicitly using braces to enforce this behavior. Revert to legacy
behavior, which again, is arguably the more correct.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
A trailing comma at the end of an mmacro call is an empty
argument, and so we can't terminate the argument-processing loop. The
only case where skip_white() returning NULL where we are allowed to
terminate the loop is in the case of nparams == 0, i.e. the macro call
has no arguments at all.
Reported-by: gabriele balducci <balducci@units.it>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Properly format the error messages when we print them (oops!)
The errhold_stack should be empty after each pass. It may even be
worthwhile to make sure it is empty after each *line*, but do this
for now.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
We must not call nasm_error_hold_push() twice... the obvious
leak of the error stack caused all kinds of errors to be suppressed.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Don't issue smacro expansion warnings until we are sure we are
actually *done* with the smacro expansion. The last pass of
expand_smacro_noreset() gets to commit warnings.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
warning_alias[0] is "all". It is represented in the loop by
value == NULL; WARN_IDX_ALL does not have an entry in warning_state[]
and so trying to poke it is an error.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Set an expression descent limit to 8192, which is more reasonable to
expect to work on most platforms. Furthermore, if getrlimit() exists,
then try to use it to see if we need to further limit the size.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
If an include file exists, but cannot be opened, that is still a
critical error.
However, downgrade this from a fatal to a nonfatal error. There really
isn't any reason to stop cold here.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
If the rest of the line is consumed, we may never see tafter, so we
have to test for end of line at line 5412. We already do at 5397, so
it clearly should have been there all along.
Reported-by: <puppet@zju.edu.cn>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Don't set "defining" until the macro definition is successfully parsed
and we know for sure that we are going to define the macro.
Together with:
a762cd4e54 BR 3392668: preproc: test for macro in TOK_LOCAL_SYMBOL
... this addresses BR 3392668.
Reported-by: <puppet@zju.edu.cn>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
TOK_LOCAL_SYMBOL is only applicable inside a macro; otherwise error
out just like we do for TOK_MMACRO_PARAM.
This *partially* addresses BR 3392668.
Reported-by: <puppet@zju.edu.cn>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Determining whether we should warn on defining a single-line macro, with a
name and a certain number of parameters, call a helper function,
smacro_defined(). It does not always return the address of the definition
structure.
Fix the code to be cautiously accessing the definition structure.
Fixes: e91f5cc132 ("preproc: fix %undef of macro aliases, and add
%ifdefalias")
Reported-by: Dale Curtis <dalecurtis@chromium.org>
Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392659
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Mistreating the macro-parameter, just equivalent to the given
argument number, leads to casting an unnecessary error. Fix to
assemble the conditional code correctly.
Fixes: de7acc3a46 ("preproc: defer %00, %? and %??
expansion for nested macros, cleanups")
Reported-by: C. Masloch <pushbx@ulukai.org>
Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392660
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
The code looked to be unintentionally always nullifying the
token pointer at first place in handling those macro-parameters.
Remove it to avoid segfault.
Fixes: de7acc3a46 ("preproc: defer %00, %? and %??
expansion for nested macros, cleanups")
Reported-by: C. Masloch <pushbx@ulukai.org>
Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392640
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
The code used to stuck in going through whitespace tokens.
Fix to increment towards on the next in the loop.
Reported-by: C. Masloch <pushbx@ulukai.org>
Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392630
Suggested-by: C. Masloch <pushbx@ulukai.org>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
The code has been fixed to print the corresponding line
numbers of %rep blocks correctly, but only for the first
iteration. For the subsequent iterations, the current line
number on the expansion needs to be explicitly reset again.
Fixes: ab6f831955 ("listing: when listing lines in macros
and rep blocks, show the actual line")
Reported-by: C. Masloch <pushbx@ulukai.org>
Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392626
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Macro aliases can legitimately point to nonexistent
macros. Furthermore, %undef should remove the pointed-at macro, not
the alias. This led to an infinite loop in the existing code; fix
that.
Add an %ifdefalias directive to test for the existence of an alias.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Add the -Lw option to flush the list file after every line
output. This is handy for debugging if nasm hangs.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
1. %xdefine was broken because the code used i as a loop, which is
a standard use for the name i. To avoid that confusion in the
future, use "op" rather than "i" to hold the directive constant.
2. Once (1) was fixed, the smacro expansion code would fail because of
parameter token numbers being indistinguishable between the ongoing
expansion and the %xdefine parameters. In a first pass, mark the
parameters with a new TOK_XDEF_PARAM token number, and change them
to proper parameter token numbers in a second pass, which is now
moved into define_smacro() which is where it arguably belongs.
3. Add a few tests for token pasting and xdefine with and without
parameters.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Technically, this is not necessary, because make_tok_qstr_len()
doesn't rely on NUL termination, and in fact it *can't*, since the
string might contain embedded NULs, but tacking on a NUL is good for
debugging if nothing else. That means reserving space for it!
Reported-by: C. Masloch <pushbx@ulukai.org>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Fix incorrectly running off the end of the intended string for %strcat
and %substr.
This is a modified version of a patch contributed by C. Masloch.
Reported-by: C. Masloch <pushbx@ulukai.org>
Originally-by: C. Masloch <pushbx@ulukai.org>
Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392599#c11
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The only way in which
%xdefine(xxx) yyyy zzzz
differs from
%define(xxx) yyyy %[zzzz]
is that in the former case macro arguments get preserved, even if
they are macros defined elsewhere. Revert to that behavior.
Reported-by: C. Masloch <pushbx@ulukai.org>
Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392623
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Add support for complex data (Dx) statement expressions involving both
initialized and uninitialized data. In addition, we have support for
overriding the size of each element on an individual item and/or list
basis.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
%exitrep should should stop emitting code immediately, not just
terminate the loop when we hit %endrep. There is a bunch of hacky code
that special-cases that using istk->in_progress == 0.
The handling of the tail of %exitrep, %include and non-emitting
conditionals using entirely different mechanisms is just dumb. They
need to be unified.
Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392612
Reported-by: Jason Hood <jadoxa@yahoo.com.au>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
We need to create a separate paragraph if the help text had used \c
anyway. Putting the enabled/disabled separately for all entries makes
it read a lot cleaner anyway.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
rdsrc.pl requires blank lines around \c paragraph, but warnings.pl
would strip them. Create a *!- prefix to force a blank line.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>