This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[3.4 PATCH] Fix -fwritable-strings (PR middle-end/18129)


Hi!

The removal of TREE_CST_RTL broke -fwritable-strings.
For -fwritable-strings, the address of the STRING_CST tree node
is used to determine if a particular writable string has been
already emitted or not yet.  But if we copy this node, we can
create duplicates (as seen in the testcase below) or as seen
on http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=136714
testcase programs that don't link with -fwritable-strings.

Both are cured by the following patch.
Ok to commit to 3.4 branch?
4.0 thankfully doesn't have this problem, as -fwritable-strings
have been removed there.

2004-10-24  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/18129
	* varasm.c (copy_constant): Don't copy STRING_CSTs if
	flag_writable_strings.
	(build_constant_desc): Call copy_constant unconditionally.

	* gcc.dg/20041024-1.c: New test.

--- gcc/varasm.c.jj	2004-04-20 15:51:26.000000000 +0200
+++ gcc/varasm.c	2004-10-24 22:19:18.396501148 +0200
@@ -2350,7 +2350,8 @@ compare_constant (const tree t1, const t
 }
 
 /* Make a copy of the whole tree structure for a constant.  This
-   handles the same types of nodes that compare_constant handles.  */
+   handles the same types of nodes that compare_constant handles.
+   Writable string constants are never copied.  */
 
 static tree
 copy_constant (tree exp)
@@ -2366,9 +2367,12 @@ copy_constant (tree exp)
       else
 	return copy_node (exp);
 
+    case STRING_CST:
+      if (flag_writable_strings)
+	return exp;
+      /* FALLTHROUGH */
     case INTEGER_CST:
     case REAL_CST:
-    case STRING_CST:
       return copy_node (exp);
 
     case COMPLEX_CST:
@@ -2434,10 +2438,7 @@ build_constant_desc (tree exp)
   struct constant_descriptor_tree *desc;
 
   desc = ggc_alloc (sizeof (*desc));
-  if (flag_writable_strings && TREE_CODE (exp) == STRING_CST)
-    desc->value = exp;
-  else
-    desc->value = copy_constant (exp);
+  desc->value = copy_constant (exp);
 
   /* Create a string containing the label name, in LABEL.  */
   labelno = const_labelno++;
--- gcc/testsuite/gcc.dg/20041024-1.c.jj	2004-10-24 22:13:37.988948431 +0200
+++ gcc/testsuite/gcc.dg/20041024-1.c	2004-10-24 22:17:26.030454354 +0200
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fwritable-strings -w" } */
+/* { dg-error "-fwritable-strings is deprecated" "" { target *-*-* } 0 } */
+
+struct S { char *a, *b; };
+
+int
+main ()
+{
+  struct S s[] = {
+    {"ABCDEFGH0123", "T"},
+    {"ABCDEFGH4567", "T"},
+    {"ABCDEFGH89ZYX", "T"},
+    {"IJK012", "T"},
+    {"IJK345", "T"},
+    {"IJK678", "T"},
+    {"IJKLMN", "T"},
+    {"IJKOPQ", "T"},
+    {0, 0}
+  };
+
+  __asm __volatile ("" : : "r" (s) : "memory");
+  return 0;
+}
+
+/* Test whether strings aren't output more than once.  */
+/* { dg-final { scan-assembler-not "ABCDEFGH0123.*ABCDEFGH0123" } } */

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]