Skip to content

Commit 4032875

Browse files
committed
[clang][ASTImporter] Add support for LLDB's new type lookup mechanism
1 parent 313a1af commit 4032875

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

clang/include/clang/AST/ASTImporter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ class TypeSourceInfo;
211211

212212
/// Whether to perform a minimal import.
213213
bool Minimal;
214+
bool LLDBRedeclCompletion = false;
214215

215216
ODRHandlingType ODRHandling;
216217

@@ -296,8 +297,10 @@ class TypeSourceInfo;
296297
/// Whether the importer will perform a minimal import, creating
297298
/// to-be-completed forward declarations when possible.
298299
bool isMinimalImport() const { return Minimal; }
300+
bool hasLLDBRedeclCompletion() const { return LLDBRedeclCompletion; }
299301

300302
void setODRHandling(ODRHandlingType T) { ODRHandling = T; }
303+
void setLLDBRedeclCompletion(bool Val) { LLDBRedeclCompletion = Val; }
301304

302305
/// \brief Import the given object, returns the result.
303306
///

clang/lib/AST/ASTImporter.cpp

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,8 @@ Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) {
10311031

10321032
template <typename T>
10331033
bool ASTNodeImporter::hasSameVisibilityContextAndLinkage(T *Found, T *From) {
1034-
if (Found->getLinkageInternal() != From->getLinkageInternal())
1034+
if (!Importer.hasLLDBRedeclCompletion() &&
1035+
Found->getLinkageInternal() != From->getLinkageInternal())
10351036
return false;
10361037

10371038
if (From->hasExternalFormalLinkage())
@@ -1482,7 +1483,9 @@ ExpectedType ASTNodeImporter::VisitInjectedClassNameType(
14821483
}
14831484

14841485
ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) {
1486+
// getCanonicalDecl in order to not trigger redeclaration completion
14851487
Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl());
1488+
14861489
if (!ToDeclOrErr)
14871490
return ToDeclOrErr.takeError();
14881491

@@ -1771,8 +1774,9 @@ Error ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) {
17711774

17721775
if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
17731776
if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) {
1774-
if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() &&
1775-
!ToRecord->getDefinition()) {
1777+
if (FromRecord->getDefinition() && !ToRecord->getDefinition() &&
1778+
(Importer.hasLLDBRedeclCompletion() ||
1779+
FromRecord->isCompleteDefinition())) {
17761780
if (Error Err = ImportDefinition(FromRecord, ToRecord))
17771781
return Err;
17781782
}
@@ -1873,12 +1877,15 @@ ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) {
18731877
ImportedOrErr.takeError());
18741878
continue;
18751879
}
1876-
FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From);
1877-
Decl *ImportedDecl = *ImportedOrErr;
1878-
FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl);
1879-
if (FieldFrom && FieldTo) {
1880-
Error Err = ImportFieldDeclDefinition(FieldFrom, FieldTo);
1881-
HandleChildErrors.handleChildImportResult(ChildErrors, std::move(Err));
1880+
1881+
if (Importer.hasLLDBRedeclCompletion()) {
1882+
FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From);
1883+
Decl *ImportedDecl = *ImportedOrErr;
1884+
FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl);
1885+
if (FieldFrom && FieldTo) {
1886+
Error Err = ImportFieldDeclDefinition(FieldFrom, FieldTo);
1887+
HandleChildErrors.handleChildImportResult(ChildErrors, std::move(Err));
1888+
}
18821889
}
18831890
}
18841891

@@ -2039,7 +2046,11 @@ Error ASTNodeImporter::ImportDefinition(
20392046
To->completeDefinition();
20402047
};
20412048

2042-
if (To->getDefinition() || To->isBeingDefined()) {
2049+
bool hasDef = (Importer.hasLLDBRedeclCompletion() &&
2050+
To->isThisDeclarationADefinition()) ||
2051+
To->getDefinition();
2052+
2053+
if (hasDef || To->isBeingDefined()) {
20432054
if (Kind == IDK_Everything ||
20442055
// In case of lambdas, the class already has a definition ptr set, but
20452056
// the contained decls are not imported yet. Also, isBeingDefined was
@@ -2558,6 +2569,9 @@ ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) {
25582569
!hasSameVisibilityContextAndLinkage(FoundR, FromR))
25592570
continue;
25602571
}
2572+
2573+
if (Importer.hasLLDBRedeclCompletion() && Importer.isMinimalImport())
2574+
return Importer.MapImported(D, FoundTypedef);
25612575
// If the "From" context has a complete underlying type but we
25622576
// already have a complete underlying type then return with that.
25632577
if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType())
@@ -2822,9 +2836,11 @@ ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) {
28222836
return POIOrErr.takeError();
28232837
}
28242838

2839+
auto Kind = Importer.hasLLDBRedeclCompletion() ? IDK_Everything : IDK_Default;
2840+
28252841
// Import the definition
28262842
if (D->isCompleteDefinition())
2827-
if (Error Err = ImportDefinition(D, D2))
2843+
if (Error Err = ImportDefinition(D, D2, Kind))
28282844
return std::move(Err);
28292845

28302846
return D2;
@@ -2902,7 +2918,8 @@ ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) {
29022918

29032919
if (IsStructuralMatch(D, FoundRecord)) {
29042920
RecordDecl *FoundDef = FoundRecord->getDefinition();
2905-
if (D->isThisDeclarationADefinition() && FoundDef) {
2921+
if (!Importer.hasLLDBRedeclCompletion() &&
2922+
D->isThisDeclarationADefinition() && FoundDef) {
29062923
// FIXME: Structural equivalence check should check for same
29072924
// user-defined methods.
29082925
Importer.MapImported(D, FoundDef);
@@ -3078,8 +3095,9 @@ ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) {
30783095
if (D->isAnonymousStructOrUnion())
30793096
D2->setAnonymousStructOrUnion(true);
30803097

3098+
auto Kind = Importer.hasLLDBRedeclCompletion() ? IDK_Everything : IDK_Default;
30813099
if (D->isCompleteDefinition())
3082-
if (Error Err = ImportDefinition(D, D2, IDK_Default))
3100+
if (Error Err = ImportDefinition(D, D2, Kind))
30833101
return std::move(Err);
30843102

30853103
return D2;
@@ -5203,7 +5221,8 @@ Error ASTNodeImporter::ImportDefinition(
52035221
diag::note_odr_objc_missing_superclass);
52045222
}
52055223

5206-
if (shouldForceImportDeclContext(Kind))
5224+
if (Importer.hasLLDBRedeclCompletion() ||
5225+
shouldForceImportDeclContext(Kind))
52075226
if (Error Err = ImportDeclContext(From))
52085227
return Err;
52095228
return Error::success();
@@ -6084,8 +6103,9 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl(
60846103
}
60856104
}
60866105

6106+
auto Kind = Importer.hasLLDBRedeclCompletion() ? IDK_Everything : IDK_Default;
60876107
if (D->isCompleteDefinition())
6088-
if (Error Err = ImportDefinition(D, D2))
6108+
if (Error Err = ImportDefinition(D, D2, Kind))
60896109
return std::move(Err);
60906110

60916111
return D2;

0 commit comments

Comments
 (0)