| 248 | } |
| 249 | |
| 250 | void BitcodeReaderMetadataList::tryToResolveCycles() { |
| 251 | if (!ForwardReference.empty()) |
| 252 | // Still forward references... can't resolve cycles. |
| 253 | return; |
| 254 | |
| 255 | // Give up on finding a full definition for any forward decls that remain. |
| 256 | for (const auto &Ref : OldTypeRefs.FwdDecls) |
| 257 | OldTypeRefs.Final.insert(Ref); |
| 258 | OldTypeRefs.FwdDecls.clear(); |
| 259 | |
| 260 | // Upgrade from old type ref arrays. In strange cases, this could add to |
| 261 | // OldTypeRefs.Unknown. |
| 262 | for (const auto &Array : OldTypeRefs.Arrays) |
| 263 | Array.second->replaceAllUsesWith(resolveTypeRefArray(Array.first.get())); |
| 264 | OldTypeRefs.Arrays.clear(); |
| 265 | |
| 266 | // Replace old string-based type refs with the resolved node, if possible. |
| 267 | // If we haven't seen the node, leave it to the verifier to complain about |
| 268 | // the invalid string reference. |
| 269 | for (const auto &Ref : OldTypeRefs.Unknown) { |
| 270 | if (DICompositeType *CT = OldTypeRefs.Final.lookup(Ref.first)) |
| 271 | Ref.second->replaceAllUsesWith(CT); |
| 272 | else |
| 273 | Ref.second->replaceAllUsesWith(Ref.first); |
| 274 | } |
| 275 | OldTypeRefs.Unknown.clear(); |
| 276 | |
| 277 | if (UnresolvedNodes.empty()) |
| 278 | // Nothing to do. |
| 279 | return; |
| 280 | |
| 281 | // Resolve any cycles. |
| 282 | for (unsigned I : UnresolvedNodes) { |
| 283 | auto &MD = MetadataPtrs[I]; |
| 284 | auto *N = dyn_cast_or_null<MDNode>(MD); |
| 285 | if (!N) |
| 286 | continue; |
| 287 | |
| 288 | assert(!N->isTemporary() && "Unexpected forward reference"); |
| 289 | N->resolveCycles(); |
| 290 | } |
| 291 | |
| 292 | // Make sure we return early again until there's another unresolved ref. |
| 293 | UnresolvedNodes.clear(); |
| 294 | } |
| 295 | |
| 296 | void BitcodeReaderMetadataList::addTypeRef(MDString &UUID, |
| 297 | DICompositeType &CT) { |
no test coverage detected