Skip to content

Commit 599ca71

Browse files
authored
[lldb] Merge CompilerContextKind::{Class,Struct} (#96145)
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](#95905 (comment)).
1 parent 1c025fb commit 599ca71

File tree

11 files changed

+48
-62
lines changed

11 files changed

+48
-62
lines changed

lldb/include/lldb/lldb-private-enumerations.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLDB_LLDB_PRIVATE_ENUMERATIONS_H
1111

1212
#include "lldb/lldb-enumerations.h"
13+
#include "llvm/ADT/BitmaskEnum.h"
1314
#include "llvm/ADT/StringRef.h"
1415
#include "llvm/Support/FormatProviders.h"
1516
#include "llvm/Support/raw_ostream.h"
@@ -197,8 +198,7 @@ enum class CompilerContextKind : uint16_t {
197198
TranslationUnit = 1,
198199
Module = 1 << 1,
199200
Namespace = 1 << 2,
200-
Class = 1 << 3,
201-
Struct = 1 << 4,
201+
ClassOrStruct = 1 << 3,
202202
Union = 1 << 5,
203203
Function = 1 << 6,
204204
Variable = 1 << 7,
@@ -210,10 +210,12 @@ enum class CompilerContextKind : uint16_t {
210210
/// Match 0..n nested modules.
211211
AnyModule = Any | Module,
212212
/// Match any type.
213-
AnyType = Any | Class | Struct | Union | Enum | Typedef | Builtin,
213+
AnyType = Any | ClassOrStruct | Union | Enum | Typedef | Builtin,
214214
/// Math any declaration context.
215-
AnyDeclContext = Any | Namespace | Class | Struct | Union | Enum | Function
215+
AnyDeclContext = Any | Namespace | ClassOrStruct | Union | Enum | Function,
216+
LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/AnyDeclContext),
216217
};
218+
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
217219

218220
// Enumerations that can be used to specify the kind of metric we're looking at
219221
// when collecting stats.

lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -394,15 +394,13 @@ static void GetDeclContextImpl(DWARFDIE die,
394394
case DW_TAG_namespace:
395395
push_ctx(CompilerContextKind::Namespace, die.GetName());
396396
break;
397+
case DW_TAG_class_type:
397398
case DW_TAG_structure_type:
398-
push_ctx(CompilerContextKind::Struct, die.GetName());
399+
push_ctx(CompilerContextKind::ClassOrStruct, die.GetName());
399400
break;
400401
case DW_TAG_union_type:
401402
push_ctx(CompilerContextKind::Union, die.GetName());
402403
break;
403-
case DW_TAG_class_type:
404-
push_ctx(CompilerContextKind::Class, die.GetName());
405-
break;
406404
case DW_TAG_enumeration_type:
407405
push_ctx(CompilerContextKind::Enum, die.GetName());
408406
break;
@@ -456,15 +454,13 @@ static void GetTypeLookupContextImpl(DWARFDIE die,
456454
case DW_TAG_namespace:
457455
push_ctx(CompilerContextKind::Namespace, die.GetName());
458456
break;
457+
case DW_TAG_class_type:
459458
case DW_TAG_structure_type:
460-
push_ctx(CompilerContextKind::Struct, die.GetName());
459+
push_ctx(CompilerContextKind::ClassOrStruct, die.GetName());
461460
break;
462461
case DW_TAG_union_type:
463462
push_ctx(CompilerContextKind::Union, die.GetName());
464463
break;
465-
case DW_TAG_class_type:
466-
push_ctx(CompilerContextKind::Class, die.GetName());
467-
break;
468464
case DW_TAG_enumeration_type:
469465
push_ctx(CompilerContextKind::Enum, die.GetName());
470466
break;

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -9173,10 +9173,8 @@ static CompilerContextKind GetCompilerKind(clang::Decl::Kind clang_kind,
91739173
if (decl_ctx) {
91749174
if (decl_ctx->isFunctionOrMethod())
91759175
return CompilerContextKind::Function;
9176-
else if (decl_ctx->isRecord())
9177-
return (CompilerContextKind)((uint16_t)CompilerContextKind::Class |
9178-
(uint16_t)CompilerContextKind::Struct |
9179-
(uint16_t)CompilerContextKind::Union);
9176+
if (decl_ctx->isRecord())
9177+
return CompilerContextKind::ClassOrStruct | CompilerContextKind::Union;
91809178
}
91819179
break;
91829180
}

lldb/source/Symbol/Type.cpp

+10-15
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,18 @@ bool lldb_private::contextMatches(llvm::ArrayRef<CompilerContext> context_chain,
7575
static CompilerContextKind ConvertTypeClass(lldb::TypeClass type_class) {
7676
if (type_class == eTypeClassAny)
7777
return CompilerContextKind::AnyType;
78-
uint16_t result = 0;
79-
if (type_class & lldb::eTypeClassClass)
80-
result |= (uint16_t)CompilerContextKind::Class;
81-
if (type_class & lldb::eTypeClassStruct)
82-
result |= (uint16_t)CompilerContextKind::Struct;
78+
CompilerContextKind result = {};
79+
if (type_class & (lldb::eTypeClassClass | lldb::eTypeClassStruct))
80+
result |= CompilerContextKind::ClassOrStruct;
8381
if (type_class & lldb::eTypeClassUnion)
84-
result |= (uint16_t)CompilerContextKind::Union;
82+
result |= CompilerContextKind::Union;
8583
if (type_class & lldb::eTypeClassEnumeration)
86-
result |= (uint16_t)CompilerContextKind::Enum;
84+
result |= CompilerContextKind::Enum;
8785
if (type_class & lldb::eTypeClassFunction)
88-
result |= (uint16_t)CompilerContextKind::Function;
86+
result |= CompilerContextKind::Function;
8987
if (type_class & lldb::eTypeClassTypedef)
90-
result |= (uint16_t)CompilerContextKind::Typedef;
91-
return (CompilerContextKind)result;
88+
result |= CompilerContextKind::Typedef;
89+
return result;
9290
}
9391

9492
TypeQuery::TypeQuery(llvm::StringRef name, TypeQueryOptions options)
@@ -207,11 +205,8 @@ void CompilerContext::Dump(Stream &s) const {
207205
case CompilerContextKind::Namespace:
208206
s << "Namespace";
209207
break;
210-
case CompilerContextKind::Class:
211-
s << "Class";
212-
break;
213-
case CompilerContextKind::Struct:
214-
s << "Structure";
208+
case CompilerContextKind::ClassOrStruct:
209+
s << "ClassOrStruct";
215210
break;
216211
case CompilerContextKind::Union:
217212
s << "Union";

lldb/test/Shell/SymbolFile/DWARF/clang-gmodules-type-lookup.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// RUN: %clangxx_host -g -gmodules -fmodules -std=c99 -x c -include-pch %t.pch %s -c -o %t.o
88
// RUN: %clangxx_host %t.o -o %t.exe
99
// RUN: lldb-test symbols -dump-clang-ast -find type --language=C99 \
10-
// RUN: -compiler-context 'AnyModule:*,Struct:TypeFromPCH' %t.exe | FileCheck %s
10+
// RUN: -compiler-context 'AnyModule:*,ClassOrStruct:TypeFromPCH' %t.exe | FileCheck %s
1111

1212
anchor_t anchor;
1313

lldb/test/Shell/SymbolFile/DWARF/x86/compilercontext.ll

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
; Test finding types by CompilerContext.
22
; RUN: llc %s -filetype=obj -o %t.o
33
; RUN: lldb-test symbols %t.o -find=type --language=C99 \
4-
; RUN: -compiler-context="Module:CModule,Module:SubModule,Struct:FromSubmoduleX" \
4+
; RUN: -compiler-context="Module:CModule,Module:SubModule,ClassOrStruct:FromSubmoduleX" \
55
; RUN: | FileCheck %s --check-prefix=NORESULTS
66
; RUN: lldb-test symbols %t.o -find=type --language=C++ \
7-
; RUN: -compiler-context="Module:CModule,Module:SubModule,Struct:FromSubmodule" \
7+
; RUN: -compiler-context="Module:CModule,Module:SubModule,ClassOrStruct:FromSubmodule" \
88
; RUN: | FileCheck %s --check-prefix=NORESULTS
99
; RUN: lldb-test symbols %t.o -find=type --language=C99 \
10-
; RUN: -compiler-context="Module:CModule,Module:SubModule,Struct:FromSubmodule" \
10+
; RUN: -compiler-context="Module:CModule,Module:SubModule,ClassOrStruct:FromSubmodule" \
1111
; RUN: | FileCheck %s
1212
; RUN: lldb-test symbols %t.o -find=type --language=C99 \
13-
; RUN: -compiler-context="Module:CModule,AnyModule:*,Struct:FromSubmodule" \
13+
; RUN: -compiler-context="Module:CModule,AnyModule:*,ClassOrStruct:FromSubmodule" \
1414
; RUN: | FileCheck %s
1515
; RUN: lldb-test symbols %t.o -find=type --language=C99 \
16-
; RUN: -compiler-context="AnyModule:*,Struct:FromSubmodule" \
16+
; RUN: -compiler-context="AnyModule:*,ClassOrStruct:FromSubmodule" \
1717
; RUN: | FileCheck %s
1818
; RUN: lldb-test symbols %t.o -find=type --language=C99 \
1919
; RUN: -compiler-context="Module:CModule,Module:SubModule,AnyType:FromSubmodule" \

lldb/test/Shell/SymbolFile/DWARF/x86/find-basic-function.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
// RUN: FileCheck --check-prefix=FULL-MANGLED-METHOD %s
3535
// RUN: lldb-test symbols --name=foo --context=context --find=function --function-flags=base %t | \
3636
// RUN: FileCheck --check-prefix=CONTEXT %s
37-
// RUN: lldb-test symbols --compiler-context=Struct:sbar,Function:foo -language=c++ -find=function -function-flags=method %t | \
37+
// RUN: lldb-test symbols --compiler-context=ClassOrStruct:sbar,Function:foo -language=c++ -find=function -function-flags=method %t | \
3838
// RUN: FileCheck --check-prefix=COMPILER-CONTEXT %s
3939
// RUN: lldb-test symbols --name=not_there --find=function %t | \
4040
// RUN: FileCheck --check-prefix=EMPTY %s

lldb/test/Shell/SymbolFile/DWARF/x86/module-ownership.mm

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
TopLevelStruct s1;
1919
// RUN: lldb-test symbols -dump-clang-ast -find type --language=ObjC++ \
20-
// RUN: -compiler-context 'Module:A,Struct:TopLevelStruct' %t.o \
20+
// RUN: -compiler-context 'Module:A,ClassOrStruct:TopLevelStruct' %t.o \
2121
// RUN: | FileCheck %s --check-prefix=CHECK-TOPLEVELSTRUCT
2222
// CHECK-TOPLEVELSTRUCT: CXXRecordDecl {{.*}} imported in A struct TopLevelStruct
2323
// CHECK-TOPLEVELSTRUCT: -FieldDecl {{.*}} in A a 'int'
@@ -45,7 +45,7 @@ @implementation SomeClass {
4545

4646
SomeClass *obj1;
4747
// RUN: lldb-test symbols -dump-clang-ast -find type --language=ObjC++ \
48-
// RUN: -compiler-context 'Module:A,Struct:SomeClass' %t.o \
48+
// RUN: -compiler-context 'Module:A,ClassOrStruct:SomeClass' %t.o \
4949
// RUN: | FileCheck %s --check-prefix=CHECK-OBJC
5050
// CHECK-OBJC: ObjCInterfaceDecl {{.*}} imported in A <undeserialized declarations> SomeClass
5151
// CHECK-OBJC-NEXT: |-ObjCIvarDecl

lldb/tools/lldb-test/lldb-test.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,7 @@ llvm::SmallVector<CompilerContext, 4> parseCompilerContext() {
306306
.Case("TranslationUnit", CompilerContextKind::TranslationUnit)
307307
.Case("Module", CompilerContextKind::Module)
308308
.Case("Namespace", CompilerContextKind::Namespace)
309-
.Case("Class", CompilerContextKind::Class)
310-
.Case("Struct", CompilerContextKind::Struct)
309+
.Case("ClassOrStruct", CompilerContextKind::ClassOrStruct)
311310
.Case("Union", CompilerContextKind::Union)
312311
.Case("Function", CompilerContextKind::Function)
313312
.Case("Variable", CompilerContextKind::Variable)

lldb/unittests/Symbol/TestType.cpp

+12-18
Original file line numberDiff line numberDiff line change
@@ -48,32 +48,26 @@ TEST(Type, GetTypeScopeAndBasename) {
4848
}
4949

5050
TEST(Type, CompilerContextPattern) {
51-
std::vector<CompilerContext> mms = {
52-
{CompilerContextKind::Module, ConstString("A")},
53-
{CompilerContextKind::Module, ConstString("B")},
54-
{CompilerContextKind::Struct, ConstString("S")}};
55-
EXPECT_TRUE(contextMatches(mms, mms));
5651
std::vector<CompilerContext> mmc = {
5752
{CompilerContextKind::Module, ConstString("A")},
5853
{CompilerContextKind::Module, ConstString("B")},
59-
{CompilerContextKind::Class, ConstString("S")}};
60-
EXPECT_FALSE(contextMatches(mms, mmc));
61-
std::vector<CompilerContext> ms = {
54+
{CompilerContextKind::ClassOrStruct, ConstString("S")}};
55+
std::vector<CompilerContext> mc = {
6256
{CompilerContextKind::Module, ConstString("A")},
63-
{CompilerContextKind::Struct, ConstString("S")}};
64-
std::vector<CompilerContext> mas = {
57+
{CompilerContextKind::ClassOrStruct, ConstString("S")}};
58+
std::vector<CompilerContext> mac = {
6559
{CompilerContextKind::Module, ConstString("A")},
6660
{CompilerContextKind::AnyModule, ConstString("*")},
67-
{CompilerContextKind::Struct, ConstString("S")}};
68-
EXPECT_TRUE(contextMatches(mms, mas));
69-
EXPECT_TRUE(contextMatches(ms, mas));
70-
EXPECT_FALSE(contextMatches(mas, ms));
71-
std::vector<CompilerContext> mmms = {
61+
{CompilerContextKind::ClassOrStruct, ConstString("S")}};
62+
EXPECT_TRUE(contextMatches(mmc, mac));
63+
EXPECT_TRUE(contextMatches(mc, mac));
64+
EXPECT_FALSE(contextMatches(mac, mc));
65+
std::vector<CompilerContext> mmmc = {
7266
{CompilerContextKind::Module, ConstString("A")},
7367
{CompilerContextKind::Module, ConstString("B")},
7468
{CompilerContextKind::Module, ConstString("C")},
75-
{CompilerContextKind::Struct, ConstString("S")}};
76-
EXPECT_TRUE(contextMatches(mmms, mas));
69+
{CompilerContextKind::ClassOrStruct, ConstString("S")}};
70+
EXPECT_TRUE(contextMatches(mmmc, mac));
7771
std::vector<CompilerContext> mme = {
7872
{CompilerContextKind::Module, ConstString("A")},
7973
{CompilerContextKind::Module, ConstString("B")},
@@ -83,7 +77,7 @@ TEST(Type, CompilerContextPattern) {
8377
{CompilerContextKind::Module, ConstString("B")},
8478
{CompilerContextKind::AnyType, ConstString("S")}};
8579
EXPECT_TRUE(contextMatches(mme, mma));
86-
EXPECT_TRUE(contextMatches(mms, mma));
80+
EXPECT_TRUE(contextMatches(mmc, mma));
8781
std::vector<CompilerContext> mme2 = {
8882
{CompilerContextKind::Module, ConstString("A")},
8983
{CompilerContextKind::Module, ConstString("B")},

lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ TEST(DWARFDIETest, GetContext) {
249249
return CompilerContext(CompilerContextKind::Namespace, ConstString(name));
250250
};
251251
auto make_struct = [](llvm::StringRef name) {
252-
return CompilerContext(CompilerContextKind::Struct, ConstString(name));
252+
return CompilerContext(CompilerContextKind::ClassOrStruct,
253+
ConstString(name));
253254
};
254255
DWARFDIE struct_die = unit->DIE().GetFirstChild().GetFirstChild();
255256
ASSERT_TRUE(struct_die);
@@ -356,7 +357,8 @@ TEST(DWARFDIETest, GetContextInFunction) {
356357
return CompilerContext(CompilerContextKind::Namespace, ConstString(name));
357358
};
358359
auto make_struct = [](llvm::StringRef name) {
359-
return CompilerContext(CompilerContextKind::Struct, ConstString(name));
360+
return CompilerContext(CompilerContextKind::ClassOrStruct,
361+
ConstString(name));
360362
};
361363
// Grab the "a::struct_t" type from the "a" namespace
362364
DWARFDIE a_struct_die = unit->DIE().GetFirstChild().GetFirstChild();

0 commit comments

Comments
 (0)