Eric Fiselier | 0ef3b1b | 2016-12-09 09:31:01 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame^] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Eric Fiselier | 0ef3b1b | 2016-12-09 09:31:01 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | #ifndef SUPPORT_DEMANGLE_H |
| 10 | #define SUPPORT_DEMANGLE_H |
| 11 | |
| 12 | #include "test_macros.h" |
| 13 | #include <string> |
| 14 | #include <cstdlib> |
| 15 | |
| 16 | #if !defined(TEST_HAS_NO_DEMANGLE) |
| 17 | # if defined(__GNUC__) || defined(__clang__) |
Eric Fiselier | 121baf4 | 2017-01-14 20:21:18 +0000 | [diff] [blame] | 18 | # if __has_include("cxxabi.h") && !defined(_LIBCPP_ABI_MICROSOFT) |
Eric Fiselier | 0ef3b1b | 2016-12-09 09:31:01 +0000 | [diff] [blame] | 19 | # include "cxxabi.h" |
| 20 | # else |
| 21 | # define TEST_HAS_NO_DEMANGLE |
| 22 | # endif |
| 23 | # else |
| 24 | # define TEST_HAS_NO_DEMANGLE |
| 25 | # endif |
| 26 | #endif |
| 27 | |
| 28 | #if defined(TEST_HAS_NO_DEMANGLE) |
| 29 | inline std::string demangle(const char* mangled_name) { |
| 30 | return mangled_name; |
| 31 | } |
| 32 | #else |
| 33 | template <size_t N> struct Printer; |
| 34 | inline std::string demangle(const char* mangled_name) { |
| 35 | int status = 0; |
Eric Fiselier | d1e211a | 2017-01-20 00:00:31 +0000 | [diff] [blame] | 36 | char* out = __cxxabiv1::__cxa_demangle(mangled_name, nullptr, nullptr, &status); |
Eric Fiselier | 0ef3b1b | 2016-12-09 09:31:01 +0000 | [diff] [blame] | 37 | if (out != nullptr) { |
| 38 | std::string res(out); |
| 39 | std::free(out); |
| 40 | return res; |
| 41 | } |
| 42 | return mangled_name; |
| 43 | } |
| 44 | #endif |
| 45 | |
| 46 | #endif // SUPPORT_DEMANGLE_H |