This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Fix defaulted equality operator so that it does not attempt to compare unnamed bit-fields
ClosedPublic

Authored by shafik on Mar 17 2023, 1:45 PM.

Details

Summary

If we look at class.bit p2 it tells us that that unnamed bit-fields are not members and class.compare.default p5 tells us that we should only non-static data members of the class.

This fixes: https://github.com/llvm/llvm-project/issues/61335 and https://github.com/llvm/llvm-project/issues/61417

Diff Detail

Event Timeline

shafik created this revision.Mar 17 2023, 1:45 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2023, 1:45 PM
shafik requested review of this revision.Mar 17 2023, 1:45 PM

I would have loved to test the case from https://github.com/llvm/llvm-project/issues/61335 directly but I think in order to do it nicely I need __builtin_memset to be usable in a constant expression context. I will add this to my todo list. I am open to other alternatives for testing this.

royjacobson added a subscriber: royjacobson.EditedMar 20 2023, 2:16 PM

I would have loved to test the case from https://github.com/llvm/llvm-project/issues/61335 directly but I think in order to do it nicely I need __builtin_memset to be usable in a constant expression context. I will add this to my todo list. I am open to other alternatives for testing this.

I managed to generate relatively readable LLVM IR for this: https://godbolt.org/z/z1YzoEcr3 (the generated equality operators are obviously not correct yet), I think matching against that is testing the issue pretty well.

(The trick to making it readable was turning on optimization, though. Not sure if we usually do that)

shafik added a comment.Apr 3 2023, 9:06 PM

I would have loved to test the case from https://github.com/llvm/llvm-project/issues/61335 directly but I think in order to do it nicely I need __builtin_memset to be usable in a constant expression context. I will add this to my todo list. I am open to other alternatives for testing this.

I managed to generate relatively readable LLVM IR for this: https://godbolt.org/z/z1YzoEcr3 (the generated equality operators are obviously not correct yet), I think matching against that is testing the issue pretty well.

(The trick to making it readable was turning on optimization, though. Not sure if we usually do that)

I think in general we can't rely on optimizations in test like this but wdyt @erichkeane

I would have loved to test the case from https://github.com/llvm/llvm-project/issues/61335 directly but I think in order to do it nicely I need __builtin_memset to be usable in a constant expression context. I will add this to my todo list. I am open to other alternatives for testing this.

I managed to generate relatively readable LLVM IR for this: https://godbolt.org/z/z1YzoEcr3 (the generated equality operators are obviously not correct yet), I think matching against that is testing the issue pretty well.

(The trick to making it readable was turning on optimization, though. Not sure if we usually do that)

I think in general we can't rely on optimizations in test like this but wdyt @erichkeane

We should not have opt enabled in our lit tests, thats correct. However, the non-optimized version of that godbolt link has reasonably readable IR that we can test.

shafik updated this revision to Diff 512983.Apr 12 2023, 3:19 PM
  • Added codegen test

@erichkeane let me know if the test I added is sufficient

erichkeane added inline comments.Apr 13 2023, 5:56 AM
clang/test/CodeGenCXX/defaulted_equality_ignore_unnamed_bitfields.cpp
24

I think these check lines aren't nearly specific enough, i think it should have a handful of CHECK lines confirming what we're doing, not just what we're not.

shafik updated this revision to Diff 513345.Apr 13 2023, 1:36 PM
shafik marked an inline comment as done.
  • Update codegen test based on feedback
erichkeane accepted this revision.Apr 14 2023, 5:49 AM
This revision is now accepted and ready to land.Apr 14 2023, 5:49 AM
shafik updated this revision to Diff 513754.Apr 14 2023, 2:55 PM
  • Add release note
This revision was landed with ongoing or failed builds.Apr 14 2023, 3:01 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2023, 3:01 PM