This is an archive of the discontinued LLVM Phabricator instance.

[clang][dataflow] Fix crash when struct with inheritance is initialized with InitExpr
AbandonedPublic

Authored by kinu on Aug 30 2023, 11:37 PM.

Details

Reviewers
NoQ
Summary

This fix still leaves inherited fields from base classes unpopulated
(even if they are accessed in the code), and might cause false
positives, but fix crashes that could happen because of source /
destination mismatches.

More details:
When a struct is declared, the Record value of the struct is usually
initialized with Environment::createValue() which internally calls
getObjectFields() (via filtering in DACtx::getModeledFields())
to collects all fields from the current and base classes.

However, if a struct is initialized with InitListExpr, its fields are
initialized based on what is returned by getFieldsForInitListExpr(),
which doesn't collect fields from base classes. Moreover, if the base
classes have their own InitListExpr, those InitListExpr's are also
visited, but the field values and locations that are initialized by
them are not merged when the child class's InitListExpr is visited.

This change adds a new getChildOrError() method in StorageLocation
and uses it in copyRecord(), so that only the fields that exist in
both record can be copied. A follow-up change can add more proper fix
around InitListExpr.

Diff Detail

Event Timeline

kinu created this revision.Aug 30 2023, 11:37 PM
Herald added a project: Restricted Project. · View Herald Transcript
kinu requested review of this revision.Aug 30 2023, 11:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 30 2023, 11:37 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
kinu updated this revision to Diff 554906.Aug 30 2023, 11:40 PM

updated comment

kinu edited the summary of this revision. (Show Details)Aug 30 2023, 11:41 PM
kinu retitled this revision from Fix crash when struct with inheritance is initialized with InitExpr to [clang][dataflow] Fix crash when struct with inheritance is initialized with InitExpr.
kinu abandoned this revision.Sep 4 2023, 9:55 AM