[libcxx-commits] [libcxx] [libc++] Ensure that `std::expected` has no tail padding (PR #69673)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Oct 27 10:45:57 PDT 2023


Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>,
Jan =?utf-8?q?Kokemüller?= <jan.kokemueller at gmail.com>
Message-ID:
In-Reply-To: <llvm/llvm-project/pull/69673/libcxx at github.com>


https://github.com/ldionne requested changes to this pull request.

Thanks a lot for working on this!

In terms of next steps: I think we should still go ahead and ship PR #68733 since it fixes a concrete issue (#68552), even though that's not fixing everything.

Then we have to figure out what to do with this overlapping padding issue. Concretely, we shipped `std::expected` as non-experimental for the first time in LLVM 17, which is still quite recent. However, it is badly broken. So:
1. We could mark it as `-fexperimental-library` again with a cherry-pick and buy ourselves more time to fix this issue properly. The downside is that some people may have started adopted `std::expected` since we released LLVM 17.0, and so it might create a lot of problems to simply remove it.
2. We could give up and remove `[[no_unique_address]]` entirely from `std::expected`, which would solve the problem safely but would also give us a less efficient implementation of `std::expected` forever. This is a plausible option but it would be really unfortunate to bake in a worse ABI than needed forever.
3. We could finish up this patch and cherry-pick it back to LLVM 17. This is nice if we manage to do it, however there is more risk. This patch is really damn tricky, and I think everyone has learned new things in this saga. I think it is obvious that we are still learning to use `[[no_unique_address]]` appropriately and some of its corner cases. It is not impossible that even this implementation suffers from other issues (whether in the library or in the compiler, cause it could also be that Clang doesn't implement the semantics 100% the way it should, I guess).

So (3) is clearly the best but we have to be OK with managing that risk, especially given the tight timeline. LLVM 17.0.4 is released on October 31st, which leaves us just a few days to hit that release. Otherwise there is LLVM 17.0.5 on November 14th, and that's the last one in the LLVM 17 series.

@tru I'm sorry to ping you here again. Essentially, this is "part 2" of fixing the `std::expected` ABI fiasco I pinged you about in #68733. We have the 3 options above to fix this, please let us know if you have opinions.

Personally I think we should go for (3), otherwise (2) if we're not comfortable with the risk. I think (1) is out of question at this point.

https://github.com/llvm/llvm-project/pull/69673


More information about the libcxx-commits mailing list