Fixes are available
October 2010 PTF for XL C/C++ for AIX, V10.1
May 2012 PTF for XL C/C++ for AIX, V10.1
January 2013 PTF for XL C/C++ for AIX, V10.1
XL C/C++ for AIX Fix Pack 18 (July 2013 PTF) for 10.1
XL C/C++ for AIX Fix Pack 19 (October 2013 PTF) for 10.1
XL C/C++ for AIX Fix Pack 21 (October 2015 PTF) for 10.1
June 2010 PTF for XL C/C++ for AIX, V10.1
May 2011 PTF for XL C/C++ for AIX, V10.1
October 2011 PTF for XL C/C++ for AIX, V10.1
February 2012 PTF for XL C/C++ for AIX, V10.1
September 2012 PTF for XL C/C++ for AIX, V10.1
XL C/C++ for AIX Fix Pack 20 (October 2014 PTF) for 10.1
APAR status
Closed as program error.
Error description
The following test case demonstrates an issue with the copy-on-write optimization performed by the string class: ===== COMPILE COMMAND: xlC test.cxx ===== TESTCASE: $ cat test.cxx #include <cstdio> #include <string> #include <vector> int main() { std::string const x = "x"; int const n = 256; std::vector<std::string> v; v.reserve(n); for(int i=0; i < n; ++i) { v.push_back(x); std::string xy = x + "y"; const char* p = x.c_str(); std::printf("x = [%s], xy = [%s]", p, xy.c_str()); #if defined(COUNT) std::printf(", count = %d", int(p[-1])); #endif std::printf("\n"); } return 0; } ===== ACTUAL OUTPUT: $ xlC test.cxx && ./a.out x = [x], xy = [xy] ... x = [x], xy = [xy] x = [x], xy = [xy] x = [xy], xy = [xy] x = [xy], xy = [xy] ... x = [xy], xy = [xy] $ ===== EXPECTED OUTPUT: $ xlC test.cxx && ./a.out x = [x], xy = [xy] ... x = [x], xy = [xy] x = [x], xy = [xy] x = [x], xy = [xy] x = [x], xy = [xy] ... x = [x], xy = [xy] $
Local fix
Use xlC_r instead of xlC, as xlC_r disables the copy-on-write optimization.
Problem summary
USERS AFFECTED: Users who use the same string many times in assign or append string operations may be affected by this issue. PROBLEM DESCRIPTION: When the same string is copied many times, the compiler uses the Copy On Write (COW) algorithm in the implementation, which only updates the reference count in the original string in the operation of assigning the original string to another string. When the reference count approaches to the maximum number for the string, instead of creating a copy of the original string, it reuses the original string, and when other operations like append happens, the original string also gets updated. This causes the test case start to fail after a certain number of copies.
Problem conclusion
The compiler has been changed to create a new copy of the original string, instead of reusing the string.
Temporary fix
Comments
APAR Information
APAR number
IZ70285
Reported component name
XL C++ AIX
Reported component ID
5724U8100
Reported release
A10
Status
CLOSED PER
PE
NoPE
HIPER
NoHIPER
Special Attention
NoSpecatt
Submitted date
2010-02-12
Closed date
2010-06-03
Last modified date
2010-06-03
APAR is sysrouted FROM one or more of the following:
APAR is sysrouted TO one or more of the following:
Fix information
Fixed component name
XL C++ AIX
Fixed component ID
5724U8100
Applicable component levels
Document Information
Modified date:
03 June 2010