From 46a8c5e43a99c16f06f637228019788d0fe1e7ca Mon Sep 17 00:00:00 2001 From: Kris Katterjohn Date: Thu, 3 Feb 2022 19:31:14 -0500 Subject: [PATCH] Fix undefined behavior when translating define_variable forms When translating a define_variable form using translate (but not using, e.g., translate_file or compfile), a DECLARE expression was being evaluated. In CL it is undefined what happens when evaluating such an expression, and this would cause a lisp error under some lisp implementations. Now we use DECLAIM instead, since this is not emitted in the special places where DECLARE expressions are allowed. No problems with the test suite or share test suite. A new test has been added to rtest_translator. --- src/trmode.lisp | 2 +- tests/rtest_translator.mac | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/trmode.lisp b/src/trmode.lisp index 481544cbd..db35a84af 100644 --- a/src/trmode.lisp +++ b/src/trmode.lisp @@ -43,7 +43,7 @@ (translate mode-form) (push-pre-transl-form ;; POSSIBLE OVERKILL HERE - `(declare (special ,var))) + `(declaim (special ,var))) (push var defined_variables) ;; Get rid of previous definitions put on by ;; the translator. diff --git a/tests/rtest_translator.mac b/tests/rtest_translator.mac index e26b88c2b..27f7b787c 100644 --- a/tests/rtest_translator.mac +++ b/tests/rtest_translator.mac @@ -1980,6 +1980,22 @@ block ([translate : false, l1, l2], [l2, is (l1 = l2)]); [[3, 13], true]; +/* Translating a define_variable form with translate (but not + * translate_file or compfile) used to invoke undefined behavior. + * This would cause a lisp error during translation under some + * (but not all) lisp implementations. + */ + +block ([translate : false], + local (foo), + foo () := (define_variable (x, 1, fixnum), x), + translate_or_lose (foo), + foo ()); +1; + +(kill (foo, x), 0); +0; + -- 2.11.4.GIT