@@ -438,8 +438,14 @@ ModuleImport::processAliasScopeMetadata(const llvm::MDNode *node) {
438438 if (aliasDomain->getNumOperands () >= 2 )
439439 if (auto *operand = dyn_cast<llvm::MDString>(aliasDomain->getOperand (1 )))
440440 description = builder.getStringAttr (operand->getString ());
441- return builder.getAttr <AliasScopeDomainAttr>(
442- DistinctAttr::create (builder.getUnitAttr ()), description);
441+ if (verifySelfRef (aliasDomain))
442+ return builder.getAttr <AliasScopeDomainAttr>(
443+ DistinctAttr::create (builder.getUnitAttr ()), description);
444+ else {
445+ auto Name = cast<llvm::MDString>(aliasDomain->getOperand (0 ));
446+ return builder.getAttr <AliasScopeDomainAttr>(
447+ builder.getStringAttr (Name->getString ()), description);
448+ }
443449 };
444450
445451 // Collect the alias scopes and domains to translate them.
@@ -452,12 +458,28 @@ ModuleImport::processAliasScopeMetadata(const llvm::MDNode *node) {
452458 // verifying its domain. Perform the verification before looking it up in
453459 // the alias scope mapping since it could have been inserted as a domain
454460 // node before.
455- if (!verifySelfRef (scope) || ! domain || ! verifyDescription (scope, 2 ) )
456- return emitError (loc) << " unsupported alias scope node: "
461+ if (!domain)
462+ return emitError (loc) << " unsupported alias scope node (no domain) : "
457463 << diagMD (scope, llvmModule.get ());
458- if (!verifySelfRef (domain) || !verifyDescription (domain, 1 ))
459- return emitError (loc) << " unsupported alias domain node: "
460- << diagMD (domain, llvmModule.get ());
464+ if (verifySelfRef (scope) && !verifyDescription (scope, 2 ))
465+ return emitError (loc)
466+ << " unsupported alias scope node (bad description): "
467+ << diagMD (scope, llvmModule.get ());
468+ if (!verifySelfRef (scope) && (scope->getNumOperands () == 0 ||
469+ !isa<llvm::MDString>(scope->getOperand (0 ))))
470+ return emitError (loc)
471+ << " unsupported alias scope node (not self-ref and no string): "
472+ << diagMD (scope, llvmModule.get ());
473+ if (!verifyDescription (domain, 1 ))
474+ return emitError (loc)
475+ << " unsupported alias domain node (bad description): "
476+ << diagMD (domain, llvmModule.get ());
477+ if (!verifySelfRef (domain) &&
478+ (domain->getNumOperands () == 0 ||
479+ !isa<llvm::MDString>(domain->getOperand (0 ))))
480+ return emitError (loc)
481+ << " unsupported alias domain node (not self ref and no string): "
482+ << diagMD (scope, llvmModule.get ());
461483
462484 if (aliasScopeMapping.contains (scope))
463485 continue ;
@@ -473,9 +495,18 @@ ModuleImport::processAliasScopeMetadata(const llvm::MDNode *node) {
473495 StringAttr description = nullptr ;
474496 if (!aliasScope.getName ().empty ())
475497 description = builder.getStringAttr (aliasScope.getName ());
476- auto aliasScopeOp = builder.getAttr <AliasScopeAttr>(
477- DistinctAttr::create (builder.getUnitAttr ()),
478- cast<AliasScopeDomainAttr>(it->second ), description);
498+ AliasScopeAttr aliasScopeOp;
499+ if (verifySelfRef (scope))
500+ aliasScopeOp = builder.getAttr <AliasScopeAttr>(
501+ DistinctAttr::create (builder.getUnitAttr ()),
502+ cast<AliasScopeDomainAttr>(it->second ), description);
503+ else {
504+ auto Name = cast<llvm::MDString>(scope->getOperand (0 ));
505+ aliasScopeOp = builder.getAttr <AliasScopeAttr>(
506+ builder.getStringAttr (Name->getString ()),
507+ cast<AliasScopeDomainAttr>(it->second ), description);
508+ }
509+
479510 aliasScopeMapping.try_emplace (aliasScope.getNode (), aliasScopeOp);
480511 }
481512 }
0 commit comments