From: hikichi@srarc2.sra.co.JP (Nobuyuki Hikichi)
Subject: bug ? for no writable string in mips-sony-bsd or mips-mips-sysv
Reply-To: hikichi@sra.co.jp
Organization: GNUs Not Usenet
Distribution: gnu
Date: Wed, 15 Apr 1992 01:49:47 GMT

I guess gcc 2.1 for in mips-sony-bsd or mips-mips-sysv has a bug with
``-fno-writable-strings'' option as following script:

	hikichi@srarc2 $ cat y.c
	char *s[] = {"ab", "b2", "b3"};

	int j;

	char *p = "this is...";

	main ()
	{
	  printf ("- p = %s\n", p);
	  p[0] = 'T';

	  printf ("+ p = %s\n", p);
	}
	hikichi@srarc2 $ gcc -fno-writable-strings y.c
	hikichi@srarc2 $ a.out
	- p = this is...
	+ p = This is...

				Name: Nobuyuki Hikichi <hikichi@sra.co.jp>
			Office: Software Research Associates, Inc. Japan.


P.S.
For reference, I add the my comment for generated code after mark of
``!!''.

	hikichi@srarc2 $ gcc -v -S y.c
	Reading specs from /usr/local/gnu/lib/gcc-lib/mips-mips-bsd/2.1/specs
	gcc version 2.1
	 /usr/local/gnu/lib/gcc-lib/mips-mips-bsd/2.1/cpp -lang-c -v -undef -D__GNUC__=2 -Dmips -Dunix -Dhost_mips -DMIPSEB -DR3000 -DSYSTYPE_BSD43 -D__mips__ -D__unix__ -D__host_mips__ -D__MIPSEB__ -D__R3000__ -D__SYSTYPE_BSD43__ -D__mips -D__unix -D__host_mips -D__MIPSEB -D__R3000 -D__SYSTYPE_BSD43 -D__LANGUAGE_C -D_LANGUAGE_C -DLANGUAGE_C y.c /usr/tmp/cc019279.i
	GNU CPP version 2.1 [AL 1.1, MM 14] RISC-OS BSD Mips
	 /usr/local/gnu/lib/gcc-lib/mips-mips-bsd/2.1/cc1 /usr/tmp/cc019279.i -quiet -dumpbase y.c -version -o y.s
	GNU C version 2.1 [AL 1.1, MM 14] RISC-OS BSD Mips compiled by GNU C version 2.1.
	hikichi@srarc2 $ cat y.s
		.file	1 "y.c"
	.data

	 # GNU C 2.1 [AL 1.1, MM 14] RISC-OS BSD Mips compiled by GNU C

	 # Cc1 defaults:

	 # Cc1 arguments (-G value = 8, Cpu = default, ISA = 1):
	 # -quiet -dumpbase -version -o

	gcc2_compiled.:
		.globl	s
	.sdata						#!! should be .text
		.align	2
	$LC0:
		.ascii	"ab\000"
		.align	2
	$LC1:
		.ascii	"b2\000"
		.align	2
	$LC2:
		.ascii	"b3\000"
	.data
		.align	2
	s:
		.word	$LC0
		.word	$LC1
		.word	$LC2
		.globl	p
	.rdata						#!! should be .text
		.align	2
	$LC3:
		.ascii	"this is...\000"
	.sdata
		.align	2
	p:
		.word	$LC3
	.rdata						#!! should be .text
		.align	2
	$LC4:
		.ascii	"- p = %s\n\000"
		.align	2
	$LC5:
		.ascii	"+ p = %s\n\000"
	.text
		.align	2
		.globl	main

							# delete tail code
	hikichi@srarc2 $ gcc -v -fwritable-strings -S y.c
	Reading specs from /usr/local/gnu/lib/gcc-lib/mips-mips-bsd/2.1/specs
	gcc version 2.1
	 /usr/local/gnu/lib/gcc-lib/mips-mips-bsd/2.1/cpp -lang-c -v -undef -D__GNUC__=2 -Dmips -Dunix -Dhost_mips -DMIPSEB -DR3000 -DSYSTYPE_BSD43 -D__mips__ -D__unix__ -D__host_mips__ -D__MIPSEB__ -D__R3000__ -D__SYSTYPE_BSD43__ -D__mips -D__unix -D__host_mips -D__MIPSEB -D__R3000 -D__SYSTYPE_BSD43 -D__LANGUAGE_C -D_LANGUAGE_C -DLANGUAGE_C y.c /usr/tmp/cc019283.i
	GNU CPP version 2.1 [AL 1.1, MM 14] RISC-OS BSD Mips
	 /usr/local/gnu/lib/gcc-lib/mips-mips-bsd/2.1/cc1 /usr/tmp/cc019283.i -quiet -dumpbase y.c -version -fwritable-strings -o y.s
	GNU C version 2.1 [AL 1.1, MM 14] RISC-OS BSD Mips compiled by GNU C version 2.1.
	hikichi@srarc2 $ cat y.s
		.file	1 "y.c"
	.data

	 # GNU C 2.1 [AL 1.1, MM 14] RISC-OS BSD Mips compiled by GNU C

	 # Cc1 defaults:

	 # Cc1 arguments (-G value = 8, Cpu = default, ISA = 1):
	 # -quiet -dumpbase -version -fwritable-strings -o

	gcc2_compiled.:
		.globl	s
	.sdata						#!! should be .text
		.align	2
	$LC0:
		.ascii	"ab\000"
		.align	2
	$LC1:
		.ascii	"b2\000"
		.align	2
	$LC2:
		.ascii	"b3\000"
	.data
		.align	2
	s:
		.word	$LC0
		.word	$LC1
		.word	$LC2
		.globl	p			#!! insert .text afther this line
		.align	2
	$LC3:
		.ascii	"this is...\000"
	.sdata
		.align	2
	p:
		.word	$LC3
	.data						#!! should be .text
		.align	2
	$LC4:
		.ascii	"- p = %s\n\000"
		.align	2
	$LC5:
		.ascii	"+ p = %s\n\000"
	.text
		.align	2
		.globl	main

		.loc	1 8
		.ent	main
	main:
		subu	$sp,$sp,40		# vars= 0, regs= 3/0, args = 16, extra= 8
		.frame	$fp,0,$31
		.mask	0xc0010000,-16
		.fmask	0x00000000,0
		sw	$31,24($sp)
		sw	$fp,20($sp)
		sw	$16,16($sp)
		addu	$fp,$sp,40	# set up frame pointer
		la	$16,__main
		jal	$31,$16
		la	$4,$LC4
		lw	$5,p

Newsgroups: gnu.gcc.bug