From 49e0099abce54b50fee77a75b90ddc73567f5692 Mon Sep 17 00:00:00 2001 From: Chris Mihelich Date: Wed, 5 Jun 2024 12:44:15 -0700 Subject: Demangle ti... and te... expressions (typeid). PiperOrigin-RevId: 640616282 Change-Id: I2aa94673283d89458886f0634adec87bbf0e57de --- absl/debugging/internal/demangle.cc | 14 +++++++++++++ absl/debugging/internal/demangle_test.cc | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) (limited to 'absl/debugging/internal') diff --git a/absl/debugging/internal/demangle.cc b/absl/debugging/internal/demangle.cc index 787edcee..1d14ac6c 100644 --- a/absl/debugging/internal/demangle.cc +++ b/absl/debugging/internal/demangle.cc @@ -1995,6 +1995,8 @@ static bool ParseBracedExpression(State *state) { // ::= sc // ::= cc // ::= rc +// ::= ti +// ::= te // ::= st // ::= at // ::= az @@ -2119,6 +2121,18 @@ static bool ParseExpression(State *state) { } state->parse_state = copy; + // typeid(type) + if (ParseTwoCharToken(state, "ti") && ParseType(state)) { + return true; + } + state->parse_state = copy; + + // typeid(expression) + if (ParseTwoCharToken(state, "te") && ParseExpression(state)) { + return true; + } + state->parse_state = copy; + // sizeof type if (ParseTwoCharToken(state, "st") && ParseType(state)) { return true; diff --git a/absl/debugging/internal/demangle_test.cc b/absl/debugging/internal/demangle_test.cc index 5dc2d03b..9050e96e 100644 --- a/absl/debugging/internal/demangle_test.cc +++ b/absl/debugging/internal/demangle_test.cc @@ -1098,6 +1098,40 @@ TEST(Demangle, ReinterpretCast) { EXPECT_STREQ("f<>()", tmp); } +TEST(Demangle, TypeidType) { + char tmp[80]; + + // Source: + // + // #include + // + // template decltype(typeid(T).name()) f(T) { return nullptr; } + // template decltype(typeid(int).name()) f(int); + // + // Full LLVM demangling of the instantiation of f: + // + // decltype(typeid (int).name()) f(int) + EXPECT_TRUE(Demangle("_Z1fIiEDTcldttiT_4nameEES0_", tmp, sizeof(tmp))); + EXPECT_STREQ("f<>()", tmp); +} + +TEST(Demangle, TypeidExpression) { + char tmp[80]; + + // Source: + // + // #include + // + // template decltype(typeid(T{}).name()) f(T) { return nullptr; } + // template decltype(typeid(int{}).name()) f(int); + // + // Full LLVM demangling of the instantiation of f: + // + // decltype(typeid (int{}).name()) f(int) + EXPECT_TRUE(Demangle("_Z1fIiEDTcldttetlT_E4nameEES0_", tmp, sizeof(tmp))); + EXPECT_STREQ("f<>()", tmp); +} + TEST(Demangle, AlignofType) { char tmp[80]; -- cgit v1.2.3