]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix integer arithmetic miss-compilation (bug#53451)
authorAndrea Corallo <akrl@sdf.org>
Wed, 9 Feb 2022 16:38:10 +0000 (17:38 +0100)
committerAndrea Corallo <akrl@sdf.org>
Wed, 9 Feb 2022 16:58:57 +0000 (17:58 +0100)
* lisp/emacs-lisp/comp-cstr.el (comp-cstr-set-range-for-arithm):
When one of the two sources is negated revert to set dst as
number.
* test/src/comp-tests.el (comp-tests-type-spec-tests): Add test to
verify this is effective.

lisp/emacs-lisp/comp-cstr.el
test/src/comp-tests.el

index 97f8f4d5c407fda95f0e2526d0a4d65c7f4f34f0..65710b58c10dbd9d507cea108fd98583f94b9b43 100644 (file)
@@ -449,18 +449,20 @@ Return them as multiple value."
   (declare (debug (range-body))
            (indent defun))
   `(with-comp-cstr-accessors
-     (when-let ((r1 (range ,src1))
-                (r2 (range ,src2)))
-       (let* ((l1 (comp-cstr-smallest-in-range r1))
-              (l2 (comp-cstr-smallest-in-range r2))
-              (h1 (comp-cstr-greatest-in-range r1))
-              (h2 (comp-cstr-greatest-in-range r2)))
-         (setf (typeset ,dst) (when (cl-some (lambda (x)
-                                               (comp-subtype-p 'float x))
-                                             (append (typeset src1)
-                                                     (typeset src2)))
-                                '(float))
-               (range ,dst) ,@range-body)))))
+     (if (or (neg src1) (neg src2))
+         (setf (typeset ,dst) '(number))
+       (when-let ((r1 (range ,src1))
+                  (r2 (range ,src2)))
+         (let* ((l1 (comp-cstr-smallest-in-range r1))
+                (l2 (comp-cstr-smallest-in-range r2))
+                (h1 (comp-cstr-greatest-in-range r1))
+                (h2 (comp-cstr-greatest-in-range r2)))
+           (setf (typeset ,dst) (when (cl-some (lambda (x)
+                                                 (comp-subtype-p 'float x))
+                                               (append (typeset src1)
+                                                       (typeset src2)))
+                                  '(float))
+                 (range ,dst) ,@range-body))))))
 
 (defun comp-cstr-add-2 (dst src1 src2)
   "Sum SRC1 and SRC2 into DST."
index eb84262dc8e6a04ee6029cf9960106f56cee42c3..96f2b42c0d713273b97f810dd26290c2c1b8053c 100644 (file)
@@ -1353,7 +1353,14 @@ Return a list of results."
          (when (eql x 1.0)
           (error ""))
          x)
-       t)))
+       t)
+
+      ;; 74
+      ((defun comp-tests-ret-type-spec-f (x)
+         (if (eq x 0)
+            (error "")
+          (1+ x)))
+       number)))
 
   (defun comp-tests-define-type-spec-test (number x)
     `(comp-deftest ,(intern (format "ret-type-spec-%d" number)) ()