Author: Michael Buch
Date: 2026-01-06T10:57:59Z
New Revision: 4ef641916408521dee857ddd3a643248a6e0d22a

URL: 
https://github.com/llvm/llvm-project/commit/4ef641916408521dee857ddd3a643248a6e0d22a
DIFF: 
https://github.com/llvm/llvm-project/commit/4ef641916408521dee857ddd3a643248a6e0d22a.diff

LOG: [clang][TypePrinter] Unify printing of anonymous/unnamed tag types 
(#169445)

In https://github.com/llvm/llvm-project/pull/168534 we made the
`TypePrinter` re-use `printNestedNameSpecifier` for printing scopes.
However, the way that the names of anonymous/unnamed types get printed
by the two are slightly inconsistent with each other.

`printNestedNameSpecifier` calls all `TagType`s without an identifer
`(anonymous)`. On the other hand, `TypePrinter` prints them slightly
more accurate (it differentiates anonymous vs. unnamed decls) and allows
for some additional customization points. E.g., with `MSVCFormatting`,
it will print `` `unnamed struct'`` instead of `(unnamed struct)`.
`printNestedNameSpecifier` already accounts for `MSVCFormatting` for
namespaces, but doesn't for `TagType`s. This inconsistency means that if
an unnamed tag is printed as part of a scope then it's displayed as
`(anonymous struct)`, but if it's the entity whose scope is being
printed, then it shows as `(unnamed struct)`.

This patch moves the printing of anonymous/unnamed tags into
`TagDecl::printName`. All the callsites that previously printed
anonymous tag decls now call `printName` to handle it. To preserve the
behaviour of not printing the kind name (i.e., `struct`/`class`/`enum`)
when printing the inner type of an elaborated type (i.e., avoiding
`struct (unnamed struct)`), this patch adds a
`PrintingPolicy::SuppressTagKeywordInAnonNames` that is appropriately
set when we want to suppress the tag keyword inside the anonymous name.
I had to make sure we set this bit to `false` when printing
nested-name-specifiers because we always want the tag keyword there
(e.g., `foo::(anonymous struct)::bar`) and for a `clangd` special case
which is described in a comment in the source.

**Test changes**

Mostly we now more accurately print the kind name of anonymous entities.
So there's a lot of `anonymous` -> `unnamed` changes. There are a
handful of `clangd` tests where the name of the entity is now `(unnamed
struct)` instead of just `(unnamed)`. That should be consistent with how
we choose to omit the tag keyword elsewhere. Since we're just printing
the name of the entity here, we include the kind tag.

Added: 
    

Modified: 
    clang-tools-extra/clangd/Hover.cpp
    clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
    clang-tools-extra/clangd/unittests/FindTargetTests.cpp
    clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
    clang/include/clang/AST/Decl.h
    clang/include/clang/AST/PrettyPrinter.h
    clang/lib/AST/Decl.cpp
    clang/lib/AST/TypePrinter.cpp
    clang/lib/ASTMatchers/ASTMatchersInternal.cpp
    clang/test/AST/HLSL/cbuffer.hlsl
    clang/test/AST/ast-dump-decl-json.c
    clang/test/AST/ast-dump-records-json.cpp
    clang/test/AST/ast-dump-records.c
    clang/test/AST/ast-dump-records.cpp
    clang/test/ASTMerge/struct/test.c
    clang/test/Analysis/Inputs/expected-plists/lambda-notes.cpp.plist
    clang/test/Analysis/analyzer-note-analysis-entry-points.cpp
    clang/test/Analysis/bug_hash_test.cpp
    clang/test/Analysis/cfg.cpp
    clang/test/Analysis/debug-CallGraph.cpp
    clang/test/Analysis/inlining/Inputs/expected-plists/path-notes.cpp.plist
    clang/test/C/C23/n3006.c
    clang/test/C/C23/n3037.c
    clang/test/CodeGen/block-with-perdefinedexpr.cpp
    clang/test/CodeGenCXX/predefined-expr.cpp
    clang/test/Index/print-type.c
    clang/test/Layout/ms-x86-alias-avoidance-padding.cpp
    clang/test/Sema/assign.c
    clang/test/Sema/switch.c
    clang/test/SemaCXX/builtin-bswapg.cpp
    clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
    clang/test/SemaCXX/cxx1z-decomposition.cpp
    clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
    clang/test/SemaCXX/predefined-expr.cpp
    clang/test/SemaCXX/undefined-internal.cpp
    clang/test/SemaObjCXX/arc-0x.mm
    clang/unittests/AST/NamedDeclPrinterTest.cpp
    clang/unittests/AST/TypePrinterTest.cpp
    clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
    clang/unittests/Tooling/QualTypeNamesTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 34369e188d4ec..bcf72255423bc 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -176,19 +176,22 @@ HoverInfo::PrintedType printType(QualType QT, ASTContext 
&ASTCtx,
   // tag for extra clarity. This isn't very idiomatic, so don't attempt it for
   // complex cases, including pointers/references, template specializations,
   // etc.
+  PrintingPolicy Copy(PP);
   if (!QT.isNull() && !QT.hasQualifiers() && PP.SuppressTagKeyword) {
     if (auto *TT = llvm::dyn_cast<TagType>(QT.getTypePtr());
-        TT && TT->isCanonicalUnqualified())
+        TT && TT->isCanonicalUnqualified()) {
+      Copy.SuppressTagKeywordInAnonNames = true;
       OS << TT->getDecl()->getKindName() << " ";
+    }
   }
-  QT.print(OS, PP);
+  QT.print(OS, Copy);
 
   const Config &Cfg = Config::current();
   if (!QT.isNull() && Cfg.Hover.ShowAKA) {
     bool ShouldAKA = false;
     QualType DesugaredTy = clang::desugarForDiagnostic(ASTCtx, QT, ShouldAKA);
     if (ShouldAKA)
-      Result.AKA = DesugaredTy.getAsString(PP);
+      Result.AKA = DesugaredTy.getAsString(Copy);
   }
   return Result;
 }

diff  --git a/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp 
b/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
index 5b1630eb00cb1..d6e94bf752452 100644
--- a/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -106,7 +106,7 @@ TEST(WorkspaceSymbols, Unnamed) {
               ElementsAre(AllOf(qName("UnnamedStruct"),
                                 withKind(SymbolKind::Variable))));
   EXPECT_THAT(getSymbols(TU, "InUnnamed"),
-              ElementsAre(AllOf(qName("(anonymous struct)::InUnnamed"),
+              ElementsAre(AllOf(qName("(unnamed struct)::InUnnamed"),
                                 withKind(SymbolKind::Field))));
 }
 
@@ -656,15 +656,16 @@ TEST(DocumentSymbols, Enums) {
       getSymbols(TU.build()),
       ElementsAre(
           AllOf(withName("(anonymous enum)"), withDetail("enum"),
-                children(AllOf(withName("Red"), withDetail("(unnamed)")))),
+                children(AllOf(withName("Red"), withDetail("(unnamed 
enum)")))),
           AllOf(withName("Color"), withDetail("enum"),
                 children(AllOf(withName("Green"), withDetail("Color")))),
           AllOf(withName("Color2"), withDetail("enum"),
                 children(AllOf(withName("Yellow"), withDetail("Color2")))),
-          AllOf(withName("ns"),
-                children(AllOf(withName("(anonymous enum)"), 
withDetail("enum"),
-                               children(AllOf(withName("Black"),
-                                              withDetail("(unnamed)"))))))));
+          AllOf(
+              withName("ns"),
+              children(AllOf(withName("(anonymous enum)"), withDetail("enum"),
+                             children(AllOf(withName("Black"),
+                                            withDetail("(unnamed 
enum)"))))))));
 }
 
 TEST(DocumentSymbols, Macro) {

diff  --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index dd26182630ae1..6aee310208e5c 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -1827,7 +1827,7 @@ TEST_F(FindExplicitReferencesTest, AllRefsInFoo) {
               int (*$2^fptr)(int $3^a, int) = nullptr;
              }
            )cpp",
-           "0: targets = {(unnamed)}\n"
+           "0: targets = {(unnamed class)}\n"
            "1: targets = {x}, decl\n"
            "2: targets = {fptr}, decl\n"
            "3: targets = {a}, decl\n"},

diff  --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp 
b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
index 1ce28c91a420c..94116fca3cbb2 100644
--- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -1470,8 +1470,8 @@ TEST_F(SymbolCollectorTest, NamelessSymbols) {
     } Foo;
   )";
   runSymbolCollector(Header, /*Main=*/"");
-  EXPECT_THAT(Symbols, UnorderedElementsAre(qName("Foo"),
-                                            qName("(anonymous struct)::a")));
+  EXPECT_THAT(Symbols,
+              UnorderedElementsAre(qName("Foo"), qName("(unnamed 
struct)::a")));
 }
 
 TEST_F(SymbolCollectorTest, SymbolFormedFromRegisteredSchemeFromMacro) {

diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 2e8ceff453547..5c46c912186c4 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -3771,6 +3771,9 @@ class TagDecl : public TypeDecl,
   /// True if this decl is currently being defined.
   void setBeingDefined(bool V = true) { TagDeclBits.IsBeingDefined = V; }
 
+  void printAnonymousTagDecl(llvm::raw_ostream &OS,
+                             const PrintingPolicy &Policy) const;
+
 public:
   friend class ASTDeclReader;
   friend class ASTDeclWriter;

diff  --git a/clang/include/clang/AST/PrettyPrinter.h 
b/clang/include/clang/AST/PrettyPrinter.h
index 48105b3b9d4cd..2ede8da209748 100644
--- a/clang/include/clang/AST/PrettyPrinter.h
+++ b/clang/include/clang/AST/PrettyPrinter.h
@@ -61,8 +61,9 @@ struct PrintingPolicy {
   /// Create a default printing policy for the specified language.
   PrintingPolicy(const LangOptions &LO)
       : Indentation(2), SuppressSpecifiers(false),
-        SuppressTagKeyword(LO.CPlusPlus), IncludeTagDefinition(false),
-        SuppressScope(false), SuppressUnwrittenScope(false),
+        SuppressTagKeyword(LO.CPlusPlus), SuppressTagKeywordInAnonNames(false),
+        IncludeTagDefinition(false), SuppressScope(false),
+        SuppressUnwrittenScope(false),
         SuppressInlineNamespace(
             llvm::to_underlying(SuppressInlineNamespaceMode::Redundant)),
         SuppressInitializers(false), ConstantArraySizeAsWritten(false),
@@ -124,6 +125,15 @@ struct PrintingPolicy {
   LLVM_PREFERRED_TYPE(bool)
   unsigned SuppressTagKeyword : 1;
 
+  /// Whether type printing should skip printing the tag keyword
+  /// of anonymous entities. E.g.,
+  ///
+  /// * \c (anonymous) as opopsed to (anonymous struct)
+  /// * \c (unnamed) as opposed to (unnamed enum)
+  ///
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned SuppressTagKeywordInAnonNames : 1;
+
   /// When true, include the body of a tag definition.
   ///
   /// This is used to place the definition of a struct

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index b12f042646bbb..66c625f41158a 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -1791,13 +1791,17 @@ void NamedDecl::printNestedNameSpecifier(raw_ostream 
&OS,
       }
       else
         OS << *ND;
-    } else if (const auto *RD = dyn_cast<RecordDecl>(DC)) {
-      if (TypedefNameDecl *TD = RD->getTypedefNameForAnonDecl())
-        OS << *TD;
-      else if (!RD->getIdentifier())
-        OS << "(anonymous " << RD->getKindName() << ')';
-      else
-        OS << *RD;
+    } else if (const auto *RD = llvm::dyn_cast<RecordDecl>(DC)) {
+      PrintingPolicy Copy(P);
+      // As part of a scope we want to print anonymous names as:
+      // ..::(anonymous struct)::..
+      //
+      // I.e., suppress tag locations, suppress leading keyword, *don't*
+      // suppress tag in name
+      Copy.SuppressTagKeyword = true;
+      Copy.SuppressTagKeywordInAnonNames = false;
+      Copy.AnonymousTagLocations = false;
+      RD->printName(OS, Copy);
     } else if (const auto *FD = dyn_cast<FunctionDecl>(DC)) {
       const FunctionProtoType *FT = nullptr;
       if (FD->hasWrittenPrototype())
@@ -4956,19 +4960,76 @@ void TagDecl::setQualifierInfo(NestedNameSpecifierLoc 
QualifierLoc) {
   }
 }
 
+void TagDecl::printAnonymousTagDecl(llvm::raw_ostream &OS,
+                                    const PrintingPolicy &Policy) const {
+  if (TypedefNameDecl *Typedef = getTypedefNameForAnonDecl()) {
+    assert(Typedef->getIdentifier() && "Typedef without identifier?");
+    OS << Typedef->getIdentifier()->getName();
+    return;
+  }
+
+  bool SuppressTagKeywordInName = Policy.SuppressTagKeywordInAnonNames;
+
+  // Emit leading keyword. Since we printed a leading keyword make sure we
+  // don't print the tag as part of the name too.
+  if (!Policy.SuppressTagKeyword) {
+    OS << getKindName() << ' ';
+    SuppressTagKeywordInName = true;
+  }
+
+  // Make an unambiguous representation for anonymous types, e.g.
+  //   (anonymous enum at /usr/include/string.h:120:9)
+  OS << (Policy.MSVCFormatting ? '`' : '(');
+
+  if (isa<CXXRecordDecl>(this) && cast<CXXRecordDecl>(this)->isLambda()) {
+    OS << "lambda";
+    SuppressTagKeywordInName = true;
+  } else if ((isa<RecordDecl>(this) &&
+              cast<RecordDecl>(this)->isAnonymousStructOrUnion())) {
+    OS << "anonymous";
+  } else {
+    OS << "unnamed";
+  }
+
+  if (!SuppressTagKeywordInName)
+    OS << ' ' << getKindName();
+
+  if (Policy.AnonymousTagLocations) {
+    PresumedLoc PLoc =
+        getASTContext().getSourceManager().getPresumedLoc(getLocation());
+    if (PLoc.isValid()) {
+      OS << " at ";
+      StringRef File = PLoc.getFilename();
+      llvm::SmallString<1024> WrittenFile(File);
+      if (auto *Callbacks = Policy.Callbacks)
+        WrittenFile = Callbacks->remapPath(File);
+      // Fix inconsistent path separator created by
+      // clang::DirectoryLookup::LookupFile when the file path is relative
+      // path.
+      llvm::sys::path::Style Style =
+          llvm::sys::path::is_absolute(WrittenFile)
+              ? llvm::sys::path::Style::native
+              : (Policy.MSVCFormatting
+                     ? llvm::sys::path::Style::windows_backslash
+                     : llvm::sys::path::Style::posix);
+      llvm::sys::path::native(WrittenFile, Style);
+      OS << WrittenFile << ':' << PLoc.getLine() << ':' << PLoc.getColumn();
+    }
+  }
+
+  OS << (Policy.MSVCFormatting ? '\'' : ')');
+}
+
 void TagDecl::printName(raw_ostream &OS, const PrintingPolicy &Policy) const {
   DeclarationName Name = getDeclName();
   // If the name is supposed to have an identifier but does not have one, then
   // the tag is anonymous and we should print it 
diff erently.
   if (Name.isIdentifier() && !Name.getAsIdentifierInfo()) {
-    // If the caller wanted to print a qualified name, they've already printed
-    // the scope. And if the caller doesn't want that, the scope information
-    // is already printed as part of the type.
-    PrintingPolicy Copy(Policy);
-    Copy.SuppressScope = true;
-    QualType(getASTContext().getCanonicalTagType(this)).print(OS, Copy);
+    printAnonymousTagDecl(OS, Policy);
+
     return;
   }
+
   // Otherwise, do the normal printing.
   Name.print(OS, Policy);
 }

diff  --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index c7ac9c2a2124f..5a0cbc47e7c1a 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -1518,18 +1518,19 @@ void TypePrinter::printTagType(const TagType *T, 
raw_ostream &OS) {
     return;
   }
 
-  bool HasKindDecoration = false;
-
+  bool PrintedKindDecoration = false;
   if (T->isCanonicalUnqualified()) {
     if (!Policy.SuppressTagKeyword && !D->getTypedefNameForAnonDecl()) {
-      HasKindDecoration = true;
+      PrintedKindDecoration = true;
       OS << D->getKindName();
       OS << ' ';
     }
   } else {
     OS << TypeWithKeyword::getKeywordName(T->getKeyword());
-    if (T->getKeyword() != ElaboratedTypeKeyword::None)
+    if (T->getKeyword() != ElaboratedTypeKeyword::None) {
+      PrintedKindDecoration = true;
       OS << ' ';
+    }
   }
 
   if (!Policy.FullyQualifiedName && !T->isCanonicalUnqualified()) {
@@ -1543,53 +1544,16 @@ void TypePrinter::printTagType(const TagType *T, 
raw_ostream &OS) {
 
   if (const IdentifierInfo *II = D->getIdentifier())
     OS << II->getName();
-  else if (TypedefNameDecl *Typedef = D->getTypedefNameForAnonDecl()) {
-    assert(Typedef->getIdentifier() && "Typedef without identifier?");
-    OS << Typedef->getIdentifier()->getName();
-  } else {
-    // Make an unambiguous representation for anonymous types, e.g.
-    //   (anonymous enum at /usr/include/string.h:120:9)
-    OS << (Policy.MSVCFormatting ? '`' : '(');
-
-    if (isa<CXXRecordDecl>(D) && cast<CXXRecordDecl>(D)->isLambda()) {
-      OS << "lambda";
-      HasKindDecoration = true;
-    } else if ((isa<RecordDecl>(D) && 
cast<RecordDecl>(D)->isAnonymousStructOrUnion())) {
-      OS << "anonymous";
-    } else {
-      OS << "unnamed";
-    }
+  else {
+    clang::PrintingPolicy Copy(Policy);
 
-    if (Policy.AnonymousTagLocations) {
-      // Suppress the redundant tag keyword if we just printed one.
-      // We don't have to worry about ElaboratedTypes here because you can't
-      // refer to an anonymous type with one.
-      if (!HasKindDecoration)
-        OS << " " << D->getKindName();
-
-      PresumedLoc PLoc = D->getASTContext().getSourceManager().getPresumedLoc(
-          D->getLocation());
-      if (PLoc.isValid()) {
-        OS << " at ";
-        StringRef File = PLoc.getFilename();
-        llvm::SmallString<1024> WrittenFile(File);
-        if (auto *Callbacks = Policy.Callbacks)
-          WrittenFile = Callbacks->remapPath(File);
-        // Fix inconsistent path separator created by
-        // clang::DirectoryLookup::LookupFile when the file path is relative
-        // path.
-        llvm::sys::path::Style Style =
-            llvm::sys::path::is_absolute(WrittenFile)
-                ? llvm::sys::path::Style::native
-                : (Policy.MSVCFormatting
-                       ? llvm::sys::path::Style::windows_backslash
-                       : llvm::sys::path::Style::posix);
-        llvm::sys::path::native(WrittenFile, Style);
-        OS << WrittenFile << ':' << PLoc.getLine() << ':' << PLoc.getColumn();
-      }
+    // Suppress the redundant tag keyword if we just printed one.
+    if (PrintedKindDecoration) {
+      Copy.SuppressTagKeywordInAnonNames = true;
+      Copy.SuppressTagKeyword = true;
     }
 
-    OS << (Policy.MSVCFormatting ? '\'' : ')');
+    D->printName(OS, Copy);
   }
 
   // If this is a class template specialization, print the template

diff  --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index a556ffca96903..31496f992d34b 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -514,7 +514,14 @@ static StringRef getNodeName(const RecordDecl &Node,
     return Node.getName();
   }
   Scratch.clear();
-  return ("(anonymous " + Node.getKindName() + ")").toStringRef(Scratch);
+
+  llvm::raw_svector_ostream OS(Scratch);
+
+  PrintingPolicy Copy(Node.getASTContext().getPrintingPolicy());
+  Copy.AnonymousTagLocations = false;
+  Node.printName(OS, Copy);
+
+  return OS.str();
 }
 
 static StringRef getNodeName(const NamespaceDecl &Node,

diff  --git a/clang/test/AST/HLSL/cbuffer.hlsl 
b/clang/test/AST/HLSL/cbuffer.hlsl
index b0b5b989e36c2..487261af19133 100644
--- a/clang/test/AST/HLSL/cbuffer.hlsl
+++ b/clang/test/AST/HLSL/cbuffer.hlsl
@@ -191,7 +191,7 @@ cbuffer CB {
     // CHECK: FieldDecl {{.*}} f 'RWBuffer<float>':'hlsl::RWBuffer<float>'
     RWBuffer<float> f;
   } s9;
-  // CHECK: VarDecl {{.*}} s9 'hlsl_constant struct (unnamed struct at 
{{.*}}cbuffer.hlsl:[[# @LINE - 8]]:3
+  // CHECK: VarDecl {{.*}} s9 'hlsl_constant struct (unnamed at 
{{.*}}cbuffer.hlsl:[[# @LINE - 8]]:3
   // CHECK: CXXRecordDecl {{.*}} struct definition
   struct {
     // CHECK: FieldDecl {{.*}} g 'float'
@@ -199,7 +199,7 @@ cbuffer CB {
     // CHECK: FieldDecl {{.*}} f 'RWBuffer<float>':'hlsl::RWBuffer<float>'
     RWBuffer<float> f;
   } s10;
-  // CHECK: VarDecl {{.*}} s10 'hlsl_constant struct (unnamed struct at 
{{.*}}cbuffer.hlsl:[[# @LINE - 6]]:3
+  // CHECK: VarDecl {{.*}} s10 'hlsl_constant struct (unnamed at 
{{.*}}cbuffer.hlsl:[[# @LINE - 6]]:3
   // CHECK: CXXRecordDecl {{.*}} implicit referenced struct __cblayout_anon 
definition
   // CHECK: PackedAttr
   // CHECK-NEXT: FieldDecl {{.*}} e 'float'

diff  --git a/clang/test/AST/ast-dump-decl-json.c 
b/clang/test/AST/ast-dump-decl-json.c
index b84ddf93f44c3..50eaaaffb52d9 100644
--- a/clang/test/AST/ast-dump-decl-json.c
+++ b/clang/test/AST/ast-dump-decl-json.c
@@ -585,7 +585,7 @@ void testParmVarDecl(int TestParmVarDecl);
 // CHECK-NEXT:    },
 // CHECK-NEXT:    "name": "e",
 // CHECK-NEXT:    "type": {
-// CHECK-NEXT:     "qualType": "enum (unnamed enum at {{.*}}:31:3)"
+// CHECK-NEXT:     "qualType": "enum (unnamed at {{.*}}:31:3)"
 // CHECK-NEXT:    }
 // CHECK-NEXT:   }
 // CHECK-NEXT:  ]
@@ -776,7 +776,7 @@ void testParmVarDecl(int TestParmVarDecl);
 // CHECK-NEXT:    },
 // CHECK-NEXT:    "name": "testRecordDeclAnon1",
 // CHECK-NEXT:    "type": {
-// CHECK-NEXT:     "qualType": "struct (unnamed struct at {{.*}}:46:3)"
+// CHECK-NEXT:     "qualType": "struct (unnamed at {{.*}}:46:3)"
 // CHECK-NEXT:    }
 // CHECK-NEXT:   }
 // CHECK-NEXT:  ]
@@ -1150,7 +1150,7 @@ void testParmVarDecl(int TestParmVarDecl);
 // CHECK-NEXT:  "name": "TestFunctionDecl",
 // CHECK-NEXT:  "mangledName": "TestFunctionDecl",
 // CHECK-NEXT:  "type": {
-// CHECK-NEXT:   "qualType": "int (int, enum (unnamed enum at {{.*}}:69:29))"
+// CHECK-NEXT:   "qualType": "int (int, enum (unnamed at {{.*}}:69:29))"
 // CHECK-NEXT:  },
 // CHECK-NEXT:  "inner": [
 // CHECK-NEXT:   {
@@ -1202,7 +1202,7 @@ void testParmVarDecl(int TestParmVarDecl);
 // CHECK-NEXT:    },
 // CHECK-NEXT:    "name": "y",
 // CHECK-NEXT:    "type": {
-// CHECK-NEXT:     "qualType": "enum (unnamed enum at {{.*}}:69:29)"
+// CHECK-NEXT:     "qualType": "enum (unnamed at {{.*}}:69:29)"
 // CHECK-NEXT:    }
 // CHECK-NEXT:   },
 // CHECK-NEXT:   {

diff  --git a/clang/test/AST/ast-dump-records-json.cpp 
b/clang/test/AST/ast-dump-records-json.cpp
index 941c6a675448a..03ae098dab037 100644
--- a/clang/test/AST/ast-dump-records-json.cpp
+++ b/clang/test/AST/ast-dump-records-json.cpp
@@ -795,7 +795,7 @@ struct Derived6 : virtual public Bases... {
 // CHECK-NEXT:    },
 // CHECK-NEXT:    "name": "b",
 // CHECK-NEXT:    "type": {
-// CHECK-NEXT:     "qualType": "struct (unnamed struct at {{.*}}:16:3)"
+// CHECK-NEXT:     "qualType": "struct (unnamed at {{.*}}:16:3)"
 // CHECK-NEXT:    }
 // CHECK-NEXT:   },
 // CHECK-NEXT:   {
@@ -2071,7 +2071,7 @@ struct Derived6 : virtual public Bases... {
 // CHECK-NEXT:    },
 // CHECK-NEXT:    "name": "b",
 // CHECK-NEXT:    "type": {
-// CHECK-NEXT:     "qualType": "struct (unnamed struct at {{.*}}:50:3)"
+// CHECK-NEXT:     "qualType": "struct (unnamed at {{.*}}:50:3)"
 // CHECK-NEXT:    }
 // CHECK-NEXT:   },
 // CHECK-NEXT:   {

diff  --git a/clang/test/AST/ast-dump-records.c 
b/clang/test/AST/ast-dump-records.c
index 1dc175c4a8560..b8320a1e064f2 100644
--- a/clang/test/AST/ast-dump-records.c
+++ b/clang/test/AST/ast-dump-records.c
@@ -47,7 +47,7 @@ struct C {
     int a;
     // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:5, col:9> col:9 a 
'int'
   } b;
-  // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} <line:[[@LINE-5]]:3, 
line:[[@LINE-1]]:5> col:5 b 'struct (unnamed struct at {{.*}}:[[@LINE-5]]:3)'
+  // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} <line:[[@LINE-5]]:3, 
line:[[@LINE-1]]:5> col:5 b 'struct (unnamed at {{.*}}:[[@LINE-5]]:3)'
 
   union {
     // CHECK-NEXT: RecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:3, 
line:[[@LINE+5]]:3> line:[[@LINE-1]]:3 union definition
@@ -128,7 +128,7 @@ union G {
     int a;
     // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:5, col:9> col:9 a 
'int'
   } b;
-  // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} <line:[[@LINE-5]]:3, 
line:[[@LINE-1]]:5> col:5 b 'struct (unnamed struct at {{.*}}:[[@LINE-5]]:3)'
+  // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} <line:[[@LINE-5]]:3, 
line:[[@LINE-1]]:5> col:5 b 'struct (unnamed at {{.*}}:[[@LINE-5]]:3)'
 
   union {
     // CHECK-NEXT: RecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:3, 
line:[[@LINE+5]]:3> line:[[@LINE-1]]:3 union definition

diff  --git a/clang/test/AST/ast-dump-records.cpp 
b/clang/test/AST/ast-dump-records.cpp
index edd13ba1c6f12..5801672a0f9d6 100644
--- a/clang/test/AST/ast-dump-records.cpp
+++ b/clang/test/AST/ast-dump-records.cpp
@@ -72,7 +72,7 @@ struct C {
     int a;
     // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:5, col:9> col:9 a 
'int'
   } b;
-  // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} <line:[[@LINE-12]]:3, 
line:[[@LINE-1]]:5> col:5 b 'struct (unnamed struct at {{.*}}:[[@LINE-12]]:3)'
+  // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} <line:[[@LINE-12]]:3, 
line:[[@LINE-1]]:5> col:5 b 'struct (unnamed at {{.*}}:[[@LINE-12]]:3)'
 
   union {
     // CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:3, 
line:[[@LINE+12]]:3> line:[[@LINE-1]]:3 union definition
@@ -202,7 +202,7 @@ union G {
     int a;
     // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:5, col:9> col:9 a 
'int'
   } b;
-  // CHECK: FieldDecl 0x{{[^ ]*}} <line:[[@LINE-13]]:3, line:[[@LINE-1]]:5> 
col:5 b 'struct (unnamed struct at {{.*}}:[[@LINE-13]]:3)'
+  // CHECK: FieldDecl 0x{{[^ ]*}} <line:[[@LINE-13]]:3, line:[[@LINE-1]]:5> 
col:5 b 'struct (unnamed at {{.*}}:[[@LINE-13]]:3)'
 
   union {
     // CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:3, 
line:[[@LINE+13]]:3> line:[[@LINE-1]]:3 union definition

diff  --git a/clang/test/ASTMerge/struct/test.c 
b/clang/test/ASTMerge/struct/test.c
index d11234472ef29..b34869c1eed44 100644
--- a/clang/test/ASTMerge/struct/test.c
+++ b/clang/test/ASTMerge/struct/test.c
@@ -44,12 +44,12 @@
 // CHECK: struct2.c:72:7: note: field 'i' has type 'int' here
 // CHECK: struct2.c:76:5: warning: external variable 'x13' declared with 
incompatible types in 
diff erent translation units ('S13' vs. 'S13')
 // CHECK: struct1.c:79:5: note: declared here with type 'S13'
-// CHECK: struct1.c:130:7: warning: type 'struct DeepUnnamedError::(anonymous 
union)::(anonymous union)::(unnamed at [[PATH_TO_INPUTS:.+]]struct1.c:130:7)' 
has incompatible definitions in 
diff erent translation units
+// CHECK: struct1.c:130:7: warning: type 'struct DeepUnnamedError::(unnamed 
union)::(unnamed union)::(unnamed at [[PATH_TO_INPUTS:.+]]struct1.c:130:7)' has 
incompatible definitions in 
diff erent translation units
 // CHECK: struct1.c:131:14: note: field 'i' has type 'long' here
 // CHECK: struct2.c:128:15: note: field 'i' has type 'float' here
-// CHECK: struct1.c:129:5: warning: type 'union DeepUnnamedError::(anonymous 
union)::(unnamed at [[PATH_TO_INPUTS]]struct1.c:129:5)' has incompatible 
definitions in 
diff erent translation units
-// CHECK: struct1.c:132:9: note: field 'S' has type 'struct (unnamed struct at 
[[PATH_TO_INPUTS]]struct1.c:130:7)' here
-// CHECK: struct2.c:129:9: note: field 'S' has type 'struct (unnamed struct at 
[[PATH_TO_INPUTS]]struct2.c:127:7)' here
+// CHECK: struct1.c:129:5: warning: type 'union DeepUnnamedError::(unnamed 
union)::(unnamed at [[PATH_TO_INPUTS]]struct1.c:129:5)' has incompatible 
definitions in 
diff erent translation units
+// CHECK: struct1.c:132:9: note: field 'S' has type 'struct (unnamed at 
[[PATH_TO_INPUTS]]struct1.c:130:7)' here
+// CHECK: struct2.c:129:9: note: field 'S' has type 'struct (unnamed at 
[[PATH_TO_INPUTS]]struct2.c:127:7)' here
 // CHECK: struct2.c:138:3: warning: external variable 'x16' declared with 
incompatible types in 
diff erent translation units ('struct DeepUnnamedError' vs. 'struct 
DeepUnnamedError')
 // CHECK: struct1.c:141:3: note: declared here with type 'struct 
DeepUnnamedError'
 // CHECK: 20 warnings generated

diff  --git a/clang/test/Analysis/Inputs/expected-plists/lambda-notes.cpp.plist 
b/clang/test/Analysis/Inputs/expected-plists/lambda-notes.cpp.plist
index 5c7768cb97ef4..d5859dca9630b 100644
--- a/clang/test/Analysis/Inputs/expected-plists/lambda-notes.cpp.plist
+++ b/clang/test/Analysis/Inputs/expected-plists/lambda-notes.cpp.plist
@@ -174,7 +174,7 @@
    <key>type</key><string>Division by zero</string>
    <key>check_name</key><string>core.DivideZero</string>
    <!-- This hash is experimental and going to change! -->
-   
<key>issue_hash_content_of_line_in_context</key><string>bd4eed3234018edced5efc2ed5562a74</string>
+   
<key>issue_hash_content_of_line_in_context</key><string>d3cd158ad0fd8ce44df89c6779a1faec</string>
   <key>issue_context_kind</key><string>C++ method</string>
   <key>issue_context</key><string>operator()</string>
   <key>issue_hash_function_offset</key><string>1</string>

diff  --git a/clang/test/Analysis/analyzer-note-analysis-entry-points.cpp 
b/clang/test/Analysis/analyzer-note-analysis-entry-points.cpp
index 7d321bfae61c9..d0cf3a334e647 100644
--- a/clang/test/Analysis/analyzer-note-analysis-entry-points.cpp
+++ b/clang/test/Analysis/analyzer-note-analysis-entry-points.cpp
@@ -51,10 +51,10 @@ void checkASTCodeBodyHasAnalysisEntryPoints() {
 }
 
 void notInvokedLambdaScope() {
-  // CHECK: note: [debug] analyzing from notInvokedLambdaScope()::(anonymous 
class)::operator()()
+  // CHECK: note: [debug] analyzing from 
notInvokedLambdaScope()::(lambda)::operator()()
   // CHECK-NEXT: |   auto notInvokedLambda = []() {
   // CHECK-NEXT: |                           ^
-  // textout-note@+1 {{[debug] analyzing from 
notInvokedLambdaScope()::(anonymous class)::operator()()}}
+  // textout-note@+1 {{[debug] analyzing from 
notInvokedLambdaScope()::(lambda)::operator()()}}
   auto notInvokedLambda = []() {
     // common-warning@+1 {{REACHABLE}} textout-note@+1 {{REACHABLE}}
     clang_analyzer_warnIfReached();
@@ -72,4 +72,4 @@ void invokedLambdaScope() {
     clang_analyzer_warnIfReached();
   };
   invokedLambda(); // textout-note {{Calling 'operator()'}}
-}
\ No newline at end of file
+}

diff  --git a/clang/test/Analysis/bug_hash_test.cpp 
b/clang/test/Analysis/bug_hash_test.cpp
index 7b812a76558dd..184d3a9dce255 100644
--- a/clang/test/Analysis/bug_hash_test.cpp
+++ b/clang/test/Analysis/bug_hash_test.cpp
@@ -65,7 +65,7 @@ void AA::X::OutOfLine() {
 
 void testLambda() {
   []() {
-    clang_analyzer_hashDump(5); // expected-warning 
{{debug.ExprInspection$void testLambda()::(anonymous class)::operator()() 
const$29$clang_analyzer_hashDump(5);$Category}}
+    clang_analyzer_hashDump(5); // expected-warning 
{{debug.ExprInspection$void testLambda()::(lambda)::operator()() 
const$29$clang_analyzer_hashDump(5);$Category}}
   }();
 }
 

diff  --git a/clang/test/Analysis/cfg.cpp b/clang/test/Analysis/cfg.cpp
index d6cef88dc18a6..2a88b73d27756 100644
--- a/clang/test/Analysis/cfg.cpp
+++ b/clang/test/Analysis/cfg.cpp
@@ -26,9 +26,9 @@
 // WARNINGS-NEXT: (CXXConstructExpr, struct standalone)
 // ANALYZER-NEXT: (CXXConstructExpr, [B1.9], struct standalone)
 // CHECK-NEXT:   9: struct standalone myStandalone;
-// WARNINGS-NEXT: (CXXConstructExpr, struct (unnamed struct at {{.*}}))
-// ANALYZER-NEXT: (CXXConstructExpr, [B1.11], struct (unnamed struct at 
{{.*}}))
-// CHECK-NEXT:  11: struct (unnamed struct at {{.*}}) myAnon;
+// WARNINGS-NEXT: (CXXConstructExpr, struct (unnamed at {{.*}}))
+// ANALYZER-NEXT: (CXXConstructExpr, [B1.11], struct (unnamed at {{.*}}))
+// CHECK-NEXT:  11: struct (unnamed at {{.*}}) myAnon;
 // WARNINGS-NEXT: (CXXConstructExpr, struct named)
 // ANALYZER-NEXT: (CXXConstructExpr, [B1.13], struct named)
 // CHECK-NEXT:  13: struct named myNamed;

diff  --git a/clang/test/Analysis/debug-CallGraph.cpp 
b/clang/test/Analysis/debug-CallGraph.cpp
index 120bb38d3bb33..04d6e5f14f963 100644
--- a/clang/test/Analysis/debug-CallGraph.cpp
+++ b/clang/test/Analysis/debug-CallGraph.cpp
@@ -97,14 +97,14 @@ namespace CallDecl {
 }
 
 // CHECK:--- Call graph Dump ---
-// CHECK-NEXT: {{Function: < root > calls: get5 add test_add mmm foo aaa < > 
bbb ddd ccc eee fff do_nothing test_single_call SomeNS::templ SomeNS::templ 
SomeNS::templUser Lambdas::Callee Lambdas::f1 Lambdas::f1\(\)::\(anonymous 
class\)::operator\(\) Lambdas::f1\(\)::\(anonymous class\)::operator\(\) 
CallDecl::SomeDef CallDecl::Caller CallDecl::SomeDecl CallDecl::SomeOtherDecl 
$}}
+// CHECK-NEXT: {{Function: < root > calls: get5 add test_add mmm foo aaa < > 
bbb ddd ccc eee fff do_nothing test_single_call SomeNS::templ SomeNS::templ 
SomeNS::templUser Lambdas::Callee Lambdas::f1 
Lambdas::f1\(\)::\(lambda\)::operator\(\) 
Lambdas::f1\(\)::\(lambda\)::operator\(\) CallDecl::SomeDef CallDecl::Caller 
CallDecl::SomeDecl CallDecl::SomeOtherDecl $}}
 // CHECK-NEXT: {{Function: CallDecl::Caller calls: CallDecl::SomeDecl 
CallDecl::SomeOtherDecl $}}
 // CHECK-NEXT: {{Function: CallDecl::SomeOtherDecl calls: CallDecl::SomeDef $}}
 // CHECK-NEXT: {{Function: CallDecl::SomeDecl calls: $}}
 // CHECK-NEXT: {{Function: CallDecl::SomeDef calls: $}}
-// CHECK-NEXT: {{Function: Lambdas::f1 calls: Lambdas::f1\(\)::\(anonymous 
class\)::operator\(\) Lambdas::f1\(\)::\(anonymous class\)::operator\(\) $}}
-// CHECK-NEXT: {{Function: Lambdas::f1\(\)::\(anonymous class\)::operator\(\) 
calls: Lambdas::Callee $}}
-// CHECK-NEXT: {{Function: Lambdas::f1\(\)::\(anonymous class\)::operator\(\) 
calls: Lambdas::Callee $}}
+// CHECK-NEXT: {{Function: Lambdas::f1 calls: 
Lambdas::f1\(\)::\(lambda\)::operator\(\) 
Lambdas::f1\(\)::\(lambda\)::operator\(\) $}}
+// CHECK-NEXT: {{Function: Lambdas::f1\(\)::\(lambda\)::operator\(\) calls: 
Lambdas::Callee $}}
+// CHECK-NEXT: {{Function: Lambdas::f1\(\)::\(lambda\)::operator\(\) calls: 
Lambdas::Callee $}}
 // CHECK-NEXT: {{Function: Lambdas::Callee calls: $}}
 // CHECK-NEXT: {{Function: SomeNS::templUser calls: SomeNS::templ 
