From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 120117 invoked by alias); 31 Oct 2018 01:42:48 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 120099 invoked by uid 89); 31 Oct 2018 01:42:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=H*f:sk:47548cb, H*f:sk:2017042, H*f:sk:9yPw@ma, H*f:sk:714daf7 X-HELO: mail-qt1-f193.google.com Received: from mail-qt1-f193.google.com (HELO mail-qt1-f193.google.com) (209.85.160.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 31 Oct 2018 01:42:45 +0000 Received: by mail-qt1-f193.google.com with SMTP id g10-v6so15974518qtq.6 for ; Tue, 30 Oct 2018 18:42:45 -0700 (PDT) Return-Path: Received: from [192.168.1.132] (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id m14sm1956349qka.21.2018.10.30.18.42.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Oct 2018 18:42:42 -0700 (PDT) Subject: Re: [PATCH] Make __PRETTY_FUNCTION__-like functions mergeable string csts (PR c++/64266). From: Jason Merrill To: =?UTF-8?Q?Martin_Li=c5=a1ka?= Cc: Jakub Jelinek , Pedro Alves , Jan Kratochvil , gcc-patches List , Segher Boessenkool , wilson@gcc.gnu.org, Nathan Sidwell References: <20170425115827.GX1809@tucnak> <3b197eef-db36-7df9-417e-e17be0616b6c@suse.cz> <3f912b8a-0153-f559-e3fe-489b57800697@redhat.com> <894565dc-5c64-cb9f-8bb4-35ee7035c075@suse.cz> <47548cbc-69c9-d925-a107-891a960a2cd1@suse.cz> <714daf75-8c45-2503-23cc-675a7c258485@suse.cz> <7b6f3ceb-d303-4b45-5740-0f4a0f3059cf@suse.cz> <9f0a60ef-7b54-a737-9003-48631dcebaf4@suse.cz> Message-ID: Date: Wed, 31 Oct 2018 06:27:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------4B1CDCFBDE64315E3B51CF65" X-IsSubscribed: yes X-SW-Source: 2018-10/txt/msg01983.txt.bz2 This is a multi-part message in MIME format. --------------4B1CDCFBDE64315E3B51CF65 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-length: 2373 On 10/29/18 9:37 AM, Jason Merrill wrote: > On Fri, Oct 26, 2018 at 3:14 AM Martin Liška wrote: >> On 10/24/18 7:24 PM, Jason Merrill wrote: >>> On Tue, Oct 23, 2018 at 4:59 AM Martin Liška wrote: >>>> However, I still see some minor ICEs, it's probably related to decay_conversion in cp_fname_init: >>>> >>>> 1) ./xg++ -B. /home/marxin/Programming/gcc/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-__func__2.C >>>> >>>> /home/marxin/Programming/gcc/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-__func__2.C:6:17: internal compiler error: Segmentation fault >>>> 6 | [] { return __func__; }(); >>>> | ^~~~~~~~ >>>> 0x1344568 crash_signal >>>> /home/marxin/Programming/gcc/gcc/toplev.c:325 >>>> 0x7ffff6bc310f ??? >>>> /usr/src/debug/glibc-2.27-6.1.x86_64/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0 >>>> 0x9db134 is_capture_proxy(tree_node*) >> >> Hi. >> >>> >>> The problem in both tests is that is_capture_proxy thinks your >>> __func__ VAR_DECL with DECL_VALUE_EXPR is a capture proxy, since it is >>> neither an anonymous union proxy nor a structured binding. >> >> I see, however I'm a rookie in area of C++ FE. Would it be solvable this problem >> with lambdas? >> >>> >>> The standard says, >>> >>> The function-local predefined variable __func__ is defined as if a >>> definition of the form >>> static const char __func__[] = "function-name "; >>> had been provided, where function-name is an implementation-defined >>> string. It is unspecified whether such a variable has an address >>> distinct from that of any other object in the program. >>> >>> So changing the type of __func__ (from array to pointer) still breaks >>> conformance. And we need to keep the type checks from pretty4.C, even >>> though the checks for strings being distinct need to go. >> >> I added following patch which puts back type to const char[] (instead of char *) >> and I made the variable static. Now I see pretty4.C testcase passing again. >> To be honest I'm not convinced about the FE changes, so a help would >> be appreciated. > > OK, I'll poke at it. This further patch teaches is_capture_proxy about function-name variables, and changes the handling of __PRETTY_FUNCTION__ in template instantiations to create new variables rather than instantiations. The C++ changes are OK with this. --------------4B1CDCFBDE64315E3B51CF65 Content-Type: text/x-patch; name="fname.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fname.diff" Content-length: 4747 commit 100f6f38f9d8bbb5d77ba7a4ccb86a4c85aa2cd9 Author: Jason Merrill Date: Mon Oct 29 22:35:59 2018 -0400 fname-p diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 8454cb4e178..f1a10297e79 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -3122,6 +3122,14 @@ struct GTY(()) lang_decl { (DECL_NAME (NODE) \ && id_equal (DECL_NAME (NODE), "__PRETTY_FUNCTION__")) +/* For a DECL, true if it is __func__ or similar. */ +#define DECL_FNAME_P(NODE) \ + (VAR_P (NODE) && DECL_NAME (NODE) && DECL_ARTIFICIAL (NODE) \ + && DECL_HAS_VALUE_EXPR_P (NODE) \ + && (id_equal (DECL_NAME (NODE), "__PRETTY_FUNCTION__") \ + || id_equal (DECL_NAME (NODE), "__FUNCTION__") \ + || id_equal (DECL_NAME (NODE), "__func__"))) + /* Nonzero if the variable was declared to be thread-local. We need a special C++ version of this test because the middle-end DECL_THREAD_LOCAL_P uses the symtab, so we can't use it for diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index cce9cc99ff1..bde8023ce3b 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -4465,7 +4465,7 @@ cp_fname_init (const char* name, tree *type_p) static tree cp_make_fname_decl (location_t loc, tree id, int type_dep) { - const char *const name = (type_dep && processing_template_decl + const char *const name = (type_dep && in_template_function () ? NULL : fname_as_string (type_dep)); tree type; tree init = cp_fname_init (name, &type); @@ -7064,8 +7064,9 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, init = NULL_TREE; release_tree_vector (cleanups); } - else if (!DECL_PRETTY_FUNCTION_P (decl)) + else { + gcc_assert (!DECL_PRETTY_FUNCTION_P (decl)); /* Deduce array size even if the initializer is dependent. */ maybe_deduce_size_from_array_init (decl, init); /* And complain about multiple initializers. */ diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c index 297327f1ab6..318671bbcd0 100644 --- a/gcc/cp/lambda.c +++ b/gcc/cp/lambda.c @@ -262,6 +262,7 @@ is_capture_proxy (tree decl) && DECL_HAS_VALUE_EXPR_P (decl) && !DECL_ANON_UNION_VAR_P (decl) && !DECL_DECOMPOSITION_P (decl) + && !DECL_FNAME_P (decl) && LAMBDA_FUNCTION_P (DECL_CONTEXT (decl))); } diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 6975027076e..510264d38a0 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -16702,6 +16702,10 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, register_local_specialization (inst, decl); break; } + else if (DECL_PRETTY_FUNCTION_P (decl)) + decl = make_fname_decl (DECL_SOURCE_LOCATION (decl), + DECL_NAME (decl), + true/*DECL_PRETTY_FUNCTION_P (decl)*/); else if (DECL_IMPLICIT_TYPEDEF_P (decl) && LAMBDA_TYPE_P (TREE_TYPE (decl))) /* Don't copy the old closure; we'll create a new one in @@ -16746,19 +16750,6 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, DECL_CONTEXT (decl) = current_function_decl; cp_check_omp_declare_reduction (decl); } - else if (VAR_P (decl) - && DECL_PRETTY_FUNCTION_P (decl)) - { - /* For __PRETTY_FUNCTION__ we have to adjust the - initializer. */ - const char *const name - = cxx_printable_name (current_function_decl, 2); - init = cp_fname_init (name, &TREE_TYPE (decl)); - SET_DECL_VALUE_EXPR (decl, init); - DECL_HAS_VALUE_EXPR_P (decl) = 1; - DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1; - maybe_push_decl (decl); - } else { int const_init = false; diff --git a/gcc/testsuite/g++.old-deja/g++.ext/pretty4.C b/gcc/testsuite/g++.old-deja/g++.ext/pretty4.C new file mode 100644 index 00000000000..eb5d0de5cc6 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.ext/pretty4.C @@ -0,0 +1,39 @@ +// { dg-do run } +// Copyright (C) 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 3 Mar 2000 + +// __PRETTY_FUNCTION__, __FUNCTION__ and __function__ should have the +// type char const [X], where X is the right value for that particular function + +static int fail; + +void unover (char const (*)[5]) {} +void foo (char const (*)[5]) {} +void foo (void *) {fail = 1;} +void foo (void const *) {fail = 1;} +void baz (char const (&)[5]) {} + +void baz () +{ + static void const *ptr = __FUNCTION__; + // all uses should be the same. + if (ptr != __FUNCTION__) + fail = 1; +} + +int main () +{ + // make sure we actually emit the VAR_DECL when needed, and things have the + // expected type. + foo (&__FUNCTION__); + baz (__FUNCTION__); + unover (&__FUNCTION__); + if (fail) + return 1; + + baz (); + if (fail) + return 1; + + return 0; +} --------------4B1CDCFBDE64315E3B51CF65--