From patchwork Tue Sep 14 07:49:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 44977 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E11C03857C69 for ; Tue, 14 Sep 2021 07:49:55 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id 775383858402 for ; Tue, 14 Sep 2021 07:49:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 775383858402 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x32f.google.com with SMTP id e26so8480385wmk.2 for ; Tue, 14 Sep 2021 00:49:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=G6/npxqTUHcn1wP5BD3sbCUPj71RpeMqUX5C+/Vt3PU=; b=UgAGD2l2bfCuWkBRfH5EUUagVAb9u7Ifgm2EY7iiXhfLqYi14eVVxr9vIlglTxlL8D 1CIW27S+gkjLRp/59x1+OId1svDTFTWhcwMu8TryMhr8A3XJxf1BvDMhHfr045YyZ07d fGE4/+ZdnZFiGlxA7+hth9j/Kw/dc5TDfc0c1e2XiMCABmn+QVqxj/OpseWu0WLeTabO GXZ1Krz7wezQkq4X+5KdkWw67Fx89XomVPJ9J/ZdMjxKem+hdRdrHqYVv9tF09AeGhY4 TyNkYFjSuXstX/StccoZJLvDy6BwhqZ9rejLmrCfMujC0Ys30bbedbOvFh3obXVDo4+h z7aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=G6/npxqTUHcn1wP5BD3sbCUPj71RpeMqUX5C+/Vt3PU=; b=N463ILng2pxZa4uP/pgSdPJEG+C9Dmtq4mVph2gk3r8VSGtLt49fpWeMH0KHEqTbHB BsXb4fFn7inVpcePUrrv4623PJutaUIgFLsHuFN4LSJsGdWQkMd+beCuVdFFCXxIFjNH duBqfZ1GYWTHUUQCYygECY2xwv20nRHLzZ9yZbKKP81sWDuyhlwVzMhzMZUYr5vhHM5x sXpY47u94Ijic+FJSfTKByN8Mk10d91JRflMXWt0LozdCQM42hp4XrDhe2wO6ofqnOQw OfBNs6LFNHav6NOReq0kao/qu+zcwgu7BRgPXQ445YSj+EC395ZopEMgCt1UGKmWjSqQ 8c2Q== X-Gm-Message-State: AOAM532qPx7qxaeaBJTM9ZL7bgREQXjSCLgrIpAKBu1msf8127g3Weru jR1W8kN6qKO1HfStIhRtBIl9ANy0ydg76W6A X-Google-Smtp-Source: ABdhPJypGVEJGMlB1b3bb/EUrl9z19eDZifDRkCq5WMREvXkyS5LUlphNQ9ZRlzVx7hq7PcJR62+1Q== X-Received: by 2002:a1c:4b09:: with SMTP id y9mr617100wma.45.1631605778525; Tue, 14 Sep 2021 00:49:38 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:41b:84f0:cf71:f5e0:b050:bede]) by smtp.gmail.com with ESMTPSA id t18sm9216787wrp.97.2021.09.14.00.49.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 00:49:37 -0700 (PDT) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Give more informative error message for by-reference types Date: Tue, 14 Sep 2021 09:49:21 +0200 Message-ID: <2211170.ElGaqSPkdT@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Recent compilers enforce more strictly the RM C.6(18) clause, which says that volatile record types are by-reference types. This changes the typical error message now given in these cases. Tested on x86-64/Linux, applied on the mainline, 11 and 10 branches. 2021-09-14 Eric Botcazou * gcc-interface/decl.c (gnat_to_gnu_entity) : Declare new constant. Adjust error message issued by validate_size in the case of by-reference types. (validate_size): Always use the error strings passed by the caller. diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c index 5cedb740a2e..d37ed3d1b52 100644 --- a/gcc/ada/gcc-interface/decl.c +++ b/gcc/ada/gcc-interface/decl.c @@ -4279,6 +4279,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) handling alignment and possible padding. */ if (is_type && (!gnu_decl || this_made_decl)) { + const bool is_by_ref = Is_By_Reference_Type (gnat_entity); + gcc_assert (!TYPE_IS_DUMMY_P (gnu_type)); /* Process the attributes, if not already done. Note that the type is @@ -4293,15 +4295,18 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) non-constant). */ if (!gnu_size && kind != E_String_Literal_Subtype) { + const char *size_s = "size for %s too small{, minimum allowed is ^}"; + const char *type_s = is_by_ref ? "by-reference type &" : "&"; + if (Known_Esize (gnat_entity)) gnu_size = validate_size (Esize (gnat_entity), gnu_type, gnat_entity, - VAR_DECL, false, false, NULL, NULL); + VAR_DECL, false, false, size_s, type_s); else gnu_size = validate_size (RM_Size (gnat_entity), gnu_type, gnat_entity, TYPE_DECL, false, Has_Size_Clause (gnat_entity), - NULL, NULL); + size_s, type_s); } /* If a size was specified, see if we can make a new type of that size @@ -4614,7 +4619,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) TYPE_ALIGN_OK (gnu_type) = 1; /* Record whether the type is passed by reference. */ - if (Is_By_Reference_Type (gnat_entity) && !VOID_TYPE_P (gnu_type)) + if (is_by_ref && !VOID_TYPE_P (gnu_type)) TYPE_BY_REFERENCE_P (gnu_type) = 1; /* Record whether an alignment clause was specified. */ @@ -9184,7 +9189,7 @@ validate_size (Uint uint_size, tree gnu_type, Entity_Id gnat_object, char buf[128]; const char *s; - if (kind == FIELD_DECL) + if (s1 && s2) { snprintf (buf, sizeof (buf), s1, s2); s = buf; @@ -9193,6 +9198,7 @@ validate_size (Uint uint_size, tree gnu_type, Entity_Id gnat_object, s = "component size for& too small{, minimum allowed is ^}"; else s = "size for& too small{, minimum allowed is ^}"; + post_error_ne_tree (s, gnat_error_node, gnat_object, old_size); return NULL_TREE;