SomeNS::templ $}}
 // CHECK-NEXT: {{Function: SomeNS::templ calls: eee $}}

diff  --git 
a/clang/test/Analysis/inlining/Inputs/expected-plists/path-notes.cpp.plist 
b/clang/test/Analysis/inlining/Inputs/expected-plists/path-notes.cpp.plist
index 6215d48ebd2c8..62aaf0fe8e2d5 100644
--- a/clang/test/Analysis/inlining/Inputs/expected-plists/path-notes.cpp.plist
+++ b/clang/test/Analysis/inlining/Inputs/expected-plists/path-notes.cpp.plist
@@ -722,7 +722,7 @@
    <key>type</key><string>Dereference of null pointer</string>
    <key>check_name</key><string>core.NullDereference</string>
    <!-- This hash is experimental and going to change! -->
-   
<key>issue_hash_content_of_line_in_context</key><string>efde323086a985fe1e8ccc6cd0123c12</string>
+   
<key>issue_hash_content_of_line_in_context</key><string>c13b0c1fd27df0a9d9c0b4c125ade016</string>
   <key>issue_context_kind</key><string>C++ method</string>
   <key>issue_context</key><string>method</string>
   <key>issue_hash_function_offset</key><string>1</string>

diff  --git a/clang/test/C/C23/n3006.c b/clang/test/C/C23/n3006.c
index e0713fa9969c4..14d73da9db49c 100644
--- a/clang/test/C/C23/n3006.c
+++ b/clang/test/C/C23/n3006.c
@@ -103,7 +103,7 @@ void misc_struct_test(void) {
 
   constexpr struct {
       int b;
-  } b = (struct S { int x; }){ 0 };  // expected-error-re {{initializing 
'const struct (unnamed struct at {{.*}}n3006.c:104:13)' with an expression of 
incompatible type 'struct S'}}
+  } b = (struct S { int x; }){ 0 };  // expected-error-re {{initializing 
'const struct (unnamed at {{.*}}n3006.c:104:13)' with an expression of 
incompatible type 'struct S'}}
 
   auto z = ({
       int a = 12;

diff  --git a/clang/test/C/C23/n3037.c b/clang/test/C/C23/n3037.c
index 113ecf74d8bef..aec0407e2bfd4 100644
--- a/clang/test/C/C23/n3037.c
+++ b/clang/test/C/C23/n3037.c
@@ -45,7 +45,7 @@ union barp { int x; float y; };     // c17-note {{previous 
definition is here}}
 union barp { int x; float y; };     // c17-error {{redefinition of 'barp'}}
 typedef struct q { int x; } q_t;    // c17-note 2 {{previous definition is 
