Author: Richard Sandiford Date: 2020-03-25T10:52:43Z New Revision: 856bdd01fd65002d8d88b491bbff53648b6002c1
URL: https://github.com/llvm/llvm-project/commit/856bdd01fd65002d8d88b491bbff53648b6002c1 DIFF: https://github.com/llvm/llvm-project/commit/856bdd01fd65002d8d88b491bbff53648b6002c1.diff LOG: [Sema][SVE] Allow casting SVE types to themselves in C Casts from an SVE type to itself aren't very useful, but they are supposed to be valid, and could occur in things like macro expansions. Such casts already work for C++ and are tested by sizeless-1.cpp. This patch makes them work for C too. Differential Revision: https://reviews.llvm.org/D76694 Added: Modified: clang/lib/Sema/SemaCast.cpp clang/test/Sema/sizeless-1.c Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp index 2d0a2298329e..73f9a86c12e3 100644 --- a/clang/lib/Sema/SemaCast.cpp +++ b/clang/lib/Sema/SemaCast.cpp @@ -2652,6 +2652,13 @@ void CastOperation::CheckCStyleCast() { return; } + // Allow casting a sizeless built-in type to itself. + if (DestType->isSizelessBuiltinType() && + Self.Context.hasSameUnqualifiedType(DestType, SrcType)) { + Kind = CK_NoOp; + return; + } + if (!DestType->isScalarType() && !DestType->isVectorType()) { const RecordType *DestRecordTy = DestType->getAs<RecordType>(); diff --git a/clang/test/Sema/sizeless-1.c b/clang/test/Sema/sizeless-1.c index a2ac9075347d..8fe8e7b30cf6 100644 --- a/clang/test/Sema/sizeless-1.c +++ b/clang/test/Sema/sizeless-1.c @@ -108,6 +108,8 @@ void func(int sel) { sel = local_int8; // expected-error {{assigning to 'int' from incompatible type 'svint8_t'}} + local_int8 = (svint8_t)local_int8; + local_int8 = (const svint8_t)local_int8; local_int8 = (svint8_t)local_int16; // expected-error {{used type 'svint8_t' (aka '__SVInt8_t') where arithmetic or pointer type is required}} local_int8 = (svint8_t)0; // expected-error {{used type 'svint8_t' (aka '__SVInt8_t') where arithmetic or pointer type is required}} sel = (int)local_int8; // expected-error {{operand of type 'svint8_t' (aka '__SVInt8_t') where arithmetic or pointer type is required}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits