From patchwork Fri Aug 24 13:13:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 961847 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-484365-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=hotmail.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="YnDsIVr1"; 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 41xhYL6Snxz9s4V for ; Fri, 24 Aug 2018 23:13:25 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:content-type:mime-version; q=dns; s= default; b=xY50i1BwPpNOR6hTdUu8Pi+rvP0NVguHsTWQxRMGqGLQzx8FMLXPV my5ymYqRG1Eg8wjnZG7S9YYceJwqAG/ech/lXMOzz2BNWAdCXl6cRtfb16T0iocZ M02ZKKspxbZcqDCK1g04kZpVD/V2fnOGRKNf2eKxCB0PpS2J+uH+DY= 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:from :to:subject:date:message-id:content-type:mime-version; s= default; bh=wBVa7s/9bcFKAJuduSinnhPGq0U=; b=YnDsIVr1B1HpS1HRVZV2 /07HFW3Hgce3jZSmt2RHgSr3LbDNwA7sV8zDQVN9TMVpv7/EFycWXof4WJaKk7o/ MBVvxUhFpdLa8siAQE++q8fQSNQHTbTiKrWoVetBNvUKkAtxHEe/txNspXZI01W5 UmWPzopwJWm9oncecgQPdgM= Received: (qmail 121809 invoked by alias); 24 Aug 2018 13:13:18 -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 120239 invoked by uid 89); 24 Aug 2018 13:13:17 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.3 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=TYPE_DECL, type_decl, simplifications, decl_chain X-HELO: EUR03-AM5-obe.outbound.protection.outlook.com Received: from mail-oln040092070053.outbound.protection.outlook.com (HELO EUR03-AM5-obe.outbound.protection.outlook.com) (40.92.70.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 24 Aug 2018 13:13:15 +0000 Received: from AM5EUR03FT023.eop-EUR03.prod.protection.outlook.com (10.152.16.52) by AM5EUR03HT165.eop-EUR03.prod.protection.outlook.com (10.152.17.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.1080.9; Fri, 24 Aug 2018 13:13:12 +0000 Received: from AM5PR0701MB2657.eurprd07.prod.outlook.com (10.152.16.53) by AM5EUR03FT023.mail.protection.outlook.com (10.152.16.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.20.1080.9 via Frontend Transport; Fri, 24 Aug 2018 13:13:12 +0000 Received: from AM5PR0701MB2657.eurprd07.prod.outlook.com ([fe80::24cf:823c:758c:41b7]) by AM5PR0701MB2657.eurprd07.prod.outlook.com ([fe80::24cf:823c:758c:41b7%7]) with mapi id 15.20.1101.007; Fri, 24 Aug 2018 13:13:12 +0000 From: Bernd Edlinger To: "gcc-patches@gcc.gnu.org" , Richard Biener , Joseph Myers , Nathan Sidwell , Jason Merrill Subject: [PATCH] Use complete_array_type on flexible array member initializers Date: Fri, 24 Aug 2018 13:13:12 +0000 Message-ID: received-spf: None (protection.outlook.com: hotmail.de does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=bernd.edlinger@hotmail.de; MIME-Version: 1.0 Hi! This patch prevents init values of STRING_CST and braced array initializers to reach the middle-end with incomplete type. This will allow further simplifications in the middle-end, and address existing issues with STRING_CST in a correct way. Bootstrapped and reg-tested on x86_64-pc-linux-gnu. Is it OK for trunk? Thanks Bernd. gcc: 2018-08-24 Bernd Edlinger * varasm.c (output_constructor_regular_field): Check TYPE_SIZE_UNIT of the init value. c-family: 2018-08-24 Bernd Edlinger * c-common.c (complete_flexible_array_elts): New helper function. * c-common.h (complete_flexible_array_elts): Declare. c: 2018-08-24 Bernd Edlinger * c-decl.c (finish_decl): Call complete_flexible_array_elts. cp: 2018-08-24 Bernd Edlinger * decl.c (check_initializer): Call complete_flexible_array_elts. diff -Npur gcc/c/c-decl.c gcc/c/c-decl.c --- gcc/c/c-decl.c 2018-08-21 08:17:41.000000000 +0200 +++ gcc/c/c-decl.c 2018-08-24 12:06:21.374892294 +0200 @@ -5035,6 +5035,8 @@ finish_decl (tree decl, location_t init_ if (init && TREE_CODE (init) == CONSTRUCTOR) add_flexible_array_elts_to_size (decl, init); + complete_flexible_array_elts (DECL_INITIAL (decl)); + if (DECL_SIZE (decl) == NULL_TREE && TREE_TYPE (decl) != error_mark_node && COMPLETE_TYPE_P (TREE_TYPE (decl))) layout_decl (decl, 0); diff -Npur gcc/c-family/c-common.c gcc/c-family/c-common.c --- gcc/c-family/c-common.c 2018-08-17 05:02:11.000000000 +0200 +++ gcc/c-family/c-common.c 2018-08-24 12:45:56.559011703 +0200 @@ -6427,6 +6427,28 @@ complete_array_type (tree *ptype, tree i return failure; } +/* INIT is an constructor of a structure with a flexible array member. + Complete the flexible array member with a domain based on it's value. */ +void +complete_flexible_array_elts (tree init) +{ + tree elt, type; + + if (init == NULL_TREE || TREE_CODE (init) != CONSTRUCTOR) + return; + + if (vec_safe_is_empty (CONSTRUCTOR_ELTS (init))) + return; + + elt = CONSTRUCTOR_ELTS (init)->last ().value; + type = TREE_TYPE (elt); + if (TREE_CODE (type) == ARRAY_TYPE + && TYPE_SIZE (type) == NULL_TREE) + complete_array_type (&TREE_TYPE (elt), elt, false); + else + complete_flexible_array_elts (elt); +} + /* Like c_mark_addressable but don't check register qualifier. */ void c_common_mark_addressable_vec (tree t) diff -Npur gcc/c-family/c-common.h gcc/c-family/c-common.h --- gcc/c-family/c-common.h 2018-08-17 05:02:11.000000000 +0200 +++ gcc/c-family/c-common.h 2018-08-24 12:06:21.375892280 +0200 @@ -1038,6 +1038,7 @@ extern tree fold_offsetof (tree, tree = tree_code ctx = ERROR_MARK); extern int complete_array_type (tree *, tree, bool); +extern void complete_flexible_array_elts (tree); extern tree builtin_type_for_size (int, bool); diff -Npur gcc/cp/decl.c gcc/cp/decl.c --- gcc/cp/decl.c 2018-08-22 22:35:38.000000000 +0200 +++ gcc/cp/decl.c 2018-08-24 12:06:21.377892252 +0200 @@ -6528,6 +6528,8 @@ check_initializer (tree decl, tree init, init_code = store_init_value (decl, init, cleanups, flags); + complete_flexible_array_elts (DECL_INITIAL (decl)); + if (pedantic && TREE_CODE (type) == ARRAY_TYPE && DECL_INITIAL (decl) && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST diff -Npur gcc/varasm.c gcc/varasm.c --- gcc/varasm.c 2018-08-16 17:28:11.000000000 +0200 +++ gcc/varasm.c 2018-08-24 12:06:21.378892238 +0200 @@ -5161,6 +5161,8 @@ output_constructor_regular_field (oc_loc on the chain is a TYPE_DECL of the enclosing struct. */ const_tree next = DECL_CHAIN (local->field); gcc_assert (!fieldsize || !next || TREE_CODE (next) != FIELD_DECL); + tree size = TYPE_SIZE_UNIT (TREE_TYPE (local->val)); + gcc_checking_assert (compare_tree_int (size, fieldsize) == 0); } else fieldsize = tree_to_uhwi (DECL_SIZE_UNIT (local->field));