From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 1D3A13858C98 for ; Thu, 4 Apr 2024 21:28:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1D3A13858C98 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1D3A13858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712266108; cv=none; b=ZAdQS9uck/O5irCBaMNggW+sfLp6qgBU7TlGHymbHsmQSC7zW4AMmiNq+FdJwjeUNCdabaSUk/BD4jVQneVnmDF82KKIbJZ6qYtCSvDbbj0Ok/OI1KXGn97kkTrPH7ekbGxBSNFvEM95fJXPHemepDwS7amzQ1adH9iq0m42zfc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712266108; c=relaxed/simple; bh=Qr6olm49CiGlHd5H0KeuiNNuKm6fEVYL/TLsre7JQx8=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=DkUu4Le7yKFOp8EANF2QMlRJeS26r04ALNaAbYbi9CnfKvirHvv5iyclxUmfJ6iYvVhvfO2o3atVnRpYtajxPMCby8phVtGwYJKMmm7EyBz7IvSc3CAplFWnKczzhRSvKjysX51uKfP5dGCKjMt8PUff3WU6KbduzRfInExVTss= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712266106; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=niWKvKqU6iDzt4z2nZ9I3wO259WNnUfKp4Kb+xHF8bo=; b=LPlO65ap5H8syuicrm6Aab91kHHJHIhMnzZBzZtnBU6WB3B7hbBp17SJPJxHM6VJzsNvFB 1TJT1PVsl+ksm0QpXesA9dqHr+yB4LjnYUpSg4ZWGr0PnBWnHKM2wLvnBK4HYYhGGOXwZ4 2P5RTln1JeA2wi+p1NfB7Bq1LMcr3SM= Received: from mail-vk1-f198.google.com (mail-vk1-f198.google.com [209.85.221.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-194-IdwHutK5MG2fGgwSuCf34w-1; Thu, 04 Apr 2024 17:28:25 -0400 X-MC-Unique: IdwHutK5MG2fGgwSuCf34w-1 Received: by mail-vk1-f198.google.com with SMTP id 71dfb90a1353d-4daaa4f6054so220984e0c.2 for ; Thu, 04 Apr 2024 14:28:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712266104; x=1712870904; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=niWKvKqU6iDzt4z2nZ9I3wO259WNnUfKp4Kb+xHF8bo=; b=SbK0rW6xz65Kiyh+C24ZDMTHdOIONgdxN75GRfXrYnWczSMji6gOM9Zi9NbtMSty4E k4H6ypopB1T1/XvyaolPuo4gNkIkGb+NowvRG0Xrlskqk5/cB9sxeHE0dND837IZxsKT c2veGo+tqzkScGEMBklMVx82Byxpo79z1bnAP7QzAr7mIVynWP0EbVivYKhvb3SQMHLC t5dfKxg6KfhpbkYUKyGp+BqKx/MXHp2JZQdFAWg899dxMCJcMzN6sur5IDEq43hbv+vM yxm9wvjeDhE74wIhvzJkIkUqyTgK3e0OopwLq1EW4T+GCYTz2R+VpqsghPPqSB489lFx tTOQ== X-Gm-Message-State: AOJu0YxayZRyhvDUywUXxzZ8Wrd5c2LHDrp6YEPSuA34iyZopZY3/Dbe yrvk85hygXjgf1Cpi4GjPohGUzZCKU+7Rv2AMEDbnod+YXA3NmD4rnAo9n5NXMoC0CN/DYzy7ci MrkenFQczIxBWRRKdikK+oK1u1iwCJpTAEfyNAYDgLBs/+Ec3rhoqCdyLxPLmAwI= X-Received: by 2002:a05:6122:e74:b0:4d4:3621:b245 with SMTP id bj52-20020a0561220e7400b004d43621b245mr3032933vkb.16.1712266104269; Thu, 04 Apr 2024 14:28:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFyZ0PEiPK/8M2nE0Tn5ltVIvn65exJY3dfilr57Og9OJkLrUUTPl1XkjaqbfwaDRhuTWV5Jg== X-Received: by 2002:a05:6122:e74:b0:4d4:3621:b245 with SMTP id bj52-20020a0561220e7400b004d43621b245mr3032923vkb.16.1712266103967; Thu, 04 Apr 2024 14:28:23 -0700 (PDT) Received: from [192.168.9.172] ([38.125.9.91]) by smtp.gmail.com with ESMTPSA id x128-20020a1f7c86000000b004b723acd1e1sm43670vkc.11.2024.04.04.14.28.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Apr 2024 14:28:23 -0700 (PDT) Message-ID: <0a3fe0db-9466-478b-bd4f-2957863b585c@redhat.com> Date: Thu, 4 Apr 2024 17:28:22 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++: constexpr error with fn redecl in local scope [PR111132] To: Marek Polacek Cc: GCC Patches , Jakub Jelinek References: <20240402175237.482119-1-polacek@redhat.com> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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: On 4/4/24 14:43, Marek Polacek wrote: > On Wed, Apr 03, 2024 at 01:14:46PM -0400, Jason Merrill wrote: >> On 4/2/24 13:52, Marek Polacek wrote: >>> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/13? >>> >>> -- >8 -- >>> We evaluate constexpr functions on the original, pre-genericization bodies. >>> That means that the function body we're evaluating will not have gone >>> through cp_genericize_r's "Map block scope extern declarations to visible >>> declarations with the same name and type in outer scopes if any". Here: >>> >>> constexpr bool bar() { return true; } // #1 >>> constexpr bool foo() { >>> constexpr bool bar(void); // #2 >>> return bar(); >>> } >>> >>> it means that we: >>> 1) register_constexpr_fundef (#1) >>> 2) cp_genericize (#1) >>> nothing interesting happens >>> 3) register_constexpr_fundef (foo) >>> does copy_fn, so we have two copies of the BIND_EXPR >>> 4) cp_genericize (foo) >>> this remaps #2 to #1, but only on one copy of the BIND_EXPR >>> 5) retrieve_constexpr_fundef (foo) >>> we find it, no problem >>> 6) retrieve_constexpr_fundef (#2) >>> and here #2 isn't found in constexpr_fundef_table, because >>> we're working on the BIND_EXPR copy where #2 wasn't mapped to #1 >>> so we fail. We've only registered #1. >>> >>> It should work to use DECL_LOCAL_DECL_ALIAS (which used to be >>> extern_decl_map). We evaluate constexpr functions on pre-cp_fold >>> bodies to avoid diagnostic problems, but the remapping I'm proposing >>> should not interfere with diagnostics. >>> >>> This is not a problem for a global scope redeclaration; there we go >>> through duplicate_decls which keeps the DECL_UID: >>> DECL_UID (olddecl) = olddecl_uid; >>> and DECL_UID is what constexpr_fundef_hasher::hash uses. >>> >>> PR c++/111132 >>> >>> gcc/cp/ChangeLog: >>> >>> * constexpr.cc (get_function_named_in_call): If there's >>> a DECL_LOCAL_DECL_ALIAS, use it. >> >> Perhaps this function should use cp_get_fndecl_from_callee, and this change >> should be made there instead? > > It doesn't seem that get_function_named_in_call can use cp_get_fndecl_from_callee, > (or be replaced with cp_get_callee_fndecl_nofold). We can get e.g. a CALL_EXPR > whose CALL_EXPR_FN is a TEMPLATE_ID_EXPR, and get_function_named_in_call > returns the TEMPLATE_ID_EXPR whereas cp_get_fndecl_from_callee would return > null: > > if (TREE_CODE (fn) == FUNCTION_DECL) > return fn; > tree type = TREE_TYPE (fn); > if (type == NULL_TREE || !INDIRECT_TYPE_P (type)) > return NULL_TREE; Why couldn't this function use cp_get_fndecl_from_callee and return the original argument if that function returns null? Jason