Skip to content

Commit f5606eb

Browse files
committed
Try different approach withreverse order of loading specializations
1 parent 524344e commit f5606eb

File tree

4 files changed

+8
-16
lines changed

4 files changed

+8
-16
lines changed

clang/lib/AST/DeclTemplate.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,12 @@ void RedeclarableTemplateDecl::loadLazySpecializationsImpl() const {
349349
GlobalDeclID *Specs = CommonBasePtr->LazySpecializations;
350350
CommonBasePtr->LazySpecializations = nullptr;
351351
unsigned SpecSize = (*Specs++).getRawValue();
352-
for (unsigned I = 0; I != SpecSize; ++I)
353-
(void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
352+
// Load the specializations in reverse order so that the most recent
353+
// specialization are visited first so they become canonical declarations.
354+
// This order matches the order in which namelookup discovers declarations
355+
// coming from modules.
356+
for (unsigned I = SpecSize; I != 0; --I)
357+
(void)Context.getExternalSource()->GetExternalDecl(Specs[I-1]);
354358
}
355359
}
356360

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4387,11 +4387,6 @@ LocalInstantiationScope::findInstantiationOf(const Decl *D) {
43874387
// a previous declaration.
43884388
if (const TagDecl *Tag = dyn_cast<TagDecl>(CheckD))
43894389
CheckD = Tag->getPreviousDecl();
4390-
else if (const VarDecl *VD = dyn_cast<VarDecl>(CheckD))
4391-
// Check re-declaration chain for variable to deduplicate variables
4392-
// that might be captured inside lambdas. Function and lambda class
4393-
// inside can be loaded from different modules.
4394-
CheckD = VD->getPreviousDecl();
43954390
else
43964391
CheckD = nullptr;
43974392
} while (CheckD);

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3291,13 +3291,6 @@ DeclContext *ASTDeclReader::getPrimaryContextForMerging(ASTReader &Reader,
32913291
if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
32923292
return TU->getPrimaryContext();
32933293

3294-
// Merge VarDecls inside functions to deduplicate variables that might be
3295-
// captured inside lambdas. Function and lambda class inside can be loaded
3296-
// from different modules.
3297-
if (auto *FD = dyn_cast<FunctionDecl>(DC))
3298-
if (FD->getOwningModule())
3299-
return FD->getCanonicalDecl();
3300-
33013294
return nullptr;
33023295
}
33033296

clang/test/Modules/odr_hash.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3084,8 +3084,8 @@ struct S5 {
30843084
};
30853085
#else
30863086
S5 s5;
3087-
// expected-error@second.h:* {{'PointersAndReferences::S5::x' from module 'SecondModule' is not present in definition of 'PointersAndReferences::S5' in module 'FirstModule'}}
3088-
// expected-note@first.h:* {{declaration of 'x' does not match}}
3087+
// expected-error@first.h:* {{'PointersAndReferences::S5::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S5' in module 'SecondModule'}}
3088+
// expected-note@second.h:* {{declaration of 'x' does not match}}
30893089
#endif
30903090

30913091
#if defined(FIRST)

0 commit comments

Comments
 (0)