From patchwork Mon Apr 22 22:18:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1926318 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=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aAwu0Wj9; 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 4VNfmz6XrVz1yP2 for ; Tue, 23 Apr 2024 08:19:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 563863858CDA for ; Mon, 22 Apr 2024 22:19:29 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 096B33858D38 for ; Mon, 22 Apr 2024 22:19:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 096B33858D38 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 096B33858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713824348; cv=none; b=szNDBdEdfXWyMYI9o6sVyADVxgE55hwekGcUFwfngBPIhv7ue87QVS6YIrOhEDsxJUCP5mG9uZMz+klD8B2+JQleGLFhNAGfyGgyEDO8pc3rochmiIO0eBivYVxAwZd2jjo7EbFR5UKeooMdsqikeObdzLSiCmtfoyokl7wN1dg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713824348; c=relaxed/simple; bh=zQ4nbHBBF5jwu4jHSFFctTYkSiVosWGebzjMsXk7ev4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=PbFFI8MAxotqG+WcLz84Wrb8AqYljNB1MgiF90Bgo7NFprvnFJ4uz6hfaadSShsgswicU4A36h09CzT2CjF8l64FKUTfHq3JOc1AP8bWB/Eu7oPkxq05iqiPxjsIMg62vqQAyLqZIT/fRAVyTDoBchb+OmJ4u2VRvz+fF4Etsyg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713824346; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RBXOUHXfwLzYT0B2geKrwh5p2jSUT2d2qtBHTjjCgZo=; b=aAwu0Wj9aPycwNSX6hZyxM79N4pEaFwtx3ILS7a/yfSgAwXH0zffWd89JkeXNoGlAsglhx bz+hbBecq/WCqWA98dNmDIV+s2yYr92hdPqhmpFSsu0PN65mHwSgkKV6y2O3wKu9Vehfmn hLaqkplX5/ODxdJdXtTztvVAziZq6lg= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-32-IDMVwUDWMRiLKvGLJYDnMw-1; Mon, 22 Apr 2024 18:19:05 -0400 X-MC-Unique: IDMVwUDWMRiLKvGLJYDnMw-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-78ee7776740so782094685a.2 for ; Mon, 22 Apr 2024 15:19:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713824344; x=1714429144; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RBXOUHXfwLzYT0B2geKrwh5p2jSUT2d2qtBHTjjCgZo=; b=AQPg1/4XiNDhFt5AKoP95wk3s6wNABz2wcrGrtEQ9Fb1PscMWW/RPbEhx4QIe53Qh2 LsDXzTahuMbyIaIkcgcBAl3R5ss3gv967lBb7Xzks0OOa8Z397cCUNm+2loTiwmQ2//y x71UPI/M3V4TECih5Fmel7fG6zzvaSGF4C7CNycFhH16F5lPAYHV0FZytY8IddRp1bEk AYwj6QifkhyYDa//j4oL7bsM4c1rI7IC4LqFzRQ7hAzKrT6gU6DYQUKnLCSMD2bFPp9E YfqT96/0Sm4lbmhG3TSzJKxe5JAQZU5gQejYalZCUmuCfO5FLOXc3Sq9oNmbFoB3BDFU 8Unw== X-Gm-Message-State: AOJu0YxMor9QWPJESaKvcIm4AjqSMnm+2kvVrSwmogENWpyYfOw4eh1J b4FmYiAPyBhJ6aTSTx2AwsCGZ8ROEBMCZW21oSuIoGokFZcw3pN8p+AfbC1rKmODZ0MPnAIFAy/ IfgMhu16hEB3vZTJ5OmylTuonZdSND1DXW8WeNtuFM6jiU7OIhQTY/zClZXlNSrczlTSxzRER0U G85EZUD4ufgU2qVPLxlOEwPLEyFQ4rQhLzZgTb X-Received: by 2002:a05:620a:4ada:b0:78f:15b7:1a7b with SMTP id sq26-20020a05620a4ada00b0078f15b71a7bmr12383012qkn.70.1713824344351; Mon, 22 Apr 2024 15:19:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE31ksSgVelAcI43EOOrlH+w3UfOIwv1UYOf9+ZwDXM75VVAG91KIISWdAxoA6vZFD1q4VuAQ== X-Received: by 2002:a05:620a:4ada:b0:78f:15b7:1a7b with SMTP id sq26-20020a05620a4ada00b0078f15b71a7bmr12382992qkn.70.1713824343984; Mon, 22 Apr 2024 15:19:03 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id y12-20020a05620a09cc00b0078d4732d92fsm4659205qky.115.2024.04.22.15.19.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 15:19:03 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: constexpr union member access folding [PR114709] Date: Mon, 22 Apr 2024 18:18:41 -0400 Message-ID: <20240422221841.3531740-1-ppalka@redhat.com> X-Mailer: git-send-email 2.45.0.rc0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.9 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 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 Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk/13/12? -- >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'" }