<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 - Possible false positive with -Wcast-align for aligned Class"
href="https://bugs.llvm.org/show_bug.cgi?id=33341">33341</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Possible false positive with -Wcast-align for aligned Class
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>4.0
</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>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Static Analyzer
</td>
</tr>
<tr>
<th>Assignee</th>
<td>kremenek@apple.com
</td>
</tr>
<tr>
<th>Reporter</th>
<td>zhengtao.lee@autodesk.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=18586" name="attach_18586" title="test code">attachment 18586</a> <a href="attachment.cgi?id=18586&action=edit" title="test code">[details]</a></span>
test code
we have a class which contains 3 doubles and they should be aligned to 8.
however consider the code below
class AcGeVector3d
{
public:
double x,y,z;
};
inline double*
asDblArray(const AcGeVector3d& vec)
{
static_assert(alignof(decltype(&vec)) == 4,"hmm?");
static_assert(alignof(AcGeVector3d*) == 4,"hmm?");
static_assert(alignof(double*) == 4, "hmm?");
static_assert(alignof(double[3]) == 8, "hmm?");
static_assert(alignof(AcGeVector3d) == 8, "hmm?");
static_assert(alignof(decltype(vec)) == 8, "hmm?");
static_assert(alignof(decltype(*&vec)) == 8, "hmm?");
static_assert(alignof(AcGeVector3d) == alignof(double[3]), "AcGeVector3d)
== alignof(double[3])");
static_assert(alignof(AcGeVector3d*) == alignof(double*), "AcGeVector3d*)
== alignof(double*)");
static_assert(sizeof(AcGeVector3d) == sizeof(double[3]), "AcGeVector3d) ==
sizeof(double[3])");
//#pragma clang diagnostic push
//#pragma clang diagnostic ignored "-Wcast-align"
return (double*)&vec;
//#pragma clang diagnostic pop
}
bool test(const AcGeVector3d& n)
{
double* p = asDblArray(n);
return p != nullptr;
}
run "clang++.exe" test.cpp -c -Wcast-align -emit-llvm -std=c++14 -target
asmjs-unknown-emscripten
the output is:
test.cpp:22:12: warning: cast from 'const AcGeVector3d *' to 'double *'
increases required alignment from 4 to 8
[-Wcast-align]
return (double*)&vec;
^~~~~~~~~~~~~
1 warning generated.
note that none of the static asserts are triggered.</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>