From patchwork Wed Dec 2 15:38:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1409802 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=GHm2GC2P; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CmNRW730sz9sRK for ; Thu, 3 Dec 2020 02:38:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AC626395C876; Wed, 2 Dec 2020 15:38:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by sourceware.org (Postfix) with ESMTPS id 86F25395C81D for ; Wed, 2 Dec 2020 15:38:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 86F25395C81D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qk1-x729.google.com with SMTP id y197so1573756qkb.7 for ; Wed, 02 Dec 2020 07:38:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=2gynjY1ouzYOxHApYATjifiRwuejPoPbW2vLbK8S7kE=; b=GHm2GC2P9BTX2SOHDoEujDUL2zhtR/+ZysCwTxzoc0q6eenJcJ4Imoy1OhOnR87k2f gTkQkVQO0SVKimKYk+gUrx/3YgdlQ2+n4LStT058CjVErpCzCEf20c1RxjRi0zdfHz18 lyGcBaeO9bPrVWz0sAby8LaAN0E22ck7mLqIIxBN8+A8suvsb+3Cyu7tl9Rt0Yb8oCeg 1inGpky+xakO9O8W20pMKa5P87ZL0+nCYEfL6qgI/G/GU7l7N00VoEqIqVMiG4JkQri8 IdmrEArdY9XuPqHfTWG45I2vcKEhdxxW5QYBB4VXDVtRzimrebTYhqiWzUVtMche+Icv K4kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=2gynjY1ouzYOxHApYATjifiRwuejPoPbW2vLbK8S7kE=; b=jPBxYgt69SXG78rhU2nI3sevlhWx02H070gIjmIZnebwuawDf7htT+HsYnyGW3QAiw g8bGT7mT1JNQcWwZQ614lx2GKgfOhuKTd/KCXR0Z6F/SAJJgzc0Vc76JGZZNuOSRFNOE II1nl1oHyMhLlNiBbL/xjoTtRBYXcDM3iuGlopx786NGMMCrX5iH/QmgJpmE7ub99Spp TXmdjAWr9WPIRqNfda0RvV1HGozIPJAAfTzman42d+++h1F2Kulewhun2DYsuwTl+2C1 8fKOYQ3/PnmW7xe2sY3vUU+Ang41qmz2yHi11W2TLpKOe8M+q0Lbmi4IB7eTHRAx29aJ DezA== X-Gm-Message-State: AOAM5313gth7MmnDh7fEInGLEEWXfVmCWF84wryGwK+PbAa0E09kd/St bAWAEBp/yTrab8XNVJhHJTE= X-Google-Smtp-Source: ABdhPJxAy4EfjmO8dtwQLY0xIsUI8EvZP0xC9FLsQrh69L3S3Y8SIcyz+Et02l0PIhKyfvwBgG/lNg== X-Received: by 2002:a37:c4d:: with SMTP id 74mr3187440qkm.161.1606923521801; Wed, 02 Dec 2020 07:38:41 -0800 (PST) Received: from ?IPv6:2620:10d:c0a8:1102:fd8c:7733:5cca:4143? ([2620:10d:c091:480::1:fb39]) by smtp.googlemail.com with ESMTPSA id h4sm2135469qkh.93.2020.12.02.07.38.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Dec 2020 07:38:40 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: c++: Extend build_array_type API Message-ID: <00f5cc87-be78-d7ae-af89-ad897986b4ad@acm.org> Date: Wed, 2 Dec 2020 10:38:39 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" The modules machinery needs to construct array types, and that wanted to determine type dependency. That doesn't work during loading, but the module loader can stream that fact too and tell the array builder. Thus this extends the API to allow a caller to specify the dependency explicitly. The call in cp_build_qualified_type_real is unreachable during the loading, so that one's ok as is. gcc/cp/ * cp-tree.h (build_cplus_array_type): Add defaulted DEP parm. * tree.c (set_array_type_common): Add DEP parm. (build_cplus_array_type): Add DEP parm, determine dependency if needed. (cp_build_qualified_type_real): Adjust array-building call. (strip_typedefs): Likewise. pushing to trunk diff --git i/gcc/cp/cp-tree.h w/gcc/cp/cp-tree.h index b5d4fc0aba1..ae1147d4589 100644 --- i/gcc/cp/cp-tree.h +++ w/gcc/cp/cp-tree.h @@ -7377,7 +7377,7 @@ extern bool is_local_temp (tree); extern tree build_aggr_init_expr (tree, tree); extern tree get_target_expr (tree); extern tree get_target_expr_sfinae (tree, tsubst_flags_t); -extern tree build_cplus_array_type (tree, tree); +extern tree build_cplus_array_type (tree, tree, int is_dep = -1); extern tree build_array_of_n_type (tree, int); extern bool array_of_runtime_bound_p (tree); extern bool vla_type_p (tree); diff --git i/gcc/cp/tree.c w/gcc/cp/tree.c index 4113a34b0c1..5932777be04 100644 --- i/gcc/cp/tree.c +++ w/gcc/cp/tree.c @@ -998,7 +998,7 @@ build_min_array_type (tree elt_type, tree index_type) build_cplus_array_type. */ static void -set_array_type_canon (tree t, tree elt_type, tree index_type) +set_array_type_canon (tree t, tree elt_type, tree index_type, bool dep) { /* Set the canonical type for this new node. */ if (TYPE_STRUCTURAL_EQUALITY_P (elt_type) @@ -1009,30 +1009,33 @@ set_array_type_canon (tree t, tree elt_type, tree index_type) TYPE_CANONICAL (t) = build_cplus_array_type (TYPE_CANONICAL (elt_type), index_type - ? TYPE_CANONICAL (index_type) : index_type); + ? TYPE_CANONICAL (index_type) : index_type, + dep); else TYPE_CANONICAL (t) = t; } /* Like build_array_type, but handle special C++ semantics: an array of a variant element type is a variant of the array of the main variant of - the element type. */ + the element type. IS_DEPENDENT is -ve if we should determine the + dependency. Otherwise its bool value indicates dependency. */ tree -build_cplus_array_type (tree elt_type, tree index_type) +build_cplus_array_type (tree elt_type, tree index_type, int dependent) { tree t; if (elt_type == error_mark_node || index_type == error_mark_node) return error_mark_node; - bool dependent = (uses_template_parms (elt_type) - || (index_type && uses_template_parms (index_type))); + if (dependent < 0) + dependent = (uses_template_parms (elt_type) + || (index_type && uses_template_parms (index_type))); if (elt_type != TYPE_MAIN_VARIANT (elt_type)) /* Start with an array of the TYPE_MAIN_VARIANT. */ t = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type), - index_type); + index_type, dependent); else if (dependent) { /* Since type_hash_canon calls layout_type, we need to use our own @@ -1062,7 +1065,11 @@ build_cplus_array_type (tree elt_type, tree index_type) *e = t; /* Set the canonical type for this new node. */ - set_array_type_canon (t, elt_type, index_type); + set_array_type_canon (t, elt_type, index_type, dependent); + + /* Mark it as dependent now, this saves time later. */ + TYPE_DEPENDENT_P_VALID (t) = true; + TYPE_DEPENDENT_P (t) = true; } } else @@ -1083,7 +1090,7 @@ build_cplus_array_type (tree elt_type, tree index_type) if (!t) { t = build_min_array_type (elt_type, index_type); - set_array_type_canon (t, elt_type, index_type); + set_array_type_canon (t, elt_type, index_type, dependent); if (!dependent) { layout_type (t); @@ -1319,7 +1326,8 @@ cp_build_qualified_type_real (tree type, if (!t) { - t = build_cplus_array_type (element_type, TYPE_DOMAIN (type)); + t = build_cplus_array_type (element_type, TYPE_DOMAIN (type), + TYPE_DEPENDENT_P (type)); /* Keep the typedef name. */ if (TYPE_NAME (t) != TYPE_NAME (type)) @@ -1555,7 +1563,7 @@ strip_typedefs (tree t, bool *remove_attributes, unsigned int flags) case ARRAY_TYPE: type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags); t0 = strip_typedefs (TYPE_DOMAIN (t), remove_attributes, flags); - result = build_cplus_array_type (type, t0); + result = build_cplus_array_type (type, t0, TYPE_DEPENDENT_P (t)); break; case FUNCTION_TYPE: case METHOD_TYPE: