This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Fix Bug 47499: __unaligned extension inconsistent behaviour with C and C++
ClosedPublic

Authored by j0le on Nov 2 2020, 10:20 AM.

Details

Summary

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

Diff Detail

Event Timeline

j0le created this revision.Nov 2 2020, 10:20 AM
j0le requested review of this revision.Nov 2 2020, 10:20 AM
rnk accepted this revision.Nov 2 2020, 10:43 AM

Thanks, this basically looks correct to me, aside from some formatting details. Do you want me to apply those fixes and land this for you? I see that was done for your last patch, but it's best to ask first.

clang/lib/CodeGen/CodeGenModule.cpp
6153–6155

It's pretty uncommon to see comment blocks between the closing if curly and the next else if. Please move this comment inside the relevant else-if block.

This revision is now accepted and ready to land.Nov 2 2020, 10:43 AM
j0le updated this revision to Diff 302496.Nov 3 2020, 12:57 AM
j0le edited the summary of this revision. (Show Details)

Moved comment into the else-if block.
Changed Summary of the diff, so that it is better suited for a commit message.

j0le marked an inline comment as done.Nov 3 2020, 1:00 AM
In D90630#2368984, @rnk wrote:

Thanks, this basically looks correct to me, aside from some formatting details. Do you want me to apply those fixes and land this for you? I see that was done for your last patch, but it's best to ask first.

Yes, that would be nice, if you could land this for me.