<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61255>61255</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang 15.0.7 (and 16) armv7 code generation error that later stopped build of gcc12 (or 13) from making progress
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
markmi
</td>
</tr>
</table>
<pre>
The problem that I report here was first discovered on FreeBSD but I report based on replication on openSUSE Tumbleweed, linux being the common/familiar context for most folks. I only tested the small reproducer on armv7 linux, not the original problem.
I show the small reproducer and its output but the original issue was build failures for a non-bootstrap build of FreeBSD's lang/gcc12 (and 13) port in/for an armv7 context. (I did not try anything older.) The reproducer is a minor change to part of the gcc source code, making the code extracted simpler for the purpose.
In the output shown later from the test program, the 2nd hexadecimal number (0x prefix) in each numbered line should be the same as the first hexadecimal number (0x prefix) in the line but usually is not. In the gcc build context, this produced a violation of invariants and unbounded looping in gcc at one stage of the build, blocking later stages from happening.
(FYI: On/for amd64 and aarch64 no failure was observed in the reproducer or in building lang/gcc12 [or 13] . So: armv7 specific of the 3.)
I show the source code for the reproducer last.
```
# uname -ap
Linux localhost.localdomain 6.2.0-1-lpae #1 SMP Mon Feb 20 06:22:59 UTC 2023 (89e2785) armv7l armv7l armv7l GNU/Linux
# clang-15 -v
clang version 15.0.7
Target: armv7hl-suse-linux-gnueabihf
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/armv7hl-suse-linux-gnueabi/12
Selected GCC installation: /usr/bin/../lib/gcc/armv7hl-suse-linux-gnueabi/12
Candidate multilib: .;@m32
Selected multilib: .;@m32
```
(Note: on FreeBSD both clang 15 and 16 get the problem for armv7. I only tested 15 on openSUSE.)
```
# clang-15 -g -O2 partition.c ; ./a.out
0: 0x498044 : next?: 0x498044
1: 0x498050 : next?: 0x498044
2: 0x49805c : next?: 0x498044
3: 0x498068 : next?: 0x498044
4: 0x498074 : next?: 0x498074
5: 0x498080 : next?: 0x498074
6: 0x49808c : next?: 0x498074
7: 0x498098 : next?: 0x498074
8: 0x4980a4 : next?: 0x4980a4
9: 0x4980b0 : next?: 0x4980a4
10: 0x4980bc : next?: 0x4980a4
11: 0x4980c8 : next?: 0x4980a4
12: 0x4980d4 : next?: 0x4980d4
13: 0x4980e0 : next?: 0x4980d4
14: 0x4980ec : next?: 0x4980d4
15: 0x4980f8 : next?: 0x4980d4
16: 0x498104 : next?: 0x498104
17: 0x498110 : next?: 0x498104
18: 0x49811c : next?: 0x498104
19: 0x498128 : next?: 0x498104
20: 0x498134 : next?: 0x498134
21: 0x498140 : next?: 0x498134
22: 0x49814c : next?: 0x498134
23: 0x498158 : next?: 0x498134
24: 0x498164 : next?: 0x498164
25: 0x498170 : next?: 0x498164
26: 0x49817c : next?: 0x498164
27: 0x498188 : next?: 0x498164
28: 0x498194 : next?: 0x498194
29: 0x4981a0 : next?: 0x498194
30: 0x4981ac : next?: 0x498194
31: 0x4981b8 : next?: 0x498194
```
(On FreeBSD only -O2 style builds got the failure. The -g use vs. not did not matter. I did not test such variations on openSUSE.)
The comments in the source code for the reproducer suggest how to run the test (in a FreeBSD context). The reproducer source code is:
```
// Minor varation of part of some gcc source code!
// For system-clang 15: cc -g -O2 partition.c ; ./a.out
// For devel/llvm16: clang16 -g -O2 partition.c ; ./a.out
#include <stdio.h>
#define NUM_ELEMENTS 32
struct partition_elem
{
struct partition_elem* next;
int class_element;
unsigned class_count;
};
typedef struct partition_def
{
int num_elements;
struct partition_elem elements[NUM_ELEMENTS];
} *partition;
struct partition_def partition_storage;
partition
partition_new (int num_elements)
{
int e;
if (NUM_ELEMENTS < num_elements) num_elements = NUM_ELEMENTS;
partition part= &partition_storage;
part->num_elements = num_elements;
for (e = 0; e < num_elements; ++e)
{
part->elements[e].class_element = e;
part->elements[e].next = &(part->elements[e]);
part->elements[e].class_count = 1;
}
for (e = 0; e < num_elements; ++e)
printf("%d: %p : next?: %p\n",e,(void*)&part->elements[e],(void*)part->elements[e].next);
return part;
}
int main(void)
{
partition part;
part= partition_new(NUM_ELEMENTS);
return !part;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0WF2P4yoS_TX0SymWjePEechDf-VqpDszK3XPwz6NsKk47GCwAGe6__0K_Jl03Hek1Y5GaRsfqFN1Cgpg1opKIe5J9kCypzvWupM2-5qZX7W4KzR_37-eEBqjC4k1uBNz8AUMNto4OKFB-M0sHIWxDriwpT6jQQ5awcEgPrw8QdHOehTMdl8NNlKUzAmt_KtuUL38eHmG17YuJP5G5IQ-ghSqfYMCharAnRBKXddaEXo4slpIwQyUWjl8c3DUBmpt_YP8ZSP4AlrJd3BoHfLQ19ZMSm_XaN6WaLxZZurztrPizSntAlQbUQnF5OB2ROInEt93v1_AnvTv20MyxUE4C7p1TeuC6xfjCWvbLmJFKySHIxOyNWgDfQZKq1WhtbPOsKaH6OMQSUK3FiRTFaGHqiwTCoTm3mKSErqDEF8RguMHG5zrAxR58Bfggndemndg6t2dfGS15GgiP4aXeuaOsMCgFkobKE9MVQhOQ8OM86y8Y1VZgtWtKb00HH0Ma_ZrUosj4JszrPQiWFE3Ek3w1X9uWtNoi5fBVV3Auvj5QCuQzPleRtfhm5fUC1MZVnuDvo0qDid8YxxLUTMJqq0LNN7l-A0ag0fx5t0TCpCVp_4zcq88eiut5FBgpymrEZgNz11a_9nAHh-G86K3tmVSvvsAKu0i6N3y4epU7VXp-AsLfcg5MDgLLft5cQShzswIppwNudWqQreKe-ZaNz7OQoVRmQPtXXGswkGcYMlbKKQugyhdJAPIdgE9saZBJVQVwVwGQvPDv7-Q9B6-jwlV8806kGDMlKfNGpQe8jdktC4smjPyIRjzmWZ8Y-DT0ZjncPagjU_h7AkieNHeaJe5tsFSHEU5-JP6FF2aiVMSjvk1IyCZdRd5RjZx_7_3N4VWeeVXrOma_g5Lj9QlkydtXRSeuK6ZULCJaBSv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