From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#48061: Unexpected result from a native-compiled function Date: Tue, 27 Apr 2021 17:20:22 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38445"; mail-complaints-to="usenet@ciao.gmane.io" To: 48061@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Apr 27 19:58:43 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 1lbRyt-0009t0-2Q for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 27 Apr 2021 19:58:43 +0200 Original-Received: from localhost ([::1]:41334 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lbRys-0002kH-4q for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 27 Apr 2021 13:58:42 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbROR-0003c5-D6 for bug-gnu-emacs@gnu.org; Tue, 27 Apr 2021 13:21:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:39254) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lbROR-0003l7-4X for bug-gnu-emacs@gnu.org; Tue, 27 Apr 2021 13:21:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lbROR-0002Ww-0B for bug-gnu-emacs@gnu.org; Tue, 27 Apr 2021 13:21:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 27 Apr 2021 17:21:02 +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.16195440329640 (code B ref 48061); Tue, 27 Apr 2021 17:21:02 +0000 Original-Received: (at 48061) by debbugs.gnu.org; 27 Apr 2021 17:20:32 +0000 Original-Received: from localhost ([127.0.0.1]:50796 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lbRNw-0002VQ-0Z for submit@debbugs.gnu.org; Tue, 27 Apr 2021 13:20:32 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:23305 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1lbRNu-0002VB-Ew for 48061@debbugs.gnu.org; Tue, 27 Apr 2021 13:20:31 -0400 Original-Received: (qmail 61304 invoked by uid 3782); 27 Apr 2021 17:20:23 -0000 Original-Received: from acm.muc.de (p4fe15a60.dip0.t-ipconnect.de [79.225.90.96]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Tue, 27 Apr 2021 19:20:23 +0200 Original-Received: (qmail 6651 invoked by uid 1000); 27 Apr 2021 17:20:22 -0000 Content-Disposition: inline In-Reply-To: X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de 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:205041 Archived-At: 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 264f2: 41 55 push %r13 264f4: 41 54 push %r12 264f6: 49 89 f4 mov %rsi,%r12 org-start 264f9: 55 push %rbp 264fa: 48 89 fd mov %rdi,%rbp here 264fd: 53 push %rbx 264fe: 48 83 ec 20 sub $0x20,%rsp 26502: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax 26509: 00 00 2650b: 48 89 44 24 18 mov %rax,0x18(%rsp) 26510: 48 8b 05 d1 2a 27 00 mov 0x272ad1(%rip),%rax # 298fe8 <_DYNAMIC+0x1f8> 26517: 48 8b 18 mov (%rax),%rbx 2651a: ff 93 b8 14 00 00 callq *0x14b8(%rbx) goto-char 26520: 48 8d 74 24 08 lea 0x8(%rsp),%rsi 26525: bf 01 00 00 00 mov $0x1,%edi 2652a: 4c 8b 35 af 2a 27 00 mov 0x272aaf(%rip),%r14 # 298fe0 <_DYNAMIC+0x1f0> 26531: 49 8b 86 c8 00 00 00 mov 0xc8(%r14),%rax 26538: 48 89 44 24 08 mov %rax,0x8(%rsp) 2653d: ff 93 08 1a 00 00 callq *0x1a08(%rbx) c-beginning-of-macro 26543: 48 85 c0 test %rax,%rax 26546: 74 52 je 2659a 26548: ff 93 68 14 00 00 callq *0x1468(%rbx) point 2654e: 49 89 c5 mov %rax,%r13 here-BOM 26551: 48 85 c0 test %rax,%rax 26554: 74 44 je 2659a 26556: 4c 89 e7 mov %r12,%rdi org-start 26559: ff 93 b8 14 00 00 callq *0x14b8(%rbx) goto-char 2655f: bf 01 00 00 00 mov $0x1,%edi 26564: 48 8d 74 24 10 lea 0x10(%rsp),%rsi 26569: 49 8b 86 c8 00 00 00 mov 0xc8(%r14),%rax 26570: 48 89 44 24 10 mov %rax,0x10(%rsp) 26575: ff 93 08 1a 00 00 callq *0x1a08(%rbx) c-beginning-of-macro 2657b: 48 89 c7 mov %rax,%rdi 2657e: 48 85 c0 test %rax,%rax 26581: 74 09 je 2658c 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. > -- > Alan Mackenzie (Nuremberg, Germany).