Blame SOURCES/gcc32-pr3581.patch

4ac4fd
2002-04-26  Richard Henderson  <rth@redhat.com>
4ac4fd
4ac4fd
	PR c/3581
4ac4fd
	* c-common.c (fix_string_type): Split out of ...
4ac4fd
	(combine_strings): ... here.  Take a varray, not a tree list.
4ac4fd
	(c_expand_builtin_printf): Use fix_string_type.
4ac4fd
	* c-common.h: Update decls.
4ac4fd
	* c-parse.in (string): Remove.  Update all uses to use STRING
4ac4fd
	instead, and not call combine_strings.
4ac4fd
	(yylexstring): New.
4ac4fd
	(_yylex): Use it.
4ac4fd
	* c-typeck.c (simple_asm_stmt): Don't call combine_strings.
4ac4fd
	(build_asm_stmt): Likewise.
4ac4fd
	* objc/objc-act.c (my_build_string): Use fix_string_type.
4ac4fd
	(build_objc_string_object): Build varray for combine_strings.
4ac4fd
cp/
4ac4fd
	* parse.y (string): Remove.  Update all uses to use STRING
4ac4fd
	instead, and not call combine_strings.
4ac4fd
	* rtti.c (tinfo_name): Use fix_string_type.
4ac4fd
	* semantics.c (finish_asm_stmt): Don't call combine_strings.
4ac4fd
	* spew.c (yylexstring): New.
4ac4fd
	(read_token): Use it.
4ac4fd
testsuite/
4ac4fd
	* g++.dg/parse/concat1.C: New test.
4ac4fd
	* gcc.dg/concat2.c: New test.
4ac4fd
4ac4fd
--- gcc/objc/objc-act.c.jj	2002-09-24 15:08:15.000000000 +0200
4ac4fd
+++ gcc/objc/objc-act.c	2004-10-05 16:08:18.744519118 +0200
4ac4fd
@@ -1207,21 +1207,7 @@ my_build_string (len, str)
4ac4fd
      int len;
4ac4fd
      const char *str;
4ac4fd
 {
4ac4fd
-  int wide_flag = 0;
4ac4fd
-  tree a_string = build_string (len, str);
4ac4fd
-
4ac4fd
-  /* Some code from combine_strings, which is local to c-parse.y.  */
4ac4fd
-  if (TREE_TYPE (a_string) == int_array_type_node)
4ac4fd
-    wide_flag = 1;
4ac4fd
-
4ac4fd
-  TREE_TYPE (a_string)
4ac4fd
-    = build_array_type (wide_flag ? integer_type_node : char_type_node,
4ac4fd
-			build_index_type (build_int_2 (len - 1, 0)));
4ac4fd
-
4ac4fd
-  TREE_CONSTANT (a_string) = 1;	/* Puts string in the readonly segment */
4ac4fd
-  TREE_STATIC (a_string) = 1;
4ac4fd
-
4ac4fd
-  return a_string;
4ac4fd
+  return fix_string_type (build_string (len, str));
4ac4fd
 }
4ac4fd
 
4ac4fd
 /* Given a chain of STRING_CST's, build a static instance of
4ac4fd
@@ -1247,7 +1233,23 @@ build_objc_string_object (strings)
4ac4fd
 
4ac4fd
   add_class_reference (constant_string_id);
4ac4fd
 
4ac4fd
-  string = combine_strings (strings);
4ac4fd
+  if (TREE_CHAIN (strings))
4ac4fd
+    {
4ac4fd
+      varray_type vstrings;
4ac4fd
+      VARRAY_TREE_INIT (vstrings, 32, "strings");
4ac4fd
+
4ac4fd
+      for (; strings ; strings = TREE_CHAIN (strings))
4ac4fd
+	VARRAY_PUSH_TREE (vstrings, strings);
4ac4fd
+
4ac4fd
+      string = combine_strings (vstrings);
4ac4fd
+
4ac4fd
+      VARRAY_FREE (vstrings);
4ac4fd
+    }
4ac4fd
+  else
4ac4fd
+    string = strings;
4ac4fd
+
4ac4fd
+  string = fix_string_type (string);
4ac4fd
+
4ac4fd
   TREE_SET_CODE (string, STRING_CST);
4ac4fd
   length = TREE_STRING_LENGTH (string) - 1;
4ac4fd
 
4ac4fd
--- gcc/c-common.h.jj	2003-09-16 16:57:44.000000000 +0200
4ac4fd
+++ gcc/c-common.h	2004-10-05 16:08:18.669532451 +0200
4ac4fd
@@ -524,8 +524,9 @@ extern void c_finish_else               
4ac4fd
 extern void c_expand_end_cond			PARAMS ((void));
4ac4fd
 /* Validate the expression after `case' and apply default promotions.  */
4ac4fd
 extern tree check_case_value			PARAMS ((tree));
4ac4fd
-/* Concatenate a list of STRING_CST nodes into one STRING_CST.  */
4ac4fd
-extern tree combine_strings			PARAMS ((tree));
4ac4fd
+extern tree fix_string_type			PARAMS ((tree));
4ac4fd
+struct varray_head_tag;
4ac4fd
+extern tree combine_strings		PARAMS ((struct varray_head_tag *));
4ac4fd
 extern void constant_expression_warning		PARAMS ((tree));
4ac4fd
 extern tree convert_and_check			PARAMS ((tree, tree));
