From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by sourceware.org (Postfix) with ESMTPS id 82FBF385C333 for ; Mon, 4 Jul 2022 07:50:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 82FBF385C333 Received: by mail-ed1-x535.google.com with SMTP id x10so3258477edd.13 for ; Mon, 04 Jul 2022 00:50:15 -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=GkdNXthGeyqBQ7t8RAVnRwf9oeZUqIOl+uVMD8mD2q8=; b=7RCApo4AyyuVTrW0MHTlqE3qC8FGFQ1KuQ3New63la2WEwimWnjg2ABhS1tO6XVKBS mLuitG0PSSaltkM04k9+/tadi6tz9TfdSkgqdHCgyx0gzUXqCBtpzuoNrpRedLA41THP vFlH4/ABffMR2tgI9nTL12za4fvlUDGl/3rTQrE+W4j+vV9R5QF/sOXJ1aBAVHxx/vq0 ucDP0il0jyQIk1MboNPQfU7QQER5mDwQaieUfYo6axqAczC0Mi4NDIr78++3VkWIjTcx M18+JEl7imdFdakrppqkxi7DqmSsOU2UHhc9YgyVViBkQPyy3LBAl0Wh7H/nlUWLGavY rNbg== X-Gm-Message-State: AJIora8+YDy/FEY0qrS6PPtRVDnawmuZq5BVzws85W3snqv+Sx6zybru nSZdghIUUrHlcrTw4IYF+hY/8XtgXo4zgQ== X-Google-Smtp-Source: AGRyM1shSSQxXFMHdO9ri3N6F7CYBnBvkoHjemJPbcCqwYGmk9NNHrqC7OpM37cOPlhY+J94qurotA== X-Received: by 2002:a05:6402:4411:b0:437:b723:72 with SMTP id y17-20020a056402441100b00437b7230072mr37038050eda.38.1656921014344; Mon, 04 Jul 2022 00:50:14 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id k9-20020a17090646c900b00711d546f8a8sm13673594ejs.139.2022.07.04.00.50.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 00:50:13 -0700 (PDT) Date: Mon, 4 Jul 2022 07:50:13 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Steve Baird Subject: [Ada] Compiler rejects legal allocator in record component constraint expression Message-ID: <20220704075013.GA99118@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="2fHTh5uZTiUOsy+g" 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.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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Jul 2022 07:50:17 -0000 --2fHTh5uZTiUOsy+g Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In some cases when a legal allocator which defines a new subtype for the allocated object occurs as part of a record component constraint expression, the compiler would incorrectly reject the allocator. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch4.adb (Analyze_Allocator): After calling Insert_Action to insert a subtype declaration associated with an allocator, the subtype declaration will usually be analyzed. But not always. Add an explicit call to Preanalyze to cope with the unusual case. The subtype declaration must be at least preanalyzed before the call to Sem_Ch3.Process_Subtype a little while later, during which we analyze an identifier that refers to the subtype. --2fHTh5uZTiUOsy+g Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb --- a/gcc/ada/sem_ch4.adb +++ b/gcc/ada/sem_ch4.adb @@ -670,10 +670,19 @@ package body Sem_Ch4 is then Def_Id := Make_Temporary (Loc, 'S'); - Insert_Action (E, - Make_Subtype_Declaration (Loc, - Defining_Identifier => Def_Id, - Subtype_Indication => Relocate_Node (E))); + declare + Subtype_Decl : constant Node_Id := + Make_Subtype_Declaration (Loc, + Defining_Identifier => Def_Id, + Subtype_Indication => Relocate_Node (E)); + begin + Insert_Action (E, Subtype_Decl); + + -- Handle unusual case where Insert_Action does not + -- analyze the declaration. Subtype_Decl must be + -- preanalyzed before call to Process_Subtype below. + Preanalyze (Subtype_Decl); + end; if Sav_Errs /= Serious_Errors_Detected and then Nkind (Constraint (E)) = --2fHTh5uZTiUOsy+g--