[Patch, Fortran] PR56737 - Fixing a bug in the I/O format cache handling

Tobias Burnus burnus@net-b.de
Thu Mar 28 09:50:00 GMT 2013


libgfortran parses the format string for formatted I/O and saves it in 
an internal representation. To speed up the I/O - for instance in a loop 
-, caching is used.

However, a pointer to format string is used for the processing of 
strings (normal string constants and Hollerith). That works well if the 
format string is a constant as then the pointer won't change between 
invocations. It often also works when the string is stack-allocated if 
either the character variable on the stack is never freed (for the same 
format string) - or multiple calls to the same format lead to the same 
stack location. (In general, the same stack location is unlikely but in 
typical I/O calls that's often the case. And static string constants are 
the rule.)

The bug dates back to the first caching implementation in GCC 4.5.

There are two possibilities:
a) To disable caching when a string (FMT_A or FMT_H) is in the format 
string.
b) To copy the format string

The attached patch does the latter. The current hashing algorithm avoids 
hash collisions by checking whether the value is exactly the same - and 
the value is given by the format string. Thus, instead of copying the 
string when storing the format in the cache, the patch copies it now 
before calling parse_format_list.

Bootstrapped and regtested on x86-64-gnu-linux.
OK for the trunk and the 4.6/4.7/4.8 branches?

Tobias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fmt-cache-fix.diff
Type: text/x-patch
Size: 3939 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20130328/4647461d/attachment.bin>


More information about the Fortran mailing list