This is an archive of the discontinued LLVM Phabricator instance.

[clang][CodeGen] Avoid emitting unnecessary memcpy of records without content
Needs ReviewPublic

Authored by strimo378 on Aug 18 2023, 3:56 AM.

Details

Summary

Clang codegen emits unnecessary memcpy for C++ records without content. This patch fixes the issue.

See https://github.com/llvm/llvm-project/issues/59336

Please let me know if the patch is going into the right direction and has a change to get accepted. If yes, I'll finish it with test cases and also extend it to C. Currently, check-clang is not showing an error...

Diff Detail

Unit TestsFailed

Event Timeline

strimo378 created this revision.Aug 18 2023, 3:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 18 2023, 3:56 AM
strimo378 requested review of this revision.Aug 18 2023, 3:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 18 2023, 3:56 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
strimo378 edited the summary of this revision. (Show Details)Aug 18 2023, 4:00 AM
strimo378 added reviewers: rjmccall, efriedma, asl.

This looks sort of similar to CodeGen::isEmptyRecord... but I guess it's not quite the same thing. (Even if a struct isn't "empty" in the ABI sense, there still might not be anything to copy.)

Instead of looking for zero-length bitfields, you probably want to just check isUnnamedBitfield()? Unnamed bitfields are just padding, whether or not they're zero-length.