<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 - GPF when passing a non-aligned struct to a __declspec(align) typedef"
href="https://bugs.llvm.org/show_bug.cgi?id=44641">44641</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>GPF when passing a non-aligned struct to a __declspec(align) typedef
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</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>LLVM Codegen
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>alexandre.ganea@ubisoft.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk, rnk@google.com
</td>
</tr></table>
<p>
<div>
<pre>Clang does not complain when a non-aligned instance is assigned to aligned
typedef'd type (repro below).
I think at least a warning would be nice (if not, an error).
MSVC and GCC handle this by doing a unaligned load.
<a href="https://godbolt.org/z/62HzmJ">https://godbolt.org/z/62HzmJ</a>
--------------------------------
// a.h
struct Vector4 { float v[4]; };
typedef __declspec(align(16)) Vector4 AlignVector4;
struct A {
AlignVector4 vec;
void SetVec(const AlignVector4& v) { vec = v; }
};
struct B {
bool b;
Vector4 vec;
};
--------------------------------
// a.cpp
#include "a.h"
int f(A& a, const B& b) {
a.SetVec(b.vec);
return (int)a.vec.v[0];
}
--------------------------------
// main.cpp
#include "a.h"
int f(A& a, const B& b);
int main() {
A a; B b;
return f(a, b);
}
--------------------------------
// Build:
// clang-cl a.cpp /O2 /c /MT
// clang-cl main.cpp /c /MT
// lld-link a.obj main.obj /entry:main /subsystem:console</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>