This is an archive of the discontinued LLVM Phabricator instance.

Add -Wpacked-non-pod to -Wall
ClosedPublic

Authored by SlaterLatiao on May 22 2023, 3:12 PM.

Details

Summary

[clang][diagnostics] Adding -Wpacked-non-pod to -Wall

  • Users will be informed when non-POD is not packed using -Wall. This is also consistent with GCC.
  • Fixes PR#60832.

Diff Detail

Event Timeline

SlaterLatiao created this revision.May 22 2023, 3:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 22 2023, 3:12 PM
SlaterLatiao requested review of this revision.May 22 2023, 3:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 22 2023, 3:12 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
SlaterLatiao edited the summary of this revision. (Show Details)May 22 2023, 3:19 PM
SlaterLatiao edited the summary of this revision. (Show Details)

Yeah, looks consistent with GCC ( https://godbolt.org/z/EGc3Ec9YT ), as you say - so I'm OK with it. But wouldn't mind a second opinion.

SlaterLatiao updated this revision to Diff 524909.EditedMay 23 2023, 3:27 PM

Test -Wpacked-non-pod not emitting warnings of "packed attribute is unnecessary".

cjdb accepted this revision.May 24 2023, 11:22 AM

Thanks for working on this!

This revision is now accepted and ready to land.May 24 2023, 11:22 AM
denik added inline comments.May 24 2023, 11:32 AM
clang/test/CodeGenCXX/warn-padded-packed.cpp
4

This one is a very neat test. I think it does what we want :)

5

Probably we don't need this one. But I'm not sure if there is any impact of the abi on`packed-non-pod`. According to the original test it checks only -Wpacked packed attribute is unnecessary warning.

  • Removed the -triple flag from warn-padded-packed testcase.
SlaterLatiao added inline comments.May 24 2023, 12:06 PM
clang/test/CodeGenCXX/warn-padded-packed.cpp
5

I added this line to make sure all the packed attribute is unnecessary warnings in the existing test of -Wpacked are not reported by -Wpacked-non-pod. Yeah if the abi doesn't have any impact on -Wpacked-non-pod this test is unnecessary.

Please be sure to add a release note for the change, and it'd probably be good to have a test case that shows this triggers under -Wall (the modified test case explicitly names the diagnostic).

dblaikie added inline comments.May 24 2023, 1:24 PM
clang/test/CodeGenCXX/warn-padded-packed.cpp
5

the old ABI shouldn't emit the -Wpacked-non-pod warning since the warning isn't correct in the old ABI - where packed is applied to non-pod equally as pod.

Please be sure to add a release note for the change, and it'd probably be good to have a test case that shows this triggers under -Wall (the modified test case explicitly names the diagnostic).

Thank you, Aaron. I'll add the test case. Should this change go under Improvements to Clang’s diagnostics in the release note?

Please be sure to add a release note for the change, and it'd probably be good to have a test case that shows this triggers under -Wall (the modified test case explicitly names the diagnostic).

Thank you, Aaron. I'll add the test case. Should this change go under Improvements to Clang’s diagnostics in the release note?

Yes, that sounds like a good place for the note. Thank you!

  • Test behavior of -Wpacked-non-pod in -Wall and update test case name.
  • Update release note.
  • Fix missing parenthesis.
aaron.ballman accepted this revision.May 25 2023, 10:19 AM

LGTM! Do you need someone to commit on your behalf? If so, what name and email address would you like us to use for patch attribution?

SlaterLatiao edited the summary of this revision. (Show Details)May 25 2023, 11:00 AM

LGTM! Do you need someone to commit on your behalf? If so, what name and email address would you like us to use for patch attribution?

Thank you, Aaron! Please use Zenong Zhang and slaterlatiao@gmail.com for the commit.

This revision was landed with ongoing or failed builds.May 25 2023, 11:18 AM
This revision was automatically updated to reflect the committed changes.
This revision is now accepted and ready to land.May 25 2023, 11:52 AM
SlaterLatiao added a comment.EditedMay 25 2023, 12:04 PM

I shouldn't remove -triple=x86_64-none-none in the test case. The "padding struct 'S1' with 1 byte" warning can be different in different architectures. I'll add it back.

Adding back the -triple flag

  • The padding size can be different on different architectures.
This revision was landed with ongoing or failed builds.May 25 2023, 1:02 PM
This revision was automatically updated to reflect the committed changes.