From patchwork Mon Jul 22 16:11:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1963325 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=ucw.cz header.i=@ucw.cz header.a=rsa-sha256 header.s=gen1 header.b=VvQjoZzc; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WSQJy2rCSz1ybY for ; Tue, 23 Jul 2024 02:12:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2C5A63858C52 for ; Mon, 22 Jul 2024 16:11:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id 328E63858C33 for ; Mon, 22 Jul 2024 16:11:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 328E63858C33 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=ucw.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kam.mff.cuni.cz ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 328E63858C33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.113.20.16 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721664695; cv=none; b=fDGC/M9Fyl/2bm+P5cXqeovI1+dLRbWrOYYmThhwQ8PaUUiT8Gq/Ke0evcWYb3zrX9ysnESpOpoUbX4MVow6JVWbrC8zXJEvTo2AyQgfmRDjs7arydiCi/vAek51wdiREY41JegTZGV8we0kVMC4T/SrPFdZqHqaBFolI/ezQ6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721664695; c=relaxed/simple; bh=Q2+x0ZpoX6F2RP9PyQ4pUAoBgQ6NTPpBclpv+guWTkg=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=KnDGJ4B5CerRAvuMNXzwVZWZMqJZjv4SEd+XwFU9w8zdJREmyVsQK/YQxW353noMbkINHO0Eo+1HXYbrOaIXqxnfztBNmnrXG8IdaTUnBVLVeVCZGIXu8wf62haJ3B7MP3eXAiBNp8dU4Oy2foQ+iraQhZuhSyaatA548aS+49c= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id C338F2841AA; Mon, 22 Jul 2024 18:11:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ucw.cz; s=gen1; t=1721664691; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=L/IXGXdJlK8sHOp10DcelufwSPaTA3uaohCVwZimhgU=; b=VvQjoZzc/mkvbiAq3bsdV0NxB5h8BoRNrGcuzQF8xOvE5HoZwpRULmucyHlcA3SJqQy11h N03QU7n3J/InFZGkretNw9gk64xOgLRxC2JZ4acAxNALHxc0m83fJoWjFm/WKNg4QCqOkY 4v0Dn3Y9M3J1RGMZWkawa7ZjEu2W9Tc= Date: Mon, 22 Jul 2024 18:11:31 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Fix accounting of offsets in unadjusted_ptr_and_unit_offset Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, JMQ_SPF_NEUTRAL, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi, unadjusted_ptr_and_unit_offset accidentally throws away the offset computed by get_addr_base_and_unit_offset. Instead of passing extra_offset it passes offset. Bootstrapped/regtested x86_64-linux and comitted. Will backport it to gcc14 PR ipa/114207 gcc/ChangeLog: * ipa-prop.cc (unadjusted_ptr_and_unit_offset): Fix accounting of offsets in ADDR_EXPR. gcc/testsuite/ChangeLog: * gcc.c-torture/execute/pr114207.c: New test. diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc index 7d7cb3835d2..99ebd6229ec 100644 --- a/gcc/ipa-prop.cc +++ b/gcc/ipa-prop.cc @@ -1370,9 +1370,9 @@ unadjusted_ptr_and_unit_offset (tree op, tree *ret, poly_int64 *offset_ret) { if (TREE_CODE (op) == ADDR_EXPR) { - poly_int64 extra_offset = 0; + poly_int64 extra_offset; tree base = get_addr_base_and_unit_offset (TREE_OPERAND (op, 0), - &offset); + &extra_offset); if (!base) { base = get_base_address (TREE_OPERAND (op, 0)); diff --git a/gcc/testsuite/gcc.c-torture/execute/pr114207.c b/gcc/testsuite/gcc.c-torture/execute/pr114207.c new file mode 100644 index 00000000000..052fa85e9fc --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr114207.c @@ -0,0 +1,23 @@ +#include +#include + +struct S { + int a, b; +}; + +__attribute__((noinline)) +void foo (struct S *s) { + struct S ss = (struct S) { + .a = s->b, + .b = s->a + }; + *s = ss; +} + +int main() { + struct S s = {6, 12}; + foo(&s); + if (s.a != 12 || s.b != 6) + __builtin_abort (); + return 0; +}