* [C++ PATCH] conversion operator names
@ 2017-06-30 18:48 Nathan Sidwell
2017-06-30 18:53 ` Nathan Sidwell
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Nathan Sidwell @ 2017-06-30 18:48 UTC (permalink / raw)
To: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 397 bytes --]
We used to give conversion operatos type-specific mangled names. Now we
just number them 'operator $N' for N in [1,...]. As such
mangle_convop_name_for_type is misnamed and has no place in mangle.c
This patch moves that machinery to lex.c, which is a better place (best
place?). Other than renaming to make_conv_op_name, nothing else
changes. For. The. Moment.
nathan
--
Nathan Sidwell
[-- Attachment #2: convop-move.diff --]
[-- Type: text/x-patch, Size: 10854 bytes --]
2017-06-30 Nathan Sidwell <nathan@acm.org>
* config-lang.in (gtfiles): Add cp/lex.c.
* cp-tree.h (mangle_convop_name_for_type): Rename ...
(make_conv_op_name): ... here. Move to lex.
* lambda.c (maybe_add_lambda_conv_op): Update.
* parser.c (cp_parser_conversion_function_id): Update.
* pt.c (tsubst_decl, tsubst_baselink, tsubst_copy,
tsubst_copy_and_build): Update.
* semantics.c (apply_deduced_return_type): Update.
* mangle.c (conv_type_hasher, conv_type_names,
mangle_conv_op_name_for_type): Move to ...
* lex.c (conv_type_hasher, conv_type_names, make_convop_name):
... here. Rename.
* libcp1plugin.cc (plugin_build_decl): Use make_conv_op_name.
(plugin_build_dependent_expr): Likewise.
Index: gcc/cp/config-lang.in
===================================================================
--- gcc/cp/config-lang.in (revision 249835)
+++ gcc/cp/config-lang.in (working copy)
@@ -45,7 +45,7 @@ gtfiles="\
\$(srcdir)/cp/except.c \
\$(srcdir)/cp/friend.c \
\$(srcdir)/cp/init.c \
-\$(srcdir)/cp/lambda.c \
+\$(srcdir)/cp/lambda.c \$(srcdir)/cp/lex.c \
\$(srcdir)/cp/mangle.c \$(srcdir)/cp/method.c \
\$(srcdir)/cp/name-lookup.c \
\$(srcdir)/cp/parser.c \$(srcdir)/cp/pt.c \
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h (revision 249843)
+++ gcc/cp/cp-tree.h (working copy)
@@ -6326,6 +6326,7 @@ extern void yyungetc (int, int);
extern tree unqualified_name_lookup_error (tree,
location_t = UNKNOWN_LOCATION);
extern tree unqualified_fn_lookup_error (cp_expr);
+extern tree make_conv_op_name (tree);
extern tree build_lang_decl (enum tree_code, tree, tree);
extern tree build_lang_decl_loc (location_t, enum tree_code, tree, tree);
extern void retrofit_lang_decl (tree);
@@ -7180,7 +7181,6 @@ extern tree mangle_vtbl_for_type (tree)
extern tree mangle_vtt_for_type (tree);
extern tree mangle_ctor_vtbl_for_type (tree, tree);
extern tree mangle_thunk (tree, int, tree, tree, tree);
-extern tree mangle_conv_op_name_for_type (tree);
extern tree mangle_guard_variable (tree);
extern tree mangle_tls_init_fn (tree);
extern tree mangle_tls_wrapper_fn (tree);
Index: gcc/cp/lambda.c
===================================================================
--- gcc/cp/lambda.c (revision 249835)
+++ gcc/cp/lambda.c (working copy)
@@ -1088,7 +1088,7 @@ maybe_add_lambda_conv_op (tree type)
/* First build up the conversion op. */
tree rettype = build_pointer_type (stattype);
- tree name = mangle_conv_op_name_for_type (rettype);
+ tree name = make_conv_op_name (rettype);
tree thistype = cp_build_qualified_type (type, TYPE_QUAL_CONST);
tree fntype = build_method_type_directly (thistype, rettype, void_list_node);
tree convfn = build_lang_decl (FUNCTION_DECL, name, fntype);
Index: gcc/cp/lex.c
===================================================================
--- gcc/cp/lex.c (revision 249835)
+++ gcc/cp/lex.c (working copy)
@@ -531,6 +531,74 @@ unqualified_fn_lookup_error (cp_expr nam
return unqualified_name_lookup_error (name, loc);
}
+struct conv_type_hasher : ggc_ptr_hash<tree_node>
+{
+ static hashval_t hash (tree);
+ static bool equal (tree, tree);
+};
+
+/* This hash table maps TYPEs to the IDENTIFIER for a conversion
+ operator to TYPE. The nodes are IDENTIFIERs whose TREE_TYPE is the
+ TYPE. */
+
+static GTY (()) hash_table<conv_type_hasher> *conv_type_names;
+
+/* Hash a node (VAL1) in the table. */
+
+hashval_t
+conv_type_hasher::hash (tree val)
+{
+ return (hashval_t) TYPE_UID (TREE_TYPE (val));
+}
+
+/* Compare VAL1 (a node in the table) with VAL2 (a TYPE). */
+
+bool
+conv_type_hasher::equal (tree val1, tree val2)
+{
+ return TREE_TYPE (val1) == val2;
+}
+
+/* Return an identifier for a conversion operator to TYPE. We can
+ get from the returned identifier to the type. */
+
+tree
+make_conv_op_name (tree type)
+{
+ tree *slot;
+ tree identifier;
+
+ if (type == error_mark_node)
+ return error_mark_node;
+
+ if (conv_type_names == NULL)
+ conv_type_names = hash_table<conv_type_hasher>::create_ggc (31);
+
+ slot = conv_type_names->find_slot_with_hash (type,
+ (hashval_t) TYPE_UID (type),
+ INSERT);
+ identifier = *slot;
+ if (!identifier)
+ {
+ char buffer[64];
+
+ /* Create a unique name corresponding to TYPE. */
+ sprintf (buffer, "operator %lu",
+ (unsigned long) conv_type_names->elements ());
+ identifier = get_identifier (buffer);
+ *slot = identifier;
+
+ /* Hang TYPE off the identifier so it can be found easily later
+ when performing conversions. */
+ TREE_TYPE (identifier) = type;
+
+ /* Set the identifier kind so we know later it's a conversion. */
+ set_identifier_kind (identifier, cik_conv_op);
+ }
+
+ return identifier;
+}
+
/* Wrapper around build_lang_decl_loc(). Should gradually move to
build_lang_decl_loc() and then rename build_lang_decl_loc() back to
build_lang_decl(). */
@@ -799,3 +867,5 @@ in_main_input_context (void)
else
return filename_cmp (main_input_filename, LOCATION_FILE (input_location)) == 0;
}
+
+#include "gt-cp-lex.h"
Index: gcc/cp/mangle.c
===================================================================
--- gcc/cp/mangle.c (revision 249835)
+++ gcc/cp/mangle.c (working copy)
@@ -4176,75 +4176,6 @@ mangle_thunk (tree fn_decl, const int th
return result;
}
-struct conv_type_hasher : ggc_ptr_hash<tree_node>
-{
- static hashval_t hash (tree);
- static bool equal (tree, tree);
-};
-
-/* This hash table maps TYPEs to the IDENTIFIER for a conversion
- operator to TYPE. The nodes are IDENTIFIERs whose TREE_TYPE is the
- TYPE. */
-
-static GTY (()) hash_table<conv_type_hasher> *conv_type_names;
-
-/* Hash a node (VAL1) in the table. */
-
-hashval_t
-conv_type_hasher::hash (tree val)
-{
- return (hashval_t) TYPE_UID (TREE_TYPE (val));
-}
-
-/* Compare VAL1 (a node in the table) with VAL2 (a TYPE). */
-
-bool
-conv_type_hasher::equal (tree val1, tree val2)
-{
- return TREE_TYPE (val1) == val2;
-}
-
-/* Return an identifier for the mangled unqualified name for a
- conversion operator to TYPE. This mangling is not specified by the
- ABI spec; it is only used internally. */
-
-tree
-mangle_conv_op_name_for_type (const tree type)
-{
- tree *slot;
- tree identifier;
-
- if (type == error_mark_node)
- return error_mark_node;
-
- if (conv_type_names == NULL)
- conv_type_names = hash_table<conv_type_hasher>::create_ggc (31);
-
- slot = conv_type_names->find_slot_with_hash (type,
- (hashval_t) TYPE_UID (type),
- INSERT);
- identifier = *slot;
- if (!identifier)
- {
- char buffer[64];
-
- /* Create a unique name corresponding to TYPE. */
- sprintf (buffer, "operator %lu",
- (unsigned long) conv_type_names->elements ());
- identifier = get_identifier (buffer);
- *slot = identifier;
-
- /* Hang TYPE off the identifier so it can be found easily later
- when performing conversions. */
- TREE_TYPE (identifier) = type;
-
- /* Set the identifier kind so we know later it's a conversion. */
- set_identifier_kind (identifier, cik_conv_op);
- }
-
- return identifier;
-}
-
/* Handle ABI backwards compatibility for past bugs where we didn't call
check_abi_tags in places where it's needed: call check_abi_tags and warn if
it makes a difference. If FOR_DECL is non-null, it's the declaration
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c (revision 249835)
+++ gcc/cp/parser.c (working copy)
@@ -14067,7 +14067,7 @@ cp_parser_conversion_function_id (cp_par
/* If the TYPE is invalid, indicate failure. */
if (type == error_mark_node)
return error_mark_node;
- return mangle_conv_op_name_for_type (type);
+ return make_conv_op_name (type);
}
/* Parse a conversion-type-id:
Index: gcc/cp/pt.c
===================================================================
--- gcc/cp/pt.c (revision 249843)
+++ gcc/cp/pt.c (working copy)
@@ -12385,7 +12385,7 @@ tsubst_decl (tree t, tree args, tsubst_f
if (member && DECL_CONV_FN_P (r))
/* Type-conversion operator. Reconstruct the name, in
case it's the name of one of the template's parameters. */
- DECL_NAME (r) = mangle_conv_op_name_for_type (TREE_TYPE (type));
+ DECL_NAME (r) = make_conv_op_name (TREE_TYPE (type));
DECL_ARGUMENTS (r) = tsubst (DECL_ARGUMENTS (t), args,
complain, t);
@@ -14242,7 +14242,7 @@ tsubst_baselink (tree baselink, tree obj
tree name = OVL_NAME (fns);
if (IDENTIFIER_CONV_OP_P (name))
- name = mangle_conv_op_name_for_type (optype);
+ name = make_conv_op_name (optype);
baselink = lookup_fnfields (qualifying_scope, name, /*protect=*/1);
if (!baselink)
@@ -15032,7 +15032,7 @@ tsubst_copy (tree t, tree args, tsubst_f
if (IDENTIFIER_CONV_OP_P (t))
{
tree new_type = tsubst (TREE_TYPE (t), args, complain, in_decl);
- return mangle_conv_op_name_for_type (new_type);
+ return make_conv_op_name (new_type);
}
else
return t;
@@ -16665,7 +16665,7 @@ tsubst_copy_and_build (tree t,
if (IDENTIFIER_CONV_OP_P (t))
{
tree new_type = tsubst (TREE_TYPE (t), args, complain, in_decl);
- t = mangle_conv_op_name_for_type (new_type);
+ t = make_conv_op_name (new_type);
}
/* Look up the name. */
Index: gcc/cp/semantics.c
===================================================================
--- gcc/cp/semantics.c (revision 249843)
+++ gcc/cp/semantics.c (working copy)
@@ -9399,7 +9399,7 @@ apply_deduced_return_type (tree fco, tre
}
if (DECL_CONV_FN_P (fco))
- DECL_NAME (fco) = mangle_conv_op_name_for_type (return_type);
+ DECL_NAME (fco) = make_conv_op_name (return_type);
TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco));
Index: libcc1/libcp1plugin.cc
===================================================================
--- libcc1/libcp1plugin.cc (revision 249835)
+++ libcc1/libcp1plugin.cc (working copy)
@@ -1321,7 +1321,7 @@ plugin_build_decl (cc1_plugin::connectio
opcode = ARRAY_REF;
break;
case CHARS2 ('c', 'v'): // operator <T> (conversion operator)
- identifier = mangle_conv_op_name_for_type (TREE_TYPE (sym_type));
+ identifier = make_conv_op_name (TREE_TYPE (sym_type));
break;
// C++11-only:
case CHARS2 ('l', 'i'): // operator "" <id>
@@ -2622,7 +2622,7 @@ plugin_build_dependent_expr (cc1_plugin:
break;
case CHARS2 ('c', 'v'): // operator <T> (conversion operator)
convop = true;
- identifier = mangle_conv_op_name_for_type (conv_type);
+ identifier = make_conv_op_name (conv_type);
break;
// C++11-only:
case CHARS2 ('l', 'i'): // operator "" <id>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [C++ PATCH] conversion operator names
2017-06-30 18:48 [C++ PATCH] conversion operator names Nathan Sidwell
@ 2017-06-30 18:53 ` Nathan Sidwell
2017-06-30 19:11 ` Jason Merrill
2017-07-01 21:41 ` Andreas Schwab
2 siblings, 0 replies; 8+ messages in thread
From: Nathan Sidwell @ 2017-06-30 18:53 UTC (permalink / raw)
To: GCC Patches
On 06/30/2017 02:48 PM, Nathan Sidwell wrote:
> We used to give conversion operatos type-specific mangled names. Now we
> just number them 'operator $N' for N in [1,...]. As such
> mangle_convop_name_for_type is misnamed and has no place in mangle.c
>
> This patch moves that machinery to lex.c, which is a better place (best
> place?). Other than renaming to make_conv_op_name, nothing else
> changes. For. The. Moment.
Oh, because this adds cp/lex.c to the gt list, a reconfigure at least is
necessary.
nathan
--
Nathan Sidwell
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [C++ PATCH] conversion operator names
2017-06-30 18:48 [C++ PATCH] conversion operator names Nathan Sidwell
2017-06-30 18:53 ` Nathan Sidwell
@ 2017-06-30 19:11 ` Jason Merrill
2017-06-30 19:53 ` Nathan Sidwell
2017-07-01 21:41 ` Andreas Schwab
2 siblings, 1 reply; 8+ messages in thread
From: Jason Merrill @ 2017-06-30 19:11 UTC (permalink / raw)
To: Nathan Sidwell; +Cc: GCC Patches
On Fri, Jun 30, 2017 at 2:48 PM, Nathan Sidwell <nathan@acm.org> wrote:
> We used to give conversion operatos type-specific mangled names. Now we
> just number them 'operator $N' for N in [1,...]. As such
> mangle_convop_name_for_type is misnamed and has no place in mangle.c
Hmm, wouldn't actual mangling make more sense, so that it's consistent
between compilations?
Jason
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [C++ PATCH] conversion operator names
2017-06-30 19:11 ` Jason Merrill
@ 2017-06-30 19:53 ` Nathan Sidwell
2017-06-30 20:25 ` Jason Merrill
0 siblings, 1 reply; 8+ messages in thread
From: Nathan Sidwell @ 2017-06-30 19:53 UTC (permalink / raw)
To: Jason Merrill; +Cc: GCC Patches
On 06/30/2017 03:11 PM, Jason Merrill wrote:
> On Fri, Jun 30, 2017 at 2:48 PM, Nathan Sidwell <nathan@acm.org> wrote:
>> We used to give conversion operatos type-specific mangled names. Now we
>> just number them 'operator $N' for N in [1,...]. As such
>> mangle_convop_name_for_type is misnamed and has no place in mangle.c
>
> Hmm, wouldn't actual mangling make more sense, so that it's consistent
> between compilations?
While that would work, I have a different and simpler plan in mind.
nathan
--
Nathan Sidwell
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [C++ PATCH] conversion operator names
2017-06-30 19:53 ` Nathan Sidwell
@ 2017-06-30 20:25 ` Jason Merrill
2017-07-03 14:14 ` Nathan Sidwell
0 siblings, 1 reply; 8+ messages in thread
From: Jason Merrill @ 2017-06-30 20:25 UTC (permalink / raw)
To: Nathan Sidwell; +Cc: GCC Patches
On Fri, Jun 30, 2017 at 3:53 PM, Nathan Sidwell <nathan@acm.org> wrote:
> On 06/30/2017 03:11 PM, Jason Merrill wrote:
>>
>> On Fri, Jun 30, 2017 at 2:48 PM, Nathan Sidwell <nathan@acm.org> wrote:
>>>
>>> We used to give conversion operatos type-specific mangled names. Now we
>>> just number them 'operator $N' for N in [1,...]. As such
>>> mangle_convop_name_for_type is misnamed and has no place in mangle.c
>>
>> Hmm, wouldn't actual mangling make more sense, so that it's consistent
>> between compilations?
>
> While that would work, I have a different and simpler plan in mind.
Suspense! :)
Jason
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [C++ PATCH] conversion operator names
2017-06-30 18:48 [C++ PATCH] conversion operator names Nathan Sidwell
2017-06-30 18:53 ` Nathan Sidwell
2017-06-30 19:11 ` Jason Merrill
@ 2017-07-01 21:41 ` Andreas Schwab
2017-07-03 14:23 ` Nathan Sidwell
2 siblings, 1 reply; 8+ messages in thread
From: Andreas Schwab @ 2017-07-01 21:41 UTC (permalink / raw)
To: Nathan Sidwell; +Cc: GCC Patches
On Jun 30 2017, Nathan Sidwell <nathan@acm.org> wrote:
> * config-lang.in (gtfiles): Add cp/lex.c.
> * cp-tree.h (mangle_convop_name_for_type): Rename ...
> (make_conv_op_name): ... here. Move to lex.
> * lambda.c (maybe_add_lambda_conv_op): Update.
> * parser.c (cp_parser_conversion_function_id): Update.
> * pt.c (tsubst_decl, tsubst_baselink, tsubst_copy,
> tsubst_copy_and_build): Update.
> * semantics.c (apply_deduced_return_type): Update.
> * mangle.c (conv_type_hasher, conv_type_names,
> mangle_conv_op_name_for_type): Move to ...
> * lex.c (conv_type_hasher, conv_type_names, make_convop_name):
> ... here. Rename.
>
> * libcp1plugin.cc (plugin_build_decl): Use make_conv_op_name.
> (plugin_build_dependent_expr): Likewise.
That breaks obj-c++.
spawn -ignore SIGHUP /opt/gcc/gcc-20170701/Build/gcc/testsuite/obj-c++/../../xg++ -B/opt/gcc/gcc-20170701/Build/gcc/testsuite/obj-c++/../../ /opt/gcc/gcc-20170701/gcc/testsuite/obj-c++.dg/basic.mm -mabi=lp64 -fno-diagnostics-show-caret -fdiagnostics-color=never -nostdinc++ -I/opt/gcc/gcc-20170701/Build/aarch64-suse-linux/libstdc++-v3/include/aarch64-suse-linux -I/opt/gcc/gcc-20170701/Build/aarch64-suse-linux/libstdc++-v3/include -I/opt/gcc/gcc-20170701/libstdc++-v3/libsupc++ -I/opt/gcc/gcc-20170701/libstdc++-v3/include/backward -I/opt/gcc/gcc-20170701/libstdc++-v3/testsuite/util -fmessage-length=0 -fgnu-runtime -ansi -pedantic-errors -Wno-long-long -I/opt/gcc/gcc-20170701/gcc/testsuite/../../libobjc -B/opt/gcc/gcc-20170701/Build/aarch64-suse-linux/./libstdc++-v3/src/.libs -L/opt/gcc/gcc-20170701/Build/aarch64-suse-linux/./libstdc++-v3/src/.libs -B/opt/gcc/gcc-20170701/Build/aarch64-suse-linux/./libstdc++-v3/src/.libs -L/opt/gcc/gcc-20170701/Build/aarch64-suse-linux/./libstdc++-v3/src/.libs -B/opt/gcc/gcc-20170701/Build/aarch64-suse-linux/./libobjc/.libs -L/opt/gcc/gcc-20170701/Build/aarch64-suse-linux/./libobjc/.libs -lobjc -lm -o ./basic.exe
In file included from /opt/gcc/gcc-20170701/Build/aarch64-suse-linux/libstdc++-v3/include/ios:44:0,
from /opt/gcc/gcc-20170701/Build/aarch64-suse-linux/libstdc++-v3/include/ostream:38,
from /opt/gcc/gcc-20170701/Build/aarch64-suse-linux/libstdc++-v3/include/iostream:39,
from /opt/gcc/gcc-20170701/gcc/testsuite/obj-c++.dg/basic.mm:6:
/opt/gcc/gcc-20170701/Build/aarch64-suse-linux/libstdc++-v3/include/bits/basic_ios.h:120:20: internal compiler error: Segmentation fault
0xdd6ad7 crash_signal
../../gcc/toplev.c:338
0x73077c hash_table_mod1(unsigned int, unsigned int)
../../gcc/hash-table.h:328
0x73077c hash_table<conv_type_hasher, xcallocator>::find_slot_with_hash(tree_node* const&, unsigned int, insert_option)
../../gcc/hash-table.h:884
0x73077c make_conv_op_name(tree_node*)
../../gcc/cp/lex.c:577
0x79f6f3 cp_parser_conversion_function_id
../../gcc/cp/parser.c:14084
0x79f6f3 cp_parser_unqualified_id
../../gcc/cp/parser.c:5836
0x79fb4f cp_parser_id_expression
../../gcc/cp/parser.c:5529
0x79fd23 cp_parser_parse_and_diagnose_invalid_type_name
../../gcc/cp/parser.c:3344
0x792703 cp_parser_member_declaration
../../gcc/cp/parser.c:23268
0x792dfb cp_parser_member_specification_opt
../../gcc/cp/parser.c:23117
0x792dfb cp_parser_class_specifier_1
../../gcc/cp/parser.c:22259
0x79547b cp_parser_class_specifier
../../gcc/cp/parser.c:22511
0x79547b cp_parser_type_specifier
../../gcc/cp/parser.c:16602
0x7a4b6f cp_parser_decl_specifier_seq
../../gcc/cp/parser.c:13504
0x7a9e23 cp_parser_single_declaration
../../gcc/cp/parser.c:26830
0x7aa1af cp_parser_template_declaration_after_parameters
../../gcc/cp/parser.c:26524
0x7aabef cp_parser_explicit_template_declaration
../../gcc/cp/parser.c:26759
0x7aabef cp_parser_template_declaration_after_export
../../gcc/cp/parser.c:26778
0x7b11af cp_parser_declaration
../../gcc/cp/parser.c:12623
0x7b14f7 cp_parser_declaration_seq_opt
../../gcc/cp/parser.c:12550
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [C++ PATCH] conversion operator names
2017-06-30 20:25 ` Jason Merrill
@ 2017-07-03 14:14 ` Nathan Sidwell
0 siblings, 0 replies; 8+ messages in thread
From: Nathan Sidwell @ 2017-07-03 14:14 UTC (permalink / raw)
To: Jason Merrill; +Cc: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 610 bytes --]
On 06/30/2017 04:24 PM, Jason Merrill wrote:
> Suspense! :)
Only because I wanted to go home :) I was abusing identifiers during
the streaming process, and had to clean them up anyway. At that point
it's a simple question of:
if (IDENTIFIER_CONV_OP_P (t))
{ write (tag_conv_op), write (tree_type (t)}
else
{ write (tag_ident), write_string (identifier_pointer (t)) }
with the obvious inverse operations on read back. Then the streamer's
entirely agnostic about conv op names.
I attach the patch I committed to the modules branch, if you're really
curious.
nathan
--
Nathan Sidwell
[-- Attachment #2: r249921.diff --]
[-- Type: text/x-patch, Size: 5401 bytes --]
2017-07-03 Nathan Sidwell <nathan@acm.org>
gcc/cp/
* module.c (cpms_{out,in}::start): Don't deal with identifiers
here.
(cpms_{out,in}::tree_node): Deal with identifiers specially.
Index: gcc/cp/module.c
===================================================================
--- gcc/cp/module.c (revision 249920)
+++ gcc/cp/module.c (revision 249921)
@@ -851,6 +851,8 @@ public:
rt_import, /* An import. */
rt_binding, /* A name-binding. */
rt_definition, /* A definition. */
+ rt_identifier, /* An identifier node. */
+ rt_conv_identifier, /* A conversion operator name. */
rt_trees, /* Global trees. */
rt_type_name, /* A type name. */
rt_typeinfo_var, /* A typeinfo object. */
@@ -2368,7 +2370,7 @@ cpms_out::start (tree_code code, tree t)
w.u (VL_EXP_OPERAND_LENGTH (t));
break;
case IDENTIFIER_NODE:
- w.str (IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t));
+ gcc_unreachable ();
break;
case TREE_BINFO:
w.u (BINFO_N_BASE_BINFOS (t));
@@ -2411,14 +2413,13 @@ cpms_in::start (tree_code code)
t = make_node (code);
break;
case IDENTIFIER_NODE:
+ gcc_unreachable ();
+ break;
case STRING_CST:
{
size_t l;
const char *str = r.str (&l);
- if (code == IDENTIFIER_NODE)
- t = get_identifier_with_length (str, l);
- else
- t = build_string (l, str);
+ t = build_string (l, str);
}
break;
case TREE_BINFO:
@@ -3928,6 +3929,27 @@ cpms_out::tree_node (tree t)
return;
}
+ if (TREE_CODE (t) == IDENTIFIER_NODE)
+ {
+ /* An identifier node. Stream the name or type. */
+ bool conv_op = IDENTIFIER_CONV_OP_P (t);
+
+ w.u (conv_op ? rt_conv_identifier : rt_identifier);
+ if (conv_op)
+ {
+ t = TREE_TYPE (t);
+ tree_node (t);
+ }
+ else
+ w.str (IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t));
+ unsigned tag = insert (t);
+ dump () && dump ("Written:%u %sidentifier:%N",
+ tag, conv_op ? "conv_op_" : "", t);
+ unnest ();
+ return;
+ }
+
+ /* Generic node streaming. */
tree_code code = TREE_CODE (t);
tree_code_class klass = TREE_CODE_CLASS (code);
gcc_assert (rt_tree_base + code < rt_ref_base);
@@ -3935,10 +3957,8 @@ cpms_out::tree_node (tree t)
unique++;
w.u (rt_tree_base + code);
- int body = 1;
- if (code == IDENTIFIER_NODE)
- body = 0;
- else if (klass == tcc_declaration)
+ bool body = true;
+ if (klass == tcc_declaration)
{
/* Write out ctx, name & maybe import reference info. */
tree_node (DECL_CONTEXT (t));
@@ -3952,11 +3972,11 @@ cpms_out::tree_node (tree t)
ident_imported_decl (CP_DECL_CONTEXT (t), node_module, t);
dump () && dump ("Writing imported %N@%I", t,
module_name (node_module));
- body = -1;
+ body = false;
}
}
- if (body >= 0)
+ if (body)
start (code, t);
unsigned tag = insert (t);
@@ -3964,9 +3984,9 @@ cpms_out::tree_node (tree t)
klass == tcc_declaration && DECL_MODULE_EXPORT_P (t)
? " (exported)": "");
- if (body > 0)
+ if (body)
tree_node_raw (code, t);
- else if (body < 0 && TREE_TYPE (t))
+ else if (TREE_TYPE (t))
{
tree type = TREE_TYPE (t);
bool existed;
@@ -4073,6 +4093,25 @@ cpms_in::tree_node ()
unnest ();
return res;
}
+ else if (tag == rt_identifier)
+ {
+ size_t l;
+ const char *str = r.str (&l);
+ tree id = get_identifier_with_length (str, l);
+ tag = insert (id);
+ dump () && dump ("Read:%u identifier:%N", tag, id);
+ unnest ();
+ return id;
+ }
+ else if (tag == rt_conv_identifier)
+ {
+ tree t = tree_node ();
+ tree id = make_conv_op_name (t);
+ tag = insert (id);
+ dump () && dump ("Read:%u conv_op_identifier:%N", tag, t);
+ unnest ();
+ return id;
+ }
else if (tag < rt_tree_base || tag >= rt_tree_base + MAX_TREE_CODES)
{
error (tag < rt_tree_base ? "unexpected key %qd"
@@ -4086,15 +4125,13 @@ cpms_in::tree_node ()
tree_code_class klass = TREE_CODE_CLASS (code);
tree t = NULL_TREE;
- int body = 1;
+ bool body = true;
tree name = NULL_TREE;
tree ctx = NULL_TREE;
int node_module = -1;
int set_module = -1;
- if (code == IDENTIFIER_NODE)
- body = 0;
- else if (klass == tcc_declaration)
+ if (klass == tcc_declaration)
{
ctx = tree_node ();
name = tree_node ();
@@ -4144,24 +4181,24 @@ cpms_in::tree_node ()
}
dump () && dump ("Importing %P@%I",
cp_ctx, name, module_name (node_module));
- body = -1;
+ body = false;
}
}
- if (body >= 0)
+ if (body)
t = start (code);
/* Insert into map. */
tag = insert (t);
- dump () && dump ("%s:%u %C:%N", body < 0 ? "Imported" : "Reading", tag,
- code, code == IDENTIFIER_NODE ? t : name);
+ dump () && dump ("%s:%u %C:%N", body ? "Reading" : "Imported", tag,
+ code, name);
- if (body > 0)
+ if (body)
{
if (!tree_node_raw (code, t, name, ctx, set_module))
goto barf;
}
- else if (body < 0 && TREE_TYPE (t) && !r.u ())
+ else if (TREE_TYPE (t) && !r.u ())
{
tree type = TREE_TYPE (t);
tag = insert (type);
@@ -4178,7 +4215,7 @@ cpms_in::tree_node ()
return NULL_TREE;
}
- if (body > 0)
+ if (body)
{
tree found = finish (t, node_module);
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [C++ PATCH] conversion operator names
2017-07-01 21:41 ` Andreas Schwab
@ 2017-07-03 14:23 ` Nathan Sidwell
0 siblings, 0 replies; 8+ messages in thread
From: Nathan Sidwell @ 2017-07-03 14:23 UTC (permalink / raw)
To: Andreas Schwab; +Cc: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 1348 bytes --]
On 07/01/2017 05:40 PM, Andreas Schwab wrote:
> On Jun 30 2017, Nathan Sidwell <nathan@acm.org> wrote:
>
>> * config-lang.in (gtfiles): Add cp/lex.c.
> That breaks obj-c++.
sorry about that. Turns out I was only building objc not objc++, so I
didn't notice that. While objcp's config-lang.in claimed the first part
of its gtfiles initializer was the same as cp's version, it had severely
bitrotted, even before my sorting patch to the latter, and was therefore
only working by accident already. Yet again, specifying the same thing
in two different places leads to breakage. Let's not do that.
This patch changes objcp's config-lang.in to source cp's variant and
extract the gtfiles list therefrom. The fly in that ointment was that
we source the lang frags from the toplevel build and the gcc dir, so
srcdir is not consistent. This patch makes it so by setting srcdir to
the gcc dir when we include the lang frags from the toplevel.
And the fly in that ointment is that while the following works in bash:
srcdir=${srcdir}/gcc . $frag
to just override srcdir during the sourcing of frag, in sh it changes
the current shell's value too. A little bit of explicit saving and
restoring is needed.
I committed the attached as sufficiently obvious. (and fixed my boot
procedure to include objc++)
nathan
--
Nathan Sidwell
[-- Attachment #2: objcpp.diff --]
[-- Type: text/x-patch, Size: 4754 bytes --]
2017-07-03 Nathan Sidwell <nathan@acm.org>
* configure.ac: Set srcdir when sourcing config-lang.in fragments.
* configure: Rebuilt.
* config-lang.in: Source cp/config-lang.in, sort objc++ gtfiles list.
Index: configure
===================================================================
--- configure (revision 249835)
+++ configure (working copy)
@@ -6166,7 +6166,12 @@ if test -d ${srcdir}/gcc; then
language=
lang_requires=
lang_requires_boot_languages=
- . ${lang_frag}
+ # set srcdir during sourcing lang_frag to the gcc dir.
+ # Sadly overriding srcdir on the . line doesn't work in plain sh as it
+ # polutes this shell
+ saved_srcdir=${srcdir}
+ srcdir=${srcdir}/gcc . ${lang_frag}
+ srcdir=${saved_srcdir}
for other in ${lang_requires} ${lang_requires_boot_languages}; do
case ,${enable_languages}, in
*,$other,*) ;;
@@ -6241,7 +6246,10 @@ if test -d ${srcdir}/gcc; then
subdir_requires=
boot_language=no
build_by_default=yes
- . ${lang_frag}
+ # set srcdir during sourcing. See above about save & restore
+ saved_srcdir=${srcdir}
+ srcdir=${srcdir}/gcc . ${lang_frag}
+ srcdir=${saved_srcdir}
if test x${language} = x; then
echo "${lang_frag} doesn't set \$language." 1>&2
exit 1
Index: configure.ac
===================================================================
--- configure.ac (revision 249835)
+++ configure.ac (working copy)
@@ -1839,7 +1839,12 @@ if test -d ${srcdir}/gcc; then
language=
lang_requires=
lang_requires_boot_languages=
- . ${lang_frag}
+ # set srcdir during sourcing lang_frag to the gcc dir.
+ # Sadly overriding srcdir on the . line doesn't work in plain sh as it
+ # polutes this shell
+ saved_srcdir=${srcdir}
+ srcdir=${srcdir}/gcc . ${lang_frag}
+ srcdir=${saved_srcdir}
for other in ${lang_requires} ${lang_requires_boot_languages}; do
case ,${enable_languages}, in
*,$other,*) ;;
@@ -1914,7 +1919,10 @@ if test -d ${srcdir}/gcc; then
subdir_requires=
boot_language=no
build_by_default=yes
- . ${lang_frag}
+ # set srcdir during sourcing. See above about save & restore
+ saved_srcdir=${srcdir}
+ srcdir=${srcdir}/gcc . ${lang_frag}
+ srcdir=${saved_srcdir}
if test x${language} = x; then
echo "${lang_frag} doesn't set \$language." 1>&2
exit 1
Index: gcc/objcp/config-lang.in
===================================================================
--- gcc/objcp/config-lang.in (revision 249835)
+++ gcc/objcp/config-lang.in (working copy)
@@ -43,8 +43,20 @@ subdir_requires="objc cp"
# avoid having the GC stuff from that header being added to gtype-cp.h
# or gtype-objc.h.
-# This list is separated in two parts: the first one is identical to
-# the C++ one, the second one contains our ObjC++ additions.
-gtfiles="\$(srcdir)/cp/rtti.c \$(srcdir)/cp/mangle.c \$(srcdir)/cp/name-lookup.h \$(srcdir)/cp/name-lookup.c \$(srcdir)/cp/cp-tree.h \$(srcdir)/cp/decl.h \$(srcdir)/cp/call.c \$(srcdir)/cp/decl.c \$(srcdir)/cp/decl2.c \$(srcdir)/cp/pt.c \$(srcdir)/cp/repo.c \$(srcdir)/cp/semantics.c \$(srcdir)/cp/tree.c \$(srcdir)/cp/parser.h \$(srcdir)/cp/parser.c \$(srcdir)/cp/method.c \$(srcdir)/cp/typeck2.c \$(srcdir)/c-family/c-common.c \$(srcdir)/c-family/c-common.h \$(srcdir)/c-family/c-objc.h \$(srcdir)/c-family/c-lex.c \$(srcdir)/c-family/c-pragma.h \$(srcdir)/c-family/c-pragma.c \$(srcdir)/cp/class.c \$(srcdir)/cp/cp-objcp-common.c \$(srcdir)/cp/except.c \$(srcdir)/cp/vtable-class-hierarchy.c \$(srcdir)/cp/constexpr.c \$(srcdir)/cp/cp-gimplify.c \
-\$(srcdir)/objc/objc-map.h \$(srcdir)/objc/objc-act.h \$(srcdir)/objc/objc-act.c \$(srcdir)/objc/objc-runtime-shared-support.c \$(srcdir)/objc/objc-gnu-runtime-abi-01.c \$(srcdir)/objc/objc-next-runtime-abi-01.c \$(srcdir)/objc/objc-next-runtime-abi-02.c \$(srcdir)/c-family/c-cppbuiltin.c"
+# Get the C++ FE's gtfiles list. Do this in a subshell, so we can
+# extract exactly the gtfiles var, but munge cp-lang.c into objcp-lang.c.
+gtfiles="$(. $srcdir/cp/config-lang.in ; \
+ echo $gtfiles | sed 's+/cp/cp-lang.c +/objcp/objcp-lang.c +')"
+
+# Now add our special bits to it. Please keep this list sorted.
+gtfiles="$gtfiles \
+\$(srcdir)/objc/objc-act.h \
+\$(srcdir)/objc/objc-map.h \
+\$(srcdir)/c-family/c-cppbuiltin.c \
+\$(srcdir)/objc/objc-act.c \
+\$(srcdir)/objc/objc-gnu-runtime-abi-01.c \
+\$(srcdir)/objc/objc-next-runtime-abi-01.c \
+\$(srcdir)/objc/objc-next-runtime-abi-02.c \
+\$(srcdir)/objc/objc-runtime-shared-support.c \
+"
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2017-07-03 14:23 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-30 18:48 [C++ PATCH] conversion operator names Nathan Sidwell
2017-06-30 18:53 ` Nathan Sidwell
2017-06-30 19:11 ` Jason Merrill
2017-06-30 19:53 ` Nathan Sidwell
2017-06-30 20:25 ` Jason Merrill
2017-07-03 14:14 ` Nathan Sidwell
2017-07-01 21:41 ` Andreas Schwab
2017-07-03 14:23 ` Nathan Sidwell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).