public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Ed Schonberg <schonberg@adacore.com>
Subject: [Ada] Crash on improper pragma Weak_External
Date: Mon, 01 Jul 2019 13:38:00 -0000	[thread overview]
Message-ID: <20190701133800.GA18538@adacore.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 527 bytes --]

This patch adds a guard on the use of pragma Weak_External. This pragma
affects link-time addresses of entities, and does not apply to types.
Previous to this patch the compiler would abort on a misuse of the
pragma.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-07-01  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* sem_prag.adb (Analyze_Pragma, case Weak_External): Pragma only
	applies to entities with run-time addresses, not to types.

gcc/testsuite/

	* gnat.dg/weak3.adb, gnat.dg/weak3.ads: New testcase.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1050 bytes --]

--- gcc/ada/sem_prag.adb
+++ gcc/ada/sem_prag.adb
@@ -25608,6 +25608,12 @@ package body Sem_Prag is
                Ent := Underlying_Type (Ent);
             end if;
 
+            --  The pragma applies to entities with addresses.
+
+            if Is_Type (Ent) then
+               Error_Pragma ("pragma applies to objects and subprograms");
+            end if;
+
             --  The only processing required is to link this item on to the
             --  list of rep items for the given entity. This is accomplished
             --  by the call to Rep_Item_Too_Late (when no error is detected

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/weak3.adb
@@ -0,0 +1,11 @@
+--  { dg-do compile }
+
+package body Weak3 is
+
+   type T is new Integer;
+   pragma Weak_External (T); --  { dg-error "pragma applies to objects and subprograms" }
+   X : T;
+
+   procedure Foo is null;
+
+end Weak3;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/weak3.ads
@@ -0,0 +1,3 @@
+package Weak3 is
+   procedure Foo;
+end Weak3;


                 reply	other threads:[~2019-07-01 13:38 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=20190701133800.GA18538@adacore.com \
    --to=derodat@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=schonberg@adacore.com \
    /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: link
Be 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).