From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id EA453384B112 for ; Tue, 7 May 2024 08:00:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EA453384B112 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 EA453384B112 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715068855; cv=none; b=Wc9Ol8S6exL+1HhucsRup6q4Ta+ik1yF+tkIka4KDHO5+aMcR4HDjwmdkf5fzlXEoikhEx8u39zSUI2ZU5gy7j6OUIOMaxgNkUOMCAu88K5PMZxKAqZ2PpHfSU+ST2wQePOWEG4cZDHIqILzJkfC4cqienSchorVUFh/LGau0VE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715068855; c=relaxed/simple; bh=NnliW9LbEdPYqDwvvgCRa8+243OAsw8ryLQaoAnjbtM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Whk6h0Oisxr0/+wjVswWavBFh1nQi06QJlfxkVYtvDdusV0pNVAQJI/rpYL1qqZjSz3GxpvfBvQCmRBr5DTGUL+D4aoXc6CPrt+rqy/OenKO8+bXI9VKFZVLSyNhlSSi8QPi7NQ9jDSPOVkaYtLIAzufgsTzXVHX0sV1p0JBvfM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-41dc9f98e8dso28445295e9.1 for ; Tue, 07 May 2024 01:00:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1715068831; x=1715673631; 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=55Hczv1DQ6ORjVniCmwrB0OWTnS2+B2fOZ1+YxryIIc=; b=LoaUdqKGNudX1en/B36p8ugpOhj8WJPqveWZBVs32WoVrdyl/R21fwouAKnN4PW9l/ VbbaRV/n6s33DJ+d29fA+i92gTJmDfz1eCYN1EmoKAvkoHGZh5nyM82XkPpzyB/ppmb3 wGl3e6xfLPEYDgtAPq27jKHdkkqYq5Kem7Rb0ZHqY5IN+y/6475iLSyOWW3Ai1MkVdrD ZQiWTnMOXPdaQg3tt7BU4a2KcVh3hhq+/nrNnPdjZkK+7A1X4pOgIAQjjINcfPsWuXRT n0LpsIlZkTSfUJD9Qaz2ILGwCpGU+Wex9lgnwOOzAcf06JJoEmeCe6vq742f8YrkOOCk KVtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715068831; x=1715673631; 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=55Hczv1DQ6ORjVniCmwrB0OWTnS2+B2fOZ1+YxryIIc=; b=lXPSR9U/A88kc/mS4LKQccxDI3l/NxLjYAuKyCquAlwuPVHtBCOw3EPX00Yt9ILH5S KbsEMsrJWWNprtp09kMuwwRE1aTshIR2mXcgiUB71Np7hVhYfd2Chd6f0w+5UhL9H3Lm YFJ1ixWbpfB3TsZkyApDmNDX71Iapb0nqKJ9WTJMxEGhDWptX3t5izpBa4AV7b9m5XYO O1+a+woV8lvTdF/SQLylMegiE8RWc7VmiHCEBpygYTXg63t/9EK3YW0p/+va+FB+3Dd6 aMHSh94MAY5dnmjALvWEzlA/uJQAMPYsEVh8DbfygeINJLX39WOPEdCdlvoHMyw4niAx tMrQ== X-Gm-Message-State: AOJu0Yw21ItBuQQDnmxDAhpDikS94IwroyYDzZjwj5K5v/FE6ONHRF3K +ol4GhUvcucVHCnvZD0E5MoJan7SfXuh7Vs4TvLblUFTjnWgrCtW93VFMLUVXX1bGjPNKlsWEgY = X-Google-Smtp-Source: AGHT+IHBkDUN6xIBPIE+VkLyeEJGhpgW4lbP13L2FyU4giaC54dxSjIWCDZ25JxP59CKTB28vA0G2Q== X-Received: by 2002:a5d:4911:0:b0:34e:de3b:3ccb with SMTP id x17-20020a5d4911000000b0034ede3b3ccbmr1613847wrq.14.1715068830749; Tue, 07 May 2024 01:00:30 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:11a6:1c9d:5099:b1e8]) by smtp.gmail.com with ESMTPSA id c12-20020adffb4c000000b0034f3e5452a5sm3735692wrs.1.2024.05.07.01.00.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 01:00:30 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED] ada: Fix detection of components with per-object constraints Date: Tue, 7 May 2024 10:00:29 +0200 Message-ID: <20240507080029.37744-1-poulhies@adacore.com> X-Mailer: git-send-email 2.43.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 List-Id: From: Piotr Trojanek Routine Contains_POC (where POC means "per-object constraint") was failing to detect expressions of the form "Current_Type'Access", because it was comparing prefix (typically an N_Identifier) with a scope (typically an N_Definining_Entity). This was harmless, because these expressions are detected anyway in Analyze_Access_Attribute, together with uses of 'Unconstrained_Access and 'Unchecked_Access. Also, this routine was failing to detect the use of discriminants in array types with constrained subtype indication, e.g.: type T (D : Integer) is record C : array (Integer range 1 .. D); end record; It is simpler to just reuse Has_Discriminant_Dependent_Constraint and leave detection of access attributes to Analyze_Access_Attribute. gcc/ada/ * sem_attr.adb (Analyze_Access_Attribute): Prevent search from going too far. * sem_ch3.adb (Analyze_Component_Declaration): Remove Contains_POC; reuse Has_Discriminant_Dependent_Constraint. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_attr.adb | 20 +++++++----- gcc/ada/sem_ch3.adb | 74 ++------------------------------------------ 2 files changed, 14 insertions(+), 80 deletions(-) diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb index c067d882048..c17f67356ef 100644 --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -1014,16 +1014,20 @@ package body Sem_Attr is Q : Node_Id := Parent (N); begin - while Present (Q) - and then Nkind (Q) /= N_Component_Declaration - loop + while Present (Q) loop + if Nkind (Q) = N_Component_Declaration then + Set_Has_Per_Object_Constraint + (Defining_Identifier (Q), True); + exit; + + -- Prevent the search from going too far + + elsif Is_Body_Or_Package_Declaration (Q) then + exit; + end if; + Q := Parent (Q); end loop; - - if Present (Q) then - Set_Has_Per_Object_Constraint - (Defining_Identifier (Q), True); - end if; end; if Nkind (P) = N_Expanded_Name then diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index 737ea809492..ad9e9317b15 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -1960,71 +1960,11 @@ package body Sem_Ch3 is T : Entity_Id; P : Entity_Id; - function Contains_POC (Constr : Node_Id) return Boolean; - -- Determines whether a constraint uses the discriminant of a record - -- type thus becoming a per-object constraint (POC). - function Is_Known_Limited (Typ : Entity_Id) return Boolean; -- Typ is the type of the current component, check whether this type is -- a limited type. Used to validate declaration against that of -- enclosing record. - ------------------ - -- Contains_POC -- - ------------------ - - function Contains_POC (Constr : Node_Id) return Boolean is - begin - -- Prevent cascaded errors - - if Error_Posted (Constr) then - return False; - end if; - - case Nkind (Constr) is - when N_Attribute_Reference => - return Attribute_Name (Constr) = Name_Access - and then Prefix (Constr) = Scope (Entity (Prefix (Constr))); - - when N_Discriminant_Association => - return Denotes_Discriminant (Expression (Constr)); - - when N_Identifier => - return Denotes_Discriminant (Constr); - - when N_Index_Or_Discriminant_Constraint => - declare - IDC : Node_Id; - - begin - IDC := First (Constraints (Constr)); - while Present (IDC) loop - - -- One per-object constraint is sufficient - - if Contains_POC (IDC) then - return True; - end if; - - Next (IDC); - end loop; - - return False; - end; - - when N_Range => - return Denotes_Discriminant (Low_Bound (Constr)) - or else - Denotes_Discriminant (High_Bound (Constr)); - - when N_Range_Constraint => - return Denotes_Discriminant (Range_Expression (Constr)); - - when others => - return False; - end case; - end Contains_POC; - ---------------------- -- Is_Known_Limited -- ---------------------- @@ -2208,18 +2148,8 @@ package body Sem_Ch3 is -- The component declaration may have a per-object constraint, set -- the appropriate flag in the defining identifier of the subtype. - if Present (Subtype_Indication (Component_Definition (N))) then - declare - Sindic : constant Node_Id := - Subtype_Indication (Component_Definition (N)); - begin - if Nkind (Sindic) = N_Subtype_Indication - and then Present (Constraint (Sindic)) - and then Contains_POC (Constraint (Sindic)) - then - Set_Has_Per_Object_Constraint (Id); - end if; - end; + if Has_Discriminant_Dependent_Constraint (Id) then + Set_Has_Per_Object_Constraint (Id); end if; -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry -- 2.43.2