Skip to content

Commit 856bdd0

Browse files
committed
[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
1 parent 578fb25 commit 856bdd0

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

clang/lib/Sema/SemaCast.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,6 +2652,13 @@ void CastOperation::CheckCStyleCast() {
26522652
return;
26532653
}
26542654

2655+
// Allow casting a sizeless built-in type to itself.
2656+
if (DestType->isSizelessBuiltinType() &&
2657+
Self.Context.hasSameUnqualifiedType(DestType, SrcType)) {
2658+
Kind = CK_NoOp;
2659+
return;
2660+
}
2661+
26552662
if (!DestType->isScalarType() && !DestType->isVectorType()) {
26562663
const RecordType *DestRecordTy = DestType->getAs<RecordType>();
26572664

clang/test/Sema/sizeless-1.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ void func(int sel) {
108108

109109
sel = local_int8; // expected-error {{assigning to 'int' from incompatible type 'svint8_t'}}
110110

111+
local_int8 = (svint8_t)local_int8;
112+
local_int8 = (const svint8_t)local_int8;
111113
local_int8 = (svint8_t)local_int16; // expected-error {{used type 'svint8_t' (aka '__SVInt8_t') where arithmetic or pointer type is required}}
112114
local_int8 = (svint8_t)0; // expected-error {{used type 'svint8_t' (aka '__SVInt8_t') where arithmetic or pointer type is required}}
113115
sel = (int)local_int8; // expected-error {{operand of type 'svint8_t' (aka '__SVInt8_t') where arithmetic or pointer type is required}}

0 commit comments

Comments
 (0)