-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
STL: Compiler intrinsics for BUILTIN-PTR-XXX #489
Comments
This comment has been minimized.
This comment has been minimized.
I am confused about:
|
Yes, that's one set of problematic cases; I think it's possible that both arguments are non-pointers with no common reference which convert to pointers when compared. Another problem set is " (Disclosure: this is largely my design/wording so any errors are mine.) It's a defect that the design permits these cases. WG21 should have specified that the same syntax is always required, and that the "converts to a builtin pointer" bit punches a hole through the semantics and not the syntax of
My current belief is that we only need the intrinsics to punch through the constraints and that
As I state above, I don't think we need to do something special. If we did, I think we could e.g.: if constexpr (__builtin_ptr_eq(T, U)) {
const auto tptr = static_cast<const volatile void*>(t);
const auto uptr = static_cast<const volatile void*>(u);
if (is_constant_evaluated()) {
return tptr == uptr;
} else {
return reinterpret_cast<uintptr_t>(t) == reinterpret_cast<uintptr_t>(u);
}
} else {
return t == u;
} Which I believe works portably for arguments that convert to object pointers, but not with arguments that convert to function pointers. Our implementation allows function pointers to implicitly convert to
I think not for the same reasons that we don't need to do anything special with the Range flavors, but again if optimizers become more aggressive we should change their bodies similarly to the above. |
Can we get this defect fixed instead? |
Yep - that's the idea. |
You may find a certain library issue being prioritized today to be of interest, then :) |
Tracked by LWG-3530 " |
LWG-3530 has been resolved by the Library Working Group, and I've filed a follow-up issue to clean up the comments we left in the code. |
The concept-constrained comparisons (
std::ranges::equal_to
,std::ranges::not_equal_to
,std::ranges::less
,std::ranges::greater
,std::ranges::less_equal
,std::ranges::greater_equal
,std::compare_three_way
) admit pairs of arguments that compare as pointers despite that they do not otherwise meet the constraints. Such arguments are recognized via the exposition-only magic macrosBUILTIN-PTR-CMP
([range.cmp]/1) andBUILTIN-PTR-THREE-WAY
([comparisons.three.way]/1). These magic macros can be implemented as three compiler intrinsics:
__builtin_ptr_equal(T, U)
which evaluates totrue
ifft == u
for expressionst
andu
such thatdecltype((t))
isT
anddecltype((u))
isU
resolves to a builtin==
operator that compares pointers.__builtin_ptr_less(T, U)
which evaluates totrue
ifft < u
for expressionst
andu
such thatdecltype((t))
isT
anddecltype((u))
isU
resolves to a builtin<
operator that compares pointers.__builtin_ptr_spaceship(T, U)
which evaluates totrue
ifft <=> u
for expressionst
andu
such thatdecltype((t))
isT
anddecltype((u))
isU
resolves to a builtin<=>
operator that compares pointers.If we cannot find a way to implement the equivalent of these intrinsics in C++ - there are library implementations, but to my knowledge none that properly handle types that convert to function pointers - we need to get these intrinsics implemented in our compiler front-ends, ideally with the same set of names. (I'm not married to the names above, but they seem as good as any.)
The text was updated successfully, but these errors were encountered: