[llvm-bugs] [Bug 33341] New: Possible false positive with -Wcast-align for aligned Class
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Jun 7 02:21:11 PDT 2017
https://bugs.llvm.org/show_bug.cgi?id=33341
Bug ID: 33341
Summary: Possible false positive with -Wcast-align for aligned
Class
Product: clang
Version: 4.0
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: Static Analyzer
Assignee: kremenek at apple.com
Reporter: zhengtao.lee at autodesk.com
CC: llvm-bugs at lists.llvm.org
Created attachment 18586
--> https://bugs.llvm.org/attachment.cgi?id=18586&action=edit
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170607/4d527712/attachment-0001.html>
More information about the llvm-bugs
mailing list