From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 65A5E3835413 for ; Wed, 11 May 2022 08:54:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 65A5E3835413 Received: by mail-wm1-x335.google.com with SMTP id r188-20020a1c44c5000000b003946c466c17so129319wma.4 for ; Wed, 11 May 2022 01:54:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=5qTx6FQ5q/GNLgVHKMK+oLL7vkBuXVw9vnujt6z8oTg=; b=aaQ6Rpz5dPsDVQuQsr/hIbEdNUUgrWecenoLFiNIzHEheqJxI1oh9btTx+psb/CtwS D9CRC0O+KxkQF23Le8sofS4zJ1JoHunUDiUKXYE7e6BNXZSB8Eholsv4oCWsjCeC4pQg zQaLMSqSRJKF7hC4gCFzxbN8koDnpdcmwH9D4P/3ZLgz6LCOdSKqjC8nLgoIxyptrqGy tchgW75WnBNyjiDZcCrZAbiuQv3cVH/hJo+FPX7HKclBEaVJD3qQb3ohTiiFCNKosDDm shsh7RFDv/SaG7tjI8FGJOS0XUMzEF3OO9KXXrV0heyOO9/Gbz1nkB6MrrkQpSsVA5SU kBLQ== X-Gm-Message-State: AOAM530SeA3qpFJaSZH7YRRSCAGeTs0pAnrcljCXoLtWYe6cjyyn4z+S Kx1xHTsj/DRJnVF59IU+Wf90idJhfSLU5w== X-Google-Smtp-Source: ABdhPJy47+qszAxEm985xNxvMV8PotXzjoZuQkxHqPh7SxQAoTBwQl3CZwBIZ8+zvh3zyJO5io9w5Q== X-Received: by 2002:a7b:c419:0:b0:393:fc45:c7ac with SMTP id k25-20020a7bc419000000b00393fc45c7acmr3771120wmi.90.1652259285943; Wed, 11 May 2022 01:54:45 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id o8-20020adfa108000000b0020c5253d8fbsm1133294wro.71.2022.05.11.01.54.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 01:54:45 -0700 (PDT) Date: Wed, 11 May 2022 08:54:45 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Subject: [Ada] Correctly reject record aggregate using brackets Message-ID: <20220511085445.GA2167899@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="GvXjxJ+pjyke8COw" Content-Disposition: inline X-Spam-Status: No, score=-13.2 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 May 2022 08:54:48 -0000 --GvXjxJ+pjyke8COw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Ada 2022 bracket syntax is only allowed for arrays and containers, not records. This change correctly rejects record aggregates using brackets along with few cases of brackets being used instead of parentheses. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * libgnat/a-direct.adb (Start_Search_Internal): Use parentheses for record aggregate. * libgnat/a-stbubo.adb (Get_UTF_8): Likewise. * libgnat/a-stbuun.adb (Get_UTF_8): Likewise. * libgnat/a-stzbou.ads (Null_Bounded_Wide_Wide_String): Likewise. * libgnat/a-swmwco.ads (Lower_Case_Mapping, Basic_Mapping): Likewise. * libgnat/a-szmzco.ads (Lower_Case_Mapping, Basic_Mapping): Likewise. * libgnat/s-statxd.adb (Fields): Likewise. * libgnat/s-stausa.adb (Initialize): Likewise. * sem_aggr.adb (Resolve_Record_Aggregate): Reject aggregates using brackets. --GvXjxJ+pjyke8COw Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/libgnat/a-direct.adb b/gcc/ada/libgnat/a-direct.adb --- a/gcc/ada/libgnat/a-direct.adb +++ b/gcc/ada/libgnat/a-direct.adb @@ -1404,11 +1404,11 @@ package body Ada.Directories is if Error /= 0 then Search.State.Dir_Contents.Append (Directory_Entry_Type' - [Valid => True, + (Valid => True, Name => To_Unbounded_String (File_Name), Full_Name => To_Unbounded_String (Path), Attr_Error_Code => Error, - others => <>]); + others => <>)); -- Otherwise, if the file exists and matches the file kind -- Filter, add the file to the search results. We capture @@ -1445,14 +1445,14 @@ package body Ada.Directories is if Found then Search.State.Dir_Contents.Append (Directory_Entry_Type' - [Valid => True, + (Valid => True, Name => To_Unbounded_String (File_Name), Full_Name => To_Unbounded_String (Path), Attr_Error_Code => 0, Kind => Kind, Modification_Time => Modification_Time (Path), - Size => Size]); + Size => Size)); end if; end if; end; diff --git a/gcc/ada/libgnat/a-stbubo.adb b/gcc/ada/libgnat/a-stbubo.adb --- a/gcc/ada/libgnat/a-stbubo.adb +++ b/gcc/ada/libgnat/a-stbubo.adb @@ -91,9 +91,9 @@ package body Ada.Strings.Text_Buffers.Bounded is -- forget to add corresponding assignment statement below. Dummy : array (1 .. 0) of Buffer_Type (0) := [others => - [Max_Characters => 0, Chars => <>, Indentation => <>, + (Max_Characters => 0, Chars => <>, Indentation => <>, Indent_Pending => <>, UTF_8_Length => <>, UTF_8_Column => <>, - All_7_Bits => <>, All_8_Bits => <>, Truncated => <>]]; + All_7_Bits => <>, All_8_Bits => <>, Truncated => <>)]; begin Buffer.Indentation := Defaulted.Indentation; Buffer.Indent_Pending := Defaulted.Indent_Pending; diff --git a/gcc/ada/libgnat/a-stbuun.adb b/gcc/ada/libgnat/a-stbuun.adb --- a/gcc/ada/libgnat/a-stbuun.adb +++ b/gcc/ada/libgnat/a-stbuun.adb @@ -104,9 +104,9 @@ package body Ada.Strings.Text_Buffers.Unbounded is -- forget to add corresponding assignment statement below. Dummy : array (1 .. 0) of Buffer_Type := [others => - [Indentation => <>, Indent_Pending => <>, UTF_8_Length => <>, + (Indentation => <>, Indent_Pending => <>, UTF_8_Length => <>, UTF_8_Column => <>, All_7_Bits => <>, All_8_Bits => <>, - List => <>, Last_Used => <>]]; + List => <>, Last_Used => <>)]; begin Buffer.Indentation := Defaulted.Indentation; Buffer.Indent_Pending := Defaulted.Indent_Pending; diff --git a/gcc/ada/libgnat/a-stzbou.ads b/gcc/ada/libgnat/a-stzbou.ads --- a/gcc/ada/libgnat/a-stzbou.ads +++ b/gcc/ada/libgnat/a-stzbou.ads @@ -493,11 +493,11 @@ package Ada.Strings.Wide_Wide_Bounded is -- the Wide_Wide_Superbounded package. Null_Bounded_Wide_Wide_String : constant Bounded_Wide_Wide_String := - [Max_Length => Max_Length, + (Max_Length => Max_Length, Current_Length => 0, Data => [1 .. Max_Length => - Wide_Wide_Superbounded.Wide_Wide_NUL]]; + Wide_Wide_Superbounded.Wide_Wide_NUL]); pragma Inline (To_Bounded_Wide_Wide_String); diff --git a/gcc/ada/libgnat/a-swmwco.ads b/gcc/ada/libgnat/a-swmwco.ads --- a/gcc/ada/libgnat/a-swmwco.ads +++ b/gcc/ada/libgnat/a-swmwco.ads @@ -181,7 +181,7 @@ private Character_Ranges'Unrestricted_Access); Lower_Case_Mapping : aliased constant Wide_Character_Mapping_Values := - [Length => 56, + (Length => 56, Domain => "ABCDEFGHIJKLMNOPQRSTUVWXYZ" & @@ -247,14 +247,14 @@ private W.LC_U_Circumflex & W.LC_U_Diaeresis & W.LC_Y_Acute & - W.LC_Icelandic_Thorn]; + W.LC_Icelandic_Thorn); Lower_Case_Map : constant Wide_Character_Mapping := (AF.Controlled with Map => Lower_Case_Mapping'Unrestricted_Access); Upper_Case_Mapping : aliased constant Wide_Character_Mapping_Values := - [Length => 56, + (Length => 56, Domain => "abcdefghijklmnopqrstuvwxyz" & @@ -320,14 +320,14 @@ private W.UC_U_Circumflex & W.UC_U_Diaeresis & W.UC_Y_Acute & - W.UC_Icelandic_Thorn]; + W.UC_Icelandic_Thorn); Upper_Case_Map : constant Wide_Character_Mapping := (AF.Controlled with Upper_Case_Mapping'Unrestricted_Access); Basic_Mapping : aliased constant Wide_Character_Mapping_Values := - [Length => 55, + (Length => 55, Domain => W.UC_A_Grave & @@ -441,7 +441,7 @@ private 'u' & -- LC_U_Circumflex 'u' & -- LC_U_Diaeresis 'y' & -- LC_Y_Acute - 'y']; -- LC_Y_Diaeresis + 'y'); -- LC_Y_Diaeresis Basic_Map : constant Wide_Character_Mapping := (AF.Controlled with diff --git a/gcc/ada/libgnat/a-szmzco.ads b/gcc/ada/libgnat/a-szmzco.ads --- a/gcc/ada/libgnat/a-szmzco.ads +++ b/gcc/ada/libgnat/a-szmzco.ads @@ -181,7 +181,7 @@ private Character_Ranges'Unrestricted_Access); Lower_Case_Mapping : aliased constant Wide_Wide_Character_Mapping_Values := - [Length => 56, + (Length => 56, Domain => "ABCDEFGHIJKLMNOPQRSTUVWXYZ" & @@ -247,14 +247,14 @@ private W.LC_U_Circumflex & W.LC_U_Diaeresis & W.LC_Y_Acute & - W.LC_Icelandic_Thorn]; + W.LC_Icelandic_Thorn); Lower_Case_Map : constant Wide_Wide_Character_Mapping := (AF.Controlled with Map => Lower_Case_Mapping'Unrestricted_Access); Upper_Case_Mapping : aliased constant Wide_Wide_Character_Mapping_Values := - [Length => 56, + (Length => 56, Domain => "abcdefghijklmnopqrstuvwxyz" & @@ -320,14 +320,14 @@ private W.UC_U_Circumflex & W.UC_U_Diaeresis & W.UC_Y_Acute & - W.UC_Icelandic_Thorn]; + W.UC_Icelandic_Thorn); Upper_Case_Map : constant Wide_Wide_Character_Mapping := (AF.Controlled with Upper_Case_Mapping'Unrestricted_Access); Basic_Mapping : aliased constant Wide_Wide_Character_Mapping_Values := - [Length => 55, + (Length => 55, Domain => W.UC_A_Grave & @@ -441,7 +441,7 @@ private 'u' & -- LC_U_Circumflex 'u' & -- LC_U_Diaeresis 'y' & -- LC_Y_Acute - 'y']; -- LC_Y_Diaeresis + 'y'); -- LC_Y_Diaeresis Basic_Map : constant Wide_Wide_Character_Mapping := (AF.Controlled with diff --git a/gcc/ada/libgnat/s-statxd.adb b/gcc/ada/libgnat/s-statxd.adb --- a/gcc/ada/libgnat/s-statxd.adb +++ b/gcc/ada/libgnat/s-statxd.adb @@ -76,36 +76,36 @@ package body System.Stream_Attributes.XDR is -- Single precision - [E_Size => 8, + (E_Size => 8, E_Bias => 127, F_Size => 23, E_Last => 2 ** 8 - 1, F_Mask => 16#7F#, -- 2 ** 7 - 1, E_Bytes => 2, F_Bytes => 3, - F_Bits => 23 mod US], + F_Bits => 23 mod US), -- Double precision - [E_Size => 11, + (E_Size => 11, E_Bias => 1023, F_Size => 52, E_Last => 2 ** 11 - 1, F_Mask => 16#0F#, -- 2 ** 4 - 1, E_Bytes => 2, F_Bytes => 7, - F_Bits => 52 mod US], + F_Bits => 52 mod US), -- Quadruple precision - [E_Size => 15, + (E_Size => 15, E_Bias => 16383, F_Size => 112, E_Last => 2 ** 8 - 1, F_Mask => 16#FF#, -- 2 ** 8 - 1, E_Bytes => 2, F_Bytes => 14, - F_Bits => 112 mod US]]; + F_Bits => 112 mod US)]; -- The representation of all items requires a multiple of four bytes -- (or 32 bits) of data. The bytes are numbered 0 through n-1. The bytes diff --git a/gcc/ada/libgnat/s-stausa.adb b/gcc/ada/libgnat/s-stausa.adb --- a/gcc/ada/libgnat/s-stausa.adb +++ b/gcc/ada/libgnat/s-stausa.adb @@ -128,9 +128,9 @@ package body System.Stack_Usage is Result_Array := new Result_Array_Type (1 .. Buffer_Size); Result_Array.all := [others => - [Task_Name => [others => ASCII.NUL], + (Task_Name => [others => ASCII.NUL], Value => 0, - Stack_Size => 0]]; + Stack_Size => 0)]; -- Set the Is_Enabled flag to true, so that the task wrapper knows that -- it has to handle dynamic stack analysis diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb --- a/gcc/ada/sem_aggr.adb +++ b/gcc/ada/sem_aggr.adb @@ -4896,6 +4896,15 @@ package body Sem_Aggr is return; end if; + -- A record aggregate can only use parentheses + + if Nkind (N) = N_Aggregate + and then Is_Homogeneous_Aggregate (N) + then + Error_Msg_N ("record aggregate must use () and not '[']", N); + return; + end if; + -- STEP 2: Verify aggregate structure Step_2 : declare --GvXjxJ+pjyke8COw--