4ac4fd
 extern void overflow_warning			PARAMS ((tree));
4ac4fd
--- gcc/cp/rtti.c.jj	2002-12-08 21:43:27.000000000 +0100
4ac4fd
+++ gcc/cp/rtti.c	2004-10-05 16:08:18.721523207 +0200
4ac4fd
@@ -298,7 +298,7 @@ tinfo_name (type)
4ac4fd
   tree name_string;
4ac4fd
 
4ac4fd
   name = mangle_type_string (type);
4ac4fd
-  name_string = combine_strings (build_string (strlen (name) + 1, name));
4ac4fd
+  name_string = fix_string_type (build_string (strlen (name) + 1, name));
4ac4fd
   return name_string;
4ac4fd
 }
4ac4fd
 
4ac4fd
--- gcc/cp/semantics.c.jj	2003-03-28 22:03:02.000000000 +0100
4ac4fd
+++ gcc/cp/semantics.c	2004-10-05 16:08:18.723522851 +0200
4ac4fd
@@ -879,9 +879,6 @@ finish_asm_stmt (cv_qualifier, string, o
4ac4fd
   tree r;
4ac4fd
   tree t;
4ac4fd
 
4ac4fd
-  if (TREE_CHAIN (string))
4ac4fd
-    string = combine_strings (string);
4ac4fd
-
4ac4fd
   if (cv_qualifier != NULL_TREE
4ac4fd
       && cv_qualifier != ridpointers[(int) RID_VOLATILE])
4ac4fd
     {
4ac4fd
--- gcc/cp/parse.y.jj	2003-01-17 18:33:10.000000000 +0100
4ac4fd
+++ gcc/cp/parse.y	2004-10-05 16:08:18.717523918 +0200
4ac4fd
@@ -349,7 +349,7 @@ cp_parse_init ()
4ac4fd
 %type <ttype> PFUNCNAME maybe_identifier
4ac4fd
 %type <ttype> paren_expr_or_null nontrivial_exprlist SELFNAME
4ac4fd
 %type <ttype> expr_no_commas expr_no_comma_rangle
4ac4fd
-%type <ttype> cast_expr unary_expr primary string STRING
4ac4fd
+%type <ttype> cast_expr unary_expr primary STRING
4ac4fd
 %type <ttype> reserved_declspecs boolean.literal
4ac4fd
 %type <ttype> reserved_typespecquals
4ac4fd
 %type <ttype> SCSPEC TYPESPEC CV_QUALIFIER maybe_cv_qualifier
4ac4fd
@@ -514,9 +514,8 @@ extdef:
4ac4fd
 		{ do_pending_inlines (); }
4ac4fd
 	| template_def
4ac4fd
 		{ do_pending_inlines (); }
4ac4fd
-	| asm_keyword '(' string ')' ';'
4ac4fd
-		{ if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
4ac4fd
-		  assemble_asm ($3); }
4ac4fd
+	| asm_keyword '(' STRING ')' ';'
4ac4fd
+		{ assemble_asm ($3); }
4ac4fd
 	| extern_lang_string '{' extdefs_opt '}'
4ac4fd
 		{ pop_lang_context (); }
4ac4fd
 	| extern_lang_string .hush_warning fndef .warning_ok eat_saved_input
4ac4fd
@@ -1587,10 +1586,10 @@ primary:
4ac4fd
 		}		
4ac4fd
 	| CONSTANT
4ac4fd
 	| boolean.literal
4ac4fd
-	| string
4ac4fd
+	| STRING
4ac4fd
 		{
4ac4fd
-		  $$ = combine_strings ($$);
4ac4fd
-		  /* combine_strings doesn't set up TYPE_MAIN_VARIANT of
4ac4fd
+		  $$ = fix_string_type ($$);
4ac4fd
+		  /* fix_string_type doesn't set up TYPE_MAIN_VARIANT of
4ac4fd
 		     a const array the way we want, so fix it.  */
4ac4fd
 		  if (flag_const_strings)
4ac4fd
 		    TREE_TYPE ($$) = build_cplus_array_type
4ac4fd
@@ -1791,13 +1790,6 @@ boolean.literal:
4ac4fd
 		{ $$ = boolean_false_node; }
4ac4fd
 	;
4ac4fd
 
4ac4fd
-/* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it.  */
4ac4fd
-string:
4ac4fd
-	  STRING
4ac4fd
-	| string STRING
4ac4fd
-		{ $$ = chainon ($$, $2); }
4ac4fd
-	;
4ac4fd
-
4ac4fd
 nodecls:
4ac4fd
 	  /* empty */
4ac4fd
 		{
4ac4fd
@@ -2091,8 +2083,8 @@ nomods_initdecls:
4ac4fd
 maybeasm:
4ac4fd
 	  /* empty */
4ac4fd
 		{ $$ = NULL_TREE; }
4ac4fd
-	| asm_keyword '(' string ')'
4ac4fd
-		{ if (TREE_CHAIN ($3)) $3 = combine_strings ($3); $$ = $3; }
4ac4fd
+	| asm_keyword '(' STRING ')'
4ac4fd
+		{ $$ = $3; }
4ac4fd
 	;
4ac4fd
 
4ac4fd
 initdcl:
4ac4fd
@@ -3489,27 +3481,27 @@ simple_stmt:
4ac4fd
                 { $$ = finish_return_stmt (NULL_TREE); }
4ac4fd
 	| RETURN_KEYWORD expr ';'
4ac4fd
                 { $$ = finish_return_stmt ($2); }
4ac4fd
-	| asm_keyword maybe_cv_qualifier '(' string ')' ';'
4ac4fd
+	| asm_keyword maybe_cv_qualifier '(' STRING ')' ';'
4ac4fd
 		{ $$ = finish_asm_stmt ($2, $4, NULL_TREE, NULL_TREE,
4ac4fd
 					NULL_TREE);
4ac4fd
 		  ASM_INPUT_P ($$) = 1; }
4ac4fd
 	/* This is the case with just output operands.  */
4ac4fd
-	| asm_keyword maybe_cv_qualifier '(' string ':' asm_operands ')' ';'
4ac4fd
+	| asm_keyword maybe_cv_qualifier '(' STRING ':' asm_operands ')' ';'
4ac4fd
 		{ $$ = finish_asm_stmt ($2, $4, $6, NULL_TREE, NULL_TREE); }
4ac4fd
 	/* This is the case with input operands as well.  */
4ac4fd
-	| asm_keyword maybe_cv_qualifier '(' string ':' asm_operands ':'
4ac4fd
+	| asm_keyword maybe_cv_qualifier '(' STRING ':' asm_operands ':'
4ac4fd
 	  asm_operands ')' ';'
4ac4fd
 		{ $$ = finish_asm_stmt ($2, $4, $6, $8, NULL_TREE); }
4ac4fd
-	| asm_keyword maybe_cv_qualifier '(' string SCOPE asm_operands ')' ';'
4ac4fd
+	| asm_keyword maybe_cv_qualifier '(' STRING SCOPE asm_operands ')' ';'
4ac4fd
 		{ $$ = finish_asm_stmt ($2, $4, NULL_TREE, $6, NULL_TREE); }
4ac4fd
 	/* This is the case with clobbered registers as well.  */
4ac4fd
-	| asm_keyword maybe_cv_qualifier '(' string ':' asm_operands ':'
4ac4fd
+	| asm_keyword maybe_cv_qualifier '(' STRING ':' asm_operands ':'
4ac4fd
 	  asm_operands ':' asm_clobbers ')' ';'
4ac4fd
 		{ $$ = finish_asm_stmt ($2, $4, $6, $8, $10); }
4ac4fd
-	| asm_keyword maybe_cv_qualifier '(' string SCOPE asm_operands ':'
4ac4fd
+	| asm_keyword maybe_cv_qualifier '(' STRING SCOPE asm_operands ':'
4ac4fd
 	  asm_clobbers ')' ';'
4ac4fd
 		{ $$ = finish_asm_stmt ($2, $4, NULL_TREE, $6, $8); }
4ac4fd
-	| asm_keyword maybe_cv_qualifier '(' string ':' asm_operands SCOPE
4ac4fd
+	| asm_keyword maybe_cv_qualifier '(' STRING ':' asm_operands SCOPE
4ac4fd
 	  asm_clobbers ')' ';'
4ac4fd
 		{ $$ = finish_asm_stmt ($2, $4, $6, NULL_TREE, $8); }
4ac4fd
 	| GOTO '*' expr ';'
4ac4fd
@@ -3670,10 +3662,10 @@ asm_operand:
4ac4fd
 	;
4ac4fd
 
4ac4fd
 asm_clobbers:
4ac4fd
-	  string
4ac4fd
-		{ $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE);}
4ac4fd
-	| asm_clobbers ',' string
4ac4fd
-		{ $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
4ac4fd
+	  STRING
4ac4fd
+		{ $$ = tree_cons (NULL_TREE, $1, NULL_TREE);}
4ac4fd
+	| asm_clobbers ',' STRING
4ac4fd
+		{ $$ = tree_cons (NULL_TREE, $3, $1); }
4ac4fd
 	;
4ac4fd
 
4ac4fd
 /* This is what appears inside the parens in a function declarator.
4ac4fd
--- gcc/cp/spew.c.jj	2002-11-09 18:39:59.000000000 +0100
4ac4fd
+++ gcc/cp/spew.c	2004-10-05 16:08:18.725522496 +0200
4ac4fd
@@ -102,6 +102,7 @@ static SPEW_INLINE int identifier_type P
4ac4fd
 static void scan_tokens PARAMS ((int));
4ac4fd
 static void feed_defarg PARAMS ((tree));
4ac4fd
 static void finish_defarg PARAMS ((void));
4ac4fd
+static void yylexstring PARAMS ((struct token *));
4ac4fd
 static int read_token PARAMS ((struct token *));
4ac4fd
 
4ac4fd
 static SPEW_INLINE int num_tokens PARAMS ((void));
4ac4fd
@@ -244,6 +245,43 @@ read_process_identifier (pyylval)
4ac4fd
   return IDENTIFIER;
4ac4fd
 }
4ac4fd
 
4ac4fd
+/* Concatenate strings before returning them to the parser.  This isn't quite
4ac4fd
+   as good as having it done in the lexer, but it's better than nothing.  */
4ac4fd
+
4ac4fd
+static void
4ac4fd
+yylexstring (t)
4ac4fd
+     struct token *t;
4ac4fd
+{
4ac4fd
+  enum cpp_ttype next_type;
4ac4fd
+  tree next;
4ac4fd
+
4ac4fd
+  next_type = c_lex (&next;;
4ac4fd
+  if (next_type == CPP_STRING || next_type == CPP_WSTRING)
4ac4fd
+    {
4ac4fd
+      varray_type strings;
4ac4fd
+
4ac4fd
+      VARRAY_TREE_INIT (strings, 32, "strings");
4ac4fd
+      VARRAY_PUSH_TREE (strings, t->yylval.ttype);
4ac4fd
+
4ac4fd
+      do
4ac4fd
+	{
4ac4fd
+	  VARRAY_PUSH_TREE (strings, next);
4ac4fd
+	  next_type = c_lex (&next;;
4ac4fd
+	}
4ac4fd
+      while (next_type == CPP_STRING || next_type == CPP_WSTRING);
4ac4fd
+
4ac4fd
+      t->yylval.ttype = combine_strings (strings);
4ac4fd
+      last_token_id = t->yylval.ttype;
4ac4fd
+
4ac4fd
+      VARRAY_FREE (strings);
4ac4fd
+    }
4ac4fd
+
4ac4fd
+  /* We will have always read one token too many.  */
4ac4fd
+  _cpp_backup_tokens (parse_in, 1);
4ac4fd
+
4ac4fd
+  t->yychar = STRING;
4ac4fd
+}
4ac4fd
+
4ac4fd
 /* Read the next token from the input file.  The token is written into
4ac4fd
    T, and its type number is returned.  */
4ac4fd
 static int
4ac4fd
@@ -338,7 +376,7 @@ read_token (t)
4ac4fd
 
4ac4fd
     case CPP_STRING:
4ac4fd
     case CPP_WSTRING:
4ac4fd
-      t->yychar = STRING;
4ac4fd
+      yylexstring (t);
4ac4fd
       break;
4ac4fd
 
4ac4fd
     default:
4ac4fd
--- gcc/c-common.c.jj	2004-10-05 16:07:28.426465214 +0200
4ac4fd
+++ gcc/c-common.c	2004-10-05 16:08:18.646536539 +0200
4ac4fd
@@ -554,106 +554,17 @@ fname_decl (rid, id)
4ac4fd
   return decl;
4ac4fd
 }
4ac4fd
 
4ac4fd
-/* Given a chain of STRING_CST nodes,
4ac4fd
-   concatenate them into one STRING_CST
4ac4fd
-   and give it a suitable array-of-chars data type.  */
4ac4fd
+/* Given a STRING_CST, give it a suitable array-of-chars data type.  */
4ac4fd
 
4ac4fd
 tree
4ac4fd
-combine_strings (strings)
4ac4fd
-     tree strings;
4ac4fd
+fix_string_type (value)
4ac4fd
+     tree value;
4ac4fd
 {
4ac4fd
-  tree value, t;
4ac4fd
-  int length = 1;
4ac4fd
-  int wide_length = 0;
4ac4fd
-  int wide_flag = 0;
4ac4fd
-  int wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
4ac4fd
-  int nchars;
4ac4fd
+  const int wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
4ac4fd
+  const int wide_flag = TREE_TYPE (value) == wchar_array_type_node;
4ac4fd
   const int nchars_max = flag_isoc99 ? 4095 : 509;
4ac4fd
-
4ac4fd
-  if (TREE_CHAIN (strings))
4ac4fd
-    {
4ac4fd
-      /* More than one in the chain, so concatenate.  */
4ac4fd
-      char *p, *q;
4ac4fd
-
4ac4fd
-      /* Don't include the \0 at the end of each substring,
4ac4fd
-	 except for the last one.
4ac4fd
-	 Count wide strings and ordinary strings separately.  */
4ac4fd
-      for (t = strings; t; t = TREE_CHAIN (t))
4ac4fd
-	{
4ac4fd
-	  if (TREE_TYPE (t) == wchar_array_type_node)
4ac4fd
-	    {
4ac4fd
-	      wide_length += (TREE_STRING_LENGTH (t) - wchar_bytes);
4ac4fd
-	      wide_flag = 1;
4ac4fd
-	    }
4ac4fd
-	  else
4ac4fd
-	    {
4ac4fd
-	      length += (TREE_STRING_LENGTH (t) - 1);
4ac4fd
-	      if (C_ARTIFICIAL_STRING_P (t) && !in_system_header)
4ac4fd
-		warning ("concatenation of string literals with __FUNCTION__ is deprecated"); 
4ac4fd
-	    }
4ac4fd
-	}
4ac4fd
-
4ac4fd
-      /* If anything is wide, the non-wides will be converted,
4ac4fd
-	 which makes them take more space.  */
4ac4fd
-      if (wide_flag)
4ac4fd
-	length = length * wchar_bytes + wide_length;
4ac4fd
-
4ac4fd
-      p = xmalloc (length);
4ac4fd
-
4ac4fd
-      /* Copy the individual strings into the new combined string.
4ac4fd
-	 If the combined string is wide, convert the chars to ints
4ac4fd
-	 for any individual strings that are not wide.  */
4ac4fd
-
4ac4fd
-      q = p;
4ac4fd
-      for (t = strings; t; t = TREE_CHAIN (t))
4ac4fd
-	{
4ac4fd
-	  int len = (TREE_STRING_LENGTH (t)
4ac4fd
-		     - ((TREE_TYPE (t) == wchar_array_type_node)
4ac4fd
-			? wchar_bytes : 1));
4ac4fd
-	  if ((TREE_TYPE (t) == wchar_array_type_node) == wide_flag)
4ac4fd
-	    {
4ac4fd
-	      memcpy (q, TREE_STRING_POINTER (t), len);
4ac4fd
-	      q += len;
4ac4fd
-	    }
4ac4fd
-	  else
4ac4fd
-	    {
4ac4fd
-	      int i, j;
4ac4fd
-	      for (i = 0; i < len; i++)
4ac4fd
-		{
4ac4fd
-		  if (BYTES_BIG_ENDIAN)
4ac4fd
-		    {
4ac4fd
-		      for (j=0; j<(WCHAR_TYPE_SIZE / BITS_PER_UNIT)-1; j++)
4ac4fd
-			*q++ = 0;
4ac4fd
-		      *q++ = TREE_STRING_POINTER (t)[i];
4ac4fd
-		    }
4ac4fd
-		  else
4ac4fd
-		    {
4ac4fd
-		      *q++ = TREE_STRING_POINTER (t)[i];
4ac4fd
-		      for (j=0; j<(WCHAR_TYPE_SIZE / BITS_PER_UNIT)-1; j++)
4ac4fd
-			*q++ = 0;
4ac4fd
-		    }
4ac4fd
-		}
4ac4fd
-	    }
4ac4fd
-	}
4ac4fd
-      if (wide_flag)
4ac4fd
-	{
4ac4fd
-	  int i;
4ac4fd
-	  for (i = 0; i < wchar_bytes; i++)
4ac4fd
-	    *q++ = 0;
4ac4fd
-	}
4ac4fd
-      else
4ac4fd
-	*q = 0;
4ac4fd
-
4ac4fd
-      value = build_string (length, p);
4ac4fd
-      free (p);
4ac4fd
-    }
4ac4fd
-  else
4ac4fd
-    {
4ac4fd
-      value = strings;
4ac4fd
-      length = TREE_STRING_LENGTH (value);
4ac4fd
-      if (TREE_TYPE (value) == wchar_array_type_node)
4ac4fd
-	wide_flag = 1;
4ac4fd
-    }
4ac4fd
+  int length = TREE_STRING_LENGTH (value);
4ac4fd
+  int nchars;
4ac4fd
 
4ac4fd
   /* Compute the number of elements, for the array type.  */
4ac4fd
   nchars = wide_flag ? length / wchar_bytes : length;
4ac4fd
@@ -686,6 +597,111 @@ combine_strings (strings)
4ac4fd
   TREE_STATIC (value) = 1;
4ac4fd
   return value;
4ac4fd
 }
4ac4fd
+
4ac4fd
+/* Given a VARRAY of STRING_CST nodes, concatenate them into one
4ac4fd
+   STRING_CST.  */
4ac4fd
+
4ac4fd
+tree
4ac4fd
+combine_strings (strings)
4ac4fd
+     varray_type strings;
4ac4fd
+{
4ac4fd
+  const int wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
4ac4fd
+  const int nstrings = VARRAY_ACTIVE_SIZE (strings);
4ac4fd
+  tree value, t;
4ac4fd
+  int length = 1;
4ac4fd
+  int wide_length = 0;
4ac4fd
+  int wide_flag = 0;
4ac4fd
+  int i;
4ac4fd
+  char *p, *q;
4ac4fd
+
4ac4fd
+  /* Don't include the \0 at the end of each substring.  Count wide
4ac4fd
+     strings and ordinary strings separately.  */
4ac4fd
+  for (i = 0; i < nstrings; ++i)
4ac4fd
+    {
4ac4fd
+      t = VARRAY_TREE (strings, i);
4ac4fd
+
4ac4fd
+      if (TREE_TYPE (t) == wchar_array_type_node)
4ac4fd
+	{
4ac4fd
+	  wide_length += TREE_STRING_LENGTH (t) - wchar_bytes;
4ac4fd
+	  wide_flag = 1;
4ac4fd
+	}
4ac4fd
+      else
4ac4fd
+	{
4ac4fd
+	  length += (TREE_STRING_LENGTH (t) - 1);
4ac4fd
+	  if (C_ARTIFICIAL_STRING_P (t) && !in_system_header)
4ac4fd
+	    warning ("concatenation of string literals with __FUNCTION__ is deprecated"); 
4ac4fd
+	}
4ac4fd
+    }
4ac4fd
+
4ac4fd
+  /* If anything is wide, the non-wides will be converted,
4ac4fd
+     which makes them take more space.  */
4ac4fd
+  if (wide_flag)
4ac4fd
+    length = length * wchar_bytes + wide_length;
4ac4fd
+
4ac4fd
+  p = xmalloc (length);
4ac4fd
+
4ac4fd
+  /* Copy the individual strings into the new combined string.
4ac4fd
+     If the combined string is wide, convert the chars to ints
4ac4fd
+     for any individual strings that are not wide.  */
4ac4fd
+
4ac4fd
+  q = p;
4ac4fd
+  for (i = 0; i < nstrings; ++i)
4ac4fd
+    {
4ac4fd
+      int len, this_wide;
4ac4fd
+
4ac4fd
+      t = VARRAY_TREE (strings, i);
4ac4fd
+      this_wide = TREE_TYPE (t) == wchar_array_type_node;
4ac4fd
+      len = TREE_STRING_LENGTH (t) - (this_wide ? wchar_bytes : 1);
4ac4fd
+      if (this_wide == wide_flag)
4ac4fd
+	{
4ac4fd
+	  memcpy (q, TREE_STRING_POINTER (t), len);
4ac4fd
+	  q += len;
4ac4fd
+	}
4ac4fd
+      else
4ac4fd
+	{
4ac4fd
+	  const int nzeros = (WCHAR_TYPE_SIZE / BITS_PER_UNIT) - 1;
4ac4fd
+	  int j, k;
4ac4fd
+
4ac4fd
+	  if (BYTES_BIG_ENDIAN)
4ac4fd
+	    {
4ac4fd
+	      for (k = 0; k < len; k++)
4ac4fd
+		{
4ac4fd
+		  for (j = 0; j < nzeros; j++)
4ac4fd
+		    *q++ = 0;
4ac4fd
+		  *q++ = TREE_STRING_POINTER (t)[k];
4ac4fd
+		}
4ac4fd
+	    }
4ac4fd
+	  else
4ac4fd
+	    {
4ac4fd
+	      for (k = 0; k < len; k++)
4ac4fd
+		{
4ac4fd
+		  *q++ = TREE_STRING_POINTER (t)[k];
4ac4fd
+		  for (j = 0; j < nzeros; j++)
4ac4fd
+		    *q++ = 0;
4ac4fd
+		}
4ac4fd
+	    }
4ac4fd
+	}
4ac4fd
+    }
4ac4fd
+
4ac4fd
+  /* Nul terminate the string.  */
4ac4fd
+  if (wide_flag)
4ac4fd
+    {
4ac4fd
+      for (i = 0; i < wchar_bytes; i++)
4ac4fd
+	*q++ = 0;
4ac4fd
+    }
4ac4fd
+  else
4ac4fd
+    *q = 0;
4ac4fd
+
4ac4fd
+  value = build_string (length, p);
4ac4fd
+  free (p);
4ac4fd
+
4ac4fd
+  if (wide_flag)
4ac4fd
+    TREE_TYPE (value) = wchar_array_type_node;
4ac4fd
+  else
4ac4fd
+    TREE_TYPE (value) = char_array_type_node;
4ac4fd
+
4ac4fd
+  return value;
4ac4fd
+}
4ac4fd
 
4ac4fd
 static int is_valid_printf_arglist PARAMS ((tree));
4ac4fd
 static rtx c_expand_builtin PARAMS ((tree, rtx, enum machine_mode, enum expand_modifier));
4ac4fd
@@ -4062,7 +4078,7 @@ c_expand_builtin_printf (arglist, target
4ac4fd
 	  memcpy (newstr, TREE_STRING_POINTER (stripped_string), newlen - 1);
4ac4fd
 	  newstr[newlen - 1] = 0;
4ac4fd
 	  
4ac4fd
-	  arglist = combine_strings (build_string (newlen, newstr));
4ac4fd
+	  arglist = fix_string_type (build_string (newlen, newstr));
4ac4fd
 	  arglist = build_tree_list (NULL_TREE, arglist);
4ac4fd
 	  fn = fn_puts;
4ac4fd
 	}
4ac4fd
--- gcc/testsuite/gcc.dg/concat2.c.jj	2004-10-05 16:08:18.746518763 +0200
4ac4fd
+++ gcc/testsuite/gcc.dg/concat2.c	2004-10-05 16:08:18.746518763 +0200
4ac4fd
@@ -0,0 +1,16 @@
4ac4fd
+/* PR c/3581 */
4ac4fd
+/* { dg-do compile } */
4ac4fd
+/* { dg-options "" } */
4ac4fd
+
4ac4fd
+/* Intended as a compile-time test for string literal concatenation.
4ac4fd
+   The fact that the string isn't actually used in the resulting program
4ac4fd
+   should allow this to compile for any target.  */
4ac4fd
+
4ac4fd
+#define e0	"a"
4ac4fd
+#define e1	e0 e0 e0 e0 e0 e0 e0 e0 e0 e0
4ac4fd
+#define e2	e1 e1 e1 e1 e1 e1 e1 e1 e1 e1
4ac4fd
+#define e3	e2 e2 e2 e2 e2 e2 e2 e2 e2 e2
4ac4fd
+#define e4	e3 e3 e3 e3 e3 e3 e3 e3 e3 e3
4ac4fd
+#define e5	e4 e4 e4 e4 e4 e4 e4 e4 e4 e4
4ac4fd
+
4ac4fd
+void foo() { (void)(e5); }
4ac4fd
--- gcc/testsuite/g++.dg/parse/concat1.C.jj	2004-10-05 16:08:18.745518941 +0200
4ac4fd
+++ gcc/testsuite/g++.dg/parse/concat1.C	2004-10-05 16:08:18.745518941 +0200
4ac4fd
@@ -0,0 +1,15 @@
4ac4fd
+/* PR c/3581 */
4ac4fd
+/* { dg-do compile } */
4ac4fd
+
4ac4fd
+/* Intended as a compile-time test for string literal concatenation.
4ac4fd
+   The fact that the string isn't actually used in the resulting program
4ac4fd
+   should allow this to compile for any target.  */
4ac4fd
+
4ac4fd
+#define e0	"a"
4ac4fd
+#define e1	e0 e0 e0 e0 e0 e0 e0 e0 e0 e0
4ac4fd
+#define e2	e1 e1 e1 e1 e1 e1 e1 e1 e1 e1
4ac4fd
+#define e3	e2 e2 e2 e2 e2 e2 e2 e2 e2 e2
4ac4fd
+#define e4	e3 e3 e3 e3 e3 e3 e3 e3 e3 e3
4ac4fd
+#define e5	e4 e4 e4 e4 e4 e4 e4 e4 e4 e4
4ac4fd
+
4ac4fd
+void foo() { (void)(e5); }
4ac4fd
--- gcc/c-parse.in.jj	2003-08-02 01:21:40.000000000 +0200
4ac4fd
+++ gcc/c-parse.in	2004-10-05 16:08:18.682530140 +0200
4ac4fd
@@ -148,7 +148,7 @@ end ifobjc
4ac4fd
 %type <ttype> BREAK CONTINUE RETURN GOTO ASM_KEYWORD SIZEOF TYPEOF ALIGNOF
4ac4fd
 
4ac4fd
 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
4ac4fd
-%type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
4ac4fd
+%type <ttype> expr_no_commas cast_expr unary_expr primary STRING
4ac4fd
 %type <ttype> declspecs_nosc_nots_nosa_noea declspecs_nosc_nots_nosa_ea
4ac4fd
 %type <ttype> declspecs_nosc_nots_sa_noea declspecs_nosc_nots_sa_ea
4ac4fd
 %type <ttype> declspecs_nosc_ts_nosa_noea declspecs_nosc_ts_nosa_ea
4ac4fd
@@ -296,6 +296,7 @@ end ifc
4ac4fd
 static void yyprint	  PARAMS ((FILE *, int, YYSTYPE));
4ac4fd
 static void yyerror	  PARAMS ((const char *));
4ac4fd
 static int yylexname	  PARAMS ((void));
4ac4fd
+static int yylexstring	  PARAMS ((void));
4ac4fd
 static inline int _yylex  PARAMS ((void));
4ac4fd
 static int  yylex	  PARAMS ((void));
4ac4fd
 static void init_reswords PARAMS ((void));
4ac4fd
@@ -623,8 +624,8 @@ primary:
4ac4fd
 		  $$ = build_external_ref ($1, yychar == '(');
4ac4fd
 		}
4ac4fd
 	| CONSTANT
4ac4fd
-	| string
4ac4fd
-		{ $$ = combine_strings ($1); }
4ac4fd
+	| STRING
4ac4fd
+		{ $$ = fix_string_type ($$); }
4ac4fd
 	| VAR_FUNC_NAME
4ac4fd
 		{ $$ = fname_decl (C_RID_CODE ($$), $$); }
4ac4fd
 	| '(' typename ')' '{' 
4ac4fd
@@ -735,29 +736,6 @@ ifobjc
4ac4fd
 end ifobjc
4ac4fd
 	;
4ac4fd
 
4ac4fd
-/* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it.  */
4ac4fd
-string:
4ac4fd
-	  STRING
4ac4fd
-	| string STRING
4ac4fd
-		{
4ac4fd
-ifc
4ac4fd
-                  static int last_lineno = 0;
4ac4fd
-                  static const char *last_input_filename = 0;
4ac4fd
-end ifc
4ac4fd
-                  $$ = chainon ($1, $2);
4ac4fd
-ifc
4ac4fd
-		  if (warn_traditional && !in_system_header
4ac4fd
-		      && (lineno != last_lineno || !last_input_filename ||
4ac4fd
-			  strcmp (last_input_filename, input_filename)))
4ac4fd
-		    {
4ac4fd
-		      warning ("traditional C rejects string concatenation");
4ac4fd
-		      last_lineno = lineno;
4ac4fd
-		      last_input_filename = input_filename;
4ac4fd
-		    }
4ac4fd
-end ifc
4ac4fd
-		}
4ac4fd
-	;
4ac4fd
-
4ac4fd
 ifobjc
4ac4fd
 /* Produces an STRING_CST with perhaps more STRING_CSTs chained
4ac4fd
    onto it, which is to be read as an ObjC string object.  */
4ac4fd
@@ -1398,10 +1376,8 @@ notype_initdecls:
4ac4fd
 maybeasm:
4ac4fd
 	  /* empty */
4ac4fd
 		{ $$ = NULL_TREE; }
4ac4fd
-	| ASM_KEYWORD '(' string ')'
4ac4fd
-		{ if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
4ac4fd
-		  $$ = $3;
4ac4fd
-		}
4ac4fd
+	| ASM_KEYWORD '(' STRING ')'
4ac4fd
+		{ $$ = $3; }
4ac4fd
 	;
4ac4fd
 
4ac4fd
 initdcl:
4ac4fd
@@ -2482,10 +2458,10 @@ asm_operand:
4ac4fd
 	;
4ac4fd
 
4ac4fd
 asm_clobbers:
4ac4fd
-	  string
4ac4fd
-		{ $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
4ac4fd
-	| asm_clobbers ',' string
4ac4fd
-		{ $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
4ac4fd
+	  STRING
4ac4fd
+		{ $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
4ac4fd
+	| asm_clobbers ',' STRING
4ac4fd
+		{ $$ = tree_cons (NULL_TREE, $3, $1); }
4ac4fd
 	;
4ac4fd
 
4ac4fd
 /* This is what appears inside the parens in a function declarator.
4ac4fd
@@ -3683,6 +3659,59 @@ end ifobjc
4ac4fd
   return IDENTIFIER;
4ac4fd
 }
4ac4fd
 
4ac4fd
+/* Concatenate strings before returning them to the parser.  This isn't quite
4ac4fd
+   as good as having it done in the lexer, but it's better than nothing.  */
4ac4fd
+
4ac4fd
+static int
4ac4fd
+yylexstring ()
4ac4fd
+{
4ac4fd
+  enum cpp_ttype next_type;
4ac4fd
+  tree orig = yylval.ttype;
4ac4fd
+
4ac4fd
+  next_type = c_lex (&yylval.ttype);
4ac4fd
+  if (next_type == CPP_STRING
4ac4fd
+      || next_type == CPP_WSTRING
4ac4fd
+      || (next_type == CPP_NAME && yylexname () == STRING))
4ac4fd
+    {
4ac4fd
+      varray_type strings;
4ac4fd
+
4ac4fd
+ifc
4ac4fd
+      static int last_lineno = 0;
4ac4fd
+      static const char *last_input_filename = 0;
4ac4fd
+      if (warn_traditional && !in_system_header
4ac4fd
+	  && (lineno != last_lineno || !last_input_filename ||
4ac4fd
+	      strcmp (last_input_filename, input_filename)))
4ac4fd
+	{
4ac4fd
+	  warning ("traditional C rejects string concatenation");
4ac4fd
+	  last_lineno = lineno;
4ac4fd
+	  last_input_filename = input_filename;
4ac4fd
+	}
4ac4fd
+end ifc
4ac4fd
+
4ac4fd
+      VARRAY_TREE_INIT (strings, 32, "strings");
4ac4fd
+      VARRAY_PUSH_TREE (strings, orig);
4ac4fd
+
4ac4fd
+      do
4ac4fd
+	{
4ac4fd
+	  VARRAY_PUSH_TREE (strings, yylval.ttype);
4ac4fd
+	  next_type = c_lex (&yylval.ttype);
4ac4fd
+	}
4ac4fd
+      while (next_type == CPP_STRING
4ac4fd
+	     || next_type == CPP_WSTRING
4ac4fd
+	     || (next_type == CPP_NAME && yylexname () == STRING));
4ac4fd
+
4ac4fd
+      yylval.ttype = combine_strings (strings);
4ac4fd
+
4ac4fd
+      VARRAY_FREE (strings);
4ac4fd
+    }
4ac4fd
+  else
4ac4fd
+    yylval.ttype = orig;
4ac4fd
+
4ac4fd
+  /* We will have always read one token too many.  */
4ac4fd
+  _cpp_backup_tokens (parse_in, 1);
4ac4fd
+
4ac4fd
+  return STRING;
4ac4fd
+}
4ac4fd
 
4ac4fd
 static inline int
4ac4fd
 _yylex ()
4ac4fd
@@ -3749,7 +3778,13 @@ _yylex ()
4ac4fd
       return 0;
4ac4fd
 
4ac4fd
     case CPP_NAME:
4ac4fd
-      return yylexname ();
4ac4fd
+      {
4ac4fd
+	int ret = yylexname ();
4ac4fd
+	if (ret == STRING)
4ac4fd
+	  return yylexstring ();
4ac4fd
+	else
4ac4fd
+	  return ret;
4ac4fd
+      }
4ac4fd
 
4ac4fd
     case CPP_NUMBER:
4ac4fd
     case CPP_CHAR:
4ac4fd
@@ -3758,7 +3793,7 @@ _yylex ()
4ac4fd
 
4ac4fd
     case CPP_STRING:
4ac4fd
     case CPP_WSTRING:
4ac4fd
-      return STRING;
4ac4fd
+      return yylexstring ();
4ac4fd
       
4ac4fd
       /* This token is Objective-C specific.  It gives the next token
4ac4fd
 	 special significance.  */
4ac4fd
--- gcc/c-typeck.c.jj	2003-03-10 17:42:06.000000000 +0100
4ac4fd
+++ gcc/c-typeck.c	2004-10-05 16:08:48.926153031 +0200
4ac4fd
@@ -6890,9 +6890,6 @@ simple_asm_stmt (expr)
4ac4fd
     {
4ac4fd
       tree stmt;
4ac4fd
 
4ac4fd
-      if (TREE_CHAIN (expr))
4ac4fd
-	expr = combine_strings (expr);
4ac4fd
-
4ac4fd
       /* Simple asm statements are treated as volatile.  */
4ac4fd
       stmt = add_stmt (build_stmt (ASM_STMT, ridpointers[(int) RID_VOLATILE],
4ac4fd
       				   expr, NULL_TREE, NULL_TREE, NULL_TREE));
4ac4fd
@@ -6917,8 +6914,6 @@ build_asm_stmt (cv_qualifier, string, ou
4ac4fd
 {
4ac4fd
   tree tail;
4ac4fd
 
4ac4fd
-  if (TREE_CHAIN (string))
4ac4fd
-    string = combine_strings (string);
4ac4fd
   if (TREE_CODE (string) != STRING_CST)
4ac4fd
     {
4ac4fd
       error ("asm template is not a string constant");