Skip to content

Commit ea31662

Browse files
authored
[clang] Add bitint classification for __builtin_classify_type (#72036)
See #71911
1 parent 3defe8f commit ea31662

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ Non-comprehensive list of changes in this release
219219
determined at runtime.
220220
* The ``__datasizeof`` keyword has been added. It is similar to ``sizeof``
221221
except that it returns the size of a type ignoring tail padding.
222+
* ``__builtin_classify_type()`` now classifies ``_BitInt`` values as the return value ``18``,
223+
to match GCC 14's behavior.
222224

223225
New Compiler Flags
224226
------------------

clang/lib/AST/ExprConstant.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11520,6 +11520,9 @@ enum class GCCTypeClass {
1152011520
// decay to pointer. (Prior to version 6 it was only used in C++ mode).
1152111521
// GCC reserves 15 for strings, but actually uses 5 (pointer) for string
1152211522
// literals.
11523+
// Lang = 16,
11524+
// OpaqueType = 17,
11525+
BitInt = 18
1152311526
};
1152411527

1152511528
/// EvaluateBuiltinClassifyType - Evaluate __builtin_classify_type the same way
@@ -11652,11 +11655,13 @@ EvaluateBuiltinClassifyType(QualType T, const LangOptions &LangOpts) {
1165211655
case Type::ObjCInterface:
1165311656
case Type::ObjCObjectPointer:
1165411657
case Type::Pipe:
11655-
case Type::BitInt:
1165611658
// GCC classifies vectors as None. We follow its lead and classify all
1165711659
// other types that don't fit into the regular classification the same way.
1165811660
return GCCTypeClass::None;
1165911661

11662+
case Type::BitInt:
11663+
return GCCTypeClass::BitInt;
11664+
1166011665
case Type::LValueReference:
1166111666
case Type::RValueReference:
1166211667
llvm_unreachable("invalid type for expression");

clang/test/Sema/builtin-classify-type.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ enum gcc_type_class {
1111
function_type_class, method_type_class,
1212
record_type_class, union_type_class,
1313
array_type_class, string_type_class,
14-
lang_type_class
14+
lang_type_class, opaque_type_class,
15+
bitint_type_class
1516
};
1617

1718
void foo(void) {
@@ -45,6 +46,7 @@ void foo(void) {
4546
vint32_t3 vt5;
4647
typedef _BitInt(64) vint64_t3 __attribute__((vector_size(16)));
4748
vint64_t3 vt6;
49+
_BitInt(16) bitint;
4850

4951
_Atomic int atomic_i;
5052
_Atomic double atomic_d;
@@ -70,6 +72,7 @@ void foo(void) {
7072
int a17[__builtin_classify_type(atomic_d) == real_type_class ? 1 : -1];
7173
int a18[__builtin_classify_type(complex_i) == complex_type_class ? 1 : -1];
7274
int a19[__builtin_classify_type(complex_d) == complex_type_class ? 1 : -1];
75+
int a20[__builtin_classify_type(bitint) == bitint_type_class ? 1 : -1];
7376
}
7477

7578
extern int (^p)(void);

clang/test/SemaCXX/builtin-classify-type.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ enum gcc_type_class {
1111
function_type_class, method_type_class,
1212
record_type_class, union_type_class,
1313
array_type_class, string_type_class,
14-
lang_type_class
14+
lang_type_class, opaque_type_class,
15+
bitint_type_class
1516
};
1617

1718
class cl {
@@ -42,6 +43,7 @@ void foo() {
4243
_Atomic double atomic_d;
4344
_Complex int complex_i;
4445
_Complex double complex_d;
46+
_BitInt(32) bitint;
4547

4648
int a1[__builtin_classify_type(f()) == void_type_class ? 1 : -1];
4749
int a2[__builtin_classify_type(i) == integer_type_class ? 1 : -1];
@@ -65,5 +67,6 @@ void foo() {
6567
int a20[__builtin_classify_type(atomic_d) == real_type_class ? 1 : -1];
6668
int a21[__builtin_classify_type(complex_i) == complex_type_class ? 1 : -1];
6769
int a22[__builtin_classify_type(complex_d) == complex_type_class ? 1 : -1];
70+
int a23[__builtin_classify_type(bitint) == bitint_type_class ? 1 : -1];
6871
}
6972

0 commit comments

Comments
 (0)