-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
clang++-18/main miscompilation on windows #94650
Comments
@llvm/issue-subscribers-clang-frontend Author: Egor Pugin (egorpugin)
Windows, llvm v18.1.6 or 19 from main branch.
|
If we write template <auto Field>
auto f() {
printf("%s\n", __PRETTY_FUNCTION__);
} results in auto f() [Field = &B::v]
auto f() [Field = &B::v] but must be auto f() [Field = &A::v]
auto f() [Field = &B::v] full #include <stdio.h>
struct A { int v; };
struct B { int v; };
template <auto Field>
auto f() {
printf("%s\n", __PRETTY_FUNCTION__);
}
int main() {
f<&A::v>();
f<&B::v>();
}
|
It's worth noting that the diagnostic points to the declaration of enclosing function, instead of pointing to offending instantiation. |
@llvm/issue-subscribers-c-17 Author: Egor Pugin (egorpugin)
Windows, llvm v18.1.6 or 19 from main branch.
or
struct A { int v; };
struct B { int v; };
template <auto Field>
void f() {}
int main() {
f<&A::v>();
f<&B::v>();
}
|
Clang seems currently bug-compatible with MSVC before VS2019 16.0/19.20 (Godbolt link). It's unfortunate that MSVC is still buggy on different variant members of the same type and at the same offset to a union (Godbolt link). union MyUnion {
int one;
int two;
};
template <auto>
void f() {}
int main() {
// There should be two specializations instantiated, but MSVC only gives one.
// Both mangle names are collapsed into '??$f@$MPEQMyUnion@@H0A@@@YAXXZ'.
f<&MyUnion::one>();
f<&MyUnion::two>();
} |
Maybe it should do so for |
It can, but I don't think it would be the right default. I think Windows software expect Microsoft mangling. |
For reference I have a PR up which fixes this mangling since MSVC fixed it starting in 1920 (VS2019). MSVC 1914 (VS2017) really doesn't support C++17 well. This is the PR, #97007, that fixes this issue so when that is merged we can close this issue out. I am trying to fix as many mangling issues as I can as I run into them as well on my side :). Clang 19 should have a lot of MSVC specific fixes coming in.
I agree that it isn't the right default. I would expect we try to honour the msvc name mangling 1:1 by default. Other times we have teams that pre-compile some of our internal support libs to save on build iteration time and that is usually done with MSVC as the core code of the software is transitioning towards Clang. I also agree that for users who mostly care about C library interfaces or minimal C++ interfaces like interfacing with the DirectX APIs but the rest of the code is completely compiled from source and only compiled with Clang then we can have more leeway with the mangling to overcome MSVC bugs. Recently I ran into this auto mangling issue, https://godbolt.org/z/r1oGP3jn9. I had code built with MSVC and Clang result in two different definitions of the same function instead of merging into one definition at link time. In this case I haven't dug deep enough to know if the VS2019 is sufficient or if a custom mangling is still technically necessary. I do think that staying true to MSVC by default is ideal with an option for users to use an MSVC-[like] mangling which may fix any MSVC mangling issues for those who don't need full MSVC semantics including its bugs. |
Following ms abi is fine, but can't correct functioning be put behind a flag? Users wanting correct behavior should not suffer from it. |
A new triple, e.g. |
@egorpugin I merged #97007 which adds support for the new mangling used in VS2019 and VS2022. This issue should be fixed in mainline now. Feel free to test out mainline and close this issue out. I still intend to get up a discourse to discuss other issues with MSVC mangling like the one @frederick-vs-ja mentioned with unions and how to go about that, likely with a new triple. |
Confirmed, works on trunk. |
Windows, llvm v18.1.6 or 19 from main branch.
or
The text was updated successfully, but these errors were encountered: