diff options
author | Chris Mihelich <cmihelic@google.com> | 2024-06-05 15:18:52 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-06-05 15:20:33 -0700 |
commit | fe43a4cb564ef6dc731d52e8246c7ecbd1fd6bf5 (patch) | |
tree | 3bff32462bd48bc9fe2c34d5c85fcdcf10f5d489 | |
parent | aad792d4cf8cb64d6edec7a3399a4444639bddd2 (diff) | |
download | abseil-fe43a4cb564ef6dc731d52e8246c7ecbd1fd6bf5.tar.gz abseil-fe43a4cb564ef6dc731d52e8246c7ecbd1fd6bf5.tar.bz2 abseil-fe43a4cb564ef6dc731d52e8246c7ecbd1fd6bf5.zip |
Demangle preincrement and predecrement, pp_... and mm_....
PiperOrigin-RevId: 640666300
Change-Id: I1dae13f515de5fae3768a54c3808b80083ed63f8
-rw-r--r-- | absl/debugging/internal/demangle.cc | 11 | ||||
-rw-r--r-- | absl/debugging/internal/demangle_test.cc | 60 |
2 files changed, 71 insertions, 0 deletions
diff --git a/absl/debugging/internal/demangle.cc b/absl/debugging/internal/demangle.cc index 8887ee47..7fe8439b 100644 --- a/absl/debugging/internal/demangle.cc +++ b/absl/debugging/internal/demangle.cc @@ -1984,6 +1984,8 @@ static bool ParseBracedExpression(State *state) { // <expression> ::= <1-ary operator-name> <expression> // ::= <2-ary operator-name> <expression> <expression> // ::= <3-ary operator-name> <expression> <expression> <expression> +// ::= pp_ <expression> # ++e; pp <expression> is e++ +// ::= mm_ <expression> # --e; mm <expression> is e-- // ::= cl <expression>+ E // ::= cp <simple-id> <expression>* E # Clang-specific. // ::= so <type> <expression> [<number>] <union-selector>* [p] E @@ -2037,6 +2039,15 @@ static bool ParseExpression(State *state) { } state->parse_state = copy; + // Preincrement and predecrement. Postincrement and postdecrement are handled + // by the operator-name logic later on. + if ((ParseThreeCharToken(state, "pp_") || + ParseThreeCharToken(state, "mm_")) && + ParseExpression(state)) { + return true; + } + state->parse_state = copy; + // Clang-specific "cp <simple-id> <expression>* E" // https://clang.llvm.org/doxygen/ItaniumMangle_8cpp_source.html#l04338 if (ParseTwoCharToken(state, "cp") && ParseSimpleId(state) && diff --git a/absl/debugging/internal/demangle_test.cc b/absl/debugging/internal/demangle_test.cc index 85a20f0a..7d455651 100644 --- a/absl/debugging/internal/demangle_test.cc +++ b/absl/debugging/internal/demangle_test.cc @@ -768,6 +768,66 @@ TEST(Demangle, SubobjectAddresses) { EXPECT_STREQ("f<>()", tmp); } +TEST(Demangle, Preincrement) { + char tmp[80]; + + // Source: + // + // template <class T> auto f(T t) -> decltype(T{++t}) { return t; } + // template auto f<int>(int t) -> decltype(int{++t}); + // + // Full LLVM demangling of the instantiation of f: + // + // decltype(int{++fp}) f<int>(int) + EXPECT_TRUE(Demangle("_Z1fIiEDTtlT_pp_fp_EES0_", tmp, sizeof(tmp))); + EXPECT_STREQ("f<>()", tmp); +} + +TEST(Demangle, Postincrement) { + char tmp[80]; + + // Source: + // + // template <class T> auto f(T t) -> decltype(T{t++}) { return t; } + // template auto f<int>(int t) -> decltype(int{t++}); + // + // Full LLVM demangling of the instantiation of f: + // + // decltype(int{fp++}) f<int>(int) + EXPECT_TRUE(Demangle("_Z1fIiEDTtlT_ppfp_EES0_", tmp, sizeof(tmp))); + EXPECT_STREQ("f<>()", tmp); +} + +TEST(Demangle, Predecrement) { + char tmp[80]; + + // Source: + // + // template <class T> auto f(T t) -> decltype(T{--t}) { return t; } + // template auto f<int>(int t) -> decltype(int{--t}); + // + // Full LLVM demangling of the instantiation of f: + // + // decltype(int{--fp}) f<int>(int) + EXPECT_TRUE(Demangle("_Z1fIiEDTtlT_mm_fp_EES0_", tmp, sizeof(tmp))); + EXPECT_STREQ("f<>()", tmp); +} + +TEST(Demangle, Postdecrement) { + char tmp[80]; + + // Source: + // + // template <class T> auto f(T t) -> decltype(T{t--}) { return t; } + // template auto f<int>(int t) -> decltype(int{t--}); + // + // Full LLVM demangling of the instantiation of f: + // + // decltype(int{fp--}) f<int>(int) + EXPECT_TRUE(Demangle("_Z1fIiEDTtlT_mmfp_EES0_", tmp, sizeof(tmp))); + EXPECT_STREQ("f<>()", tmp); +} + TEST(Demangle, UnaryFoldExpressions) { char tmp[80]; |