Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macroexpand-all and tagbody (and a miscompilation bug as well) #683

Open
Gleefre opened this issue Nov 1, 2024 · 0 comments
Open

macroexpand-all and tagbody (and a miscompilation bug as well) #683

Gleefre opened this issue Nov 1, 2024 · 0 comments

Comments

@Gleefre
Copy link

Gleefre commented Nov 1, 2024

ext:macroexpand-all doesn't "protect" macroexpansion of the macros in tagbody that are integers and thus can become a tag.

(defmacro not-tag () 1514)
(ext:macroexpand-all '(tagbody (not-tag)))
; => (TAGBODY 1514)

CLHS says (https://www.lispworks.com/documentation/HyperSpec/Body/s_tagbod.htm):

If a statement is a macro form and its macro expansion is an atom, that atom is treated as a statement, not a tag.

This means that the expansion of (not-tag) should be "protected" so that it doesn't become a tag, for example with a progn, as ABCL does with symbols:

(defmacro not-tag-good () 'tag)
(ext:macroexpand-all '(tagbody (not-tag-good)))
; => (TAGBODY (PROGN TAG))

This also leads to problems in compiled code:

(defmacro not-tag () 1514)

(defun foo ()
  (block nil
    (tagbody
       (ignore-errors (go 1514))
       (return 'good)
       (not-tag)
       (return 'bad))))

(foo)  ; => BAD

Tested on ABCL 1.9.2

(lisp-implementation-version)
; => "1.9.2"
;    "OpenJDK_64-Bit_Server_VM-Private_Build-21.0.1+12-Ubuntu-223.04"
;    "amd64-Linux-6.2.0-39-generic"

This affects quite a few other implementations, see this table (two last columns): https://plaster.tymoon.eu/view/4637.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant