This is an archive of the discontinued LLVM Phabricator instance.

[Sema][Windows] Don't special-case void* in __unaligned conversions.
ClosedPublic

Authored by efriedma on Mar 3 2022, 12:43 PM.

Details

Summary

As far as I can tell, MSVC allows the relevant conversions for all pointer types. Found compiling a Windows SDK header.

I've verified that the updated errors in MicrosoftExtensions.cpp match the ones that MSVC actually emits, except for the one with a FIXME. (Not sure why this wasn't done for the patch that added the tests.)

Diff Detail

Event Timeline

efriedma created this revision.Mar 3 2022, 12:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2022, 12:43 PM
efriedma requested review of this revision.Mar 3 2022, 12:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2022, 12:43 PM

I don't particularly understand this qualifier, is this something that perhaps @rnk could take a look at?

clang/test/SemaCXX/MicrosoftExtensions.cpp
88–89

Hmm... this one was quite suspicious. In this case, it was choosing the 'int' returning overload, MSVC doesn't do that here, it seems to always choose the best match without the __unaligned (as you're doing now).

91–92

MSVC is warning on this one, its a shame we don't have something similar.

rnk added a comment.Mar 8 2022, 3:14 PM

I remember writing up feedback on this patch, but it's gone now, oh well.

I wasn't able to find any history for why void* was special here.

I see that MSVC doesn't warn when converting from __unaligned int* to int*, but that seems dangerous. Our team has an active feature request to tighten up clang warnings to make it harder to form unaligned pointers, so I'd like to insist that we warn when the __unaligned qualifier gets lost.

clang/test/SemaCXX/MicrosoftExtensions.cpp
91–92

I agree this is important, and I think it's a blocking issue. We don't want to allow new constructs, introduce a warning for them later, and then ask people to clean it up.

efriedma updated this revision to Diff 413989.Mar 8 2022, 6:34 PM

Added warning. This roughly matches the corresponding MSVC warning, as far as I can tell.

I wasn't able to find any history for why void* was special here.

As far as I can tell, nobody ever thought void* was special. The check was an attempt to restrict dubious conversions while still remaining compatible with existing code.

This looks fine to me, though we should wait for @rnk to decide whether the warning is sufficient for him.

rnk accepted this revision.Mar 9 2022, 3:19 PM

lgtm, thanks!

This revision is now accepted and ready to land.Mar 9 2022, 3:19 PM