llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)

<details>
<summary>Changes</summary>

Our dwarf parsing code treats structures and classes as interchangable. 
CompilerContextKind is used when looking DIEs for types. This makes sure we 
always they're treated the same way.

See also #<!-- -->95905#discussion_r1645686628.

---
Full diff: https://github.com/llvm/llvm-project/pull/96145.diff


11 Files Affected:

- (modified) lldb/include/lldb/lldb-private-enumerations.h (+6-4) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp (+4-8) 
- (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp (+2-4) 
- (modified) lldb/source/Symbol/Type.cpp (+10-15) 
- (modified) lldb/test/Shell/SymbolFile/DWARF/clang-gmodules-type-lookup.c 
(+1-1) 
- (modified) lldb/test/Shell/SymbolFile/DWARF/x86/compilercontext.ll (+5-5) 
- (modified) lldb/test/Shell/SymbolFile/DWARF/x86/find-basic-function.cpp 
(+1-1) 
- (modified) lldb/test/Shell/SymbolFile/DWARF/x86/module-ownership.mm (+2-2) 
- (modified) lldb/tools/lldb-test/lldb-test.cpp (+1-2) 
- (modified) lldb/unittests/Symbol/TestType.cpp (+12-18) 
- (modified) lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp (+4-2) 


``````````diff
diff --git a/lldb/include/lldb/lldb-private-enumerations.h 
b/lldb/include/lldb/lldb-private-enumerations.h
index 68e060f2393f7..9d18316dcea25 100644
--- a/lldb/include/lldb/lldb-private-enumerations.h
+++ b/lldb/include/lldb/lldb-private-enumerations.h
@@ -10,6 +10,7 @@
 #define LLDB_LLDB_PRIVATE_ENUMERATIONS_H
 
 #include "lldb/lldb-enumerations.h"
+#include "llvm/ADT/BitmaskEnum.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FormatProviders.h"
 #include "llvm/Support/raw_ostream.h"
@@ -197,8 +198,7 @@ enum class CompilerContextKind : uint16_t {
   TranslationUnit = 1,
   Module = 1 << 1,
   Namespace = 1 << 2,
-  Class = 1 << 3,
-  Struct = 1 << 4,
+  ClassOrStruct = 1 << 3,
   Union = 1 << 5,
   Function = 1 << 6,
   Variable = 1 << 7,
@@ -210,10 +210,12 @@ enum class CompilerContextKind : uint16_t {
   /// Match 0..n nested modules.
   AnyModule = Any | Module,
   /// Match any type.
-  AnyType = Any | Class | Struct | Union | Enum | Typedef | Builtin,
+  AnyType = Any | ClassOrStruct | Union | Enum | Typedef | Builtin,
   /// Math any declaration context.
-  AnyDeclContext = Any | Namespace | Class | Struct | Union | Enum | Function
+  AnyDeclContext = Any | Namespace | ClassOrStruct | Union | Enum | Function,
+  LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/AnyDeclContext),
 };
+LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
 
 // Enumerations that can be used to specify the kind of metric we're looking at
 // when collecting stats.
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
index ada3da85112fe..fb32e2adeb3fe 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
@@ -394,15 +394,13 @@ static void GetDeclContextImpl(DWARFDIE die,
     case DW_TAG_namespace:
       push_ctx(CompilerContextKind::Namespace, die.GetName());
       break;
+    case DW_TAG_class_type:
     case DW_TAG_structure_type:
-      push_ctx(CompilerContextKind::Struct, die.GetName());
+      push_ctx(CompilerContextKind::ClassOrStruct, die.GetName());
       break;
     case DW_TAG_union_type:
       push_ctx(CompilerContextKind::Union, die.GetName());
       break;
-    case DW_TAG_class_type:
-      push_ctx(CompilerContextKind::Class, die.GetName());
-      break;
     case DW_TAG_enumeration_type:
       push_ctx(CompilerContextKind::Enum, die.GetName());
       break;
@@ -456,15 +454,13 @@ static void GetTypeLookupContextImpl(DWARFDIE die,
     case DW_TAG_namespace:
       push_ctx(CompilerContextKind::Namespace, die.GetName());
       break;
+    case DW_TAG_class_type:
     case DW_TAG_structure_type:
-      push_ctx(CompilerContextKind::Struct, die.GetName());
+      push_ctx(CompilerContextKind::ClassOrStruct, die.GetName());
       break;
     case DW_TAG_union_type:
       push_ctx(CompilerContextKind::Union, die.GetName());
       break;
-    case DW_TAG_class_type:
-      push_ctx(CompilerContextKind::Class, die.GetName());
-      break;
     case DW_TAG_enumeration_type:
       push_ctx(CompilerContextKind::Enum, die.GetName());
       break;
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 0270c67366d1d..ffd9ff2021fbd 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -9173,10 +9173,8 @@ static CompilerContextKind 
GetCompilerKind(clang::Decl::Kind clang_kind,
     if (decl_ctx) {
       if (decl_ctx->isFunctionOrMethod())
         return CompilerContextKind::Function;
-      else if (decl_ctx->isRecord())
-        return (CompilerContextKind)((uint16_t)CompilerContextKind::Class |
-                                     (uint16_t)CompilerContextKind::Struct |
-                                     (uint16_t)CompilerContextKind::Union);
+      if (decl_ctx->isRecord())
+        return CompilerContextKind::ClassOrStruct | CompilerContextKind::Union;
     }
     break;
   }
diff --git a/lldb/source/Symbol/Type.cpp b/lldb/source/Symbol/Type.cpp
index 585808ace15ce..e76574795733f 100644
--- a/lldb/source/Symbol/Type.cpp
+++ b/lldb/source/Symbol/Type.cpp
@@ -75,20 +75,18 @@ bool 
lldb_private::contextMatches(llvm::ArrayRef<CompilerContext> context_chain,
 static CompilerContextKind ConvertTypeClass(lldb::TypeClass type_class) {
   if (type_class == eTypeClassAny)
     return CompilerContextKind::AnyType;
-  uint16_t result = 0;
-  if (type_class & lldb::eTypeClassClass)
-    result |= (uint16_t)CompilerContextKind::Class;
-  if (type_class & lldb::eTypeClassStruct)
-    result |= (uint16_t)CompilerContextKind::Struct;
+  CompilerContextKind result = {};
+  if (type_class & (lldb::eTypeClassClass | lldb::eTypeClassStruct))
+    result |= CompilerContextKind::ClassOrStruct;
   if (type_class & lldb::eTypeClassUnion)
-    result |= (uint16_t)CompilerContextKind::Union;
+    result |= CompilerContextKind::Union;
   if (type_class & lldb::eTypeClassEnumeration)
-    result |= (uint16_t)CompilerContextKind::Enum;
+    result |= CompilerContextKind::Enum;
   if (type_class & lldb::eTypeClassFunction)
-    result |= (uint16_t)CompilerContextKind::Function;
+    result |= CompilerContextKind::Function;
   if (type_class & lldb::eTypeClassTypedef)
-    result |= (uint16_t)CompilerContextKind::Typedef;
-  return (CompilerContextKind)result;
+    result |= CompilerContextKind::Typedef;
+  return result;
 }
 
 TypeQuery::TypeQuery(llvm::StringRef name, TypeQueryOptions options)
@@ -207,11 +205,8 @@ void CompilerContext::Dump(Stream &s) const {
   case CompilerContextKind::Namespace:
     s << "Namespace";
     break;
-  case CompilerContextKind::Class:
-    s << "Class";
-    break;
-  case CompilerContextKind::Struct:
-    s << "Structure";
+  case CompilerContextKind::ClassOrStruct:
+    s << "ClassOrStruct";
     break;
   case CompilerContextKind::Union:
     s << "Union";
diff --git a/lldb/test/Shell/SymbolFile/DWARF/clang-gmodules-type-lookup.c 
b/lldb/test/Shell/SymbolFile/DWARF/clang-gmodules-type-lookup.c
index f42a5d3907dfd..a8da692e57b1f 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/clang-gmodules-type-lookup.c
+++ b/lldb/test/Shell/SymbolFile/DWARF/clang-gmodules-type-lookup.c
@@ -7,7 +7,7 @@
 // RUN: %clangxx_host -g -gmodules -fmodules -std=c99 -x c -include-pch %t.pch 
%s -c -o %t.o
 // RUN: %clangxx_host %t.o -o %t.exe
 // RUN: lldb-test symbols -dump-clang-ast -find type --language=C99 \
-// RUN:   -compiler-context 'AnyModule:*,Struct:TypeFromPCH' %t.exe | 
FileCheck %s
+// RUN:   -compiler-context 'AnyModule:*,ClassOrStruct:TypeFromPCH' %t.exe | 
FileCheck %s
 
 anchor_t anchor;
 
diff --git a/lldb/test/Shell/SymbolFile/DWARF/x86/compilercontext.ll 
b/lldb/test/Shell/SymbolFile/DWARF/x86/compilercontext.ll
index 149f7efbbfbe4..8fa45e955abf1 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/x86/compilercontext.ll
+++ b/lldb/test/Shell/SymbolFile/DWARF/x86/compilercontext.ll
@@ -1,19 +1,19 @@
 ; Test finding types by CompilerContext.
 ; RUN: llc %s -filetype=obj -o %t.o
 ; RUN: lldb-test symbols %t.o -find=type --language=C99 \
-; RUN:   
-compiler-context="Module:CModule,Module:SubModule,Struct:FromSubmoduleX" \
+; RUN:   
-compiler-context="Module:CModule,Module:SubModule,ClassOrStruct:FromSubmoduleX"
 \
 ; RUN:   | FileCheck %s --check-prefix=NORESULTS
 ; RUN: lldb-test symbols %t.o -find=type --language=C++ \
-; RUN:   
-compiler-context="Module:CModule,Module:SubModule,Struct:FromSubmodule" \
+; RUN:   
-compiler-context="Module:CModule,Module:SubModule,ClassOrStruct:FromSubmodule" 
\
 ; RUN:   | FileCheck %s --check-prefix=NORESULTS
 ; RUN: lldb-test symbols %t.o -find=type --language=C99 \
-; RUN:   
-compiler-context="Module:CModule,Module:SubModule,Struct:FromSubmodule" \
+; RUN:   
-compiler-context="Module:CModule,Module:SubModule,ClassOrStruct:FromSubmodule" 
\
 ; RUN:   | FileCheck %s
 ; RUN: lldb-test symbols %t.o -find=type --language=C99 \
-; RUN:   -compiler-context="Module:CModule,AnyModule:*,Struct:FromSubmodule" \
+; RUN:   
-compiler-context="Module:CModule,AnyModule:*,ClassOrStruct:FromSubmodule" \
 ; RUN:   | FileCheck %s
 ; RUN: lldb-test symbols %t.o -find=type --language=C99 \
-; RUN:   -compiler-context="AnyModule:*,Struct:FromSubmodule" \
+; RUN:   -compiler-context="AnyModule:*,ClassOrStruct:FromSubmodule" \
 ; RUN:   | FileCheck %s
 ; RUN: lldb-test symbols %t.o -find=type --language=C99 \
 ; RUN:   
-compiler-context="Module:CModule,Module:SubModule,AnyType:FromSubmodule" \
diff --git a/lldb/test/Shell/SymbolFile/DWARF/x86/find-basic-function.cpp 
b/lldb/test/Shell/SymbolFile/DWARF/x86/find-basic-function.cpp
index b9a63525d0711..c42f9fe0b8b52 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/x86/find-basic-function.cpp
+++ b/lldb/test/Shell/SymbolFile/DWARF/x86/find-basic-function.cpp
@@ -34,7 +34,7 @@
 // RUN:   FileCheck --check-prefix=FULL-MANGLED-METHOD %s
 // RUN: lldb-test symbols --name=foo --context=context --find=function 
--function-flags=base %t | \
 // RUN:   FileCheck --check-prefix=CONTEXT %s
-// RUN: lldb-test symbols --compiler-context=Struct:sbar,Function:foo 
-language=c++ -find=function -function-flags=method %t | \
+// RUN: lldb-test symbols --compiler-context=ClassOrStruct:sbar,Function:foo 
-language=c++ -find=function -function-flags=method %t | \
 // RUN:   FileCheck --check-prefix=COMPILER-CONTEXT %s
 // RUN: lldb-test symbols --name=not_there --find=function %t | \
 // RUN:   FileCheck --check-prefix=EMPTY %s
diff --git a/lldb/test/Shell/SymbolFile/DWARF/x86/module-ownership.mm 
b/lldb/test/Shell/SymbolFile/DWARF/x86/module-ownership.mm
index 4f39e2e5a9e17..2dec109a781ca 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/x86/module-ownership.mm
+++ b/lldb/test/Shell/SymbolFile/DWARF/x86/module-ownership.mm
@@ -17,7 +17,7 @@
 
 TopLevelStruct s1;
 // RUN: lldb-test symbols -dump-clang-ast -find type --language=ObjC++ \
-// RUN:   -compiler-context 'Module:A,Struct:TopLevelStruct' %t.o \
+// RUN:   -compiler-context 'Module:A,ClassOrStruct:TopLevelStruct' %t.o \
 // RUN:   | FileCheck %s --check-prefix=CHECK-TOPLEVELSTRUCT
 // CHECK-TOPLEVELSTRUCT: CXXRecordDecl {{.*}} imported in A struct 
TopLevelStruct
 // CHECK-TOPLEVELSTRUCT: -FieldDecl {{.*}} in A a 'int'
@@ -45,7 +45,7 @@ @implementation SomeClass {
 
 SomeClass *obj1;
 // RUN: lldb-test symbols -dump-clang-ast -find type --language=ObjC++ \
-// RUN:   -compiler-context 'Module:A,Struct:SomeClass' %t.o \
+// RUN:   -compiler-context 'Module:A,ClassOrStruct:SomeClass' %t.o \
 // RUN:   | FileCheck %s --check-prefix=CHECK-OBJC
 // CHECK-OBJC: ObjCInterfaceDecl {{.*}} imported in A <undeserialized 
declarations> SomeClass
 // CHECK-OBJC-NEXT: |-ObjCIvarDecl
diff --git a/lldb/tools/lldb-test/lldb-test.cpp 
b/lldb/tools/lldb-test/lldb-test.cpp
index 33281cfb15074..30df2ddf864cd 100644
--- a/lldb/tools/lldb-test/lldb-test.cpp
+++ b/lldb/tools/lldb-test/lldb-test.cpp
@@ -306,8 +306,7 @@ llvm::SmallVector<CompilerContext, 4> 
parseCompilerContext() {
             .Case("TranslationUnit", CompilerContextKind::TranslationUnit)
             .Case("Module", CompilerContextKind::Module)
             .Case("Namespace", CompilerContextKind::Namespace)
-            .Case("Class", CompilerContextKind::Class)
-            .Case("Struct", CompilerContextKind::Struct)
+            .Case("ClassOrStruct", CompilerContextKind::ClassOrStruct)
             .Case("Union", CompilerContextKind::Union)
             .Case("Function", CompilerContextKind::Function)
             .Case("Variable", CompilerContextKind::Variable)
diff --git a/lldb/unittests/Symbol/TestType.cpp 
b/lldb/unittests/Symbol/TestType.cpp
index da849d804e4d5..79201d6ba2e59 100644
--- a/lldb/unittests/Symbol/TestType.cpp
+++ b/lldb/unittests/Symbol/TestType.cpp
@@ -48,32 +48,26 @@ TEST(Type, GetTypeScopeAndBasename) {
 }
 
 TEST(Type, CompilerContextPattern) {
-  std::vector<CompilerContext> mms = {
-      {CompilerContextKind::Module, ConstString("A")},
-      {CompilerContextKind::Module, ConstString("B")},
-      {CompilerContextKind::Struct, ConstString("S")}};
-  EXPECT_TRUE(contextMatches(mms, mms));
   std::vector<CompilerContext> mmc = {
       {CompilerContextKind::Module, ConstString("A")},
       {CompilerContextKind::Module, ConstString("B")},
-      {CompilerContextKind::Class, ConstString("S")}};
-  EXPECT_FALSE(contextMatches(mms, mmc));
-  std::vector<CompilerContext> ms = {
+      {CompilerContextKind::ClassOrStruct, ConstString("S")}};
+  std::vector<CompilerContext> mc = {
       {CompilerContextKind::Module, ConstString("A")},
-      {CompilerContextKind::Struct, ConstString("S")}};
-  std::vector<CompilerContext> mas = {
+      {CompilerContextKind::ClassOrStruct, ConstString("S")}};
+  std::vector<CompilerContext> mac = {
       {CompilerContextKind::Module, ConstString("A")},
       {CompilerContextKind::AnyModule, ConstString("*")},
-      {CompilerContextKind::Struct, ConstString("S")}};
-  EXPECT_TRUE(contextMatches(mms, mas));
-  EXPECT_TRUE(contextMatches(ms, mas));
-  EXPECT_FALSE(contextMatches(mas, ms));
-  std::vector<CompilerContext> mmms = {
+      {CompilerContextKind::ClassOrStruct, ConstString("S")}};
+  EXPECT_TRUE(contextMatches(mmc, mac));
+  EXPECT_TRUE(contextMatches(mc, mac));
+  EXPECT_FALSE(contextMatches(mac, mc));
+  std::vector<CompilerContext> mmmc = {
       {CompilerContextKind::Module, ConstString("A")},
       {CompilerContextKind::Module, ConstString("B")},
       {CompilerContextKind::Module, ConstString("C")},
-      {CompilerContextKind::Struct, ConstString("S")}};
-  EXPECT_TRUE(contextMatches(mmms, mas));
+      {CompilerContextKind::ClassOrStruct, ConstString("S")}};
+  EXPECT_TRUE(contextMatches(mmmc, mac));
   std::vector<CompilerContext> mme = {
       {CompilerContextKind::Module, ConstString("A")},
       {CompilerContextKind::Module, ConstString("B")},
@@ -83,7 +77,7 @@ TEST(Type, CompilerContextPattern) {
       {CompilerContextKind::Module, ConstString("B")},
       {CompilerContextKind::AnyType, ConstString("S")}};
   EXPECT_TRUE(contextMatches(mme, mma));
-  EXPECT_TRUE(contextMatches(mms, mma));
+  EXPECT_TRUE(contextMatches(mmc, mma));
   std::vector<CompilerContext> mme2 = {
       {CompilerContextKind::Module, ConstString("A")},
       {CompilerContextKind::Module, ConstString("B")},
diff --git a/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp 
b/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp
index 2a7d38f18fc77..122b7de7516b6 100644
--- a/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp
+++ b/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp
@@ -249,7 +249,8 @@ TEST(DWARFDIETest, GetContext) {
     return CompilerContext(CompilerContextKind::Namespace, ConstString(name));
   };
   auto make_struct = [](llvm::StringRef name) {
-    return CompilerContext(CompilerContextKind::Struct, ConstString(name));
+    return CompilerContext(CompilerContextKind::ClassOrStruct,
+                           ConstString(name));
   };
   DWARFDIE struct_die = unit->DIE().GetFirstChild().GetFirstChild();
   ASSERT_TRUE(struct_die);
@@ -356,7 +357,8 @@ TEST(DWARFDIETest, GetContextInFunction) {
     return CompilerContext(CompilerContextKind::Namespace, ConstString(name));
   };
   auto make_struct = [](llvm::StringRef name) {
-    return CompilerContext(CompilerContextKind::Struct, ConstString(name));
+    return CompilerContext(CompilerContextKind::ClassOrStruct,
+                           ConstString(name));
   };
   // Grab the "a::struct_t" type from the "a" namespace
   DWARFDIE a_struct_die = unit->DIE().GetFirstChild().GetFirstChild();

``````````

</details>


https://github.com/llvm/llvm-project/pull/96145
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to