<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 - [coroutines] Merging frame variables drops alignment information"
href="https://bugs.llvm.org/show_bug.cgi?id=48712">48712</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[coroutines] Merging frame variables drops alignment information
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</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>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++2a
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>jeremy.morse.llvm@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk, yedeng.yd@linux.alibaba.com
</td>
</tr></table>
<p>
<div>
<pre>A recent patch to merge non-overlapping allocas in coroutine frames [0] appears
to drop alignment information from one of the merged allocas. I have a fairly
complicated C++ reproducer that manages to crash as a result of this, however I
think it's best illustrated by one of the frame-reuse tests [1]. In that file,
%a and %b are merged into a single frame element:
%a.Frame = type {
void (%a.Frame*)*,
void (%a.Frame*)*,
%"struct.task::promise_type",
%struct.big_structure,
i1 }
Where the big_structure and big_structure.2 allocas have been merged into
big_structure. If I change %a to have 64 byte alignment:
%a = alloca %struct.big_structure, align 64
Then the frame is reshaped accordingly:
%a.Frame = type {
void (%a.Frame*)*,
void (%a.Frame*)*,
%"struct.task::promise_type",
i1,
[46 x i8],
%struct.big_structure }
With padding place before the big_structure type. If I add alignment to %b
instead of %a:
%b = alloca %struct.big_structure.2, align 64
Then the field in the frame doesn't get aligned:
%a.Frame = type {
void (%a.Frame*)*,
void (%a.Frame*)*,
%"struct.task::promise_type",
%struct.big_structure,
i1 }
The subsequent use of that unaligned field for %b's pointer:
%a.reload.addr = getelementptr inbounds %a.Frame, %a.Frame* %FramePtr, i32 0,
i32 3
%b.reload.addr = bitcast %struct.big_structure* %a.reload.addr to
%struct.big_structure.2*
Produces a pointer for %b that was supposed to be aligned to 64 bytes before
being split into a coroutine; and afterwards will not be aligned to 64 bytes.
I'm still hunting for why this causes my reproducer to crash later on, but I
believe this loss of alignment is a bug.
[0] <a href="https://reviews.llvm.org/rGb3a722e66b75">https://reviews.llvm.org/rGb3a722e66b75</a>
[1]
<a href="https://github.com/llvm/llvm-project/blob/a6db7cf1ce7f3523adb132819c1697a572bdcfde/llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-02.ll">https://github.com/llvm/llvm-project/blob/a6db7cf1ce7f3523adb132819c1697a572bdcfde/llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-02.ll</a></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>