Date: Tue, 7 Mar 2023 02:53:15 -0800 From: Mark Millard <marklmi@yahoo.com> To: FreeBSD Toolchain <freebsd-toolchain@freebsd.org>, freebsd-arm <freebsd-arm@freebsd.org> Subject: a system-clang 15 and devel/llvm1[56] armv7 code generation error: a small test case Message-ID: <A92A4836-E615-46C0-8F43-E19A98671E1B@yahoo.com> In-Reply-To: <B703089D-0EA6-49D4-96F9-69C09B0FF23C@yahoo.com> References: <F536BC00-49D3-41F8-A328-EA10FD21E1DC.ref@yahoo.com> <F536BC00-49D3-41F8-A328-EA10FD21E1DC@yahoo.com> <2HOLCFE6Z_cOyGycU4ZBU7Lf6kcqohVx7tiLiRLzdjMEc6a8DFeH1IaJqdPNJOqFVTh1MGE7_UUJLcg2gg0UbTZIHZl72NbaNEsqrJwJ3xA=@lorenzosalvadore.it> <93707ED2-F529-49DE-A018-794827F56247@yahoo.com> <7AA0AE73-87CC-4B26-92B2-A0EC4281F429@yahoo.com> <480C8278-DC30-40D6-AED2-F52F59E78EBC@yahoo.com> <EB917CA9-CC67-4F79-8EBD-6BE82B021D45@yahoo.com> <B703089D-0EA6-49D4-96F9-69C09B0FF23C@yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
[This is just an FYI about a system-clang 15 and devel/llvm1[56] armv7 code generation bug. The investigation sequence notes that lead to this discovery is on the freebsd-ports list.] On Mar 7, 2023, at 02:26, Mark Millard <marklmi@yahoo.com> wrote on the freebsd-ports list: > Below is a small example C source showing the clang 15+ armv7 > problem that leads to the unbounded looping in later code in > the lang/gcc12+ builds: a data structure is mis-initialized, > breaking its invariant properties used by the later code > structure. >=20 > # more partition.c > // Minor varation of part of some gcc source code! >=20 > // For system-clang 15: cc -g -O2 partition.c ; ./a.out > // For devel/llvm16: clang16 -g -O2 partition.c ; ./a.out >=20 > #include <stdio.h> >=20 > #define NUM_ELEMENTS 32 >=20 > struct partition_elem > { > struct partition_elem* next; > int class_element; > unsigned class_count; > }; >=20 > typedef struct partition_def > { > int num_elements; > struct partition_elem elements[NUM_ELEMENTS]; > } *partition; >=20 > struct partition_def partition_storage; >=20 > partition > partition_new (int num_elements) > { > int e; >=20 > if (NUM_ELEMENTS < num_elements) num_elements =3D NUM_ELEMENTS; >=20 > partition part=3D &partition_storage; > part->num_elements =3D num_elements; > for (e =3D 0; e < num_elements; ++e) > { > part->elements[e].class_element =3D e; > part->elements[e].next =3D &(part->elements[e]); > part->elements[e].class_count =3D 1; > } >=20 > for (e =3D 0; e < num_elements; ++e) > printf("%d: %p : next?: = %p\n",e,(void*)&part->elements[e],(void*)part->elements[e].next); >=20 > return part; > } >=20 > int main(void) > { > partition part; > part=3D partition_new(NUM_ELEMENTS); >=20 > return !part; > } >=20 > In the output below, note the blocks of 4 "next" > values that do not change. Each should match the > earlier hexadecimal value on the same line: point > back to same element of the array. 3 of 4 do not. >=20 > # cc -g -O2 partition.c > # ./a.out > 0: 0x40a84 : next?: 0x40a84 > 1: 0x40a90 : next?: 0x40a84 > 2: 0x40a9c : next?: 0x40a84 > 3: 0x40aa8 : next?: 0x40a84 > 4: 0x40ab4 : next?: 0x40ab4 > 5: 0x40ac0 : next?: 0x40ab4 > 6: 0x40acc : next?: 0x40ab4 > 7: 0x40ad8 : next?: 0x40ab4 > 8: 0x40ae4 : next?: 0x40ae4 > 9: 0x40af0 : next?: 0x40ae4 > 10: 0x40afc : next?: 0x40ae4 > 11: 0x40b08 : next?: 0x40ae4 > 12: 0x40b14 : next?: 0x40b14 > 13: 0x40b20 : next?: 0x40b14 > 14: 0x40b2c : next?: 0x40b14 > 15: 0x40b38 : next?: 0x40b14 > 16: 0x40b44 : next?: 0x40b44 > 17: 0x40b50 : next?: 0x40b44 > 18: 0x40b5c : next?: 0x40b44 > 19: 0x40b68 : next?: 0x40b44 > 20: 0x40b74 : next?: 0x40b74 > 21: 0x40b80 : next?: 0x40b74 > 22: 0x40b8c : next?: 0x40b74 > 23: 0x40b98 : next?: 0x40b74 > 24: 0x40ba4 : next?: 0x40ba4 > 25: 0x40bb0 : next?: 0x40ba4 > 26: 0x40bbc : next?: 0x40ba4 > 27: 0x40bc8 : next?: 0x40ba4 > 28: 0x40bd4 : next?: 0x40bd4 > 29: 0x40be0 : next?: 0x40bd4 > 30: 0x40bec : next?: 0x40bd4 > 31: 0x40bf8 : next?: 0x40bd4 >=20 > Turns out that the -O2 is important: no other that I > tried got the problem, including -O3 not getting the > problem. lang/gcc12+ builds happen to use -O2 , at > least in my environment. >=20 > -g is not required for the problem. >=20 I've not built lang/gcc11 or before in a long time. Building them "no bootstrap" style via clang15+ may hit the same type of problem for all I know. =3D=3D=3D Mark Millard marklmi at yahoo.com
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?A92A4836-E615-46C0-8F43-E19A98671E1B>