[clang] 1d65c35 - [clang] Reject `_Complex _BitInt` (#119402)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 12 03:19:52 PST 2024
Author: Mariya Podchishchaeva
Date: 2024-12-12T12:19:48+01:00
New Revision: 1d65c35ce16f1bc340649ac8319b34c833e23a1f
URL: https://github.com/llvm/llvm-project/commit/1d65c35ce16f1bc340649ac8319b34c833e23a1f
DIFF: https://github.com/llvm/llvm-project/commit/1d65c35ce16f1bc340649ac8319b34c833e23a1f.diff
LOG: [clang] Reject `_Complex _BitInt` (#119402)
The C standard doesn't require support for these types and Codegen for
these types is incorrect ATM.
See https://github.com/llvm/llvm-project/issues/119352
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/DeclSpec.cpp
clang/test/AST/ByteCode/complex.cpp
clang/test/CodeGenCXX/ext-int.cpp
clang/test/SemaCXX/ext-int.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6802c0c50b8f0c..ae57b84f9247c4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -61,6 +61,8 @@ code bases.
C/C++ Language Potentially Breaking Changes
-------------------------------------------
+- Clang now rejects ``_Complex _BitInt`` types.
+
C++ Specific Potentially Breaking Changes
-----------------------------------------
diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index ee237ffc4d2b99..47644680b720bf 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -1343,8 +1343,7 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) {
S.getLocForEndOfToken(getTypeSpecComplexLoc()),
" double");
TypeSpecType = TST_double; // _Complex -> _Complex double.
- } else if (TypeSpecType == TST_int || TypeSpecType == TST_char ||
- TypeSpecType == TST_bitint) {
+ } else if (TypeSpecType == TST_int || TypeSpecType == TST_char) {
// Note that this intentionally doesn't include _Complex _Bool.
if (!S.getLangOpts().CPlusPlus)
S.Diag(TSTLoc, diag::ext_integer_complex);
diff --git a/clang/test/AST/ByteCode/complex.cpp b/clang/test/AST/ByteCode/complex.cpp
index ee11c6214b70c5..2c0111c53d3bfe 100644
--- a/clang/test/AST/ByteCode/complex.cpp
+++ b/clang/test/AST/ByteCode/complex.cpp
@@ -146,11 +146,6 @@ constexpr _Complex int I3 = {15};
static_assert(__real(I3) == 15, "");
static_assert(__imag(I3) == 0, "");
-constexpr _Complex _BitInt(8) A = {4};
-static_assert(__real(A) == 4, "");
-static_assert(__imag(A) == 0, "");
-
-
constexpr _Complex double Doubles[4] = {{1.0, 2.0}};
static_assert(__real(Doubles[0]) == 1.0, "");
static_assert(__imag(Doubles[0]) == 2.0, "");
@@ -163,9 +158,6 @@ static_assert(__imag(Doubles[3]) == 0.0, "");
static_assert(~(0.5 + 1.5j) == (0.5 + -1.5j), "");
-static_assert(__extension__ __imag(A) == 0, "");
-static_assert(__imag(__extension__ A) == 0, "");
-
void func(void) {
__complex__ int arr;
_Complex int result;
diff --git a/clang/test/CodeGenCXX/ext-int.cpp b/clang/test/CodeGenCXX/ext-int.cpp
index 97b5d6ce16b880..f470398ec2095d 100644
--- a/clang/test/CodeGenCXX/ext-int.cpp
+++ b/clang/test/CodeGenCXX/ext-int.cpp
@@ -549,24 +549,6 @@ void Shift(_BitInt(28) Ext, _BitInt(65) LargeExt, int i) {
// CHECK: ashr i65 {{.+}}, %[[PROMO]]
}
-void ComplexTest(_Complex _BitInt(12) first, _Complex _BitInt(33) second) {
- // LIN: define{{.*}} void @_Z11ComplexTestCDB12_CDB33_
- // WIN: define dso_local void @"?ComplexTest@@YAXU?$_Complex at U?$_BitInt@$0M@@__clang@@@__clang@@U?$_Complex at U?$_BitInt@$0CB@@__clang@@@2@@Z"
- first + second;
- // CHECK: %[[FIRST_REALP:.+]] = getelementptr inbounds nuw { i12, i12 }, ptr %{{.+}}, i32 0, i32 0
- // CHECK: %[[FIRST_REAL:.+]] = load i12, ptr %[[FIRST_REALP]]
- // CHECK: %[[FIRST_IMAGP:.+]] = getelementptr inbounds nuw { i12, i12 }, ptr %{{.+}}, i32 0, i32 1
- // CHECK: %[[FIRST_IMAG:.+]] = load i12, ptr %[[FIRST_IMAGP]]
- // CHECK: %[[FIRST_REAL_CONV:.+]] = sext i12 %[[FIRST_REAL]]
- // CHECK: %[[FIRST_IMAG_CONV:.+]] = sext i12 %[[FIRST_IMAG]]
- // CHECK: %[[SECOND_REALP:.+]] = getelementptr inbounds nuw { i33, i33 }, ptr %{{.+}}, i32 0, i32 0
- // CHECK: %[[SECOND_REAL:.+]] = load i33, ptr %[[SECOND_REALP]]
- // CHECK: %[[SECOND_IMAGP:.+]] = getelementptr inbounds nuw { i33, i33 }, ptr %{{.+}}, i32 0, i32 1
- // CHECK: %[[SECOND_IMAG:.+]] = load i33, ptr %[[SECOND_IMAGP]]
- // CHECK: %[[REAL:.+]] = add i33 %[[FIRST_REAL_CONV]], %[[SECOND_REAL]]
- // CHECK: %[[IMAG:.+]] = add i33 %[[FIRST_IMAG_CONV]], %[[SECOND_IMAG]]
-}
-
typedef _BitInt(64) vint64_t16 __attribute__((vector_size(16)));
void VectorTest(vint64_t16 first, vint64_t16 second) {
// LIN: define{{.*}} void @_Z10VectorTestDv2_DB64_S0_(<2 x i64> %{{.+}}, <2 x i64> %{{.+}})
diff --git a/clang/test/SemaCXX/ext-int.cpp b/clang/test/SemaCXX/ext-int.cpp
index 000b871ccd3433..d974221e774a79 100644
--- a/clang/test/SemaCXX/ext-int.cpp
+++ b/clang/test/SemaCXX/ext-int.cpp
@@ -101,8 +101,10 @@ typedef _BitInt(37) __attribute__((vector_size(16))) VecTy4;
// expected-error at +1{{'_BitInt' vector element width must be a power of 2}}
typedef _BitInt(37) __attribute__((ext_vector_type(32))) OtherVecTy4;
-// Allow _Complex:
+// expected-error at +1{{'_Complex _BitInt' is invalid}}
_Complex _BitInt(3) Cmplx;
+// expected-error at +1{{'_Complex _BitInt' is invalid}}
+typedef _Complex _BitInt(3) Cmp;
// Reject cases of _Atomic:
// expected-error at +1{{_Atomic cannot be applied to integer type '_BitInt(4)'}}
More information about the cfe-commits
mailing list