here}}
 typedef struct q { int x; } q_t;    // c17-error {{redefinition of 'q'}} \
-                                       c17-error-re {{typedef redefinition 
with 
diff erent types ('struct (unnamed struct at {{.*}})' vs 'struct q')}}
+                                       c17-error-re {{typedef redefinition 
with 
diff erent types ('struct (unnamed at {{.*}})' vs 'struct q')}}
 typedef struct { int x; } untagged_q_t; // both-note {{previous definition is 
here}}
 typedef struct { int x; } untagged_q_t; // both-error {{typedef redefinition 
with 
diff erent types}}
 void func3(void) {
@@ -432,9 +432,9 @@ void compare_unnamed_struct_from_
diff erent_outer_type(
     struct InnerUnnamedStruct_
diff erentNaming 
diff erentFieldName,
     struct InnerUnnamedStruct_
diff erentShape 
diff erentType) {
   inner_unnamed_tagged.untagged = sameOuterType.untagged;
-  inner_unnamed_tagged.untagged = matchingType.untagged; // both-error-re 
{{assigning to 'struct (unnamed struct at {{.*}})' from incompatible type 
'struct (unnamed struct at {{.*}})'}}
-  inner_unnamed_tagged.untagged = 
diff erentFieldName.untaggedDifferent; // both-error-re {{assigning to 'struct 
(unnamed struct at {{.*}})' from incompatible type 'struct (unnamed struct at 
{{.*}})'}}
-  inner_unnamed_tagged.untagged = 
diff erentType.untagged; // both-error-re {{assigning to 'struct (unnamed 
struct at {{.*}})' from incompatible type 'struct (unnamed struct at {{.*}})'}}
+  inner_unnamed_tagged.untagged = matchingType.untagged; // both-error-re 
{{assigning to 'struct (unnamed at {{.*}})' from incompatible type 'struct 
(unnamed at {{.*}})'}}
+  inner_unnamed_tagged.untagged = 
diff erentFieldName.untaggedDifferent; // both-error-re {{assigning to 'struct 
(unnamed at {{.*}})' from incompatible type 'struct (unnamed at {{.*}})'}}
+  inner_unnamed_tagged.untagged = 
diff erentType.untagged; // both-error-re {{assigning to 'struct (unnamed at 
{{.*}})' from incompatible type 'struct (unnamed at {{.*}})'}}
 }
 
 // Test the same thing with enumerations (test for unions is omitted because

diff  --git a/clang/test/CodeGen/block-with-perdefinedexpr.cpp 
b/clang/test/CodeGen/block-with-perdefinedexpr.cpp
index 890c2d6358569..597971e6fb6be 100644
--- a/clang/test/CodeGen/block-with-perdefinedexpr.cpp
+++ b/clang/test/CodeGen/block-with-perdefinedexpr.cpp
@@ -67,11 +67,11 @@ class Foo {
   }
   void inside_lambda() {
     auto lambda = []() {
-      // CHECK-DAG: 
@__PRETTY_FUNCTION__.___ZZN12foonamespace3Foo13inside_lambdaEvENKUlvE_clEv_block_invoke
 = private unnamed_addr constant [92 x i8] c"auto 
foonamespace::Foo::inside_lambda()::(anonymous class)::operator()() 
const_block_invoke\00", align 1
+      // CHECK-DAG: 
@__PRETTY_FUNCTION__.___ZZN12foonamespace3Foo13inside_lambdaEvENKUlvE_clEv_block_invoke
 = private unnamed_addr constant [83 x i8] c"auto 
foonamespace::Foo::inside_lambda()::(lambda)::operator()() 
const_block_invoke\00", align 1
       const char * (^block1)() = ^() {
         return __PRETTY_FUNCTION__;
       };
-      // CHECK-DAG:      
@__PRETTY_FUNCTION__.___ZZN12foonamespace3Foo13inside_lambdaEvENKUlvE_clEv_block_invoke_2
 = private unnamed_addr constant [94 x i8] c"auto 
foonamespace::Foo::inside_lambda()::(anonymous class)::operator()() 
const_block_invoke_2\00", align 1
+      // CHECK-DAG:      
@__PRETTY_FUNCTION__.___ZZN12foonamespace3Foo13inside_lambdaEvENKUlvE_clEv_block_invoke_2
 = private unnamed_addr constant [85 x i8] c"auto 
foonamespace::Foo::inside_lambda()::(lambda)::operator()() 
const_block_invoke_2\00", align 1
       const char * (^block2)() = ^() {
         return __PRETTY_FUNCTION__;
       };

diff  --git a/clang/test/CodeGenCXX/predefined-expr.cpp 
b/clang/test/CodeGenCXX/predefined-expr.cpp
index 815bcbb3bd899..1f036c5d520c9 100644
--- a/clang/test/CodeGenCXX/predefined-expr.cpp
+++ b/clang/test/CodeGenCXX/predefined-expr.cpp
@@ -10,7 +10,7 @@
 // CHECK-DAG: private unnamed_addr constant [103 x i8] c"static void 
ClassWithTemplateTemplateParam<char>::staticMember() [T = char, Param = 
NS::ClassTemplate]\00"
 // CHECK-DAG: private unnamed_addr constant [106 x i8] c"void OuterClass<int 
*>::MiddleClass::InnerClass<float>::memberFunction(T, U) const [T = int *, U = 
float]\00"
 // CHECK-DAG: private unnamed_addr constant [51 x i8] c"void 
functionTemplateWithCapturedStmt(T) [T = int]\00"
-// CHECK-DAG: private unnamed_addr constant [76 x i8] c"auto 
functionTemplateWithLambda(int)::(anonymous class)::operator()() const\00"
+// CHECK-DAG: private unnamed_addr constant [67 x i8] c"auto 
functionTemplateWithLambda(int)::(lambda)::operator()() const\00"
 // CHECK-DAG: private unnamed_addr constant [65 x i8] c"void 
functionTemplateWithUnnamedTemplateParameter(T) [T = float]\00"
 
 // CHECK-DAG: private unnamed_addr constant [60 x i8] c"void 
functionTemplateExplicitSpecialization(T) [T = double]\00"
@@ -28,13 +28,13 @@
 // CHECK-DAG: private unnamed_addr constant [46 x i8] c"void 
NS::Base::functionTemplate1(T) [T = int]\00"
 
 // CHECK-DAG: private unnamed_addr constant [23 x i8] 
c"anonymousUnionFunction\00"
-// CHECK-DAG: private unnamed_addr constant [83 x i8] c"void 
NS::ContainerForAnonymousRecords::(anonymous 
union)::anonymousUnionFunction()\00"
+// CHECK-DAG: private unnamed_addr constant [81 x i8] c"void 
NS::ContainerForAnonymousRecords::(unnamed union)::anonymousUnionFunction()\00"
 
 // CHECK-DAG: private unnamed_addr constant [24 x i8] 
c"anonymousStructFunction\00"
-// CHECK-DAG: private unnamed_addr constant [85 x i8] c"void 
NS::ContainerForAnonymousRecords::(anonymous 
struct)::anonymousStructFunction()\00"
+// CHECK-DAG: private unnamed_addr constant [83 x i8] c"void 
NS::ContainerForAnonymousRecords::(unnamed 
struct)::anonymousStructFunction()\00"
 
 // CHECK-DAG: private unnamed_addr constant [23 x i8] 
c"anonymousClassFunction\00"
-// CHECK-DAG: private unnamed_addr constant [83 x i8] c"void 
NS::ContainerForAnonymousRecords::(anonymous 
class)::anonymousClassFunction()\00"
+// CHECK-DAG: private unnamed_addr constant [81 x i8] c"void 
NS::ContainerForAnonymousRecords::(unnamed class)::anonymousClassFunction()\00"
 
 // CHECK-DAG: private unnamed_addr constant [12 x i8] c"~Destructor\00"
 // CHECK-DAG: private unnamed_addr constant [30 x i8] 
c"NS::Destructor::~Destructor()\00"

diff  --git a/clang/test/Index/print-type.c b/clang/test/Index/print-type.c
index 9fb85f8da4e66..3ceecbd90b250 100644
--- a/clang/test/Index/print-type.c
+++ b/clang/test/Index/print-type.c
@@ -71,7 +71,7 @@ _Atomic(unsigned long) aul;
 // CHECK: TypeRef=struct Struct:16:8 [type=struct Struct] [typekind=Record] 
[isPOD=1]
 // CHECK: StructDecl=struct (unnamed at {{.*}}):18:1 (Definition) [type=struct 
(unnamed at {{.*}}print-type.c:18:1)] [typekind=Record] [isPOD=1] [nbFields=2] 
[isAnon=1] [isAnonRecDecl=0]
 // CHECK: StructDecl=struct (unnamed at {{.*}}):23:1 (Definition) [type=struct 
(unnamed at {{.*}}print-type.c:23:1)] [typekind=Record] [isPOD=1] [nbFields=1] 
[isAnon=1] [isAnonRecDecl=0]
-// CHECK: StructDecl=struct (anonymous at {{.*}}):24:3 (Definition) 
[type=struct (anonymous struct)::(anonymous at {{.*}}print-type.c:24:3)] 
[typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] [isAnonRecDecl=1]
+// CHECK: StructDecl=struct (anonymous at {{.*}}):24:3 (Definition) 
[type=struct (unnamed struct)::(anonymous at {{.*}}print-type.c:24:3)] 
[typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] [isAnonRecDecl=1]
 // CHECK: FieldDecl=x:25:17 (Definition) [type=_Atomic(int)] [typekind=Atomic] 
[valuetype=int] [valuetypekind=Int] [isPOD=0] [isAnonRecDecl=0]
 // CHECK: FieldDecl=y:26:9 (Definition) [type=int] [typekind=Int] [isPOD=1] 
[isAnonRecDecl=0]
 // CHECK: StructDecl=struct (unnamed at {{.*}}):30:10 (Definition) 
[type=struct (unnamed at {{.*}}print-type.c:30:10)] [typekind=Record] [isPOD=1] 
[nbFields=2] [isAnon=1] [isAnonRecDecl=0]

diff  --git a/clang/test/Layout/ms-x86-alias-avoidance-padding.cpp 
b/clang/test/Layout/ms-x86-alias-avoidance-padding.cpp
index bc6a56ef37538..a83810e28741b 100644
--- a/clang/test/Layout/ms-x86-alias-avoidance-padding.cpp
+++ b/clang/test/Layout/ms-x86-alias-avoidance-padding.cpp
@@ -49,7 +49,7 @@ struct AT3 : AT2, AT1 {
 // CHECK-NEXT:    0 |   struct AT2 (base)
 // CHECK-NEXT:    0 |     struct AT0 t
 // CHECK-NEXT:    0 |       union AT0::(unnamed at {{.*}} x
-// CHECK-NEXT:    0 |         struct AT0::(anonymous union)::(unnamed at 
{{.*}} y
+// CHECK-NEXT:    0 |         struct AT0::(unnamed union)::(unnamed at {{.*}} y
 // CHECK-NEXT:    0 |           int a
 // CHECK-NEXT:    4 |           struct AT t (empty)
 // CHECK:         0 |         int b
@@ -66,7 +66,7 @@ struct AT3 : AT2, AT1 {
 // CHECK-X64-NEXT:    0 |   struct AT2 (base)
 // CHECK-X64-NEXT:    0 |     struct AT0 t
 // CHECK-X64-NEXT:    0 |       union AT0::(unnamed at {{.*}} x
-// CHECK-X64-NEXT:    0 |         struct AT0::(anonymous union)::(unnamed at 
{{.*}} y
+// CHECK-X64-NEXT:    0 |         struct AT0::(unnamed union)::(unnamed at 
{{.*}} y
 // CHECK-X64-NEXT:    0 |           int a
 // CHECK-X64-NEXT:    4 |           struct AT t (empty)
 // CHECK-X64:         0 |         int b

diff  --git a/clang/test/Sema/assign.c b/clang/test/Sema/assign.c
index 13ea1062b9e1e..711e68ce4e44c 100644
--- a/clang/test/Sema/assign.c
+++ b/clang/test/Sema/assign.c
@@ -6,7 +6,7 @@ void test2 (const struct {int a;} *x) {
   // expected-note@-1 {{variable 'x' declared const here}}
 
   x->a = 10;
-  // expected-error-re@-1 {{cannot assign to variable 'x' with const-qualified 
type 'const struct (unnamed struct at {{.*}}assign.c:5:19) *'}}
+  // expected-error-re@-1 {{cannot assign to variable 'x' with const-qualified 
type 'const struct (unnamed at {{.*}}assign.c:5:19) *'}}
 }
 
 typedef int arr[10];

