@@ -1825,29 +1825,34 @@ TryImplicitConversion(Sema &S, Expr *From, QualType ToType,
18251825 return ICS;
18261826 }
18271827
1828- const Type *FromTy = FromType->getUnqualifiedDesugaredType();
1829- if (S.getLangOpts().HLSL && FromTy->isHLSLAttributedResourceType()) {
1830- bool CanConvert = false;
1831- const Type *ToTy = ToType->getUnqualifiedDesugaredType();
1832- if (ToTy->isHLSLAttributedResourceType()) {
1833- auto *ToResType = cast<HLSLAttributedResourceType>(ToTy);
1834- auto *FromResType = cast<HLSLAttributedResourceType>(FromTy);
1835- if (S.Context.hasSameUnqualifiedType(ToResType->getWrappedType(),
1836- FromResType->getWrappedType()) &&
1837- S.Context.hasSameUnqualifiedType(ToResType->getContainedType(),
1838- FromResType->getContainedType()) &&
1839- ToResType->getAttrs() == FromResType->getAttrs())
1828+ if (S.getLangOpts().HLSL) {
1829+ // Handle conversion of the HLSL resource types.
1830+ const Type *FromTy = FromType->getUnqualifiedDesugaredType();
1831+ if (FromTy->isHLSLAttributedResourceType()) {
1832+ // Attributed resource types can convert to other attributed
1833+ // resource types with the same attributes and contained types,
1834+ // or to __hlsl_resource_t without any attributes.
1835+ bool CanConvert = false;
1836+ const Type *ToTy = ToType->getUnqualifiedDesugaredType();
1837+ if (ToTy->isHLSLAttributedResourceType()) {
1838+ auto *ToResType = cast<HLSLAttributedResourceType>(ToTy);
1839+ auto *FromResType = cast<HLSLAttributedResourceType>(FromTy);
1840+ if (S.Context.hasSameUnqualifiedType(ToResType->getWrappedType(),
1841+ FromResType->getWrappedType()) &&
1842+ S.Context.hasSameUnqualifiedType(ToResType->getContainedType(),
1843+ FromResType->getContainedType()) &&
1844+ ToResType->getAttrs() == FromResType->getAttrs())
1845+ CanConvert = true;
1846+ } else if (ToTy->isHLSLResourceType()) {
18401847 CanConvert = true;
1841- }
1842- else if (ToTy->isHLSLResourceType()) {
1843- CanConvert = true;
1844- }
1845- if (CanConvert) {
1846- ICS.setStandard();
1847- ICS.Standard.setAsIdentityConversion();
1848- ICS.Standard.setFromType(FromType);
1849- ICS.Standard.setAllToTypes(ToType);
1850- return ICS;
1848+ }
1849+ if (CanConvert) {
1850+ ICS.setStandard();
1851+ ICS.Standard.setAsIdentityConversion();
1852+ ICS.Standard.setFromType(FromType);
1853+ ICS.Standard.setAllToTypes(ToType);
1854+ return ICS;
1855+ }
18511856 }
18521857 }
18531858
0 commit comments