This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH][RFC] Transition C++ FE to use TRANSLATION_UNIT_DECL context for globals
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Cc: jason at redhat dot com
- Date: Fri, 24 Sep 2010 16:40:43 +0200 (CEST)
- Subject: [PATCH][RFC] Transition C++ FE to use TRANSLATION_UNIT_DECL context for globals
This is a start at using TRANSLATION_UNIT_DECL for DECL_CONTEXT of
file-scope entities. The idea is to make the translation-unit decl
the context of global_namespace and adjust FROB_CONTEXT accordingly.
And then deal with the fallout (which the following patch only
partially does).
Is that approach ok in general? If so I'll continue fixing whatever
the testsuite and bootstrap catches.
The idea is of course to support proper language-specific debuginfo
from mixed-language LTO units.
Thanks,
Richard.
2010-09-24 Richard Guenther <rguenther@suse.de>
* cp-tree.h (CP_DECL_CONTEXT): Check DECL_FILE_SCOPE_P.
(CP_TYPE_CONTEXT): Similar.
(FROB_CONTEXT): Frob global_namespace to the global
TRANSLATION_UNIT_DECL.
* decl.c (cxx_init_decl_processing): Build a TRANSLATION_UNIT_DECL,
set DECL_CONTEXT of global_namespace to it.
.... fix fallout ....
Index: gcc/cp/cp-tree.h
===================================================================
*** gcc/cp/cp-tree.h.orig 2010-09-24 15:44:43.000000000 +0200
--- gcc/cp/cp-tree.h 2010-09-24 15:50:37.000000000 +0200
*************** struct GTY((variable_size)) lang_decl {
*** 2363,2372 ****
/* NULL_TREE in DECL_CONTEXT represents the global namespace. */
#define CP_DECL_CONTEXT(NODE) \
! (DECL_CONTEXT (NODE) ? DECL_CONTEXT (NODE) : global_namespace)
#define CP_TYPE_CONTEXT(NODE) \
! (TYPE_CONTEXT (NODE) ? TYPE_CONTEXT (NODE) : global_namespace)
! #define FROB_CONTEXT(NODE) ((NODE) == global_namespace ? NULL_TREE : (NODE))
/* 1 iff NODE has namespace scope, including the global namespace. */
#define DECL_NAMESPACE_SCOPE_P(NODE) \
--- 2363,2374 ----
/* NULL_TREE in DECL_CONTEXT represents the global namespace. */
#define CP_DECL_CONTEXT(NODE) \
! (!DECL_FILE_SCOPE_P (NODE) ? DECL_CONTEXT (NODE) : global_namespace)
#define CP_TYPE_CONTEXT(NODE) \
! ((TYPE_CONTEXT (NODE) \
! && TREE_CODE (TYPE_CONTEXT (NODE)) != TRANSLATION_UNIT_DECL) \
! ? TYPE_CONTEXT (NODE) : global_namespace)
! #define FROB_CONTEXT(NODE) ((NODE) == global_namespace ? DECL_CONTEXT (NODE) : (NODE))
/* 1 iff NODE has namespace scope, including the global namespace. */
#define DECL_NAMESPACE_SCOPE_P(NODE) \
Index: gcc/cp/decl.c
===================================================================
*** gcc/cp/decl.c.orig 2010-09-24 15:44:43.000000000 +0200
--- gcc/cp/decl.c 2010-09-24 16:13:43.000000000 +0200
*************** cxx_init_decl_processing (void)
*** 3417,3422 ****
--- 3417,3423 ----
gcc_assert (global_namespace == NULL_TREE);
global_namespace = build_lang_decl (NAMESPACE_DECL, global_scope_name,
void_type_node);
+ DECL_CONTEXT (global_namespace) = build_translation_unit_decl (NULL_TREE);
TREE_PUBLIC (global_namespace) = 1;
begin_scope (sk_namespace, global_namespace);
*************** start_decl (const cp_declarator *declara
*** 4241,4247 ****
&& lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
warning (0, "inline function %q+D given attribute noinline", decl);
! if (context && COMPLETE_TYPE_P (complete_type (context)))
{
if (TREE_CODE (decl) == VAR_DECL)
{
--- 4242,4250 ----
&& lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
warning (0, "inline function %q+D given attribute noinline", decl);
! if (context
! && TREE_CODE (context) != TRANSLATION_UNIT_DECL
! && COMPLETE_TYPE_P (complete_type (context)))
{
if (TREE_CODE (decl) == VAR_DECL)
{
*************** grokfndecl (tree ctype,
*** 6888,6895 ****
&& strncmp (IDENTIFIER_POINTER (declarator)+2, "builtin_", 8) == 0))
&& current_lang_name == lang_name_cplusplus
&& ctype == NULL_TREE
! /* NULL_TREE means global namespace. */
! && DECL_CONTEXT (decl) == NULL_TREE)
SET_DECL_LANGUAGE (decl, lang_c);
/* Should probably propagate const out from type to decl I bet (mrs). */
--- 6891,6897 ----
&& strncmp (IDENTIFIER_POINTER (declarator)+2, "builtin_", 8) == 0))
&& current_lang_name == lang_name_cplusplus
&& ctype == NULL_TREE
! && DECL_FILE_SCOPE_P (decl))
SET_DECL_LANGUAGE (decl, lang_c);
/* Should probably propagate const out from type to decl I bet (mrs). */
Index: gcc/cp/name-lookup.c
===================================================================
*** gcc/cp/name-lookup.c.orig 2010-09-13 11:11:54.000000000 +0200
--- gcc/cp/name-lookup.c 2010-09-24 16:00:30.000000000 +0200
*************** maybe_push_decl (tree decl)
*** 1166,1172 ****
DECL or it may be a previous decl of the same name. */
if (decl == error_mark_node
|| (TREE_CODE (decl) != PARM_DECL
! && DECL_CONTEXT (decl) != NULL_TREE
/* Definitions of namespace members outside their namespace are
possible. */
&& TREE_CODE (DECL_CONTEXT (decl)) != NAMESPACE_DECL)
--- 1166,1172 ----
DECL or it may be a previous decl of the same name. */
if (decl == error_mark_node
|| (TREE_CODE (decl) != PARM_DECL
! && !DECL_FILE_SCOPE_P (decl)
/* Definitions of namespace members outside their namespace are
possible. */
&& TREE_CODE (DECL_CONTEXT (decl)) != NAMESPACE_DECL)
*************** namespace_binding (tree name, tree scope
*** 3068,3074 ****
{
cxx_binding *binding;
! if (scope == NULL)
scope = global_namespace;
else
/* Unnecessary for the global namespace because it can't be an alias. */
--- 3068,3075 ----
{
cxx_binding *binding;
! if (scope == NULL
! || TREE_CODE (scope) == TRANSLATION_UNIT_DECL)
scope = global_namespace;
else
/* Unnecessary for the global namespace because it can't be an alias. */
Index: gcc/cp/pt.c
===================================================================
*** gcc/cp/pt.c.orig 2010-09-13 11:11:54.000000000 +0200
--- gcc/cp/pt.c 2010-09-24 16:32:59.000000000 +0200
*************** template_class_depth (tree type)
*** 342,348 ****
int depth;
for (depth = 0;
! type && TREE_CODE (type) != NAMESPACE_DECL;
type = (TREE_CODE (type) == FUNCTION_DECL)
? CP_DECL_CONTEXT (type) : TYPE_CONTEXT (type))
{
--- 342,349 ----
int depth;
for (depth = 0;
! type && TREE_CODE (type) != NAMESPACE_DECL
! && TREE_CODE (type) != TRANSLATION_UNIT_DECL;
type = (TREE_CODE (type) == FUNCTION_DECL)
? CP_DECL_CONTEXT (type) : TYPE_CONTEXT (type))
{
*************** tsubst (tree t, tree args, tsubst_flags_
*** 10012,10018 ****
|| t == void_type_node
|| t == char_type_node
|| t == unknown_type_node
! || TREE_CODE (t) == NAMESPACE_DECL)
return t;
if (DECL_P (t))
--- 10013,10020 ----
|| t == void_type_node
|| t == char_type_node
|| t == unknown_type_node
! || TREE_CODE (t) == NAMESPACE_DECL
! || TREE_CODE (t) == TRANSLATION_UNIT_DECL)
return t;
if (DECL_P (t))