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]

[Ada] improve handling of long string concat


Tested on i686-linux, committed on trunk

Fold long sequences of concatenations of string literals into a single literal
during parsing, in order to avoid very deep recursion in the front end, which
was causing stack overflow. The rewritten tree is "" & "folded...literal", so
that the normal overload resolution for "&" can be used. If it resolves to a
predefined "&", all is well. Otherwise, we give an error, because the folded
result is wrong (it doesn't call the user-defined function).
No small test case is possible -- it takes tens of thousands of concatenations
to cause trouble.

2007-08-31  Bob Duff  <duff@adacore.com>

	* par-ch4.adb (P_Simple_Expression): Fold long sequences of
	concatenations of string literals into a single literal, in order to
	avoid very deep recursion in the front end, which was causing stack
	overflow.

	* sem_eval.adb (Eval_Concatenation): If the left operand is the empty
	string, and the right operand is a string literal (the case of "" &
	"..."), optimize by avoiding copying the right operand -- just use the
	value of the right operand directly.

	* stringt.adb (Store_String_Chars): Optimize by growing the
	String_Chars table all at once, rather than appending characters one by
	one.
	(Write_String_Table_Entry): If the string to be printed is very long,
	just print the first few characters, followed by the length. Otherwise,
	doing "pn(n)" in the debugger can take an extremely long time.

	* sem_prag.adb (Process_Interface_Name): Replace loop doing
	Store_String_Char with Store_String_Chars.

Attachment: difs
Description: Text document


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