diff  --git a/clang/test/Sema/switch.c b/clang/test/Sema/switch.c
index 6e912d02d6cc7..76068b6415c08 100644
--- a/clang/test/Sema/switch.c
+++ b/clang/test/Sema/switch.c
@@ -110,14 +110,14 @@ void test7(void) {
   switch(a) {
     case A:
     case B:
-    case 3: // expected-warning{{case value not in enumerated type 'enum 
(unnamed enum}}
+    case 3: // expected-warning{{case value not in enumerated type 'enum 
(unnamed}}
       break;
   }
   switch(a) {
     case A:
     case B:
-    case 3 ... //expected-warning{{case value not in enumerated type 'enum 
(unnamed enum}}
-        4: //expected-warning{{case value not in enumerated type 'enum 
(unnamed enum}}
+    case 3 ... //expected-warning{{case value not in enumerated type 'enum 
(unnamed}}
+        4: //expected-warning{{case value not in enumerated type 'enum 
(unnamed}}
       break;
   }
   switch(a) {
@@ -125,16 +125,16 @@ void test7(void) {
       break;
   }
   switch(a) {
-    case 0 ... 2: //expected-warning{{case value not in enumerated type 'enum 
(unnamed enum}}
+    case 0 ... 2: //expected-warning{{case value not in enumerated type 'enum 
(unnamed}}
       break;
   }
   switch(a) {
-    case 1 ... 3: //expected-warning{{case value not in enumerated type 'enum 
(unnamed enum}}
+    case 1 ... 3: //expected-warning{{case value not in enumerated type 'enum 
(unnamed}}
       break;
   }
   switch(a) {
-    case 0 ...  //expected-warning{{case value not in enumerated type 'enum 
(unnamed enum}}
-      3:  //expected-warning{{case value not in enumerated type 'enum (unnamed 
enum}}
+    case 0 ...  //expected-warning{{case value not in enumerated type 'enum 
(unnamed}}
+      3:  //expected-warning{{case value not in enumerated type 'enum 
(unnamed}}
       break;
   }
 
