[nasm:nasm-2.15.xx] BR 3392715: fix %ifid with $ and $$

nasm-bot for H. Peter Anvin (Intel) hpa at zytor.com
Thu Aug 27 11:45:10 PDT 2020


Commit-ID:  2b4886afdd60106bac617408201e3d5160181dc6
Gitweb:     http://repo.or.cz/w/nasm.git?a=commitdiff;h=2b4886afdd60106bac617408201e3d5160181dc6
Author:     H. Peter Anvin (Intel) <hpa at zytor.com>
AuthorDate: Thu, 27 Aug 2020 11:43:08 -0700
Committer:  H. Peter Anvin (Intel) <hpa at zytor.com>
CommitDate: Thu, 27 Aug 2020 11:43:08 -0700

BR 3392715: fix %ifid with $ and $$

%ifid $ and %ifid $$ has traditionally been false, revert to that
behavior.

Reported-by: Mike Hommey <mh+anfz at glandium.org>
Signed-off-by: H. Peter Anvin (Intel) <hpa at zytor.com>


---
 asm/preproc.c          |  6 ++----
 doc/changes.src        |  5 +++++
 travis/test/ifid.asm   | 19 +++++++++++++++++++
 travis/test/ifid.bin.t |  3 +++
 travis/test/ifid.json  | 11 +++++++++++
 5 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/asm/preproc.c b/asm/preproc.c
index 3fa4e281..a03e6aba 100644
--- a/asm/preproc.c
+++ b/asm/preproc.c
@@ -1600,8 +1600,7 @@ static Token *tokenize(const char *line)
                 /* type = -1; */
             }
         } else if (p[0] == '$' && p[1] == '$') {
-            /* TOKEN_BASE - treat as TOK_ID for pasting purposes */
-            type = TOK_ID;
+            type = TOK_OTHER;   /* TOKEN_BASE */
             p += 2;
         } else if (nasm_isnumstart(*p)) {
             bool is_hex = false;
@@ -1667,8 +1666,7 @@ static Token *tokenize(const char *line)
             p--;        /* Point to first character beyond number */
 
             if (p == line+1 && *line == '$') {
-                /* TOKEN_HERE - treat as TOK_ID for pasting purposes */
-                type = TOK_ID;
+                type = TOK_OTHER; /* TOKEN_HERE */
             } else {
                 if (has_e && !is_hex) {
                     /* 1e13 is floating-point, but 1e13h is not */
diff --git a/doc/changes.src b/doc/changes.src
index f6642168..9b0e02d0 100644
--- a/doc/changes.src
+++ b/doc/changes.src
@@ -7,6 +7,11 @@
 The NASM 2 series supports x86-64, and is the production version of NASM
 since 2007.
 
+\S{cl-2.15.05} Version 2.15.05
+
+\b Correct \c{%ifid $} and \c{%ifid $$} being treated as true. See
+\k{iftyp}.
+
 \S{cl-2.15.04} Version 2.15.04
 
 \b More sensible handling of the case where one single-line macro
diff --git a/travis/test/ifid.asm b/travis/test/ifid.asm
new file mode 100644
index 00000000..ffe03d27
--- /dev/null
+++ b/travis/test/ifid.asm
@@ -0,0 +1,19 @@
+; BR 3392715: Test proper operation of %ifid with $ and $$
+; This produces a human-readable file when compiled with -f bin
+
+%define LF 10
+
+%macro ifid 2
+  %ifid %1
+    %define %%is 'true'
+  %else
+    %define %%is 'false'
+  %endif
+  %defstr %%what   %1
+  %defstr %%should %2
+	db '%ifid ', %%what, ' = ', %%is, ' (expect ', %%should, ')', LF
+%endmacro
+
+	ifid hello, true
+	ifid $, false
+	ifid $$, false
diff --git a/travis/test/ifid.bin.t b/travis/test/ifid.bin.t
new file mode 100644
index 00000000..ca86592d
--- /dev/null
+++ b/travis/test/ifid.bin.t
@@ -0,0 +1,3 @@
+%ifid hello = true (expect true)
+%ifid $ = false (expect false)
+%ifid $$ = false (expect false)
diff --git a/travis/test/ifid.json b/travis/test/ifid.json
new file mode 100644
index 00000000..cf1a3854
--- /dev/null
+++ b/travis/test/ifid.json
@@ -0,0 +1,11 @@
+[
+	{
+		"description": "BR 3392715: Test proper operation of %ifid with $ and $$",
+		"id": "ifid",
+		"format": "bin",
+		"source": "ifid.asm",
+		"target": [
+			{ "output": "ifid.bin" }
+		]
+	}
+]


More information about the Nasm-commits mailing list