From patchwork Fri Oct 2 12:01:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1375682 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=bv3Tzq1v; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C2pVk4VP1z9s1t for ; Fri, 2 Oct 2020 22:01:16 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 869B7398D009; Fri, 2 Oct 2020 12:01:13 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by sourceware.org (Postfix) with ESMTPS id BD3F8398B878 for ; Fri, 2 Oct 2020 12:01:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BD3F8398B878 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qt1-x830.google.com with SMTP id 19so942068qtp.1 for ; Fri, 02 Oct 2020 05:01:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=ufGB4C6x7D4VuDfF+Iit2T8rlBrzYKWTwD98WTLgGrs=; b=bv3Tzq1va0v+zGqrDAIdihRcvlbUqJKxlvV1bjWfRIml/b9faivSgtdhGhngribb+J fcPKVmDjzcjJnesZL1lh/rItIQMG9YWvgqwM8jFB6wIKr8FyTIfa6gkvQcW0WU26hmf6 b1Sx86eOSIehDfjwr8ZBQ7MndvxlxE+wkqodvezn+y1vmv9yFbxjE7ZL5FhuNMY9xgC+ NxK/jVGM0KcJOtQtVBVocbAe0RxRIpi0UXQpd85zgzPchTf9lpphfepzcxqQYwaBX5lR bCuIbE+CRjYb31Me9EBkKyL5rlMSON+xC6HrsKJSIfOEJEF94E0eKumlSeoEKV4tIKU3 OVyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=ufGB4C6x7D4VuDfF+Iit2T8rlBrzYKWTwD98WTLgGrs=; b=X4gt+5zA2SUk6yiuNYOrsXYu5SbVNy7qBK1/A6L6+byX45UtMvSrRdAUxA4ghjtGdK ztfysjaib+2KVXcNJHdr3whzA13rwlxwHi7fIb9bfKpNFMTziMMzHJamNTw6HL7lpIIk im0Hnzj4fX8xgke+jjTiSWMfy8+DjRF8g7lkELp+w5k/3O/mN79CEA+loXTuPQAROSbT ll9dWlQMpiHmpeKmMuBmmgRaa+AkET9igC38l8X1ltP2VQ2CD3rg919f2W4/C+5rvjXJ Q6RmHTdYvFtwCpmGxsIpyiGtSKePn6mTlYKlJCXklU/2ZNgkcNnAM6Jk4B8NscwEt+AL BB6A== X-Gm-Message-State: AOAM532Yc7r0cYQ9bYCk2Fmm+GfjEVG9mrhl4jFBZ2liQiAJ34ctSJ44 +0+of4Ig0LiOWlfhiSjVBh4= X-Google-Smtp-Source: ABdhPJzAIV5yPhkhubOwpcio/01uKnRmX6PNyivSaWoKFyOb3NhAajQRdSMb6UCB4NFbuHAOcTUsKQ== X-Received: by 2002:ac8:38b4:: with SMTP id f49mr1740446qtc.97.1601640070083; Fri, 02 Oct 2020 05:01:10 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a8:1102:c54d:f6a0:d608:f6d3? ([2620:10d:c091:480::1:60a7]) by smtp.googlemail.com with ESMTPSA id f3sm835194qtg.71.2020.10.02.05.01.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 02 Oct 2020 05:01:08 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: c++: Simplify __FUNCTION__ creation Message-ID: <693bf0fd-bb88-a393-c90b-1dd792a588e6@acm.org> Date: Fri, 2 Oct 2020 08:01:07 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-10.0 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, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" I had reason to wander into cp_make_fname, and noticed it's the only caller of cp_fname_init. Folding it in makes the code simpler. gcc/cp/ * cp-tree.h (cp_fname_init): Delete declaration. * decl.c (cp_fname_init): Merge into only caller ... (cp_make_fname): ... here & refactor. pushing to trunk nathan diff --git i/gcc/cp/cp-tree.h w/gcc/cp/cp-tree.h index 3ccd54ce24b..aa93b11b91f 100644 --- i/gcc/cp/cp-tree.h +++ w/gcc/cp/cp-tree.h @@ -6520,7 +6520,6 @@ extern tree create_implicit_typedef (tree, tree); extern int local_variable_p (const_tree); extern tree register_dtor_fn (tree); extern tmpl_spec_kind current_tmpl_spec_kind (int); -extern tree cp_fname_init (const char *, tree *); extern tree cxx_builtin_function (tree decl); extern tree cxx_builtin_function_ext_scope (tree decl); extern tree cxx_simulate_builtin_function_decl (tree); diff --git i/gcc/cp/decl.c w/gcc/cp/decl.c index d2a8d4012ab..6b306ee4667 100644 --- i/gcc/cp/decl.c +++ w/gcc/cp/decl.c @@ -4592,38 +4592,6 @@ cxx_init_decl_processing (void) using_eh_for_cleanups (); } -/* Generate an initializer for a function naming variable from - NAME. NAME may be NULL, to indicate a dependent name. TYPE_P is - filled in with the type of the init. */ - -tree -cp_fname_init (const char* name, tree *type_p) -{ - tree domain = NULL_TREE; - tree type; - tree init = NULL_TREE; - size_t length = 0; - - if (name) - { - length = strlen (name); - domain = build_index_type (size_int (length)); - init = build_string (length + 1, name); - } - - type = cp_build_qualified_type (char_type_node, TYPE_QUAL_CONST); - type = build_cplus_array_type (type, domain); - - *type_p = type; - - if (init) - TREE_TYPE (init) = type; - else - init = error_mark_node; - - return init; -} - /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give the decl, LOC is the location to give the decl, NAME is the initialization string and TYPE_DEP indicates whether NAME depended @@ -4634,31 +4602,45 @@ 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 * name = NULL; - bool release_name = false; + tree domain = NULL_TREE; + tree init = NULL_TREE; + if (!(type_dep && in_template_function ())) { + const char *name = NULL; + bool release_name = false; + if (current_function_decl == NULL_TREE) name = "top level"; - else if (type_dep == 1) /* __PRETTY_FUNCTION__ */ - name = cxx_printable_name (current_function_decl, 2); - else if (type_dep == 0) /* __FUNCTION__ */ + else if (type_dep == 0) { + /* __FUNCTION__ */ name = fname_as_string (type_dep); release_name = true; } else - gcc_unreachable (); + { + /* __PRETTY_FUNCTION__ */ + gcc_checking_assert (type_dep == 1); + name = cxx_printable_name (current_function_decl, 2); + } + + size_t length = strlen (name); + domain = build_index_type (size_int (length)); + init = build_string (length + 1, name); + if (release_name) + free (const_cast (name)); } - tree type; - tree init = cp_fname_init (name, &type); - tree decl = build_decl (loc, VAR_DECL, id, type); - if (release_name) - free (CONST_CAST (char *, name)); + tree type = cp_build_qualified_type (char_type_node, TYPE_QUAL_CONST); + type = build_cplus_array_type (type, domain); - /* As we're using pushdecl_with_scope, we must set the context. */ - DECL_CONTEXT (decl) = current_function_decl; + if (init) + TREE_TYPE (init) = type; + else + init = error_mark_node; + + tree decl = build_decl (loc, VAR_DECL, id, type); TREE_READONLY (decl) = 1; DECL_ARTIFICIAL (decl) = 1; @@ -4667,13 +4649,10 @@ cp_make_fname_decl (location_t loc, tree id, int type_dep) 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; - } + 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) { @@ -4685,7 +4664,7 @@ cp_make_fname_decl (location_t loc, tree id, int type_dep) else { DECL_THIS_STATIC (decl) = true; - pushdecl_top_level_and_finish (decl, NULL_TREE); + decl = pushdecl_top_level_and_finish (decl, NULL_TREE); } return decl;