public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Missing accessibility actuals on calls to interface conversion functions
@ 2019-12-18  7:28 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2019-12-18  7:28 UTC (permalink / raw)
  To: gcc-patches; +Cc: Gary Dismukes

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

In certain cases of conversions to interface types, the compiler
generates a special function to handle the conversion. In cases where
such a function has an extra accessibility-level formal and the target
type of the conversion has a designated type that comes from a limited
view (via limited_with_clause), the resolution of the type conversion
wasn't retrieving the needed nonlimited view, which resulted in the call
to the interface conversion function not being expanded and hence not
being passed the needed actual for the accessibility level.

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

2019-12-18  Gary Dismukes  <dismukes@adacore.com>

gcc/ada/

	* sem_res.adb (Resolve_Type_Conversion): Add handling for access
	types with designated operand and target types that are
	referenced in places that have a limited view of an interface
	type by retrieving the nonlimited view when it exists.  Add ???
	comments related to missing limited_with_clause handling for
	Target (in the non-access case).

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

--- gcc/ada/sem_res.adb
+++ gcc/ada/sem_res.adb
@@ -11827,12 +11827,35 @@ package body Sem_Res is
                Set_Etype (Expression (N), Opnd);
             end if;
 
+            --  It seems that Non_Limited_View should also be applied for
+            --  Target when it has a limited view, but that leads to missing
+            --  error checks on interface conversions further below. ???
+
             if Is_Access_Type (Opnd) then
                Opnd := Designated_Type (Opnd);
+
+               --  If the type of the operand is a limited view, use nonlimited
+               --  view when available. If it is a class-wide type, recover the
+               --  class-wide type of the nonlimited view.
+
+               if From_Limited_With (Opnd)
+                 and then Has_Non_Limited_View (Opnd)
+               then
+                  Opnd := Non_Limited_View (Opnd);
+               end if;
             end if;
 
             if Is_Access_Type (Target_Typ) then
                Target := Designated_Type (Target);
+
+               --  If the target type is a limited view, use nonlimited view
+               --  when available.
+
+               if From_Limited_With (Target)
+                 and then Has_Non_Limited_View (Target)
+               then
+                  Target := Non_Limited_View (Target);
+               end if;
             end if;
 
             if Opnd = Target then
@@ -11840,6 +11863,10 @@ package body Sem_Res is
 
             --  Conversion from interface type
 
+            --  It seems that it would be better for the error checks below
+            --  to be performed as part of Validate_Conversion (and maybe some
+            --  of the error checks above could be moved as well?). ???
+
             elsif Is_Interface (Opnd) then
 
                --  Ada 2005 (AI-217): Handle entities from limited views


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-12-18  7:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-18  7:28 [Ada] Missing accessibility actuals on calls to interface conversion functions Pierre-Marie de Rodat

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).