[llvm-bugs] [Bug 49708] std::memcpy with incorrect align attribute on arguments introduces undefined behavior

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Mar 24 02:09:23 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=49708

Roman Lebedev <lebedev.ri at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|NEW                         |RESOLVED
                 CC|                            |lebedev.ri at gmail.com

--- Comment #1 from Roman Lebedev <lebedev.ri at gmail.com> ---
Why is that not correct?

A pointer to an integer is 4-byte aligned:
https://clang.godbolt.org/z/zda9M15K1
All accesses to it are 4-byte aligned.
If it is not, that's UB already.

So when `g()` casts a char* to an int*,
iff the target pointer has larger alignment
than the actual alignment of the pointer,
that's UB.

-- 
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/20210324/3ced9720/attachment.html>


More information about the llvm-bugs mailing list