From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by sourceware.org (Postfix) with ESMTPS id E31D93849AE2 for ; Thu, 16 May 2024 09:26:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E31D93849AE2 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 E31D93849AE2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715851601; cv=none; b=QwlnpyposycJVtbQZDCFLEeQSrFN1AH8yO19SxuIs2ePp2cJKz5iXfOzFblOJkHuOW/tjlfyF6LX2eoz7NHgDB7evmaPNq6Q5Fq/VkEz1moR5lhpPpGgle53n4tYgZsw+KSOZNg3704CGO9wMUsjrC7poQz7cnQnT+Jxmse42hc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715851601; c=relaxed/simple; bh=072yk7QeLZ/oIrgGPFU+qN1cQKKKJclRsQKrjhIcdVw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=UlyhHXC2EfqS5cU57NcMt7JVUYZhpckNJ/QExOpTXjIJ6ehglU/FdwdvWjdny0CNhgQn8yz1SFKXCVSIRJ+/lrQv71l5poA8yVxGg0UI1HkJiB8rnimUuYksr+yq6ajw1REVY7cPlvtnYPOb/nTrtDykcAQRRr54vD7aS/GDjw4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-520f9d559f6so658648e87.3 for ; Thu, 16 May 2024 02:26:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1715851594; x=1716456394; 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=7e1LDkaACHLfd11ZwTyR/eEtBFLIY8lu57EnuGUI6mk=; b=jl7ZPaEhqdfCjhzX8gToYRS9w15GZELVXkPXHSCH+lkMlSMZFfAAFDZRAK7pyum4dH zAyTWC1U74qK3rhuG9fIDIJmBVIRSAIajrkj4YBHWcq0josb0nsuOyZ4z/idCgWxiW1r LHkmRIuS7Jjp70TkPiwhyNmi358uyH5TnOdzRmjf+X5iSl+KD30WSxJtJhEioOjHQtJa CxM4nfhbHZRoXGM0dFOLSAjWLb5Hxr6uOUgvwqtlWqGIsx+YZOewkBtVG9/me/oHteca Xtjuic7mgU4032m0r+IrC1dckS9Vz65pNNGpT37HL97iANYdsV4png0WMkSUP8GMcJy1 +hxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715851594; x=1716456394; 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=7e1LDkaACHLfd11ZwTyR/eEtBFLIY8lu57EnuGUI6mk=; b=lGV4MChZFqfbbPyxoMgTfcAFzUBz5fDFlmNVMfL8r+FeubQ9gtNszO8EvCGszTYR1A tyybM4U4o6kAKpNpmqx3NoerIfpl6yFB23GBrRqVJQDfl4DMVO479soDFDi7/NjkIlZ/ H9t7G2QqIfN6gdIMkf3ZEypSO3taXAasznwk9A0E8IwvYUPvNF7Jd9TWUvuDMCY1BiEp eywxR8ueVrdWamK6arSg6iYlUcy8KXv0zKPiXtq3iuqd7ZE15PdCHFZ54RMarPZp6NEy EG/UjqCbR6Jed+aclKSABTPKE/8F9JQSNrmYIedOyVW5MvBrbDSxvvJldDkNXkbLXhV6 Ai1A== X-Gm-Message-State: AOJu0YxWhaoyuSebL4S3YV18ZpmUwYiSOLDKbjk+t8ekKUrSw/BNHQf1 wIB9tlNPLrereQpULH6YhOd1mA+0JfKtBKtteAuun2x5926cN83N36K9GNQeaxZoVFK+V6JbMjQ = X-Google-Smtp-Source: AGHT+IG32ZCDiIkKAR/AWIMzYH7CTPuz04UNg4ZZP5X22IFkuaCPpaH51LAi4/lLsYqSe1CBl5pgdw== X-Received: by 2002:a19:8c56:0:b0:51d:a87e:27e6 with SMTP id 2adb3069b0e04-5221006e5a4mr10940962e87.67.1715851594399; Thu, 16 May 2024 02:26:34 -0700 (PDT) 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 5b1f17b1804b1-41fd10cf8besm135802635e9.1.2024.05.16.02.26.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 02:26:33 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Gary Dismukes Subject: [COMMITTED 32/35] ada: Exception on Indefinite_Vector aggregate with loop_parameter_specification Date: Thu, 16 May 2024 11:26:01 +0200 Message-ID: <20240516092606.41242-32-poulhies@adacore.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240516092606.41242-1-poulhies@adacore.com> References: <20240516092606.41242-1-poulhies@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.7 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 Constraint_Error is raised on evaluation of a container aggregate with a loop_parameter_specification for the type Indefinite_Vector. This happens due to the Aggregate aspect for type Indefinite_Vector specifying the Empty_Vector constant for the type's Empty operation rather than using the type's primitive Empty function. This problem shows up as a recent regression relative to earlier compilers, evidently due to recent fixes in the container aggregate area, which uncovered this issue of the wrong specification in Ada.Containers.Indefinite_Vectors. The compiler incorrectly initializes the aggregate object using the Empty_Vector constant rather than invoking the New_Vector function to allocate the vector object with the appropriate number of elements, and subsequent calls to Replace_Element fail because the vector object is empty. In addition to correcting the Indefinite_Vectors generic package, checking is added to give an error for an attempt to specify the Empty operation as a constant rather than a function. (Also note that another AdaCore package that needs a similar correction is the VSS.Vector_Strings package.) gcc/ada/ * libgnat/a-coinve.ads (type Vector): In the Aggregate aspect for this type, the Empty operation is changed to denote the Empty function, rather than the Empty_Vector constant. * exp_aggr.adb (Expand_Container_Aggregate): Remove code for handling the case where the Empty_Subp denotes a constant object, which should never happen (and add an assertion that Empty_Subp must denote a function). * sem_ch13.adb (Valid_Empty): No longer allow the entity to be an E_Constant, and require the (optional) parameter of an Empty function to be of a signed integer type (rather than any integer type). Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_aggr.adb | 24 +++++++++--------------- gcc/ada/libgnat/a-coinve.ads | 2 +- gcc/ada/sem_ch13.adb | 5 +---- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb index f04dba719d9..5d2b334722a 100644 --- a/gcc/ada/exp_aggr.adb +++ b/gcc/ada/exp_aggr.adb @@ -7119,10 +7119,12 @@ package body Exp_Aggr is Append (Init_Stat, Aggr_Code); -- The container will grow dynamically. Create a declaration for - -- the object, and initialize it either from a call to the Empty - -- function, or from the Empty constant. + -- the object, and initialize it from a call to the parameterless + -- Empty function. else + pragma Assert (Ekind (Entity (Empty_Subp)) = E_Function); + Decl := Make_Object_Declaration (Loc, Defining_Identifier => Temp, @@ -7130,20 +7132,12 @@ package body Exp_Aggr is Insert_Action (N, Decl); - -- The Empty entity is either a parameterless function, or - -- a constant. - - if Ekind (Entity (Empty_Subp)) = E_Function then - Init_Stat := Make_Assignment_Statement (Loc, - Name => New_Occurrence_Of (Temp, Loc), - Expression => Make_Function_Call (Loc, - Name => New_Occurrence_Of (Entity (Empty_Subp), Loc))); + -- The Empty entity is a parameterless function - else - Init_Stat := Make_Assignment_Statement (Loc, - Name => New_Occurrence_Of (Temp, Loc), - Expression => New_Occurrence_Of (Entity (Empty_Subp), Loc)); - end if; + Init_Stat := Make_Assignment_Statement (Loc, + Name => New_Occurrence_Of (Temp, Loc), + Expression => Make_Function_Call (Loc, + Name => New_Occurrence_Of (Entity (Empty_Subp), Loc))); Append (Init_Stat, Aggr_Code); end if; diff --git a/gcc/ada/libgnat/a-coinve.ads b/gcc/ada/libgnat/a-coinve.ads index 138ec3641c3..c51ec8aa06d 100644 --- a/gcc/ada/libgnat/a-coinve.ads +++ b/gcc/ada/libgnat/a-coinve.ads @@ -63,7 +63,7 @@ is Variable_Indexing => Reference, Default_Iterator => Iterate, Iterator_Element => Element_Type, - Aggregate => (Empty => Empty_Vector, + Aggregate => (Empty => Empty, Add_Unnamed => Append, New_Indexed => New_Vector, Assign_Indexed => Replace_Element); diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index 00392ae88eb..13bf93ca548 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -16527,13 +16527,10 @@ package body Sem_Ch13 is if Etype (E) /= Typ or else Scope (E) /= Scope (Typ) then return False; - elsif Ekind (E) = E_Constant then - return True; - elsif Ekind (E) = E_Function then return No (First_Formal (E)) or else - (Is_Integer_Type (Etype (First_Formal (E))) + (Is_Signed_Integer_Type (Etype (First_Formal (E))) and then No (Next_Formal (First_Formal (E)))); else return False; -- 2.43.2