From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 101917 invoked by alias); 25 Apr 2017 11:48:40 -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 101637 invoked by uid 89); 25 Apr 2017 11:48:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS,URIBL_RED autolearn=ham version=3.3.2 spammy=merrill, Merrill, sk:segher, U*segher X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Apr 2017 11:48:19 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id C7204AC39; Tue, 25 Apr 2017 11:48:05 +0000 (UTC) To: GCC Patches Cc: Jason Merrill , Segher Boessenkool From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Subject: [PATCH] Make __FUNCTION__ a mergeable string and do not generate symbol entry. Message-ID: Date: Tue, 25 Apr 2017 11:58:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2516C6F531CC550B53D7D3A1" X-IsSubscribed: yes X-SW-Source: 2017-04/txt/msg01170.txt.bz2 This is a multi-part message in MIME format. --------------2516C6F531CC550B53D7D3A1 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-length: 356 Hello. This is patch that was originally installed by Jason and later reverted due to PR70422. In the later PR Richi suggested a fix for that and Segher verified that it helped him to survive regression tests. That's reason why I'm resending that. Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. Ready to be installed? Martin --------------2516C6F531CC550B53D7D3A1 Content-Type: text/x-patch; name="0001-Make-__FUNCTION__-a-mergeable-string-and-do-not-gene.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Make-__FUNCTION__-a-mergeable-string-and-do-not-gene.pa"; filename*1="tch" Content-length: 8493 >From a34ce0ef37ae00609c9f3ff98a9cb0b7db6a8bd0 Mon Sep 17 00:00:00 2001 From: marxin Date: Thu, 20 Apr 2017 14:56:30 +0200 Subject: [PATCH] Make __FUNCTION__ a mergeable string and do not generate symbol entry. gcc/cp/ChangeLog: 2017-04-20 Jason Merrill Martin Liska Segher Boessenkool PR c++/64266 PR c++/70353 PR bootstrap/70422 Core issue 1962 * decl.c (cp_fname_init): Decay the initializer to pointer. (cp_make_fname_decl): Set DECL_DECLARED_CONSTEXPR_P, * pt.c (tsubst_expr) [DECL_EXPR]: Set DECL_VALUE_EXPR, DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P and DECL_IGNORED_P. Don't call cp_finish_decl. gcc/testsuite/ChangeLog: 2017-04-20 Jason Merrill Segher Boessenkool PR c++/64266 PR c++/70353 PR bootstrap/70422 Core issue 1962 * g++.dg/cpp0x/constexpr-__func__2.C: Add static assert test. * g++.dg/ext/fnname5.C: New test. * g++.old-deja/g++.ext/pretty4.C: Remove. --- gcc/cp/decl.c | 20 ++++-- gcc/cp/pt.c | 26 +++++--- gcc/testsuite/g++.dg/cpp0x/constexpr-__func__2.C | 7 +- gcc/testsuite/g++.dg/ext/fnname5.C | 33 +++++++++ gcc/testsuite/g++.old-deja/g++.ext/pretty4.C | 85 ------------------------ 5 files changed, 66 insertions(+), 105 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/fnname5.C delete mode 100644 gcc/testsuite/g++.old-deja/g++.ext/pretty4.C diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 8e9a466afa0..c418fa4ce89 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -4348,13 +4348,15 @@ cp_fname_init (const char* name, tree *type_p) type = cp_build_qualified_type (char_type_node, TYPE_QUAL_CONST); type = build_cplus_array_type (type, domain); - *type_p = type; + *type_p = type_decays_to (type); if (init) TREE_TYPE (init) = type; else init = error_mark_node; + init = decay_conversion (init, tf_warning_or_error); + return init; } @@ -4380,12 +4382,21 @@ cp_make_fname_decl (location_t loc, tree id, int type_dep) /* As we're using pushdecl_with_scope, we must set the context. */ DECL_CONTEXT (decl) = current_function_decl; - TREE_STATIC (decl) = 1; TREE_READONLY (decl) = 1; DECL_ARTIFICIAL (decl) = 1; + DECL_IGNORED_P (decl) = 1; + DECL_DECLARED_CONSTEXPR_P (decl) = 1; TREE_USED (decl) = 1; + if (init) + { + SET_DECL_VALUE_EXPR (decl, init); + DECL_HAS_VALUE_EXPR_P (decl) = 1; + /* For decl_constant_var_p. */ + DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1; + } + if (current_function_decl) { cp_binding_level *b = current_binding_level; @@ -4394,13 +4405,12 @@ cp_make_fname_decl (location_t loc, tree id, int type_dep) while (b->level_chain->kind != sk_function_parms) b = b->level_chain; pushdecl_with_scope (decl, b, /*is_friend=*/false); - cp_finish_decl (decl, init, /*init_const_expr_p=*/false, NULL_TREE, - LOOKUP_ONLYCONVERTING); + add_decl_expr (decl); } else { DECL_THIS_STATIC (decl) = true; - pushdecl_top_level_and_finish (decl, init); + pushdecl_top_level_and_finish (decl, NULL_TREE); } return decl; diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index f8436b30b37..8d8cd0c5861 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -15808,21 +15808,25 @@ 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; maybe_push_decl (decl); - 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)); - } - else - init = tsubst_init (init, decl, args, complain, in_decl); + + init = tsubst_init (init, decl, args, complain, in_decl); if (VAR_P (decl)) const_init = (DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-__func__2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-__func__2.C index e6782905423..673fb4f3a93 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-__func__2.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-__func__2.C @@ -1,5 +1,5 @@ // PR c++/70353 -// { dg-do link { target c++11 } } +// { dg-do compile { target c++11 } } constexpr const char* ce () { @@ -8,6 +8,5 @@ constexpr const char* ce () const char *c = ce(); -int main() -{ -} +#define SA(X) static_assert((X),#X) +SA(ce()[0] == 'c'); diff --git a/gcc/testsuite/g++.dg/ext/fnname5.C b/gcc/testsuite/g++.dg/ext/fnname5.C new file mode 100644 index 00000000000..04fa7d3f92d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/fnname5.C @@ -0,0 +1,33 @@ +// PR c++/64266 +/* { dg-do compile } */ + +extern "C" int printf (const char *, ...); + +struct A +{ + void foo(int i) + { + printf ("__FUNCTION__ = %s\n", __FUNCTION__); + printf ("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__); + } + + void foo() + { + printf ("__FUNCTION__ = %s\n", __FUNCTION__); + } +}; + +int +main () +{ + A a; + a.foo (0); + a.foo (); + return 0; +} + +/* { dg-final { scan-assembler-not "_ZZN1A3fooEvE12__FUNCTION__" } } */ +/* { dg-final { scan-assembler-not "_ZZN1A3fooEiE12__FUNCTION__" } } */ +/* { dg-final { scan-assembler-not "_ZZN1A3fooEiE19__PRETTY_FUNCTION__" } } */ +/* { dg-final { scan-assembler ".(string|ascii)\\s+\"void A::foo\\(int\\)(.0)?\"" } } */ +/* { dg-final { scan-assembler ".(string|ascii)\\s+\"foo(.0)?\"" } } */ diff --git a/gcc/testsuite/g++.old-deja/g++.ext/pretty4.C b/gcc/testsuite/g++.old-deja/g++.ext/pretty4.C deleted file mode 100644 index 9017d567132..00000000000 --- a/gcc/testsuite/g++.old-deja/g++.ext/pretty4.C +++ /dev/null @@ -1,85 +0,0 @@ -// { 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 void const *strings[4]; -static void const *tpls[4]; -static unsigned pos = 0; -static int fail; -static void const *ptr = 0; - -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]) {} - -template void PV (char const (&objRef)[I]) -{ - strings[pos] = objRef; - tpls[pos] = __PRETTY_FUNCTION__; - pos++; -} - -void fn () -{ - PV (__FUNCTION__); - PV (__func__); - PV (__PRETTY_FUNCTION__); - PV ("wibble"); -} - -void baz () -{ - ptr = __FUNCTION__; - // there should be no string const merging - if (ptr == "baz") - fail = 1; - // but all uses should be the same. - if (ptr != __FUNCTION__) - fail = 1; -} -int baz (int) -{ - return ptr == __FUNCTION__; -} - -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; - - // __FUNCTION__ should be unique across functions with the same base name - // (it's a local static, _not_ a string). - baz (); - if (fail) - return 1; - if (baz (1)) - return 1; - fn (); - - // Check the names of fn. They should all be distinct strings (though two - // will have the same value). - if (strings[0] == strings[1]) - return 1; - if (strings[0] == strings[2]) - return 1; - if (strings[1] == strings[2]) - return 1; - - // check the names of the template functions so invoked - if (tpls[0] != tpls[1]) - return 1; - if (tpls[0] == tpls[2]) - return 1; - - return 0; -} -- 2.12.2 --------------2516C6F531CC550B53D7D3A1--