From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by sourceware.org (Postfix) with ESMTPS id AAA053857C58 for ; Fri, 14 Oct 2022 11:20:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AAA053857C58 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qt1-x831.google.com with SMTP id w3so3406698qtv.9 for ; Fri, 14 Oct 2022 04:20:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date:message-id:reply-to; bh=AldY1Z3AmyMsWGBnfJkbOmH7Dn6WzQC5JQTFGAMZYW0=; b=VWUv7mXWJEALq67wUwGQ7skqicZH/dSd5LU7x3D9nM8zz0oZibx59LEEQLpXOC31L6 GWL74WosmKkwOy+4RGN6nwdXAheccQbd5hitbMK4WUYdgnwfTX6SFwj/R4UxDnuSPda5 iBMJPO61i4SIV73nbkW9aRLXEl037lQJdr9OWQNxiB7FKKWHMzo4UGxem6Mlfah9HpYU l58S/lJBKWD3HLuO7yKzIVg/ftm1NjOp4qAHXMwlRw2AOIPRJGgiicAJ3stgQOnLM5um NDGD7alFxYhMCmdG74/KO1no+ry1j/Q9tkC+YZsmDpzd32SM3sonRtiuOonlD71E82iz htNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AldY1Z3AmyMsWGBnfJkbOmH7Dn6WzQC5JQTFGAMZYW0=; b=3vI5WUmZj1wz9lmumxa5fK5GBjY2R3sBwHMvNmXc8ys4n/gdvIYMZwTr0cYpO6tmDu gfIOjwbOwoCEXIGMXnZkOX1Y44zs0VgnT4xc64wuV70m/sB9Xa7jb4Y8HZcIijnqlfaq /qa2OA+s0w/DTCtt3GvSNth0lZtSoi15SaexV03fulovbCMGji8kawxv18uNDQye3JOx VUvjrjmsCf7UekgGMNh3L8dQDinL/BTSuJUR7ZxfKkWG/CXCwk3tFfxFG1mJWUASdbA8 KsqswXkz+fRKl0/Ra4LXFTXTIxLdWQABCzmFCZfE5L0W2ZM9dYfl/R+1VEn7TwgbFI3j 9kDA== X-Gm-Message-State: ACrzQf0XpTt3I8N9wx/jana0JTb/epN+y8dvU1JbBqNN5nZCAmVlcXU3 nOzHz7jqtkEtO4kMPt0AwYU= X-Google-Smtp-Source: AMsMyM5nv3hJVhxvGud22AfnO1xQ1H+u6PyEoa8g1+UXt2Aj3vGss2U+kYeKTAaedccTCdbExToZlg== X-Received: by 2002:ac8:5d49:0:b0:39c:c082:1417 with SMTP id g9-20020ac85d49000000b0039cc0821417mr3624129qtx.687.1665746404867; Fri, 14 Oct 2022 04:20:04 -0700 (PDT) Received: from ?IPV6:2620:10d:c0a8:11d9::105c? ([2620:10d:c091:480::a170]) by smtp.googlemail.com with ESMTPSA id h15-20020a05620a244f00b006cebda00630sm2303729qkn.60.2022.10.14.04.20.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 14 Oct 2022 04:20:04 -0700 (PDT) Sender: Nathan Sidwell Message-ID: <1f77260a-4578-df1b-74cb-5cd540a5a844@acm.org> Date: Fri, 14 Oct 2022 07:20:03 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Subject: Re: [PATCH] c++ modules: ICE with dynamic_cast [PR106304] Content-Language: en-US To: Patrick Palka , gcc-patches@gcc.gnu.org Cc: jason@redhat.com References: <20221013190427.181432-1-ppalka@redhat.com> From: Nathan Sidwell In-Reply-To: <20221013190427.181432-1-ppalka@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3040.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,NICE_REPLY_A,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: On 10/13/22 15:04, Patrick Palka wrote: > The FUNCTION_DECL we build for __dynamic_cast has an empty DECL_CONTEXT, > but trees_out::tree_node expects all FUNCTION_DECLs to have non-empty > DECL_CONTEXT thus we crash when streaming out the dynamic_cast in the > below testcase. > > This patch naively fixes this by setting DECL_CONTEXT for __dynamic_cast > appropriately. Like for __cxa_atexit which is similarly lazily declared, > I suppose we should push it into the namespace too. > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk? This is correct, there were a bunch of similar issues, surprising these never triggered. > > PR c++/106304 > > gcc/cp/ChangeLog: > > * constexpr.cc (cxx_dynamic_cast_fn_p): Check for abi_node > instead of global_namespace. > * rtti.cc (build_dynamic_cast_1): Set DECL_CONTEXT and > DECL_SOURCE_LOCATION on dynamic_cast_node, and push it > into the namespace. > > gcc/testsuite/ChangeLog: > > * g++.dg/modules/pr106304_a.C: New test. > * g++.dg/modules/pr106304_b.C: New test. > --- > gcc/cp/constexpr.cc | 2 +- > gcc/cp/rtti.cc | 4 ++++ > gcc/testsuite/g++.dg/modules/pr106304_a.C | 12 ++++++++++++ > gcc/testsuite/g++.dg/modules/pr106304_b.C | 8 ++++++++ > 4 files changed, 25 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/g++.dg/modules/pr106304_a.C > create mode 100644 gcc/testsuite/g++.dg/modules/pr106304_b.C > > diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc > index 06dcd71c926..5939d2882f8 100644 > --- a/gcc/cp/constexpr.cc > +++ b/gcc/cp/constexpr.cc > @@ -2108,7 +2108,7 @@ cxx_dynamic_cast_fn_p (tree fndecl) > { > return (cxx_dialect >= cxx20 > && id_equal (DECL_NAME (fndecl), "__dynamic_cast") > - && CP_DECL_CONTEXT (fndecl) == global_namespace); > + && CP_DECL_CONTEXT (fndecl) == abi_node); > } > > /* Often, we have an expression in the form of address + offset, e.g. > diff --git a/gcc/cp/rtti.cc b/gcc/cp/rtti.cc > index f5b43ec0fb2..a85c7b56409 100644 > --- a/gcc/cp/rtti.cc > +++ b/gcc/cp/rtti.cc > @@ -787,6 +787,10 @@ build_dynamic_cast_1 (location_t loc, tree type, tree expr, > NULL_TREE)); > dcast_fn = (build_library_fn_ptr > (fn_name, fn_type, ECF_LEAF | ECF_PURE | ECF_NOTHROW)); > + /* As with __cxa_atexit in get_atexit_node. */ > + DECL_CONTEXT (dcast_fn) = FROB_CONTEXT (current_namespace); > + DECL_SOURCE_LOCATION (dcast_fn) = BUILTINS_LOCATION; > + dcast_fn = pushdecl (dcast_fn, /*hiding=*/true); > pop_abi_namespace (flags); > dynamic_cast_node = dcast_fn; > } > diff --git a/gcc/testsuite/g++.dg/modules/pr106304_a.C b/gcc/testsuite/g++.dg/modules/pr106304_a.C > new file mode 100644 > index 00000000000..b999eeccf4a > --- /dev/null > +++ b/gcc/testsuite/g++.dg/modules/pr106304_a.C > @@ -0,0 +1,12 @@ > +// PR c++/106304 > +// { dg-additional-options -fmodules-ts } > +// { dg-module-cmi pr106304 } > + > +export module pr106304; > + > +struct A { virtual ~A() = default; }; > +struct B : A { }; > + > +inline const B* as_b(const A& a) { > + return dynamic_cast(&a); > +} > diff --git a/gcc/testsuite/g++.dg/modules/pr106304_b.C b/gcc/testsuite/g++.dg/modules/pr106304_b.C > new file mode 100644 > index 00000000000..e8333909c8d > --- /dev/null > +++ b/gcc/testsuite/g++.dg/modules/pr106304_b.C > @@ -0,0 +1,8 @@ > +// PR c++/106304 > +// { dg-additional-options -fmodules-ts } > + > +module pr106304; > + > +void f(A& a) { > + as_b(a); > +} -- Nathan Sidwell