This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Don't emit pointer to int cast warnings under -Wmicrosoft-cast
ClosedPublic

Authored by aeubanks on Mar 4 2020, 1:34 PM.

Details

Summary

MSVC also warns on this:
$ cat /tmp/a.c
int f(void* p) { return (int) p; }

$ cl /c /tmp/a.c
C:/src/tmp/a.c(1): warning C4311: 'type cast': pointer truncation from
'void *' to 'int'

Warnings originally added in https://reviews.llvm.org/D72231.

Diff Detail

Event Timeline

aeubanks created this revision.Mar 4 2020, 1:34 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 4 2020, 1:34 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aeubanks retitled this revision from Don't emit pointer to int cast warnings under -Wmicrosoft-cast to [Sema] Don't emit pointer to int cast warnings under -Wmicrosoft-cast.Mar 4 2020, 2:29 PM
rnk added a subscriber: rsmith.Mar 4 2020, 3:01 PM

Looking at the review, I think @rsmith requested this -Wmicrosoft-cast behavior here:
https://reviews.llvm.org/D72231#1857660

This change looks good to me, but I wanted to get his input before we undo his request.

rnk accepted this revision.Mar 6 2020, 4:08 PM

I re-read Richard's comment:

Would it make sense to put the MS extension warning into the -Wpointer-to-int-cast group so that we can control this warning consistently across platforms? You could get that effect by introducing a new warning group (eg, "-Wmicrosoft-pointer-to-int-cast") containing just the ExtWarn warning, and putting that group in both MicrosoftCast and PointerToIntCast.

My interpretation is that he was suggesting the change that you are making here. So, let's continue without his additional approval.

I'll go ahead and push this in a minute.

This revision is now accepted and ready to land.Mar 6 2020, 4:08 PM
rnk added a comment.Mar 9 2020, 10:19 AM

I think I patched this in, ran tests, but didn't push. Feel free to push if you get the chance.

This revision was automatically updated to reflect the committed changes.