diff --git a/src/cmp/cmpbackend-cxx/cmppass2-cont.lsp b/src/cmp/cmpbackend-cxx/cmppass2-cont.lsp index cb8567f7b..6defe114a 100644 --- a/src/cmp/cmpbackend-cxx/cmppass2-cont.lsp +++ b/src/cmp/cmpbackend-cxx/cmppass2-cont.lsp @@ -91,15 +91,19 @@ (defun c2tagbody-body (body) ;;; INV: BODY is a list of tags and forms. We have processed the body ;;; so that the last element is always a form producing NIL. - (loop for (this-form next-form . rest) on body do + (loop for (this-form . rest) on body do (cond ((tag-p this-form) (wt-label (tag-jump this-form))) - ((tag-p next-form) - (with-exit-label (*exit* (tag-jump next-form)) - (let ((*destination* 'TRASH)) - (c2expr this-form)))) + ((endp rest) + ;; Last form, it is never a label! + (c2expr this-form)) (t - (c2expr this-form))))) + (let* ((next-form (first rest)) + (maybe-tag (when (tag-p next-form) + (tag-jump next-form)))) + (with-exit-label (*exit* maybe-tag) + (let ((*destination* 'TRASH)) + (c2expr this-form)))))))) (defun c2go (c1form tag nonlocal) (declare (ignore c1form)) diff --git a/src/tests/normal-tests/compiler.lsp b/src/tests/normal-tests/compiler.lsp index 253df5a2a..4f08600c6 100644 --- a/src/tests/normal-tests/compiler.lsp +++ b/src/tests/normal-tests/compiler.lsp @@ -2571,3 +2571,23 @@ (symbol-macrolet ((value -27)) (load-time-value (block b4 (woosh b4 value)))))))))) + +;;; Date 2025-11-16 +;;; URL: https://gitlab.com/embeddable-common-lisp/ecl/-/issues/802 +;;; Regression commit: 521e815158dc92e6b8af18d007808349764b5623 +;;; Reported by: Jan Moringen +;;; Description +;;; +;;; Regression in TAGBODY handling by the C compiler. +;;; +(deftest cmp.0110.tagbody-regression () + (is (eql 42 + (funcall (compile nil + '(lambda (&aux (always-nil nil)) + (block nil + (tagbody + :package + (when always-nil + (go :package)) + :symbol + (return 42)))))))))