From unknown Fri Sep 19 14:39:45 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#42360 <42360@debbugs.gnu.org> To: bug#42360 <42360@debbugs.gnu.org> Subject: Status: [feature/native-comp] miscompilation(?) of functions with non local exits Reply-To: bug#42360 <42360@debbugs.gnu.org> Date: Fri, 19 Sep 2025 21:39:45 +0000 retitle 42360 [feature/native-comp] miscompilation(?) of functions with non= local exits reassign 42360 emacs submitter 42360 Andrea Corallo severity 42360 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Wed Jul 15 04:24:10 2020 Received: (at submit) by debbugs.gnu.org; 15 Jul 2020 08:24:10 +0000 Received: from localhost ([127.0.0.1]:52067 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jvci1-0004Qd-LW for submit@debbugs.gnu.org; Wed, 15 Jul 2020 04:24:09 -0400 Received: from lists.gnu.org ([209.51.188.17]:46750) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jvchy-0004QS-WB for submit@debbugs.gnu.org; Wed, 15 Jul 2020 04:24:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jvchy-000364-Pk for bug-gnu-emacs@gnu.org; Wed, 15 Jul 2020 04:24:06 -0400 Received: from mx.sdf.org ([205.166.94.24]:53993) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jvchw-0006Yq-0w; Wed, 15 Jul 2020 04:24:06 -0400 Received: from mab (ma.sdf.org [205.166.94.33]) by mx.sdf.org (8.15.2/8.14.5) with ESMTP id 06F8O013004347; Wed, 15 Jul 2020 08:24:01 GMT From: Andrea Corallo To: bug-gnu-emacs@gnu.org Subject: [feature/native-comp] miscompilation(?) of functions with non local exits Date: Wed, 15 Jul 2020 08:24:00 +0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=205.166.94.24; envelope-from=akrl@sdf.org; helo=mx.sdf.org X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/15 04:24:01 X-ACL-Warn: Detected OS = ??? X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit Cc: Eli Zaretskii , Stefan Monnier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) Due to a recent modification native-comp is (probably?) miscompiling lexical scope functions with non local exits if they involve code with side effect on local variables. Before fixing I prefer to double check the correct behavior we want. Considering the following piece of (lexical scoped) code: === (let (x) (ignore-errors (setq x t) (error "foo")) x) === Three options: 1- Because setq is evaluated the expression should always evaluate to t. 2- Unwinding the original state of the stack is restored, when it was saved 'x' was nil so the expression should evaluate to nil. 3- This is unspecified. The current stock implementaion does always 1 so I'm prone to just go for it but I wanted to double check to be on the safe side. FYI 1 implies C register variables cannot be used to implement Lisp local variable if non local exits are present. Thanks Andrea -- akrl@sdf.org From debbugs-submit-bounces@debbugs.gnu.org Wed Jul 15 10:25:17 2020 Received: (at submit) by debbugs.gnu.org; 15 Jul 2020 14:25:17 +0000 Received: from localhost ([127.0.0.1]:53324 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jviLU-0000go-Pd for submit@debbugs.gnu.org; Wed, 15 Jul 2020 10:25:17 -0400 Received: from lists.gnu.org ([209.51.188.17]:46620) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jviLT-0000gi-1B for submit@debbugs.gnu.org; Wed, 15 Jul 2020 10:25:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jviLS-00061c-Rn for bug-gnu-emacs@gnu.org; Wed, 15 Jul 2020 10:25:14 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:58374) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jviLR-0002n5-8h; Wed, 15 Jul 2020 10:25:13 -0400 Received: from [176.228.60.248] (port=1954 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1jviLP-0005AZ-DT; Wed, 15 Jul 2020 10:25:12 -0400 Date: Wed, 15 Jul 2020 17:25:11 +0300 Message-Id: <83v9iolut4.fsf@gnu.org> From: Eli Zaretskii To: Andrea Corallo In-Reply-To: (message from Andrea Corallo on Wed, 15 Jul 2020 08:24:00 +0000) Subject: Re: [feature/native-comp] miscompilation(?) of functions with non local exits References: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: submit Cc: bug-gnu-emacs@gnu.org, monnier@iro.umontreal.ca X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Andrea Corallo > Cc: Eli Zaretskii , Stefan Monnier > Date: Wed, 15 Jul 2020 08:24:00 +0000 > > === > (let (x) > (ignore-errors > (setq x t) > (error "foo")) > x) > === > > Three options: > > 1- Because setq is evaluated the expression should always evaluate to > t. > > 2- Unwinding the original state of the stack is restored, when it was > saved 'x' was nil so the expression should evaluate to nil. > > 3- This is unspecified. > > The current stock implementaion does always 1 so I'm prone to just go > for it but I wanted to double check to be on the safe side. I tend to alternative 1 as well. From debbugs-submit-bounces@debbugs.gnu.org Wed Jul 15 15:17:36 2020 Received: (at submit) by debbugs.gnu.org; 15 Jul 2020 19:17:36 +0000 Received: from localhost ([127.0.0.1]:53634 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jvmuN-0001W1-P0 for submit@debbugs.gnu.org; Wed, 15 Jul 2020 15:17:35 -0400 Received: from lists.gnu.org ([209.51.188.17]:49068) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jvmuM-0001Vt-NM for submit@debbugs.gnu.org; Wed, 15 Jul 2020 15:17:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53010) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jvmuM-0004yC-IR for bug-gnu-emacs@gnu.org; Wed, 15 Jul 2020 15:17:34 -0400 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:52845) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jvmuK-0000h7-Cf; Wed, 15 Jul 2020 15:17:33 -0400 Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 355A9808BD; Wed, 15 Jul 2020 15:17:30 -0400 (EDT) Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 6484F805A4; Wed, 15 Jul 2020 15:17:28 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1594840648; bh=+je70xS4DUNvW5CQ0s2d7rueCEVZe9iCaPFcEeZocW4=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=GAhUg8qjU3c76eCZY8oa39dNiWmi+33lP+lo71RP1SuhoyWIMt5qSQZ3+0V0B1tQy /b0S77nhcOlqB6ezJTBmhHfhv5+/foDNWiHt1h1oBJ94EC5nlaM/UgAel5BvoMvP9H B6pPq73GrUmCsV7nQDofX8zjcRryyUEDXPYK/w876Sql3SAETK5yWMk4OogFSdcoKv 1R6Wac4QRU18x+mfY97QtzO5JzsuzggvtUaBFNEXTWlkZ1vfXH2eBaHCCy/hQ55weE BPoqpciTLTD3x/hcuJOobAevgeiFjTYxXl4/u70b063LECsktb88+c0vtKHZp2+5d1 3xMKjLtscgoxg== Received: from asado (unknown [45.72.129.42]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 2D831120642; Wed, 15 Jul 2020 15:17:28 -0400 (EDT) From: Stefan Monnier To: Andrea Corallo Subject: Re: [feature/native-comp] miscompilation(?) of functions with non local exits Message-ID: References: Date: Wed, 15 Jul 2020 15:17:27 -0400 In-Reply-To: (Andrea Corallo's message of "Wed, 15 Jul 2020 08:24:00 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.020 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain X-SPAM-LEVEL: Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/15 15:17:30 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit Cc: bug-gnu-emacs@gnu.org, Eli Zaretskii X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) > Three options: > > 1- Because setq is evaluated the expression should always evaluate to > t. > > 2- Unwinding the original state of the stack is restored, when it was > saved 'x' was nil so the expression should evaluate to nil. > > 3- This is unspecified. Very definitely (1)! We don't want to introduce into Elisp the kind of messy semantics you get in C with non-volatile variables and longjmp. > FYI 1 implies C register variables cannot be used to implement Lisp > local variable if non local exits are present. IIUC, the problem only occurs for those vars which have a `condition-case` (or `unwind-protect` or `catch`) in their scope and where the var is modified within that construct and that a non-local exit can jump to the end of that construct after the var was thus modified, and that the var is used after the construct. This should be fairly rare (not sure if those cases can easily be written differently, OTOH). The compiler could replace those vars by boxing them inside a cons-cell (so the register-stored C var is immutable and contains a pointer to a cons cell which holds the real value in the `car`), just like we do with mutated Elisp vars captured by closures. Stefan From debbugs-submit-bounces@debbugs.gnu.org Wed Jul 15 17:19:45 2020 Received: (at submit) by debbugs.gnu.org; 15 Jul 2020 21:19:45 +0000 Received: from localhost ([127.0.0.1]:53782 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jvooa-0004Re-VS for submit@debbugs.gnu.org; Wed, 15 Jul 2020 17:19:45 -0400 Received: from lists.gnu.org ([209.51.188.17]:37360) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jvooZ-0004RX-Je for submit@debbugs.gnu.org; Wed, 15 Jul 2020 17:19:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57262) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jvooZ-0006Ib-CY for bug-gnu-emacs@gnu.org; Wed, 15 Jul 2020 17:19:43 -0400 Received: from mx.sdf.org ([205.166.94.24]:63295) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jvooW-0008HF-Bw; Wed, 15 Jul 2020 17:19:43 -0400 Received: from mab (ma.sdf.org [205.166.94.33]) by mx.sdf.org (8.15.2/8.14.5) with ESMTP id 06FLJbOY015184; Wed, 15 Jul 2020 21:19:37 GMT From: Andrea Corallo To: Stefan Monnier Subject: Re: [feature/native-comp] miscompilation(?) of functions with non local exits References: Date: Wed, 15 Jul 2020 21:19:37 +0000 In-Reply-To: (Stefan Monnier's message of "Wed, 15 Jul 2020 15:17:27 -0400") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=205.166.94.24; envelope-from=akrl@sdf.org; helo=mx.sdf.org X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/15 17:19:38 X-ACL-Warn: Detected OS = ??? X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit Cc: bug-gnu-emacs@gnu.org, Eli Zaretskii X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) Stefan Monnier writes: >> Three options: >> >> 1- Because setq is evaluated the expression should always evaluate to >> t. >> >> 2- Unwinding the original state of the stack is restored, when it was >> saved 'x' was nil so the expression should evaluate to nil. >> >> 3- This is unspecified. > > Very definitely (1)! All right, I pushed a fix that restores behavior 1. >> FYI 1 implies C register variables cannot be used to implement Lisp >> local variable if non local exits are present. > > IIUC, the problem only occurs for those vars which have > a `condition-case` (or `unwind-protect` or `catch`) in their scope and > where the var is modified within that construct and that a non-local > exit can jump to the end of that construct after the var was thus > modified, and that the var is used after the construct. Correct. If the compiler keep these variables in the stack then it's all fine because setjump will restore SP and inside the stack you'll find the most updated value. On the contrary if the variable was kept in a register then its updated value may be lost if the reg is callee saved. > This should be fairly rare (not sure if those cases can easily be > written differently, OTOH). The case I've encountered is `truncate-string-to-width'. > The compiler could replace those vars > by boxing them inside a cons-cell (so the register-stored C var is > immutable and contains a pointer to a cons cell which holds the real > value in the `car`), just like we do with mutated Elisp vars captured > by closures. What I pushed now is (for functions with non locals) just to keep stored all local vars in an array (as the bytecompiler does). I added note and we should be able to implement something more selective as suggested. Either adding an indirection or marking the sensitive variables as volatile. Thanks both for the feedback. Andrea -- akrl@sdf.org From debbugs-submit-bounces@debbugs.gnu.org Thu Jul 16 15:47:33 2020 Received: (at 42360-done) by debbugs.gnu.org; 16 Jul 2020 19:47:33 +0000 Received: from localhost ([127.0.0.1]:56057 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jw9qv-0006Hr-L2 for submit@debbugs.gnu.org; Thu, 16 Jul 2020 15:47:33 -0400 Received: from mx.sdf.org ([205.166.94.24]:61781) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jw9qu-0006Hj-4N for 42360-done@debbugs.gnu.org; Thu, 16 Jul 2020 15:47:32 -0400 Received: from mab (ma.sdf.org [205.166.94.33]) by mx.sdf.org (8.15.2/8.14.5) with ESMTP id 06GJlUlt008584; Thu, 16 Jul 2020 19:47:30 GMT From: Andrea Corallo To: 42360-done@debbugs.gnu.org Subject: Re: bug#42360: [feature/native-comp] miscompilation(?) of functions with non local exits References: Date: Thu, 16 Jul 2020 19:47:30 +0000 In-Reply-To: (Andrea Corallo via's message of "Wed, 15 Jul 2020 21:19:37 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 42360-done Cc: eliz@gnu.org, Stefan Monnier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Right I think we can close this. Thanks Andrea -- akrl@sdf.org From unknown Fri Sep 19 14:39:45 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Fri, 14 Aug 2020 11:24:06 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator