• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // -*- C++ -*-
2 //===-------------------- support/android/wchar_support.c ------------------===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10 
11 #include <iostream>
12 #include <locale>
13 
main(void)14 int main(void) {
15   // TODO(digit): This imbue is required, otherwise a crash will happen
16   // at runtime, with the following stack trace:
17   //
18   //   #0  0x00069ae0 in std::(anonymous namespace)::default_terminate () at jni/../../../../gabi++/src/terminate.cc:57
19   //   #1  0x00069e48 in std::terminate () at jni/../../../../gabi++/src/terminate.cc:123
20   //   #2  0x00067d44 in __cxxabiv1::call_terminate (unwind_exception=0x1827470) at jni/../../../../gabi++/src/helper_func_internal.cc:58
21   //   #3  0x00066bf8 in (anonymous namespace)::throwException (header=0x1827438) at jni/../../../../gabi++/src/cxxabi.cc:126
22   //   #4  0x00066e64 in __cxxabiv1::__cxa_throw (thrown_exc=0x18274c8, tinfo=0x7fa00, dest=0x69c10 <std::bad_cast::~bad_cast()>)
23   //       at jni/../../../../gabi++/src/cxxabi.cc:190
24   //   #5  0x00010be0 in std::__1::locale::__imp::use_facet (this=0x80b28, id=28) at jni/../../../libcxx/src/locale.cpp:426
25   //   #6  0x00010f50 in std::__1::locale::use_facet (this=0xbe980ab4, x=...) at jni/../../../libcxx/src/locale.cpp:568
26   //   #7  0x00009e88 in use_facet<std::__1::ctype<char> > (__l=<optimized out>) at jni/../../../libcxx/include/__locale:172
27   //   #8  widen (__c=10 '\n', this=0x80084) at jni/../../../libcxx/include/ios:726
28   //   #9  std::__1::endl<char, std::__1::char_traits<char> > (__os=...) at jni/../../../libcxx/include/ostream:1181
29   //   #10 0x00009ad0 in operator<< (
30   //   __pf=0x9e20 <std::__1::endl<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)>, this=0x80080) at jni/../../../libcxx/include/ostream:306
31   //   #11 main () at jni/test_1.cc:22
32   //
33   // The issue seems to be that on #9, the id retrieved through
34   // locale::id::__get() reaches 28, which is an invalid index in the
35   // facets_ vector defined in locale.cpp:124 and populated in
36   // locale::__imp::__imp(size_t) in the same source file.
37   //
38   // Not sure if a libc++ bug or something else. Investigate.
39   std::cout.imbue(std::locale("C"));
40   std::cout << "Hello World" << std::endl;
41   return 0;
42 }
43