Mark string constants CONSTANT and INVARIANT
Ian Lance Taylor
ian@airs.com
Mon Aug 15 23:03:00 GMT 2005
One would expect that STRING_CST nodes would be marked as
TREE_CONSTANT and TREE_INVARIANT. And, formerly, they were, because
build_string called make_node, and that function (really
make_node_stat) sets TREE_CONSTANT and TREE_INVARIANT for all nodes of
kind tree_constant.
However, this patch:
2004-09-17 Geoffrey Keating <geoffk@apple.com>
PR pch/13361
* c-typeck.c (constructor_asmspec): Delete.
(struct initializer_stack): Delete field 'asmspec'.
(start_init): Delete saving of asmspec.
(finish_init): Don't update constructor_asmspec.
* dwarf2out.c (rtl_for_decl_location): Duplicate string from tree.
* stmt.c (expand_asm): Duplicate strings from tree.
(expand_asm_operands): Likewise.
* tree.c (tree_size): Update computation of size of STRING_CST.
(make_node): Don't make STRING_CST nodes.
(build_string): Allocate string with tree node.
(tree_code_size): Clean up assertions, don't allow requests
for "the size of a STRING_CST".
* tree.def (STRING_CST): Update comment.
* tree.h (TREE_STRING_POINTER): Adjust for change to STRING_CST.
(tree_string): Place contents of string in tree node.
* config/sh/sh.c (sh_handle_sp_switch_attribute): Duplicate string
from tree.
changed build_string to no longer make_node. It now calls
ggc_alloc_tree directly. And it forgets to set TREE_CONSTANT and
TREE_INVARIANT.
I noticed this because I noticed that PRETTY_FUNCTION strings were
being put into .data rather than into a mergeable string section.
This is a regression.
I tested this obvious patch with a bootstrap and testsuite run on
i686-pc-linux-gnu. OK for mainline and 4.0 branch?
:ADDPATCH tree:
Ian
2005-08-15 Ian Lance Taylor <ian@airs.com>
* tree.c (build_string): Mark tree CONSTANT and INVARIANT.
Index: tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.c,v
retrieving revision 1.499
diff -p -u -r1.499 tree.c
--- tree.c 11 Aug 2005 04:21:45 -0000 1.499
+++ tree.c 15 Aug 2005 22:25:22 -0000
@@ -1053,6 +1053,8 @@ build_string (int len, const char *str)
memset (s, 0, sizeof (struct tree_common));
TREE_SET_CODE (s, STRING_CST);
+ TREE_CONSTANT (s) = 1;
+ TREE_INVARIANT (s) = 1;
TREE_STRING_LENGTH (s) = len;
memcpy ((char *) TREE_STRING_POINTER (s), str, len);
((char *) TREE_STRING_POINTER (s))[len] = '\0';
More information about the Gcc-patches
mailing list