@@ -168,11 +168,11 @@ void test9(void) {
     C = 1
   } a;
   switch(a) {
-    case 0: //expected-warning{{case value not in enumerated type 'enum 
(unnamed enum}}
+    case 0: //expected-warning{{case value not in enumerated type 'enum 
(unnamed}}
     case 1:
-    case 2: //expected-warning{{case value not in enumerated type 'enum 
(unnamed enum}}
+    case 2: //expected-warning{{case value not in enumerated type 'enum 
(unnamed}}
     case 3:
-    case 4: //expected-warning{{case value not in enumerated type 'enum 
(unnamed enum}}
+    case 4: //expected-warning{{case value not in enumerated type 'enum 
(unnamed}}
       break;
   }
 }
@@ -185,14 +185,14 @@ void test10(void) {
     D = 12
   } a;
   switch(a) {
-    case 0 ...  //expected-warning{{case value not in enumerated type 'enum 
(unnamed enum}}
-           1:  //expected-warning{{case value not in enumerated type 'enum 
(unnamed enum}}
+    case 0 ...  //expected-warning{{case value not in enumerated type 'enum 
(unnamed}}
+           1:  //expected-warning{{case value not in enumerated type 'enum 
(unnamed}}
     case 2 ... 4:
-    case 5 ...  //expected-warning{{case value not in enumerated type 'enum 
(unnamed enum}}    
-             9:  //expected-warning{{case value not in enumerated type 'enum 
(unnamed enum}}
+    case 5 ...  //expected-warning{{case value not in enumerated type 'enum 
(unnamed}} 
+             9:  //expected-warning{{case value not in enumerated type 'enum 
(unnamed}}
     case 10 ... 12:
