Index: lib/CodeGen/CodeGenTBAA.cpp =================================================================== --- lib/CodeGen/CodeGenTBAA.cpp +++ lib/CodeGen/CodeGenTBAA.cpp @@ -127,7 +127,8 @@ return getBaseTypeInfo(QTy); const Type *Ty = Context.getCanonicalType(QTy).getTypePtr(); - if (llvm::MDNode *N = MetadataCache[Ty]) + llvm::MDNode *&N = MetadataCache[Ty]; + if (N) return N; // Handle builtin types. @@ -160,8 +161,7 @@ // treating wchar_t, char16_t, and char32_t as distinct from their // "underlying types". default: - return MetadataCache[Ty] = - createTBAAScalarType(BTy->getName(Features), getChar()); + return N = createTBAAScalarType(BTy->getName(Features), getChar()); } } @@ -169,14 +169,13 @@ // an object through a glvalue of other than one of the following types the // behavior is undefined: [...] a char, unsigned char, or std::byte type." if (Ty->isStdByteType()) - return MetadataCache[Ty] = getChar(); + return N = getChar(); // Handle pointers and references. // TODO: Implement C++'s type "similarity" and consider dis-"similar" // pointers distinct. if (Ty->isPointerType() || Ty->isReferenceType()) - return MetadataCache[Ty] = createTBAAScalarType("any pointer", - getChar()); + return N = createTBAAScalarType("any pointer", getChar()); // Enum types are distinct types. In C++ they have "underlying types", // however they aren't related for TBAA. @@ -186,16 +185,16 @@ // TODO: Is there a way to get a program-wide unique name for a // decl with local linkage or no linkage? if (!Features.CPlusPlus || !ETy->getDecl()->isExternallyVisible()) - return MetadataCache[Ty] = getChar(); + return N = getChar(); SmallString<256> OutName; llvm::raw_svector_ostream Out(OutName); MContext.mangleTypeName(QualType(ETy, 0), Out); - return MetadataCache[Ty] = createTBAAScalarType(OutName, getChar()); + return N = createTBAAScalarType(OutName, getChar()); } // For now, handle any other kind of type conservatively. - return MetadataCache[Ty] = getChar(); + return N = getChar(); } TBAAAccessInfo CodeGenTBAA::getVTablePtrAccessInfo() { @@ -244,11 +243,10 @@ return true; } -llvm::MDNode * -CodeGenTBAA::getTBAAStructInfo(QualType QTy) { +llvm::MDNode *CodeGenTBAA::getTBAAStructInfo(QualType QTy) { const Type *Ty = Context.getCanonicalType(QTy).getTypePtr(); - - if (llvm::MDNode *N = StructMetadataCache[Ty]) + llvm::MDNode *&N = StructMetadataCache[Ty]; + if (N) return N; SmallVector Fields; @@ -256,7 +254,7 @@ return MDHelper.createTBAAStructNode(Fields); // For now, handle any other kind of type conservatively. - return StructMetadataCache[Ty] = nullptr; + return N = nullptr; } llvm::MDNode *CodeGenTBAA::getBaseTypeInfo(QualType QTy) { @@ -264,7 +262,8 @@ return nullptr; const Type *Ty = Context.getCanonicalType(QTy).getTypePtr(); - if (llvm::MDNode *N = BaseTypeMetadataCache[Ty]) + llvm::MDNode *&N = BaseTypeMetadataCache[Ty]; + if (N) return N; if (const RecordType *TTy = QTy->getAs()) { @@ -279,7 +278,7 @@ llvm::MDNode *FieldNode = isValidBaseType(FieldQTy) ? getBaseTypeInfo(FieldQTy) : getTypeInfo(FieldQTy); if (!FieldNode) - return BaseTypeMetadataCache[Ty] = nullptr; + return N = nullptr; Fields.push_back(std::make_pair( FieldNode, Layout.getFieldOffset(idx) / Context.getCharWidth())); } @@ -293,11 +292,10 @@ OutName = RD->getName(); } // Create the struct type node with a vector of pairs (offset, type). - return BaseTypeMetadataCache[Ty] = - MDHelper.createTBAAStructTypeNode(OutName, Fields); + return N = MDHelper.createTBAAStructTypeNode(OutName, Fields); } - return BaseTypeMetadataCache[Ty] = nullptr; + return N = nullptr; } llvm::MDNode *CodeGenTBAA::getAccessTagInfo(TBAAAccessInfo Info) {