Skip to content

Commit 1d65c35

Browse files
authored
[clang] Reject _Complex _BitInt (#119402)
The C standard doesn't require support for these types and Codegen for these types is incorrect ATM. See #119352
1 parent a480d51 commit 1d65c35

File tree

5 files changed

+6
-29
lines changed

5 files changed

+6
-29
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ code bases.
6161
C/C++ Language Potentially Breaking Changes
6262
-------------------------------------------
6363

64+
- Clang now rejects ``_Complex _BitInt`` types.
65+
6466
C++ Specific Potentially Breaking Changes
6567
-----------------------------------------
6668

clang/lib/Sema/DeclSpec.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,8 +1343,7 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) {
13431343
S.getLocForEndOfToken(getTypeSpecComplexLoc()),
13441344
" double");
13451345
TypeSpecType = TST_double; // _Complex -> _Complex double.
1346-
} else if (TypeSpecType == TST_int || TypeSpecType == TST_char ||
1347-
TypeSpecType == TST_bitint) {
1346+
} else if (TypeSpecType == TST_int || TypeSpecType == TST_char) {
13481347
// Note that this intentionally doesn't include _Complex _Bool.
13491348
if (!S.getLangOpts().CPlusPlus)
13501349
S.Diag(TSTLoc, diag::ext_integer_complex);

clang/test/AST/ByteCode/complex.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,6 @@ constexpr _Complex int I3 = {15};
146146
static_assert(__real(I3) == 15, "");
147147
static_assert(__imag(I3) == 0, "");
148148

149-
constexpr _Complex _BitInt(8) A = {4};
150-
static_assert(__real(A) == 4, "");
151-
static_assert(__imag(A) == 0, "");
152-
153-
154149
constexpr _Complex double Doubles[4] = {{1.0, 2.0}};
155150
static_assert(__real(Doubles[0]) == 1.0, "");
156151
static_assert(__imag(Doubles[0]) == 2.0, "");
@@ -163,9 +158,6 @@ static_assert(__imag(Doubles[3]) == 0.0, "");
163158

164159
static_assert(~(0.5 + 1.5j) == (0.5 + -1.5j), "");
165160

166-
static_assert(__extension__ __imag(A) == 0, "");
167-
static_assert(__imag(__extension__ A) == 0, "");
168-
169161
void func(void) {
170162
__complex__ int arr;
171163
_Complex int result;

clang/test/CodeGenCXX/ext-int.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -549,24 +549,6 @@ void Shift(_BitInt(28) Ext, _BitInt(65) LargeExt, int i) {
549549
// CHECK: ashr i65 {{.+}}, %[[PROMO]]
550550
}
551551

552-
void ComplexTest(_Complex _BitInt(12) first, _Complex _BitInt(33) second) {
553-
// LIN: define{{.*}} void @_Z11ComplexTestCDB12_CDB33_
554-
// WIN: define dso_local void @"?ComplexTest@@YAXU?$_Complex@U?$_BitInt@$0M@@__clang@@@__clang@@U?$_Complex@U?$_BitInt@$0CB@@__clang@@@2@@Z"
555-
first + second;
556-
// CHECK: %[[FIRST_REALP:.+]] = getelementptr inbounds nuw { i12, i12 }, ptr %{{.+}}, i32 0, i32 0
557-
// CHECK: %[[FIRST_REAL:.+]] = load i12, ptr %[[FIRST_REALP]]
558-
// CHECK: %[[FIRST_IMAGP:.+]] = getelementptr inbounds nuw { i12, i12 }, ptr %{{.+}}, i32 0, i32 1
559-
// CHECK: %[[FIRST_IMAG:.+]] = load i12, ptr %[[FIRST_IMAGP]]
560-
// CHECK: %[[FIRST_REAL_CONV:.+]] = sext i12 %[[FIRST_REAL]]
561-
// CHECK: %[[FIRST_IMAG_CONV:.+]] = sext i12 %[[FIRST_IMAG]]
562-
// CHECK: %[[SECOND_REALP:.+]] = getelementptr inbounds nuw { i33, i33 }, ptr %{{.+}}, i32 0, i32 0
563-
// CHECK: %[[SECOND_REAL:.+]] = load i33, ptr %[[SECOND_REALP]]
564-
// CHECK: %[[SECOND_IMAGP:.+]] = getelementptr inbounds nuw { i33, i33 }, ptr %{{.+}}, i32 0, i32 1
565-
// CHECK: %[[SECOND_IMAG:.+]] = load i33, ptr %[[SECOND_IMAGP]]
566-
// CHECK: %[[REAL:.+]] = add i33 %[[FIRST_REAL_CONV]], %[[SECOND_REAL]]
567-
// CHECK: %[[IMAG:.+]] = add i33 %[[FIRST_IMAG_CONV]], %[[SECOND_IMAG]]
568-
}
569-
570552
typedef _BitInt(64) vint64_t16 __attribute__((vector_size(16)));
571553
void VectorTest(vint64_t16 first, vint64_t16 second) {
572554
// LIN: define{{.*}} void @_Z10VectorTestDv2_DB64_S0_(<2 x i64> %{{.+}}, <2 x i64> %{{.+}})

clang/test/SemaCXX/ext-int.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ typedef _BitInt(37) __attribute__((vector_size(16))) VecTy4;
101101
// expected-error@+1{{'_BitInt' vector element width must be a power of 2}}
102102
typedef _BitInt(37) __attribute__((ext_vector_type(32))) OtherVecTy4;
103103

104-
// Allow _Complex:
104+
// expected-error@+1{{'_Complex _BitInt' is invalid}}
105105
_Complex _BitInt(3) Cmplx;
106+
// expected-error@+1{{'_Complex _BitInt' is invalid}}
107+
typedef _Complex _BitInt(3) Cmp;
106108

107109
// Reject cases of _Atomic:
108110
// expected-error@+1{{_Atomic cannot be applied to integer type '_BitInt(4)'}}

0 commit comments

Comments
 (0)