Commit c6000317 by Chris Mihelich Committed by Copybara-Service

Demangle <extended-qualifier> in types, e.g., U5AS128 for address_space(128).

PiperOrigin-RevId: 641310017
Change-Id: I0f10a2a1965e842db4efda455e0cdfbeb6656fa5
parent c586e8d8
......@@ -598,6 +598,7 @@ static bool ParseCtorDtorName(State *state);
static bool ParseDecltype(State *state);
static bool ParseType(State *state);
static bool ParseCVQualifiers(State *state);
static bool ParseExtendedQualifier(State *state);
static bool ParseBuiltinType(State *state);
static bool ParseVendorExtendedType(State *state);
static bool ParseFunctionType(State *state);
......@@ -1322,7 +1323,6 @@ static bool ParseDecltype(State *state) {
// ::= O <type> # rvalue reference-to (C++0x)
// ::= C <type> # complex pair (C 2000)
// ::= G <type> # imaginary (C 2000)
// ::= U <source-name> <type> # vendor extended type qualifier
// ::= <builtin-type>
// ::= <function-type>
// ::= <class-enum-type> # note: just an alias for <name>
......@@ -1378,12 +1378,6 @@ static bool ParseType(State *state) {
}
state->parse_state = copy;
if (ParseOneCharToken(state, 'U') && ParseSourceName(state) &&
ParseType(state)) {
return true;
}
state->parse_state = copy;
if (ParseBuiltinType(state) || ParseFunctionType(state) ||
ParseClassEnumType(state) || ParseArrayType(state) ||
ParsePointerToMemberType(state) || ParseDecltype(state) ||
......@@ -1427,19 +1421,35 @@ static bool ParseType(State *state) {
return ParseLongToken(state, "_SUBSTPACK_");
}
// <qualifiers> ::= <extended-qualifier>* <CV-qualifiers>
// <CV-qualifiers> ::= [r] [V] [K]
//
// We don't allow empty <CV-qualifiers> to avoid infinite loop in
// ParseType().
static bool ParseCVQualifiers(State *state) {
ComplexityGuard guard(state);
if (guard.IsTooComplex()) return false;
int num_cv_qualifiers = 0;
while (ParseExtendedQualifier(state)) ++num_cv_qualifiers;
num_cv_qualifiers += ParseOneCharToken(state, 'r');
num_cv_qualifiers += ParseOneCharToken(state, 'V');
num_cv_qualifiers += ParseOneCharToken(state, 'K');
return num_cv_qualifiers > 0;
}
// <extended-qualifier> ::= U <source-name> [<template-args>]
static bool ParseExtendedQualifier(State *state) {
ComplexityGuard guard(state);
if (guard.IsTooComplex()) return false;
ParseState copy = state->parse_state;
if (ParseOneCharToken(state, 'U') && ParseSourceName(state) &&
Optional(ParseTemplateArgs(state))) {
return true;
}
state->parse_state = copy;
return false;
}
// <builtin-type> ::= v, etc. # single-character builtin types
// ::= <vendor-extended-type>
// ::= Dd, etc. # two-character builtin types
......
......@@ -760,6 +760,40 @@ TEST(Demangle, GnuVectorSizeIsADependentOperatorExpression) {
EXPECT_STREQ("f<>()", tmp);
}
TEST(Demangle, SimpleAddressSpace) {
char tmp[80];
// Source:
//
// void f(const int __attribute__((address_space(128)))*) {}
//
// LLVM demangling:
//
// f(int const AS128*)
//
// Itanium ABI 5.1.5.1, "Qualified types", notes that address_space is mangled
// nonuniformly as a legacy exception: the number is part of the source-name
// if nondependent but is an expression in template-args if dependent. Thus
// it is a convenient test case for both forms.
EXPECT_TRUE(Demangle("_Z1fPU5AS128Ki", tmp, sizeof(tmp)));
EXPECT_STREQ("f()", tmp);
}
TEST(Demangle, DependentAddressSpace) {
char tmp[80];
// Source:
//
// template <int n> void f (const int __attribute__((address_space(n)))*) {}
// template void f<128>(const int __attribute__((address_space(128)))*);
//
// LLVM demangling:
//
// void f<128>(int AS<128>*)
EXPECT_TRUE(Demangle("_Z1fILi128EEvPU2ASIT_Ei", tmp, sizeof(tmp)));
EXPECT_STREQ("f<>()", tmp);
}
TEST(Demangle, TransactionSafeEntryPoint) {
char tmp[80];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment