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 66B96385840D for ; Tue, 2 May 2023 20:25:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 66B96385840D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683059137; 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=VVuFHAE0rP1g/XNpuKejiYl7ZF60yMd6DYmjFEVXL88=; b=Bk7M0OY98vMaTx+/HqJgLA/iXTPd3t1fLgOXsa+cKBqAn8GAW1dIq6rdVCA5kz0auJyEjQ FWuxVu/eQhUj0pKt+BvEjPJSGV/3d3QsOv9Fnv00BShoKEJS6A9Th3xIB451MfDiFMrcnk Ky0UJF55O5P8S4VatVkASsvpjv7l6v4= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-183-7YyJyejPNq-rTYNC8ll-ag-1; Tue, 02 May 2023 16:25:36 -0400 X-MC-Unique: 7YyJyejPNq-rTYNC8ll-ag-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-751319bd93cso2160185a.0 for ; Tue, 02 May 2023 13:25:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683059135; x=1685651135; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VVuFHAE0rP1g/XNpuKejiYl7ZF60yMd6DYmjFEVXL88=; b=km4AJPJzxK13PKIn1u6rpxymixViai0zBtK/B0jK0sdvYCyx0K520Hax+6+F6n/i/n uMsvzz9ju8ANGXzZ6p1dcVvgPAYk8+bOn/9C1i+BMJarTOxHCpZqJYKtzl0BRKxLxO95 H0DR0Ln0bQfPvmfW+v3zFLsKWu+vIINA6vPA6uqyh6kIJ6AI+9J83jHaNC/IJHhWz3jg jQn6Cph2vttTVI2rHYlqgTnpPXDuTOiNl2JLwLP4zivbmbULbSzlYMXMrNWGDuhM7jk8 9WmcvAA0A8B4hPEUohuR1glhBdQ28LaMYGsdF6RTYFb/wn/ulIMT8YQTgqJh5P6U2G2+ OuEw== X-Gm-Message-State: AC+VfDyYT8xO1QVtt/V8DrJzyETHViKwlqMkVfCUgEyWtRnLedrsP7Ad uYQR/kQRiEkvtry78lZd8yc9hfLG/H7C8W/dfGFV+h2LfnHQXt4YHQPEhCJRFVYbXvWBYSRPssJ mQ9mInIg5XEKj5eKUAF78J7o42jpvnYq8ljLQaHGNtOZX5fEsrRWMlFZDQAvRvcAT8agSLO5iGQ == X-Received: by 2002:a05:6214:529c:b0:61b:6382:4579 with SMTP id kj28-20020a056214529c00b0061b63824579mr5466702qvb.9.1683059135428; Tue, 02 May 2023 13:25:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ76Uti2rk+aOKaiSsdFucwQehbqK2DxF8hE0eBvwdK7JZMHaWNY1B7RPGMEJxZodjPpsy77fg== X-Received: by 2002:a05:6214:529c:b0:61b:6382:4579 with SMTP id kj28-20020a056214529c00b0061b63824579mr5466660qvb.9.1683059134898; Tue, 02 May 2023 13:25:34 -0700 (PDT) Received: from jason.com (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 y11-20020ac8128b000000b003ef6582d971sm9060696qti.47.2023.05.02.13.25.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 13:25:34 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] c++: look for empty base at specific offset [PR109678] Date: Tue, 2 May 2023 16:25:25 -0400 Message-Id: <20230502202525.1964821-2-jason@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230502202525.1964821-1-jason@redhat.com> References: <20230502202525.1964821-1-jason@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.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_H2,SPF_HELO_NONE,SPF_NONE,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: Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- While looking at the empty base handling for 109678, it occurred to me that we ought to be able to look for an empty base at a specific offset, not just in general. PR c++/109678 gcc/cp/ChangeLog: * cp-tree.h (lookup_base): Add offset parm. * constexpr.cc (cxx_fold_indirect_ref_1): Pass it. * search.cc (struct lookup_base_data_s): Add offset. (dfs_lookup_base): Handle it. (lookup_base): Pass it. --- gcc/cp/cp-tree.h | 3 ++- gcc/cp/constexpr.cc | 2 +- gcc/cp/search.cc | 25 ++++++++++++++++++++++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index c9c4cd6f32f..406a5508ce7 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7515,7 +7515,8 @@ extern tree build_if_nonnull (tree, tree, tsubst_flags_t); extern tree get_parent_with_private_access (tree decl, tree binfo); extern bool accessible_base_p (tree, tree, bool); extern tree lookup_base (tree, tree, base_access, - base_kind *, tsubst_flags_t); + base_kind *, tsubst_flags_t, + HOST_WIDE_INT = -1); extern tree dcast_base_hint (tree, tree); extern int accessible_p (tree, tree, bool); extern int accessible_in_template_p (tree, tree); diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 37d1c444c9e..70dd6cf4d90 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -5452,7 +5452,7 @@ cxx_fold_indirect_ref_1 (const constexpr_ctx *ctx, location_t loc, tree type, which is likely to be a waste of time (109678). */ if (is_empty_class (type) && CLASS_TYPE_P (optype) - && DERIVED_FROM_P (type, optype)) + && lookup_base (optype, type, ba_any, NULL, tf_none, off)) { if (empty_base) *empty_base = true; diff --git a/gcc/cp/search.cc b/gcc/cp/search.cc index 3f521b3bd72..cd80f285ac9 100644 --- a/gcc/cp/search.cc +++ b/gcc/cp/search.cc @@ -56,6 +56,7 @@ static tree dfs_get_pure_virtuals (tree, void *); struct lookup_base_data_s { + HOST_WIDE_INT offset; /* Offset we want, or -1 if any. */ tree t; /* type being searched. */ tree base; /* The base type we're looking for. */ tree binfo; /* Found binfo. */ @@ -74,6 +75,22 @@ dfs_lookup_base (tree binfo, void *data_) { struct lookup_base_data_s *data = (struct lookup_base_data_s *) data_; + if (data->offset != -1) + { + /* We're looking for the type at a particular offset. */ + int comp = compare_tree_int (BINFO_OFFSET (binfo), data->offset); + if (comp > 0) + /* Don't bother looking into bases laid out later; even if they + do virtually inherit from the base we want, we can get there + by another path. */ + return dfs_skip_bases; + else if (comp != 0 + && SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), data->base)) + /* Right type, wrong offset. */ + return dfs_skip_bases; + /* Fall through. */ + } + if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), data->base)) { if (!data->binfo) @@ -190,7 +207,7 @@ accessible_base_p (tree t, tree base, bool consider_local_p) /* Lookup BASE in the hierarchy dominated by T. Do access checking as ACCESS specifies. Return the binfo we discover. If KIND_PTR is non-NULL, fill with information about what kind of base we - discovered. + discovered. If OFFSET is other than -1, only match at that offset. If the base is inaccessible, or ambiguous, then error_mark_node is returned. If the tf_error bit of COMPLAIN is not set, no error @@ -198,7 +215,8 @@ accessible_base_p (tree t, tree base, bool consider_local_p) tree lookup_base (tree t, tree base, base_access access, - base_kind *kind_ptr, tsubst_flags_t complain) + base_kind *kind_ptr, tsubst_flags_t complain, + HOST_WIDE_INT offset /* = -1 */) { tree binfo; tree t_binfo; @@ -246,8 +264,9 @@ lookup_base (tree t, tree base, base_access access, data.base = base; data.binfo = NULL_TREE; data.ambiguous = data.via_virtual = false; - data.repeated_base = CLASSTYPE_REPEATED_BASE_P (t); + data.repeated_base = (offset == -1) && CLASSTYPE_REPEATED_BASE_P (t); data.want_any = access == ba_any; + data.offset = offset; dfs_walk_once (t_binfo, dfs_lookup_base, NULL, &data); binfo = data.binfo; -- 2.31.1