From patchwork Tue Sep 16 08:22:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 120339 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E579C385734D for ; Tue, 16 Sep 2025 08:24:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E579C385734D Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=WNGUV+9E X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 2259D385734D for ; Tue, 16 Sep 2025 08:23:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2259D385734D Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2259D385734D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::333 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758010990; cv=none; b=vrjTqI0zkorFB/bP5Is8q70KvAXkSEx1bjoa3CdIbtsLaPFH6XZ6hTwaWbmR4OKk9meSYhAwVpIf9Gfbx84yg2i/TmnJidXLx1EaltssrjV7huoBtUoYTpsTuAdS1Qd+I4bGsEprj34WYWNswJe2SH58pjY+jToy6ofyDl5gD/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758010990; c=relaxed/simple; bh=hSSoAszZ5jOdhUax/fqAxZDncmo0Hoqql2GBx+KJKQw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=aOgNXLr5geenVlqLYCqveK0jbGQPbNA7IyYDIbONH/VDl+lGt9IRwSF6oqawT0JSEje+KtHRWQE8hKK91jJqeDHEGiJxmTBwedNbwvKexXgmczgD6LdPtn156nfDwOq+u1IBjJ84WMJsgMbU2pfA9hNsnoJNdoJI6ETohdaGaKI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2259D385734D Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-45decc9e83eso56064105e9.3 for ; Tue, 16 Sep 2025 01:23:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1758010989; x=1758615789; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=AMhbnkbtv5MCpwGqV+KwYbViFZjERvuvY5bEM/3eSxA=; b=WNGUV+9Ex92NRThOIgqjdzgi9ja6gSB/nBqi6AasFP/iPa2lTuneMlBqhhb+4UMNMV TU2Q5tn0zPsFwLQ67myyxkQDgTiKbGmJh4lKtPVfc3ezZoYXZ/MLG0sKlFcqc9gwNX+8 haREMu7k1sBUj0AdvBYGrANXjfdQo5J3dN5EJWdniN0JmWroBEWP6kuxDqQ1dX38N1ko g68PK9n0RdK2b3AS2Rrtg+n2TxEC4K5BuEGmNg+qmSYr1ZwVRNzLoICxRRr9UpMwU83h 7Ob5gJRoKk1vXP8wDI/C7ytAzVGhbxowTDV9x736A334dZNpTietdskHX8Ih2wPTfku/ 1Qxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758010989; x=1758615789; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AMhbnkbtv5MCpwGqV+KwYbViFZjERvuvY5bEM/3eSxA=; b=d0jWWWRRBEx0T0KBSHaqmpfVOmd+3UB9xTpKOCq0vzLzsrLmkwaH1UeaMHL5u4M8d6 3ZWQXPW2wphLWETmd6qJkz5DmLIWqokmMp6Bq90x3hAN47QJvEpeyVo9ulN3yB4Bex2o zcuWBsIzKeZBEjABZajG70ipt3IoNiWkZHBhBj3mN1zLlW9+Umlu4ua9z4tvYEn9CtjZ RTrR42J0urVBZcwCWxsnQZjiFRIAzxZz40nScaAm9LhFWQC9LLo6Tapocmq2bIsQ+sNr S1UDN+6Al0N4z256/LWHXSLJcTAdZ5Oi6w3IcYQezaq24fi2ecVH6Zc+/UD60dYiYtBW crAQ== X-Gm-Message-State: AOJu0YzbTCx83APaMK0zAz9am/ynCSP5W3VZjlK9PYwb9RIuLc8iFFxT 1cAXUedS6BQpaQnTjE8qDTDEMjOM72+m5tCoA955+B/S25fuu0Ish8AdQZuALl4NeMgJtmxmeov K/lY= X-Gm-Gg: ASbGncsUH3lIyCj7AQWqxmnIshEXdX6Maeux6UvIHybp7mVVYZKCN7migfB0nGNcQts DlhB6sTtVehAxC1ZFm+OyrABgCJmJdqLz5UuOl3/j/fmI/I9psyt8OeWMZMGgGRNi7GKnfmKHyQ uXFOkVkVV0ebzx5OTVZB+ZIVHmYrsDthatB3duS/oucCp/0xb7tH+Am9k1ltSMZdMV0nVKMxYLi JsDIXlHHXvNjrfNeKfTkbg2t3EVXcChm8rhlF9/lQoS7S66mrrA2+PmMfcGbYFB1h30oPv9b0vn pTI/+g9Isk6dlm3FI19QyH3wOrXmoYAisYdvGiUsOWq/Zyey4lyKrTIIe26aiV3fP5gGUsl570U fXMERBDMYsSvR2jU0XynICNjGkern0VEzY9AqZyU= X-Google-Smtp-Source: AGHT+IETw3/DQ2wKoUNuUWnzc+bo3cAjNeXDbe0NW8lvF63zIS9rzuCnXBHMTYIDAjv7M8gAnZLxVQ== X-Received: by 2002:a05:600c:1507:b0:45c:b549:2241 with SMTP id 5b1f17b1804b1-45f21200dcamr78161395e9.27.1758010988547; Tue, 16 Sep 2025 01:23:08 -0700 (PDT) Received: from localhost.localdomain ([2a01:cb15:8541:af00:f92d:585:510e:3226]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45f3252260csm12826285e9.2.2025.09.16.01.23.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Sep 2025 01:23:07 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Gary Dismukes Subject: [COMMITTED 1/2] ada: Revert "Remove dependence on secondary stack for type with controlled component" Date: Tue, 16 Sep 2025 10:22:56 +0200 Message-ID: <20250916082257.2900903-1-poulhies@adacore.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org From: Gary Dismukes This reverts commit 91b51fc42b167eedaaded6360c490a4306bc5c55. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_ch6.adb | 49 ++++++++++++++++++++++++++++++--------------- gcc/ada/exp_ch6.ads | 6 ++++-- gcc/ada/exp_ch7.adb | 20 +++++++++--------- 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb index 58361e10bd9c..5056b1f990fa 100644 --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -9093,6 +9093,27 @@ package body Exp_Ch6 is -- tagged, the called function itself must perform the allocation of -- the return object, so we pass parameters indicating that. + -- But that's also the case when the result subtype needs finalization + -- actions because the caller side allocation may result in undesirable + -- finalization. Consider the following example: + -- + -- function Make_Lim_Ctrl return Lim_Ctrl is + -- begin + -- return Result : Lim_Ctrl := raise Program_Error do + -- null; + -- end return; + -- end Make_Lim_Ctrl; + -- + -- Obj : Lim_Ctrl_Ptr := new Lim_Ctrl'(Make_Lim_Ctrl); + -- + -- Even though the size of limited controlled type Lim_Ctrl is known, + -- allocating Obj at the caller side will chain Obj on Lim_Ctrl_Ptr's + -- finalization collection. The subsequent call to Make_Lim_Ctrl will + -- fail during the initialization actions for Result, which means that + -- Result (and Obj by extension) should not be finalized. However Obj + -- will be finalized when access type Lim_Ctrl_Ptr goes out of scope + -- since it is already attached on the its finalization collection. + if Needs_BIP_Alloc_Form (Function_Id) then Temp_Init := Empty; @@ -9257,7 +9278,11 @@ package body Exp_Ch6 is end if; end; - -- Add implicit actuals for the BIP formal parameters, if any + -- When the function has a controlling result, an allocation-form + -- parameter must be passed indicating that the caller is allocating + -- the result object. This is needed because such a function can be + -- called as a dispatching operation and must be treated similarly + -- to functions with unconstrained result subtypes. Add_Unconstrained_Actuals_To_Build_In_Place_Call (Func_Call, @@ -9282,14 +9307,6 @@ package body Exp_Ch6 is Add_Access_Actual_To_Build_In_Place_Call (Func_Call, Function_Id, Return_Obj_Actual); - -- If the allocation is done in the caller, create a custom Allocate - -- procedure if need be. - - if not Needs_BIP_Alloc_Form (Function_Id) then - Build_Allocate_Deallocate_Proc - (Declaration_Node (Return_Obj_Access), Mark => Allocator); - end if; - -- Finally, replace the allocator node with a reference to the temp Rewrite (Allocator, New_Occurrence_Of (Return_Obj_Access, Loc)); @@ -9751,7 +9768,7 @@ package body Exp_Ch6 is -- ensure that the heap allocation can properly chain the object -- and later finalize it when the library unit goes out of scope. - if Needs_BIP_Collection (Function_Id) then + if Needs_BIP_Collection (Func_Call) then Build_Finalization_Collection (Typ => Ptr_Typ, For_Lib_Level => True, @@ -10314,12 +10331,6 @@ package body Exp_Ch6 is Typ : constant Entity_Id := Underlying_Type (Etype (Func_Id)); begin - -- No need for BIP_Collection if allocation is always done in the caller - - if not Needs_BIP_Alloc_Form (Func_Id) then - return False; - end if; - -- A formal for the finalization collection is needed for build-in-place -- functions whose result type needs finalization or is a tagged type. -- Tagged primitive build-in-place functions need such a formal because @@ -10344,6 +10355,12 @@ package body Exp_Ch6 is Typ : constant Entity_Id := Underlying_Type (Etype (Func_Id)); begin + -- See Make_Build_In_Place_Call_In_Allocator for the rationale + + if Needs_BIP_Collection (Func_Id) then + return True; + end if; + -- A formal giving the allocation method is needed for build-in-place -- functions whose result type is returned on the secondary stack or -- is a tagged type. Tagged primitive build-in-place functions need diff --git a/gcc/ada/exp_ch6.ads b/gcc/ada/exp_ch6.ads index 3867270e71a9..5919627a4e7e 100644 --- a/gcc/ada/exp_ch6.ads +++ b/gcc/ada/exp_ch6.ads @@ -301,8 +301,10 @@ package Exp_Ch6 is -- BIP_Alloc_Form parameter (see type BIP_Formal_Kind). function Needs_BIP_Collection (Func_Id : Entity_Id) return Boolean; - -- Ada 2005 (AI-318-02): Return True if the function needs an implicit - -- BIP_Collection parameter (see type BIP_Formal_Kind). + -- Ada 2005 (AI-318-02): Return True if the result subtype of function + -- Func_Id might need finalization actions. This includes build-in-place + -- functions with tagged result types, since they can be invoked via + -- dispatching calls, and descendant types may require finalization. function Needs_BIP_Task_Actuals (Func_Id : Entity_Id) return Boolean; -- Return True if the function returns an object of a type that has tasks. diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb index d60c6edecdff..62e9d2cbb73f 100644 --- a/gcc/ada/exp_ch7.adb +++ b/gcc/ada/exp_ch7.adb @@ -4758,18 +4758,18 @@ package body Exp_Ch7 is -- We mark the secondary stack if it is used in this construct, and -- we're not returning a function result on the secondary stack, except - -- that a build-in-place function that only conditionally returns on - -- the secondary stack will also need a mark. A run-time test for doing - -- the release call is needed in the case where the build-in-place - -- function has a BIP_Alloc_Form parameter (see Create_Finalizer). + -- that a build-in-place function that might or might not return on the + -- secondary stack always needs a mark. A run-time test is required in + -- the case where the build-in-place function has a BIP_Alloc extra + -- parameter (see Create_Finalizer). Needs_Sec_Stack_Mark : constant Boolean := - Uses_Sec_Stack (Scop) - and then - (not Sec_Stack_Needed_For_Return (Scop) - or else - (Is_Build_In_Place_Function (Scop) - and then Needs_BIP_Alloc_Form (Scop))); + (Uses_Sec_Stack (Scop) + and then + not Sec_Stack_Needed_For_Return (Scop)) + or else + (Is_Build_In_Place_Function (Scop) + and then Needs_BIP_Alloc_Form (Scop)); Needs_Custom_Cleanup : constant Boolean := Nkind (N) = N_Block_Statement From patchwork Tue Sep 16 08:22:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 120340 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E169A3857348 for ; Tue, 16 Sep 2025 08:25:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E169A3857348 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=QkfMNQBS X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id 422EE3858C2A for ; Tue, 16 Sep 2025 08:23:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 422EE3858C2A Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 422EE3858C2A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::330 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758010991; cv=none; b=TSDR9xtvUDi+nlvy0RmWR7de2fyg1RlLCcrZNtboFShEhgOBTzUYN1cUN6Vw27lbJEkOyGy02ZI+1EQdoGuqE14Muz0J0LZs/KiY87toDsgHZmiay5ykzwGGIuU4hoBtWrLLz9IMaV7NE++kH7OoUIh2JBMdONYzOA7dJrqJTJ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758010991; c=relaxed/simple; bh=ow+JrRSxZ4ipTiznDQ7aFMphyWnibftBG3BMs4eSQao=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=dX2lqVKHjZq3o37QTy2+0tu9PfKNJbv8If4haKFZJKRGVaP2OLHs+kL9kNl82JR9aBItsYNemDZJXhqaKnbdniXkq5gCRwmN+6HdUMVNyYdq/6VEJgwzyQp6kG6j8/zJbbvspilhsMJp/Oeun7qRBAI2qdL9y6UCydRBPho6gM4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 422EE3858C2A Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-45f29d2357aso16706755e9.2 for ; Tue, 16 Sep 2025 01:23:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1758010990; x=1758615790; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3wLTUYgYUsMRYF6iS8tjzV6WaNONAACTrKwgLysJ6fw=; b=QkfMNQBSTDYDS73k+3Uv/slLUuVFXpet71OQ+VBMEVesqSM8C5W0qO9F9gI1yQyNNx +Hoj5oqPEaOSv16XIvIy3KW0XV8S1/ITx6kSsmG+jvXOxnaPhk2iJNrMWwSVbiF9XcQ2 llAFWh7Aa9DyYRwHYF87MXQndL/yqkqc1yHD8bmb5qMzZ3uST+WOaVLxwnSbz4NTmLfx KWCLL7cH9gnA1+RHEAYAWyXGnq8kFAg5CVDp0MHoaY81Bgx4WPjtclIovMIW+iu9YwPS ftCD6OGgiv0cH/jnmWElbSMnoHc1dA2Ttatp+415VPglA8Rwgsrzuek/C2L+2ITjVqsL VtHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758010990; x=1758615790; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3wLTUYgYUsMRYF6iS8tjzV6WaNONAACTrKwgLysJ6fw=; b=c/EH8Ck4YEXsGy2ToY0ndf2OKG9Ev9zLHAcfG5xDgFxVKcl4HW/+6nvhGERqqKPMM4 zy7wzq864bn7M320Q4cYw7Ij1TzPybpeRx//HzcQa9m2eZlbo1m+GR0D5YcINkcg4qIH tS19i+UcjJZc4BavP7/RbKP6xUMjkNi8C7uk5htP2itTWkzxzcYVOAY/OBQx9uhZcrVT 0hC+MFwQurajN2Cvtg/Lg+Vu61xzWbsz6waBDSr5zpR6BCNQ6xuhBMu44HBueO2wPv7P 2m101stPWazHknZ7BRD/sE3GdLonRx/NCPCh87HX5HqiTLH6gitidvkIwonmKCc9WrHQ 0o1w== X-Gm-Message-State: AOJu0YwJ9MPafmzDb9q96qCEo8GOHq97s+XuocQV81eiztpokR+0acAX YLaLEaPPgf2YQbFjM0iwDn2tDTgA8/aLKEN1LjyCmv3SIqp4QBzBijl3f7+s/a8tzg4a1dBli4H YoRc= X-Gm-Gg: ASbGncuxQsKUv+SGgs+CFom1MKjqyMn88+obIIsH+8nkPkEoYOIX61hJP1SaVLXW6hc jFvf3h5Qg0VWDrVVd0/6l9FnDmZUUJMHXJb8poT/lZCo+whLNWaygORmzz/o2nZgaSUy9hcEesS I2/865CtrL5zSyIGXXgL8/94R0SFhfJmR+XWXhdrdsK1Qjdf7n6kUfTiqKCZAuAgeFYpHQ6OcWC sXid0/6cO8UYapBxpmLej0uNAQOia6AOAS3sW9mK/jcbRr1xOUXSkAMQL1DUnV4gAqIK02N1ENL 872Eff0A2X2fMCg3By2FV35WFttyMhyeywu7BVaVAf3pQ+0qeZqOv7S7xorLe3VevXLZf87Z2A+ mRWEly2K/UdZj/OInJwA7G/kVBufK5ZPmtm/v+JDh1yWwXOIfbA== X-Google-Smtp-Source: AGHT+IHnOjCVrHxwSsBNNgAdunfxKpZpsNbMmveHLni3SPgexCTwzBgCdNh0nIjidGzhDSq8+Bacug== X-Received: by 2002:a05:600c:c8d:b0:45d:f7e4:87a3 with SMTP id 5b1f17b1804b1-45f214ac212mr110880735e9.3.1758010989648; Tue, 16 Sep 2025 01:23:09 -0700 (PDT) Received: from localhost.localdomain ([2a01:cb15:8541:af00:f92d:585:510e:3226]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45f3252260csm12826285e9.2.2025.09.16.01.23.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Sep 2025 01:23:08 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Ronan Desplanques Subject: [COMMITTED 2/2] ada: Fix error message for Stream_Size Date: Tue, 16 Sep 2025 10:22:57 +0200 Message-ID: <20250916082257.2900903-2-poulhies@adacore.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250916082257.2900903-1-poulhies@adacore.com> References: <20250916082257.2900903-1-poulhies@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org From: Ronan Desplanques Before this patch, confirming Stream_Size aspect specifications on elementary types were incorrectly rejected when the stream size was 128, and the error messages emitted for Stream_Size aspect errors gave incorrect possible values. This patch fixes this. The most significant part of the fix is a new subprogram in Exp_Strm, Get_Primitives, that makes it possible to retrieve a precise list of supported stream sizes, but also to select the right runtime streaming primitives for a given type. Using the latter, this patch factorizes code that was present in both Build_Elementary_Input_Call and Build_Elementary_Write_Call. gcc/ada/ChangeLog: * exp_strm.ads (Get_Primitives): New function. * exp_strm.adb (Get_Primitives): Likewise. (Build_Elementary_Input_Call, Build_Elementary_Write_Call): use Get_Primitives. (Has_Stream_Standard_Rep): Add formal parameter and rename to... (Is_Stream_Standard_Rep): New function. * sem_ch13.adb (Analyze_Attribute_Definition_Clause): Fix error emission. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_strm.adb | 447 +++++++++++++++---------------------------- gcc/ada/exp_strm.ads | 30 +++ gcc/ada/sem_ch13.adb | 74 ++++--- 3 files changed, 234 insertions(+), 317 deletions(-) diff --git a/gcc/ada/exp_strm.adb b/gcc/ada/exp_strm.adb index 5e1c9134fb57..3bb6966dc1c2 100644 --- a/gcc/ada/exp_strm.adb +++ b/gcc/ada/exp_strm.adb @@ -33,7 +33,6 @@ with Mutably_Tagged; use Mutably_Tagged; with Namet; use Namet; with Nlists; use Nlists; with Nmake; use Nmake; -with Rtsfind; use Rtsfind; with Sem_Aux; use Sem_Aux; with Sem_Util; use Sem_Util; with Sinfo; use Sinfo; @@ -43,7 +42,6 @@ with Snames; use Snames; with Stand; use Stand; with Tbuild; use Tbuild; with Ttypes; use Ttypes; -with Uintp; use Uintp; package body Exp_Strm is @@ -82,13 +80,13 @@ package body Exp_Strm is -- Decls and Stms are the declarations and statements for the body and -- The parameter Fnam is the name of the constructed function. - function Has_Stream_Standard_Rep (U_Type : Entity_Id) return Boolean; - -- This function is used to test the type U_Type, to determine if it has - -- a standard representation from a streaming point of view. Standard means - -- that it has a standard representation (e.g. no enumeration rep clause), - -- and the size of the root type is the same as the streaming size (which - -- is defined as value specified by a Stream_Size clause if present, or - -- the Esize of U_Type if not). + function Is_Stream_Standard_Rep + (U_Type : Entity_Id; S_Size : Uint) return Boolean; + -- This function is used to test the type U_Type, to determine whether it + -- would have a standard representation from a streaming point of view if + -- its Stream_Size attribute was set to S_Size. Standard means that it has + -- a standard representation (e.g. no enumeration rep clause), and the size + -- of the root type is the same as the stream size. function Make_Stream_Subprogram_Name (Loc : Source_Ptr; @@ -436,51 +434,39 @@ package body Exp_Strm is Build_Array_Read_Write_Procedure (Typ, Decl, Pnam, Name_Write); end Build_Array_Write_Procedure; - --------------------------------- - -- Build_Elementary_Input_Call -- - --------------------------------- + function Get_Primitives + (P_Type : Entity_Id; P_Size : Uint) return Primitive_Result + is - function Build_Elementary_Input_Call (N : Node_Id) return Node_Id is - Loc : constant Source_Ptr := Sloc (N); - P_Type : constant Entity_Id := Entity (Prefix (N)); - U_Type : constant Entity_Id := Underlying_Type (P_Type); - Rt_Type : constant Entity_Id := Root_Type (U_Type); - FST : constant Entity_Id := First_Subtype (U_Type); - Strm : constant Node_Id := First (Expressions (N)); - Targ : constant Node_Id := Next (Strm); - P_Size : constant Uint := Get_Stream_Size (FST); - Res : Node_Id; - Lib_RE : RE_Id; + function Prims (Input, Write : RE_Id) return Primitive_Result; + function Prims (Input, Write : RE_Id) return Primitive_Result is + begin + return (Primitives, 0, Input, Write); + end Prims; + function PSizes (L : Sizes) return Primitive_Result; + function PSizes (L : Sizes) return Primitive_Result is + begin + return (Possible_Sizes, L'Length, L); + end PSizes; + + U_Type : constant Entity_Id := Underlying_Type (P_Type); + FST : constant Entity_Id := First_Subtype (U_Type); + Rt_Type : constant Entity_Id := Root_Type (U_Type); + + Rep_Is_Standard : constant Boolean := + Known_RM_Size (U_Type) + and then Is_Stream_Standard_Rep (U_Type, P_Size); begin - -- Check first for Boolean and Character. These are enumeration types, - -- but we treat them specially, since they may require special handling - -- in the transfer protocol. However, this special handling only applies - -- if they have standard representation, otherwise they are treated like - -- any other enumeration type. - - if Rt_Type = Standard_Boolean - and then Has_Stream_Standard_Rep (U_Type) + if Rt_Type = Standard_Boolean and then Rep_Is_Standard then + return Prims (RE_I_B, RE_W_B); + elsif Rt_Type = Standard_Character and then Rep_Is_Standard then + return Prims (RE_I_C, RE_W_C); + elsif Rt_Type = Standard_Wide_Character and then Rep_Is_Standard then + return Prims (RE_I_WC, RE_W_WC); + elsif Rt_Type = Standard_Wide_Wide_Character and then Rep_Is_Standard then - Lib_RE := RE_I_B; - - elsif Rt_Type = Standard_Character - and then Has_Stream_Standard_Rep (U_Type) - then - Lib_RE := RE_I_C; - - elsif Rt_Type = Standard_Wide_Character - and then Has_Stream_Standard_Rep (U_Type) - then - Lib_RE := RE_I_WC; - - elsif Rt_Type = Standard_Wide_Wide_Character - and then Has_Stream_Standard_Rep (U_Type) - then - Lib_RE := RE_I_WWC; - - -- Floating point types - + return Prims (RE_I_WWC, RE_W_WWC); elsif Is_Floating_Point_Type (U_Type) then -- Question: should we use P_Size or Rt_Type to distinguish between @@ -500,23 +486,30 @@ package body Exp_Strm is -- To deal with these two requirements we add the special checks -- on equal sizes and use the root type to distinguish. - if P_Size <= Standard_Short_Float_Size + if P_Size = Standard_Short_Float_Size and then (Standard_Short_Float_Size /= Standard_Float_Size or else Rt_Type = Standard_Short_Float) then - Lib_RE := RE_I_SF; + return Prims (RE_I_SF, RE_W_SF); - elsif P_Size <= Standard_Float_Size then - Lib_RE := RE_I_F; + elsif P_Size = Standard_Float_Size then + return Prims (RE_I_F, RE_W_F); - elsif P_Size <= Standard_Long_Float_Size + elsif P_Size = Standard_Long_Float_Size and then (Standard_Long_Float_Size /= Standard_Long_Long_Float_Size - or else Rt_Type = Standard_Long_Float) + or else Rt_Type = Standard_Long_Float) then - Lib_RE := RE_I_LF; + return Prims (RE_I_LF, RE_W_LF); + elsif P_Size = Standard_Long_Long_Float_Size then + return Prims (RE_I_LLF, RE_W_LLF); else - Lib_RE := RE_I_LLF; + return + PSizes + ((Standard_Short_Float_Size, + Standard_Float_Size, + Standard_Long_Float_Size, + Standard_Long_Long_Float_Size)); end if; -- Signed integer types. Also includes signed fixed-point types and @@ -548,35 +541,42 @@ package body Exp_Strm is -- The following set of tests gets repeated many times, we should -- have an abstraction defined ??? - and then - (Is_Fixed_Point_Type (U_Type) - or else - Is_Enumeration_Type (U_Type) - or else - (Is_Signed_Integer_Type (U_Type) - and then not Has_Biased_Representation (FST))) + and then (Is_Fixed_Point_Type (U_Type) + or else Is_Enumeration_Type (U_Type) + or else (Is_Signed_Integer_Type (U_Type) + and then not Has_Biased_Representation (FST))) then - if P_Size <= Standard_Short_Short_Integer_Size then - Lib_RE := RE_I_SSI; + if P_Size = Standard_Short_Short_Integer_Size then + return Prims (RE_I_SSI, RE_W_SSI); - elsif P_Size <= Standard_Short_Integer_Size then - Lib_RE := RE_I_SI; + elsif P_Size = Standard_Short_Integer_Size then + return Prims (RE_I_SI, RE_W_SI); elsif P_Size = 24 then - Lib_RE := RE_I_I24; + return Prims (RE_I_I24, RE_W_I24); - elsif P_Size <= Standard_Integer_Size then - Lib_RE := RE_I_I; + elsif P_Size = Standard_Integer_Size then + return Prims (RE_I_I, RE_W_I); - elsif P_Size <= Standard_Long_Integer_Size then - Lib_RE := RE_I_LI; + elsif P_Size = Standard_Long_Integer_Size then + return Prims (RE_I_LI, RE_W_LI); - elsif P_Size <= Standard_Long_Long_Integer_Size then - Lib_RE := RE_I_LLI; + elsif P_Size = Standard_Long_Long_Integer_Size then + return Prims (RE_I_LLI, RE_W_LLI); + elsif P_Size = Standard_Long_Long_Long_Integer_Size then + return Prims (RE_I_LLLI, RE_W_LLLI); else - Lib_RE := RE_I_LLLI; + return + PSizes + ((Standard_Short_Short_Integer_Size, + Standard_Short_Integer_Size, + 24, + Standard_Integer_Size, + Standard_Long_Integer_Size, + Standard_Long_Long_Integer_Size, + Standard_Long_Long_Long_Integer_Size)); end if; -- Unsigned integer types, also includes unsigned fixed-point types @@ -586,41 +586,74 @@ package body Exp_Strm is -- Also includes signed integer types that are unsigned in the sense -- that they do not include negative numbers. See above for details. - elsif Is_Modular_Integer_Type (U_Type) - or else Is_Fixed_Point_Type (U_Type) - or else Is_Enumeration_Type (U_Type) + elsif Is_Modular_Integer_Type (U_Type) + or else Is_Fixed_Point_Type (U_Type) + or else Is_Enumeration_Type (U_Type) or else Is_Signed_Integer_Type (U_Type) then - if P_Size <= Standard_Short_Short_Integer_Size then - Lib_RE := RE_I_SSU; + if P_Size = Standard_Short_Short_Integer_Size then + return Prims (RE_I_SSU, RE_W_SSU); - elsif P_Size <= Standard_Short_Integer_Size then - Lib_RE := RE_I_SU; + elsif P_Size = Standard_Short_Integer_Size then + return Prims (RE_I_SU, RE_W_SU); elsif P_Size = 24 then - Lib_RE := RE_I_U24; + return Prims (RE_I_U24, RE_W_U24); - elsif P_Size <= Standard_Integer_Size then - Lib_RE := RE_I_U; + elsif P_Size = Standard_Integer_Size then + return Prims (RE_I_U, RE_W_U); - elsif P_Size <= Standard_Long_Integer_Size then - Lib_RE := RE_I_LU; + elsif P_Size = Standard_Long_Integer_Size then + return Prims (RE_I_LU, RE_W_LU); - elsif P_Size <= Standard_Long_Long_Integer_Size then - Lib_RE := RE_I_LLU; + elsif P_Size = Standard_Long_Long_Integer_Size then + return Prims (RE_I_LLU, RE_W_LLU); + + elsif P_Size = Standard_Long_Long_Long_Integer_Size then + return Prims (RE_I_LLLU, RE_W_LLLU); else - Lib_RE := RE_I_LLLU; + return + PSizes + ((Standard_Short_Short_Integer_Size, + Standard_Short_Integer_Size, + 24, + Standard_Integer_Size, + Standard_Long_Integer_Size, + Standard_Long_Long_Integer_Size, + Standard_Long_Long_Long_Integer_Size)); end if; else pragma Assert (Is_Access_Type (U_Type)); if Present (P_Size) and then P_Size > System_Address_Size then - Lib_RE := RE_I_AD; + return Prims (RE_I_AD, RE_W_AD); else - Lib_RE := RE_I_AS; + return Prims (RE_I_AS, RE_W_AS); end if; end if; + end Get_Primitives; + --------------------------------- + -- Build_Elementary_Input_Call -- + --------------------------------- + + function Build_Elementary_Input_Call (N : Node_Id) return Node_Id is + Loc : constant Source_Ptr := Sloc (N); + P_Type : constant Entity_Id := Entity (Prefix (N)); + U_Type : constant Entity_Id := Underlying_Type (P_Type); + FST : constant Entity_Id := First_Subtype (U_Type); + Strm : constant Node_Id := First (Expressions (N)); + Targ : constant Node_Id := Next (Strm); + P_Size : constant Uint := Get_Stream_Size (FST); + Res : Node_Id; + + Prims : constant Primitive_Result := Get_Primitives (P_Type, P_Size); + + Lib_RE : constant RE_Id := + (case Prims.S is + when Primitives => Prims.Input, + when others => raise Program_Error); + begin -- Call the function, and do an unchecked conversion of the result -- to the actual type of the prefix. If the target is a discriminant, -- and we are in the body of the default implementation of a 'Read @@ -679,191 +712,22 @@ package body Exp_Strm is function Build_Elementary_Write_Call (N : Node_Id) return Node_Id is Loc : constant Source_Ptr := Sloc (N); - P_Type : constant Entity_Id := Entity (Prefix (N)); - U_Type : constant Entity_Id := Underlying_Type (P_Type); - Rt_Type : constant Entity_Id := Root_Type (U_Type); - FST : constant Entity_Id := First_Subtype (U_Type); - Strm : constant Node_Id := First (Expressions (N)); - Item : constant Node_Id := Next (Strm); - P_Size : Uint; - Lib_RE : RE_Id; + P_Type : constant Entity_Id := Entity (Prefix (N)); + U_Type : constant Entity_Id := Underlying_Type (P_Type); + FST : constant Entity_Id := First_Subtype (U_Type); + Strm : constant Node_Id := First (Expressions (N)); + Item : constant Node_Id := Next (Strm); + P_Size : constant Uint := Get_Stream_Size (FST); Libent : Entity_Id; + Prims : constant Primitive_Result := Get_Primitives (P_Type, P_Size); + + Lib_RE : constant RE_Id := + (case Prims.S is + when Primitives => Prims.Write, + when others => raise Program_Error); begin - -- Compute the size of the stream element. This is either the size of - -- the first subtype or if given the size of the Stream_Size attribute. - - if Has_Stream_Size_Clause (FST) then - P_Size := Static_Integer (Expression (Stream_Size_Clause (FST))); - else - P_Size := Esize (FST); - end if; - - -- Find the routine to be called - - -- Check for First Boolean and Character. These are enumeration types, - -- but we treat them specially, since they may require special handling - -- in the transfer protocol. However, this special handling only applies - -- if they have standard representation, otherwise they are treated like - -- any other enumeration type. - - if Rt_Type = Standard_Boolean - and then Has_Stream_Standard_Rep (U_Type) - then - Lib_RE := RE_W_B; - - elsif Rt_Type = Standard_Character - and then Has_Stream_Standard_Rep (U_Type) - then - Lib_RE := RE_W_C; - - elsif Rt_Type = Standard_Wide_Character - and then Has_Stream_Standard_Rep (U_Type) - then - Lib_RE := RE_W_WC; - - elsif Rt_Type = Standard_Wide_Wide_Character - and then Has_Stream_Standard_Rep (U_Type) - then - Lib_RE := RE_W_WWC; - - -- Floating point types - - elsif Is_Floating_Point_Type (U_Type) then - - -- Question: should we use P_Size or Rt_Type to distinguish between - -- possible floating point types? If a non-standard size or a stream - -- size is specified, then we should certainly use the size. But if - -- we have two types the same (notably Short_Float_Size = Float_Size - -- which is close to universally true, and Long_Long_Float_Size = - -- Long_Float_Size, true on most targets except the x86), then we - -- would really rather use the root type, so that if people want to - -- fiddle with System.Stream_Attributes to get inter-target portable - -- streams, they get the size they expect. Consider in particular the - -- case of a stream written on an x86, with 96-bit Long_Long_Float - -- being read into a non-x86 target with 64 bit Long_Long_Float. A - -- special version of System.Stream_Attributes can deal with this - -- provided the proper type is always used. - - -- To deal with these two requirements we add the special checks - -- on equal sizes and use the root type to distinguish. - - if P_Size <= Standard_Short_Float_Size - and then (Standard_Short_Float_Size /= Standard_Float_Size - or else Rt_Type = Standard_Short_Float) - then - Lib_RE := RE_W_SF; - - elsif P_Size <= Standard_Float_Size then - Lib_RE := RE_W_F; - - elsif P_Size <= Standard_Long_Float_Size - and then (Standard_Long_Float_Size /= Standard_Long_Long_Float_Size - or else Rt_Type = Standard_Long_Float) - then - Lib_RE := RE_W_LF; - - else - Lib_RE := RE_W_LLF; - end if; - - -- Signed integer types. Also includes signed fixed-point types and - -- signed enumeration types share this circuitry. - - -- Note on signed integer types. We do not consider types as signed for - -- this purpose if they have no negative numbers, or if they have biased - -- representation. The reason is that the value in either case basically - -- represents an unsigned value. - - -- For example, consider: - - -- type W is range 0 .. 2**32 - 1; - -- for W'Size use 32; - - -- This is a signed type, but the representation is unsigned, and may - -- be outside the range of a 32-bit signed integer, so this must be - -- treated as 32-bit unsigned. - - -- Similarly, the representation is also unsigned if we have: - - -- type W is range -1 .. +254; - -- for W'Size use 8; - - -- forcing a biased and unsigned representation - - elsif not Is_Unsigned_Type (FST) - and then - (Is_Fixed_Point_Type (U_Type) - or else - Is_Enumeration_Type (U_Type) - or else - (Is_Signed_Integer_Type (U_Type) - and then not Has_Biased_Representation (FST))) - then - if P_Size <= Standard_Short_Short_Integer_Size then - Lib_RE := RE_W_SSI; - - elsif P_Size <= Standard_Short_Integer_Size then - Lib_RE := RE_W_SI; - - elsif P_Size = 24 then - Lib_RE := RE_W_I24; - - elsif P_Size <= Standard_Integer_Size then - Lib_RE := RE_W_I; - - elsif P_Size <= Standard_Long_Integer_Size then - Lib_RE := RE_W_LI; - - elsif P_Size <= Standard_Long_Long_Integer_Size then - Lib_RE := RE_W_LLI; - - else - Lib_RE := RE_W_LLLI; - end if; - - -- Unsigned integer types, also includes unsigned fixed-point types - -- and unsigned enumeration types (note we know they are unsigned - -- because we already tested for signed above). - - -- Also includes signed integer types that are unsigned in the sense - -- that they do not include negative numbers. See above for details. - - elsif Is_Modular_Integer_Type (U_Type) - or else Is_Fixed_Point_Type (U_Type) - or else Is_Enumeration_Type (U_Type) - or else Is_Signed_Integer_Type (U_Type) - then - if P_Size <= Standard_Short_Short_Integer_Size then - Lib_RE := RE_W_SSU; - - elsif P_Size <= Standard_Short_Integer_Size then - Lib_RE := RE_W_SU; - - elsif P_Size = 24 then - Lib_RE := RE_W_U24; - - elsif P_Size <= Standard_Integer_Size then - Lib_RE := RE_W_U; - - elsif P_Size <= Standard_Long_Integer_Size then - Lib_RE := RE_W_LU; - - elsif P_Size <= Standard_Long_Long_Integer_Size then - Lib_RE := RE_W_LLU; - - else - Lib_RE := RE_W_LLLU; - end if; - - else pragma Assert (Is_Access_Type (U_Type)); - - if Present (P_Size) and then P_Size > System_Address_Size then - Lib_RE := RE_W_AD; - else - Lib_RE := RE_W_AS; - end if; - end if; + pragma Assert (Prims.S = Primitives); -- Unchecked-convert parameter to the required type (i.e. the type of -- the corresponding parameter, and call the appropriate routine. @@ -871,12 +735,15 @@ package body Exp_Strm is Libent := RTE (Lib_RE); return - Make_Procedure_Call_Statement (Loc, - Name => New_Occurrence_Of (Libent, Loc), - Parameter_Associations => New_List ( - Relocate_Node (Strm), - Unchecked_Convert_To (Etype (Next_Formal (First_Formal (Libent))), - Relocate_Node (Item)))); + Make_Procedure_Call_Statement + (Loc, + Name => New_Occurrence_Of (Libent, Loc), + Parameter_Associations => + New_List + (Relocate_Node (Strm), + Unchecked_Convert_To + (Etype (Next_Formal (First_Formal (Libent))), + Relocate_Node (Item)))); end Build_Elementary_Write_Call; ----------------------------------------- @@ -1766,22 +1633,15 @@ package body Exp_Strm is -- Has_Stream_Standard_Rep -- ----------------------------- - function Has_Stream_Standard_Rep (U_Type : Entity_Id) return Boolean is - Siz : Uint; - + function Is_Stream_Standard_Rep + (U_Type : Entity_Id; S_Size : Uint) return Boolean is begin if Has_Non_Standard_Rep (U_Type) then return False; end if; - if Has_Stream_Size_Clause (U_Type) then - Siz := Static_Integer (Expression (Stream_Size_Clause (U_Type))); - else - Siz := Esize (First_Subtype (U_Type)); - end if; - - return Siz = Esize (Root_Type (U_Type)); - end Has_Stream_Standard_Rep; + return S_Size = Esize (Root_Type (U_Type)); + end Is_Stream_Standard_Rep; --------------------------------- -- Make_Stream_Subprogram_Name -- @@ -1827,5 +1687,4 @@ package body Exp_Strm is return Base_Type (E); end if; end Stream_Base_Type; - end Exp_Strm; diff --git a/gcc/ada/exp_strm.ads b/gcc/ada/exp_strm.ads index 733cf9c0dd19..54eded5d61df 100644 --- a/gcc/ada/exp_strm.ads +++ b/gcc/ada/exp_strm.ads @@ -26,7 +26,9 @@ -- Routines to build stream subprograms for composite types with Exp_Tss; use Exp_Tss; +with Rtsfind; use Rtsfind; with Types; use Types; +with Uintp; use Uintp; package Exp_Strm is @@ -138,4 +140,32 @@ package Exp_Strm is -- always null), and Pnam is the name of the constructed procedure. -- Used by Exp_Dist to generate stream-oriented attributes for RACWs. + type Status is (Primitives, Possible_Sizes); + + type Sizes is array (Positive range <>) of Nat; + + type Primitive_Result + (S : Status; + Len : Natural) + is record + case S is + when Primitives => + Input : RE_Id; + Write : RE_Id; + + when Possible_Sizes => + List : Sizes (1 .. Len); + end case; + end record; + + -------------------- + -- Get_Primitives -- + -------------------- + + function Get_Primitives + (P_Type : Entity_Id; P_Size : Uint) return Primitive_Result; + -- If P_Type supports a stream size of P_Size, returns the corresponding + -- input and write primitives. Otherwise, returns a list of the stream + -- sizes P_Type supports, in nondecreasing order and with possible + -- duplicates. end Exp_Strm; diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index 2166eb318d75..22fea0d02907 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -37,6 +37,7 @@ with Errid; use Errid; with Errout; use Errout; with Exp_Ch3; use Exp_Ch3; with Exp_Disp; use Exp_Disp; +with Exp_Strm; use Exp_Strm; with Exp_Tss; use Exp_Tss; with Exp_Util; use Exp_Util; with Expander; use Expander; @@ -8366,32 +8367,59 @@ package body Sem_Ch13 is if Duplicate_Clause then null; - + elsif No (Size) then + Error_Msg_N ("invalid argument for Stream_Size aspect", Nam); elsif Is_Elementary_Type (U_Ent) then - -- Size will be empty if we already detected an error - -- (e.g. Expr is of the wrong type); we might as well - -- give the useful hint below even in that case. - - if No (Size) or else - (Size /= System_Storage_Unit - and then Size /= System_Storage_Unit * 2 - and then Size /= System_Storage_Unit * 3 - and then Size /= System_Storage_Unit * 4 - and then Size /= System_Storage_Unit * 8) - then - Error_Msg_N - ("stream size for elementary type must be 8, 16, 24, " & - "32 or 64", N); - - elsif Known_RM_Size (U_Ent) and then RM_Size (U_Ent) > Size then - Error_Msg_Uint_1 := RM_Size (U_Ent); - Error_Msg_N - ("stream size for elementary type must be 8, 16, 24, " & - "32 or 64 and at least ^", N); - end if; - Set_Has_Stream_Size_Clause (U_Ent); + declare + Minimum_Size : constant Uint := + (if Known_RM_Size (U_Ent) + then RM_Size (U_Ent) + else Uint_0); + + Size_Or_Zero : constant Uint := + (if Size < Minimum_Size then Uint_0 else Size); + -- If the requested size is smaller than the RM size of the + -- type, we pass zero to Get_Primitives. That will always + -- give us the list of supported sizes we need to report an + -- error. + + P : constant Primitive_Result := + Get_Primitives (U_Ent, Size_Or_Zero); + + Error_Text : Bounded_String; + + In_First_Iteration : Boolean := True; + Previous_Value : Nat := 0; + begin + case P.S is + when Possible_Sizes => + Error_Msg_N ("unsupported stream size", N); + + Append + (Error_Text, + "\supported stream sizes for this type: "); + for Sz of P.List loop + if Minimum_Size <= Sz and then Sz /= Previous_Value + then + if In_First_Iteration then + In_First_Iteration := False; + else + Append (Error_Text, ", "); + end if; + + Append (Error_Text, Sz); + + Previous_Value := Sz; + end if; + end loop; + Error_Msg_N (To_String (Error_Text), N); + + when others => + null; + end case; + end; else Error_Msg_N ("Stream_Size cannot be given for &", Nam); end if;