Update prebuilt Clang to r416183b from Android.

https://android.googlesource.com/platform/prebuilts/clang/host/
linux-x86/+/06a71ddac05c22edb2d10b590e1769b3f8619bef

clang 12.0.5 (based on r416183b) from build 7284624.

Change-Id: I277a316abcf47307562d8b748b84870f31a72866
Signed-off-by: Olivier Deprez <olivier.deprez@arm.com>
diff --git a/linux-x64/clang/include/llvm/Demangle/Demangle.h b/linux-x64/clang/include/llvm/Demangle/Demangle.h
index 6fea7ef..b4006a0 100644
--- a/linux-x64/clang/include/llvm/Demangle/Demangle.h
+++ b/linux-x64/clang/include/llvm/Demangle/Demangle.h
@@ -32,8 +32,29 @@
                       int *status);
 
 
-enum MSDemangleFlags { MSDF_None = 0, MSDF_DumpBackrefs = 1 << 0 };
-char *microsoftDemangle(const char *mangled_name, char *buf, size_t *n,
+enum MSDemangleFlags {
+  MSDF_None = 0,
+  MSDF_DumpBackrefs = 1 << 0,
+  MSDF_NoAccessSpecifier = 1 << 1,
+  MSDF_NoCallingConvention = 1 << 2,
+  MSDF_NoReturnType = 1 << 3,
+  MSDF_NoMemberType = 1 << 4,
+};
+
+/// Demangles the Microsoft symbol pointed at by mangled_name and returns it.
+/// Returns a pointer to the start of a null-terminated demangled string on
+/// success, or nullptr on error.
+/// If n_read is non-null and demangling was successful, it receives how many
+/// bytes of the input string were consumed.
+/// buf can point to a *n_buf bytes large buffer where the demangled name is
+/// stored. If the buffer is too small, it is grown with realloc(). If buf is
+/// nullptr, then this malloc()s memory for the result.
+/// *n_buf stores the size of buf on input if buf is non-nullptr, and it
+/// receives the size of the demangled string on output if n_buf is not nullptr.
+/// status receives one of the demangle_ enum entries above if it's not nullptr.
+/// Flags controls various details of the demangled representation.
+char *microsoftDemangle(const char *mangled_name, size_t *n_read,
+                        char *buf, size_t *n_buf,
                         int *status, MSDemangleFlags Flags = MSDF_None);
 
 /// Attempt to demangle a string using different demangling schemes.
diff --git a/linux-x64/clang/include/llvm/Demangle/DemangleConfig.h b/linux-x64/clang/include/llvm/Demangle/DemangleConfig.h
index 73f89d3..b7b7dbd 100644
--- a/linux-x64/clang/include/llvm/Demangle/DemangleConfig.h
+++ b/linux-x64/clang/include/llvm/Demangle/DemangleConfig.h
@@ -15,13 +15,6 @@
 #ifndef LLVM_DEMANGLE_COMPILER_H
 #define LLVM_DEMANGLE_COMPILER_H
 
-#ifdef _MSC_VER
-// snprintf is implemented in VS 2015
-#if _MSC_VER < 1900
-#define snprintf _snprintf_s
-#endif
-#endif
-
 #ifndef __has_feature
 #define __has_feature(x) 0
 #endif
diff --git a/linux-x64/clang/include/llvm/Demangle/ItaniumDemangle.h b/linux-x64/clang/include/llvm/Demangle/ItaniumDemangle.h
index aaccb27..6bfc02d 100644
--- a/linux-x64/clang/include/llvm/Demangle/ItaniumDemangle.h
+++ b/linux-x64/clang/include/llvm/Demangle/ItaniumDemangle.h
@@ -57,6 +57,11 @@
     X(LocalName) \
     X(VectorType) \
     X(PixelVectorType) \
+    X(SyntheticTemplateParamName) \
+    X(TypeTemplateParamDecl) \
+    X(NonTypeTemplateParamDecl) \
+    X(TemplateTemplateParamDecl) \
+    X(TemplateParamPackDecl) \
     X(ParameterPack) \
     X(TemplateArgumentPack) \
     X(ParameterPackExpansion) \
@@ -77,6 +82,7 @@
     X(PostfixExpr) \
     X(ConditionalExpr) \
     X(MemberExpr) \
+    X(SubobjectExpr) \
     X(EnclosingExpr) \
     X(CastExpr) \
     X(SizeofParamPackExpr) \
@@ -86,12 +92,15 @@
     X(PrefixExpr) \
     X(FunctionParam) \
     X(ConversionExpr) \
+    X(PointerToMemberConversionExpr) \
     X(InitListExpr) \
     X(FoldExpr) \
     X(ThrowExpr) \
     X(UUIDOfExpr) \
     X(BoolExpr) \
-    X(IntegerCastExpr) \
+    X(StringLiteral) \
+    X(LambdaExpr) \
+    X(EnumLiteral)    \
     X(IntegerLiteral) \
     X(FloatLiteral) \
     X(DoubleLiteral) \
@@ -303,7 +312,7 @@
   return Q1 = static_cast<Qualifiers>(Q1 | Q2);
 }
 
-class QualType : public Node {
+class QualType final : public Node {
 protected:
   const Qualifiers Quals;
   const Node *Child;
@@ -600,48 +609,12 @@
   }
 };
 
