From patchwork Mon Oct 4 16:20:29 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 66710 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 7315AB70DC for ; Tue, 5 Oct 2010 03:20:42 +1100 (EST) Received: (qmail 5614 invoked by alias); 4 Oct 2010 16:20:40 -0000 Received: (qmail 5577 invoked by uid 22791); 4 Oct 2010 16:20:38 -0000 X-SWARE-Spam-Status: No, hits=-6.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_TM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 04 Oct 2010 16:20:31 +0000 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o94GKULx027379 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 4 Oct 2010 12:20:30 -0400 Received: from [127.0.0.1] (ovpn-113-109.phx2.redhat.com [10.3.113.109]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o94GKTfF007145 for ; Mon, 4 Oct 2010 12:20:30 -0400 Message-ID: <4CA9FECD.2010606@redhat.com> Date: Mon, 04 Oct 2010 12:20:29 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.14) Gecko/20101002 Lightning/1.0b1 Shredder/3.0.9pre MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH to add decl_storage_duration Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org The constexpr code wants to look at the storage duration of a decl, and it seemed odd to me that there wasn't already a function for that. This function isn't currently used by anything, but it is used by the constexpr code that I'll be merging in soon. Tested x86_64-pc-linux-gnu, applied to trunk. commit 69828ddfbcbe5a791ed15fb304a2079364544617 Author: Jason Merrill Date: Mon Oct 4 10:00:11 2010 -0400 * tree.c (decl_storage_duration): New. * cp-tree.h: Declare it. (duration_kind): Return values. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 6ce10e6..fa62570 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -3934,6 +3934,13 @@ typedef enum linkage_kind { lk_external /* External linkage. */ } linkage_kind; +typedef enum duration_kind { + dk_static, + dk_thread, + dk_auto, + dk_dynamic +} duration_kind; + /* Bitmask flags to control type substitution. */ enum tsubst_flags { tf_none = 0, /* nothing special */ @@ -5402,6 +5409,7 @@ extern int count_trees (tree); extern int char_type_p (tree); extern void verify_stmt_tree (tree); extern linkage_kind decl_linkage (tree); +extern duration_kind decl_storage_duration (tree); extern tree cp_walk_subtrees (tree*, int*, walk_tree_fn, void*, struct pointer_set_t*); #define cp_walk_tree(a,b,c,d) \ diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index ddfb354..174500e 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -2985,6 +2985,25 @@ decl_linkage (tree decl) /* Everything else has internal linkage. */ return lk_internal; } + +/* Returns the storage duration of the object or reference associated with + the indicated DECL, which should be a VAR_DECL or PARM_DECL. */ + +duration_kind +decl_storage_duration (tree decl) +{ + if (TREE_CODE (decl) == PARM_DECL) + return dk_auto; + if (TREE_CODE (decl) == FUNCTION_DECL) + return dk_static; + gcc_assert (TREE_CODE (decl) == VAR_DECL); + if (!TREE_STATIC (decl) + && !DECL_EXTERNAL (decl)) + return dk_auto; + if (DECL_THREAD_LOCAL_P (decl)) + return dk_thread; + return dk_static; +} /* EXP is an expression that we want to pre-evaluate. Returns (in *INITP) an expression that will perform the pre-evaluation. The