<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - missed optimization with C constructors of sparse structures"
href="https://bugs.llvm.org/show_bug.cgi?id=40776">40776</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>missed optimization with C constructors of sparse structures
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>8.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>arnd@linaro.org
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>I stumbled over a file with excessive stack usage in the Linux kernel when
building with clang, but not with gcc, reduced the test case to:
struct i2c_adapter {
char name[48];
int a[1000];
} hexium_attach_hexium;
void hexium_attach(void) {
hexium_attach_hexium = (struct i2c_adapter){"hexium gemini"};
}
$ clang-8 -Werror -c hexium-gemini.c -Wframe-larger-than=100 -O2
hexium-gemini.c:5:6: error: stack frame size of 4056 bytes in function
'hexium_attach' [-Werror,-Wframe-larger-than=]
Comparing the output shows that clang not only allocates stack space for the
extra copy of the structure, but also fails to optimize the string assignment:
<a href="https://godbolt.org/z/7jpy_y">https://godbolt.org/z/7jpy_y</a>
I worked around it in the kernel sources by using an explict memset and
strscpy, but this seems like a generally useful optimization that could be
added.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>