-class NodeOrString {
-  const void *First;
-  const void *Second;
-
-public:
-  /* implicit */ NodeOrString(StringView Str) {
-    const char *FirstChar = Str.begin();
-    const char *SecondChar = Str.end();
-    if (SecondChar == nullptr) {
-      assert(FirstChar == SecondChar);
-      ++FirstChar, ++SecondChar;
-    }
-    First = static_cast<const void *>(FirstChar);
-    Second = static_cast<const void *>(SecondChar);
-  }
-
-  /* implicit */ NodeOrString(Node *N)
-      : First(static_cast<const void *>(N)), Second(nullptr) {}
-  NodeOrString() : First(nullptr), Second(nullptr) {}
-
-  bool isString() const { return Second && First; }
-  bool isNode() const { return First && !Second; }
-  bool isEmpty() const { return !First && !Second; }
-
-  StringView asString() const {
-    assert(isString());
-    return StringView(static_cast<const char *>(First),
-                      static_cast<const char *>(Second));
-  }
-
-  const Node *asNode() const {
-    assert(isNode());
-    return static_cast<const Node *>(First);
-  }
-};
-
 class ArrayType final : public Node {
   const Node *Base;
-  NodeOrString Dimension;
+  Node *Dimension;
 
 public:
-  ArrayType(const Node *Base_, NodeOrString Dimension_)
+  ArrayType(const Node *Base_, Node *Dimension_)
       : Node(KArrayType,
              /*RHSComponentCache=*/Cache::Yes,
              /*ArrayCache=*/Cache::Yes),
@@ -658,10 +631,8 @@
     if (S.back() != ']')
       S += " ";
     S += "[";
-    if (Dimension.isString())
-      S += Dimension.asString();
-    else if (Dimension.isNode())
-      Dimension.asNode()->print(S);
+    if (Dimension)
+      Dimension->print(S);
     S += "]";
     Base->printRight(S);
   }
@@ -927,10 +898,10 @@
 
 class VectorType final : public Node {
   const Node *BaseType;
-  const NodeOrString Dimension;
+  const Node *Dimension;
 
 public:
-  VectorType(const Node *BaseType_, NodeOrString Dimension_)
+  VectorType(const Node *BaseType_, Node *Dimension_)
       : Node(KVectorType), BaseType(BaseType_),
         Dimension(Dimension_) {}
 
@@ -939,19 +910,17 @@
   void printLeft(OutputStream &S) const override {
     BaseType->print(S);
     S += " vector[";
-    if (Dimension.isNode())
-      Dimension.asNode()->print(S);
-    else if (Dimension.isString())
-      S += Dimension.asString();
+    if (Dimension)
+      Dimension->print(S);
     S += "]";
   }
 };
 
 class PixelVectorType final : public Node {
-  const NodeOrString Dimension;
+  const Node *Dimension;
 
 public:
-  PixelVectorType(NodeOrString Dimension_)
+  PixelVectorType(const Node *Dimension_)
       : Node(KPixelVectorType), Dimension(Dimension_) {}
 
   template<typename Fn> void match(Fn F) const { F(Dimension); }
@@ -959,11 +928,132 @@
   void printLeft(OutputStream &S) const override {
     // FIXME: This should demangle as "vector pixel".
     S += "pixel vector[";
-    S += Dimension.asString();
+    Dimension->print(S);
     S += "]";
   }
 };
 
+enum class TemplateParamKind { Type, NonType, Template };
+
+/// An invented name for a template parameter for which we don't have a
+/// corresponding template argument.
+///
+/// This node is created when parsing the <lambda-sig> for a lambda with
+/// explicit template arguments, which might be referenced in the parameter
+/// types appearing later in the <lambda-sig>.
+class SyntheticTemplateParamName final : public Node {
+  TemplateParamKind Kind;
+  unsigned Index;
+
+public:
+  SyntheticTemplateParamName(TemplateParamKind Kind_, unsigned Index_)
+      : Node(KSyntheticTemplateParamName), Kind(Kind_), Index(Index_) {}
+
+  template<typename Fn> void match(Fn F) const { F(Kind, Index); }
+
+  void printLeft(OutputStream &S) const override {
+    switch (Kind) {
+    case TemplateParamKind::Type:
+      S += "$T";
+      break;
+    case TemplateParamKind::NonType:
+      S += "$N";
+      break;
+    case TemplateParamKind::Template:
+      S += "$TT";
+      break;
+    }
+    if (Index > 0)
+      S << Index - 1;
+  }
+};
+
+/// A template type parameter declaration, 'typename T'.
+class TypeTemplateParamDecl final : public Node {
+  Node *Name;
+
+public:
+  TypeTemplateParamDecl(Node *Name_)
+      : Node(KTypeTemplateParamDecl, Cache::Yes), Name(Name_) {}
+
+  template<typename Fn> void match(Fn F) const { F(Name); }
+
+  void printLeft(OutputStream &S) const override {
+    S += "typename ";
+  }
+
+  void printRight(OutputStream &S) const override {
+    Name->print(S);
+  }
+};
+
+/// A non-type template parameter declaration, 'int N'.
+class NonTypeTemplateParamDecl final : public Node {
+  Node *Name;
+  Node *Type;
+
+public:
+  NonTypeTemplateParamDecl(Node *Name_, Node *Type_)
+      : Node(KNonTypeTemplateParamDecl, Cache::Yes), Name(Name_), Type(Type_) {}
+
+  template<typename Fn> void match(Fn F) const { F(Name, Type); }
+
+  void printLeft(OutputStream &S) const override {
+    Type->printLeft(S);
+    if (!Type->hasRHSComponent(S))
+      S += " ";
+  }
+
+  void printRight(OutputStream &S) const override {
+    Name->print(S);
+    Type->printRight(S);
+  }
+};
+
+/// A template template parameter declaration,
+/// 'template<typename T> typename N'.
+class TemplateTemplateParamDecl final : public Node {
+  Node *Name;
+  NodeArray Params;
+
+public:
+  TemplateTemplateParamDecl(Node *Name_, NodeArray Params_)
+      : Node(KTemplateTemplateParamDecl, Cache::Yes), Name(Name_),
+        Params(Params_) {}
+
+  template<typename Fn> void match(Fn F) const { F(Name, Params); }
+
+  void printLeft(OutputStream &S) const override {
+    S += "template<";
+    Params.printWithComma(S);
+    S += "> typename ";
+  }
+
+  void printRight(OutputStream &S) const override {
+    Name->print(S);
+  }
+};
+
+/// A template parameter pack declaration, 'typename ...T'.
+class TemplateParamPackDecl final : public Node {
+  Node *Param;
+
+public:
+  TemplateParamPackDecl(Node *Param_)
+      : Node(KTemplateParamPackDecl, Cache::Yes), Param(Param_) {}
+
+  template<typename Fn> void match(Fn F) const { F(Param); }
+
+  void printLeft(OutputStream &S) const override {
+    Param->printLeft(S);
+    S += "...";
+  }
+
+  void printRight(OutputStream &S) const override {
+    Param->printRight(S);
+  }
+};
+
 /// An unexpanded parameter pack (either in the expression or type context). If
 /// this AST is correct, this node will have a ParameterPackExpansion node above
 /// it.
