@@ -342,7 +342,7 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type *Ty) {
342
342
// field. Virtual bases are more complex and omitted, but avoid an
343
343
// incomplete view for NewStructPathTBAA.
344
344
if (CodeGenOpts.NewStructPathTBAA && CXXRD->getNumVBases () != 0 )
345
- return BaseTypeMetadataCache[Ty] = nullptr ;
345
+ return nullptr ;
346
346
for (const CXXBaseSpecifier &B : CXXRD->bases ()) {
347
347
if (B.isVirtual ())
348
348
continue ;
@@ -354,7 +354,7 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type *Ty) {
354
354
? getBaseTypeInfo (BaseQTy)
355
355
: getTypeInfo (BaseQTy);
356
356
if (!TypeNode)
357
- return BaseTypeMetadataCache[Ty] = nullptr ;
357
+ return nullptr ;
358
358
uint64_t Offset = Layout.getBaseClassOffset (BaseRD).getQuantity ();
359
359
uint64_t Size =
360
360
Context.getASTRecordLayout (BaseRD).getDataSize ().getQuantity ();
@@ -378,7 +378,7 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type *Ty) {
378
378
llvm::MDNode *TypeNode = isValidBaseType (FieldQTy) ?
379
379
getBaseTypeInfo (FieldQTy) : getTypeInfo (FieldQTy);
380
380
if (!TypeNode)
381
- return BaseTypeMetadataCache[Ty] = nullptr ;
381
+ return nullptr ;
382
382
383
383
uint64_t BitOffset = Layout.getFieldOffset (Field->getFieldIndex ());
384
384
uint64_t Offset = Context.toCharUnitsFromBits (BitOffset).getQuantity ();
@@ -418,14 +418,20 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfo(QualType QTy) {
418
418
return nullptr ;
419
419
420
420
const Type *Ty = Context.getCanonicalType (QTy).getTypePtr ();
421
- if (llvm::MDNode *N = BaseTypeMetadataCache[Ty])
422
- return N;
423
421
424
- // Note that the following helper call is allowed to add new nodes to the
425
- // cache, which invalidates all its previously obtained iterators. So we
426
- // first generate the node for the type and then add that node to the cache.
422
+ // nullptr is a valid value in the cache, so use find rather than []
423
+ auto I = BaseTypeMetadataCache.find (Ty);
424
+ if (I != BaseTypeMetadataCache.end ())
425
+ return I->second ;
426
+
427
+ // First calculate the metadata, before recomputing the insertion point, as
428
+ // the helper can recursively call us.
427
429
llvm::MDNode *TypeNode = getBaseTypeInfoHelper (Ty);
428
- return BaseTypeMetadataCache[Ty] = TypeNode;
430
+ LLVM_ATTRIBUTE_UNUSED auto inserted =
431
+ BaseTypeMetadataCache.insert ({Ty, TypeNode});
432
+ assert (inserted.second && " BaseType metadata was already inserted" );
433
+
434
+ return TypeNode;
429
435
}
430
436
431
437
llvm::MDNode *CodeGenTBAA::getAccessTagInfo (TBAAAccessInfo Info) {
0 commit comments