diff options
author | Hans Wennborg <hans@hanshq.net> | 2017-07-26 16:35:53 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2017-07-26 16:35:53 +0000 |
commit | 7a0666d0f312ee33dba0935018e7b758b89d202c (patch) | |
tree | a2356834a765655df4ad2f5290c6400ab8b59f69 /test/CodeGenCXX | |
parent | 3378e4c41b473dcb573f8d7c99fc15eb8e855428 (diff) |
Merging r309058:
------------------------------------------------------------------------
r309058 | majnemer | 2017-07-25 16:33:58 -0700 (Tue, 25 Jul 2017) | 9 lines
[CodeGen] Correctly model std::byte's aliasing properties
std::byte, when defined as an enum, needs to be given special treatment
with regards to its aliasing properties. An array of std::byte is
allowed to be used as storage for other types.
This fixes PR33916.
Differential Revision: https://reviews.llvm.org/D35824
------------------------------------------------------------------------
git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_50@309135 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGenCXX')
-rw-r--r-- | test/CodeGenCXX/std-byte.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/CodeGenCXX/std-byte.cpp b/test/CodeGenCXX/std-byte.cpp new file mode 100644 index 0000000000..a3cc634221 --- /dev/null +++ b/test/CodeGenCXX/std-byte.cpp @@ -0,0 +1,41 @@ +// RUN: %clang_cc1 -std=c++1z -Werror -triple i386-unknown-unknown -emit-llvm -O1 -disable-llvm-passes -o - %s | FileCheck %s + +// std::byte should be considered equivalent to char for aliasing. + +namespace std { +enum byte : unsigned char {}; +} + +// CHECK-LABEL: define void @test0( +extern "C" void test0(std::byte *sb, int *i) { + // CHECK: store i8 0, i8* %{{.*}} !tbaa [[TAG_CHAR:!.*]] + *sb = std::byte{0}; + + // CHECK: store i32 1, i32* %{{.*}} !tbaa [[TAG_INT:!.*]] + *i = 1; +} + +enum byte : unsigned char {}; +namespace my { +enum byte : unsigned char {}; +namespace std { +enum byte : unsigned char {}; +} // namespace std +} // namespace my + +// Make sure we don't get confused with other enums named 'byte'. + +// CHECK-LABEL: define void @test1( +extern "C" void test1(::byte *b, ::my::byte *mb, ::my::std::byte *msb) { + *b = ::byte{0}; + *mb = ::my::byte{0}; + *msb = ::my::std::byte{0}; + // CHECK-NOT: store i8 0, i8* %{{.*}} !tbaa [[TAG_CHAR]] +} + +// CHECK: !"any pointer", [[TYPE_CHAR:!.*]], +// CHECK: [[TYPE_CHAR]] = !{!"omnipotent char", [[TAG_CXX_TBAA:!.*]], +// CHECK: [[TAG_CXX_TBAA]] = !{!"Simple C++ TBAA"} +// CHECK: [[TAG_CHAR]] = !{[[TYPE_CHAR:!.*]], [[TYPE_CHAR]], i64 0} +// CHECK: [[TAG_INT]] = !{[[TYPE_INT:!.*]], [[TYPE_INT]], i64 0} +// CHECK: [[TYPE_INT]] = !{!"int", [[TYPE_CHAR]] |