diff options
author | Javier Miranda <miranda@adacore.com> | 2019-07-22 13:56:36 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2019-07-22 13:56:36 +0000 |
commit | 2fdc20b65c2f3409591aeea810001a29ff1d6739 (patch) | |
tree | 3d01bf6710398160325173c03e27686536a77d66 | |
parent | 0af66bdce078d022e19dae1c83dfa06f7f622648 (diff) | |
download | gcc-2fdc20b65c2f3409591aeea810001a29ff1d6739.zip gcc-2fdc20b65c2f3409591aeea810001a29ff1d6739.tar.gz gcc-2fdc20b65c2f3409591aeea810001a29ff1d6739.tar.bz2 |
[Ada] Crash in C++ constructor without external and link name
The compiler blows up processing the declaration of a tagged type
variable that has a C++ constructor without external or link name. After
this patch the frontend reports an error.
2019-07-22 Javier Miranda <miranda@adacore.com>
gcc/ada/
* freeze.adb (Freeze_Subprogram): Check that C++ constructors
must have external or link name.
gcc/testsuite/
* gnat.dg/cpp_constructor2.adb: New testcase.
From-SVN: r273670
-rw-r--r-- | gcc/ada/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/ada/freeze.adb | 15 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/cpp_constructor2.adb | 19 |
4 files changed, 43 insertions, 0 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index c42164b..5cb3ab4 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2019-07-22 Javier Miranda <miranda@adacore.com> + + * freeze.adb (Freeze_Subprogram): Check that C++ constructors + must have external or link name. + 2019-07-22 Ed Schonberg <schonberg@adacore.com> * sem_res.adb (Resolve_Selected_Component): If the prefix has a diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb index b29ff67..728eaf2 100644 --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -62,6 +62,7 @@ with Sem_Util; use Sem_Util; with Sinfo; use Sinfo; with Snames; use Snames; with Stand; use Stand; +with Stringt; use Stringt; with Targparm; use Targparm; with Tbuild; use Tbuild; with Ttypes; use Ttypes; @@ -8766,6 +8767,20 @@ package body Freeze is Set_Is_Pure (E, False); end if; + -- For C++ constructors check that their external name has been given + -- (either in pragma CPP_Constructor or in a pragma import). + + if Is_Constructor (E) + and then + (No (Interface_Name (E)) + or else String_Equal + (L => Strval (Interface_Name (E)), + R => Strval (Get_Default_External_Name (E)))) + then + Error_Msg_N + ("'C++ constructor must have external name or link name", E); + end if; + -- We also reset the Pure indication on a subprogram with an Address -- parameter, because the parameter may be used as a pointer and the -- referenced data may change even if the address value does not. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f8372ba..2fa30eb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-07-22 Javier Miranda <miranda@adacore.com> + + * gnat.dg/cpp_constructor2.adb: New testcase. + 2019-07-22 Ed Schonberg <schonberg@adacore.com> * gnat.dg/warn22.adb: New testcase. diff --git a/gcc/testsuite/gnat.dg/cpp_constructor2.adb b/gcc/testsuite/gnat.dg/cpp_constructor2.adb new file mode 100644 index 0000000..3b245b0 --- /dev/null +++ b/gcc/testsuite/gnat.dg/cpp_constructor2.adb @@ -0,0 +1,19 @@ +-- { dg-do compile } + +procedure CPP_Constructor2 is + + package P is + type X is tagged limited record + A, B, C, D : Integer; + end record; + pragma Import (Cpp, X); + + procedure F1 (V : X); + pragma Import (Cpp, F1); + + function F2 return X; -- { dg-error "C\\+\\+ constructor must have external name or link name" } + pragma Cpp_Constructor (F2); + end P; +begin + null; +end CPP_Constructor2; |