This is an archive of the discontinued LLVM Phabricator instance.

[clang][codegen] Fix emission of consteval constructor of derived type
ClosedPublic

Authored by Fznamznon on Jan 25 2023, 4:42 AM.

Details

Summary

For simple derived type ConstantEmitter returns a struct of the same
size but different type which is then stored field-by-field into memory
via pointer to derived type. In case base type has more fields than derived,
the incorrect GEP is emitted. So, just cast pointer to derived type to
appropriate type with enough fields.

Fixes https://github.com/llvm/llvm-project/issues/60166

Diff Detail

Event Timeline

Fznamznon created this revision.Jan 25 2023, 4:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 25 2023, 4:42 AM
Fznamznon requested review of this revision.Jan 25 2023, 4:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 25 2023, 4:42 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Unit tests fail seems unrelated. I'm seeing the same test fail for a commit that is already in main https://github.com/llvm/llvm-project/commit/f1f583347d00aad378eb0128e72d3d2e8be5174b .

shafik added a subscriber: shafik.Jan 25 2023, 7:52 AM

Makes sense to me but I am not familiar with this area so I will let someone else who has more knowledge approve.

clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
95

nitpick: I have been using GH as a prefix for Github issues.

118

I think having a link to the github issue in the summary allows for the issue be closed automatically when you commit. Is this correct @aaron.ballman I have been doing this for a while and they get closed when I commit but maybe there is another mechanism involved.

I think having a link to the github issue in the summary allows for the issue be closed automatically when you commit. Is this correct @aaron.ballman I have been doing this for a while and they get closed when I commit but maybe there is another mechanism involved.

This works at least for GitHub pull requests, see https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue . We've been using this in a downstream project. I was hoping it works in the same way for commits, so added issue ID to a commit message.

Fznamznon updated this revision to Diff 492485.Jan 26 2023, 9:23 AM

Rebase and apply nit

I think having a link to the github issue in the summary allows for the issue be closed automatically when you commit. Is this correct @aaron.ballman I have been doing this for a while and they get closed when I commit but maybe there is another mechanism involved.

This works at least for GitHub pull requests, see https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue . We've been using this in a downstream project. I was hoping it works in the same way for commits, so added issue ID to a commit message.

Yes, this works the same way for commits here. I learned recently that folks appreciate a full link to the issue (Fixes https://github.com/llvm/llvm-project/issues/NNNN) instead of Fixes #NNNN because it makes it easier to traverse from the commit message to the github issue (and it will still automatically close the issue on commit), so you might consider changing that when you land the patch.

The changes look correct to me, but codegen is not my area of expertise, so adding some other codegen reviewers to double-check.

Fznamznon retitled this revision from Fix emission of consteval constructor of derived type to [clang][codegen] Fix emission of consteval constructor of derived type.Feb 8 2023, 3:59 AM

Ping.

I discovered that this patch also helps to fix crash reported in https://github.com/llvm/llvm-project/issues/59223 .

Fznamznon edited the summary of this revision. (Show Details)Feb 8 2023, 4:02 AM
aaron.ballman accepted this revision.Feb 8 2023, 6:27 AM

LGTM, but please add a release note about the issues this fixes.

This revision is now accepted and ready to land.Feb 8 2023, 6:27 AM
Fznamznon updated this revision to Diff 495851.Feb 8 2023, 7:31 AM

Rebase and add a release note