Skip to content

Commit

Permalink
[lldb] Don't assume name of libc++ inline namespace in LibCxxUnordere…
Browse files Browse the repository at this point in the history
…dMap

Follow up to D117383, fixing the assumption that libc++ always uses `__1` as
its inline namespace name.

Reviewed By: rupprecht

Differential Revision: https://reviews.llvm.org/D133259
  • Loading branch information
kastiglione committed Nov 11, 2022
1 parent 88aac16 commit b66da73
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
Expand Up @@ -67,11 +67,23 @@ size_t lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::
return m_num_elements;
}

static void consumeInlineNamespace(llvm::StringRef &name) {
// Delete past an inline namespace, if any: __[a-zA-Z0-9_]+::
auto scratch = name;
if (scratch.consume_front("__") && std::isalnum(scratch[0])) {
scratch = scratch.drop_while([](char c) { return std::isalnum(c); });
if (scratch.consume_front("::")) {
// Successfully consumed a namespace.
name = scratch;
}
}
}

static bool isStdTemplate(ConstString type_name, llvm::StringRef type) {
llvm::StringRef name = type_name.GetStringRef();
// The type name may or may not be prefixed with `std::` or `std::__1::`.
// The type name may be prefixed with `std::__<inline-namespace>::`.
if (name.consume_front("std::"))
name.consume_front("__1::");
consumeInlineNamespace(name);
return name.consume_front(type) && name.startswith("<");
}

Expand Down

0 comments on commit b66da73

Please sign in to comment.