]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix `cond` miscompilation bug
authorMattias Engdegård <mattiase@acm.org>
Thu, 2 Mar 2023 08:56:59 +0000 (09:56 +0100)
committerMattias Engdegård <mattiase@acm.org>
Thu, 2 Mar 2023 14:47:26 +0000 (15:47 +0100)
This fixes a bug that miscompiled

  (cond ... C S1...Sn)

where S1...Sn are switch clauses (that can be compiled into a switch
op) and C a non-switch clause, by tucking on an extra copy of C at the
end.  This was a serious wrong-code bug when the condition of C had
side-effects; otherwise it was only a waste of time and space.

* lisp/emacs-lisp/bytecomp.el (byte-compile-cond): Fix.
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--test-cases):
Add test case.

lisp/emacs-lisp/bytecomp.el
test/lisp/emacs-lisp/bytecomp-tests.el

index 095468ad978f2a04bf1e6f3e9cadc1044d246b37..6f3d7a709037076e21d7a1cffac03a4c04ac17d4 100644 (file)
@@ -4590,6 +4590,7 @@ Return (TAIL VAR TEST CASES), where:
         (if switch-prefix
             (progn
               (byte-compile-cond-jump-table (cdr switch-prefix) donetag)
+              (setq clause nil)
               (setq clauses (car switch-prefix)))
           (setq clause (car clauses))
           (cond ((or (eq (car clause) t)
index b6dcfeedb0c1cf1f76557bb4e5e70d8a514d2899..10b009a261c1e73683b910363bbdea55fe23dd1a 100644 (file)
@@ -757,6 +757,15 @@ inner loops respectively."
         (bytecomp-test-identity 3)
       (error 'bad)
       (:success))                       ; empty handler
+
+    ;; `cond' miscompilation bug
+    (let ((fn (lambda (x)
+                (let ((y nil))
+                  (cond ((progn (setq x (1+ x)) (> x 10)) (setq y 'a))
+                        ((eq x 1) (setq y 'b))
+                        ((eq x 2) (setq y 'c)))
+                  (list x y)))))
+      (mapcar fn (bytecomp-test-identity '(0 1 2 3 10 11))))
     )
   "List of expressions for cross-testing interpreted and compiled code.")