-    case 13 ...  //expected-warning{{case value not in enumerated type 'enum 
(unnamed enum}}
-              16: //expected-warning{{case value not in enumerated type 'enum 
(unnamed enum}}
+    case 13 ...  //expected-warning{{case value not in enumerated type 'enum 
(unnamed}}
+              16: //expected-warning{{case value not in enumerated type 'enum 
(unnamed}}
       break;
   }
 }

diff  --git a/clang/test/SemaCXX/builtin-bswapg.cpp 
b/clang/test/SemaCXX/builtin-bswapg.cpp
index 9d8d103e77c51..539390fa9b606 100644
--- a/clang/test/SemaCXX/builtin-bswapg.cpp
+++ b/clang/test/SemaCXX/builtin-bswapg.cpp
@@ -135,13 +135,13 @@ void test_lambda_errors() {
   
   lambda(1.0f);
   // expected-error@#lambda_use {{1st argument must be a scalar integer type 
(was 'float')}}
-  // expected-note@-2 {{in instantiation of function template specialization 
'test_lambda_errors()::(anonymous class)::operator()<float>' requested here}}
+  // expected-note@-2 {{in instantiation of function template specialization 
'test_lambda_errors()::(lambda)::operator()<float>' requested here}}
   lambda(1.0l);
   // expected-error@#lambda_use {{1st argument must be a scalar integer type 
