[PATCH] D140696: [clang][dataflow] Treat unions as structs.

Dmitri Gribenko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 29 14:55:57 PST 2022


gribozavr2 added a comment.

> With this change, unions are modeled exactly as structs (as far as I can tell), which is unsound.

Modeling just the storage of the union (but not the value) is sound. The first revision of the patch was a targeted fix that allowed us to continue maintaining the invariant that `this` is always modeled with a non-null `StorageLocation`.

About modeling values of unions as structs (and members of unions as struct members), I can think of some unsoundness but nothing that affects what we are modeling now (e.g., pointers to two struct members should compare unequal, but pointers to two union members should compare equal). If the code writes to one union member, but reads from the other, code has UB. So it generally shouldn't be a problem, for the purpose of modeling, to model more storage in the union that a program free of union-related UB should never use. WDYT?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140696/new/

https://reviews.llvm.org/D140696



More information about the cfe-commits mailing list