From patchwork Tue Nov 28 09:40:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 170655 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3793176vqx; Tue, 28 Nov 2023 01:41:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IG6hwIZ8LEoarLqHTzLmwOR7KjOg5+z/DLgUw1d0jaHMeBg7QVCjc/yFcSv9V6RO+eRPugJ X-Received: by 2002:a05:620a:8e8c:b0:77d:869c:20b9 with SMTP id rf12-20020a05620a8e8c00b0077d869c20b9mr11599961qkn.77.1701164490029; Tue, 28 Nov 2023 01:41:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701164490; cv=pass; d=google.com; s=arc-20160816; b=B8negJPnw6gqD67+gRh7AWtFOHZf4YnSTujRcUOvfxZ1LcobjJCzaW0DpVlDp2shbc SYqRm5ojSaLruGTS0XUSSLhU0bjw3MUlplzBGAgVVDkGAXaVyrFu97EwTPG997Xi6gkG QpDi5p6bpwQeLI7dn+i5tfmTk26kG6Hf6HgntQcBLerwc6E/Wy8YJ7NhIwnq39ZAEBWn rli/bXUNZHIBtN2yXSFOCDb94KnqZUQ6CKrdlBRIQQQM3GAk4C8PVxghRhoOS7qJOHCL p7xzm5Z3ulKb6UAvgha+fxCRGeoxvhTrjlz8lAecC3nBYqeQC4zFoDeuqE1fDHQg67r3 2gCg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=6RStW0ORHIBqzlPMTC05rfoKKu6qwWJQ2xJwyNkxGyM=; fh=VfpjIVwbQyKCLGOH4P8eKpbC0rx5s9zOz2f2H065zJg=; b=w1bSZsE9Tx9xK/4p2Tmo26zfzN3nB0YKuLOl0yUN5l9Yt7jdydxEdS0/RxcCBQabJB 7VPjUQIkoHRFRbAg6AtG5ljXNR7buA33heSye+24MUNQCUB7hJxcVPNC2df6AIDS7hty C9oHEy2K2vy8XEwkyoSXnzof83tjC7pQFYGel/NZuWNxJpJKCs5k6H4RH4aJyg937d83 GY7753Dk+j+TTliCrK+5TWuh1pVEna7WJJZ6TXHDEk/sN+QlI4Dd4LzGt5PvoYC4oXMh kyVVzjFLxIYSU1noBwSId1T8cicQh+J/N7yCkCkFcU4COZg8OB00HvdqWOssU/ukigay 2UhA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=HRgMtYK2; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id dt50-20020a05620a47b200b0077d6be2fb08si7482692qkb.358.2023.11.28.01.41.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 01:41:30 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=HRgMtYK2; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 64EBE394800C for ; Tue, 28 Nov 2023 09:40:44 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oo1-xc2c.google.com (mail-oo1-xc2c.google.com [IPv6:2607:f8b0:4864:20::c2c]) by sourceware.org (Postfix) with ESMTPS id 4A7A63949094 for ; Tue, 28 Nov 2023 09:40:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4A7A63949094 Authentication-Results: sourceware.org; dmarc=pass (p=none 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 4A7A63949094 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c2c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701164419; cv=none; b=mly7750xv9CjU0Ij4A/YrHxQQkETvT0mOu8wR8xFS1kiqz2LjbSkXHHnGqo0etEZLc+OWuJ5SugAyqbNs500VSKDYIHln2t+e7D1yBaMbUCAJ1Nh3PE33O7vYFTckYN5UVs1G+0tn+TXLhse2+EvFTJZ5javNbhnKMI3uNnwAAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701164419; c=relaxed/simple; bh=Ai/oXtvvy2jcLIyYBX9guaPq8/gUf5KKPYFU9h93Jzg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=DwiiwYNfqTe+lL5iRlHaf1J1XCFMuaHtrALg2pMukr9y/vc6k3L97KE3Kewof9/XD7vEtQ6q4021kXHsTiwbeP7NudOJHeXG1lxVa21nWS6I3hySSPuvn5WjLqQkOziqS8K/oe72MtSF3GnlooOwJzNSV3XZLUMX/d5FyMWMyPk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc2c.google.com with SMTP id 006d021491bc7-58d956c8c38so800710eaf.2 for ; Tue, 28 Nov 2023 01:40:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1701164417; x=1701769217; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=6RStW0ORHIBqzlPMTC05rfoKKu6qwWJQ2xJwyNkxGyM=; b=HRgMtYK2x0TDzHGtnfDpYfQwCK1ZQQeV4EdVEFn2aKM7qW4xXC64md57HavAS8wY5S M11AVgbhv4SK0zyHDrXzNY9jeU61lczZtQ52ytdU7cQ+tZpcqHzSgnq0GJDd2Kdius7G e9+Zp3u+Icasex3GNv1jWi424PjS6ruV+RQVqtzt4qOF1jPBO/FHpYT9h9LrtckVj72e 5Ewf9UCkVGoqdWitpshM4g4SGAHyDm/d7fdwWVYjMrOQPa69CrMTkXjez2B+PhGTaJB7 sTOdye46+JOQHhKRKg0M3GSFN1rhkMNH4jY7cfHWgmTZ06yTkVKXmFP/vlNshYXEdcKB /A6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701164417; x=1701769217; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=6RStW0ORHIBqzlPMTC05rfoKKu6qwWJQ2xJwyNkxGyM=; b=DvPvg4K5yAdGQ78IoFKQPw2+3fW2smex4T6aLQTgYWBS4zLuIWPMPf6MGFFwqRduRa pjpEq4v8kBxyAvt6fScgns1hYdvF26ZatRm9guKC05Ak/e7CllxGN7kiidWm4NouFXga Ydc1VHq0KulRFdkRO9Qzv9N+SvDIJIK1pAUI1xjlQcnMtJOQ/9FJ1PwXXvTChfROMeRy 8TcFn1YG6XxgBsjEI8PZyKN8jY9Oj+wZtTyW39nmvv72Uc6A12uRDh0jHouMeoWwycik BGhhZ73nc78I7zOMa8epz1gzwSFI+AkFTxlVig2iwRnL7bCaHaYZ5pW4qk0eWX2Rxrju jfdQ== X-Gm-Message-State: AOJu0Yz6WjRvewezFXCQYm/Li04kuUiB09UKzZD0Gd0GEEComsA+kAiY 1atOUjcHgU0CA+p4uzurCYGMxasboeUYceO8TcgKHw== X-Received: by 2002:a05:6820:1c9a:b0:589:d42b:d88 with SMTP id ct26-20020a0568201c9a00b00589d42b0d88mr17460893oob.2.1701164417616; Tue, 28 Nov 2023 01:40:17 -0800 (PST) Received: from localhost.localdomain ([2001:861:3382:1a90:a24b:a65f:9576:c701]) by smtp.gmail.com with ESMTPSA id 28-20020a63115c000000b0059d219cb359sm9108930pgr.9.2023.11.28.01.40.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 01:40:17 -0800 (PST) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Steve Baird Subject: [COMMITTED] ada: Error compiling reduction expression with overloaded reducer subprogram Date: Tue, 28 Nov 2023 10:40:08 +0100 Message-ID: <20231128094008.2971318-1-poulhies@adacore.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783800256480594218 X-GMAIL-MSGID: 1783800256480594218 From: Steve Baird In some cases involving a reduction expression with an overloaded reducer subprogram, the accumulator type is not determined correctly. This can lead to spurious compile-time errors. gcc/ada/ * exp_attr.adb (Expand_N_Attribute_Reference): In the case of a Reduce attribute reference, fix bugs in initializing Accum_Typ. The previous version was incorrect in the case where E1 refers to the first of multiple possible overload resolution candidates and that candidate does not turn out to be the right one. The previous version also had code to compute Accum_Typ via a different method if the initial computation turned out to yield a universal numeric type. Delete that initial computation and use the second method in all cases. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_attr.adb | 77 +++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 43 deletions(-) diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb index dddc05437b4..66fd6848a1d 100644 --- a/gcc/ada/exp_attr.adb +++ b/gcc/ada/exp_attr.adb @@ -6039,7 +6039,7 @@ package body Exp_Attr is E2 : constant Node_Id := Next (E1); Bnn : constant Entity_Id := Make_Temporary (Loc, 'B', N); - Accum_Typ : Entity_Id; + Accum_Typ : Entity_Id := Empty; New_Loop : Node_Id; function Build_Stat (Comp : Node_Id) return Node_Id; @@ -6058,7 +6058,6 @@ package body Exp_Attr is begin if Nkind (E1) = N_Attribute_Reference then - Accum_Typ := Entity (Prefix (E1)); Stat := Make_Assignment_Statement (Loc, Name => New_Occurrence_Of (Bnn, Loc), Expression => Make_Attribute_Reference (Loc, @@ -6069,14 +6068,12 @@ package body Exp_Attr is Comp))); elsif Ekind (Entity (E1)) = E_Procedure then - Accum_Typ := Etype (First_Formal (Entity (E1))); Stat := Make_Procedure_Call_Statement (Loc, Name => New_Occurrence_Of (Entity (E1), Loc), Parameter_Associations => New_List ( New_Occurrence_Of (Bnn, Loc), Comp)); else - Accum_Typ := Etype (Entity (E1)); Stat := Make_Assignment_Statement (Loc, Name => New_Occurrence_Of (Bnn, Loc), Expression => Make_Function_Call (Loc, @@ -6137,12 +6134,9 @@ package body Exp_Attr is Statements => New_List (Build_Stat (Relocate_Node (Expr)))); - -- If the reducer subprogram is a universal operator, then - -- we still look at the context to find the type for now. + -- Look at the context to find the type. - if Is_Universal_Numeric_Type (Accum_Typ) then - Accum_Typ := Etype (N); - end if; + Accum_Typ := Etype (N); end; else @@ -6172,43 +6166,40 @@ package body Exp_Attr is Statements => New_List ( Build_Stat (New_Occurrence_Of (Elem, Loc)))); - -- If the reducer subprogram is a universal operator, then - -- we need to look at the prefix to find the type. This is + -- Look at the prefix to find the type. This is -- modeled on Analyze_Iterator_Specification in Sem_Ch5. - if Is_Universal_Numeric_Type (Accum_Typ) then - declare - Ptyp : constant Entity_Id := - Base_Type (Etype (Prefix (N))); + declare + Ptyp : constant Entity_Id := + Base_Type (Etype (Prefix (N))); - begin - if Is_Array_Type (Ptyp) then - Accum_Typ := Component_Type (Ptyp); - - elsif Has_Aspect (Ptyp, Aspect_Iterable) then - declare - Element : constant Entity_Id := - Get_Iterable_Type_Primitive - (Ptyp, Name_Element); - begin - if Present (Element) then - Accum_Typ := Etype (Element); - end if; - end; - - else - declare - Element : constant Node_Id := - Find_Value_Of_Aspect - (Ptyp, Aspect_Iterator_Element); - begin - if Present (Element) then - Accum_Typ := Entity (Element); - end if; - end; - end if; - end; - end if; + begin + if Is_Array_Type (Ptyp) then + Accum_Typ := Component_Type (Ptyp); + + elsif Has_Aspect (Ptyp, Aspect_Iterable) then + declare + Element : constant Entity_Id := + Get_Iterable_Type_Primitive + (Ptyp, Name_Element); + begin + if Present (Element) then + Accum_Typ := Etype (Element); + end if; + end; + + else + declare + Element : constant Node_Id := + Find_Value_Of_Aspect + (Ptyp, Aspect_Iterator_Element); + begin + if Present (Element) then + Accum_Typ := Entity (Element); + end if; + end; + end if; + end; end; end if;