public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Eric Botcazou <ebotcazou@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-10118] Give more informative error message for by-reference types Date: Tue, 14 Sep 2021 07:49:21 +0000 (GMT) [thread overview] Message-ID: <20210914074921.045103858018@sourceware.org> (raw) https://gcc.gnu.org/g:d15a351ce195356d172fffcfb04075a6bfeb0a79 commit r10-10118-gd15a351ce195356d172fffcfb04075a6bfeb0a79 Author: Eric Botcazou <ebotcazou@adacore.com> Date: Tue Sep 14 09:41:36 2021 +0200 Give more informative error message for by-reference types 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. gcc/ada/ * gcc-interface/decl.c (gnat_to_gnu_entity) <is_type>: 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: --- gcc/ada/gcc-interface/decl.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c index 751e7042540..efbcf70eadc 100644 --- a/gcc/ada/gcc-interface/decl.c +++ b/gcc/ada/gcc-interface/decl.c @@ -4257,6 +4257,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 @@ -4271,15 +4273,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 @@ -4582,7 +4587,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. */ @@ -9037,7 +9042,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; @@ -9046,6 +9051,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;
reply other threads:[~2021-09-14 7:49 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210914074921.045103858018@sourceware.org \ --to=ebotcazou@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).