| 1 |
#include <gtest/gtest.h> |
| 2 |
#include <gtest/gtest-matchers.h> |
| 3 |
#include <gmock/gmock.h> |
| 4 |
#include <gmock/gmock-matchers.h> |
| 5 |
|
| 6 |
#ifdef TEST_MODULE |
| 7 |
import cpptrace; |
| 8 |
#else |
| 9 |
#include <cpptrace/utils.hpp> |
| 10 |
#endif |
| 11 |
|
| 12 |
namespace { |
| 13 |
|
| 14 |
#define DO_TEST(symbol, expected) EXPECT_EQ(cpptrace::prune_symbol(symbol), expected) << "Input: " << symbol |
| 15 |
|
| 16 |
TEST(PruneSymbolTests, Basic) { |
| 17 |
// https://godbolt.org/z/Weas1ETPv |
| 18 |
DO_TEST("foo()", "foo"); |
| 19 |
DO_TEST("foo(int, char)", "foo"); |
| 20 |
DO_TEST("void foo(void)", "foo"); |
| 21 |
DO_TEST("void foo(int, char)", "foo"); |
| 22 |
} |
| 23 |
|
| 24 |
TEST(PruneSymbolTests, Namespaces) { |
| 25 |
// https://godbolt.org/z/WzfsrPhE4 |
| 26 |
DO_TEST("foo()", "foo"); |
| 27 |
DO_TEST("ns::foo()", "ns::foo"); |
| 28 |
DO_TEST("ns::ns2::foo()", "ns::ns2::foo"); |
| 29 |
DO_TEST("ns::v1::bar()", "ns::v1::bar"); |
| 30 |
DO_TEST("(anonymous namespace)::bar()", "(anonymous namespace)::bar"); |
| 31 |
|
| 32 |
DO_TEST("void foo(void)", "foo"); |
| 33 |
DO_TEST("void ns::foo(void)", "ns::foo"); |
| 34 |
DO_TEST("void ns::ns2::foo(void)", "ns::ns2::foo"); |
| 35 |
DO_TEST("void ns::v1::bar(void)", "ns::v1::bar"); |
| 36 |
DO_TEST("void `anonymous namespace'::bar(void)", "(anonymous namespace)::bar"); |
| 37 |
} |
| 38 |
|
| 39 |
TEST(PruneSymbolTests, BasicTemplates) { |
| 40 |
// https://godbolt.org/z/czWo9bdrn |
| 41 |
DO_TEST("void foo<int>(int const&)", "foo"); |
| 42 |
DO_TEST("void foo<int, double>(int const&, double const&)", "foo"); |
| 43 |
DO_TEST("void foo<S<int>>(S<int> const&)", "foo"); // llvm |
| 44 |
DO_TEST("void foo<S<int> >(S<int> const&)", "foo"); // gnutils |
| 45 |
DO_TEST("void foo<S<int, float>>(S<int, float> const&)", "foo"); |
| 46 |
DO_TEST("void foo<S<int, float> >(S<int, float> const&)", "foo"); |
| 47 |
DO_TEST("void foo<S<S<float>, S<int>>>(S<S<float>, S<int>> const&)", "foo"); |
| 48 |
DO_TEST("void foo<S<S<float>, S<int> > >(S<S<float>, S<int> > const&)", "foo"); |
| 49 |
|
| 50 |
DO_TEST("void foo<int>(int const &)", "foo"); |
| 51 |
DO_TEST("void foo<int,double>(int const &,double const &)", "foo"); |
| 52 |
DO_TEST("void foo<S<int> >(S<int> const &)", "foo"); |
| 53 |
DO_TEST("void foo<S<int,float> >(S<int,float> const &)", "foo"); |
| 54 |
DO_TEST("void foo<S<S<float>,S<int> > >(S<S<float>,S<int> > const &)", "foo"); |
| 55 |
} |
| 56 |
|
| 57 |
TEST(PruneSymbolTests, MemberFunctions) { |
| 58 |
// https://godbolt.org/z/re9zfzPq5 |
| 59 |
DO_TEST("S::S()", "S::S"); |
| 60 |
DO_TEST("S::~S()", "S::~S"); |
| 61 |
DO_TEST("S::foo()", "S::foo"); |
| 62 |
DO_TEST("S::bar() const", "S::bar"); |
| 63 |
DO_TEST("void S::bar() const", "S::bar"); |
| 64 |
|
| 65 |
DO_TEST("ns::SS<>::SS()", "ns::SS::SS"); |
| 66 |
DO_TEST("ns::SS<>::~SS()", "ns::SS::~SS"); |
| 67 |
DO_TEST("ns::SS<>::foo()", "ns::SS::foo"); |
| 68 |
DO_TEST("ns::SS<int, float>::SS()", "ns::SS::SS"); |
| 69 |
DO_TEST("ns::SS<int, float>::~SS()", "ns::SS::~SS"); |
| 70 |
DO_TEST("ns::SS<int, float>::foo()", "ns::SS::foo"); |
| 71 |
DO_TEST("ns::SS<ns::SS<int>, ns::SS<float>>::SS()", "ns::SS::SS"); |
| 72 |
DO_TEST("ns::SS<ns::SS<int>, ns::SS<float>>::~SS()", "ns::SS::~SS"); |
| 73 |
DO_TEST("ns::SS<ns::SS<int>, ns::SS<float>>::foo()", "ns::SS::foo"); |
| 74 |
|
| 75 |
DO_TEST("ns::SS<>::SS<>(void)", "ns::SS::SS"); |
| 76 |
DO_TEST("ns::SS<>::~SS<>(void)", "ns::SS::~SS"); |
| 77 |
DO_TEST("void ns::SS<>::foo(void)", "ns::SS::foo"); |
| 78 |
DO_TEST("ns::SS<int,float>::SS<int,float>(void)", "ns::SS::SS"); |
| 79 |
DO_TEST("ns::SS<int,float>::~SS<int,float>(void)", "ns::SS::~SS"); |
| 80 |
DO_TEST("void ns::SS<int,float>::foo(void)", "ns::SS::foo"); |
| 81 |
DO_TEST("ns::SS<ns::SS<int>,ns::SS<float> >::SS<ns::SS<int>,ns::SS<float> >(void)", "ns::SS::SS"); |
| 82 |
DO_TEST("ns::SS<ns::SS<int>,ns::SS<float> >::~SS<ns::SS<int>,ns::SS<float> >(void)", "ns::SS::~SS"); |
| 83 |
DO_TEST("void ns::SS<ns::SS<int>,ns::SS<float> >::foo(void)", "ns::SS::foo"); |
| 84 |
} |
| 85 |
|
| 86 |
TEST(PruneSymbolTests, TemplatedMemberFunctions) { |
| 87 |
// https://godbolt.org/z/dc3TEheK9 |
| 88 |
DO_TEST("ns::SS<>::SS<>()", "ns::SS::SS"); |
| 89 |
DO_TEST("void ns::SS<>::foo<>()", "ns::SS::foo"); |
| 90 |
DO_TEST("ns::SS<int, float>::SS<int, float>(int, float)", "ns::SS::SS"); |
| 91 |
DO_TEST("void ns::SS<int, float>::foo<int, float>()", "ns::SS::foo"); |
| 92 |
DO_TEST("ns::SS<ns::SS<int>, ns::SS<float>>::SS<ns::SS<int>, ns::SS<float>>(ns::SS<int>, ns::SS<float>)", "ns::SS::SS"); |
| 93 |
DO_TEST("void ns::SS<ns::SS<int>, ns::SS<float>>::foo<ns::SS<int>, ns::SS<float>>()", "ns::SS::foo"); |
| 94 |
|
| 95 |
DO_TEST("ns::SS<ns::SS<int>, ns::SS<float> >::SS<ns::SS<int>, ns::SS<float> >(ns::SS<int>, ns::SS<float>)", "ns::SS::SS"); |
| 96 |
DO_TEST("void ns::SS<ns::SS<int>, ns::SS<float> >::foo<ns::SS<int>, ns::SS<float> >()", "ns::SS::foo"); |
| 97 |
|
| 98 |
DO_TEST("ns::SS<>::SS<><>(void)", "ns::SS::SS"); |
| 99 |
DO_TEST("void ns::SS<>::foo<>(void)", "ns::SS::foo"); |
| 100 |
DO_TEST("ns::SS<int,float>::SS<int,float><int,float>(int,float)", "ns::SS::SS"); |
| 101 |
DO_TEST("void ns::SS<int,float>::foo<int,float>(void)", "ns::SS::foo"); |
| 102 |
DO_TEST("ns::SS<ns::SS<int>,ns::SS<float> >::SS<ns::SS<int>,ns::SS<float> ><ns::SS<int>,ns::SS<float> >(ns::SS<int>,ns::SS<float>)", "ns::SS::SS"); |
| 103 |
DO_TEST("void ns::SS<ns::SS<int>,ns::SS<float> >::foo<ns::SS<int>,ns::SS<float> >(void)", "ns::SS::foo"); |
| 104 |
} |
| 105 |
|
| 106 |
TEST(PruneSymbolTests, Decltype) { |
| 107 |
// https://godbolt.org/z/dc3TEheK9 |
| 108 |
DO_TEST("decltype(declval<int>() + declval<int>()) foo<int>(int)", "foo"); |
| 109 |
DO_TEST("decltype (((declval<int>)())+((declval<int>)())) foo<int>(int)", "foo"); |
| 110 |
DO_TEST("decltype(std::declval<int>() + std::declval<int>()) foo<int>(int)", "foo"); |
| 111 |
DO_TEST("int foo<int>(int)", "foo"); |
| 112 |
|
| 113 |
DO_TEST("decltype(declval<int>() + declval<int>()) bar<int>(decltype(declval<int>()))", "bar"); |
| 114 |
DO_TEST("decltype (((declval<int>)())+((declval<int>)())) bar<int>(decltype ((declval<int>)()))", "bar"); |
| 115 |
DO_TEST("decltype(std::declval<int>() + std::declval<int>()) bar<int>(decltype(std::declval<int>()))", "bar"); |
| 116 |
DO_TEST("int bar<int>(int &&)", "bar"); |
| 117 |
|
| 118 |
DO_TEST("decltype(declval<int>() < declval<int>()) baz<int>(int)", "baz"); |
| 119 |
DO_TEST("decltype (((declval<int>)())<((declval<int>)())) baz<int>(int)", "baz"); |
| 120 |
DO_TEST("decltype(std::declval<int>() < std::declval<int>()) baz<int>(int)", "baz"); |
| 121 |
DO_TEST("bool baz<int>(int)", "baz"); |
| 122 |
|
| 123 |
// https://godbolt.org/z/4M1xfW5rP |
| 124 |
DO_TEST("decltype(int{} + int{}) foo<int>(int)", "foo"); |
| 125 |
DO_TEST("decltype (int{}+int{}) foo<int>(int)", "foo"); |
| 126 |
DO_TEST("int foo<int>(int)", "foo"); |
| 127 |
} |
| 128 |
|
| 129 |
TEST(PruneSymbolTests, Operators) { |
| 130 |
// https://godbolt.org/z/qMKEKW656 |
| 131 |
DO_TEST("S<int>::operator*() const", "S::operator*"); |
| 132 |
DO_TEST("S<int>::operator+(S<int> const&) const", "S::operator+"); |
| 133 |
DO_TEST("S<int>::operator>(S<int> const&) const", "S::operator>"); |
| 134 |
DO_TEST("S<int>::operator<<(S<int> const&) const", "S::operator<<"); |
| 135 |
DO_TEST("S<int>::operator()() const", "S::operator()"); |
| 136 |
DO_TEST("S<int>::operator[](int) const", "S::operator[]"); |
| 137 |
|
| 138 |
DO_TEST("void S<int>::operator*(void)const", "S::operator*"); |
| 139 |
DO_TEST("void S<int>::operator+(S<int> const &)const", "S::operator+"); |
| 140 |
DO_TEST("void S<int>::operator>(S<int> const &)const", "S::operator>"); |
| 141 |
DO_TEST("void S<int>::operator<<(S<int> const &)const", "S::operator<<"); |
| 142 |
DO_TEST("void S<int>::operator()(void)const", "S::operator()"); |
| 143 |
DO_TEST("void S<int>::operator[](int)const", "S::operator[]"); |
| 144 |
|
| 145 |
// https://godbolt.org/z/E1bqKf8vv |
| 146 |
DO_TEST("operator*(S, S)", "operator*"); |
| 147 |
DO_TEST("operator\"\" _w(unsigned long long)", "operator\"\"_w"); |
| 148 |
DO_TEST("unsigned __int64 operator \"\" _w(unsigned __int64)", "operator\"\"_w"); |
| 149 |
} |
| 150 |
|
| 151 |
TEST(PruneSymbolTests, TemplatedOperators) { |
| 152 |
// https://godbolt.org/z/nfcrTfj7M |
| 153 |
DO_TEST("void operator+<S>(S, S)", "operator+"); |
| 154 |
// DO_TEST("void operator<<S>(S, S)", "operator<"); // TODO FAIL |
| 155 |
DO_TEST("void operator<<<S>(S, S)", "operator<<"); |
| 156 |
DO_TEST("void operator< <S>(S, S)", "operator<"); |
| 157 |
DO_TEST("void operator<< <S>(S, S)", "operator<<"); |
| 158 |
} |
| 159 |
|
| 160 |
TEST(PruneSymbolTests, OperatorNewDeleteCoAwait) { |
| 161 |
// https://godbolt.org/z/rq16K9sK3 |
| 162 |
DO_TEST("operator new(unsigned long)", "operator new"); |
| 163 |
DO_TEST("operator new[](unsigned long)", "operator new[]"); |
| 164 |
DO_TEST("operator delete(unsigned long)", "operator delete"); |
| 165 |
DO_TEST("operator delete[](unsigned long)", "operator delete[]"); |
| 166 |
DO_TEST("S::operator new(unsigned long)", "S::operator new"); |
| 167 |
DO_TEST("S::operator new[](unsigned long)", "S::operator new[]"); |
| 168 |
DO_TEST("S::operator delete(void*)", "S::operator delete"); |
| 169 |
DO_TEST("S::operator delete[](void*)", "S::operator delete[]"); |
| 170 |
|
| 171 |
DO_TEST("void * operator new(unsigned __int64)", "operator new"); |
| 172 |
DO_TEST("void * operator new[](unsigned __int64)", "operator new[]"); |
| 173 |
DO_TEST("void operator delete(void *)", "operator delete"); |
| 174 |
DO_TEST("void operator delete[](void *)", "operator delete[]"); |
| 175 |
DO_TEST("static void * S::operator new(unsigned __int64)", "S::operator new"); |
| 176 |
DO_TEST("static void * S::operator new[](unsigned __int64)", "S::operator new[]"); |
| 177 |
DO_TEST("static void S::operator delete(void *)", "S::operator delete"); |
| 178 |
DO_TEST("static void S::operator delete[](void *)", "S::operator delete[]"); |
| 179 |
|
| 180 |
// https://godbolt.org/z/a3GeKjh5a |
| 181 |
DO_TEST("operator co_await(A)", "operator co_await"); |
| 182 |
DO_TEST("B::operator co_await()", "B::operator co_await"); |
| 183 |
DO_TEST("void operator co_await(A)", "operator co_await"); |
| 184 |
DO_TEST("void B::operator co_await(void)", "B::operator co_await"); |
| 185 |
} |
| 186 |
|
| 187 |
TEST(PruneSymbolTests, NTTPs) { |
| 188 |
// https://godbolt.org/z/4aPavzsba |
| 189 |
DO_TEST("void foo<12, 20, 256, 1>()", "foo"); |
| 190 |
DO_TEST("void foo<true, false>()", "foo"); |
| 191 |
DO_TEST("void foo<(char)97, (char)98, (char)0, (char)39>()", "foo"); |
| 192 |
DO_TEST("void foo<0x1p-1, 0x1.8p+3f, 0x1.00aabbccp+10>()", "foo"); |
| 193 |
DO_TEST("void foo<&p>()", "foo"); |
| 194 |
DO_TEST("void foo<&main>()", "foo"); |
| 195 |
DO_TEST("void foo<&void foo<20, true>()>()", "foo"); |
| 196 |
|
| 197 |
DO_TEST("void foo<12,20,256,1>(void)", "foo"); |
| 198 |
DO_TEST("void foo<1,0>(void)", "foo"); |
| 199 |
DO_TEST("void foo<0.500000,12.000000,1026.667712>(void)", "foo"); |
| 200 |
DO_TEST("void foo<&int p>(void)", "foo"); |
| 201 |
DO_TEST("void foo<&void foo<20,1>(void)>(void)", "foo"); |
| 202 |
|
| 203 |
// https://godbolt.org/z/WEz836Yv7 |
| 204 |
DO_TEST("void foo<fixed_string<12ul>{\"foobar`'\\\"bar\"}>()", "foo"); |
| 205 |
DO_TEST("void foo<fixed_string<12>{char{102,111,111,98,97,114,96,39,34,98,97,114,0}}>(void)", "foo"); |
| 206 |
|
| 207 |
DO_TEST("void foo<fixed_string<12ul>{\"foobar`'\\\"bar\"}>()::test", "foo::test"); |
| 208 |
DO_TEST("void foo<fixed_string<13ul>{\"foobar`\\\"bar\\\"'\"}>()::test", "foo::test"); |
| 209 |
DO_TEST("void foo<fixed_string<13ul>{\"foobar`\\\"bar'\"}>()::test", "foo::test"); |
| 210 |
DO_TEST("void foo<fixed_string<13>{char{102,111,111,98,97,114,96,34,98,97,114,34,39,0}}>(void)::test", "foo::test"); |
| 211 |
|
| 212 |
// test that unterminated strings cause errors |
| 213 |
DO_TEST("void foo<bar(\"test\")>::baz", "foo::baz"); |
| 214 |
DO_TEST("void foo<bar(`test')>::baz", "foo::baz"); |
| 215 |
DO_TEST("void foo<bar(\"test)>::baz", "void foo<bar(\"test)>::baz"); |
| 216 |
DO_TEST("void foo<bar(`test)>::baz", "void foo<bar(`test)>::baz"); |
| 217 |
} |
| 218 |
|
| 219 |
TEST(PruneSymbolTests, OperatorNTTPs) { |
| 220 |
// https://godbolt.org/z/foY7WfGv3 |
| 221 |
DO_TEST("void foo<&S::operator<(S const&)>()", "foo"); |
| 222 |
DO_TEST("void foo<&S::operator>(S const&)>()", "foo"); |
| 223 |
DO_TEST("void foo<&S::operator>>(S const&)>()", "foo"); |
| 224 |
DO_TEST("void foo<&S::operator>>=(S const&)>()", "foo"); |
| 225 |
DO_TEST("void foo<&S::operator<=(S const&)>()", "foo"); |
| 226 |
DO_TEST("void foo<&S::operator<<=(S const&)>()", "foo"); |
| 227 |
// DO_TEST("void foo<&bool X<int, float>::operator<<int, float>(X<int, float> const&)>()", "foo"); // TODO: FAIL |
| 228 |
DO_TEST("void foo<&bool X<int, float>::operator><int, float>(X<int, float> const&)>()", "foo"); |
| 229 |
DO_TEST("void foo<&bool X<int, float>::operator>><int, float>(X<int, float> const&)>()", "foo"); |
| 230 |
DO_TEST("void foo<&bool X<int, float>::operator>>=<int, float>(X<int, float> const&)>()", "foo"); |
| 231 |
DO_TEST("void foo<&bool X<int, float>::operator<=<int, float>(X<int, float> const&)>()", "foo"); |
| 232 |
DO_TEST("void foo<&bool X<int, float>::operator<<=<int, float>(X<int, float> const&)>()", "foo"); |
| 233 |
|
| 234 |
DO_TEST("void foo<&bool S::operator<(S const &)>(void)", "foo"); |
| 235 |
DO_TEST("void foo<&bool S::operator>(S const &)>(void)", "foo"); |
| 236 |
DO_TEST("void foo<&bool S::operator>>(S const &)>(void)", "foo"); |
| 237 |
DO_TEST("void foo<&bool S::operator>>=(S const &)>(void)", "foo"); |
| 238 |
DO_TEST("void foo<&bool S::operator<=(S const &)>(void)", "foo"); |
| 239 |
DO_TEST("void foo<&bool S::operator<<=(S const &)>(void)", "foo"); |
| 240 |
// DO_TEST("void foo<&bool X<int,float>::operator<<int,float>(X<int,float> const &)>(void)", "foo"); // TODO: FAIL |
| 241 |
DO_TEST("void foo<&bool X<int,float>::operator><int,float>(X<int,float> const &)>(void)", "foo"); |
| 242 |
DO_TEST("void foo<&bool X<int,float>::operator>><int,float>(X<int,float> const &)>(void)", "foo"); |
| 243 |
DO_TEST("void foo<&bool X<int,float>::operator>>=<int,float>(X<int,float> const &)>(void)", "foo"); |
| 244 |
DO_TEST("void foo<&bool X<int,float>::operator<=<int,float>(X<int,float> const &)>(void)", "foo"); |
| 245 |
DO_TEST("void foo<&bool X<int,float>::operator<<=<int,float>(X<int,float> const &)>(void)", "foo"); |
| 246 |
|
| 247 |
DO_TEST("void foo<&S::operator>(S const&)>()::test", "foo::test"); |
| 248 |
DO_TEST("void foo<&S::operator>>(S const&)>()::test", "foo::test"); |
| 249 |
DO_TEST("void foo<&S::operator>>=(S const&)>()::test", "foo::test"); |
| 250 |
DO_TEST("void foo<&bool S::operator>(S const &)>(void)::test", "foo::test"); |
| 251 |
DO_TEST("void foo<&bool S::operator>>(S const &)>(void)::test", "foo::test"); |
| 252 |
DO_TEST("void foo<&bool S::operator>>=(S const &)>(void)::test", "foo::test"); |
| 253 |
DO_TEST("void foo<&bool X<int,float>::operator><int,float>(X<int,float> const &)>(void)::test", "foo::test"); |
| 254 |
DO_TEST("void foo<&bool X<int,float>::operator>><int,float>(X<int,float> const &)>(void)::test", "foo::test"); |
| 255 |
DO_TEST("void foo<&bool X<int,float>::operator>>=<int,float>(X<int,float> const &)>(void)::test", "foo::test"); |
| 256 |
DO_TEST("void foo<&S::operator>(S const&), bar>()::test", "foo::test"); |
| 257 |
DO_TEST("void foo<&S::operator>>(S const&), bar>()::test", "foo::test"); |
| 258 |
DO_TEST("void foo<&S::operator>>=(S const&), bar>()::test", "foo::test"); |
| 259 |
DO_TEST("void foo<&bool S::operator>(S const &)>(vo, barid)::test", "foo::test"); |
| 260 |
DO_TEST("void foo<&bool S::operator>>(S const &)>(vo, barid)::test", "foo::test"); |
| 261 |
DO_TEST("void foo<&bool S::operator>>=(S const &)>(vo, barid)::test", "foo::test"); |
| 262 |
DO_TEST("void foo<&bool X<int,float>::operator><int,float>(X<int,float> const &)>(vo, barid)::test", "foo::test"); |
| 263 |
DO_TEST("void foo<&bool X<int,float>::operator>><int,float>(X<int,float> const &)>(vo, barid)::test", "foo::test"); |
| 264 |
DO_TEST("void foo<&bool X<int,float>::operator>>=<int,float>(X<int,float> const &)>(vo, barid)::test", "foo::test"); |
| 265 |
|
| 266 |
// TODO: foo<&S::operator>>() isn't legal C++ but maybe it could appear in demangled output? |
| 267 |
} |
| 268 |
|
| 269 |
TEST(PruneSymbolTests, BasicLambdas) { |
| 270 |
// https://godbolt.org/z/5n83rGK8j |
| 271 |
DO_TEST("main::'lambda'()::operator()() const", "main::<lambda>::operator()"); |
| 272 |
DO_TEST("main::'lambda0'()::operator()() const", "main::<lambda0>::operator()"); |
| 273 |
DO_TEST("main::{lambda()#1}::operator()() const", "main::<lambda#1>::operator()"); |
| 274 |
DO_TEST("main::{lambda()#2}::operator()() const", "main::<lambda#2>::operator()"); |
| 275 |
DO_TEST("main::$_0::operator()() const", "main::$_0::operator()"); |
| 276 |
DO_TEST("main::$_1::operator()() const", "main::$_1::operator()"); |
| 277 |
DO_TEST("`int main(void)'::`2'::<lambda_1>::operator()(void)const", "`main'::`2'::<lambda_1>::operator()"); |
| 278 |
DO_TEST("`int main(void)'::`2'::<lambda_2>::operator()(void)const", "`main'::`2'::<lambda_2>::operator()"); |
| 279 |
} |
| 280 |
|
| 281 |
TEST(PruneSymbolTests, TemplatedLambdas) { |
| 282 |
// https://godbolt.org/z/GGEWfE144 |
| 283 |
DO_TEST("auto main::'lambda'<typename $T>($T)::operator()<int>($T) const", "main::<lambda>::operator()"); |
| 284 |
DO_TEST("auto main::{lambda<typename $T0>($T0)#1}::operator()<int>(int) const", "main::<lambda#1>::operator()"); |
| 285 |
// DO_TEST("", ""); // TODO: llvm-symbolizer can't handle currently |
| 286 |
DO_TEST("auto `int main(void)'::`2'::<lambda_1>::operator()<int>(int)const", "`main'::`2'::<lambda_1>::operator()"); |
| 287 |
} |
| 288 |
|
| 289 |
TEST(PruneSymbolTests, NestedLambdas) { |
| 290 |
// https://godbolt.org/z/s4GseqrGK |
| 291 |
DO_TEST("main::'lambda'()::operator()() const", "main::<lambda>::operator()"); |
| 292 |
DO_TEST("main::'lambda'()::operator()() const::'lambda'()::operator()() const", "main::<lambda>::operator()::<lambda>::operator()"); |
| 293 |
DO_TEST("main::{lambda()#1}::operator()() const", "main::<lambda#1>::operator()"); |
| 294 |
DO_TEST("main::{lambda()#1}::operator()() const::{lambda()#1}::operator()() const", "main::<lambda#1>::operator()::<lambda#1>::operator()"); |
| 295 |
DO_TEST("main::$_0::operator()() const", "main::$_0::operator()"); |
| 296 |
DO_TEST("main::$_0::operator()() const::'lambda'()::operator()() const", "main::$_0::operator()::<lambda>::operator()"); |
| 297 |
DO_TEST("`int main(void)'::`2'::<lambda_1>::operator()(void)const", "`main'::`2'::<lambda_1>::operator()"); |
| 298 |
DO_TEST("``int main(void)'::`2'::<lambda_1>::operator()(void)const '::`2'::<lambda_1>::operator()(void)const", "``main'::`2'::<lambda_1>::operator()'::`2'::<lambda_1>::operator()"); |
| 299 |
// https://godbolt.org/z/fnvW63819 |
| 300 |
DO_TEST("auto main::'lambda'<typename $T>($T)::operator()<int>($T) const", "main::<lambda>::operator()"); |
| 301 |
DO_TEST("auto auto main::'lambda'<typename $T>($T)::operator()<int>($T) const::'lambda'<typename $T0>($T)::operator()<int>($T) const", "main::<lambda>::operator()::<lambda>::operator()"); |
| 302 |
DO_TEST("auto main::{lambda<typename $T0>($T0)#1}::operator()<int>(int) const", "main::<lambda#1>::operator()"); |
| 303 |
DO_TEST("auto main::{lambda<typename $T0>($T0)#1}::operator()<int>(int) const::{lambda<typename $T0>($T0)#1}::operator()<int>(int) const", "main::<lambda#1>::operator()::<lambda#1>::operator()"); |
| 304 |
// TODO: LLVM |
| 305 |
// TODO: LLVM |
| 306 |
DO_TEST("auto `int main(void)'::`2'::<lambda_1>::operator()<int>(int)const", "`main'::`2'::<lambda_1>::operator()"); |
| 307 |
DO_TEST("auto `auto `int main(void)'::`2'::<lambda_1>::operator()<int>(int)const '::`2'::<lambda_1>::operator()<int>(int)const", "``main'::`2'::<lambda_1>::operator()'::`2'::<lambda_1>::operator()"); |
| 308 |
} |
| 309 |
|
| 310 |
TEST(PruneSymbolTests, LambdaTemplateArgs) { |
| 311 |
// https://godbolt.org/z/9f53KezPE |
| 312 |
DO_TEST("S<main::'lambda'()>::foo()", "S::foo"); |
| 313 |
DO_TEST("SS<main::'lambda0'(){}>::foo()", "SS::foo"); |
| 314 |
DO_TEST("S<main::{lambda()#1}>::foo()", "S::foo"); |
| 315 |
DO_TEST("SS<main::{lambda()#2}{}>::foo()", "SS::foo"); |
| 316 |
DO_TEST("void S<`int main(void)'::`2'::<lambda_1_> >::foo(void)", "S::foo"); |
| 317 |
DO_TEST("void SS<`int main(void)'::`2'::<lambda_2_>{}>::foo(void)", "SS::foo"); |
| 318 |
} |
| 319 |
|
| 320 |
TEST(PruneSymbolTests, LambdasInTemplates) { |
| 321 |
// https://godbolt.org/z/qKv8xz7Mv |
| 322 |
DO_TEST("S<int>::foo()::'lambda'()::operator()() const", "S::foo::<lambda>::operator()"); |
| 323 |
DO_TEST("S<int>::foo()::{lambda()#1}::operator()() const", "S::foo::<lambda#1>::operator()"); |
| 324 |
DO_TEST("`void S<int>::foo(void)'::`2'::<lambda_1>::operator()(void)const", "`S::foo'::`2'::<lambda_1>::operator()"); |
| 325 |
} |
| 326 |
|
| 327 |
TEST(PruneSymbolTests, LocalTypes) { |
| 328 |
// https://godbolt.org/z/51fbhMTMe |
| 329 |
DO_TEST("foo()::S::bar()", "foo::S::bar"); |
| 330 |
DO_TEST("void `void foo(void)'::`2'::S::bar(void)", "`foo'::`2'::S::bar"); |
| 331 |
|
| 332 |
DO_TEST("foo()::S::bar()::'lambda'()::operator()() const::V::boo()", "foo::S::bar::<lambda>::operator()::V::boo"); |
| 333 |
DO_TEST("foo()::S::bar()::{lambda()#1}::operator()() const::V::boo()", "foo::S::bar::<lambda#1>::operator()::V::boo"); |
| 334 |
DO_TEST("void ``void `void foo(void)'::`2'::S::bar(void)'::`2'::<lambda_1>::operator()(void)const '::`2'::V::boo(void)", "```foo'::`2'::S::bar'::`2'::<lambda_1>::operator()'::`2'::V::boo"); |
| 335 |
|
| 336 |
// https://godbolt.org/z/hGaW8j9r3 |
| 337 |
DO_TEST("auto auto A<SS>::foo<SS>()::'lambda'(auto)::operator()<int>(auto) const", "A::foo::<lambda>::operator()"); |
| 338 |
DO_TEST("auto auto A<SS>::foo<SS>()::'lambda'(auto)::operator()<int>(auto) const::S::foo()", "A::foo::<lambda>::operator()::S::foo"); |
| 339 |
DO_TEST("auto A<SS>::foo<SS>()::{lambda(auto:1)#1}::operator()<int>(int) const", "A::foo::<lambda#1>::operator()"); |
| 340 |
DO_TEST("A<SS>::foo<SS>()::{lambda(auto:1)#1}::operator()<int>(int) const::S::foo()", "A::foo::<lambda#1>::operator()::S::foo"); |
| 341 |
DO_TEST("auto `auto A<SS>::foo<SS>(void)'::`2'::<lambda_1>::operator()<int>(int)const", "`A::foo'::`2'::<lambda_1>::operator()"); |
| 342 |
DO_TEST("void `auto `auto A<SS>::foo<SS>(void)'::`2'::<lambda_1>::operator()<int>(int)const '::`2'::S::foo(void)", "``A::foo'::`2'::<lambda_1>::operator()'::`2'::S::foo"); |
| 343 |
} |
| 344 |
|
| 345 |
TEST(PruneSymbolTests, QualifiersAndAttributes) { |
| 346 |
// https://godbolt.org/z/rG5Ed5qed |
| 347 |
DO_TEST("S::foo() const volatile &&", "S::foo"); |
| 348 |
DO_TEST("int const && S::foo(void)const volatile &&", "S::foo"); |
| 349 |
|
| 350 |
DO_TEST("auto main::'lambda'(auto const volatile&&)::operator()<'lambda'(auto const volatile&&)>(this auto const volatile&&)", "main::<lambda>::operator()"); |
| 351 |
DO_TEST("auto main::{lambda(auto:1 const volatile&&)#1}::operator()<{lambda(auto:1 const volatile&&)#1}>(this {lambda(auto:1 const volatile&&)#1} const volatile&&)", "main::<lambda#1>::operator()"); |
| 352 |
DO_TEST("static auto `int main(void)'::`2'::<lambda_1>::operator()<`int main(void)'::`2'::<lambda_1> >(UNKNOWN,`int main(void)'::`2'::<lambda_1> const volatile &&)", "`main'::`2'::<lambda_1>::operator()"); |
| 353 |
} |
| 354 |
|
| 355 |
TEST(PruneSymbolTests, ConversionOperator) { |
| 356 |
// https://godbolt.org/z/v8hc1vb9P |
| 357 |
DO_TEST("S::operator int()", "S::operator int"); |
| 358 |
DO_TEST("S::operator void*()", "S::operator void*"); |
| 359 |
DO_TEST("S::operator std::nullptr_t()", "S::operator std::nullptr_t"); |
| 360 |
DO_TEST("S::operator X<int>()", "S::operator X"); |
| 361 |
DO_TEST("S::operator ns::Z()", "S::operator ns::Z"); |
| 362 |
DO_TEST("S::operator ns::Y<int><int>()", "S::operator ns::Y"); |
| 363 |
DO_TEST("S::operator main::'lambda'()<main::'lambda'()>()", "S::operator main::<lambda>"); |
| 364 |
DO_TEST("S::operator main::'lambda'()<main::'lambda'()>()::'lambda'()::operator()() const", "S::operator main::<lambda>::<lambda>::operator()"); |
| 365 |
|
| 366 |
DO_TEST("S::operator decltype(nullptr)()", "S::operator decltype(nullptr)"); |
| 367 |
DO_TEST("S::operator main::{lambda()#1}<main::{lambda()#1}>()", "S::operator main::<lambda#1>"); |
| 368 |
DO_TEST("S::operator main::{lambda()#1}<main::{lambda()#1}>()::{lambda()#1}::operator()() const", "S::operator main::<lambda#1>::<lambda#1>::operator()"); |
| 369 |
|
| 370 |
DO_TEST("S::operator main::$_0<main::$_0>()", "S::operator main::$_0"); |
| 371 |
DO_TEST("S::operator main::$_0<main::$_0>()::'lambda'()::operator()() const", "S::operator main::$_0::<lambda>::operator()"); |
| 372 |
|
| 373 |
// https://godbolt.org/z/4qqP9reqr |
| 374 |
DO_TEST("S::operator S::operator*()::X<S::operator*()::X>()", "S::operator S::operator*::X"); |
| 375 |
// DO_TEST("S::operator<`S::operator*(void)'::`2'::X> `S::operator*(void)'::`2'::X(void)", "S::operator `S::operator*'::`2'::X"); // TODO FAIL |
| 376 |
|
| 377 |
DO_TEST("S::operator T&()", "S::operator T&"); |
| 378 |
DO_TEST("S::operator T&&()", "S::operator T&&"); |
| 379 |
|
| 380 |
// https://godbolt.org/z/PTe1xh6Go |
| 381 |
DO_TEST("S::operator int X::*()", "S::operator int X::*"); |
| 382 |
DO_TEST("S::operator int Y<int>::*()", "S::operator int Y::*"); |
| 383 |
|
| 384 |
DO_TEST("S::operator std::vector<int> X::*()", "S::operator std::vector X::*"); |
| 385 |
DO_TEST("S::operator std::vector<int> Y<int>::*()", "S::operator std::vector Y::*"); |
| 386 |
DO_TEST("S::operator std::vector<int> ns<X>::ns::X::*()", "S::operator std::vector ns::ns::X::*"); |
| 387 |
DO_TEST("S::operator std::vector<int> ns<X>::ns::Y<int>::*()", "S::operator std::vector ns::ns::Y::*"); |
| 388 |
DO_TEST("S::operator std::vector<int> ns<X>::ns::X::*()::test", "S::operator std::vector ns::ns::X::*::test"); |
| 389 |
DO_TEST("S::operator std::vector<int> ns<X>::ns::Y<int>::*()::test", "S::operator std::vector ns::ns::Y::*::test"); |
| 390 |
} |
| 391 |
|
| 392 |
TEST(PruneSymbolTests, DeducedConversionOperator) { |
| 393 |
// https://godbolt.org/z/9rzdKvGh7 |
| 394 |
DO_TEST("S<float>::operator auto()", "S::operator auto"); |
| 395 |
DO_TEST("S<float>::operator auto()", "S::operator auto"); |
| 396 |
DO_TEST("S<float>::operator decltype(auto)()", "S::operator decltype(auto)"); |
| 397 |
|
| 398 |
// DO_TEST("S<float>::operator (void)", "S::operator"); // Microsoft's lovely demangling |
| 399 |
// DO_TEST("S<float>::operator (void)::test", "S::operator::test"); |
| 400 |
DO_TEST("S<float>::operator float(void)", "S::operator float"); |
| 401 |
} |
| 402 |
|
| 403 |
TEST(PruneSymbolTests, FunctionPointers) { |
| 404 |
// https://godbolt.org/z/TWfa4f6Kc |
| 405 |
DO_TEST("void (*foo<int>())(int, double)", "foo"); |
| 406 |
DO_TEST("void (**foo<int>())(int, double)", "foo"); |
| 407 |
DO_TEST("void (&baz<int>())(int, double)", "baz"); |
| 408 |
DO_TEST("void (** (**bar<int>())(int, double))(int, double)", "bar"); |
| 409 |
DO_TEST("void (**(**bar<int>())(int, double))(int, double)", "bar"); |
| 410 |
DO_TEST("void (__cdecl** foo<int>(void))(int,double)", "foo"); |
| 411 |
DO_TEST("void (__cdecl** (__cdecl** bar<int>(void))(int,double))(int,double)", "bar"); |
| 412 |
DO_TEST("void (__cdecl&baz<int>(void))(int,double)", "baz"); |
| 413 |
} |
| 414 |
|
| 415 |
TEST(PruneSymbolTests, UnnamedTypes) { |
| 416 |
// https://godbolt.org/z/jx8GnrW4v |
| 417 |
DO_TEST("main::'unnamed'::foo()", "main::<unnamed>::foo"); |
| 418 |
DO_TEST("main::{unnamed type#1}::foo()", "main::<unnamed type#1>::foo"); |
| 419 |
} |
| 420 |
|
| 421 |
TEST(PruneSymbolTests, TemplateHeavySymbols) { |
| 422 |
// https://godbolt.org/z/z1nrMsYfs |
| 423 |
DO_TEST("__find_if<__gnu_cxx::__normal_iterator<int*, std::vector<int> >, __gnu_cxx::__ops::_Iter_pred<main()::<lambda(auto:19)> > >", "__find_if"); |
| 424 |
// DO_TEST("operator()<__gnu_cxx::__normal_iterator<int*, std::vector<int> >, __gnu_cxx::__normal_iterator<int*, std::vector<int> >, std::identity, main()::<lambda(auto:18)> >", "ns::SS::SS"); |
| 425 |
DO_TEST("std::__1::find_if[abi:ne200100]<std::__1::__wrap_iter<int*>, main::$_1>(std::__1::__wrap_iter<int*>, std::__1::__wrap_iter<int*>, main::$_1)", "std::__1::find_if"); |
| 426 |
DO_TEST("std::__1::_IfImpl<borrowed_range<T>>::_Select<decltype(std::__1::ranges::__cpo::begin(std::declval<T&>())), std::__1::ranges::dangling> std::__1::ranges::__find_if::operator()[abi:ne200100]<std::__1::vector<int, std::__1::allocator<int>>&, std::__1::identity, main::$_0>(T&&, main::$_0, T0) const", "std::__1::ranges::__find_if::operator()"); |
| 427 |
DO_TEST("std::__1::ranges::__find_if_impl[abi:ne200100]<std::__1::__wrap_iter<int*>, std::__1::__wrap_iter<int*>, main::$_0, std::__1::identity>(std::__1::__wrap_iter<int*>, std::__1::__wrap_iter<int*>, main::$_0&, std::__1::identity&)", "std::__1::ranges::__find_if_impl"); |
| 428 |
} |
| 429 |
|
| 430 |
TEST(PruneSymbolTests, StorageClasses) { |
| 431 |
// https://godbolt.org/z/xPYKW8Pz5 |
| 432 |
DO_TEST("static void S::foo(void)", "S::foo"); |
| 433 |
} |
| 434 |
|
| 435 |
TEST(PruneSymbolTests, Noexcept) { |
| 436 |
// https://godbolt.org/z/xjsM67s17 |
| 437 |
DO_TEST("void foo<X>(X (*)() noexcept(X::n))", "foo"); |
| 438 |
} |
| 439 |
|
| 440 |
TEST(PruneSymbolTests, MiscNesting) { |
| 441 |
// https://godbolt.org/z/5Gj99ernr |
| 442 |
DO_TEST("void use1<5>(Wrapper<(5)<(5)>)", "use1"); |
| 443 |
DO_TEST("void use2<5>(Wrapper<((5)>(5))>)", "use2"); |
| 444 |
DO_TEST("void use1<5>(Wrapper<5 < 5>)", "use1"); |
| 445 |
DO_TEST("void use2<5>(Wrapper<(5 > 5)>)", "use2"); |
| 446 |
DO_TEST("void use1<5>(Wrapper<0>)", "use1"); |
| 447 |
DO_TEST("void use2<5>(Wrapper<0>)", "use2"); |
| 448 |
} |
| 449 |
|
| 450 |
TEST(PruneSymbolTests, Misc) { |
| 451 |
// https://godbolt.org/z/cqfW7MK57 |
| 452 |
DO_TEST("foo(...)", "foo"); |
| 453 |
} |
| 454 |
|
| 455 |
TEST(PruneSymbolTests, Extra) { |
| 456 |
DO_TEST("operator<<(std::ostream&, Foo const&)", "operator<<"); |
| 457 |
DO_TEST("std::ostream & operator<<(std::ostream &, Foo const &)", "operator<<"); |
| 458 |
DO_TEST("Foo::operator+=(int)", "Foo::operator+="); |
| 459 |
DO_TEST("Foo::operator+=(int) const", "Foo::operator+="); |
| 460 |
DO_TEST("Foo::operator bool() const noexcept", "Foo::operator bool"); |
| 461 |
DO_TEST("Foo::operator int() const", "Foo::operator int"); |
| 462 |
|
| 463 |
DO_TEST("Foo::bar() const", "Foo::bar"); |
| 464 |
DO_TEST("Foo::bar() volatile", "Foo::bar"); |
| 465 |
DO_TEST("Foo::bar() const &", "Foo::bar"); |
| 466 |
DO_TEST("Foo::bar() &&", "Foo::bar"); |
| 467 |
DO_TEST("Foo::bar() const noexcept", "Foo::bar"); |
| 468 |
DO_TEST("Foo::bar() const & noexcept", "Foo::bar"); |
| 469 |
|
| 470 |
DO_TEST("void foo<3>()", "foo"); |
| 471 |
DO_TEST("void foo<'a'>()", "foo"); |
| 472 |
DO_TEST("void foo<true>()", "foo"); |
| 473 |
DO_TEST("void foo<&Foo::bar>()", "foo"); |
| 474 |
DO_TEST("void foo<(int)5>()", "foo"); |
| 475 |
|
| 476 |
DO_TEST("main::{lambda()#1}::operator()() const", "main::<lambda#1>::operator()"); |
| 477 |
DO_TEST("main::$_0::operator()() const", "main::$_0::operator()"); |
| 478 |
|
| 479 |
DO_TEST("virtual void __cdecl ns::Foo::bar(int) const", "ns::Foo::bar"); |
| 480 |
DO_TEST("static int __cdecl ns::Foo::baz(char)", "ns::Foo::baz"); |
| 481 |
DO_TEST("__thiscall Foo::Foo(void)", "Foo::Foo"); |
| 482 |
DO_TEST("virtual __thiscall Foo::~Foo(void)", "Foo::~Foo"); |
| 483 |
|
| 484 |
DO_TEST("virtual thunk to Foo::bar()", "Foo::bar"); |
| 485 |
|
| 486 |
DO_TEST("void foo<std::vector<int,std::allocator<int>>>(std::vector<int,std::allocator<int>> const&)", "foo"); |
| 487 |
DO_TEST("void foo<std::basic_string<char>>(std::basic_string<char> const&)", "foo"); |
| 488 |
} |
| 489 |
|
| 490 |
TEST(PruneSymbolTests, RegressionTests) { |
| 491 |
// Symbols I've observed not pruning correctly |
| 492 |
DO_TEST("void (* const&std::_Any_data::_M_access<void (*)(cpptrace::v1::log_level, char const*)>() const)(cpptrace::v1::log_level, char const*)", "std::_Any_data::_M_access"); |
| 493 |
DO_TEST("void (* const*std::__addressof<void (* const)(cpptrace::v1::log_level, char const*)>(void (* const&)(cpptrace::v1::log_level, char const*)))(cpptrace::v1::log_level, char const*)", "std::__addressof"); |
| 494 |
DO_TEST("void (* const&std::forward<void (* const&)(cpptrace::v1::log_level, char const*)>(std::remove_reference<void (* const&)(cpptrace::v1::log_level, char const*)>::type&))(cpptrace::v1::log_level, char const*)", "std::forward"); |
| 495 |
DO_TEST("fmt::v10::detail::parse_format_specs<char>(char const*, char const*, fmt::v10::detail::dynamic_format_specs<char>&, fmt::v10::basic_format_parse_context<char>&, fmt::v10::detail::type)::{unnamed type#1}::operator()(fmt::v10::detail::state, bool)", "fmt::v10::detail::parse_format_specs::<unnamed type#1>::operator()"); |
| 496 |
DO_TEST("fmt::v10::detail::parse_format_specs<char>(char const*, char const*, fmt::v10::detail::dynamic_format_specs<char>&, fmt::v10::basic_format_parse_context<char>&, fmt::v10::detail::type)::{unnamed type#2}::operator()(fmt::v10::presentation_type, int)", "fmt::v10::detail::parse_format_specs::<unnamed type#2>::operator()"); |
| 497 |
} |
| 498 |
|
| 499 |
} |