diff mbox

[Ada] Fix C++ interfacing bug on 32-bit Windows

Message ID 1793409.tfH0N9H0DS@polaris
State New
Headers show

Commit Message

Eric Botcazou Nov. 24, 2015, 8:43 a.m. UTC
This fixes a regression present on mainline and 5 branch pertaining to the 
calling convention used for an imported function with CPP convention on 32-bit 
Windows.  This platform is special because C++ methods use a special calling 
convention ("thiscall") and we obviously need to do the same on the Ada side, 
which is a bit tricky because of the way the primitive operations (counterpart 
of methods in Ada) are declared.

Tested on x86-64/Linux and x86/Windows, applied on mainline and 5 branch.


2015-11-24  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/decl.c (is_cplusplus_method): Check that the type of
	the first parameter (indirectly) has C++ convention too.
diff mbox

Patch

Index: gcc-interface/decl.c
===================================================================
--- gcc-interface/decl.c	(revision 230786)
+++ gcc-interface/decl.c	(working copy)
@@ -5403,9 +5403,28 @@  get_minimal_subprog_decl (Entity_Id gnat
 bool
 is_cplusplus_method (Entity_Id gnat_entity)
 {
+  /* Check that the subprogram has C++ convention.  */
   if (Convention (gnat_entity) != Convention_CPP)
     return false;
 
+  /* A constructor is a method on the C++ side.  We deal with it now because
+     it is declared without the 'this' parameter in the sources and, although
+     the front-end will create a version with the 'this' parameter for code
+     generation purposes, we want to return true for both versions.  */
+  if (Is_Constructor (gnat_entity))
+    return true;
+
+  /* And that the type of the first parameter (indirectly) has it too.  */
+  Entity_Id gnat_first = First_Formal (gnat_entity);
+  if (No (gnat_first))
+    return false;
+
+  Entity_Id gnat_type = Etype (gnat_first);
+  if (Is_Access_Type (gnat_type))
+    gnat_type = Directly_Designated_Type (gnat_type);
+  if (Convention (gnat_type) != Convention_CPP)
+    return false;
+
   /* This is the main case: C++ method imported as a primitive operation.
      Note that a C++ class with no virtual functions can be imported as a
      limited record type so the operation is not necessarily dispatching.  */
@@ -5416,10 +5435,6 @@  is_cplusplus_method (Entity_Id gnat_enti
   if (Is_Subprogram (gnat_entity) && Is_Thunk (gnat_entity))
     return true;
 
-  /* A constructor is a method on the C++ side.  */
-  if (Is_Constructor (gnat_entity))
-    return true;
-
   /* This is set on the E_Subprogram_Type built for a dispatching call.  */
   if (Is_Dispatch_Table_Entity (gnat_entity))
     return true;