-
Notifications
You must be signed in to change notification settings - Fork 12.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
Missing [[no_unique_address]] support on Windows #49358
Comments
*** Bug llvm/llvm-bugzilla-archive#51051 has been marked as a duplicate of this bug. *** |
This is not a bug. Microsoft has not defined the ABI for this attribute on their platform, so Clang needs to wait for Microsoft to define that before we can support [[no_unique_address]] there (otherwise we run into potential ABI incompatibilities). However, I'm leaving this request open because presumably Microsoft will define the ABI on their platform for this feature, and then Clang can follow suit. |
Microsoft already added support for this as of VS 2019 16.9. |
Alas, but I don't believe the documentation based on how their compiler behaves in practice (which is not something Clang will be emulating because it looks to be a buggy implementation). See https://godbolt.org/z/j1PzbK68P, but basically, __has_cpp_attribute returns false for both no_unique_address and msvc::no_unique_address, yet the latter actually does the correct thing that the former is standardized to do while the former is silently ignored. |
It is not intended that MSVC predefines As an STL developer, I would greatly appreciate if clang-cl were to implement |
mentioned in issue #50395 |
Thanks!
Personally, I think it's unfortunate that Microsoft is not implementing the standard attribute but are instead creating problems by introducing a vendor-specific attribute that behaves the same as the standard attribute.
As someone who writes portable code and hates jumping through ridiculous hoops to do so, I would greatly appreciate if cl were to implement That said, I have no problem with Clang implementing [[msvc::no_unique_address]] so long as we match Microsoft's ABI for it. Is there any documentation available on the ABI for this? |
* [[no_unique_address]] with cl is silently ignored. * Don't use either with with clang-cl, they are unrecognised. Useful links: * https://reviews.llvm.org/D110485 * llvm/llvm-project#49358
I'm not sure what the best way forward is for us here. Since MSVC treats Is Also, like it or not, if there is a bunch of code using |
Agreed that it's not great, but rushing is also not great given the ABI concerns.
I'm strongly opposed because of ABI. Using fields with
I'm absolutely happy to see an implementation for it once we know we can match the Microsoft ABI for it. Without that, I have the same ABI concerns as above. |
It sounds like supporting For |
+1, hopefully someone from Microsoft can help with the ABI questions so we don't have to reverse engineer it.
The warning helps but it doesn't actually address the ABI issues (users are still going to have a hard ABI break and this decreases our compatibility with MSVC). I think when the user passes |
Note that "reverse engineer" is often understood as reverse engineering cl.exe and looking at its assembly. This is not something we've ever done. We've very often compiled test programs with cl.exe and looked at its output. That's how most of clang-cl's behavior was implemented. This is not reverse engineering. (This distinction is important for EULA reasons etc.) With that out of the way: Sure, it'd be nice to have docs, but we wrote most of clang-cl without such docs. Re non-prefixed We have a history of inventing ABI stuff until actual ABI arrives (eg https://reviews.llvm.org/rG2ac58801873ab99dd5de48ad7557b76f1803100b – but see We also have a history for being standards-compliant by default where it makes sense (different defaults for various of the I guess we can also add a Given that |
Good points, I definitely did not mean the former interpretation. :-)
It doesn't have to be docs; it can be extensive tests, for example. However, there are folks from Microsoft on this thread asking us to support their attribute, so I'm hoping they can volunteer to help verify the feature (either with documentation, test cases, etc).
My point is that the ABI has already arrived and we need to match it otherwise we're making extra work for ourselves and our users.
I don't think we can say what most people do or don't do.
I'm not super keen on adding a |
Actually, no - earlier, when using |
We gave a long talk about this a while ago: https://docs.google.com/presentation/d/1oxNHaVjA9Gn_rTzX6HIpJHP7nXRua_0URXxxJ3oYRq0/edit#slide=id.p The use case is "I want to be able to build software against the Windows SDK". Under this interpretation, as long as you can link against system libs, all's well. But @mstorsjo's point makes sense – by default we have to match what cl.exe does. But having some opt-in thing (/Zc: flag to toggle it globally, and maybe a |
I fired off an email to some folks at Microsoft asking for some guidance, FWIW. I think it would be reasonable to expose an alternative attribute spelling in the meantime, as annoying as that is. Is I think historically we have aimed for more ABI compatibility than just the ability to link against the SDK. Back when we supported MSVC fallback, you could get arbitrary mixes of translation units between MSVC and clang-cl. |
Isn't |
Is there evidence that
That's my belief. I think we should just support that form rather than introduce a third form of the attribute. |
Ah, I had misread the bug and had misunderstood what that does. I think then it's probably best to just make |
Yeah, I agree. I would still like input from MSVC folks on why they made their own spelling here and make the standard feature a no-op. |
I got it explained to me in microsoft/STL#1364 (comment), and https://devblogs.microsoft.com/cppblog/msvc-cpp20-and-the-std-cpp20-switch/#msvc-extensions-and-abi also hints at the same: Due to the fact that they silently accepted the attribute without actually doing anything about it, for a number of releases, they considered that "accepting and not doing anything about it" had been settled in ABI as users could have ended up using it blindly, so that changing it could break existing deployed code. |
As concerned user, this sounds like a really good solution! Can we also get a warning about the no-op behavior. So that users that want to use this, know it ain't working and how they should adapt their code to get the intended behavior? |
I want to update the question about this, as I understand at the moment there is still no support for |
It depends on what you mean by "near". It's certainly on the todo list, but I don't think anyone is prepared to commit to a timeline. |
Support for Support for [[msvc::no_unique_address]]` is waiting for someone to do the implementation work to ensure we're matching Microsoft's ABI for their vendor attribute; I don't know anyone is prepared to commit to a timeline for that. |
For myself, I defined the "near future" in the probable next major (?) release (15.x). But yes, I understand that it still depends on the guys from Microsoft. Just as I understand, Microsoft has already implemented its However, Aaron gave the answer I was expecting, thank you. |
I think those next steps sound correct to me, and thank you to @amykhuang for looking into the effort! |
forgot to update here that I have a patch at https://reviews.llvm.org/D157762 (the implementation is still very much a work in progress) There are a couple of cases (that I've found so far) where I can't figure out MSVC's intended behavior, such as https://godbolt.org/z/6cP554ddb. @CaseyCarter is this something you could help with? |
@llvm/issue-subscribers-clang-codegen |
@llvm/issue-subscribers-clang-frontend |
This is DevCom-10416202, with an added "Oops, we sometimes layout distinct objects at the same address". I sincerely hope this is not intended behavior since it's very much not conformant. I've pinged the internal bug tracker and added a slightly reduced version of your repro (https://godbolt.org/z/3GGj9xsfe). |
@CaseyCarter if this layout is a bug, can you provide some guidance on how and where Clang should aim for MSVC compatibility? In other words, should we expect a bug fix that changes the layout of these structs in future compiler versions, and if so, should Clang just not worry about being bug for bug compatible here? There are some other ways we could approach this:
The main top priority use case for some form of no_unique_address support in libc++ is to eliminate compressed_pair. I believe folks using libc++ generally do not aim for ABI compatibility with the MSVC compiler, so for libc++ purposes, we don't need an attribute that is perfectly ABI compatible with the MSVC compiler. If users want Clang/MSVC ABI compatibility, those users typically use the MSVC STL, which is what any MSVC-precompiled code would use. After re-reading what I've written, I'm unfortunately leading myself to the conclusion that we should implement |
I poked the pertinent compiler dev about DevCom-10416202 - which they fixed just in time for VS2022 17.8 preview 3 - but I didn't make it clear that I had an expanded repro from you folks with more non-conforming class layouts involving
I do not recommend bug compatibility here. This isn't a part of the ABI that's been baked-in for decades, I don't even know of any current users of |
sounds like because the attribute is relatively unused and we're only planning to use it in libc++, it shouldn't be too much of an issue if the ABI doesn't match up at the moment? also, have a few more questions on layout here https://godbolt.org/z/nMexrWxG4, sorry it's a bit long |
Thanks for the input! I think we can proceed with landing an implementation of |
(Unrelated nit: The I'll send this on the compiler team and see if it elucidates any comments. |
Based on the discussion in this thread, I concur. When landing the changes, I think we should explicitly document the expectations so users are aware we're not making them any promises regarding ABI compatibility or stability. Thank you to everyone for pulling this together! |
This attribute should match the behavior of MSVC's [[msvc::no_unique_address]] attribute. Bug: llvm#49358 Differential Revision: https://reviews.llvm.org/D157762
This implements the [[msvc::no_unique_address]] attribute. There is not ABI compatibility in this patch because the attribute is relatively new and there's still some uncertainty in the MSVC version. Bug: #49358 Also see https://reviews.llvm.org/D157762.
Does 4a55d42 mean this is done? |
I think so. |
Extended Description
https://clang.llvm.org/cxx_status.html#cxx20 lists the [[no_unique_address]] attribute as supported since Clang 9. However, the attribute does not seem to currently be supported on Windows platforms.
Compiling the following source code on Windows with Clang 12.0.0 with -std=c++20:
gives the following warning:
The size of objects from Y1 are also the same size as those from Y2, indicating that an unique address is indeed still generated:
prints "16, 16" compared to "8, 16" on Linux: https://godbolt.org/z/nfaf3KeP3
The text was updated successfully, but these errors were encountered: