From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 872623836E8A for ; Thu, 27 Jun 2024 08:52:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 872623836E8A 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 872623836E8A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719478379; cv=none; b=SjjNVESRcg/XF1QPN4+TJGmv0unoXFRy7vFWXZ5it60rCZPLz8lJqFyR7KA7vZRpQNwNQb7rEdzsZM0o7G5a5wBB/0ghdmhJDYlTYiiMRDk9L7kW6QaXFuLJsSgQ5H5cjIGiG6nGLgkwMy82H4fsF86aos6dLveQJJJbDQ1EpiQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719478379; c=relaxed/simple; bh=l6rDOU8hY73/3P/zGoMwwRoJFlRRs8AadNqCSTC6j24=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=SGkXrmKnUgzQtc4AhFGPNtyTbr1SIWx7D/jhSZiU0j6S36sMKES7JdC3qkRny2BHYOz9igLZZdH+Xv+7cyxZ8W26ngYbld9D0eqiCI+Tte08wr4UBTjX52CEov4CmT/MkByZ5+e7Bu8xqrweXa9INjXALagus1QNo1DqXXu65cU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-36703b0f914so990144f8f.0 for ; Thu, 27 Jun 2024 01:52:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1719478367; x=1720083167; 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=sM6hWwvmR/nEkOC88BzqS4R3iEfHJEjeBKskJ5nh1NM=; b=SgcCZzUTB4nN0dzUY9zu4GDFIfgu6JH9xInp4nA3jIr/oPPjz742oXUWPmNIgCPlME SQe5mXqTaRzZ+huvwv6i60EmHJF99DPh1AZLUlMEtGg+6WmW2PWp6815/LTxxreH5Blw m1uP5B4SdSmiplz0ZAtTfCHDc4HqxHxTP+VRnVuZmC5Mzo37nL+H8GprXolh6KjdwUVj qwbsTm8KRsE7qZZbGOLnL/+772do08A//pP5vA/6m1+JsKpXBsgQJHJX19nOavAF5Dqu jkv/lJ3WqsIjcv8oVpvmhTDbEXb22U7ySaUzWHeqGNzSxeiH94Ln/6mOC5uSVgN+OYGP H+NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719478367; x=1720083167; 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=sM6hWwvmR/nEkOC88BzqS4R3iEfHJEjeBKskJ5nh1NM=; b=P4P9gonvuyGdRInC8AL56a3yFhdxTaatwbCFilCj3fJfyRLEG/3ehbp7TrHJk2YeIA zR4oZxMDs8dS5Jqc3+5FwMYFRbsAkhm8TxnQku1XHbKd/wHUdXvHJUm3gJHGvze0fodx jcSlPj/B8I9SP0Yeu9Bx3POkONhFNtjKdBCOI8EjkAzoEeoLvVA2Sxwx857mmLN9pGYC UtnNdI29mC6GXySxSA9kCvhnZpSj1yrbvJ82dJkTTjodnZsxboSjslGVIxdw1dJKKOmx Axm5AAHJ/KS+qFMPRGtmh78pN3VXELNH2zUz+pM7+tZzLtVrBaXRbt+m2Q0yjHRnFGNy NzZQ== X-Gm-Message-State: AOJu0YyeDWtycTCq2Z2Etp2uwH56yZ7fuQzKlQnFI80dvQYxUTejOx/5 /W8M4K+wsZjG9EPs82peiX4mNfNvglrk1wrQK8PoVQ7w9S6gNjzGQ6lt/jo6vAYuyN8PKeRgaNE = X-Google-Smtp-Source: AGHT+IF0F8DdIsRFgX3f7rUOnD27nFTJq8H8zKmPrWYB260LQSIgIM8KMaQLOF+rnLPfB0BVczXofw== X-Received: by 2002:a5d:64ce:0:b0:366:defe:1b3b with SMTP id ffacd0b85a97d-3673cc55d39mr2025077f8f.11.1719478367092; Thu, 27 Jun 2024 01:52:47 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 01:52:46 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Javier Miranda Subject: [COMMITTED 6/7] ada: Reject ambiguous function calls in interpolated string expressions Date: Thu, 27 Jun 2024 10:52:29 +0200 Message-ID: <20240627085232.226541-6-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.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_ASCII_DIVIDERS,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: Javier Miranda gcc/ada/ * sem_ch2.adb (Analyze_Interpolated_String_Literal): Report interpretations of ambiguous parameterless function calls. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch2.adb | 80 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/gcc/ada/sem_ch2.adb b/gcc/ada/sem_ch2.adb index 08cc75c9104..ddbb329d1f8 100644 --- a/gcc/ada/sem_ch2.adb +++ b/gcc/ada/sem_ch2.adb @@ -38,6 +38,8 @@ with Rident; use Rident; with Sem; use Sem; with Sem_Ch8; use Sem_Ch8; with Sem_Dim; use Sem_Dim; +with Sem_Res; use Sem_Res; +with Sem_Type; use Sem_Type; with Sinfo; use Sinfo; with Sinfo.Nodes; use Sinfo.Nodes; with Sinfo.Utils; use Sinfo.Utils; @@ -135,20 +137,96 @@ package body Sem_Ch2 is ----------------------------------------- procedure Analyze_Interpolated_String_Literal (N : Node_Id) is + + procedure Check_Ambiguous_Parameterless_Call (Func_Call : Node_Id); + -- Examine the interpretations of the call to the given parameterless + -- function call and report the location of each interpretation. + + ---------------------------------------- + -- Check_Ambiguous_Parameterless_Call -- + ---------------------------------------- + + procedure Check_Ambiguous_Parameterless_Call (Func_Call : Node_Id) is + + procedure Report_Interpretation (E : Entity_Id); + -- Report an interpretation of the function call + + --------------------------- + -- Report_Interpretation -- + --------------------------- + + procedure Report_Interpretation (E : Entity_Id) is + begin + Error_Msg_Sloc := Sloc (E); + + if Nkind (Parent (E)) = N_Full_Type_Declaration then + Error_Msg_N ("interpretation (inherited) #!", Func_Call); + else + Error_Msg_N ("interpretation #!", Func_Call); + end if; + end Report_Interpretation; + + -- Local variables + + Error_Reported : Boolean; + I : Interp_Index; + It : Interp; + + -- Start of processing for Check_Ambiguous_Parameterless_Call + + begin + Error_Reported := False; + + -- Examine possible interpretations + + Get_First_Interp (Name (Func_Call), I, It); + while Present (It.Nam) loop + if It.Nam /= Entity (Name (Func_Call)) + and then Ekind (It.Nam) = E_Function + and then No (First_Formal (It.Nam)) + then + if not Error_Reported then + Error_Msg_NE + ("ambiguous call to&", Func_Call, + Entity (Name (Func_Call))); + Report_Interpretation (Entity (Name (Func_Call))); + Error_Reported := True; + end if; + + Report_Interpretation (It.Nam); + end if; + + Get_Next_Interp (I, It); + end loop; + end Check_Ambiguous_Parameterless_Call; + + -- Local variables + Str_Elem : Node_Id; + -- Start of processing for Analyze_Interpolated_String_Literal + begin Set_Etype (N, Any_String); Str_Elem := First (Expressions (N)); while Present (Str_Elem) loop + + -- Before analyzed, a function call that has parameter is an + -- N_Indexed_Component node, and a call to a function that has + -- no parameters is an N_Identifier node. + Analyze (Str_Elem); + -- After analyzed, if it is still an N_Identifier node then we + -- found ambiguity and could not rewrite it as N_Function_Call. + if Nkind (Str_Elem) = N_Identifier and then Ekind (Entity (Str_Elem)) = E_Function and then Is_Overloaded (Str_Elem) then - Error_Msg_NE ("ambiguous call to&", Str_Elem, Entity (Str_Elem)); + Check_Parameterless_Call (Str_Elem); + Check_Ambiguous_Parameterless_Call (Str_Elem); end if; Next (Str_Elem); -- 2.45.2