aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeoffrey Keating <geoffk@apple.com>2004-09-18 05:50:52 +0000
committerGeoffrey Keating <geoffk@gcc.gnu.org>2004-09-18 05:50:52 +0000
commita396f8ae242ddd9993230025093b5f768647d194 (patch)
tree5b612839071d1427646211852251d0557c61a619
parent9aa44508a821e8de072de1f6d8ea344753a0a4d1 (diff)
downloadgcc-a396f8ae242ddd9993230025093b5f768647d194.zip
gcc-a396f8ae242ddd9993230025093b5f768647d194.tar.gz
gcc-a396f8ae242ddd9993230025093b5f768647d194.tar.bz2
re PR pch/13361 (const wchar_t * strings not stored in pch)
* tree-inline.c (copy_tree_r): Don't duplicate constants, they're shared anyway. 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. From-SVN: r87695
-rw-r--r--gcc/ChangeLog24
-rw-r--r--gcc/c-typeck.c15
-rw-r--r--gcc/config/sh/sh.c4
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/lex.c4
-rw-r--r--gcc/dwarf2out.c3
-rw-r--r--gcc/stmt.c16
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/pch/wchar-1.C1
-rw-r--r--gcc/testsuite/g++.dg/pch/wchar-1.Hs2
-rw-r--r--gcc/tree-inline.c3
-rw-r--r--gcc/tree.c36
-rw-r--r--gcc/tree.def2
-rw-r--r--gcc/tree.h4
14 files changed, 85 insertions, 41 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 65cc2e1..1e3efe3 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,27 @@
+2004-09-17 Geoffrey Keating <geoffk@apple.com>
+
+ * tree-inline.c (copy_tree_r): Don't duplicate constants, they're
+ shared anyway.
+
+ 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.
+
2004-09-17 Zack Weinberg <zack@codesourcery.com>
* Makefile.in (c-parse.o): Depend on $(C_PRAGMA_H).
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 5ec00aa4..c00b9ec 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -4319,9 +4319,6 @@ int constructor_no_implicit = 0; /* 0 for C; 1 for some other languages. */
such as (struct foo) {...}. */
static tree constructor_decl;
-/* start_init saves the ASMSPEC arg here for really_start_incremental_init. */
-static const char *constructor_asmspec;
-
/* Nonzero if this is an initializer for a top-level decl. */
static int constructor_top_level;
@@ -4393,7 +4390,6 @@ struct initializer_stack
{
struct initializer_stack *next;
tree decl;
- const char *asmspec;
struct constructor_stack *constructor_stack;
struct constructor_range_stack *constructor_range_stack;
tree elements;
@@ -4410,17 +4406,12 @@ struct initializer_stack *initializer_stack;
/* Prepare to parse and output the initializer for variable DECL. */
void
-start_init (tree decl, tree asmspec_tree, int top_level)
+start_init (tree decl, tree asmspec_tree ATTRIBUTE_UNUSED, int top_level)
{
const char *locus;
- struct initializer_stack *p = XNEW (struct initializer_stack);
- const char *asmspec = 0;
-
- if (asmspec_tree)
- asmspec = TREE_STRING_POINTER (asmspec_tree);
+ struct initializer_stack *p = xmalloc (sizeof (struct initializer_stack));
p->decl = constructor_decl;
- p->asmspec = constructor_asmspec;
p->require_constant_value = require_constant_value;
p->require_constant_elements = require_constant_elements;
p->constructor_stack = constructor_stack;
@@ -4434,7 +4425,6 @@ start_init (tree decl, tree asmspec_tree, int top_level)
initializer_stack = p;
constructor_decl = decl;
- constructor_asmspec = asmspec;
constructor_designated = 0;
constructor_top_level = top_level;
@@ -4490,7 +4480,6 @@ finish_init (void)
free (spelling_base);
constructor_decl = p->decl;
- constructor_asmspec = p->asmspec;
require_constant_value = p->require_constant_value;
require_constant_elements = p->require_constant_elements;
constructor_stack = p->constructor_stack;
diff --git a/gcc/config/sh/sh.c b/gcc/config/sh/sh.c
index ce4ee85..c7d158c 100644
--- a/gcc/config/sh/sh.c
+++ b/gcc/config/sh/sh.c
@@ -7161,8 +7161,8 @@ sh_handle_sp_switch_attribute (tree *node, tree name, tree args,
}
else
{
- sp_switch = gen_rtx_SYMBOL_REF (VOIDmode,
- TREE_STRING_POINTER (TREE_VALUE (args)));
+ char *s = ggc_strdup (TREE_STRING_POINTER (TREE_VALUE (args)));
+ sp_switch = gen_rtx_SYMBOL_REF (VOIDmode, s);
}
return NULL_TREE;
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index be9b0d3..2cf1f74 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2004-09-16 Geoffrey Keating <geoffk@apple.com>
+
+ PR pch/13361
+ * cp/lex.c (handle_pragma_interface): Duplicate string from tree.
+ (handle_pragma_implementation): Likewise.
+
2004-09-17 Jeffrey D. Oldham <oldham@codesourcery.com>
Zack Weinberg <zack@codesourcery.com>
diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c
index 4fa1645..c7b1cf6 100644
--- a/gcc/cp/lex.c
+++ b/gcc/cp/lex.c
@@ -471,7 +471,7 @@ handle_pragma_interface (cpp_reader* dfile ATTRIBUTE_UNUSED )
else if (fname == 0)
main_filename = lbasename (input_filename);
else
- main_filename = TREE_STRING_POINTER (fname);
+ main_filename = ggc_strdup (TREE_STRING_POINTER (fname));
finfo = get_fileinfo (input_filename);
@@ -519,7 +519,7 @@ handle_pragma_implementation (cpp_reader* dfile ATTRIBUTE_UNUSED )
}
else
{
- main_filename = TREE_STRING_POINTER (fname);
+ main_filename = ggc_strdup (TREE_STRING_POINTER (fname));
if (cpp_included (parse_in, main_filename))
warning ("#pragma implementation for %s appears after file is included",
main_filename);
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 51b3681..e269629 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -9889,7 +9889,8 @@ rtl_for_decl_location (tree decl)
TREE_STRING_LENGTH (init) - 1) == 0
&& ((size_t) TREE_STRING_LENGTH (init)
== strlen (TREE_STRING_POINTER (init)) + 1))
- rtl = gen_rtx_CONST_STRING (VOIDmode, TREE_STRING_POINTER (init));
+ rtl = gen_rtx_CONST_STRING (VOIDmode,
+ ggc_strdup (TREE_STRING_POINTER (init)));
}
/* If the initializer is something that we know will expand into an
immediate RTL constant, expand it now. Expanding anything else
diff --git a/gcc/stmt.c b/gcc/stmt.c
index e5d094d..099c5e7 100644
--- a/gcc/stmt.c
+++ b/gcc/stmt.c
@@ -267,7 +267,8 @@ expand_asm (tree string, int vol)
if (TREE_CODE (string) == ADDR_EXPR)
string = TREE_OPERAND (string, 0);
- body = gen_rtx_ASM_INPUT (VOIDmode, TREE_STRING_POINTER (string));
+ body = gen_rtx_ASM_INPUT (VOIDmode,
+ ggc_strdup (TREE_STRING_POINTER (string)));
MEM_VOLATILE_P (body) = vol;
@@ -851,7 +852,7 @@ expand_asm_operands (tree string, tree outputs, tree inputs,
body = gen_rtx_ASM_OPERANDS ((noutputs == 0 ? VOIDmode
: GET_MODE (output_rtx[0])),
- TREE_STRING_POINTER (string),
+ ggc_strdup (TREE_STRING_POINTER (string)),
empty_string, 0, argvec, constraintvec,
locus);
@@ -932,7 +933,8 @@ expand_asm_operands (tree string, tree outputs, tree inputs,
ASM_OPERANDS_INPUT (body, i) = op;
ASM_OPERANDS_INPUT_CONSTRAINT_EXP (body, i)
- = gen_rtx_ASM_INPUT (TYPE_MODE (type), constraints[i + noutputs]);
+ = gen_rtx_ASM_INPUT (TYPE_MODE (type),
+ ggc_strdup (constraints[i + noutputs]));
if (decl_conflicts_with_clobbers_p (val, clobbered_regs))
clobber_conflict_found = 1;
@@ -966,7 +968,7 @@ expand_asm_operands (tree string, tree outputs, tree inputs,
if (noutputs == 1 && nclobbers == 0)
{
- ASM_OPERANDS_OUTPUT_CONSTRAINT (body) = constraints[0];
+ ASM_OPERANDS_OUTPUT_CONSTRAINT (body) = ggc_strdup (constraints[0]);
emit_insn (gen_rtx_SET (VOIDmode, output_rtx[0], body));
}
@@ -994,9 +996,9 @@ expand_asm_operands (tree string, tree outputs, tree inputs,
output_rtx[i],
gen_rtx_ASM_OPERANDS
(GET_MODE (output_rtx[i]),
- TREE_STRING_POINTER (string),
- constraints[i], i, argvec, constraintvec,
- locus));
+ ggc_strdup (TREE_STRING_POINTER (string)),
+ ggc_strdup (constraints[i]),
+ i, argvec, constraintvec, locus));
MEM_VOLATILE_P (SET_SRC (XVECEXP (body, 0, i))) = vol;
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index c9d44bbc..ddc44e6 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2004-09-16 Geoffrey Keating <geoffk@apple.com>
+
+ PR pch/13361
+ * testsuite/g++.dg/pch/wchar-1.C: New.
+ * testsuite/g++.dg/pch/wchar-1.Hs: New.
+
2004-09-17 Kenneth Zadeck <Kenneth.Zadeck@NaturalBridge.com>
* gcc.c-torture/execute/20040917-1.c: New test.
diff --git a/gcc/testsuite/g++.dg/pch/wchar-1.C b/gcc/testsuite/g++.dg/pch/wchar-1.C
new file mode 100644
index 0000000..6cb5fe1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pch/wchar-1.C
@@ -0,0 +1 @@
+#include "wchar-1.H"
diff --git a/gcc/testsuite/g++.dg/pch/wchar-1.Hs b/gcc/testsuite/g++.dg/pch/wchar-1.Hs
new file mode 100644
index 0000000..431908b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pch/wchar-1.Hs
@@ -0,0 +1,2 @@
+#include <stddef.h>
+const wchar_t test_var[] = L"wide string";
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index 707faaf..243b870 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -2257,7 +2257,6 @@ copy_tree_r (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
/* We make copies of most nodes. */
if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code))
- || TREE_CODE_CLASS (code) == tcc_constant
|| code == TREE_LIST
|| code == TREE_VEC
|| code == TYPE_DECL)
@@ -2291,6 +2290,8 @@ copy_tree_r (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
*walk_subtrees = 0;
else if (TREE_CODE_CLASS (code) == tcc_declaration)
*walk_subtrees = 0;
+ else if (TREE_CODE_CLASS (code) == tcc_constant)
+ *walk_subtrees = 0;
else
gcc_assert (code != STATEMENT_LIST);
return NULL_TREE;
diff --git a/gcc/tree.c b/gcc/tree.c
index 02d2ee9..98ab924 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -159,17 +159,12 @@ decl_assembler_name (tree decl)
return DECL_CHECK (decl)->decl.assembler_name;
}
-/* Compute the number of bytes occupied by a tree with code CODE. This
- function cannot be used for TREE_VEC or PHI_NODE codes, which are of
- variable length. */
+/* Compute the number of bytes occupied by a tree with code CODE.
+ This function cannot be used for TREE_VEC, PHI_NODE, or STRING_CST
+ codes, which are of variable length. */
size_t
tree_code_size (enum tree_code code)
{
- /* We can't state the size of a TREE_VEC or PHI_NODE
- without knowing how many elements it will have. */
- gcc_assert (code != TREE_VEC);
- gcc_assert (code != PHI_NODE);
-
switch (TREE_CODE_CLASS (code))
{
case tcc_declaration: /* A decl node */
@@ -194,7 +189,7 @@ tree_code_size (enum tree_code code)
case REAL_CST: return sizeof (struct tree_real_cst);
case COMPLEX_CST: return sizeof (struct tree_complex);
case VECTOR_CST: return sizeof (struct tree_vector);
- case STRING_CST: return sizeof (struct tree_string);
+ case STRING_CST: gcc_unreachable ();
default:
return lang_hooks.tree_size (code);
}
@@ -208,7 +203,8 @@ tree_code_size (enum tree_code code)
case ERROR_MARK:
case PLACEHOLDER_EXPR: return sizeof (struct tree_common);
- case PHI_NODE:
+ case TREE_VEC:
+ case PHI_NODE: gcc_unreachable ();
case SSA_NAME: return sizeof (struct tree_ssa_name);
@@ -241,6 +237,9 @@ tree_size (tree node)
return (sizeof (struct tree_vec)
+ (TREE_VEC_LENGTH (node) - 1) * sizeof(char *));
+ case STRING_CST:
+ return sizeof (struct tree_string) + TREE_STRING_LENGTH (node) - 1;
+
default:
return tree_code_size (code);
}
@@ -719,10 +718,23 @@ build_real_from_int_cst (tree type, tree i)
tree
build_string (int len, const char *str)
{
- tree s = make_node (STRING_CST);
+ tree s;
+ size_t length;
+
+ length = len + sizeof (struct tree_string);
+
+#ifdef GATHER_STATISTICS
+ tree_node_counts[(int) c_kind]++;
+ tree_node_sizes[(int) c_kind] += length;
+#endif
+
+ s = ggc_alloc_tree (length);
+ memset (s, 0, sizeof (struct tree_common));
+ TREE_SET_CODE (s, STRING_CST);
TREE_STRING_LENGTH (s) = len;
- TREE_STRING_POINTER (s) = ggc_alloc_string (str, len);
+ memcpy ((char *) TREE_STRING_POINTER (s), str, len);
+ ((char *) TREE_STRING_POINTER (s))[len] = '\0';
return s;
}
diff --git a/gcc/tree.def b/gcc/tree.def
index c050742..922c75f 100644
--- a/gcc/tree.def
+++ b/gcc/tree.def
@@ -266,7 +266,7 @@ DEFTREECODE (COMPLEX_CST, "complex_cst", tcc_constant, 0)
/* Contents are in TREE_VECTOR_CST_ELTS field. */
DEFTREECODE (VECTOR_CST, "vector_cst", tcc_constant, 0)
-/* Contents are TREE_STRING_LENGTH and TREE_STRING_POINTER fields. */
+/* Contents are TREE_STRING_LENGTH and the actual contents of the string. */
DEFTREECODE (STRING_CST, "string_cst", tcc_constant, 0)
/* Declarations. All references to names are represented as ..._DECL
diff --git a/gcc/tree.h b/gcc/tree.h
index 289d275..17f0475 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -1053,13 +1053,13 @@ struct tree_real_cst GTY(())
/* In a STRING_CST */
#define TREE_STRING_LENGTH(NODE) (STRING_CST_CHECK (NODE)->string.length)
-#define TREE_STRING_POINTER(NODE) (STRING_CST_CHECK (NODE)->string.pointer)
+#define TREE_STRING_POINTER(NODE) (STRING_CST_CHECK (NODE)->string.str)
struct tree_string GTY(())
{
struct tree_common common;
int length;
- const char *pointer;
+ const char str[1];
};
/* In a COMPLEX_CST node. */