From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 03C323838A09 for ; Thu, 27 Jun 2024 08:52:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 03C323838A09 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 03C323838A09 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719478370; cv=none; b=wtlf+RYKPLMit4WIquGihe5A2bECSlG/ntP1RDfJcKQpFiBZF3xoBnuQLjv7K/Y0UGGmKUWFzlF0OVCClzbRau4MWb0PAkNXDyxJfmr8kEZ2FsMxo9LlmeTsnSDQsXyLGrg7DlKjqvJeJ3IjmQVjZfsBWLFMsPKXELzMm5SCEMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719478370; c=relaxed/simple; bh=wYC/fUKLkEVhErD9C1FkT1nQoRIQxRwylgtGgcwPw0k=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vzsJtIIm/K5iBM2D9EAS/iz+HxNv4pA3ZNkxdt4PRSgudsgo6m2lIjtYoq2QnqbhbJQe3r03cHGJ7ABfy2HfgeJgftQfe2yDv0GWpzhwP+D2nr6IfoAAgvrgUP+ap2QdU2FJNTnj9oOr+OXB6zmpiKhd4JVWnuGwf2bI4nvoZaY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-35f06861ae6so5790100f8f.2 for ; Thu, 27 Jun 2024 01:52:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1719478364; x=1720083164; 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=/y7QigmNVR+EVerw4xn8tk9cgH6UvGgQxTDIeymf50I=; b=CvrJcem6Rns9gvKI87+Kz47LEbcnwf6+FwBu0TVn1PqPuckp7rXdv49Rjek16/v8HA pjHdzh6Tldsn4XgQejjZa9lbdxHl01YdB7OufcJBp3UcUag91aEQbAaZs3rakT60MU8f v1TiZbxB/9QZ9lz4ssrbGERnbAHbI17Efe3H/uwXoUZgJCWTresBUSGRDre3LbdTGoPW GoOuAbL8V+UgE6UHi4tnI1XW/rjoLT9Vgbnm3bwGoGFq5sunX0KtN0/eR8lMUb2F/Jao dhZ7LquW9pmFDQ/ZhdRKtdgFCIrpeyvnA0V/6WivLIz7Qk4I2t1q6xD7DltyJ5mizlQj ofAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719478364; x=1720083164; 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=/y7QigmNVR+EVerw4xn8tk9cgH6UvGgQxTDIeymf50I=; b=apcKXH8A94rD72+Q6ojkTO99BbxC/MqnCNSYrKqVpZoZlcpnQ/TvMmPOj8oT2Y01T0 J9qOrYsG99/7RcJqMrlzjUgcUJq83Vcww6GOLziSFXKCnZhGqi5RB+UGOsII6dT2ey+n /Li2Mh0EB67Z9RtK/I2ORWRKjF57AbOyXBl7HjghGEXGbPtlmBz2nK5o3xk6LRlGvIoH +nE4YZR+2CzBMp9Q2cVN5GL5Yugk2Ec/Gr/tOzcYWihXQKNJ3TvbjLfaawbCGOda1izQ 66+GR9NrKEYMYbhqHkCd1aPHXxw6scuiNFBhRFikr4aukDbXx96Gch1cf1Z1SxqAzpwt EAng== X-Gm-Message-State: AOJu0YwTfY/8dBLcJGlKdxxYA9Cn0fL9eApOny33bms5LNAlQckjkuAS NIg3GdrkQULt/hOXLTuSVjfRhjXPkcAi9oQm6Ex9F+/NvVsGOkZV6OeQJnV1xC8ZottJAc27G2E = X-Google-Smtp-Source: AGHT+IFy05U090RPHBUEVNb+rY3E8Pnh9hGqFFzPz0qVSb4n39N4pQDR4pX8KT+yveBSBBLRK8Hujg== X-Received: by 2002:a05:6000:154d:b0:360:89a3:5293 with SMTP id ffacd0b85a97d-366e93b18f9mr10818615f8f.0.1719478363580; Thu, 27 Jun 2024 01:52:43 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:2a5d:d7ee:58d:fee4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3674357c14fsm1149133f8f.16.2024.06.27.01.52.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 01:52:43 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Martin Clochard Subject: [COMMITTED 2/7] ada: Overridden operation field not correctly set for controlling result wrappers Date: Thu, 27 Jun 2024 10:52:25 +0200 Message-ID: <20240627085232.226541-2-poulhies@adacore.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240627085232.226541-1-poulhies@adacore.com> References: <20240627085232.226541-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: Martin Clochard Implicit wrapper overridings generated for functions with controlling result when deriving with null extension may have field Overridden_Operation incorrectly set, when making several such derivations in succession. This happens because overridings were assumed to come from source, and entities generated by Derive_Subprograms were also assumed to be derived from source subprograms. Overridden_Operation could be set to the entity generated by Derive_Subprograms for the same type, resulting in a cycle between Overriden_Operation and Alias fields, causing non-termination in GNATprove. gcc/ada/ * sem_ch6.adb (Check_Overriding_Indicator) Remove Comes_From_Source filter. (New_Overloaded_Entity) Move up special case of LSP_Subprogram, and remove Comes_From_Source filter. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch6.adb | 82 +++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 47 deletions(-) diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb index e97afdaf12e..43aa2e636fa 100644 --- a/gcc/ada/sem_ch6.adb +++ b/gcc/ada/sem_ch6.adb @@ -6916,13 +6916,11 @@ package body Sem_Ch6 is -- operation is the inherited primitive (which is available -- through the attribute alias) - if (Is_Dispatching_Operation (Subp) - or else Is_Dispatching_Operation (Overridden_Subp)) + if Is_Dispatching_Operation (Subp) and then not Comes_From_Source (Overridden_Subp) and then Find_Dispatching_Type (Overridden_Subp) = Find_Dispatching_Type (Subp) and then Present (Alias (Overridden_Subp)) - and then Comes_From_Source (Alias (Overridden_Subp)) then Set_Overridden_Operation (Subp, Alias (Overridden_Subp)); Inherit_Subprogram_Contract (Subp, Alias (Overridden_Subp)); @@ -12565,16 +12563,25 @@ package body Sem_Ch6 is Enter_Overloaded_Entity (S); + -- LSP wrappers must override the ultimate alias of their + -- wrapped dispatching primitive E; required to traverse the + -- chain of ancestor primitives (see Map_Primitives). They + -- don't inherit contracts. + + if Is_Wrapper (S) + and then Present (LSP_Subprogram (S)) + then + Set_Overridden_Operation (S, Ultimate_Alias (E)); + -- For entities generated by Derive_Subprograms the -- overridden operation is the inherited primitive -- (which is available through the attribute alias). - if not (Comes_From_Source (E)) + elsif not (Comes_From_Source (E)) and then Is_Dispatching_Operation (E) and then Find_Dispatching_Type (E) = Find_Dispatching_Type (S) and then Present (Alias (E)) - and then Comes_From_Source (Alias (E)) then Set_Overridden_Operation (S, Alias (E)); Inherit_Subprogram_Contract (S, Alias (E)); @@ -12591,20 +12598,8 @@ package body Sem_Ch6 is -- must check whether the target is an init_proc. elsif not Is_Init_Proc (S) then - - -- LSP wrappers must override the ultimate alias of their - -- wrapped dispatching primitive E; required to traverse - -- the chain of ancestor primitives (c.f. Map_Primitives) - -- They don't inherit contracts. - - if Is_Wrapper (S) - and then Present (LSP_Subprogram (S)) - then - Set_Overridden_Operation (S, Ultimate_Alias (E)); - else - Set_Overridden_Operation (S, E); - Inherit_Subprogram_Contract (S, E); - end if; + Set_Overridden_Operation (S, E); + Inherit_Subprogram_Contract (S, E); Set_Is_Ada_2022_Only (S, Is_Ada_2022_Only (E)); end if; @@ -12619,37 +12614,30 @@ package body Sem_Ch6 is -- If S is a user-defined subprogram or a null procedure -- expanded to override an inherited null procedure, or a - -- predefined dispatching primitive then indicate that E - -- overrides the operation from which S is inherited. + -- predefined dispatching primitive, or a function wrapper + -- expanded to override an inherited function with + -- dispatching result, then indicate that S overrides the + -- operation from which E is inherited. - if Comes_From_Source (S) - or else - (Present (Parent (S)) - and then Nkind (Parent (S)) = N_Procedure_Specification - and then Null_Present (Parent (S))) - or else - (Present (Alias (E)) - and then - Is_Predefined_Dispatching_Operation (Alias (E))) + if (not Is_Wrapper (S) or else No (LSP_Subprogram (S))) + and then Present (Alias (E)) + and then + (Comes_From_Source (S) + or else + (Nkind (Parent (S)) = N_Procedure_Specification + and then Null_Present (Parent (S))) + or else Is_Predefined_Dispatching_Operation (Alias (E)) + or else + (E in E_Function_Id + and then Is_Dispatching_Operation (E) + and then Has_Controlling_Result (E) + and then Is_Wrapper (S) + and then not Is_Dispatch_Table_Wrapper (S))) then - if Present (Alias (E)) then - - -- LSP wrappers must override the ultimate alias of - -- their wrapped dispatching primitive E; required to - -- traverse the chain of ancestor primitives (see - -- Map_Primitives). They don't inherit contracts. - - if Is_Wrapper (S) - and then Present (LSP_Subprogram (S)) - then - Set_Overridden_Operation (S, Ultimate_Alias (E)); - else - Set_Overridden_Operation (S, Alias (E)); - Inherit_Subprogram_Contract (S, Alias (E)); - end if; + Set_Overridden_Operation (S, Alias (E)); + Inherit_Subprogram_Contract (S, Alias (E)); - Set_Is_Ada_2022_Only (S, Is_Ada_2022_Only (Alias (E))); - end if; + Set_Is_Ada_2022_Only (S, Is_Ada_2022_Only (Alias (E))); end if; if Is_Dispatching_Operation (E) then -- 2.45.2