From patchwork Sat May 9 20:13:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1286855 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=adacore.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=adacore-com.20150623.gappssmtp.com header.i=@adacore-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=fon1Y3RA; 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 49KJMs15yBz9sNH for ; Sun, 10 May 2020 06:15:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 92C713851C3B; Sat, 9 May 2020 20:14:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id 833E03851C3B for ; Sat, 9 May 2020 20:14:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 833E03851C3B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=botcazou@adacore.com Received: by mail-wm1-x336.google.com with SMTP id m12so8784316wmc.0 for ; Sat, 09 May 2020 13:14:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=YoLK1d3qwixtsecESBJa/T9ThcEKjXNMJayFSGAzOmE=; b=fon1Y3RAqxVIl0GdMyczvnDmkycfqIto8m9+ASTpV+D/YexVhqgFIowjBzHDiyy63D VoykRksKk5+Y7uld9g/blabJkEEOnpA/J7xbrftqamFwVX2zCPe2zzq78Nohpym1LMn7 AQFb5iFmlZPosJnsAyTV9cgRPiwZ8UaKNPTy2qmIRtt+mY695NaNS7mJLTkYdI0E3IQf rsuFzrb41ZVScbVxSbRjwOFMSDbRkxr37iFvG3D8mXsnflef5XeeB2404F7Cej+pIHaA 38xQiN4EU5fVoeJBflO3LbotFtC3SdQZvNa3c0tZhqH9+ZOD8MRGqDPUl5HHr35A/L0X w4oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=YoLK1d3qwixtsecESBJa/T9ThcEKjXNMJayFSGAzOmE=; b=huYPbMxXe8X9ZVhoT8HaeTUhYiwzQ5N7Wd3WPawIkmpOm9hcBi8q/eHGKSbChfNAVx KkFF5Oizxpl9ubtTPLOyOndSnwgrEnR5iaQP6MZvyyvJwFXN49rOvfzR07thnlc7AEZT czV7N38B7qMunX8Gu3XyrmOaEOthkSe8vL3+GQLaa5u1UCuPy2GFGvNV+Ee1tCjXpW1Q nbFHd3MO2AATm4B+6FqLhOuDiWpLbrUYldhi5iD+69ZZuyeU1HhvqvuyN2srq9cmqmye 9owHrS9JBL1FE5ZJ4I2/hwo/BmW3Ny2zrobVW0LdcR+Xj8p6n4xcdD/rwvluSSfOv2n1 b+7w== X-Gm-Message-State: AGi0Pub+Ra7oeIum7ZuFqRM4lV3AuK2VrhNOxYNALc6lisGQuMbajGi3 gu7qE1HTbyqrRnkcPzzJoxlibQrJtxtkng== X-Google-Smtp-Source: APiQypIsouDKU3BpQJVgreNb2lmVxR5+Jr2Td/FmGQHaGq4wlqe9ouQDFrxbff+YjOBQwXI7LzRfyA== X-Received: by 2002:a1c:305:: with SMTP id 5mr7932126wmd.60.1589055294859; Sat, 09 May 2020 13:14:54 -0700 (PDT) Received: from polaris.localnet ([2a01:e0a:41b:9230:1a03:73ff:fe45:373a]) by smtp.gmail.com with ESMTPSA id d15sm9347980wrs.38.2020.05.09.13.14.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 09 May 2020 13:14:53 -0700 (PDT) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Small housekeeping work in gigi Date: Sat, 09 May 2020 22:13:18 +0200 Message-ID: <28895531.4LPaRbbggl@polaris> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, 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" No functional changes. 2020-05-09 Eric Botcazou * gcc-interface/gigi.h (change_qualified_type): Move around. (maybe_vector_array): Likewise. (maybe_padded_object): New static line function. * gcc-interface/trans.c (Attribute_to_gnu) : Remove useless code. : Remove obsolete code. (Call_to_gn): Likewise. Use maybe_padded_object to remove padding. (gnat_to_gnu): Likewise. : Do not add a useless null character at the end. : Likewise and remove obsolete code. (add_decl_expr): Likewise. (maybe_implicit_deref): Likewise. * gcc-interface/utils.c (maybe_unconstrained_array): Likewise. * gcc-interface/utils2.c (gnat_invariant_expr): Likewise. diff --git a/gcc/ada/gcc-interface/gigi.h b/gcc/ada/gcc-interface/gigi.h index edfcbd5a782..c4e9d77e771 100644 --- a/gcc/ada/gcc-interface/gigi.h +++ b/gcc/ada/gcc-interface/gigi.h @@ -1065,20 +1065,6 @@ extern void enumerate_modes (void (*f) (const char *, int, int, int, int, int, #define gigi_checking_assert(EXPR) \ gcc_checking_assert ((EXPR) || type_annotate_only) -/* If EXP's type is a VECTOR_TYPE, return EXP converted to the associated - TYPE_REPRESENTATIVE_ARRAY. */ - -static inline tree -maybe_vector_array (tree exp) -{ - tree etype = TREE_TYPE (exp); - - if (VECTOR_TYPE_P (etype)) - exp = convert (TYPE_REPRESENTATIVE_ARRAY (etype), exp); - - return exp; -} - /* Return the smallest power of 2 larger than X. */ static inline unsigned HOST_WIDE_INT @@ -1144,6 +1130,33 @@ gnat_signed_type_for (tree type_node) return gnat_signed_or_unsigned_type_for (0, type_node); } +/* Like build_qualified_type, but TYPE_QUALS is added to the existing + qualifiers on TYPE. */ + +static inline tree +change_qualified_type (tree type, int type_quals) +{ + /* Qualifiers must be put on the associated array type. */ + if (TREE_CODE (type) == UNCONSTRAINED_ARRAY_TYPE) + return type; + + return build_qualified_type (type, TYPE_QUALS (type) | type_quals); +} + +/* If EXPR's type is a VECTOR_TYPE, return EXPR converted to the associated + TYPE_REPRESENTATIVE_ARRAY. */ + +static inline tree +maybe_vector_array (tree expr) +{ + tree type = TREE_TYPE (expr); + + if (VECTOR_TYPE_P (type)) + expr = convert (TYPE_REPRESENTATIVE_ARRAY (type), expr); + + return expr; +} + /* Adjust the character type TYPE if need be. */ static inline tree @@ -1186,15 +1199,15 @@ maybe_debug_type (tree type) return type; } -/* Like build_qualified_type, but TYPE_QUALS is added to the existing - qualifiers on TYPE. */ +/* Remove the padding around EXPR if need be. */ static inline tree -change_qualified_type (tree type, int type_quals) +maybe_padded_object (tree expr) { - /* Qualifiers must be put on the associated array type. */ - if (TREE_CODE (type) == UNCONSTRAINED_ARRAY_TYPE) - return type; + tree type = TREE_TYPE (expr); - return build_qualified_type (type, TYPE_QUALS (type) | type_quals); + if (TYPE_IS_PADDING_P (type)) + expr = convert (TREE_TYPE (TYPE_FIELDS (type)), expr); + + return expr; } diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c index 802adc92db1..20529e157e0 100644 --- a/gcc/ada/gcc-interface/trans.c +++ b/gcc/ada/gcc-interface/trans.c @@ -2893,10 +2893,6 @@ Attribute_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, int attribute) break; case Attr_Component_Size: - if (TREE_CODE (gnu_prefix) == COMPONENT_REF - && TYPE_IS_PADDING_P (TREE_TYPE (TREE_OPERAND (gnu_prefix, 0)))) - gnu_prefix = TREE_OPERAND (gnu_prefix, 0); - gnu_prefix = maybe_implicit_deref (gnu_prefix); gnu_type = TREE_TYPE (gnu_prefix); @@ -2934,7 +2930,6 @@ Attribute_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, int attribute) = build_unary_op (INDIRECT_REF, NULL_TREE, convert (build_pointer_type (gnu_result_type), integer_zero_node)); - TREE_PRIVATE (gnu_result) = 1; break; case Attr_Mechanism_Code: @@ -5468,8 +5463,6 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, /* Otherwise the parameter is passed by copy. */ else { - tree gnu_size; - if (!in_param) gnu_name_list = tree_cons (NULL_TREE, gnu_name, gnu_name_list); @@ -5490,25 +5483,9 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, gnu_actual = convert (gnu_formal_type, gnu_actual); - /* If this is 'Null_Parameter, pass a zero even though we are - dereferencing it. */ - if (TREE_CODE (gnu_actual) == INDIRECT_REF - && TREE_PRIVATE (gnu_actual) - && (gnu_size = TYPE_SIZE (TREE_TYPE (gnu_actual))) - && TREE_CODE (gnu_size) == INTEGER_CST - && compare_tree_int (gnu_size, BITS_PER_WORD) <= 0) - { - tree type_for_size - = gnat_type_for_size (TREE_INT_CST_LOW (gnu_size), 1); - gnu_actual - = unchecked_convert (DECL_ARG_TYPE (gnu_formal), - build_int_cst (type_for_size, 0), - false); - } - /* If this is a front-end built-in function, there is no need to convert to the type used to pass the argument. */ - else if (!frontend_builtin) + if (!frontend_builtin) gnu_actual = convert (DECL_ARG_TYPE (gnu_formal), gnu_actual); } @@ -5630,11 +5607,8 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, tree gnu_actual = maybe_unconstrained_array (TREE_VALUE (gnu_name_list)); - /* If the result is a padded type, remove the padding. */ - if (TYPE_IS_PADDING_P (TREE_TYPE (gnu_result))) - gnu_result - = convert (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (gnu_result))), - gnu_result); + /* If the result is padded, remove the padding. */ + gnu_result = maybe_padded_object (gnu_result); /* If the actual is a type conversion, the real target object is denoted by the inner Expression and we need to convert the @@ -6959,19 +6933,15 @@ gnat_to_gnu (Node_Id gnat_node) int i; char *string; if (length >= ALLOCA_THRESHOLD) - string = XNEWVEC (char, length + 1); + string = XNEWVEC (char, length); else - string = (char *) alloca (length + 1); + string = (char *) alloca (length); /* Build the string with the characters in the literal. Note that Ada strings are 1-origin. */ for (i = 0; i < length; i++) string[i] = Get_String_Char (gnat_string, i + 1); - /* Put a null at the end of the string in case it's in a context - where GCC will want to treat it as a C string. */ - string[i] = 0; - gnu_result = build_string (length, string); /* Strings in GCC don't normally have types, but we want @@ -7199,6 +7169,7 @@ gnat_to_gnu (Node_Id gnat_node) Node_Id *gnat_expr_array; gnu_array_object = maybe_implicit_deref (gnu_array_object); + gnu_array_object = maybe_unconstrained_array (gnu_array_object); /* Convert vector inputs to their representative array type, to fit what the code below expects. */ @@ -7209,14 +7180,6 @@ gnat_to_gnu (Node_Id gnat_node) gnu_array_object = maybe_vector_array (gnu_array_object); } - gnu_array_object = maybe_unconstrained_array (gnu_array_object); - - /* If we got a padded type, remove it too. */ - if (TYPE_IS_PADDING_P (TREE_TYPE (gnu_array_object))) - gnu_array_object - = convert (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (gnu_array_object))), - gnu_array_object); - /* The failure of this assertion will very likely come from a missing expansion for a packed array access. */ gcc_assert (TREE_CODE (TREE_TYPE (gnu_array_object)) == ARRAY_TYPE); @@ -8855,9 +8818,7 @@ gnat_to_gnu (Node_Id gnat_node) && TREE_CODE (TREE_TYPE (gnu_result)) == RECORD_TYPE)) { /* Remove any padding. */ - if (TYPE_IS_PADDING_P (TREE_TYPE (gnu_result))) - gnu_result = convert (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (gnu_result))), - gnu_result); + gnu_result = maybe_padded_object (gnu_result); } else if (gnu_result == error_mark_node || gnu_result_type == void_type_node) @@ -9083,10 +9044,8 @@ add_decl_expr (tree gnu_decl, Node_Id gnat_node) DECL_READONLY_ONCE_ELAB (gnu_decl) = 1; } - /* If GNU_DECL has a padded type, convert it to the unpadded - type so the assignment is done properly. */ - if (TYPE_IS_PADDING_P (type)) - gnu_decl = convert (TREE_TYPE (TYPE_FIELDS (type)), gnu_decl); + /* Remove any padding so the assignment is done properly. */ + gnu_decl = maybe_padded_object (gnu_decl); gnu_stmt = build_binary_op (INIT_EXPR, NULL_TREE, gnu_decl, gnu_init); add_stmt_with_node (gnu_stmt, gnat_node); @@ -10806,14 +10765,13 @@ adjust_for_implicit_deref (Node_Id exp) static tree maybe_implicit_deref (tree exp) { - /* If the type is a pointer, dereference it. */ + /* If the object is a pointer, dereference it. */ if (POINTER_TYPE_P (TREE_TYPE (exp)) || TYPE_IS_FAT_POINTER_P (TREE_TYPE (exp))) exp = build_unary_op (INDIRECT_REF, NULL_TREE, exp); - /* If we got a padded type, remove it too. */ - if (TYPE_IS_PADDING_P (TREE_TYPE (exp))) - exp = convert (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (exp))), exp); + /* If the object is padded, remove the padding. */ + exp = maybe_padded_object (exp); return exp; } diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index 9d0014820a5..9dd08e2f02c 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -5257,11 +5257,9 @@ maybe_unconstrained_array (tree exp) exp = build_component_ref (exp, DECL_CHAIN (TYPE_FIELDS (type)), false); - type = TREE_TYPE (exp); - /* If the array type is padded, convert to the unpadded type. */ - if (TYPE_IS_PADDING_P (type)) - exp = convert (TREE_TYPE (TYPE_FIELDS (type)), exp); + /* If the array is padded, remove the padding. */ + exp = maybe_padded_object (exp); } break; diff --git a/gcc/ada/gcc-interface/utils2.c b/gcc/ada/gcc-interface/utils2.c index 30d08f50896..2ff865434b9 100644 --- a/gcc/ada/gcc-interface/utils2.c +++ b/gcc/ada/gcc-interface/utils2.c @@ -2934,8 +2934,7 @@ gnat_invariant_expr (tree expr) { expr = DECL_INITIAL (expr); /* Look into CONSTRUCTORs built to initialize padded types. */ - if (TYPE_IS_PADDING_P (TREE_TYPE (expr))) - expr = convert (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (expr))), expr); + expr = maybe_padded_object (expr); expr = remove_conversions (expr, false); }