diff options
author | Chris Mihelich <cmihelic@google.com> | 2024-05-29 04:12:22 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-05-29 04:13:24 -0700 |
commit | 1f5a9cdc4354faccda4227235ea1acb77d9a4466 (patch) | |
tree | d1c4479d55d5bbf773e8f231c5ec2b85c376c7c6 /absl/debugging | |
parent | 457fdbf960b541743de0a08956b20f2421073284 (diff) | |
download | abseil-1f5a9cdc4354faccda4227235ea1acb77d9a4466.tar.gz abseil-1f5a9cdc4354faccda4227235ea1acb77d9a4466.tar.bz2 abseil-1f5a9cdc4354faccda4227235ea1acb77d9a4466.zip |
Demangle static_cast and friends.
PiperOrigin-RevId: 638232699
Change-Id: I134905927ba72eaa5eaf821bb5535942746a3672
Diffstat (limited to 'absl/debugging')
-rw-r--r-- | absl/debugging/internal/demangle.cc | 13 | ||||
-rw-r--r-- | absl/debugging/internal/demangle_test.cc | 70 |
2 files changed, 83 insertions, 0 deletions
diff --git a/absl/debugging/internal/demangle.cc b/absl/debugging/internal/demangle.cc index 40a55c7d..f04e4dbc 100644 --- a/absl/debugging/internal/demangle.cc +++ b/absl/debugging/internal/demangle.cc @@ -1877,6 +1877,10 @@ static bool ParseBracedExpression(State *state) { // ::= cv <type> <expression> # type (expression) // ::= cv <type> _ <expression>* E # type (expr-list) // ::= tl <type> <braced-expression>* E +// ::= dc <type> <expression> +// ::= sc <type> <expression> +// ::= cc <type> <expression> +// ::= rc <type> <expression> // ::= st <type> // ::= <template-param> // ::= <function-param> @@ -1942,6 +1946,15 @@ static bool ParseExpression(State *state) { } state->parse_state = copy; + // dynamic_cast, static_cast, const_cast, reinterpret_cast. + // + // <expression> ::= (dc | sc | cc | rc) <type> <expression> + if (ParseCharClass(state, "dscr") && ParseOneCharToken(state, 'c') && + ParseType(state) && ParseExpression(state)) { + return true; + } + state->parse_state = copy; + // Parse the conversion expressions jointly to avoid re-parsing the <type> in // their common prefix. Parsed as: // <expression> ::= cv <type> <conversion-args> diff --git a/absl/debugging/internal/demangle_test.cc b/absl/debugging/internal/demangle_test.cc index 96051d31..2c582415 100644 --- a/absl/debugging/internal/demangle_test.cc +++ b/absl/debugging/internal/demangle_test.cc @@ -706,6 +706,76 @@ TEST(Demangle, ReferenceQualifiedFunctionTypes) { EXPECT_STREQ("f()", tmp); } +TEST(Demangle, DynamicCast) { + char tmp[80]; + + // Source: + // + // template <class T> auto f(T* p) -> decltype(dynamic_cast<const T*>(p)) { + // return p; + // } + // struct S {}; + // void g(S* p) { f(p); } + // + // Full LLVM demangling of the instantiation of f: + // + // decltype(dynamic_cast<S const*>(fp)) f<S>(S*) + EXPECT_TRUE(Demangle("_Z1fI1SEDTdcPKT_fp_EPS1_", tmp, sizeof(tmp))); + EXPECT_STREQ("f<>()", tmp); +} + +TEST(Demangle, StaticCast) { + char tmp[80]; + + // Source: + // + // template <class T> auto f(T* p) -> decltype(static_cast<const T*>(p)) { + // return p; + // } + // void g(int* p) { f(p); } + // + // Full LLVM demangling of the instantiation of f: + // + // decltype(static_cast<int const*>(fp)) f<int>(int*) + EXPECT_TRUE(Demangle("_Z1fIiEDTscPKT_fp_EPS0_", tmp, sizeof(tmp))); + EXPECT_STREQ("f<>()", tmp); +} + +TEST(Demangle, ConstCast) { + char tmp[80]; + + // Source: + // + // template <class T> auto f(T* p) -> decltype(const_cast<const T*>(p)) { + // return p; + // } + // void g(int* p) { f(p); } + // + // Full LLVM demangling of the instantiation of f: + // + // decltype(const_cast<int const*>(fp)) f<int>(int*) + EXPECT_TRUE(Demangle("_Z1fIiEDTccPKT_fp_EPS0_", tmp, sizeof(tmp))); + EXPECT_STREQ("f<>()", tmp); +} + +TEST(Demangle, ReinterpretCast) { + char tmp[80]; + + // Source: + // + // template <class T> auto f(T* p) + // -> decltype(reinterpret_cast<const T*>(p)) { + // return p; + // } + // void g(int* p) { f(p); } + // + // Full LLVM demangling of the instantiation of f: + // + // decltype(reinterpret_cast<int const*>(fp)) f<int>(int*) + EXPECT_TRUE(Demangle("_Z1fIiEDTrcPKT_fp_EPS0_", tmp, sizeof(tmp))); + EXPECT_STREQ("f<>()", tmp); +} + TEST(Demangle, ThreadLocalWrappers) { char tmp[80]; |