summaryrefslogtreecommitdiff
path: root/absl/debugging
diff options
context:
space:
mode:
authorGravatar Chris Mihelich <cmihelic@google.com>2024-05-28 11:04:04 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2024-05-28 11:04:54 -0700
commit4a861bb14ba1baf203912f11360d4d8a6379faf7 (patch)
tree9b13bb36b4b9b4a5c087b1aa6a2d663c6b7c02df /absl/debugging
parent90d49cbad8c503418a10056e2d50c93caa0d142b (diff)
Demangle valueless literals LDnE (nullptr) and LA<number>_<type>E ("foo").
PiperOrigin-RevId: 637958502 Change-Id: If81eba9729c16b5d5ac7187cf74738d8aaace367
Diffstat (limited to 'absl/debugging')
-rw-r--r--absl/debugging/internal/demangle.cc33
-rw-r--r--absl/debugging/internal/demangle_test.cc20
2 files changed, 49 insertions, 4 deletions
diff --git a/absl/debugging/internal/demangle.cc b/absl/debugging/internal/demangle.cc
index c27cc01a..38b5458e 100644
--- a/absl/debugging/internal/demangle.cc
+++ b/absl/debugging/internal/demangle.cc
@@ -2040,10 +2040,35 @@ static bool ParseExprPrimary(State *state) {
return false;
}
- // The merged cast production.
- if (ParseOneCharToken(state, 'L') && ParseType(state) &&
- ParseExprCastValueAndTrailingE(state)) {
- return true;
+ if (ParseOneCharToken(state, 'L')) {
+ // There are two special cases in which a literal may or must contain a type
+ // without a value. The first is that both LDnE and LDn0E are valid
+ // encodings of nullptr, used in different situations. Recognize LDnE here,
+ // leaving LDn0E to be recognized by the general logic afterward.
+ if (ParseThreeCharToken(state, "DnE")) return true;
+
+ // The second special case is a string literal, currently mangled in C++98
+ // style as LA<length + 1>_KcE. This is inadequate to support C++11 and
+ // later versions, and the discussion of this problem has not converged.
+ //
+ // https://github.com/itanium-cxx-abi/cxx-abi/issues/64
+ //
+ // For now the bare-type mangling is what's used in practice, so we
+ // recognize this form and only this form if an array type appears here.
+ // Someday we'll probably have to accept a new form of value mangling in
+ // LA...E constructs. (Note also that C++20 allows a wide range of
+ // class-type objects as template arguments, so someday their values will be
+ // mangled and we'll have to recognize them here too.)
+ if (RemainingInput(state)[0] == 'A' /* an array type follows */) {
+ if (ParseType(state) && ParseOneCharToken(state, 'E')) return true;
+ state->parse_state = copy;
+ return false;
+ }
+
+ // The merged cast production.
+ if (ParseType(state) && ParseExprCastValueAndTrailingE(state)) {
+ return true;
+ }
}
state->parse_state = copy;
diff --git a/absl/debugging/internal/demangle_test.cc b/absl/debugging/internal/demangle_test.cc
index 96074237..2cfd1f95 100644
--- a/absl/debugging/internal/demangle_test.cc
+++ b/absl/debugging/internal/demangle_test.cc
@@ -375,6 +375,26 @@ TEST(Demangle, LiteralOfGlobalNamespaceEnumType) {
EXPECT_STREQ("f<>()", tmp);
}
+TEST(Demangle, NullptrLiterals) {
+ char tmp[80];
+
+ // void f<nullptr>()
+ EXPECT_TRUE(Demangle("_Z1fILDnEEvv", tmp, sizeof(tmp)));
+ EXPECT_STREQ("f<>()", tmp);
+
+ // also void f<nullptr>()
+ EXPECT_TRUE(Demangle("_Z1fILDn0EEvv", tmp, sizeof(tmp)));
+ EXPECT_STREQ("f<>()", tmp);
+}
+
+TEST(Demangle, StringLiterals) {
+ char tmp[80];
+
+ // void f<"<char const [42]>">()
+ EXPECT_TRUE(Demangle("_Z1fILA42_KcEEvv", tmp, sizeof(tmp)));
+ EXPECT_STREQ("f<>()", tmp);
+}
+
// Test the GNU abi_tag extension.
TEST(Demangle, AbiTags) {
char tmp[80];