@@ -1410,21 +1500,36 @@
 };
 
 class ClosureTypeName : public Node {
+  NodeArray TemplateParams;
   NodeArray Params;
   StringView Count;
 
 public:
-  ClosureTypeName(NodeArray Params_, StringView Count_)
-      : Node(KClosureTypeName), Params(Params_), Count(Count_) {}
+  ClosureTypeName(NodeArray TemplateParams_, NodeArray Params_,
+                  StringView Count_)
+      : Node(KClosureTypeName), TemplateParams(TemplateParams_),
+        Params(Params_), Count(Count_) {}
 
-  template<typename Fn> void match(Fn F) const { F(Params, Count); }
+  template<typename Fn> void match(Fn F) const {
+    F(TemplateParams, Params, Count);
+  }
+
+  void printDeclarator(OutputStream &S) const {
+    if (!TemplateParams.empty()) {
+      S += "<";
+      TemplateParams.printWithComma(S);
+      S += ">";
+    }
+    S += "(";
+    Params.printWithComma(S);
+    S += ")";
+  }
 
   void printLeft(OutputStream &S) const override {
     S += "\'lambda";
     S += Count;
-    S += "\'(";
-    Params.printWithComma(S);
-    S += ")";
+    S += "\'";
+    printDeclarator(S);
   }
 };
 
@@ -1553,6 +1658,40 @@
   }
 };
 
+class SubobjectExpr : public Node {
+  const Node *Type;
+  const Node *SubExpr;
+  StringView Offset;
+  NodeArray UnionSelectors;
+  bool OnePastTheEnd;
+
+public:
+  SubobjectExpr(const Node *Type_, const Node *SubExpr_, StringView Offset_,
+                NodeArray UnionSelectors_, bool OnePastTheEnd_)
+      : Node(KSubobjectExpr), Type(Type_), SubExpr(SubExpr_), Offset(Offset_),
+        UnionSelectors(UnionSelectors_), OnePastTheEnd(OnePastTheEnd_) {}
+
+  template<typename Fn> void match(Fn F) const {
+    F(Type, SubExpr, Offset, UnionSelectors, OnePastTheEnd);
+  }
+
+  void printLeft(OutputStream &S) const override {
+    SubExpr->print(S);
+    S += ".<";
+    Type->print(S);
+    S += " at offset ";
+    if (Offset.empty()) {
+      S += "0";
+    } else if (Offset[0] == 'n') {
+      S += "-";
+      S += Offset.dropFront();
+    } else {
+      S += Offset;
+    }
+    S += ">";
+  }
+};
+
 class EnclosingExpr : public Node {
   const StringView Prefix;
   const Node *Infix;
@@ -1740,6 +1879,28 @@
   }
 };
 
+class PointerToMemberConversionExpr : public Node {
+  const Node *Type;
+  const Node *SubExpr;
+  StringView Offset;
+
+public:
+  PointerToMemberConversionExpr(const Node *Type_, const Node *SubExpr_,
+                                StringView Offset_)
+      : Node(KPointerToMemberConversionExpr), Type(Type_), SubExpr(SubExpr_),
+        Offset(Offset_) {}
+
+  template<typename Fn> void match(Fn F) const { F(Type, SubExpr, Offset); }
+
+  void printLeft(OutputStream &S) const override {
+    S += "(";
+    Type->print(S);
+    S += ")(";
+    SubExpr->print(S);
+    S += ")";
+  }
+};
+
 class InitListExpr : public Node {
   const Node *Ty;
   NodeArray Inits;
@@ -1902,22 +2063,57 @@
   }
 };
 
