From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from d208-15.smtp-out.ca-central-1.amazonses.com (d208-15.smtp-out.ca-central-1.amazonses.com [23.249.208.15]) by sourceware.org (Postfix) with ESMTPS id B0F753858D20 for ; Thu, 10 Aug 2023 04:55:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B0F753858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=annexi-strayline.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ca-central-1.amazonses.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=k5b76xhpalcgrb3af3ji3mgpa4ove7c7; d=annexi-strayline.com; t=1691643305; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; bh=DTWiWnqa1046foyiBjaNrDX/K9sKsTV3mv1froFaVWo=; b=nE38FMI8UKEpcxOhhgJcs4M302CXTPyFt6NtZ4ll6Nxl8cgys2fOU5dFAHP2nypV Ae3q+u9L2YNSkqrS4ATzr0rMUsaf1sKbprrEeYkVx+Py3Ml3w9zxrBKA4C9SBJcno3N DgXqhQLwO1SowuvSKFOZjsesngGZWOFh5q5VRweo= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=qpcfy54xse57bzmyicqs5kisv46vyagl; d=amazonses.com; t=1691643305; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type:Feedback-ID; bh=DTWiWnqa1046foyiBjaNrDX/K9sKsTV3mv1froFaVWo=; b=mjshDsVZY5qk2qiNNIrrDZ3PjSNyfE1KP0fxSL7rms4EQKjiAFU2sXWsGH+b+muc 4eB7DLkZihtkp65LQnWMKuhd1kewtBZ47aJkcvGhk16m/ZLKFwH8dqV2GOZGZrGAXjD rmLG/8g2CZYOZ98c+/ooRdaHJyNWnMXUXG8iu6po= From: Richard Wai To: gcc-patches@gcc.gnu.org Cc: 'Eric Botcazou' , 'Arnaud Charlet' , 'Stephen Baird' Subject: [PATCH 1/2] Ada: Synchronized private extensions are always limited Date: Thu, 10 Aug 2023 04:55:05 +0000 Message-ID: <010d0189ddcc5ef0-fd001d71-0986-4cce-8d50-53fa385360db-000000@ca-central-1.amazonses.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0046_01D9CB25.4D429D20" X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdnLQbFmob3/hjwrQG6akJjbpd96IQ== Content-Language: en-ca Feedback-ID: 1.ca-central-1.KKZpW0DP3lOi0JgzUh4V+obZyxLGOx2dpGS8+RWwiDg=:AmazonSES X-SES-Outgoing: 2023.08.10-23.249.208.15 X-Spam-Status: No, score=1.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DOS_OUTLOOK_TO_MX,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This is a multipart message in MIME format. ------=_NextPart_000_0046_01D9CB25.4D429D20 Content-Type: multipart/alternative; boundary="----=_NextPart_001_0047_01D9CB25.4D42C430" ------=_NextPart_001_0047_01D9CB25.4D42C430 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit GNAT currently considers a synchronized private extension that derives from an interface to be limited only when said interface is a concurrent interface. However it is of course legal for a synchronized private extension to derive from a limited interface. In this case GNAT fails to correctly determine that the private extension is limited. This causes two separate problems that makes discriminated types in such a case impossible: 1. GNAT inappropriately rejects compilation, claiming default discriminants on such a private extension are illegal. 2. GNAT fails to generate the expected discriminals for the unconstrained discriminanted case, leading to the corresponding discriminants of the "corresponding record" of the underlying concurrent type to have no identifiers, and thus compilation fails. Fairly simple fix. If "synchronized" appears in the private extension declaration, it is limited. This is explicit in the RM as well (7.3(6/2)). Fixing this bug uncovered of a related bug wrt. TSS address finalizer generation for constrained subtypes of synchronized private extensions with no default discriminants. That patch is to follow separately. Patch file is attached. -- Begin change log entry -- ada: Private extensions with the keyword "synchronized" are always limited. GNAT was relying on synchronized private type extensions deriving from a concurrent interface to determine its limitedness. This does not cover the case where such an extension derives a limited interface. RM-7.6(6/2) makes is clear that "synchronized" in a private extension implies the derived type is limited. GNAT should explicitly check for the presence of "synchronized" in a private extension declaration, and it should have the same effect as the presence of "limited". gcc/ada/ * sem_ch3.adb (Build_Derived_Record_Type): Treat presence of keyword "synchronized" the same as "limited" when determining if a private extension is limited. -- End change log entry -- This patch was bootstrapped on x86_64-*-freebsd13.2. Two new test cases were added. Note that 4 gnat test cases fail currently on master and are unrelated to this patch. Check-ada output of this patch: === acats tests === Running chapter a ... Running chapter c2 ... Running chapter c3 ... Running chapter c4 ... Running chapter c5 ... Running chapter c6 ... Running chapter c7 ... Running chapter c8 ... Running chapter c9 ... Running chapter ca ... Running chapter cb ... Running chapter cc ... Running chapter cd ... Running chapter ce ... Running chapter cxa ... Running chapter cxb ... Running chapter cxf ... Running chapter cxg ... Running chapter cxh ... Running chapter cz ... Running chapter d ... Running chapter e ... Running chapter l ... === acats Summary === # of expected passes 2328 # of unexpected failures 0 Native configuration is x86_64-unknown-freebsd13.2 === gnat tests === Schedule of variations: unix Running target unix FAIL: gnat.dg/specs/alignment2.ads (test for warnings, line 14) FAIL: gnat.dg/specs/alignment2.ads (test for warnings, line 20) FAIL: gnat.dg/specs/alignment2.ads (test for warnings, line 38) FAIL: gnat.dg/specs/alignment2.ads (test for warnings, line 42) === gnat Summary === # of expected passes 3402 # of unexpected failures 4 # of expected failures 23 # of unsupported tests 10 gnatmake version 14.0.0 20230809 (experimental) Richard Wai ANNEXI-STRAYLINE ------=_NextPart_001_0047_01D9CB25.4D42C430-- ------=_NextPart_000_0046_01D9CB25.4D429D20 Content-Type: application/octet-stream; name="ada-synchronized-private-types-are-limited.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="ada-synchronized-private-types-are-limited.patch" >From f87d0da43296b87cd242380a4077a167e5ea1291 Mon Sep 17 00:00:00 2001=0A= From: Richard Wai =0A= Date: Wed, 9 Aug 2023 01:54:48 -0400=0A= Subject: [PATCH 1/2] ada: Consider that any synchronized private extension = is=0A= always a limited type, even if it inherits from a non-concurrent interface= .=0A= Add two regression tests for two separate problems that arose=0A= =0A= ---=0A= gcc/ada/sem_ch3.adb | 12 +++--=0A= .../gnat.dg/sync_tag_discriminals.adb | 51 +++++++++++++++++++=0A= gcc/testsuite/gnat.dg/sync_tag_limited.adb | 50 ++++++++++++++++++=0A= 3 files changed, 110 insertions(+), 3 deletions(-)=0A= create mode 100644 gcc/testsuite/gnat.dg/sync_tag_discriminals.adb=0A= create mode 100644 gcc/testsuite/gnat.dg/sync_tag_limited.adb=0A= =0A= diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb=0A= index 042ace01724..48731a7bf04 100644=0A= --- a/gcc/ada/sem_ch3.adb=0A= +++ b/gcc/ada/sem_ch3.adb=0A= @@ -9494,9 +9494,15 @@ package body Sem_Ch3 is=0A= =20=0A= -- AI-419: Limitedness is not inherited from an interface parent, s= o to=0A= -- be limited in that case the type must be explicitly declared as= =0A= - -- limited. However, task and protected interfaces are always limit= ed.=0A= -=0A= - if Limited_Present (Type_Def) then=0A= + -- limited, or synchronized. While task and protected interfaces ar= e=0A= + -- always limited, a synchronized private extension might not inher= it=0A= + -- from such interfaces, and so we also need to recognize the=0A= + -- explicit limitedness implied by a synchronized private extension= =0A= + -- the does not derive from a synchronized interface (see RM-7.3(6/= 2)).=0A= +=0A= + if Limited_Present (Type_Def)=0A= + or else Synchronized_Present (Type_Def)=0A= + then=0A= Set_Is_Limited_Record (Derived_Type);=0A= =20=0A= elsif Is_Limited_Record (Parent_Type)=0A= diff --git a/gcc/testsuite/gnat.dg/sync_tag_discriminals.adb b/gcc/testsuit= e/gnat.dg/sync_tag_discriminals.adb=0A= new file mode 100644=0A= index 00000000000..b105acf6e98=0A= --- /dev/null=0A= +++ b/gcc/testsuite/gnat.dg/sync_tag_discriminals.adb=0A= @@ -0,0 +1,51 @@=0A= +-- This test is related to sync_tag_limited in that previous versions of G= NAT=0A= +-- failed to consider a synchronized private extension as limited if it wa= s=0A= +-- not derrived from a synchronized interface (i.e. a limited interface). = Since=0A= +-- such a private type would not be considered limited, GNAT would fail to= =0A= +-- correctly build the expected discriminals later needed by the creation = of=0A= +-- the concurrent type's "corresponding record type", leading to a compila= tion=0A= +-- error where the discriminants of the corresponding record type had no= =0A= +-- identifiers.=0A= +--=0A= +-- This test is in addition to sync_tag_limited because the sync_tag_limit= ed=0A= +-- would fail for "legality" reasons (default discriminants not allowed fo= r=0A= +-- a non-limited taged type). It is also an opportunity to ensure that non= -=0A= +-- defaulted discriminated synchronized private extensions work as expecte= d.=0A= +=0A= +-- { dg-do compile }=0A= +=0A= +procedure Sync_Tag_Discriminals is=0A= +=20=20=20=0A= + package Ifaces is=0A= +=20=20=20=20=20=20=0A= + type Test_Interface is limited interface;=0A= +=20=20=20=20=20=20=0A= + procedure Interface_Action (Test: in out Test_Interface) is abstract= ;=0A= +=20=20=20=20=20=20=0A= + end Ifaces;=0A= +=20=20=20=0A= +=20=20=20=0A= + package Implementation is=0A= + type Test_Implementation=0A= + (Constraint: Positive) is=0A= + synchronized new Ifaces.Test_Interface with private;=0A= +=20=20=20=20=20=20=0A= + private=0A= + protected type Test_Implementation=0A= + (Constraint: Positive)=0A= + is new Ifaces.Test_Interface with=0A= +=20=20=20=20=20=20=0A= + overriding procedure Interface_Action;=0A= +=20=20=20=20=20=20=20=20=20=0A= + end Test_Implementation;=0A= + end Implementation;=0A= +=20=20=20=0A= + package body Implementation is=0A= + protected body Test_Implementation is=0A= + procedure Interface_Action is null;=0A= + end;=0A= + end Implementation;=0A= +=20=20=20=0A= +begin=0A= + null;=0A= +end Sync_Tag_Discriminals;=0A= diff --git a/gcc/testsuite/gnat.dg/sync_tag_limited.adb b/gcc/testsuite/gna= t.dg/sync_tag_limited.adb=0A= new file mode 100644=0A= index 00000000000..608f10662a3=0A= --- /dev/null=0A= +++ b/gcc/testsuite/gnat.dg/sync_tag_limited.adb=0A= @@ -0,0 +1,50 @@=0A= +-- Synchronized tagged types created by a private extension with the keyw= ord=0A= +-- 'synchronized' shall be seen as an (immutably) limited tagged type, an= d=0A= +-- should therefore accept default disciminant spectifications.=0A= +-- This was a bug in earlier versions of GNAT, whereby GNAT erroneously= =0A= +-- relied on a parent synchronized interface to determine limitedness=0A= +-- of a synchronized private extension. The problem being that a synchron= ized=0A= +-- private extension can derive a non-synchronized interface (specificall= y a=0A= +-- limited interface), Yet the RM makes it clear (7.3(6/2)) that such=0A= +-- synchronized private extensions are always limited.=0A= +--=0A= +-- Ergo: Default discriminants are of course legal on any synchronized pr= ivate=0A= +-- extension.=0A= +=0A= +-- { dg-do compile }=0A= +=0A= +procedure Sync_Tag_Limited is=0A= +=20=20=20=0A= + package Ifaces is=0A= +=20=20=20=20=20=20=0A= + type Test_Interface is limited interface;=0A= +=20=20=20=20=20=20=0A= + procedure Interface_Action (Test: in out Test_Interface) is abstract= ;=0A= +=20=20=20=20=20=20=0A= + end Ifaces;=0A= +=20=20=20=0A= +=20=20=20=0A= + package Implementation is=0A= + type Test_Implementation=0A= + (Constraint: Positive :=3D 1) is=0A= + synchronized new Ifaces.Test_Interface with private;=0A= +=20=20=20=20=20=20=0A= + private=0A= + protected type Test_Implementation=0A= + (Constraint: Positive :=3D 1)=0A= + is new Ifaces.Test_Interface with=0A= +=20=20=20=20=20=20=0A= + overriding procedure Interface_Action;=0A= +=20=20=20=20=20=20=20=20=20=0A= + end Test_Implementation;=0A= + end Implementation;=0A= +=20=20=20=0A= + package body Implementation is=0A= + protected body Test_Implementation is=0A= + procedure Interface_Action is null;=0A= + end;=0A= + end Implementation;=0A= +=20=20=20=0A= +begin=0A= + null;=0A= +end Sync_Tag_Limited;=0A= --=20=0A= 2.40.1=0A= =0A= ------=_NextPart_000_0046_01D9CB25.4D429D20--