diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-10-07 02:45:12 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-10-07 02:45:12 +0000 |
commit | 74ce7112c3fccccfa7edb134c0a2d8fe2aab462f (patch) | |
tree | a1a3033a88578775d8ad04388ae2bcbc9c00c999 /clang | |
parent | a30730f6904916e8c97f6fd934bf493e999cb1e4 (diff) | |
download | bcm5719-llvm-74ce7112c3fccccfa7edb134c0a2d8fe2aab462f.tar.gz bcm5719-llvm-74ce7112c3fccccfa7edb134c0a2d8fe2aab462f.zip |
Fix behavior of __builtin_bit_cast when the From and To types are the
same.
We were missing the lvalue-to-rvalue conversion entirely in this case,
and in fact still need the full CK_LValueToRValueBitCast conversion to
perform a load with no TBAA.
llvm-svn: 373874
Diffstat (limited to 'clang')
-rw-r--r-- | clang/include/clang/AST/OperationKinds.def | 5 | ||||
-rw-r--r-- | clang/lib/Sema/SemaCast.cpp | 5 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/builtin-bit-cast-no-tbaa.cpp | 5 | ||||
-rw-r--r-- | clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp | 16 |
4 files changed, 24 insertions, 7 deletions
diff --git a/clang/include/clang/AST/OperationKinds.def b/clang/include/clang/AST/OperationKinds.def index 9af92c1ae7f..f29664e8eb3 100644 --- a/clang/include/clang/AST/OperationKinds.def +++ b/clang/include/clang/AST/OperationKinds.def @@ -66,8 +66,9 @@ CAST_OPERATION(BitCast) /// bool b; reinterpret_cast<char&>(b) = 'a'; CAST_OPERATION(LValueBitCast) -/// CK_LValueToRValueBitCast - A conversion that causes us to reinterpret an -/// lvalue as an rvalue of a different type. Created by __builtin_bit_cast. +/// CK_LValueToRValueBitCast - A conversion that causes us to reinterpret the +/// object representation of an lvalue as an rvalue. Created by +/// __builtin_bit_cast. CAST_OPERATION(LValueToRValueBitCast) /// CK_LValueToRValue - A conversion which causes the extraction of diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp index 71e5e8e4286..8c6abc448d9 100644 --- a/clang/lib/Sema/SemaCast.cpp +++ b/clang/lib/Sema/SemaCast.cpp @@ -2835,11 +2835,6 @@ void CastOperation::CheckBuiltinBitCast() { return; } - if (Self.Context.hasSameUnqualifiedType(DestType, SrcType)) { - Kind = CK_NoOp; - return; - } - Kind = CK_LValueToRValueBitCast; } diff --git a/clang/test/CodeGenCXX/builtin-bit-cast-no-tbaa.cpp b/clang/test/CodeGenCXX/builtin-bit-cast-no-tbaa.cpp index 3f0e490a5f9..b26e519bee3 100644 --- a/clang/test/CodeGenCXX/builtin-bit-cast-no-tbaa.cpp +++ b/clang/test/CodeGenCXX/builtin-bit-cast-no-tbaa.cpp @@ -15,5 +15,10 @@ void test_scalar2() { // CHECK: load i32, i32* {{.*}}, align 4, !tbaa ![[MAY_ALIAS_TBAA]] } +int test_same_type(int &r) { + // CHECK: load i32, i32* {{.*}}, align 4, !tbaa ![[MAY_ALIAS_TBAA]] + return __builtin_bit_cast(int, r); +} + // CHECK: ![[CHAR_TBAA:.*]] = !{!"omnipotent char", {{.*}}, i64 0} // CHECK: ![[MAY_ALIAS_TBAA]] = !{![[CHAR_TBAA]], ![[CHAR_TBAA]], i64 0} diff --git a/clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp b/clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp index 0a12e7eebe4..06771f8f325 100644 --- a/clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp +++ b/clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp @@ -381,3 +381,19 @@ constexpr bool test_pad_buffer() { return x.a == z.a && x.b == z.b; } static_assert(test_pad_buffer()); + +constexpr unsigned char identity1a = 42; +constexpr unsigned char identity1b = __builtin_bit_cast(unsigned char, identity1a); +static_assert(identity1b == 42); + +struct IdentityInStruct { + unsigned char n; +}; +constexpr IdentityInStruct identity2a = {42}; +constexpr unsigned char identity2b = __builtin_bit_cast(unsigned char, identity2a.n); + +union IdentityInUnion { + unsigned char n; +}; +constexpr IdentityInUnion identity3a = {42}; +constexpr unsigned char identity3b = __builtin_bit_cast(unsigned char, identity3a.n); |