From 85e1a649439ef4d96cbdeeb91c46a1b49ea22d00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= Date: Tue, 28 Oct 2025 17:01:35 +0100 Subject: [PATCH] Fix numeric comparison bug when optimisation is disabled * lisp/emacs-lisp/bytecomp.el (byte-compile-cmp): Don't assume that N-ary comparisons have been normalised, which is done in the optimiser. Reported by Pip Cet. --- lisp/emacs-lisp/bytecomp.el | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 7c652b0c6fb..b016b04c2d3 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -4069,18 +4069,22 @@ If it is nil, then the handler is \"byte-compile-SYMBOL.\"" (defun byte-compile-cmp (form) "Compile calls to numeric comparisons such as `<', `=' etc." - ;; Lisp-level transforms should already have reduced valid calls to 2 args. - (if (not (= (length form) 3)) - (byte-compile-subr-wrong-args form "1 or more") - (byte-compile-two-args - (if (macroexp-const-p (nth 1 form)) - ;; First argument is constant: flip it so that the constant - ;; is last, which may allow more lapcode optimizations. - (let* ((op (car form)) - (flipped-op (cdr (assq op '((< . >) (<= . >=) - (> . <) (>= . <=) (= . =)))))) - (list flipped-op (nth 2 form) (nth 1 form))) - form)))) + ;; Lisp-level transforms should already have reduced valid calls to 2 args, + ;; but optimisations may have been disabled. + (let ((l (length form))) + (cond + ((= l 3) + (byte-compile-two-args + (if (macroexp-const-p (nth 1 form)) + ;; First argument is constant: flip it so that the constant + ;; is last, which may allow more lapcode optimizations. + (let* ((op (car form)) + (flipped-op (cdr (assq op '((< . >) (<= . >=) + (> . <) (>= . <=) (= . =)))))) + (list flipped-op (nth 2 form) (nth 1 form))) + form))) + ((= l 2) (byte-compile-form `(progn ,(nth 1 form) t))) + (t (byte-compile-normal-call form))))) (defun byte-compile-three-args (form) (if (not (= (length form) 4))