Re: r309058 - [CodeGen] Correctly model std::byte's aliasing properties

2017-07-26 Thread Hans Wennborg via cfe-commits
r309135. Thanks!

On Wed, Jul 26, 2017 at 9:29 AM, Richard Smith  wrote:
> I think so too :)
>
> On 26 Jul 2017 9:23 am, "Hans Wennborg via cfe-commits"
>  wrote:
>
> Yes, I think so. Richard, what say you?
>
> On Tue, Jul 25, 2017 at 4:41 PM, David Majnemer via cfe-commits
>  wrote:
>> Should this go into 5.0 ?
>>
>> On Tue, Jul 25, 2017 at 4:33 PM, David Majnemer via cfe-commits
>>  wrote:
>>>
>>> Author: majnemer
>>> Date: Tue Jul 25 16:33:58 2017
>>> New Revision: 309058
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=309058=rev
>>> Log:
>>> [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
>>>
>>> Added:
>>> cfe/trunk/test/CodeGenCXX/std-byte.cpp
>>> Modified:
>>> cfe/trunk/include/clang/AST/Type.h
>>> cfe/trunk/lib/AST/Type.cpp
>>> cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r309058 - [CodeGen] Correctly model std::byte's aliasing properties

2017-07-26 Thread Richard Smith via cfe-commits
I think so too :)

On 26 Jul 2017 9:23 am, "Hans Wennborg via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:

Yes, I think so. Richard, what say you?

On Tue, Jul 25, 2017 at 4:41 PM, David Majnemer via cfe-commits
 wrote:
