This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Implicitly apply the may_alias attribute to std::byte
ClosedPublic

Authored by majnemer on Jul 24 2017, 4:58 PM.

Details

Diff Detail

Repository
rL LLVM

Event Timeline

majnemer created this revision.Jul 24 2017, 4:58 PM
rsmith edited edge metadata.Jul 24 2017, 6:02 PM

I would prefer to handle std::byte explicitly in the places where it matters, rather than adding an attribute to it and otherwise treating it like any other enumeration. We're going to want to be able to identify std::byte for warning emission and probably other codegen purposes too -- it's more a new fundamental type that happens to be defined in the library (like std::nullptr_t) than a type that just happens to be mayalias. Maybe a Type::is[Std]Byte, analogous to Type::isAlignValT?

As far as I can see, nowhere in Clang cares about MayAliasAttr on enums other than CodeGenTBAA.cpp.

majnemer updated this revision to Diff 108105.Jul 25 2017, 10:03 AM
  • Address review feedback.
Quuxplusone added inline comments.
test/CodeGenCXX/std-byte.cpp
7 ↗(On Diff #108105)

Would it be worth adding an explicit test that ::byte, ::my::byte, ::my::std::byte are or are not handled in the same way?

majnemer updated this revision to Diff 108166.Jul 25 2017, 3:20 PM
  • Address review comments
majnemer marked an inline comment as done.Jul 25 2017, 3:20 PM
rsmith accepted this revision.Jul 25 2017, 4:24 PM

LGTM with a tweaked comment. Thanks!

lib/CodeGen/CodeGenTBAA.cpp
88–90 ↗(On Diff #108166)

[basic.lval]p10: "If a program attempts to access the stored value of an object through a glvalue of other than one of the following types the behavior is undefined: [...] a char, unsigned char, or std::byte type."

... is the relevant quotation for the purpose of aliasing.

This revision is now accepted and ready to land.Jul 25 2017, 4:24 PM
This revision was automatically updated to reflect the committed changes.