g++-12 reports:
libcxx/include/string:727:13: error: anonymous struct with base classes 727 | : __padding<value_type>
Differential D122598
[libcxx] avoid using anonymous struct with base classes (fixes gcc-12) azat on Mar 28 2022, 10:34 AM. Authored by
Details
g++-12 reports: libcxx/include/string:727:13: error: anonymous struct with base classes 727 | : __padding<value_type>
Diff Detail
Event Timeline
Comment Actions Why not make it something like template <class CharT> struct short_size { char __padding[sizeof(CharT) - 1]; unsigned char __size_; }; ? That would eliminate the need for __padded all together. This of course requires another extension, but makes the code a lot simpler. Comment Actions So I was wondering how to make sure this change is good, and wasn't too sure. It turns out that we don't have any ABI compatibility testing for this code path. I'm adding that in D123081, so I'd like for D123081 to land before we land this. Once we have backdeployment testing running on arm64, we can try messing up the padding here in a subtle way, confirm that it breaks our tests, and then move forward with this patch with confidence (and satisfaction knowing our tests really have our back). This looks correct to me, but still requesting changes so it shows up in the review queue.
Comment Actions ldionne should I resubmit the patch to run CI against https://reviews.llvm.org/D123081? As for failures, they looks unrelated?
Comment Actions @azat Please rebase on top of main and then re-upload the patch. It should run on top of the fixed CI and I would expect that everything looks green! Comment Actions And I just applied your original patch locally on my arm64 macbook air, ran the macOS 11 backdeployment testing, and I can see numerous tests failing because strings have an incorrect length. So this issue would have been caught with macOS arm64 backdeployment CI. With this additional confidence, this LGTM if CI is passing. Please provide Author Name <email@domain> if you need us to commit this for you. Thanks! Comment Actions
Great, thanks!
Azat Khuzhin <a3at.mail@gmail.com> Interesting, I though that should be included in the patch on phabricator. Comment Actions
@jgorbe AFAICS - No, have you experience some issues? Plus I see there are tests for string formatting in lldb, which cover both: long and short strings: Comment Actions Thanks for the reply! Yes, I've seen some test failures while trying to update our llvm to (closer to) HEAD, and I bisected them to this commit. These were the affected tests: lldb/test/API/commands/expression/call-function/TestCallStdStringFunction.py.test I believe all of them failed with some string output being replaced by "Summary Unavailable". My first attempt at reproducing it in a plain upstream checkout failed (ninja check-lldb showed me lots of errors, both before and after this change, but it's very possible that I was doing something wrong with my local build), so I added the comment here to see if anyone else was experiencing the same problem, or if the problem was in our side. If you're not seeing the problem, that's additional evidence that the problem might be on our side. |
This is an ABI break, since __padding<char, 1> is normally elided via the empty base optimization. This change prevents that from happening.
Instead, I believe we should give a name to this anonymous struct, since the lack thereof is non-standard and also pretty surprising. I would do:
Then, you'll have to change places where we access .__size_ directly into accessing .__padded_.__size_ instead. Note that __padded_ isn't a great name, but I couldn't think of anything better. Suggestions are welcome.