-class IntegerCastExpr : public Node {
+class StringLiteral : public Node {
+  const Node *Type;
+
+public:
+  StringLiteral(const Node *Type_) : Node(KStringLiteral), Type(Type_) {}
+
+  template<typename Fn> void match(Fn F) const { F(Type); }
+
+  void printLeft(OutputStream &S) const override {
+    S += "\"<";
+    Type->print(S);
+    S += ">\"";
+  }
+};
+
+class LambdaExpr : public Node {
+  const Node *Type;
+
+public:
+  LambdaExpr(const Node *Type_) : Node(KLambdaExpr), Type(Type_) {}
+
+  template<typename Fn> void match(Fn F) const { F(Type); }
+
+  void printLeft(OutputStream &S) const override {
+    S += "[]";
+    if (Type->getKind() == KClosureTypeName)
+      static_cast<const ClosureTypeName *>(Type)->printDeclarator(S);
+    S += "{...}";
+  }
+};
+
+class EnumLiteral : public Node {
   // ty(integer)
   const Node *Ty;
   StringView Integer;
 
 public:
-  IntegerCastExpr(const Node *Ty_, StringView Integer_)
-      : Node(KIntegerCastExpr), Ty(Ty_), Integer(Integer_) {}
+  EnumLiteral(const Node *Ty_, StringView Integer_)
+      : Node(KEnumLiteral), Ty(Ty_), Integer(Integer_) {}
 
   template<typename Fn> void match(Fn F) const { F(Ty, Integer); }
 
   void printLeft(OutputStream &S) const override {
-    S += "(";
+    S << "(";
     Ty->print(S);
-    S += ")";
-    S += Integer;
+    S << ")";
+
+    if (Integer[0] == 'n')
+      S << "-" << Integer.dropFront(1);
+    else
+      S << Integer;
   }
 };
 
@@ -2039,10 +2235,10 @@
   static_assert(std::is_pod<T>::value,
                 "T is required to be a plain old data type");
 
-  T* First;
-  T* Last;
-  T* Cap;
-  T Inline[N];
+  T* First = nullptr;
+  T* Last = nullptr;
+  T* Cap = nullptr;
+  T Inline[N] = {0};
 
   bool isInline() const { return First == Inline; }
 
@@ -2167,10 +2363,36 @@
   // table.
   PODSmallVector<Node *, 32> Subs;
 
+  using TemplateParamList = PODSmallVector<Node *, 8>;
+
+  class ScopedTemplateParamList {
+    AbstractManglingParser *Parser;
+    size_t OldNumTemplateParamLists;
+    TemplateParamList Params;
+
+  public:
+    ScopedTemplateParamList(AbstractManglingParser *TheParser)
+        : Parser(TheParser),
+          OldNumTemplateParamLists(TheParser->TemplateParams.size()) {
+      Parser->TemplateParams.push_back(&Params);
+    }
+    ~ScopedTemplateParamList() {
+      assert(Parser->TemplateParams.size() >= OldNumTemplateParamLists);
+      Parser->TemplateParams.dropBack(OldNumTemplateParamLists);
+    }
+  };
+
   // Template parameter table. Like the above, but referenced like "T42_".
   // This has a smaller size compared to Subs and Names because it can be
   // stored on the stack.
-  PODSmallVector<Node *, 8> TemplateParams;
+  TemplateParamList OuterTemplateParams;
+
+  // Lists of template parameters indexed by template parameter depth,
+  // referenced like "TL2_4_". If nonempty, element 0 is always
+  // OuterTemplateParams; inner elements are always template parameter lists of
+  // lambda expressions. For a generic lambda with no explicit template
+  // parameter list, the corresponding parameter list pointer will be null.
+  PODSmallVector<TemplateParamList *, 4> TemplateParams;
 
   // Set of unresolved forward <template-param> references. These can occur in a
   // conversion operator's type, and are resolved in the enclosing <encoding>.
@@ -2178,7 +2400,9 @@
 
   bool TryToParseTemplateArgs = true;
   bool PermitForwardTemplateReferences = false;
-  bool ParsingLambdaParams = false;
+  size_t ParsingLambdaParamsAtLevel = (size_t)-1;
+
+  unsigned NumSyntheticTemplateParameters[3] = {};
 
   Alloc ASTAllocator;
 
@@ -2193,9 +2417,11 @@
     Names.clear();
     Subs.clear();
     TemplateParams.clear();
-    ParsingLambdaParams = false;
+    ParsingLambdaParamsAtLevel = (size_t)-1;
     TryToParseTemplateArgs = true;
     PermitForwardTemplateReferences = false;
+    for (int I = 0; I != 3; ++I)
+      NumSyntheticTemplateParameters[I] = 0;
     ASTAllocator.reset();
   }
 
@@ -2253,6 +2479,7 @@
   bool parseSeqId(size_t *Out);
   Node *parseSubstitution();
   Node *parseTemplateParam();
+  Node *parseTemplateParamDecl();
   Node *parseTemplateArgs(bool TagTemplates = false);
   Node *parseTemplateArg();
 
@@ -2268,6 +2495,8 @@
   Node *parseConversionExpr();
   Node *parseBracedExpr();
   Node *parseFoldExpr();
+  Node *parsePointerToMemberConversionExpr();
+  Node *parseSubobjectExpr();
 
   /// Parse the <type> production.
   Node *parseType();
@@ -2301,9 +2530,10 @@
     size_t E = ForwardTemplateRefs.size();
     for (; I < E; ++I) {
       size_t Idx = ForwardTemplateRefs[I]->Index;
-      if (Idx >= TemplateParams.size())
+      if (TemplateParams.empty() || !TemplateParams[0] ||
+          Idx >= TemplateParams[0]->size())
         return true;
-      ForwardTemplateRefs[I]->Ref = TemplateParams[Idx];
+      ForwardTemplateRefs[I]->Ref = (*TemplateParams[0])[Idx];
     }
     ForwardTemplateRefs.dropBack(State.ForwardTemplateRefsBegin);
     return false;
@@ -2470,7 +2700,12 @@
 // <lambda-sig> ::= <parameter type>+  # Parameter types or "v" if the lambda has no parameters
 template <typename Derived, typename Alloc>
 Node *
