From patchwork Fri Oct 20 18:29:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 828768 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-464652-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="uybLdNKg"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yJZ8c6Tb5z9t3l for ; Sat, 21 Oct 2017 05:29:51 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=C5EDadhmHrEl4fRG5gNfg0P4lRCCbJICPn+bwbYNxF3rwOhXHR hlAwaruDD5cMwgxyE/HFkKJGKnxohw320fZpOCedUj36fIH7v3dbPn2gutO7Sw4x Gw5sMqiv8uUIXqZiSGv6Nt3CFwefgKwYideAoksa8tSvhYcstk+86jWSY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=0wWsqeA6QxuvUm0tzm2X6L1q7mU=; b=uybLdNKgUU6mofe0nX9E G+OXtuDAZB30W4ciY+pesiHvkX4jq2pmm3b0DinsD0/AFLLyPv4HFgREHxlGAghl P3G9poVkbq2Gyzon3nDZwl8ozh0HafdrozGVNdjKiZlSMgCycTg8WoiBYSXrzojz 1c1xjmk9kOwVDYB9aXL8cc8= Received: (qmail 98732 invoked by alias); 20 Oct 2017 18:29:43 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 98721 invoked by uid 89); 20 Oct 2017 18:29:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.4 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, SUBJ_ALL_CAPS autolearn=ham version=3.3.2 spammy=POD, claims X-HELO: mail-pf0-f178.google.com Received: from mail-pf0-f178.google.com (HELO mail-pf0-f178.google.com) (209.85.192.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 20 Oct 2017 18:29:41 +0000 Received: by mail-pf0-f178.google.com with SMTP id p87so12198842pfj.3 for ; Fri, 20 Oct 2017 11:29:41 -0700 (PDT) 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=fVlfmHALtbQ6W8apC4dgfV41heqNY7V53+LetYbiVWM=; b=cjzx6R7R53NPfPecrGFA4ytsd1cKOL4I6YAtEkGWt6orcxrXqY++e4h+lSIY2wMzRc hyIREAaD4KwLgx3iHqM/7vkNoYQZNO0HefNadq0EUpmsmTKK/4eOw2o9o5Vm3kQNi22l m2DZrsNSoJPhGLYR1Vou5ggKrxzmj7Y+UDi4AGrhnkDtOvJhgGP4c/f9+otkMjItJF3x TTNuhmdkyrMEbuZS9fr95hAXkkCkkr8eZomIwg9Od4/R2/eg2jJSWkPKENuAIB5A8T9o i80jOxtTALhG1ZCt3FWzQIsj2THhk55Efq7jT1+yvJ9/n4P/9P/gOiaWVn4qe6Qu1RFs Dzuw== X-Gm-Message-State: AMCzsaU1LHymzUYxyPmG2kkqm0E+GGETEO7YNo2xv3Dy0oG3GyzBVZCc MB1IPcJfTR/kTrIFyENza/s= X-Google-Smtp-Source: ABhQp+QbWLUtqD4i63ud+OHw5BEmxH2JHMYF5da9SJZCMeDW149ouajIRKstQKp996l1NkKWLk9NoQ== X-Received: by 10.159.207.129 with SMTP id z1mr4909750plo.174.1508524180143; Fri, 20 Oct 2017 11:29:40 -0700 (PDT) Received: from ?IPv6:2620:10d:c082:1055:31e1:4d57:79ff:da5a? ([2620:10d:c090:200::4:36f8]) by smtp.googlemail.com with ESMTPSA id u131sm2406431pgc.89.2017.10.20.11.29.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Oct 2017 11:29:39 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] AS_BASETYPE Message-ID: <5b067290-e469-fc55-b20f-6e9ea412d697@acm.org> Date: Fri, 20 Oct 2017 14:29:37 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 We have a special 'as-base' instance of each class, for use in derived layouts. for some classes this is just the regular class itself, but for others it's a new instance. This instance is not in the class-members, and that's now biting me on the modules branch (i'd been punting on it before). This patch does a few cleanup, which make sense on trunk. We do seem to be creating this instance in more cases than necessary -- looking at (CLASSTYPE_NON_LAYOUT_POD_P (t) || CLASSTYPE_EMPTY_P (t)). The former claims to 'not be the language non-pod'. but it actually is if you're in c++98-land. I /think/ we only need a special instance for a) empty classes b) classes with virtual bases c) non-pod classes with tail padding (which could be overlaid in derivation). But that's a cleanup for another day. nathan 2017-10-20 Nathan Sidwell * class.c (layout_class_type): Cleanup as-base creation, determine mode here. (finish_struct_1): ... not here. Index: class.c =================================================================== --- class.c (revision 253948) +++ class.c (working copy) @@ -5992,8 +5992,6 @@ layout_class_type (tree t, tree *virtual bool last_field_was_bitfield = false; /* The location at which the next field should be inserted. */ tree *next_field; - /* T, as a base class. */ - tree base_t; /* Keep track of the first non-static data member. */ non_static_data_members = TYPE_FIELDS (t); @@ -6218,15 +6216,11 @@ layout_class_type (tree t, tree *virtual that the type is laid out they are no longer important. */ remove_zero_width_bit_fields (t); - /* Create the version of T used for virtual bases. We do not use - make_class_type for this version; this is an artificial type. For - a POD type, we just reuse T. */ if (CLASSTYPE_NON_LAYOUT_POD_P (t) || CLASSTYPE_EMPTY_P (t)) { - base_t = make_node (TREE_CODE (t)); - - /* Set the size and alignment for the new type. */ - tree eoc; + /* T needs a different layout as a base (eliding virtual bases + or whatever). Create that version. */ + tree base_t = make_node (TREE_CODE (t)); /* If the ABI version is not at least two, and the last field was a bit-field, RLI may not be on a byte @@ -6235,7 +6229,7 @@ layout_class_type (tree t, tree *virtual indicates the total number of bits used. Therefore, rli_size_so_far, rather than rli_size_unit_so_far, is used to compute TYPE_SIZE_UNIT. */ - eoc = end_of_class (t, /*include_virtuals_p=*/0); + tree eoc = end_of_class (t, /*include_virtuals_p=*/0); TYPE_SIZE_UNIT (base_t) = size_binop (MAX_EXPR, fold_convert (sizetype, @@ -6252,7 +6246,8 @@ layout_class_type (tree t, tree *virtual SET_TYPE_ALIGN (base_t, rli->record_align); TYPE_USER_ALIGN (base_t) = TYPE_USER_ALIGN (t); - /* Copy the fields from T. */ + /* Copy the non-static data members of T. This will include its + direct non-virtual bases & vtable. */ next_field = &TYPE_FIELDS (base_t); for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field)) if (TREE_CODE (field) == FIELD_DECL) @@ -6263,9 +6258,14 @@ layout_class_type (tree t, tree *virtual } *next_field = NULL_TREE; + /* We use the base type for trivial assignments, and hence it + needs a mode. */ + compute_record_mode (base_t); + + TYPE_CONTEXT (base_t) = t; + /* Record the base version of the type. */ CLASSTYPE_AS_BASE (t) = base_t; - TYPE_CONTEXT (base_t) = t; } else CLASSTYPE_AS_BASE (t) = t; @@ -6822,11 +6822,6 @@ finish_struct_1 (tree t) set_class_bindings (t); - if (CLASSTYPE_AS_BASE (t) != t) - /* We use the base type for trivial assignments, and hence it - needs a mode. */ - compute_record_mode (CLASSTYPE_AS_BASE (t)); - /* With the layout complete, check for flexible array members and zero-length arrays that might overlap other members in the final layout. */