From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by sourceware.org (Postfix) with ESMTPS id 46C0F3858D3C for ; Mon, 20 May 2024 07:49:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 46C0F3858D3C 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 46C0F3858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::235 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716191376; cv=none; b=rIQh+l9bR5n40kRn0DqLLWaAWFl38LwQ6U7eyXoqzcfVjtjvzbeDO+IXW0GpTMXajPyPFkBWOd8Yw/qrA2M01XGMhwWDwsSekWgd9xWtEgRKCMNeSXB6Hf1w+THhqKlg2K49tjgqMe3SL2Nt6K8ukdILfb/Yvmcy4Nk5sCM6aHI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716191376; c=relaxed/simple; bh=a0i047vI7DKs9UYO1++PwcHwOaW+xOINoESLueOHTdk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=LyS8b7ShM0asgeS192DpjwwCO1hDvzUdgwzxz99kRWheI8t+zgJ45e8j3RwqXO/zMfRbu2XWB88wLEB+bCIMq7KVXgd1WxQkaXjTN/vyhoeYFxHa3UkJec2DAzESRFnq2hVJBj/oRoxWxMPLhTue5a+2er+IZsT8/3rErlXy4ao= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2e271acb015so51303681fa.1 for ; Mon, 20 May 2024 00:49:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1716191370; x=1716796170; 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=VZKE3Ym66cYZswVKXmUH34AHDsGWB9rRvUg/w6gJDWQ=; b=i1AXpYCBt+OFLKWmOeLEdAmurP3gmWi4cjwiNV3UuNGhtgcf2wgCzOBctvnsURWszx W5c2LwopChDaCkmB0rOMLg+7LoaxmxH9l92LTtXTORIx2JlsEDul2LckImGxlHEiTYnR 4hsp+iEpeRt/QLL0rL4SZMo7qEo2zCfQ8OhduP0Zbsb4KSh/Mme8JXKdUveqT9uoOBC6 ud+bB6WlBwxTR+NgDx7ivKyj0Jf2JoWPg//ExqHp6zIg17U9kvqX+q/YYiqvf93yjrbk KpV/07XdTLli6CjyqNj7jJ9nvFT+sZ1jvbwOenZSoYHRlqj9EVHlYu2eiCbTXUCBX8CI JclA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716191370; x=1716796170; 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=VZKE3Ym66cYZswVKXmUH34AHDsGWB9rRvUg/w6gJDWQ=; b=CPAf91HE7Sc6C7x3hJu/tZGfWU490YDG+8JZKEvgkPFNoGsMoo9YJ87pKJ2f//MIww si5RUEP8cvMgyyQ4At+f2xEb78ZaJssx3FIb6WX/R4fmrIkFsk+fszArmGQUll65IvUq +HdIVOdFHUG0couL61GP0pB7fnM924QtIBoEomCCusV+QQVHlR72bzQvsDv8Yh5LPtBv ojtDL5gERlUZr7cOVFG1mh2+g/bzt5K+3maVjLKdZlGXL/xb6qMqOboW/czBClafkPr7 jsSjpdHVBUnotbOAmMOj/+f0PZH4ylH+WuwiPcUBSXHM4xD1+vu3U/7G0PsSK2PvvY2M Afag== X-Gm-Message-State: AOJu0Yydq/kP6BcQAfn+bHprnYG3Ub0i2V+4W0KExWTGBK+If4bonfk9 SZEBjE0H+O9JKX5y1rgLCuQx70uY1nrdCHWQwcBHZJ8suus8ThKzGkIdcMFYcED5WaO0rs62Ycs = X-Google-Smtp-Source: AGHT+IFBSPYsB+Ra87gDh1SM/KROaoVZZ+p+c5666tJvO9LnHWFDuFytAnC8AjlznU2EojVKIQ9pEg== X-Received: by 2002:a05:651c:1415:b0:2e3:bb5a:bef with SMTP id 38308e7fff4ca-2e5204aee02mr166347051fa.48.1716191369832; Mon, 20 May 2024 00:49:29 -0700 (PDT) Received: from poulhies-Precision-5550.lan ([2001:861:3382:1a90:de37:8b1c:1f33:2610]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41f88111033sm446892175e9.34.2024.05.20.00.49.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 00:49:29 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Gary Dismukes Subject: [COMMITTED 23/30] ada: Error on instantiation of generic containing legal container aggregate Date: Mon, 20 May 2024 09:48:49 +0200 Message-ID: <20240520074858.222435-23-poulhies@adacore.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240520074858.222435-1-poulhies@adacore.com> References: <20240520074858.222435-1-poulhies@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.9 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 List-Id: From: Gary Dismukes When a container aggregate for a predefined container type (such as a Vector type) that has an iterated component association occurs within a generic unit and that generic is instantiated, the compiler reports a spurious error message "iterated component association can only appear in an array aggregate" and the compilation aborts (because Unrecoverable_Error is raised unconditionally after that error). The problem is that as part of the instantiation process, for aggregates whose type has a partial view, in Copy_Generic_Node the compiler switches the visibility so that the full view of the type is available, and for a type whose full view is a record type this leads to incorrectly trying to process the aggregate as a record aggregate in Resolve_Aggregate (making a call to Resolve_Record_Aggregate). Rather than trying to address this by changing what Copy_Generic_Node does, this can be fixed by reordering and adjusting the code in Resolve_Aggregate, so that we first test whether we need to resolve as a record aggregate (if the aggregate is not homogeneous), followed by testing whether the type has an Aggregate aspect and calling Resolve_Container_Aggregate. As a bonus, we also remove the subsequent complex condition and redundant code for handling null container aggregates. gcc/ada/ * sem_aggr.adb (Resolve_Aggregate): Move condition and call for Resolve_Record_Aggregate in front of code related to calling Resolve_Container_Aggregate (and add test that the aggregate is not homogeneous), and remove special-case testing and call to Resolve_Container_Aggregate for empty aggregates. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_aggr.adb | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb index 658b3a4634c..6e40e5c2564 100644 --- a/gcc/ada/sem_aggr.adb +++ b/gcc/ada/sem_aggr.adb @@ -1182,8 +1182,12 @@ package body Sem_Aggr is elsif Is_Array_Type (Typ) and then Null_Record_Present (N) then Error_Msg_N ("null record forbidden in array aggregate", N); + elsif Is_Record_Type (Typ) + and then not Is_Homogeneous_Aggregate (N) + then + Resolve_Record_Aggregate (N, Typ); + elsif Has_Aspect (Typ, Aspect_Aggregate) - and then Ekind (Typ) /= E_Record_Type and then Ada_Version >= Ada_2022 then -- Check for Ada 2022 and () aggregate. @@ -1194,22 +1198,6 @@ package body Sem_Aggr is Resolve_Container_Aggregate (N, Typ); - -- Check Ada 2022 empty aggregate [] initializing a record type that has - -- aspect aggregate; the empty aggregate will be expanded into a call to - -- the empty function specified in the aspect aggregate. - - elsif Has_Aspect (Typ, Aspect_Aggregate) - and then Ekind (Typ) = E_Record_Type - and then Is_Homogeneous_Aggregate (N) - and then Is_Empty_List (Expressions (N)) - and then Is_Empty_List (Component_Associations (N)) - and then Ada_Version >= Ada_2022 - then - Resolve_Container_Aggregate (N, Typ); - - elsif Is_Record_Type (Typ) then - Resolve_Record_Aggregate (N, Typ); - elsif Is_Array_Type (Typ) then -- First a special test, for the case of a positional aggregate of -- 2.43.2