> Should this go into 5.0 ?
>
> On Tue, Jul 25, 2017 at 4:33 PM, David Majnemer via cfe-commits
>  wrote:
>>
>> Author: majnemer
>> Date: Tue Jul 25 16:33:58 2017
>> New Revision: 309058
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=309058=rev
>> Log:
>> [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
>>
>> Added:
>> cfe/trunk/test/CodeGenCXX/std-byte.cpp
>> Modified:
>> cfe/trunk/include/clang/AST/Type.h
>> cfe/trunk/lib/AST/Type.cpp
>> cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r309058 - [CodeGen] Correctly model std::byte's aliasing properties

2017-07-26 Thread Hans Wennborg via cfe-commits
Yes, I think so. Richard, what say you?

On Tue, Jul 25, 2017 at 4:41 PM, David Majnemer via cfe-commits
 wrote:
> Should this go into 5.0 ?
>
> On Tue, Jul 25, 2017 at 4:33 PM, David Majnemer via cfe-commits
>  wrote:
>>
>> Author: majnemer
>> Date: Tue Jul 25 16:33:58 2017
>> New Revision: 309058
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=309058=rev
>> Log:
>> [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
>>
>> Added:
>> cfe/trunk/test/CodeGenCXX/std-byte.cpp
>> Modified:
>> cfe/trunk/include/clang/AST/Type.h
>> cfe/trunk/lib/AST/Type.cpp
>> cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r309058 - [CodeGen] Correctly model std::byte's aliasing properties

2017-07-25 Thread David Majnemer via cfe-commits
Should this go into 5.0 ?

On Tue, Jul 25, 2017 at 4:33 PM, David Majnemer via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: majnemer
> Date: Tue Jul 25 16:33:58 2017
> New Revision: 309058
>
> URL: http://llvm.org/viewvc/llvm-project?rev=309058=rev
> Log:
> [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
>
> Added:
> cfe/trunk/test/CodeGenCXX/std-byte.cpp
> Modified:
> cfe/trunk/include/clang/AST/Type.h
> cfe/trunk/lib/AST/Type.cpp
> cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
>
> Modified: cfe/trunk/include/clang/AST/Type.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/AST/Type.h?rev=309058=309057=309058=diff
> 
> ==
> --- cfe/trunk/include/clang/AST/Type.h (original)
> +++ cfe/trunk/include/clang/AST/Type.h Tue Jul 25 16:33:58 2017
> @@ -1752,6 +1752,7 @@ public:
>bool isTemplateTypeParmType() const;  // C++ template type
> parameter
>bool isNullPtrType() const;   // C++11 std::nullptr_t
>bool isAlignValT() const; // C++17 std::align_val_t
> +  bool isStdByteType() const;   // C++17 std::byte
>bool isAtomicType() const;// C11 _Atomic()
>
>  #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
>
> Modified: cfe/trunk/lib/AST/Type.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/
> Type.cpp?rev=309058=309057=309058=diff
> 
> ==
> --- cfe/trunk/lib/AST/Type.cpp (original)
> +++ cfe/trunk/lib/AST/Type.cpp Tue Jul 25 16:33:58 2017
> @@ -2313,6 +2313,15 @@ bool Type::isAlignValT() const {
>return false;
>  }
>
> +bool Type::isStdByteType() const {
> +  if (auto *ET = getAs()) {
> +auto *II = ET->getDecl()->getIdentifier();
> +if (II && II->isStr("byte") && ET->getDecl()->isInStdNamespace())
> +  return true;
> +  }
> +  return false;
> +}
> +
>  bool Type::isPromotableIntegerType() const {
>if (const BuiltinType *BT = getAs())
>  switch (BT->getKind()) {
>
> Modified: cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/
> CodeGenTBAA.cpp?rev=309058=309057=309058=diff
> 
> ==
> --- cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp Tue Jul 25 16:33:58 2017
> @@ -139,6 +139,12 @@ CodeGenTBAA::getTBAAInfo(QualType QTy) {
>  }
>}
>
> +  // C++1z [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."
> +  if (Ty->isStdByteType())
> +return MetadataCache[Ty] = getChar();
> +
>// Handle pointers.
>// TODO: Implement C++'s type "similarity" and consider dis-"similar"
>// pointers distinct.
>
> Added: cfe/trunk/test/CodeGenCXX/std-byte.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> CodeGenCXX/std-byte.cpp?rev=309058=auto
> 
> ==
> --- cfe/trunk/test/CodeGenCXX/std-byte.cpp (added)
> +++ cfe/trunk/test/CodeGenCXX/std-byte.cpp Tue Jul 25 16:33:58 2017
> @@ -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:!.*]], 

r309058 - [CodeGen] Correctly model std::byte's aliasing properties

2017-07-25 Thread David Majnemer via cfe-commits
Author: majnemer
Date: Tue Jul 25 16:33:58 2017
New Revision: 309058

URL: http://llvm.org/viewvc/llvm-project?rev=309058=rev
Log:
[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

Added:
cfe/trunk/test/CodeGenCXX/std-byte.cpp
Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=309058=309057=309058=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Tue Jul 25 16:33:58 2017
@@ -1752,6 +1752,7 @@ public:
   bool isTemplateTypeParmType() const;  // C++ template type parameter
   bool isNullPtrType() const;   // C++11 std::nullptr_t
   bool isAlignValT() const; // C++17 std::align_val_t
+  bool isStdByteType() const;   // C++17 std::byte
   bool isAtomicType() const;// C11 _Atomic()
 
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \

Modified: cfe/trunk/lib/AST/Type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=309058=309057=309058=diff
==
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Tue Jul 25 16:33:58 2017
@@ -2313,6 +2313,15 @@ bool Type::isAlignValT() const {
   return false;
 }
 
+bool Type::isStdByteType() const {
+  if (auto *ET = getAs()) {
+auto *II = ET->getDecl()->getIdentifier();
+if (II && II->isStr("byte") && ET->getDecl()->isInStdNamespace())
+  return true;
+  }
+  return false;
+}
+
 bool Type::isPromotableIntegerType() const {
   if (const BuiltinType *BT = getAs())
 switch (BT->getKind()) {

Modified: cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp?rev=309058=309057=309058=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp Tue Jul 25 16:33:58 2017
@@ -139,6 +139,12 @@ CodeGenTBAA::getTBAAInfo(QualType QTy) {
 }
   }
 
+  // C++1z [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."
+  if (Ty->isStdByteType())
+return MetadataCache[Ty] = getChar();
+
   // Handle pointers.
   // TODO: Implement C++'s type "similarity" and consider dis-"similar"
   // pointers distinct.

Added: cfe/trunk/test/CodeGenCXX/std-byte.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/std-byte.cpp?rev=309058=auto
==
--- cfe/trunk/test/CodeGenCXX/std-byte.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/std-byte.cpp Tue Jul 25 16:33:58 2017
@@ -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]]


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits