Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@ Improvements to Clang's diagnostics

- Clang now diagnoses ``[[deprecated]]`` attribute usage on local variables (#GH90073).

- Improved diagnostic message for ``__builtin_bit_cast`` size mismatch (#GH115870).

Improvements to Clang's time-trace
----------------------------------

Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -12354,7 +12354,7 @@ def err_preserve_enum_value_not_const: Error<
def err_bit_cast_non_trivially_copyable : Error<
"__builtin_bit_cast %select{source|destination}0 type must be trivially copyable">;
def err_bit_cast_type_size_mismatch : Error<
"__builtin_bit_cast source size does not equal destination size (%0 vs %1)">;
"size of '__builtin_bit_cast' source type %0 does not match destination type %1 (%2 vs %3 bytes)">;

// SYCL-specific diagnostics
def warn_sycl_kernel_num_of_template_params : Warning<
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaCast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3283,7 +3283,8 @@ void CastOperation::CheckBuiltinBitCast() {
CharUnits SourceSize = Self.Context.getTypeSizeInChars(SrcType);
if (DestSize != SourceSize) {
Self.Diag(OpRange.getBegin(), diag::err_bit_cast_type_size_mismatch)
<< (int)SourceSize.getQuantity() << (int)DestSize.getQuantity();
<< SrcType << DestType << (int)SourceSize.getQuantity()
<< (int)DestSize.getQuantity();
SrcExpr = ExprError();
return;
}
Expand Down
4 changes: 2 additions & 2 deletions clang/test/AST/ByteCode/builtin-bit-cast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ typedef bool bool32 __attribute__((ext_vector_type(32)));
typedef bool bool128 __attribute__((ext_vector_type(128)));

static_assert(bit_cast<unsigned char>(bool8{1,0,1,0,1,0,1,0}) == (LITTLE_END ? 0x55 : 0xAA), "");
constexpr bool8 b8 = __builtin_bit_cast(bool8, 0x55); // both-error {{__builtin_bit_cast source size does not equal destination size (4 vs 1)}}
constexpr bool8 b8 = __builtin_bit_cast(bool8, 0x55); // both-error {{'__builtin_bit_cast' source type 'int' does not match destination type 'bool8' (vector of 8 'bool' values) (4 vs 1 bytes)}}
#if 0
static_assert(check_round_trip<bool8>(static_cast<unsigned char>(0)), "");
static_assert(check_round_trip<bool8>(static_cast<unsigned char>(1)), "");
Expand Down Expand Up @@ -535,5 +535,5 @@ namespace test_complex {
static_assert(TF.A == 1.0f && TF.B == 2.0f);

constexpr double D = __builtin_bit_cast(double, test_float_complex);
constexpr int M = __builtin_bit_cast(int, test_int_complex); // both-error {{__builtin_bit_cast source size does not equal destination size}}
constexpr int M = __builtin_bit_cast(int, test_int_complex); // both-error {{size of '__builtin_bit_cast' source type 'const _Complex unsigned int' does not match destination type 'int' (8 vs 4 bytes)}}
}
2 changes: 1 addition & 1 deletion clang/test/SemaCXX/builtin-bit-cast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void test1() {

void test2() {
constexpr int i = 0;
// expected-error@+1{{__builtin_bit_cast source size does not equal destination size (4 vs 1)}}
// expected-error@+1{{size of '__builtin_bit_cast' source type 'const int' does not match destination type 'char' (4 vs 1 bytes)}}
constexpr char c = __builtin_bit_cast(char, i);
}

Expand Down
2 changes: 1 addition & 1 deletion clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,5 +525,5 @@ namespace test_complex {
static_assert(TF.A == 1.0f && TF.B == 2.0f);

constexpr double D = __builtin_bit_cast(double, test_float_complex);
constexpr int M = __builtin_bit_cast(int, test_int_complex); // expected-error {{__builtin_bit_cast source size does not equal destination size}}
constexpr int M = __builtin_bit_cast(int, test_int_complex); // expected-error {{size of '__builtin_bit_cast' source type 'const _Complex unsigned int' does not match destination type 'int' (8 vs 4 bytes)}}
}
Loading