From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 8B5163858424 for ; Tue, 23 Apr 2024 02:58:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8B5163858424 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8B5163858424 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713841100; cv=none; b=GejH+8AwlUQYtNcLJaai/+nOnk7f9W2HV+LeRY2creAb3OYTrsqZN+XWEjxbj5n+6YuZ8Sl2sOJ7eSTMnCfk7P5RS4230tvJIZzUpIx5Ww/3clPVbyLx5Umx0FNPzN2yaTZO2uPSQBtmzmPakQ0C/Au9l2B4T4DftloLu1jodDU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713841100; c=relaxed/simple; bh=OmZb7KzPKYSAjotoyd9N4zpmoYCmuuwx47ozUxEOpRU=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=B3A5galkx+C+eCZJKCQNyV3ebLrngTy00m9BJoVq+/ewzs8yVUjJviULZXQgvxRd29PSbUYRR2Xv2BfzgjAfurHdZKfHYsSt5j+fncEDleDR/c2wOEN+L1ZGD/h5ui7zszC9mVX3qrE7t5vj5f7rc14iKaax5n2Ziv2swHShafc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713841098; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c0zf28V5yeuidzxM4bmFy/jg+0Fhjj+3FoKd+L61jXg=; b=Die/qdnWNSXzikWgAfaTh4fn6cghoIdKSvQvKNK3RNDcacJFMhD9JD2muT21B2LYMee9SL I5ZJ3HYXR0e/1wsQAfmz4xy7CILt/63uwo0Q8oAnrZB7r/w1PsByTftVtPwEaaXRJnIusn l6DPIg3DCNmdhC3vJL+EsoYzUPegh80= Received: from mail-oo1-f70.google.com (mail-oo1-f70.google.com [209.85.161.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-157-g3H4VBP-P8yQIhmGVlAWag-1; Mon, 22 Apr 2024 22:58:16 -0400 X-MC-Unique: g3H4VBP-P8yQIhmGVlAWag-1 Received: by mail-oo1-f70.google.com with SMTP id 006d021491bc7-5a796dc1461so7754797eaf.3 for ; Mon, 22 Apr 2024 19:58:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713841095; x=1714445895; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=c0zf28V5yeuidzxM4bmFy/jg+0Fhjj+3FoKd+L61jXg=; b=a127lyPCYjZEpWTF9P8e7Ne39PUkZuViRcB025jlwR+9Z25ROmTdiA3cafPz8yAkf5 zIkM/3Ch2xDi1rTlhviLKpxayMyYv33LWNWe5Mav0c8Fa7gWarLoGunQLSUyP6nJHY8/ 2AeefDsMOk82fW8dQhwP8EYYjnkIDAxBeUZjAWJvM54tK7TH6U2keaJuFobJyiT9TKnL iU7AaKHY9LYnE1mcBmrTuZyiDBKr0FIMtAVk60UUcxSnrmNRdIUY1aicfmO65kOtpY40 l7loHbPLJSo9OqTPR4eo2OUL7Ma3bxfTQ9RUttg+06XyJFMw4nlbeZG0VusZ4EICPDRA OCig== X-Forwarded-Encrypted: i=1; AJvYcCWZT/VdCJGaqsY5xZ5M+8dIW2AcTeOFgAQhOzdIH1L21JbS/orBjS+HnUz/X9paFafvIEse/GJtU+X8fupnl0kHR9E8Zktuxw== X-Gm-Message-State: AOJu0YynmsqP/UAbhDhrttn3KngKgHx51XN8ZqmrKkaIun9zOEM9u98Z MYh5fLSHLKNpEnDFMRTn5yIKzBfhgMBofVUg3zkqOOVB763XHM6JU17jiyHjZpaXtizhYciM8Gl tJY6xHCMrB+XUIl+mYcHlPipn9M1M1LAf9oBX8TcvJgzcItC7/zhGBvQ= X-Received: by 2002:a05:6358:2c8f:b0:183:645b:cf8d with SMTP id l15-20020a0563582c8f00b00183645bcf8dmr15594603rwm.16.1713841094784; Mon, 22 Apr 2024 19:58:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGS7papWgUISpc8VgjlJRigMbvI+jyJeZ+BD+eb/N+CtPuqxZL1WiN2SS+LC7Y5G40TE3b4Fw== X-Received: by 2002:a05:6358:2c8f:b0:183:645b:cf8d with SMTP id l15-20020a0563582c8f00b00183645bcf8dmr15594547rwm.16.1713841093489; Mon, 22 Apr 2024 19:58:13 -0700 (PDT) Received: from [192.168.1.130] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id k5-20020a0cabc5000000b0069b7929cdfcsm3518365qvb.111.2024.04.22.19.58.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Apr 2024 19:58:12 -0700 (PDT) Message-ID: Date: Mon, 22 Apr 2024 22:58:11 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++: constexpr union member access folding [PR114709] To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20240422221841.3531740-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20240422221841.3531740-1-ppalka@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 List-Id: On 4/22/24 15:18, Patrick Palka wrote: > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK > for trunk/13/12? OK with a rationale comment. > -- >8 -- > > The object/offset canonicalization performed in cxx_fold_indirect_ref > is undesirable for union member accesses because it loses information > about the member being accessed which we may later need to diagnose an > inactive-member access. So this patch restricts the canonicalization > accordingly. > > PR c++/114709 > > gcc/cp/ChangeLog: > > * constexpr.cc (cxx_fold_indirect_ref): Restrict object/offset > canonicalization to RECORD_TYPE member accesses. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp0x/constexpr-union8.C: New test. > --- > gcc/cp/constexpr.cc | 1 + > gcc/testsuite/g++.dg/cpp0x/constexpr-union8.C | 8 ++++++++ > 2 files changed, 9 insertions(+) > create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-union8.C > > diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc > index fcc847d85df..941a478e889 100644 > --- a/gcc/cp/constexpr.cc > +++ b/gcc/cp/constexpr.cc > @@ -5797,6 +5797,7 @@ cxx_fold_indirect_ref (const constexpr_ctx *ctx, location_t loc, tree type, > more folding opportunities. */ > auto canonicalize_obj_off = [] (tree& obj, tree& off) { > while (TREE_CODE (obj) == COMPONENT_REF > + && TREE_CODE (TREE_TYPE (TREE_OPERAND (obj, 0))) == RECORD_TYPE > && (tree_int_cst_sign_bit (off) || integer_zerop (off))) > { > tree field = TREE_OPERAND (obj, 1); > diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-union8.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-union8.C > new file mode 100644 > index 00000000000..34c264944b6 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-union8.C > @@ -0,0 +1,8 @@ > +// PR c++/114709 > +// { dg-do compile { target c++11 } } > + > +struct T1 { int a, b; }; > +struct T2 { int c; double d; }; > +union U { T1 t1; T2 t2; }; > + > +constexpr int v = U{{1,2}}.t2.*&T2::c; // { dg-error "accessing 'U::t2'" }