diff options
author | Chris Mihelich <cmihelic@google.com> | 2024-06-07 14:34:05 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-06-07 14:34:47 -0700 |
commit | 3941dc4183616821ba5909c2b6878e158a8afde0 (patch) | |
tree | 494ab0c9260d9ab29bef6c5d6d497919dcc3127b /absl | |
parent | 9140cc7b19ee1eddde576ff18d486b6e7a3f6170 (diff) |
Demangle _BitInt types DB..., DU....
PiperOrigin-RevId: 641360162
Change-Id: Iabce55eb61feaa4dc099093a6496e26ab66906fa
Diffstat (limited to 'absl')
-rw-r--r-- | absl/debugging/internal/demangle.cc | 31 | ||||
-rw-r--r-- | absl/debugging/internal/demangle_test.cc | 24 |
2 files changed, 55 insertions, 0 deletions
diff --git a/absl/debugging/internal/demangle.cc b/absl/debugging/internal/demangle.cc index 184d89fb..26421c0e 100644 --- a/absl/debugging/internal/demangle.cc +++ b/absl/debugging/internal/demangle.cc @@ -1453,12 +1453,43 @@ static bool ParseExtendedQualifier(State *state) { // <builtin-type> ::= v, etc. # single-character builtin types // ::= <vendor-extended-type> // ::= Dd, etc. # two-character builtin types +// ::= DB (<number> | <expression>) _ # _BitInt(N) +// ::= DU (<number> | <expression>) _ # unsigned _BitInt(N) // // Not supported: // ::= DF <number> _ # _FloatN (N bits) static bool ParseBuiltinType(State *state) { ComplexityGuard guard(state); if (guard.IsTooComplex()) return false; + ParseState copy = state->parse_state; + + // DB (<number> | <expression>) _ # _BitInt(N) + // DU (<number> | <expression>) _ # unsigned _BitInt(N) + if (ParseTwoCharToken(state, "DB") || + (ParseTwoCharToken(state, "DU") && MaybeAppend(state, "unsigned "))) { + bool append = state->parse_state.append; + DisableAppend(state); + int number = -1; + if (!ParseNumber(state, &number) && !ParseExpression(state)) { + state->parse_state = copy; + return false; + } + RestoreAppend(state, append); + + if (!ParseOneCharToken(state, '_')) { + state->parse_state = copy; + return false; + } + + MaybeAppend(state, "_BitInt("); + if (number >= 0) { + MaybeAppendDecimal(state, number); + } else { + MaybeAppend(state, "?"); // the best we can do for dependent sizes + } + MaybeAppend(state, ")"); + return true; + } for (const AbbrevPair *p = kBuiltinTypeList; p->abbrev != nullptr; ++p) { // Guaranteed only 1- or 2-character strings in kBuiltinTypeList. diff --git a/absl/debugging/internal/demangle_test.cc b/absl/debugging/internal/demangle_test.cc index 111e895c..c702e189 100644 --- a/absl/debugging/internal/demangle_test.cc +++ b/absl/debugging/internal/demangle_test.cc @@ -660,6 +660,30 @@ TEST(Demangle, ComplexFloatingPointLiterals) { EXPECT_STREQ("f<>()", tmp); } +TEST(Demangle, SimpleSignedBitInt) { + char tmp[80]; + + // S::operator _BitInt(256)() const + EXPECT_TRUE(Demangle("_ZNK1ScvDB256_Ev", tmp, sizeof(tmp))); + EXPECT_STREQ("S::operator _BitInt(256)()", tmp); +} + +TEST(Demangle, SimpleUnsignedBitInt) { + char tmp[80]; + + // S::operator unsigned _BitInt(256)() const + EXPECT_TRUE(Demangle("_ZNK1ScvDU256_Ev", tmp, sizeof(tmp))); + EXPECT_STREQ("S::operator unsigned _BitInt(256)()", tmp); +} + +TEST(Demangle, DependentBitInt) { + char tmp[80]; + + // S::operator _BitInt(256)<256>() const + EXPECT_TRUE(Demangle("_ZNK1ScvDBT__ILi256EEEv", tmp, sizeof(tmp))); + EXPECT_STREQ("S::operator _BitInt(?)<>()", tmp); +} + TEST(Demangle, GlobalInitializers) { char tmp[80]; |