Commit d51148d
committed
[libcxx] Recalculate union-member sizes in basic_string
Fixes #51158: instantiating a `basic_string` with a character type of
3, 5, or greater than 8 wouldn't work properly, because the two
members of its internal union disagreed on the location of the bit
flag indicating which member was live.
This commit completely rewrites the calculations of how much to pad
the two sub-structures so that their lengths match. Two new
static_asserts check that, after all the calculation is done, the
compiler agrees that the structures really did end up the same size. A
new test instantiates `basic_string` with every size of character type
up to 16, and four different alignment requirements.
The new code now potentially has to pad _both_ sub-structures,
depending on what is and is not divisible by the size of the character
type. This also means that the `__padding` type must have a method to
zero it out (otherwise the `__grow_by` method stops being constexpr,
which an existing test depends on).
I've also added some extra checks to the existing test
`push_back.pass.cpp`, which _could_ have found this issue by checking
that pushing huge characters on to a string updated the length in the
appropriate way.1 parent bf07226 commit d51148d
File tree
3 files changed
+169
-6
lines changed- libcxx
- include
- test/std/strings/basic.string
- string.modifiers/string_append
3 files changed
+169
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
719 | 719 | | |
720 | 720 | | |
721 | 721 | | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
722 | 726 | | |
723 | 727 | | |
724 | 728 | | |
725 | | - | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
726 | 732 | | |
727 | 733 | | |
728 | 734 | | |
| |||
819 | 825 | | |
820 | 826 | | |
821 | 827 | | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
822 | 855 | | |
823 | 856 | | |
824 | 857 | | |
| |||
829 | 862 | | |
830 | 863 | | |
831 | 864 | | |
| 865 | + | |
832 | 866 | | |
833 | 867 | | |
834 | 868 | | |
835 | 869 | | |
836 | | - | |
837 | | - | |
838 | 870 | | |
839 | 871 | | |
840 | | - | |
| 872 | + | |
841 | 873 | | |
842 | 874 | | |
843 | 875 | | |
844 | 876 | | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
845 | 882 | | |
846 | 883 | | |
847 | 884 | | |
| |||
887 | 924 | | |
888 | 925 | | |
889 | 926 | | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
890 | 934 | | |
891 | 935 | | |
892 | 936 | | |
| |||
900 | 944 | | |
901 | 945 | | |
902 | 946 | | |
903 | | - | |
904 | | - | |
905 | 947 | | |
906 | 948 | | |
| 949 | + | |
| 950 | + | |
907 | 951 | | |
908 | 952 | | |
909 | 953 | | |
| |||
2764 | 2808 | | |
2765 | 2809 | | |
2766 | 2810 | | |
| 2811 | + | |
2767 | 2812 | | |
2768 | 2813 | | |
2769 | 2814 | | |
| |||
Lines changed: 114 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
87 | 88 | | |
| 89 | + | |
88 | 90 | | |
| 91 | + | |
89 | 92 | | |
| 93 | + | |
90 | 94 | | |
91 | 95 | | |
92 | 96 | | |
| |||
0 commit comments