(was 'long double')}}
-  // expected-note@-2 {{in instantiation of function template specialization 
'test_lambda_errors()::(anonymous class)::operator()<long double>' requested 
here}}
+  // expected-note@-2 {{in instantiation of function template specialization 
'test_lambda_errors()::(lambda)::operator()<long double>' requested here}}
   lambda("hello");
   // expected-error@#lambda_use {{1st argument must be a scalar integer type 
(was 'const char *')}}
-  // expected-note@-2 {{in instantiation of function template specialization 
'test_lambda_errors()::(anonymous class)::operator()<const char *>' requested 
here}}
+  // expected-note@-2 {{in instantiation of function template specialization 
'test_lambda_errors()::(lambda)::operator()<const char *>' requested here}}
 }
 
 template <class... Args> void test_variadic_template_argument_count(Args... 
args) {

diff  --git a/clang/test/SemaCXX/cxx0x-nontrivial-union.cpp 
b/clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
index 1eb7e3a2dea8b..3d80794f44375 100644
--- a/clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
+++ b/clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
@@ -136,7 +136,7 @@ namespace pr16061 {
 
   template<typename T> struct Test2 {
     union {
-      struct {  // expected-note-re {{default constructor of 
'Test2<pr16061::X>' is implicitly deleted because variant field 'struct 
(anonymous struct at{{.+}})' has a non-trivial default constructor}}
+      struct {  // expected-note-re {{default constructor of 
'Test2<pr16061::X>' is implicitly deleted because variant field 'struct 
(anonymous at{{.+}})' has a non-trivial default constructor}}
         T x;
       };
     };

diff  --git a/clang/test/SemaCXX/cxx1z-decomposition.cpp 
b/clang/test/SemaCXX/cxx1z-decomposition.cpp
index 158a3a66deb47..6425f1ee7796e 100644
--- a/clang/test/SemaCXX/cxx1z-decomposition.cpp
+++ b/clang/test/SemaCXX/cxx1z-decomposition.cpp
@@ -105,7 +105,7 @@ void enclosing() {
 void bitfield() {
   struct { int a : 3, : 4, b : 5; } a;
   auto &[x, y] = a;
-  auto &[p, q, r] = a; // expected-error-re {{type 'struct (unnamed struct at 
{{.*}})' binds to 2 elements, but 3 names were provided}}
+  auto &[p, q, r] = a; // expected-error-re {{type 'struct (unnamed at 
{{.*}})' binds to 2 elements, but 3 names were provided}}
 }
 
 void for_range() {

diff  --git a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp 
b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
index ff104243a9735..6da589dcf1b25 100644
--- a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
+++ b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
@@ -636,7 +636,7 @@ template <typename T>
 struct scope_exit {
     T t;
     constexpr ~scope_exit() { t(); }
-    // expected-error@-1 {{call to immediate function 'GH109096::(anonymous 
class)::operator()' is not a constant expression}} \
+    // expected-error@-1 {{call to immediate function 
'GH109096::(lambda)::operator()' is not a constant expression}} \
     // expected-note@-1 {{implicit use of 'this' pointer is only allowed 
within the evaluation}}
 };
 

