From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31110 invoked by alias); 26 Jan 2016 22:21:36 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 30901 invoked by uid 89); 26 Jan 2016 22:21:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qk0-f176.google.com Received: from mail-qk0-f176.google.com (HELO mail-qk0-f176.google.com) (209.85.220.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 26 Jan 2016 22:21:30 +0000 Received: by mail-qk0-f176.google.com with SMTP id s5so69572839qkd.0 for ; Tue, 26 Jan 2016 14:21:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=YZ60OKZV7ffjurnSDXQysGJ5m3z3JGSB3K5OHlLBK/k=; b=A0u+bnFNxDaPYkTlp6LvzBWQz9iZmjHQSqNfYM3g4/4t4OB3TErXUk/PV43NiK/mhk 1isvXLoRoU7tcPdLPplg6QIJPf2F70VxRBFpWJmZcGFdzEuYKy85bjUnnYsopcuAN6dw 9ZiCp8jxPjj0gebsgAaIGVPpDED9K3Pqy02n3dYVuLkvKWyyG3WcBLSc8jGa0hvatZ+7 p7O9PPqtocNcrwOtZNxlYsObVXb8q1NzNcjQ8yFYGHfb0QiLnPXK1xmNW2/prf4seRP+ oiAPgCobT6HOrla6wLCNtLhS/yQeSCWHbnr3ilXr2gT55pYl8TqxNbJ/0vGdMZs2xbIg oFnw== X-Gm-Message-State: AG10YOShQSfxefKEtq8Bkc18pwEjUkn5z0++ldDaGBXjsH28KKFhonX4bbV1aFWjIT0exxqvN4UowmMostxz3g== MIME-Version: 1.0 X-Received: by 10.55.77.2 with SMTP id a2mr31346815qkb.108.1453846888180; Tue, 26 Jan 2016 14:21:28 -0800 (PST) Received: by 10.55.4.210 with HTTP; Tue, 26 Jan 2016 14:21:27 -0800 (PST) In-Reply-To: <20160126214000.GL3017@tucnak.redhat.com> References: <566F23AE.6070604@redhat.com> <566F2A0B.4010102@redhat.com> <56A7C8AC.8070204@redhat.com> <20160126214000.GL3017@tucnak.redhat.com> Date: Tue, 26 Jan 2016 22:21:00 -0000 Message-ID: Subject: Re: PING^1: [PATCH] Add TYPE_EMPTY_RECORD for C++ empty class From: "H.J. Lu" To: Jakub Jelinek Cc: GCC Patches , Jason Merrill , Richard Biener , Markus Trippelsdorf Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2016-01/txt/msg02051.txt.bz2 On Tue, Jan 26, 2016 at 1:40 PM, Jakub Jelinek wrote: > On Tue, Jan 26, 2016 at 01:21:52PM -0800, H.J. Lu wrote: >> Like this: >> >> /* Returns true if TYPE is POD for the purpose of layout and an empty >> class or an class with empty classes. */ >> >> static bool >> is_empty_record (tree type) >> { >> if (type == error_mark_node) >> return false; >> >> if (!CLASS_TYPE_P (type)) >> return false; >> >> if (CLASSTYPE_NON_LAYOUT_POD_P (type)) >> return false; >> >> gcc_assert (COMPLETE_TYPE_P (type)); >> >> if (CLASSTYPE_EMPTY_P (type)) >> return true; >> >> tree field; >> >> for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) >> if (TREE_CODE (field) == FIELD_DECL >> && !DECL_ARTIFICIAL (field) >> && !is_empty_record (TREE_TYPE (field))) >> return false; >> >> return true; >> } > > So you say that K1 in e.g.: > > struct A1 {}; struct A2 {}; > struct B1 { A1 a; A2 b; }; struct B2 { A1 a; A2 b; }; > struct C1 { B1 a; B2 b; }; struct C2 { B1 a; B2 b; }; > struct D1 { C1 a; C2 b; }; struct D2 { C1 a; C2 b; }; > struct E1 { D1 a; D2 b; }; struct E2 { D1 a; D2 b; }; > struct F1 { E1 a; E2 b; }; struct F2 { E1 a; E2 b; }; > struct G1 { F1 a; F2 b; }; struct G2 { F1 a; F2 b; }; > struct H1 { G1 a; G2 b; }; struct H2 { G1 a; G2 b; }; > struct I1 { H1 a; H2 b; }; struct I2 { H1 a; H2 b; }; > struct J1 { I1 a; I2 b; }; struct J2 { I1 a; I2 b; }; > struct K1 { J1 a; J2 b; }; > int v; > __attribute__((noinline, noclone)) > K1 foo (int a, K1 x, int b) > { > v = a + b; > return x; > } > K1 k, m; > void > bar (void) > { > m = foo (1, k, 2); > } > > is empty class? What does clang do with this? > > Jakub Revised: /* Returns true if TYPE is POD of one-byte or less in size for the purpose of layout and an empty class or an class with empty classes. */ static bool is_empty_record (tree type) { if (type == error_mark_node) return false; if (!CLASS_TYPE_P (type)) return false; if (CLASSTYPE_NON_LAYOUT_POD_P (type)) return false; gcc_assert (COMPLETE_TYPE_P (type)); if (CLASSTYPE_EMPTY_P (type)) return true; if (int_size_in_bytes (type) > 1) return false; tree field; for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) if (TREE_CODE (field) == FIELD_DECL && !DECL_ARTIFICIAL (field) && !is_empty_record (TREE_TYPE (field))) return false; return true; } -- H.J.