-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Clang omits call to move constructor with aggregate init from template type #61145
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
Comments
For what it's worth, in case it's helpful or not, I found this not with an |
There is a serious codegen bug with Clang aggregate init when working with concepts. llvm/llvm-project#61145
There is a serious codegen bug with Clang aggregate init when working with concepts. llvm/llvm-project#61145
@llvm/issue-subscribers-clang-frontend |
@llvm/issue-subscribers-c-20 |
Note if we change the move line to: return S{std::move(v)}; Then gcc and clang match behavior: https://godbolt.org/z/4MeGTvv6E This looks like a clang bug but not sure what is going wrong. |
Any chance of this being fixed in Clang 16? Without it the guidance will likely have to be to avoid paren aggregate init, and write tooling to enforce it isn't used. |
I believe the clang-16 window has closed, I am not really sure where to begin here or how far reaching the issue is. Maybe @zygoloid has an idea of where to poke this. |
I've not been keeping up to date with the parenthesized aggregate init work, but it looks broken enough that I think we should disable it in the Clang 16 release. I'm looking at a reduced testcase with just this statement:
For that, we produce this AST in the template:
... which is already wrong: we're missing the Then, after template instantiation happens, we get this AST:
... in which the |
The broken ASTs here will also crash the constant evaluator pretty easily. |
I think that would be https://reviews.llvm.org/D129531 then |
Ugh, that's not good. :-( @tstellar @tru -- is it too late for 16.0.0? @zygoloid -- if it is too late for 16.0.0, would it be reasonable to revert in 16.0.1 instead (assuming we can't get the issues resolved in time for .0.1 or they're too large/risky for the dot release)? |
FYI: that was reverted and relanded in https://reviews.llvm.org/D141546 That's a very big patch to revert right before a release, even if we have time. :( |
So I reverted the patch locally but realized this code does not work w/ parens anymore, so it fixes the problem in a way but not very nicely since folks who now rely on this feature will be broken. I don't have the bandwidth right now to dig into this too much more today. |
The 16.0.0 is planned for tomorrow, so I don't think we are going to be able to get this done in time especially if there isn't already a fix. Can we document this issue in the release notes? |
So I took a naive stab at this per @zygoloid 's comments and I wrapped the
I tried building the crashing example (https://godbolt.org/z/G88zerqnK) and we are indeed creating the
|
There are two different bugs here; the constant evaluator crash is due to the template instantiation bug. You should be able to see whether the bind-to-temporary fix is effective by compiling |
I think we should remove an existing release note: https://github.com/llvm/llvm-project/blob/release/16.x/clang/docs/ReleaseNotes.rst?plain=1#L254 Can you remove that one from the release branch? I'll update https://clang.llvm.org/cxx_status.html accordingly as well from Clang 16 back to No. |
We thought we had implemented these papers appropriately but have since discovered significant issues. See discussion of the issues at: #61145 The work already done on these papers is remaining in tree for the moment while people investigate whether the issues can be fixed forward in main. The status page is being updated so the status is clear to users of the upcoming Clang 16 release.
I will push 68b3396 to the release branch. Done! |
We thought we had implemented these papers appropriately but have since discovered significant issues. See discussion of the issues at: llvm/llvm-project#61145 The work already done on these papers is remaining in tree for the moment while people investigate whether the issues can be fixed forward in main. The status page is being updated so the status is clear to users of the upcoming Clang 16 release.
When there's a potential patch fix, I will be happy to try it against subspace, which is where I found this bug among others. |
Now that I pushed 7df3c71 to |
/cherry-pick 7df3c71 |
/branch llvm/llvm-project-release-prs/issue61145 |
/pull-request llvm/llvm-project-release-prs#407 |
Are P0960R3 and P1975R0 considered unsupported still?
|
@H-G-Hristov There is also #61567, but (I think) that isn't a miscomple and unlike this bug, that bug doesn't cause the compiler to crash. @AaronBallman any thoughts? |
I think these are distinct issues, yes. |
Sorry, I was unclear - my question was whether resolving this issue is sufficient to mark P0960R3 as supported in Clang 16.x, or do we still need to resolve #61567 before doing so? |
Oh, thank you for clarifying! :-) Hmm this is a tough one. #61567 is about false positive warning diagnostics, which is usually a matter of QoI and so not really something that would hold us back from claiming support for P0960R3. However, this bit worries me:
largely because there's a significant number of users who compile with |
It's also about false positive errors, not just warnings. |
Agreed on holding off on claiming full support especially since I have a patch for #61567 (https://reviews.llvm.org/D148274) |
How would one know if this has made it into a Clang 16 release? |
It's queued for merge to the release branch and will most likely end up in 16.0.3 |
Template struct members don't get default initialized when using () parenthesis initialization. #include <iostream>
template <typename T>
struct Object
{
T t;
bool shouldBeTrue = true;
};
int main()
{
std::cout << Object<int>(123).shouldBeTrue << std::endl; // 0, broken
std::cout << Object<int>{123}.shouldBeTrue << std::endl; // 1, as expected
} Example: https://godbolt.org/z/nbdxhcWMT |
* Fix an issue where temporaries initialized via parenthesized aggregate initialization don't get destroyed. * Fix an issue where aggregate initialization omits calls to class members' move constructors after a TreeTransform. This occurs because the CXXConstructExpr wrapping the call to the move constructor gets unboxed during a TreeTransform of the wrapping FunctionalCastExpr (as with a InitListExpr), but unlike InitListExpr, we dont reperform the InitializationSequence for the list's expressions to regenerate the CXXConstructExpr. This patch fixes this bug by treating CXXParenListInitExpr identically to InitListExpr in this regard. Fixes #61145 Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D146465 (cherry picked from commit 7df3c71)
P0960R3 and P1975R0 were marked not implemented because of llvm#61145, This issue has been fixed and backported to LLVM 16, the status page should reflect that. Differential Revision: https://reviews.llvm.org/D150122
P0960R3 and P1975R0 were marked not implemented because of #61145, This issue has been fixed and backported to LLVM 16, the status page should reflect that. Reviewed By: #clang-language-wg, ayzhao, erichkeane Differential Revision: https://reviews.llvm.org/D150122
cc: @alanzhao1
This code double frees with Clang, when it should not: https://godbolt.org/z/5sfT8sW4j
Output in GCC:
Output in Clang:
Can't show the output of MSVC from godbolt but the code works there.
The text was updated successfully, but these errors were encountered: