This is an archive of the discontinued LLVM Phabricator instance.

[WIP] Add warning when zero-initializing a union if its first member is not is largest
Needs ReviewPublic

Authored by leonardchan on Sep 24 2019, 10:36 AM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

This may result in the entire union not being initialized. For example:

union U {
  uint32_t x;
  uint64_t y;
};

void func() {
  U u = {};
  ...
}

Some might assume that U u = {} zero-initializes the whole union whereas only the bits that compose U.x are zero-inited.

Oddly enough (mostly from what I've seen personally), this seems to only matter in the case we use -ftrivial-auto-var-init=pattern where llvm undefs are replaced with non-zero values. In any normal case, it seems that these undefs just get lowered to zeros.

See: http://lists.llvm.org/pipermail/cfe-dev/2019-September/063383.html

Diff Detail

Event Timeline

leonardchan created this revision.Sep 24 2019, 10:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 24 2019, 10:36 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript