20
20
#include " clang/AST/TemplateBase.h"
21
21
#include " clang/AST/TemplateName.h"
22
22
#include " clang/AST/Type.h"
23
- #include " clang/AST/ODRHash.h"
24
- #include " clang/AST/ExprCXX.h"
25
23
#include " clang/AST/TypeLoc.h"
26
24
#include " clang/Basic/Builtins.h"
27
25
#include " clang/Basic/LLVM.h"
@@ -333,43 +331,16 @@ RedeclarableTemplateDecl::CommonBase *RedeclarableTemplateDecl::getCommonPtr() c
333
331
return Common;
334
332
}
335
333
336
- void RedeclarableTemplateDecl::loadLazySpecializationsImpl (
337
- bool OnlyPartial/* =false*/ ) const {
334
+ void RedeclarableTemplateDecl::loadLazySpecializationsImpl () const {
338
335
// Grab the most recent declaration to ensure we've loaded any lazy
339
336
// redeclarations of this template.
340
337
CommonBase *CommonBasePtr = getMostRecentDecl ()->getCommonPtr ();
341
- if (auto *Specs = CommonBasePtr->LazySpecializations ) {
342
- if (!OnlyPartial)
343
- CommonBasePtr->LazySpecializations = nullptr ;
344
- for (uint32_t I = 0 , N = Specs[0 ].DeclID ; I != N; ++I) {
345
- // Skip over already loaded specializations.
346
- if (!Specs[I+1 ].ODRHash )
347
- continue ;
348
- if (!OnlyPartial || Specs[I+1 ].IsPartial )
349
- (void )loadLazySpecializationImpl (Specs[I+1 ]);
350
- }
351
- }
352
- }
353
-
354
- Decl *RedeclarableTemplateDecl::loadLazySpecializationImpl (
355
- LazySpecializationInfo &LazySpecInfo) const {
356
- uint32_t ID = LazySpecInfo.DeclID ;
357
- assert (ID && " Loading already loaded specialization!" );
358
- // Note that we loaded the specialization.
359
- LazySpecInfo.DeclID = LazySpecInfo.ODRHash = LazySpecInfo.IsPartial = 0 ;
360
- return getASTContext ().getExternalSource ()->GetExternalDecl (ID);
361
- }
362
-
363
- void
364
- RedeclarableTemplateDecl::loadLazySpecializationsImpl (ArrayRef<TemplateArgument>
365
- Args,
366
- TemplateParameterList *TPL) const {
367
- CommonBase *CommonBasePtr = getMostRecentDecl ()->getCommonPtr ();
368
- if (auto *Specs = CommonBasePtr->LazySpecializations ) {
369
- unsigned Hash = TemplateArgumentList::ComputeODRHash (Args);
370
- for (uint32_t I = 0 , N = Specs[0 ].DeclID ; I != N; ++I)
371
- if (Specs[I+1 ].ODRHash && Specs[I+1 ].ODRHash == Hash)
372
- (void )loadLazySpecializationImpl (Specs[I+1 ]);
338
+ if (CommonBasePtr->LazySpecializations ) {
339
+ ASTContext &Context = getASTContext ();
340
+ uint32_t *Specs = CommonBasePtr->LazySpecializations ;
341
+ CommonBasePtr->LazySpecializations = nullptr ;
342
+ for (uint32_t I = 0 , N = *Specs++; I != N; ++I)
343
+ (void )Context.getExternalSource ()->GetExternalDecl (Specs[I]);
373
344
}
374
345
}
375
346
@@ -380,8 +351,6 @@ RedeclarableTemplateDecl::findSpecializationImpl(
380
351
ProfileArguments&&... ProfileArgs) {
381
352
using SETraits = SpecEntryTraits<EntryType>;
382
353
383
- loadLazySpecializationsImpl (std::forward<ProfileArguments>(ProfileArgs)...);
384
-
385
354
llvm::FoldingSetNodeID ID;
386
355
EntryType::Profile (ID, std::forward<ProfileArguments>(ProfileArgs)...,
387
356
getASTContext ());
@@ -397,14 +366,10 @@ void RedeclarableTemplateDecl::addSpecializationImpl(
397
366
398
367
if (InsertPos) {
399
368
#ifndef NDEBUG
400
- auto Args = SETraits::getTemplateArgs (Entry);
401
- // Due to hash collisions, it can happen that we load another template
402
- // specialization with the same hash. This is fine, as long as the next
403
- // call to findSpecializationImpl does not find a matching Decl for the
404
- // template arguments.
405
- loadLazySpecializationsImpl (Args);
406
369
void *CorrectInsertPos;
407
- assert (!findSpecializationImpl (Specializations, CorrectInsertPos, Args) &&
370
+ assert (!findSpecializationImpl (Specializations,
371
+ CorrectInsertPos,
372
+ SETraits::getTemplateArgs (Entry)) &&
408
373
InsertPos == CorrectInsertPos &&
409
374
" given incorrect InsertPos for specialization" );
410
375
#endif
@@ -478,14 +443,12 @@ FunctionTemplateDecl::getSpecializations() const {
478
443
FunctionDecl *
479
444
FunctionTemplateDecl::findSpecialization (ArrayRef<TemplateArgument> Args,
480
445
void *&InsertPos) {
481
- auto *Common = getCommonPtr ();
482
- return findSpecializationImpl (Common->Specializations , InsertPos, Args);
446
+ return findSpecializationImpl (getSpecializations (), InsertPos, Args);
483
447
}
484
448
485
449
void FunctionTemplateDecl::addSpecialization (
486
450
FunctionTemplateSpecializationInfo *Info, void *InsertPos) {
487
- auto *Common = getCommonPtr ();
488
- addSpecializationImpl<FunctionTemplateDecl>(Common->Specializations , Info,
451
+ addSpecializationImpl<FunctionTemplateDecl>(getSpecializations (), Info,
489
452
InsertPos);
490
453
}
491
454
@@ -545,9 +508,8 @@ ClassTemplateDecl *ClassTemplateDecl::CreateDeserialized(ASTContext &C,
545
508
DeclarationName (), nullptr , nullptr );
546
509
}
547
510
548
- void ClassTemplateDecl::LoadLazySpecializations (
549
- bool OnlyPartial/* =false*/ ) const {
550
- loadLazySpecializationsImpl (OnlyPartial);
511
+ void ClassTemplateDecl::LoadLazySpecializations () const {
512
+ loadLazySpecializationsImpl ();
551
513
}
552
514
553
515
llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
@@ -558,7 +520,7 @@ ClassTemplateDecl::getSpecializations() const {
558
520
559
521
llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
560
522
ClassTemplateDecl::getPartialSpecializations () const {
561
- LoadLazySpecializations (/* PartialOnly = */ true );
523
+ LoadLazySpecializations ();
562
524
return getCommonPtr ()->PartialSpecializations ;
563
525
}
564
526
@@ -572,15 +534,12 @@ ClassTemplateDecl::newCommon(ASTContext &C) const {
572
534
ClassTemplateSpecializationDecl *
573
535
ClassTemplateDecl::findSpecialization (ArrayRef<TemplateArgument> Args,
574
536
void *&InsertPos) {
575
- auto *Common = getCommonPtr ();
576
- return findSpecializationImpl (Common->Specializations , InsertPos, Args);
537
+ return findSpecializationImpl (getSpecializations (), InsertPos, Args);
577
538
}
578
539
579
540
void ClassTemplateDecl::AddSpecialization (ClassTemplateSpecializationDecl *D,
580
541
void *InsertPos) {
581
- auto *Common = getCommonPtr ();
582
- addSpecializationImpl<ClassTemplateDecl>(Common->Specializations , D,
583
- InsertPos);
542
+ addSpecializationImpl<ClassTemplateDecl>(getSpecializations (), D, InsertPos);
584
543
}
585
544
586
545
ClassTemplatePartialSpecializationDecl *
@@ -925,14 +884,6 @@ TemplateArgumentList::CreateCopy(ASTContext &Context,
925
884
return new (Mem) TemplateArgumentList (Args);
926
885
}
927
886
928
- unsigned TemplateArgumentList::ComputeODRHash (ArrayRef<TemplateArgument> Args) {
929
- ODRHash Hasher;
930
- for (TemplateArgument TA : Args)
931
- Hasher.AddTemplateArgument (TA);
932
-
933
- return Hasher.CalculateHash ();
934
- }
935
-
936
887
FunctionTemplateSpecializationInfo *FunctionTemplateSpecializationInfo::Create (
937
888
ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template,
938
889
TemplateSpecializationKind TSK, const TemplateArgumentList *TemplateArgs,
@@ -1275,9 +1226,8 @@ VarTemplateDecl *VarTemplateDecl::CreateDeserialized(ASTContext &C,
1275
1226
DeclarationName (), nullptr , nullptr );
1276
1227
}
1277
1228
1278
- void VarTemplateDecl::LoadLazySpecializations (
1279
- bool OnlyPartial/* =false*/ ) const {
1280
- loadLazySpecializationsImpl (OnlyPartial);
1229
+ void VarTemplateDecl::LoadLazySpecializations () const {
1230
+ loadLazySpecializationsImpl ();
1281
1231
}
1282
1232
1283
1233
llvm::FoldingSetVector<VarTemplateSpecializationDecl> &
@@ -1288,7 +1238,7 @@ VarTemplateDecl::getSpecializations() const {
1288
1238
1289
1239
llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &
1290
1240
VarTemplateDecl::getPartialSpecializations () const {
1291
- LoadLazySpecializations (/* PartialOnly = */ true );
1241
+ LoadLazySpecializations ();
1292
1242
return getCommonPtr ()->PartialSpecializations ;
1293
1243
}
1294
1244
@@ -1302,14 +1252,12 @@ VarTemplateDecl::newCommon(ASTContext &C) const {
1302
1252
VarTemplateSpecializationDecl *
1303
1253
VarTemplateDecl::findSpecialization (ArrayRef<TemplateArgument> Args,
1304
1254
void *&InsertPos) {
1305
- auto *Common = getCommonPtr ();
1306
- return findSpecializationImpl (Common->Specializations , InsertPos, Args);
1255
+ return findSpecializationImpl (getSpecializations (), InsertPos, Args);
1307
1256
}
1308
1257
1309
1258
void VarTemplateDecl::AddSpecialization (VarTemplateSpecializationDecl *D,
1310
1259
void *InsertPos) {
1311
- auto *Common = getCommonPtr ();
1312
- addSpecializationImpl<VarTemplateDecl>(Common->Specializations , D, InsertPos);
1260
+ addSpecializationImpl<VarTemplateDecl>(getSpecializations (), D, InsertPos);
1313
1261
}
1314
1262
1315
1263
VarTemplatePartialSpecializationDecl *
0 commit comments