From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andrea Corallo via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#48061: Unexpected result from a native-compiled function Date: Tue, 27 Apr 2021 20:02:45 +0000 Message-ID: References: Reply-To: Andrea Corallo Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26856"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 48061@debbugs.gnu.org To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Apr 27 22:05:35 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lbTxe-0006jB-I2 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 27 Apr 2021 22:05:34 +0200 Original-Received: from localhost ([::1]:32976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lbTxd-0001vm-JU for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 27 Apr 2021 16:05:33 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51472) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbTvC-0000PN-4n for bug-gnu-emacs@gnu.org; Tue, 27 Apr 2021 16:03:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:39445) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lbTvB-0003ut-SJ for bug-gnu-emacs@gnu.org; Tue, 27 Apr 2021 16:03:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lbTvB-0006Wo-Oo for bug-gnu-emacs@gnu.org; Tue, 27 Apr 2021 16:03:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andrea Corallo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 27 Apr 2021 20:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48061 X-GNU-PR-Package: emacs Original-Received: via spool by 48061-submit@debbugs.gnu.org id=B48061.161955377225078 (code B ref 48061); Tue, 27 Apr 2021 20:03:01 +0000 Original-Received: (at 48061) by debbugs.gnu.org; 27 Apr 2021 20:02:52 +0000 Original-Received: from localhost ([127.0.0.1]:50991 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lbTv2-0006WQ-7w for submit@debbugs.gnu.org; Tue, 27 Apr 2021 16:02:52 -0400 Original-Received: from mx.sdf.org ([205.166.94.24]:63245) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lbTuz-0006WF-R7 for 48061@debbugs.gnu.org; Tue, 27 Apr 2021 16:02:50 -0400 Original-Received: from mab (ma.sdf.org [205.166.94.33]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id 13RK2jvd023521 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO); Tue, 27 Apr 2021 20:02:46 GMT In-Reply-To: (Alan Mackenzie's message of "Tue, 27 Apr 2021 17:20:22 +0000") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:205054 Archived-At: Alan Mackenzie writes: > On Tue, Apr 27, 2021 at 14:49:31 +0000, Alan Mackenzie wrote: >> Hello, Emacs. > >> In certain circumstances (see below for recipe), the natively compiled >> version of c-determine-limit-no-macro returns an invalid result, nil. >> In the same circumstances, the edebug instrumented version returns the >> correct result, a buffer position. > >> So far I have tried M-x disassemble RET c-determine-limit-no-macro, but >> I wasn't able to follow the output (there were no symbols in the >> listing). > > I've now managed to get a decent disassembly, and there is indeed a > missing machine instruction in the code which causes it to fail: > > The function is: > > ######################################################################### > (defun c-determine-limit-no-macro (here org-start) > ;; If HERE is inside a macro, and ORG-START is not also in the same macro, > ;; return the beginning of the macro. Otherwise return HERE. Point is not > ;; preserved by this function. > (goto-char here) > (let ((here-BOM (and (c-beginning-of-macro) (point)))) > (if (and here-BOM > (not (eq (progn (goto-char org-start) > (and (c-beginning-of-macro) (point))) > here-BOM))) > here-BOM > here))) > ######################################################################### > > The register use in the compiled function is: > > rbp here > r12 org-start > r13 here-BOM > > The disassembly (with some added notes) is this: > > 00000000000264f0 : > 264f0: 41 56 push %r14 [...] > 26583: ff 93 68 14 00 00 callq *0x1468(%rbx) point > 26589: 48 89 c7 mov %rax,%rdi > 2658c: 4c 89 ee mov %r13,%rsi here-BOM > 2658f: ff 93 60 27 00 00 callq *0x2760(%rbx) eq > 26595: 48 85 c0 test %rax,%rax <======================================================== > 26598: 74 03 je 2659d > 2659a: 48 89 e8 mov %rbp,%rax here > 2659d: 48 8b 54 24 18 mov 0x18(%rsp),%rdx > 265a2: 64 48 2b 14 25 28 00 sub %fs:0x28,%rdx > 265a9: 00 00 > 265ab: 75 0d jne 265ba > 265ad: 48 83 c4 20 add $0x20,%rsp > 265b1: 5b pop %rbx > 265b2: 5d pop %rbp > 265b3: 41 5c pop %r12 > 265b5: 41 5d pop %r13 > 265b7: 41 5e pop %r14 > 265b9: c3 retq > 265ba: e8 41 12 fe ff callq 7800 <__stack_chk_fail@plt> > 265bf: 90 nop > > After the indicated line (0x26595), when 0x0 (nil) is in rax (i.e. the > `eq' function has returned nil) the result of the function should be > here-BOM, i.e. r13. There is no instruction > > mov %r13,%rax > > to effect this return. Instead, rax is still holding nil, and this is > falsely returned. > Hi Alan, thanks for investigating this! I had a quick look and I think I see what's the issue, I'll follow up when I've the fix. Thanks Andrea