getUBSanFunctionTypeHash does not handle the attributed function case correctly. For a function with an attribute, the QualType passed to the function is a FunctionNoProtoType wrapped in an AttributedType. As a result, the code goes down the !isa<FunctionNoProtoType> branch which is incorrect behavior. This results in an assertion failure inside the call to getFunctionTypeWithExceptionSpec.
The added test is a sanity check that the compiler no longer crashes during compilation.
rdar://113144087
Checking isa<T> still doesn't handle cases where Ty is wrapped in other sugar types (not just AttributedType).
Instead of adding if (isa<AttributedType>(Ty)) above, I would use
Ty->isFunctionNoProtoType() here.
isFunctionNoProtoType is a helper function that uses getAs<FunctionNoProtoType>(). getAs<T> removes any existing sugar until it reaches T or a non-sugar type.