From patchwork Tue Jun 12 10:01:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 928218 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-479526-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="d2f8XZGO"; 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 414lmK0M9xz9s0W for ; Tue, 12 Jun 2018 20:02:08 +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:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=dpAnINPtTu09dCdO bRD21IKzgqKwkwPbCVcqI/nKsqAJQCBxrRRbtzy57rWqSIdechpg3SuY9DeK1a94 927WWmj7aBlpLtcJW3qJTiERC7i/vftLmTCagJIctXmDqc599amC2PQUwVCbxJBF vqevaOB3qobY31+4E1T6aXJ1AQE= 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:mime-version:content-type :content-transfer-encoding; s=default; bh=EV2f+DFGIVMKqZTzes+uNb TgYEU=; b=d2f8XZGOzU0LoQHGY/pNI7r2KP4PJzOPlWncnkd4kQzYY5nEDk4tr8 lxS+pfjj++4o6VaZmbpMACwwFPK34qBQsjTJRYuM8EHXmuJ7jk9MqnfWCbaRwyUh H72+YH1VGEcsJRavXaMKpvVkheC4A75v4uyKOv2l/Je2kKVrS6JIw= Received: (qmail 118272 invoked by alias); 12 Jun 2018 10:01:54 -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 118123 invoked by uid 89); 12 Jun 2018 10:01:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 12 Jun 2018 10:01:50 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 7825581399 for ; Tue, 12 Jun 2018 12:01:48 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Jd4CWXhvXI-Y for ; Tue, 12 Jun 2018 12:01:48 +0200 (CEST) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 5513781385 for ; Tue, 12 Jun 2018 12:01:48 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Plug loophole in warn_on_field_placement Date: Tue, 12 Jun 2018 12:01:46 +0200 Message-ID: <2202697.YcyMOAgK1I@polaris> MIME-Version: 1.0 Only the first component of a group of reordered bitfields was warned about. Tested on x86-64/Linux, applied on mainline and 8 branch. 2018-06-12 Eric Botcazou * gcc-interface/decl.c (warn_on_field_placement): Use specific wording for discriminants. (warn_on_list_placement): New static function. (components_to_record): Use it to warn on multiple fields in list. Index: gcc-interface/decl.c =================================================================== --- gcc-interface/decl.c (revision 261479) +++ gcc-interface/decl.c (working copy) @@ -7296,31 +7296,44 @@ warn_on_field_placement (tree gnu_field, if (!Comes_From_Source (gnat_record_type)) return; + Entity_Id gnat_field + = gnu_field_to_gnat (gnu_field, gnat_component_list, gnat_record_type); + gcc_assert (Present (gnat_field)); + const char *msg1 = in_variant ? "?variant layout may cause performance issues" : "?record layout may cause performance issues"; const char *msg2 - = field_has_self_size (gnu_field) - ? "?component & whose length depends on a discriminant" - : field_has_variable_size (gnu_field) - ? "?component & whose length is not fixed" - : "?component & whose length is not multiple of a byte"; + = Ekind (gnat_field) == E_Discriminant + ? "?discriminant & whose length is not multiple of a byte" + : field_has_self_size (gnu_field) + ? "?component & whose length depends on a discriminant" + : field_has_variable_size (gnu_field) + ? "?component & whose length is not fixed" + : "?component & whose length is not multiple of a byte"; const char *msg3 = do_reorder ? "?comes too early and was moved down" : "?comes too early and ought to be moved down"; - Entity_Id gnat_field - = gnu_field_to_gnat (gnu_field, gnat_component_list, gnat_record_type); - - gcc_assert (Present (gnat_field)); - post_error (msg1, gnat_field); post_error_ne (msg2, gnat_field, gnat_field); post_error (msg3, gnat_field); } +/* Likewise but for every field present on GNU_FIELD_LIST. */ + +static void +warn_on_list_placement (tree gnu_field_list, Node_Id gnat_component_list, + Entity_Id gnat_record_type, bool in_variant, + bool do_reorder) +{ + for (tree gnu_tmp = gnu_field_list; gnu_tmp; gnu_tmp = DECL_CHAIN (gnu_tmp)) + warn_on_field_placement (gnu_tmp, gnat_component_list, gnat_record_type, + in_variant, do_reorder); +} + /* Structure holding information for a given variant. */ typedef struct vinfo { @@ -7895,11 +7908,18 @@ components_to_record (Node_Id gnat_compo if (tmp_bitp_size != 0) { if (w_reorder && tmp_last_reorder_field_type < 2) - warn_on_field_placement (gnu_tmp_bitp_list - ? gnu_tmp_bitp_list : gnu_last, - gnat_component_list, - gnat_record_type, in_variant, - do_reorder); + { + if (gnu_tmp_bitp_list) + warn_on_list_placement (gnu_tmp_bitp_list, + gnat_component_list, + gnat_record_type, in_variant, + do_reorder); + else + warn_on_field_placement (gnu_last, + gnat_component_list, + gnat_record_type, in_variant, + do_reorder); + } if (do_reorder) gnu_bitp_list = chainon (gnu_tmp_bitp_list, gnu_bitp_list); @@ -7953,10 +7973,16 @@ components_to_record (Node_Id gnat_compo if (last_reorder_field_type == 2 && tmp_bitp_size != 0 && tmp_last_reorder_field_type < 2) - warn_on_field_placement (gnu_tmp_bitp_list - ? gnu_tmp_bitp_list : gnu_field_list, - gnat_component_list, gnat_record_type, - in_variant, do_reorder); + { + if (gnu_tmp_bitp_list) + warn_on_list_placement (gnu_tmp_bitp_list, + gnat_component_list, gnat_record_type, + in_variant, do_reorder); + else + warn_on_field_placement (gnu_field_list, + gnat_component_list, gnat_record_type, + in_variant, do_reorder); + } } if (do_reorder)