From abc0f8d1096a66c087365327c217963eab15839c Mon Sep 17 00:00:00 2001 From: Chris Mihelich Date: Wed, 29 May 2024 05:05:20 -0700 Subject: Demangle Clang's encoding of __attribute__((enable_if(condition, "message"))). PiperOrigin-RevId: 638244694 Change-Id: I80393c6c00f1554057a915e0d71f88b7d899818c --- absl/debugging/internal/demangle.cc | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'absl/debugging/internal/demangle.cc') diff --git a/absl/debugging/internal/demangle.cc b/absl/debugging/internal/demangle.cc index f04e4dbc..606ff4e7 100644 --- a/absl/debugging/internal/demangle.cc +++ b/absl/debugging/internal/demangle.cc @@ -585,6 +585,7 @@ static bool ParseCVQualifiers(State *state); static bool ParseBuiltinType(State *state); static bool ParseFunctionType(State *state); static bool ParseBareFunctionType(State *state); +static bool ParseOverloadAttribute(State *state); static bool ParseClassEnumType(State *state); static bool ParseArrayType(State *state); static bool ParsePointerToMemberType(State *state); @@ -1437,13 +1438,17 @@ static bool ParseFunctionType(State *state) { return true; } -// ::= <(signature) type>+ +// ::= * <(signature) type>+ +// +// The * prefix is nonstandard; see the comment on +// ParseOverloadAttribute. static bool ParseBareFunctionType(State *state) { ComplexityGuard guard(state); if (guard.IsTooComplex()) return false; ParseState copy = state->parse_state; DisableAppend(state); - if (OneOrMore(ParseType, state)) { + if (ZeroOrMore(ParseOverloadAttribute, state) && + OneOrMore(ParseType, state)) { RestoreAppend(state, copy.append); MaybeAppend(state, "()"); return true; @@ -1452,6 +1457,25 @@ static bool ParseBareFunctionType(State *state) { return false; } +// ::= Ua +// +// The nonstandard production is sufficient to accept the +// current implementation of __attribute__((enable_if(condition, "message"))) +// and future attributes of a similar shape. See +// https://clang.llvm.org/docs/AttributeReference.html#enable-if and the +// definition of CXXNameMangler::mangleFunctionEncodingBareType in Clang's +// source code. +static bool ParseOverloadAttribute(State *state) { + ComplexityGuard guard(state); + if (guard.IsTooComplex()) return false; + ParseState copy = state->parse_state; + if (ParseTwoCharToken(state, "Ua") && ParseName(state)) { + return true; + } + state->parse_state = copy; + return false; +} + // ::= static bool ParseClassEnumType(State *state) { ComplexityGuard guard(state); -- cgit v1.2.3