From d8f8b16648d012d68ccb148a808c9a404960ea20 Mon Sep 17 00:00:00 2001 From: Ed Schonberg Date: Mon, 1 Jul 2019 13:37:11 +0000 Subject: [PATCH] [Ada] Crash on improper pragma Weak_External 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. 2019-07-01 Ed Schonberg 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. From-SVN: r272876 --- gcc/ada/ChangeLog | 5 +++++ gcc/ada/sem_prag.adb | 6 ++++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gnat.dg/weak3.adb | 11 +++++++++++ gcc/testsuite/gnat.dg/weak3.ads | 3 +++ 5 files changed, 29 insertions(+) create mode 100644 gcc/testsuite/gnat.dg/weak3.adb create mode 100644 gcc/testsuite/gnat.dg/weak3.ads diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 65ca1e6cc0a..f2e8f39ff29 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2019-07-01 Ed Schonberg + + * sem_prag.adb (Analyze_Pragma, case Weak_External): Pragma only + applies to entities with run-time addresses, not to types. + 2019-07-01 Piotr Trojanek * einfo.adb, sem_ch7.adb, sem_prag.adb, sem_util.adb: Update diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb index b6d259f82db..ca3603c8ca6 100644 --- a/gcc/ada/sem_prag.adb +++ b/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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4d49ad3de83..0929da1ff03 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-07-01 Ed Schonberg + + * gnat.dg/weak3.adb, gnat.dg/weak3.ads: New testcase. + 2019-07-01 Ed Schonberg * gnat.dg/prot7.adb, gnat.dg/prot7.ads: New testcase. diff --git a/gcc/testsuite/gnat.dg/weak3.adb b/gcc/testsuite/gnat.dg/weak3.adb new file mode 100644 index 00000000000..ab494a082f9 --- /dev/null +++ b/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; diff --git a/gcc/testsuite/gnat.dg/weak3.ads b/gcc/testsuite/gnat.dg/weak3.ads new file mode 100644 index 00000000000..1c41a2d6585 --- /dev/null +++ b/gcc/testsuite/gnat.dg/weak3.ads @@ -0,0 +1,3 @@ +package Weak3 is + procedure Foo; +end Weak3; -- 2.30.2