diff  --git a/clang/test/SemaCXX/predefined-expr.cpp 
b/clang/test/SemaCXX/predefined-expr.cpp
index 8cba0d41a2997..ea41f0b505d31 100644
--- a/clang/test/SemaCXX/predefined-expr.cpp
+++ b/clang/test/SemaCXX/predefined-expr.cpp
@@ -26,8 +26,8 @@ int baz() {
   []() {
     static_assert(sizeof(__func__) == 11, "operator()");
     static_assert(sizeof(__FUNCTION__) == 11, "operator()");
-    static_assert(sizeof(__PRETTY_FUNCTION__) == 50,
-                  "auto baz()::<anonymous class>::operator()() const");
+    static_assert(sizeof(__PRETTY_FUNCTION__) == 41,
+                  "auto baz()::<lambda>::operator()() const");
     return 0;
   }
   ();
@@ -56,8 +56,8 @@ int main() {
   []() {
     static_assert(sizeof(__func__) == 11, "operator()");
     static_assert(sizeof(__FUNCTION__) == 11, "operator()");
-    static_assert(sizeof(__PRETTY_FUNCTION__) == 51,
-                  "auto main()::<anonymous class>::operator()() const");
+    static_assert(sizeof(__PRETTY_FUNCTION__) == 42,
+                  "auto main()::<lambda>::operator()() const");
     return 0;
   }
   ();
@@ -87,8 +87,8 @@ int main() {
     {
       static_assert(sizeof(__func__) == 11, "operator()");
       static_assert(sizeof(__FUNCTION__) == 11, "operator()");
-      static_assert(sizeof(__PRETTY_FUNCTION__) == 51,
-                    "auto main()::<anonymous class>::operator()() const");
+      static_assert(sizeof(__PRETTY_FUNCTION__) == 42,
+                    "auto main()::<lambda>::operator()() const");
     }
   }
   ();

diff  --git a/clang/test/SemaCXX/undefined-internal.cpp 
b/clang/test/SemaCXX/undefined-internal.cpp
index 9745f097c76b7..9cd27ee2c981b 100644
--- a/clang/test/SemaCXX/undefined-internal.cpp
+++ b/clang/test/SemaCXX/undefined-internal.cpp
@@ -227,7 +227,7 @@ namespace test7 {
 
 namespace test8 {
   typedef struct {
-    void bar(); // expected-warning {{function 'test8::(anonymous 
struct)::bar' has internal linkage but is not defined}}
+    void bar(); // expected-warning {{function 'test8::(unnamed struct)::bar' 
has internal linkage but is not defined}}
     void foo() {
       bar(); // expected-note {{used here}}
     }

diff  --git a/clang/test/SemaObjCXX/arc-0x.mm b/clang/test/SemaObjCXX/arc-0x.mm
index cd941502dabf7..9eeda7e10c239 100644
--- a/clang/test/SemaObjCXX/arc-0x.mm
+++ b/clang/test/SemaObjCXX/arc-0x.mm
@@ -195,8 +195,8 @@ void test() {
   };
 
   static union { // expected-error {{call to implicitly-deleted default 
constructor of}}
-    union { // expected-note-re {{default constructor of '(unnamed union at 
{{.*}}' is implicitly deleted because field 'test_union::(anonymous 
union)::(anonymous union at {{.*}})' has a deleted default constructor}}
-      union { // expected-note-re {{default constructor of '(anonymous union 
at {{.*}}' is implicitly deleted because field 'test_union::(anonymous 
union)::(anonymous union)::(anonymous union at {{.*}})' has a deleted default 
constructor}}
+    union { // expected-note-re {{default constructor of '(unnamed union at 
{{.*}}' is implicitly deleted because field 'test_union::(unnamed 
union)::(anonymous union at {{.*}})' has a deleted default constructor}}
+      union { // expected-note-re {{default constructor of '(anonymous union 
at {{.*}}' is implicitly deleted because field 'test_union::(unnamed 
union)::(anonymous union)::(anonymous union at {{.*}})' has a deleted default 
constructor}}
         __weak id g1; // expected-note-re {{default constructor of '(anonymous 
union at {{.*}}' is implicitly deleted because variant field 'g1' is an ObjC 
pointer}}
         int g2;
       };

diff  --git a/clang/unittests/AST/NamedDeclPrinterTest.cpp 
b/clang/unittests/AST/NamedDeclPrinterTest.cpp
index cd833725b448d..599ccd7f06fc6 100644
--- a/clang/unittests/AST/NamedDeclPrinterTest.cpp
+++ b/clang/unittests/AST/NamedDeclPrinterTest.cpp
@@ -265,3 +265,32 @@ TEST(NamedDeclPrinter, NestedNameSpecifierTemplateArgs) {
   ASSERT_TRUE(
       PrintedNestedNameSpecifierMatches(Code, "method", "vector<int>::"));
 }
+
+TEST(NamedDeclPrinter, NestedNameSpecifierLambda) {
+  const char *Code =
+      R"(
+        auto l = [] {
+          struct Foo {
+            void method();
+          };
+        };
+)";
+  ASSERT_TRUE(PrintedNestedNameSpecifierMatches(
+      Code, "method", "(lambda)::operator()()::Foo::"));
+}
+
+TEST(NamedDeclPrinter, NestedNameSpecifierAnonymousTags) {
+  const char *Code =
+      R"(
+        struct Foo {
+          class {
+            public:
+            struct {
+              void method();
+            } i;
+          };
+        };
+)";
+  ASSERT_TRUE(PrintedNestedNameSpecifierMatches(
+      Code, "method", "Foo::(anonymous class)::(unnamed struct)::"));
+}

diff  --git a/clang/unittests/AST/TypePrinterTest.cpp 
b/clang/unittests/AST/TypePrinterTest.cpp
index 3cadf9b265bd1..de4cfa4074eba 100644
--- a/clang/unittests/AST/TypePrinterTest.cpp
+++ b/clang/unittests/AST/TypePrinterTest.cpp
@@ -328,7 +328,7 @@ TEST(TypePrinter, NestedNameSpecifiers) {
   // Further levels of nesting print the entire scope.
   ASSERT_TRUE(PrintedTypeMatches(
       Code, {}, fieldDecl(hasName("u"), hasType(qualType().bind("id"))),
-      "union level1()::Inner::Inner(int)::(anonymous struct)::(unnamed)",
+      "union level1()::Inner::Inner(int)::(unnamed struct)::(unnamed)",
       [](PrintingPolicy &Policy) {
         Policy.FullyQualifiedName = true;
         Policy.AnonymousTagLocations = false;

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index 5d452355d0e43..697623c8a48e8 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2709,25 +2709,48 @@ TEST_P(ASTMatchersTest, 
HasName_MatchesAnonymousNamespaces) {
   EXPECT_TRUE(matches(code, recordDecl(hasName("::a::C"))));
 }
 
-TEST_P(ASTMatchersTest, HasName_MatchesAnonymousOuterClasses) {
+TEST_P(ASTMatchersTest, HasName_MatchesUnnamedOuterClasses) {
   if (!GetParam().isCXX()) {
     return;
   }
 
   EXPECT_TRUE(matches("class A { class { class C; } x; };",
-                      recordDecl(hasName("A::(anonymous class)::C"))));
+                      recordDecl(hasName("A::(unnamed class)::C"))));
   EXPECT_TRUE(matches("class A { class { class C; } x; };",
-                      recordDecl(hasName("::A::(anonymous class)::C"))));
+                      recordDecl(hasName("::A::(unnamed class)::C"))));
   EXPECT_FALSE(matches("class A { class { class C; } x; };",
                        recordDecl(hasName("::A::C"))));
   EXPECT_TRUE(matches("class A { struct { class C; } x; };",
-                      recordDecl(hasName("A::(anonymous struct)::C"))));
+                      recordDecl(hasName("A::(unnamed struct)::C"))));
   EXPECT_TRUE(matches("class A { struct { class C; } x; };",
-                      recordDecl(hasName("::A::(anonymous struct)::C"))));
+                      recordDecl(hasName("::A::(unnamed struct)::C"))));
   EXPECT_FALSE(matches("class A { struct { class C; } x; };",
                        recordDecl(hasName("::A::C"))));
 }
 
+TEST_P(ASTMatchersTest, HasName_MatchesAnonymousOuterClasses) {
+  if (!GetParam().isCXX()) {
+    return;
+  }
+
+  EXPECT_TRUE(matches(
+      "class A { struct { struct { class C; } x; }; };",
+      recordDecl(hasName("A::(anonymous struct)::(unnamed struct)::C"))));
+  EXPECT_TRUE(matches(
+      "class A { struct { struct { class C; } x; }; };",
+      recordDecl(hasName("::A::(anonymous struct)::(unnamed struct)::C"))));
+  EXPECT_FALSE(matches("class A { struct { struct { class C; } x; }; };",
+                       recordDecl(hasName("A::(unnamed struct)::C"))));
+  EXPECT_TRUE(matches(
+      "class A { class { public: struct { class C; } x; }; };",
+      recordDecl(hasName("A::(anonymous class)::(unnamed struct)::C"))));
+  EXPECT_TRUE(matches(
+      "class A { class { public: struct { class C; } x; }; };",
+      recordDecl(hasName("::A::(anonymous class)::(unnamed struct)::C"))));
+  EXPECT_FALSE(matches("class A { class { public: struct { class C; } x; }; 
};",
+                       recordDecl(hasName("A::(unnamed struct)::C"))));
+}
+
 TEST_P(ASTMatchersTest, HasName_MatchesFunctionScope) {
   if (!GetParam().isCXX()) {
     return;

diff  --git a/clang/unittests/Tooling/QualTypeNamesTest.cpp 
b/clang/unittests/Tooling/QualTypeNamesTest.cpp
index 1139392983fce..3dfc94a9d27de 100644
--- a/clang/unittests/Tooling/QualTypeNamesTest.cpp
+++ b/clang/unittests/Tooling/QualTypeNamesTest.cpp
@@ -361,14 +361,14 @@ TEST(QualTypeNameTest, AnonStrucs) {
   TypeNameVisitor AnonStrucs;
   AnonStrucs.ExpectedQualTypeNames["a"] = "short";
   AnonStrucs.ExpectedQualTypeNames["un_in_st_1"] =
-      "union (unnamed struct at input.cc:1:1)::(unnamed union at "
+      "union (unnamed struct at input.cc:1:1)::(unnamed at "
       "input.cc:2:27)";
   AnonStrucs.ExpectedQualTypeNames["b"] = "short";
   AnonStrucs.ExpectedQualTypeNames["un_in_st_2"] =
-      "union (unnamed struct at input.cc:1:1)::(unnamed union at "
+      "union (unnamed struct at input.cc:1:1)::(unnamed at "
       "input.cc:5:27)";
   AnonStrucs.ExpectedQualTypeNames["anon_st"] =
-      "struct (unnamed struct at input.cc:1:1)";
+      "struct (unnamed at input.cc:1:1)";
   AnonStrucs.runOver(R"(struct {
                           union {
                             short a;


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to