[CodeGen] Fix Bug 47499: __unaligned extension inconsistent behaviour with C and C++
authorJan Ole Hüser <j.hueser@beckhoff.de>
Thu, 5 Nov 2020 19:01:51 +0000 (11:01 -0800)
committerReid Kleckner <rnk@google.com>
Thu, 5 Nov 2020 20:57:17 +0000 (12:57 -0800)
commitd2e7dca5ca92c655e451d6fcb806df38d7f2d56b
treef4288cd1a41835b08252ea8b05a44dd948c18c26
parent1af037f643fc5499f83d92e5aec199950871d475
[CodeGen] Fix Bug 47499: __unaligned extension inconsistent behaviour with C and C++

For the language C++ the keyword __unaligned (a Microsoft extension) had no effect on pointers.

The reason, why there was a difference between C and C++ for the keyword __unaligned:
For C, the Method getAsCXXREcordDecl() returns nullptr. That guarantees that hasUnaligned() is called.
If the language is C++, it is not guaranteed, that hasUnaligend() is called and evaluated.

Here are some links:

The Bug: https://bugs.llvm.org/show_bug.cgi?id=47499
Thread on the cfe-dev mailing list: http://lists.llvm.org/pipermail/cfe-dev/2020-September/066783.html
Diff, that introduced the check hasUnaligned() in getNaturalTypeAlignment(): https://reviews.llvm.org/D30166

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D90630
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/unaligned-struct-copy.c [new file with mode: 0644]