10b8c8bc8SPiotr Fusik //===----------------------------------------------------------------------===//
20b8c8bc8SPiotr Fusik //
30b8c8bc8SPiotr Fusik // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b8c8bc8SPiotr Fusik // See https://llvm.org/LICENSE.txt for license information.
50b8c8bc8SPiotr Fusik // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b8c8bc8SPiotr Fusik //
70b8c8bc8SPiotr Fusik //===----------------------------------------------------------------------===//
80b8c8bc8SPiotr Fusik 
90b8c8bc8SPiotr Fusik // UNSUPPORTED: 32-bit-pointer
10122064a6SMartin Storsjö // REQUIRES: large_tests
110b8c8bc8SPiotr Fusik 
12*0547e573SLouis Dionne // This bug was fixed in the dylib by 53aed4759b33e33614e0f4e321bc1ef764b6d5b6.
13*0547e573SLouis Dionne // XFAIL: using-built-library-before-llvm-17
14*0547e573SLouis Dionne 
15bce3b505SRyan Prichard // Android devices frequently don't have enough memory to run this test. Rather
16bce3b505SRyan Prichard // than throw std::bad_alloc, exhausting memory triggers the OOM Killer.
17bce3b505SRyan Prichard // UNSUPPORTED: LIBCXX-ANDROID-FIXME
18bce3b505SRyan Prichard 
190b8c8bc8SPiotr Fusik // Test that tellp() does not break the stringstream after INT_MAX, due to use
200b8c8bc8SPiotr Fusik // of pbump() that accept int.
210b8c8bc8SPiotr Fusik 
220b8c8bc8SPiotr Fusik #include <cassert>
230b8c8bc8SPiotr Fusik #include <climits>
240b8c8bc8SPiotr Fusik #include <sstream>
250b8c8bc8SPiotr Fusik #include <string>
260b8c8bc8SPiotr Fusik 
270b8c8bc8SPiotr Fusik int main(int, char**) {
280b8c8bc8SPiotr Fusik   std::stringstream ss;
290b8c8bc8SPiotr Fusik   std::string payload(INT_MAX - 1, '\0');
300b8c8bc8SPiotr Fusik 
310b8c8bc8SPiotr Fusik   ss.write(payload.data(), payload.size());
320b8c8bc8SPiotr Fusik   assert(ss.tellp() == INT_MAX - 1);
330b8c8bc8SPiotr Fusik 
340b8c8bc8SPiotr Fusik   ss.write("a", 1);
350b8c8bc8SPiotr Fusik   assert(ss.tellp() == INT_MAX);
360b8c8bc8SPiotr Fusik 
370b8c8bc8SPiotr Fusik   ss.write("b", 1);
380b8c8bc8SPiotr Fusik   assert(ss.tellp() == INT_MAX + 1ULL);
390b8c8bc8SPiotr Fusik   // it fails only after previous tellp() corrupts the internal field with int
400b8c8bc8SPiotr Fusik   // overflow
410b8c8bc8SPiotr Fusik   assert(ss.tellp() == INT_MAX + 1ULL);
420b8c8bc8SPiotr Fusik 
430b8c8bc8SPiotr Fusik   return 0;
440b8c8bc8SPiotr Fusik }
45