From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw1-x112d.google.com (mail-yw1-x112d.google.com [IPv6:2607:f8b0:4864:20::112d]) by sourceware.org (Postfix) with ESMTPS id 97EE63858C50 for ; Tue, 13 Feb 2024 15:26:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 97EE63858C50 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 97EE63858C50 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707837976; cv=none; b=knU0OM9h14AU2NAX3cVF+pBaK2SLIcuKN5/qz8rEzMRpfvQY9qfdcFvXTJCks14lns5hCvSVEU2qRwsmunqOshIsRtZhsRlX5F1nKrSW+d1vIFDQLfYdWP0Pf5mMWpJrS/zLPUwLyGwsVAI9OGBH68D00d6GICMAD9lOYagIW3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707837976; c=relaxed/simple; bh=NGiFNlyoSH9kzY6iA2mEvIRiSaGMFu81Xd0xebhSY9c=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=iSW5Y4YmFOZaCHVVF+TOpVtyrGp/NfxQW1kcUvLoZI42bbSYshGgy9Ft/8mQrzar1Qb0p5qDepPXi5EPdoKxDSCRg82Cxu4eXKhpx3J+NIFiu1dOVCXNklADFz0he3BXgFRMLKAqnMstw5Ett77cp78NavMek56lwKU4JfenS7Y= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112d.google.com with SMTP id 00721157ae682-6078f656914so5259827b3.3 for ; Tue, 13 Feb 2024 07:26:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707837974; x=1708442774; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=DuvzaW6Vjs3ojmygO/W8Sa79LFtPqMAzUIoG6Wh07FY=; b=JIwZCTY9XkKYxlj43fSKW1ved9e3bBGlacT2UeCVbS4LWSiQ8RtpkFrU/WvG9FW9UV ZSZLn9sSiim6aAg1iRl2xPL2kcFlFIvWJtX+pzeveMphCxA6y/K/Vhq/fJ2PuAynKXXp WIdyq54SllTAOhhEHwviMpzkWWTA+LYaHA3hEqiIVIcxJytp6cUmzRBd2H/VVhEHarg0 n4qA3LOnPhUtE7cYtakUwDe37o2yscuauF3DlreH/8MZUItxq7s0sFxcqPRDFfeWzH5D Xr0WPveanXUB4i11BpQ7r7i5nM9Z5fUU/VkERO2MmRYi+Wud7TxrDDuH+fCfbitB6jCT y7Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707837974; x=1708442774; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DuvzaW6Vjs3ojmygO/W8Sa79LFtPqMAzUIoG6Wh07FY=; b=VAZVXlHE+3NgCo4KQpNi9V6b5zjSIMG6foE7iQqccWZYgQJlqYrMIuUJwIDa3s48Lo gjxZ6iaRh4X9ne4vXPSSbpMYLaj0wzVzhj1R+jqMddkQ5dJGrC48SbgXDlj9ZzN5Y9Gg B0+JrGaP+SAIqaRYPDg2WsjU5/78gZwZ+B9j5SZMNBsQA2fiSuhX1XXxmageASby9JeI IEqB/9bW1dmw15HEMXIpErf9C+3na2Qc9KlJqsrq1Yu7RTd/UKSQlnRJE5pzPWagJP9v 35EtVM+4ytBnaScNQrW73isaVe9JXqJCNPBPGqDrOysk8k4HjhDB1WiRN/8ebiKSWazQ Mk/g== X-Gm-Message-State: AOJu0Ywx8wLXn7IAg/hSUmQ9I/EVhoPHn89tVfTUtdxCwssUnofe+iLb Xq5eI85twmKutmAv4g+zBFhg++TWLu1EBeiifchkF/Xmnr6AZ0wwFOeblmIUd3XEe48aWkB4dXk WvjuhdCXm4FrJ1xslK94WTtms9NE3s2SooDQ= X-Google-Smtp-Source: AGHT+IEmJZHG50pBPcFgcjsBB4ywICwoGe1AFCfHmJLRxvfW404e3FNZLdpvOPhFrovTdGPNceJo1SnRU68PYLgb9vk= X-Received: by 2002:a5b:c4a:0:b0:dc6:c619:61d8 with SMTP id d10-20020a5b0c4a000000b00dc6c61961d8mr9672863ybr.35.1707837973771; Tue, 13 Feb 2024 07:26:13 -0800 (PST) MIME-Version: 1.0 References: <4b5ab0fa-7f70-4617-379-a80c94b1dc6@redhat.com> In-Reply-To: <4b5ab0fa-7f70-4617-379-a80c94b1dc6@redhat.com> From: Ties Klappe Date: Tue, 13 Feb 2024 16:25:37 +0100 Message-ID: Subject: Re: Nested restrict pointers: missed optimization & client with UB? To: Joseph Myers Cc: gcc@gcc.gnu.org Content-Type: multipart/alternative; boundary="000000000000c2bb5c06114503ca" X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --000000000000c2bb5c06114503ca Content-Type: text/plain; charset="UTF-8" Thank you both for your quick replies. @Joseph, thank you for linking me to the other issue. If I understand correctly what the point is, would you then agree that the program main when calling foo2 has *defined* behavior? What surprises me is that *p and *q might be the same restricted pointer: the *xp* object itself is not declared as *int** *restrict* but as *int**. By passing *xp* as argument to foo1, is the type of the object *xp* then implicitly converted to (or merely interpreted as) *int* restrict *(because of the argument type)*, i.e.* xp corresponds to the object *P *the standard refers to? int main() { int x = 0; int* xp = &x; int res = foo2(&xp, &xp); return 0; } --- @Richard, thank you for the alternative implementation. Is foo3 meant to be optimized by GCC currently (I didn't manage to get GCC13.2 to do it)? Or is it a hypothetical example that would allow GCC to optimize it? int foo3(int *restrict * p, int *restrict * q) { int a; *p = &a; **q = 11; **p = 12; return **q; } Kind regards, Ties Op di 13 feb 2024 om 15:29 schreef Joseph Myers : > On Tue, 13 Feb 2024, Ties Klappe via Gcc wrote: > > > int foo2(int *restrict *p, int *restrict *q) > > { > > **p = 10; > > **q = 11; > > return **p; > > } > > In this case, *p and *q might be the same restricted pointer object. See > the more detailed explanation at > . > > -- > Joseph S. Myers > josmyers@redhat.com > > --000000000000c2bb5c06114503ca--