blob: f8e90a19f746a6ec72fd344320351f7f24665db5 [file] [log] [blame]
Eric Fiselier0ef3b1b2016-12-09 09:31:01 +00001// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
Chandler Carruth57b08b02019-01-19 10:56:40 +00004// 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 Fiselier0ef3b1b2016-12-09 09:31:01 +00007//
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 Fiselier121baf42017-01-14 20:21:18 +000018# if __has_include("cxxabi.h") && !defined(_LIBCPP_ABI_MICROSOFT)
Eric Fiselier0ef3b1b2016-12-09 09:31:01 +000019# 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)
29inline std::string demangle(const char* mangled_name) {
30 return mangled_name;
31}
32#else
33template <size_t N> struct Printer;
34inline std::string demangle(const char* mangled_name) {
35 int status = 0;
Eric Fiselierd1e211a2017-01-20 00:00:31 +000036 char* out = __cxxabiv1::__cxa_demangle(mangled_name, nullptr, nullptr, &status);
Eric Fiselier0ef3b1b2016-12-09 09:31:01 +000037 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