-AbstractManglingParser<Derived, Alloc>::parseUnnamedTypeName(NameState *) {
+AbstractManglingParser<Derived, Alloc>::parseUnnamedTypeName(NameState *State) {
+  // <template-params> refer to the innermost <template-args>. Clear out any
+  // outer args that we may have inserted into TemplateParams.
+  if (State != nullptr)
+    TemplateParams.clear();
+
   if (consumeIf("Ut")) {
     StringView Count = parseNumber();
     if (!consumeIf('_'))
@@ -2478,22 +2713,59 @@
     return make<UnnamedTypeName>(Count);
   }
   if (consumeIf("Ul")) {
-    NodeArray Params;
-    SwapAndRestore<bool> SwapParams(ParsingLambdaParams, true);
+    SwapAndRestore<size_t> SwapParams(ParsingLambdaParamsAtLevel,
+                                      TemplateParams.size());
+    ScopedTemplateParamList LambdaTemplateParams(this);
+
+    size_t ParamsBegin = Names.size();
+    while (look() == 'T' &&
+           StringView("yptn").find(look(1)) != StringView::npos) {
+      Node *T = parseTemplateParamDecl();
+      if (!T)
+        return nullptr;
+      Names.push_back(T);
+    }
+    NodeArray TempParams = popTrailingNodeArray(ParamsBegin);
+
+    // FIXME: If TempParams is empty and none of the function parameters
+    // includes 'auto', we should remove LambdaTemplateParams from the
+    // TemplateParams list. Unfortunately, we don't find out whether there are
+    // any 'auto' parameters until too late in an example such as:
+    //
+    //   template<typename T> void f(
+    //       decltype([](decltype([]<typename T>(T v) {}),
+    //                   auto) {})) {}
+    //   template<typename T> void f(
+    //       decltype([](decltype([]<typename T>(T w) {}),
+    //                   int) {})) {}
+    //
+    // Here, the type of v is at level 2 but the type of w is at level 1. We
+    // don't find this out until we encounter the type of the next parameter.
+    //
+    // However, compilers can't actually cope with the former example in
+    // practice, and it's likely to be made ill-formed in future, so we don't
+    // need to support it here.
+    //
+    // If we encounter an 'auto' in the function parameter types, we will
+    // recreate a template parameter scope for it, but any intervening lambdas
+    // will be parsed in the 'wrong' template parameter depth.
+    if (TempParams.empty())
+      TemplateParams.pop_back();
+
     if (!consumeIf("vE")) {
-      size_t ParamsBegin = Names.size();
       do {
         Node *P = getDerived().parseType();
         if (P == nullptr)
           return nullptr;
         Names.push_back(P);
       } while (!consumeIf('E'));
-      Params = popTrailingNodeArray(ParamsBegin);
     }
+    NodeArray Params = popTrailingNodeArray(ParamsBegin);
+
     StringView Count = parseNumber();
     if (!consumeIf('_'))
       return nullptr;
-    return make<ClosureTypeName>(Params, Count);
+    return make<ClosureTypeName>(TempParams, Params, Count);
   }
   if (consumeIf("Ub")) {
     (void)parseNumber();
@@ -3300,7 +3572,9 @@
   if (!consumeIf("Dv"))
     return nullptr;
   if (look() >= '1' && look() <= '9') {
-    StringView DimensionNumber = parseNumber();
+    Node *DimensionNumber = make<NameType>(parseNumber());
+    if (!DimensionNumber)
+      return nullptr;
     if (!consumeIf('_'))
       return nullptr;
     if (consumeIf('p'))
@@ -3325,7 +3599,7 @@
   Node *ElemType = getDerived().parseType();
   if (!ElemType)
     return nullptr;
-  return make<VectorType>(ElemType, StringView());
+  return make<VectorType>(ElemType, /*Dimension=*/nullptr);
 }
 
 // <decltype>  ::= Dt <expression> E  # decltype of an id-expression or class member access (C++0x)
@@ -3351,10 +3625,12 @@
   if (!consumeIf('A'))
     return nullptr;
 
-  NodeOrString Dimension;
+  Node *Dimension = nullptr;
 
   if (std::isdigit(look())) {
-    Dimension = parseNumber();
+    Dimension = make<NameType>(parseNumber());
+    if (!Dimension)
+      return nullptr;
     if (!consumeIf('_'))
       return nullptr;
   } else if (!consumeIf('_')) {
@@ -3852,8 +4128,11 @@
 //                  ::= fp <top-level CV-Qualifiers> <parameter-2 non-negative number> _   # L == 0, second and later parameters
 //                  ::= fL <L-1 non-negative number> p <top-level CV-Qualifiers> _         # L > 0, first parameter
 //                  ::= fL <L-1 non-negative number> p <top-level CV-Qualifiers> <parameter-2 non-negative number> _   # L > 0, second and later parameters
+//                  ::= fpT      # 'this' expression (not part of standard?)
 template <typename Derived, typename Alloc>
 Node *AbstractManglingParser<Derived, Alloc>::parseFunctionParam() {
+  if (consumeIf("fpT"))
+    return make<NameType>("this");
   if (consumeIf("fp")) {
     parseCVQualifiers();
     StringView Num = parseNumber();
@@ -3949,6 +4228,7 @@
 //                ::= L <type> <value float> E                           # floating literal
 //                ::= L <string type> E                                  # string literal
 //                ::= L <nullptr type> E                                 # nullptr literal (i.e., "LDnE")
+//                ::= L <lambda type> E                                  # lambda expression
 // FIXME:         ::= L <type> <real-part float> _ <imag-part float> E   # complex floating point literal (C 2000)
 //                ::= L <mangled-name> E                                 # external name
 template <typename Derived, typename Alloc>
@@ -4012,7 +4292,13 @@
     return getDerived().template parseFloatingLiteral<double>();
   case 'e':
     ++First;
+#if defined(__powerpc__) || defined(__s390__)
+    // Handle cases where long doubles encoded with e have the same size
+    // and representation as doubles.
+    return getDerived().template parseFloatingLiteral<double>();
+#else
     return getDerived().template parseFloatingLiteral<long double>();
+#endif
   case '_':
     if (consumeIf("_Z")) {
       Node *R = getDerived().parseEncoding();
@@ -4020,24 +4306,43 @@
         return R;
     }
     return nullptr;
+  case 'A': {
+    Node *T = getDerived().parseType();
+    if (T == nullptr)
+      return nullptr;
+    // FIXME: We need to include the string contents in the mangling.
+    if (consumeIf('E'))
+      return make<StringLiteral>(T);
+    return nullptr;
+  }
+  case 'D':
+    if (consumeIf("DnE"))
+      return make<NameType>("nullptr");
+    return nullptr;
   case 'T':
     // Invalid mangled name per
     //   http://sourcerytools.com/pipermail/cxx-abi-dev/2011-August/002422.html
     return nullptr;
+  case 'U': {
+    // FIXME: Should we support LUb... for block literals?
+    if (look(1) != 'l')
+      return nullptr;
+    Node *T = parseUnnamedTypeName(nullptr);
+    if (!T || !consumeIf('E'))
+      return nullptr;
+    return make<LambdaExpr>(T);
+  }
   default: {
     // might be named type
     Node *T = getDerived().parseType();
     if (T == nullptr)
       return nullptr;
-    StringView N = parseNumber();
-    if (!N.empty()) {
-      if (!consumeIf('E'))
-        return nullptr;
-      return make<IntegerCastExpr>(T, N);
-    }
-    if (consumeIf('E'))
-      return T;
-    return nullptr;
+    StringView N = parseNumber(/*AllowNegative=*/true);
+    if (N.empty())
+      return nullptr;
+    if (!consumeIf('E'))
+      return nullptr;
+    return make<EnumLiteral>(T, N);
   }
   }
 }
@@ -4159,6 +4464,50 @@
   return make<FoldExpr>(IsLeftFold, OperatorName, Pack, Init);
 }
 
+// <expression> ::= mc <parameter type> <expr> [<offset number>] E
+//
+// Not yet in the spec: https://github.com/itanium-cxx-abi/cxx-abi/issues/47
+template <typename Derived, typename Alloc>
+Node *AbstractManglingParser<Derived, Alloc>::parsePointerToMemberConversionExpr() {
+  Node *Ty = getDerived().parseType();
+  if (!Ty)
+    return nullptr;
+  Node *Expr = getDerived().parseExpr();
+  if (!Expr)
+    return nullptr;
+  StringView Offset = getDerived().parseNumber(true);
+  if (!consumeIf('E'))
+    return nullptr;
+  return make<PointerToMemberConversionExpr>(Ty, Expr, Offset);
+}
+
+// <expression> ::= so <referent type> <expr> [<offset number>] <union-selector>* [p] E
+// <union-selector> ::= _ [<number>]
+//
+// Not yet in the spec: https://github.com/itanium-cxx-abi/cxx-abi/issues/47
+template <typename Derived, typename Alloc>
+Node *AbstractManglingParser<Derived, Alloc>::parseSubobjectExpr() {
+  Node *Ty = getDerived().parseType();
+  if (!Ty)
+    return nullptr;
+  Node *Expr = getDerived().parseExpr();
+  if (!Expr)
+    return nullptr;
+  StringView Offset = getDerived().parseNumber(true);
+  size_t SelectorsBegin = Names.size();
+  while (consumeIf('_')) {
+    Node *Selector = make<NameType>(parseNumber());
+    if (!Selector)
+      return nullptr;
+    Names.push_back(Selector);
+  }
+  bool OnePastTheEnd = consumeIf('p');
+  if (!consumeIf('E'))
+    return nullptr;
+  return make<SubobjectExpr>(
+      Ty, Expr, Offset, popTrailingNodeArray(SelectorsBegin), OnePastTheEnd);
+}
+
 // <expression> ::= <unary operator-name> <expression>
 //              ::= <binary operator-name> <expression> <expression>
 //              ::= <ternary operator-name> <expression> <expression> <expression>
@@ -4416,6 +4765,9 @@
     return nullptr;
   case 'm':
     switch (First[1]) {
+    case 'c':
+      First += 2;
+      return parsePointerToMemberConversionExpr();
     case 'i':
       First += 2;
       return getDerived().parseBinaryExpr("-");
@@ -4563,6 +4915,9 @@
         return Ex;
       return make<CastExpr>("static_cast", T, Ex);
     }
+    case 'o':
+      First += 2;
+      return parseSubobjectExpr();
     case 'p': {
       First += 2;
       Node *Child = getDerived().parseExpr();
@@ -4730,6 +5085,16 @@
   switch (look()) {
   case 'T':
     switch (look(1)) {
+    // TA <template-arg>    # template parameter object
+    //
+    // Not yet in the spec: https://github.com/itanium-cxx-abi/cxx-abi/issues/63
+    case 'A': {
+      First += 2;
+      Node *Arg = getDerived().parseTemplateArg();
+      if (Arg == nullptr)
+        return nullptr;
+      return make<SpecialName>("template parameter object for ", Arg);
+    }
     // TV <type>    # virtual table
     case 'V': {
       First += 2;
@@ -4851,6 +5216,22 @@
 //            ::= <special-name>
 template <typename Derived, typename Alloc>
 Node *AbstractManglingParser<Derived, Alloc>::parseEncoding() {
+  // The template parameters of an encoding are unrelated to those of the
+  // enclosing context.
+  class SaveTemplateParams {
+    AbstractManglingParser *Parser;
+    decltype(TemplateParams) OldParams;
+
+  public:
+    SaveTemplateParams(AbstractManglingParser *TheParser) : Parser(TheParser) {
+      OldParams = std::move(Parser->TemplateParams);
+      Parser->TemplateParams.clear();
+    }
+    ~SaveTemplateParams() {
+      Parser->TemplateParams = std::move(OldParams);
+    }
+  } SaveTemplateParams(this);
+
   if (look() == 'G' || look() == 'T')
     return getDerived().parseSpecialName();
 
@@ -4942,7 +5323,12 @@
 #else
     static const size_t mangled_size = 20;  // May need to be adjusted to 16 or 24 on other platforms
 #endif
-    static const size_t max_demangled_size = 40;
+    // `-0x1.ffffffffffffffffffffffffffffp+16383` + 'L' + '\0' == 42 bytes.
+    // 28 'f's * 4 bits == 112 bits, which is the number of mantissa bits.
+    // Negatives are one character longer than positives.
+    // `0x1.` and `p` are constant, and exponents `+16383` and `-16382` are the
+    // same length. 1 sign bit, 112 mantissa bits, and 15 exponent bits == 128.
+    static const size_t max_demangled_size = 42;
     static constexpr const char *spec = "%LaL";
 };
 
@@ -5062,11 +5448,22 @@
 
 // <template-param> ::= T_    # first template parameter
 //                  ::= T <parameter-2 non-negative number> _
+//                  ::= TL <level-1> __
+//                  ::= TL <level-1> _ <parameter-2 non-negative number> _
 template <typename Derived, typename Alloc>
 Node *AbstractManglingParser<Derived, Alloc>::parseTemplateParam() {
   if (!consumeIf('T'))
     return nullptr;
 
+  size_t Level = 0;
+  if (consumeIf('L')) {
+    if (parsePositiveInteger(&Level))
+      return nullptr;
+    ++Level;
+    if (!consumeIf('_'))
+      return nullptr;
+  }
+
   size_t Index = 0;
   if (!consumeIf('_')) {
     if (parsePositiveInteger(&Index))
@@ -5076,15 +5473,11 @@
       return nullptr;
   }
 
-  // Itanium ABI 5.1.8: In a generic lambda, uses of auto in the parameter list
-  // are mangled as the corresponding artificial template type parameter.
-  if (ParsingLambdaParams)
-    return make<NameType>("auto");
-
   // If we're in a context where this <template-param> refers to a
   // <template-arg> further ahead in the mangled name (currently just conversion
   // operator types), then we should only look it up in the right context.
-  if (PermitForwardTemplateReferences) {
+  // This can only happen at the outermost level.
+  if (PermitForwardTemplateReferences && Level == 0) {
     Node *ForwardRef = make<ForwardTemplateReference>(Index);
     if (!ForwardRef)
       return nullptr;
@@ -5094,9 +5487,78 @@
     return ForwardRef;
   }
 
-  if (Index >= TemplateParams.size())
+  if (Level >= TemplateParams.size() || !TemplateParams[Level] ||
+      Index >= TemplateParams[Level]->size()) {
+    // Itanium ABI 5.1.8: In a generic lambda, uses of auto in the parameter
+    // list are mangled as the corresponding artificial template type parameter.
+    if (ParsingLambdaParamsAtLevel == Level && Level <= TemplateParams.size()) {
+      // This will be popped by the ScopedTemplateParamList in
+      // parseUnnamedTypeName.
+      if (Level == TemplateParams.size())
+        TemplateParams.push_back(nullptr);
+      return make<NameType>("auto");
+    }
+
     return nullptr;
-  return TemplateParams[Index];
+  }
+
+  return (*TemplateParams[Level])[Index];
+}
+
+// <template-param-decl> ::= Ty                          # type parameter
+//                       ::= Tn <type>                   # non-type parameter
+//                       ::= Tt <template-param-decl>* E # template parameter
+//                       ::= Tp <template-param-decl>    # parameter pack
+template <typename Derived, typename Alloc>
+Node *AbstractManglingParser<Derived, Alloc>::parseTemplateParamDecl() {
+  auto InventTemplateParamName = [&](TemplateParamKind Kind) {
+    unsigned Index = NumSyntheticTemplateParameters[(int)Kind]++;
+    Node *N = make<SyntheticTemplateParamName>(Kind, Index);
+    if (N) TemplateParams.back()->push_back(N);
+    return N;
+  };
+
+  if (consumeIf("Ty")) {
+    Node *Name = InventTemplateParamName(TemplateParamKind::Type);
+    if (!Name)
+      return nullptr;
+    return make<TypeTemplateParamDecl>(Name);
+  }
+
+  if (consumeIf("Tn")) {
+    Node *Name = InventTemplateParamName(TemplateParamKind::NonType);
+    if (!Name)
+      return nullptr;
+    Node *Type = parseType();
+    if (!Type)
+      return nullptr;
+    return make<NonTypeTemplateParamDecl>(Name, Type);
+  }
+
+  if (consumeIf("Tt")) {
+    Node *Name = InventTemplateParamName(TemplateParamKind::Template);
+    if (!Name)
+      return nullptr;
+    size_t ParamsBegin = Names.size();
+    ScopedTemplateParamList TemplateTemplateParamParams(this);
+    while (!consumeIf("E")) {
+      Node *P = parseTemplateParamDecl();
+      if (!P)
+        return nullptr;
+      Names.push_back(P);
+    }
+    NodeArray Params = popTrailingNodeArray(ParamsBegin);
+    return make<TemplateTemplateParamDecl>(Name, Params);
+  }
+
+  if (consumeIf("Tp")) {
+    Node *P = parseTemplateParamDecl();
+    if (!P)
+      return nullptr;
+    return make<TemplateParamPackDecl>(P);
+  }
+
+  return nullptr;
 }
 
 // <template-arg> ::= <type>                    # type or template
@@ -5153,8 +5615,11 @@
 
   // <template-params> refer to the innermost <template-args>. Clear out any
   // outer args that we may have inserted into TemplateParams.
-  if (TagTemplates)
+  if (TagTemplates) {
     TemplateParams.clear();
+    TemplateParams.push_back(&OuterTemplateParams);
+    OuterTemplateParams.clear();
+  }
 
   size_t ArgsBegin = Names.size();
   while (!consumeIf('E')) {
@@ -5172,7 +5637,7 @@
         if (!TableEntry)
           return nullptr;
       }
-      TemplateParams.push_back(TableEntry);
+      TemplateParams.back()->push_back(TableEntry);
     } else {
       Node *Arg = getDerived().parseTemplateArg();
       if (Arg == nullptr)
diff --git a/linux-x64/clang/include/llvm/Demangle/MicrosoftDemangle.h b/linux-x64/clang/include/llvm/Demangle/MicrosoftDemangle.h
index 382e794..c6f2606 100644
--- a/linux-x64/clang/include/llvm/Demangle/MicrosoftDemangle.h
+++ b/linux-x64/clang/include/llvm/Demangle/MicrosoftDemangle.h
@@ -158,6 +158,7 @@
                                     QualifiedNameNode *QN);
   SymbolNode *demangleDeclarator(StringView &MangledName);
   SymbolNode *demangleMD5Name(StringView &MangledName);
+  SymbolNode *demangleTypeinfoName(StringView &MangledName);
 
   VariableSymbolNode *demangleVariableEncoding(StringView &MangledName,
                                                StorageClass SC);
diff --git a/linux-x64/clang/include/llvm/Demangle/MicrosoftDemangleNodes.h b/linux-x64/clang/include/llvm/Demangle/MicrosoftDemangleNodes.h
index da9d9d5..62e0f47 100644
--- a/linux-x64/clang/include/llvm/Demangle/MicrosoftDemangleNodes.h
+++ b/linux-x64/clang/include/llvm/Demangle/MicrosoftDemangleNodes.h
@@ -16,6 +16,8 @@
 #include "llvm/Demangle/DemangleConfig.h"
 #include "llvm/Demangle/StringView.h"
 #include <array>
+#include <cstdint>
+#include <string>
 
 namespace llvm {
 namespace itanium_demangle {
@@ -73,6 +75,9 @@
   OF_Default = 0,
   OF_NoCallingConvention = 1,
   OF_NoTagSpecifier = 2,
+  OF_NoAccessSpecifier = 4,
+  OF_NoMemberType = 8,
+  OF_NoReturnType = 16,
 };
 
 // Types
@@ -301,8 +306,6 @@
     outputPost(OS, Flags);
   }
 
-  void outputQuals(bool SpaceBefore, bool SpaceAfter) const;
-
   Qualifiers Quals = Q_None;
 };
 
@@ -310,8 +313,8 @@
   explicit PrimitiveTypeNode(PrimitiveKind K)
       : TypeNode(NodeKind::PrimitiveType), PrimKind(K) {}
 
-  void outputPre(OutputStream &OS, OutputFlags Flags) const;
-  void outputPost(OutputStream &OS, OutputFlags Flags) const {}
+  void outputPre(OutputStream &OS, OutputFlags Flags) const override;
+  void outputPost(OutputStream &OS, OutputFlags Flags) const override {}
 
   PrimitiveKind PrimKind;
 };
@@ -471,8 +474,8 @@
 struct TagTypeNode : public TypeNode {
   explicit TagTypeNode(TagKind Tag) : TypeNode(NodeKind::TagType), Tag(Tag) {}
 
-  void outputPre(OutputStream &OS, OutputFlags Flags) const;
-  void outputPost(OutputStream &OS, OutputFlags Flags) const;
+  void outputPre(OutputStream &OS, OutputFlags Flags) const override;
+  void outputPost(OutputStream &OS, OutputFlags Flags) const override;
 
   QualifiedNameNode *QualifiedName = nullptr;
   TagKind Tag;
@@ -481,8 +484,8 @@
 struct ArrayTypeNode : public TypeNode {
   ArrayTypeNode() : TypeNode(NodeKind::ArrayType) {}
 
-  void outputPre(OutputStream &OS, OutputFlags Flags) const;
-  void outputPost(OutputStream &OS, OutputFlags Flags) const;
+  void outputPre(OutputStream &OS, OutputFlags Flags) const override;
+  void outputPost(OutputStream &OS, OutputFlags Flags) const override;
 
   void outputDimensionsImpl(OutputStream &OS, OutputFlags Flags) const;
   void outputOneDimension(OutputStream &OS, OutputFlags Flags, Node *N) const;
@@ -505,7 +508,7 @@
   void outputPre(OutputStream &OS, OutputFlags Flags) const override;
   void outputPost(OutputStream &OS, OutputFlags Flags) const override;
 
-  IdentifierNode *Identifier;
+  IdentifierNode *Identifier = nullptr;
 };
 
 struct NodeArrayNode : public Node {
@@ -581,7 +584,7 @@
 
   void output(OutputStream &OS, OutputFlags Flags) const override;
   QualifiedNameNode *TargetName = nullptr;
-  Qualifiers Quals;
+  Qualifiers Quals = Qualifiers::Q_None;
 };
 
 struct LocalStaticGuardVariableNode : public SymbolNode {
diff --git a/linux-x64/clang/include/llvm/Demangle/Utility.h b/linux-x64/clang/include/llvm/Demangle/Utility.h
index ec23859..846a5f0 100644
--- a/linux-x64/clang/include/llvm/Demangle/Utility.h
+++ b/linux-x64/clang/include/llvm/Demangle/Utility.h
@@ -25,9 +25,9 @@
 // Stream that AST nodes write their string representation into after the AST
 // has been parsed.
 class OutputStream {
-  char *Buffer;
-  size_t CurrentPosition;
-  size_t BufferCapacity;
+  char *Buffer = nullptr;
+  size_t CurrentPosition = 0;
+  size_t BufferCapacity = 0;
 
   // Ensure there is at least n more positions in buffer.
   void grow(size_t N) {
@@ -52,7 +52,7 @@
     char *TempPtr = std::end(Temp);
 
     while (N) {
-      *--TempPtr = '0' + char(N % 10);
+      *--TempPtr = char('0' + N % 10);
       N /= 10;
     }
 
@@ -137,7 +137,7 @@
 
   char *getBuffer() { return Buffer; }
   char *getBufferEnd() { return Buffer + CurrentPosition - 1; }
-  size_t getBufferCapacity() { return BufferCapacity; }
+  size_t getBufferCapacity() const { return BufferCapacity; }
 };
 
 template <class T> class SwapAndRestore {