aboutsummaryrefslogtreecommitdiff
path: root/absl/debugging
diff options
context:
space:
mode:
authorChris Mihelich <cmihelic@google.com>2024-05-29 07:51:17 -0700
committerCopybara-Service <copybara-worker@google.com>2024-05-29 07:51:59 -0700
commit64457068f2b1960e4c339e0c090eeb8b73ddddd6 (patch)
tree57568f814f789cd62a7495717ffc161df9ca09fe /absl/debugging
parent77d0ac71e41bb35c6415d38f20b5cd8faadec35a (diff)
downloadabseil-64457068f2b1960e4c339e0c090eeb8b73ddddd6.tar.gz
abseil-64457068f2b1960e4c339e0c090eeb8b73ddddd6.tar.bz2
abseil-64457068f2b1960e4c339e0c090eeb8b73ddddd6.zip
Demangle Clang's last-resort notation _SUBSTPACK_.
PiperOrigin-RevId: 638283381 Change-Id: Icdd46801f530bd4e8083777c14c78593fd6e111d
Diffstat (limited to 'absl/debugging')
-rw-r--r--absl/debugging/internal/demangle.cc21
-rw-r--r--absl/debugging/internal/demangle_test.cc19
2 files changed, 39 insertions, 1 deletions
diff --git a/absl/debugging/internal/demangle.cc b/absl/debugging/internal/demangle.cc
index 2e692d38..c9dbb3c6 100644
--- a/absl/debugging/internal/demangle.cc
+++ b/absl/debugging/internal/demangle.cc
@@ -329,6 +329,22 @@ static bool ParseThreeCharToken(State *state, const char *three_char_token) {
return false;
}
+// Returns true and advances "mangled_idx" if we find a copy of the
+// NUL-terminated string "long_token" at "mangled_idx" position.
+static bool ParseLongToken(State *state, const char *long_token) {
+ ComplexityGuard guard(state);
+ if (guard.IsTooComplex()) return false;
+ int i = 0;
+ for (; long_token[i] != '\0'; ++i) {
+ // Note that we cannot run off the end of the NUL-terminated input here.
+ // Inside the loop body, long_token[i] is known to be different from NUL.
+ // So if we read the NUL on the end of the input here, we return at once.
+ if (RemainingInput(state)[i] != long_token[i]) return false;
+ }
+ state->parse_state.mangled_idx += i;
+ return true;
+}
+
// Returns true and advances "mangled_cur" if we find any character in
// "char_class" at "mangled_cur" position.
static bool ParseCharClass(State *state, const char *char_class) {
@@ -1329,7 +1345,10 @@ static bool ParseType(State *state) {
}
state->parse_state = copy;
- return false;
+ // For this notation see CXXNameMangler::mangleType in Clang's source code.
+ // The relevant logic and its comment "not clear how to mangle this!" date
+ // from 2011, so it may be with us awhile.
+ return ParseLongToken(state, "_SUBSTPACK_");
}
// <CV-qualifiers> ::= [r] [V] [K]
diff --git a/absl/debugging/internal/demangle_test.cc b/absl/debugging/internal/demangle_test.cc
index 5ecb33c2..d559d8ca 100644
--- a/absl/debugging/internal/demangle_test.cc
+++ b/absl/debugging/internal/demangle_test.cc
@@ -353,6 +353,25 @@ TEST(Demangle, LambdaWithExplicitPackArgument) {
EXPECT_STREQ(tmp, "f<>()::{lambda()#1}::operator()<>()");
}
+TEST(Demangle, SubstpackNotationForTroublesomeTemplatePack) {
+ char tmp[100];
+
+ // Source:
+ //
+ // template <template <class> class, template <class> class> struct B {};
+ //
+ // template <template <class> class... T> struct A {
+ // template <template <class> class... U> void f(B<T, U>&&...) {}
+ // };
+ //
+ // template void A<>::f<>();
+ //
+ // LLVM can't demangle its own _SUBSTPACK_ notation.
+ ASSERT_TRUE(Demangle("_ZN1AIJEE1fIJEEEvDpO1BI_SUBSTPACK_T_E",
+ tmp, sizeof(tmp)));
+ EXPECT_STREQ(tmp, "A<>::f<>()");
+}
+
// Test corner cases of boundary conditions.
TEST(Demangle, CornerCases) {
char tmp[10];