[COMMITTED,24/30] ada: Error on instantiation of generic containing legal container aggregate
Message ID | 20240520074858.222435-24-poulhies@adacore.com |
---|---|
State | Committed |
Commit | a74dff4d9d0b26e91d02acb81e9ed2e34d0d38e9 |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> 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 7AEAA3858CDB for <patchwork@sourceware.org>; Mon, 20 May 2024 07:55:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id BD9BB3858C98 for <gcc-patches@gcc.gnu.org>; Mon, 20 May 2024 07:49:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BD9BB3858C98 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 BD9BB3858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716191376; cv=none; b=W6AVQ6iWx0LwOTAqFA8QQnziOyC9RnU0/+c8xcglhZgCG8x5+4Ptg1Vm+/mEXzNWMsZJFKQybcXH2Fuk71KwxzQba//a8MFrq068fOWHCnqloweUTF+1RwghBBLJXhVWE2n41o8Ine2qlF4DseiOY5/bJb/s0tl425DzrDK7IAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716191376; c=relaxed/simple; bh=4LRO6KJCSfk09QFcBSzNKaZTm2yF53007hB66PEndEw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=AlwnONBLB9DnhDRJEnDqhTfVZhiJ8CQcEzcQJs0hCib9OBhHfSVUjX0fy+kXCRQ3oQ5aTTwYytWAfsqw+beIaMmghP8YQLCyzL6Vjjg0sILEL4r7h5+zf3C2M2bJ7Lyaiy19LAkQMMd6dBprsVJ1gOGnwy2PqmSsC3BIPFCioDE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-42017f8de7aso17510275e9.1 for <gcc-patches@gcc.gnu.org>; 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=eIl8XaSBfKeqpZIc6VYCFD5btjeXnAD8KkrcKHntheI=; b=ODaDyLEfz/swz/GBEMfQdT9UBSYVHQHqMWG5TDKdO9zOcn5TXEluIhG59N2BplupDZ h/RBOovqjIoWH+SbS1AuSnisC8cBmqRdRKZKWhG14audtMmLhlP2cdpd6XBlPfNSaNND YBlb+k+D1Xms1fYRIU8YNRLTxAGkxseRzrciQyTi9H5giFYtWru6Ra5g88m74lOTSC0s lKrWGwP0aUxTDYYJv3YIj1IhVqASDRThjcWngvKbbdNevB6WACun/YwhTfo6WelRqaYQ 1uSymxjjWKNRb8xVbhYR1cv+qavMIBWvVlykVo9gZdJr/Tbbrlxi5brrqlBW562BsLfN LaPQ== 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=eIl8XaSBfKeqpZIc6VYCFD5btjeXnAD8KkrcKHntheI=; b=HYXGUE8jBJPMgIhSEG9PrdeO2hi4tNLWvEFhIDI7GOaw7luoPz29y6LE3+KYDk9n8L lh0Xs20rdzM7VQHMyEDIfw5uPAqkZK3JIRLVCGD4sY6ekLip8EcDHI9GUfvtcLb3ruQG /3X+yW/rQXCyjV8x3veEX3v5S/pzOJ0jVFL0CJCaV3Yv4zvUTQivfhCUFYBWxNss0EvV LUcIJC0s4sGKyqoWKbjcDLjdbbuLaxxwgh7ppkRCB4SAnc0BVXiVUItuc6ynlId1PFVL LfQT1wfXX+Ama53gCfjmA0rMsE1vdAGrkgFwm7E57y02E9pwyXq0avWGXc7kD3X5T1gx mAaw== X-Gm-Message-State: AOJu0YzUirfmbH+9TCZhJzysNrrnNZjTV991dH2Oy9TWT8OVWxMkBNa5 wPK2RGqBmTlfEDDEzo4VxsAS1Rhy7/yIvVpgQn3WAu3Gwby2OPXe3Jm5Jy8YkRzZ5uz4G0ccaLc = X-Google-Smtp-Source: AGHT+IHKfvNjKnOI72WCuxGEv8wBeV+wkOYCpbjv3/SroeC4sZdSQt0MLG0gILHV0GnmJ5ouEGXU8Q== X-Received: by 2002:a05:600c:a41:b0:41d:7d76:ffd4 with SMTP id 5b1f17b1804b1-41feaa2f3e4mr205542915e9.8.1716191370616; Mon, 20 May 2024 00:49:30 -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:30 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= <poulhies@adacore.com> To: gcc-patches@gcc.gnu.org Cc: Gary Dismukes <dismukes@adacore.com> Subject: [COMMITTED 24/30] ada: Error on instantiation of generic containing legal container aggregate Date: Mon, 20 May 2024 09:48:50 +0200 Message-ID: <20240520074858.222435-24-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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org |
Series |
[COMMITTED,01/30] ada: Rework and augment documentation on strict aliasing
|
|
Commit Message
Marc Poulhiès
May 20, 2024, 7:48 a.m. UTC
From: Gary Dismukes <dismukes@adacore.com>
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. Also, add error
check for an attempt to use "[]" for an aggregate of a record type
that does not specify an Aggregate aspect.
(Resolve_Record_Aggregate): Remove error check for record
aggregates with "[]" (now done by Resolve_Aggregate).
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/sem_aggr.adb | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb index 6e40e5c2564..60738550ec1 100644 --- a/gcc/ada/sem_aggr.adb +++ b/gcc/ada/sem_aggr.adb @@ -1198,6 +1198,14 @@ package body Sem_Aggr is Resolve_Container_Aggregate (N, Typ); + -- Check for an attempt to use "[]" for an aggregate of a record type + -- after handling the case where the type has an Aggregate aspect, + -- because the aspect can be specified for record types, but if it + -- wasn't specified, then this is an error. + + elsif Is_Record_Type (Typ) and then Is_Homogeneous_Aggregate (N) then + Error_Msg_N ("record aggregate must use (), not '[']", N); + elsif Is_Array_Type (Typ) then -- First a special test, for the case of a positional aggregate of @@ -5518,15 +5526,6 @@ 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 (), not '[']", N); - return; - end if; - -- STEP 2: Verify aggregate structure Step_2 : declare