From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 205E1386180C for ; Tue, 9 Jan 2024 13:15:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 205E1386180C 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 205E1386180C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::334 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704806144; cv=none; b=R9+p+cO/Jm3/gRnySf93fzITDLuzXPJUgPgOlIDcqVh7OgfNyB/4rIUDCBCJLsTEBcZZZ68qKGQEhnSTRZ/akL3sm3yVy3VIH+4KZafsbQNPwyBC4RJjRRXTEmLJRdlfP1C3gMLnB55JIbqFk60FZ+tFXDBMLdW9c2JzrXP9fP0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704806144; c=relaxed/simple; bh=XWlug7E5B92ayNK7OTT7dCw6yX4zvx2M/pTh7OPtTLc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=EZvLyBZd/7X1ONAtqWkNj/DeqI70622zMH2FA18KgJgegCALvEJNV+pR1oK8mOlaQHvDnNUEyE8UC+0eVUnquinidQBg4aKgJWg4M+ofySeQfAGdqVNUZz9TltTkyZSj7euAaVJsVlmuoGmSlWV85tar94FDMGhfdYpLjM39UUM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40e490c2115so10585125e9.0 for ; Tue, 09 Jan 2024 05:15:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1704806135; x=1705410935; 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=Xe5We+PtWYKLIGCvgc/I8/bDNWqtJRf2PLc+IwHP7SY=; b=gEz/3Qipx1XE6CTkaHmvnbxdTl67ogv/PI7eiBeGI0q71nO9sshi+iU1ZRBo4CvRVO GD5RLqs0fRF4WAJfz3RgUK133WTFwS6Bm4W6ykT8k2gtwH5iP2y4/oCykr80coK419MY wN3KviwFMt7bmOFtFAJfKbuE5rWdMPvjpm/eSF3nFZTtUYpgAvV1Usa5PnNTZCTTZUc5 vTzyKYjo9SvhK+6L5Aj2hBWj4Ms8U7+J80PjEzsMDKIAcYI7QD4mNXLrluaOb9DNh7bO U3YM/bn+3akuTc5W9vFaVqdgYxRxkoJz3Yif7CbYyNePQ1D3rsZ8tKu9cEpOgL70e405 xljw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704806135; x=1705410935; 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=Xe5We+PtWYKLIGCvgc/I8/bDNWqtJRf2PLc+IwHP7SY=; b=bNfNIuN2qYP8+Jcyt5SQKByiiafJNuyaoyA8z59h7Kur1j/niLtRnY9BR22UkuDa1E 5LQmXaMOvBXS75FEZClkgYi2j8m/nGiIAS6SkRBDw8W7ISq33FAtfbFJt3eTcPIJfV06 tCGUZ4sMgmKWGxiV6pStpkXsjS3r3DZ99MXassUtyhVOAovBhM/aS6aoK/4ICfKIS2HP OMq7W6NQEkAcVpkVaZKQYUnI3JD8ilCgUg/t1tlOU92ItrYlObzaiFSPtf8sbM/1WCl3 3vUcHQcyaRXw1Zt6o6tg8ndcniChP8uVV3bL1IGRN7l4w5yVwKmdBqto5M0PX5RMS/RB fApA== X-Gm-Message-State: AOJu0Yxgu16T41ERO8UFjgmtQ/l7qDBD7ic4HEXklg1taqq22rYi0Psk y8IW37cnooz/dUykbSVdgpnJQ6MkEkY845NJpOJIXxsLaw== X-Google-Smtp-Source: AGHT+IFR6EIANl846h0nwtat3mxfRNV4Fm+iljY3pAnH6WcZrZjN4TiLt7HY5kD84Vroa2ud7DDG5w== X-Received: by 2002:a05:600c:4ecd:b0:40e:362c:bd98 with SMTP id g13-20020a05600c4ecd00b0040e362cbd98mr432594wmq.116.1704806134937; Tue, 09 Jan 2024 05:15:34 -0800 (PST) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id h4-20020a05600c314400b0040d7c3d5454sm14696695wmo.3.2024.01.09.05.15.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 05:15:34 -0800 (PST) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Steve Baird Subject: [COMMITTED] ada: Error compiling Ada 2022 object renaming with no subtype mark Date: Tue, 9 Jan 2024 14:15:33 +0100 Message-ID: <20240109131533.744010-1-poulhies@adacore.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.6 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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Steve Baird In some cases the compiler would crash or generate spurious errors compiling a legal object renaming declaration that lacks a subtype mark. In addition to fixing the immediate problem, change Atree.Copy_Slots so that attempts to modify either the Empty or the Error nodes (e.g., by passing one of them as the target in a call to Rewrite) are ineffective. Cope with the consequences of this. gcc/ada/ * sem_ch8.adb (Check_Constrained_Object): Before updating the subtype mark of an object renaming declaration by calling Rewrite, first check whether the destination of the Rewrite call exists. * atree.adb (Copy_Slots): Return without performing any updates if Destination equals Empty or Error, or if Source equals Empty. Any of those conditions indicates an error case. * sem_ch12.adb (Analyze_Formal_Derived_Type): Avoid cascading errors. * sem_ch3.adb (Analyze_Number_Declaration): In an error case, do not pass Error as destination in a call to Rewrite. (Find_Type_Of_Subtype_Indic): In an error case, do not pass Error or Empty as destination in a call to Rewrite. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/atree.adb | 16 +++++++++++++--- gcc/ada/sem_ch12.adb | 6 ++++++ gcc/ada/sem_ch3.adb | 14 ++++++++------ gcc/ada/sem_ch8.adb | 14 +++++++++++++- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/gcc/ada/atree.adb b/gcc/ada/atree.adb index f265526afb7..7a55b18c605 100644 --- a/gcc/ada/atree.adb +++ b/gcc/ada/atree.adb @@ -1260,9 +1260,9 @@ package body Atree is end if; end Change_Node; - ---------------- - -- Copy_Slots -- - ---------------- + ------------------------ + -- Copy_Dynamic_Slots -- + ------------------------ procedure Copy_Dynamic_Slots (From, To : Node_Offset; Num_Slots : Slot_Count) @@ -1282,6 +1282,10 @@ package body Atree is Destination_Slots := Source_Slots; end Copy_Dynamic_Slots; + ---------------- + -- Copy_Slots -- + ---------------- + procedure Copy_Slots (Source, Destination : Node_Id) is pragma Debug (Validate_Node (Source)); pragma Assert (Source /= Destination); @@ -1292,6 +1296,12 @@ package body Atree is Node_Offsets.Table (Node_Offsets.First .. Node_Offsets.Last); begin + -- Empty_Or_Error use as described in types.ads + if Destination <= Empty_Or_Error or No (Source) then + pragma Assert (Serious_Errors_Detected > 0); + return; + end if; + Copy_Dynamic_Slots (Off_F (Source), Off_F (Destination), S_Size); All_Node_Offsets (Destination).Slots := All_Node_Offsets (Source).Slots; diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb index d2285082f97..5bddb5a8556 100644 --- a/gcc/ada/sem_ch12.adb +++ b/gcc/ada/sem_ch12.adb @@ -2541,6 +2541,12 @@ package body Sem_Ch12 is end if; end if; + if Subtype_Mark (Def) <= Empty_Or_Error then + pragma Assert (Serious_Errors_Detected > 0); + -- avoid passing bad argument to Entity + return; + end if; + -- If the parent type has a known size, so does the formal, which makes -- legal representation clauses that involve the formal. diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index a6bc8c95cd2..70cf772edcc 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -3668,7 +3668,7 @@ package body Sem_Ch3 is -------------------------------- procedure Analyze_Number_Declaration (N : Node_Id) is - E : constant Node_Id := Expression (N); + E : Node_Id := Expression (N); Id : constant Entity_Id := Defining_Identifier (N); Index : Interp_Index; It : Interp; @@ -3694,14 +3694,13 @@ package body Sem_Ch3 is Set_Is_Pure (Id, Is_Pure (Current_Scope)); - -- Process expression, replacing error by integer zero, to avoid - -- cascaded errors or aborts further along in the processing - -- Replace Error by integer zero, which seems least likely to cause -- cascaded errors. if E = Error then - Rewrite (E, Make_Integer_Literal (Sloc (E), Uint_0)); + pragma Assert (Serious_Errors_Detected > 0); + E := Make_Integer_Literal (Sloc (N), Uint_0); + Set_Expression (N, E); Set_Error_Posted (E); end if; @@ -18615,7 +18614,10 @@ package body Sem_Ch3 is -- Otherwise we have a subtype mark without a constraint elsif Error_Posted (S) then - Rewrite (S, New_Occurrence_Of (Any_Id, Sloc (S))); + -- Don't rewrite if S is Empty or Error + if S > Empty_Or_Error then + Rewrite (S, New_Occurrence_Of (Any_Id, Sloc (S))); + end if; return Any_Type; else diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb index 2e6b1b6d785..5408be3e1a5 100644 --- a/gcc/ada/sem_ch8.adb +++ b/gcc/ada/sem_ch8.adb @@ -861,7 +861,19 @@ package body Sem_Ch8 is Defining_Identifier => Subt, Subtype_Indication => Make_Subtype_From_Expr (Nam, Typ))); - Rewrite (Subtype_Mark (N), New_Occurrence_Of (Subt, Loc)); + + declare + New_Subtype_Mark : constant Node_Id := + New_Occurrence_Of (Subt, Loc); + begin + if Present (Subtype_Mark (N)) then + Rewrite (Subtype_Mark (N), New_Subtype_Mark); + else + -- An Ada2022 renaming with no subtype mark + Set_Subtype_Mark (N, New_Subtype_Mark); + end if; + end; + Set_Etype (Nam, Subt); -- Suppress discriminant checks on this subtype if the original -- 2.43.0