From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Pip Cet via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#74771: Native compilation bug with struct predicates when lexical binding enabled (HEAD) Date: Tue, 10 Dec 2024 21:21:04 +0000 Message-ID: <87jzc7me0b.fsf@protonmail.com> References: <0446a656-1fa2-4160-a8ba-69c060a52589@risk-engineering.org> Reply-To: Pip Cet Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13215"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 74771@debbugs.gnu.org To: Eric Marsden Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Dec 10 22:22:23 2024 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 1tL7gV-0003Hc-Bz for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 10 Dec 2024 22:22:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tL7gD-0006NW-LH; Tue, 10 Dec 2024 16:22:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tL7gB-0006N1-2O for bug-gnu-emacs@gnu.org; Tue, 10 Dec 2024 16:22:03 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tL7gA-0006A7-Qn for bug-gnu-emacs@gnu.org; Tue, 10 Dec 2024 16:22:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:From:Date:To:Subject; bh=AGpgk17BWxs/uHembsjpoEOXRloBeStBQCxfnwm2d00=; b=B+XZgMvJnJMcRvFvtnrK0IRwKc5WicwR3UPafisysmySc1O+CBANCZeuiZldrAk8HoOtYaszlOlNbavp7vPebAEAC6KaqBVhCB+LC5cCYo99dxwxNWtizUqceEJ4tbdRtWk+d/xriMxHazSkBw8+piTXUHgtvNVestOREPLgt+JoNAfJm3At6LP7zVskatqbUoptgmghbhMB2CGSYHY/FTVD6xvGApguXwquwHbMEoQUT441+W7qJM5WYk8s61Hi8168ZN8l4CoTxWftyL0c+/E0vkYFvetzc2fH9LneRKeF/ZyvkamzhIb4IxVwv9XQe2G6ixRpPugwiacAlz/irA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tL7gA-0002d8-7N for bug-gnu-emacs@gnu.org; Tue, 10 Dec 2024 16:22:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Pip Cet Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 10 Dec 2024 21:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74771 X-GNU-PR-Package: emacs Original-Received: via spool by 74771-submit@debbugs.gnu.org id=B74771.17338656779879 (code B ref 74771); Tue, 10 Dec 2024 21:22:02 +0000 Original-Received: (at 74771) by debbugs.gnu.org; 10 Dec 2024 21:21:17 +0000 Original-Received: from localhost ([127.0.0.1]:59812 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tL7fR-0002ZG-AZ for submit@debbugs.gnu.org; Tue, 10 Dec 2024 16:21:17 -0500 Original-Received: from mail-4316.protonmail.ch ([185.70.43.16]:42827) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tL7fO-0002YM-G2 for 74771@debbugs.gnu.org; Tue, 10 Dec 2024 16:21:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1733865668; x=1734124868; bh=AGpgk17BWxs/uHembsjpoEOXRloBeStBQCxfnwm2d00=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=pZbrWF3P33Dxib/iDGBDCaG8Pemx5ZrImGj4gydSpd0IsYCHfEC0lfKefdoruUb+Y +zgcLPR7r/4+FfDrLKcdeRGOYujtVGgxzUEoPWTxJcAU6JgRo427ObnTXqjDpwZ4DT IEUnM90evJrDCeAHPHLHqZABDrlRhcqd6bvF7DEmzbzrfkBmXWTQ5nSOYigAS/qs/x gWbK9nWbq8FzRfsTeNhXox98B+56wmQAsBcV9fcGrKVVhueyXN/dk9fAzWm8Latf+u PD9GT64JVZf1tcsUw/WUG6eYomUtZqBEwQ75LDeZED0uOxmURDpgeUBsIxI3kU1t3/ BcjSFzAYS4cmQ== In-Reply-To: <0446a656-1fa2-4160-a8ba-69c060a52589@risk-engineering.org> Feedback-ID: 112775352:user:proton X-Pm-Message-ID: 7aab1edf49afcfdf44708eb1f8ef9b0dace55ef4 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:296785 Archived-At: "Eric Marsden" writes: > Hi, > > With the attached source file, Emacs miscompiles the struct predicate suc= h > that a repeated call to the predicate on a non-struct object returns t. > This occurs with current HEAD on Linux/AMD64, but not on the Emacs 30.0.9= 2 > pretest. It does not occur when the lexical binding cookie is not present= . > > % /opt/emacs/bin/emacs -Q --batch --eval "(load (native-compile \"/tmp/bu= g.el\"))" -f run > Loading /home/emarsden/.emacs.d/eln-cache/31.0.50-c021c983/bug-59c4b27c-c= 70072f9.eln (native compiled elisp)... > Running in GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version = 3.24.43, cairo version 1.18.2) > =C2=A0of 2024-12-09 > is? nil > is? t=C2=A0=C2=A0 ;; expecting nil > bar: 111 > > [2. text/x-emacs-lisp; bug.el]... Can you try this patch? diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 0d40f05bef1..c3e9a8be66d 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -2029,15 +2029,18 @@ comp--add-cond-cstrs (call symbol-value ,(and (pred comp-cstr-cl-tag-p) mvar-tag)= )) (set ,(and (pred comp-mvar-p) mvar-3) (call memq ,(and (pred comp-mvar-p) mvar-1) ,(and (pred comp= -mvar-p) mvar-2))) - (cond-jump ,(and (pred comp-mvar-p) mvar-3) ,(pred comp-mvar-p) ,= bb1 ,bb2)) - (comp--emit-assume 'and mvar-tested - (make--comp-mvar :type (comp-cstr-cl-tag mvar-tag= )) - (comp--add-cond-cstrs-target-block b bb2) - nil) - (comp--emit-assume 'and mvar-tested - (make--comp-mvar :type (comp-cstr-cl-tag mvar-tag= )) - (comp--add-cond-cstrs-target-block b bb1) - t)) + (cond-jump ,(and (pred comp-mvar-p) mvar-3) ,(and (pred comp-mvar= -p) mvar-4) ,bb1 ,bb2)) + (cond + ((and (comp-cstr-imm-vld-p mvar-4) + (eq (comp-cstr-imm mvar-4) t)) + (comp--emit-assume 'and mvar-tested + (make--comp-mvar :type (comp-cstr-cl-tag mvar-= tag)) + (comp--add-cond-cstrs-target-block b bb2) + nil) + (comp--emit-assume 'and mvar-tested + (make--comp-mvar :type (comp-cstr-cl-tag mvar-= tag)) + (comp--add-cond-cstrs-target-block b bb1) + t)))) (`((set ,(and (pred comp-mvar-p) cmp-res) (,(pred comp--call-op-p) ,(and (or (pred comp--equality-fun-p) IIUC, the code blindly assumes that cond-jump would use t as its second argument. In your code, the second argument was nil, so the assumptions were put into the wrong basic blocks. It looks like there are quite a few such assumptions in comp.el. I think we should fix them all to ensure that they test for truth, not falsehood. After that, we'll have to decide whether it's worth it to optimize the negated cases. Pip