[PATCH] D43199: [IRMover] Implement name based structure type mapping

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 13 07:46:22 PST 2018


Eugene Leviant via Phabricator via llvm-commits
<llvm-commits at lists.llvm.org> writes:

> +static StringRef getTypeNamePrefix(StringRef Name) {
> +  size_t DotPos = Name.rfind('.');
> +  return (DotPos == 0 || DotPos == StringRef::npos || Name.back() == '.' ||
> +          !isdigit(static_cast<unsigned char>(Name[DotPos + 1])))
> +             ? Name
> +             : Name.substr(0, DotPos);
> +}
> +
>  /// Loop over all of the linked values to compute type mappings.  For example,
>  /// if we link "extern Foo *x" and "Foo *x = NULL", then we have two struct
>  /// types 'Foo' but one got renamed when the module was loaded into the same
> @@ -729,14 +737,12 @@
>      }
>  
>      // Check to see if there is a dot in the name followed by a digit.
> -    size_t DotPos = ST->getName().rfind('.');
> -    if (DotPos == 0 || DotPos == StringRef::npos ||
> -        ST->getName().back() == '.' ||
> -        !isdigit(static_cast<unsigned char>(ST->getName()[DotPos + 1])))
> +    auto STTypePrefix = getTypeNamePrefix(ST->getName());
> +    if (STTypePrefix.size()== ST->getName().size())
>        continue;
>  
>      // Check to see if the destination module has a struct with the prefix name.
> -    StructType *DST = DstM.getTypeByName(ST->getName().substr(0, DotPos));
> +    StructType *DST = DstM.getTypeByName(STTypePrefix);
>      if (!DST)
>        continue;

This part is a nice cleanup, please commit it and rebase.

Cheers,
Rafael


More information about the llvm-commits mailing list