Bug 18129 - [3.4 Regression] -fwritable-strings doesn't work
Summary: [3.4 Regression] -fwritable-strings doesn't work
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 3.4.3
: P2 normal
Target Milestone: 3.4.3
Assignee: Not yet assigned to anyone
URL:
Keywords: patch, wrong-code
Depends on:
Blocks:
 
Reported: 2004-10-24 19:44 UTC by Jakub Jelinek
Modified: 2004-10-31 14:28 UTC (History)
1 user (show)

See Also:
Host:
Target: x86_64-redhat-linux
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-10-24 19:56:22


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2004-10-24 19:44:36 UTC
struct S { char *a, *b; };

extern void foo (struct S *);

int
main ()
{
  struct S s[] = {
    {"ABCDEFGH0123", "T"},
    {"ABCDEFGH4567", "T"},
    {"ABCDEFGH89ZYX", "T"},
    {"IJK012", "T"},
    {"IJK345", "T"},
    {"IJK678", "T"},
    {"IJKLMN", "T"},
    {"IJKOPQ", "T"},
    {0, 0}
  };

  foo (s);
  return 0;
}

at -O2 -fwritable-strings results in 33 .data strings (one is "", so 32), while
the program has just 16 - everything is duplicated and only one copy is used.

With more strings in the table, the result is sometimes unlinkable due to
undefined .LCxxx symbols.

I'm very well aware that -fwritable-strings is deprecated, but either it should
be killed already in GCC 3.4.x, or it should work.
Comment 1 Andrew Pinski 2004-10-24 19:56:22 UTC
Confirmed.

20030422 (236) between 20030504 (237)
Comment 2 Andrew Pinski 2004-10-24 20:31:55 UTC
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-10/msg02020.html>.
Comment 3 GCC Commits 2004-10-31 09:10:21 UTC
Subject: Bug 18129

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	jakub@gcc.gnu.org	2004-10-31 09:10:12

Modified files:
	gcc            : ChangeLog varasm.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: 20041024-1.c 

Log message:
	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.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.678&r2=2.2326.2.679
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/varasm.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.405.2.3&r2=1.405.2.4
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.302&r2=1.3389.2.303
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/20041024-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1

Comment 4 Giovanni Bajo 2004-10-31 10:24:32 UTC
Fixed.
Comment 5 Andrew Pinski 2004-10-31 14:28:15 UTC
Should have been closed.