[libcxx-commits] [PATCH] D97802: [libc++] Increase readability of typeinfo comparison of ARM64
Richard Smith - zygoloid via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Apr 7 13:39:02 PDT 2021
rsmith added inline comments.
================
Comment at: libcxx/include/typeinfo:265-269
static bool __lt(__type_name_t __lhs, __type_name_t __rhs) _NOEXCEPT {
- if (__is_type_name_unique(__lhs, __rhs))
+ if (__is_type_name_unique(__lhs) || __is_type_name_unique(__rhs))
return __lhs < __rhs;
return __builtin_strcmp(__type_name_to_string(__lhs), __type_name_to_string(__rhs)) < 0;
}
----------------
This is not an ordering relation. For example, we could have non-unique C < unique B < non-unique A < non-unique C, where the first and second comparisons are address comparisons, and the third comparison is a string comparison.
I think perhaps something like this would work:
```
bool __lhs_unique = __is_type_name_unique(__lhs);
if (__lhs_unique != __is_type_name_unique(__rhs))
return __lhs_unique;
if (__lhs_unique)
return __lhs < __rhs;
return __builtin_strcmp(__type_name_to_string(__lhs), __type_name_to_string(__rhs)) < 0;
```
(That is: order all unique typeinfos before all non-unique ones, then order unique typeinfos by pointer and non-unique ones by string.)
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D97802/new/
https://reviews.llvm.org/D97802
More information about the libcxx-commits
mailing list