[clang] [clang] Add bitint classification for __builtin_classify_type (PR #72036)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 16 00:35:24 PST 2023
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/72036
>From ed41b0889b6da62fa307888857ce185f516f3af1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Sat, 11 Nov 2023 18:44:13 +0100
Subject: [PATCH] [clang] Add bitint classification for __builtin_classify_type
See #71911
---
clang/docs/ReleaseNotes.rst | 2 ++
clang/lib/AST/ExprConstant.cpp | 7 ++++++-
clang/test/Sema/builtin-classify-type.c | 5 ++++-
clang/test/SemaCXX/builtin-classify-type.cpp | 5 ++++-
4 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ed1a978b5382d71..e030f97ab662fdb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -219,6 +219,8 @@ Non-comprehensive list of changes in this release
determined at runtime.
* The ``__datasizeof`` keyword has been added. It is similar to ``sizeof``
except that it returns the size of a type ignoring tail padding.
+* ``__builtin_classify_type()`` now classifies ``_BitInt`` values as the return value ``18``,
+ to match GCC 14's behavior.
New Compiler Flags
------------------
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 373972eb6cab11b..4fb444e3b9f7e1b 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11520,6 +11520,9 @@ enum class GCCTypeClass {
// decay to pointer. (Prior to version 6 it was only used in C++ mode).
// GCC reserves 15 for strings, but actually uses 5 (pointer) for string
// literals.
+ // Lang = 16,
+ // OpaqueType = 17,
+ BitInt = 18
};
/// EvaluateBuiltinClassifyType - Evaluate __builtin_classify_type the same way
@@ -11652,11 +11655,13 @@ EvaluateBuiltinClassifyType(QualType T, const LangOptions &LangOpts) {
case Type::ObjCInterface:
case Type::ObjCObjectPointer:
case Type::Pipe:
- case Type::BitInt:
// GCC classifies vectors as None. We follow its lead and classify all
// other types that don't fit into the regular classification the same way.
return GCCTypeClass::None;
+ case Type::BitInt:
+ return GCCTypeClass::BitInt;
+
case Type::LValueReference:
case Type::RValueReference:
llvm_unreachable("invalid type for expression");
diff --git a/clang/test/Sema/builtin-classify-type.c b/clang/test/Sema/builtin-classify-type.c
index a222ac8af0e32fd..9a4de34e823f231 100644
--- a/clang/test/Sema/builtin-classify-type.c
+++ b/clang/test/Sema/builtin-classify-type.c
@@ -11,7 +11,8 @@ enum gcc_type_class {
function_type_class, method_type_class,
record_type_class, union_type_class,
array_type_class, string_type_class,
- lang_type_class
+ lang_type_class, opaque_type_class,
+ bitint_type_class
};
void foo(void) {
@@ -45,6 +46,7 @@ void foo(void) {
vint32_t3 vt5;
typedef _BitInt(64) vint64_t3 __attribute__((vector_size(16)));
vint64_t3 vt6;
+ _BitInt(16) bitint;
_Atomic int atomic_i;
_Atomic double atomic_d;
@@ -70,6 +72,7 @@ void foo(void) {
int a17[__builtin_classify_type(atomic_d) == real_type_class ? 1 : -1];
int a18[__builtin_classify_type(complex_i) == complex_type_class ? 1 : -1];
int a19[__builtin_classify_type(complex_d) == complex_type_class ? 1 : -1];
+ int a20[__builtin_classify_type(bitint) == bitint_type_class ? 1 : -1];
}
extern int (^p)(void);
diff --git a/clang/test/SemaCXX/builtin-classify-type.cpp b/clang/test/SemaCXX/builtin-classify-type.cpp
index ebc81425e401f11..ed5430960001002 100644
--- a/clang/test/SemaCXX/builtin-classify-type.cpp
+++ b/clang/test/SemaCXX/builtin-classify-type.cpp
@@ -11,7 +11,8 @@ enum gcc_type_class {
function_type_class, method_type_class,
record_type_class, union_type_class,
array_type_class, string_type_class,
- lang_type_class
+ lang_type_class, opaque_type_class,
+ bitint_type_class
};
class cl {
@@ -42,6 +43,7 @@ void foo() {
_Atomic double atomic_d;
_Complex int complex_i;
_Complex double complex_d;
+ _BitInt(32) bitint;
int a1[__builtin_classify_type(f()) == void_type_class ? 1 : -1];
int a2[__builtin_classify_type(i) == integer_type_class ? 1 : -1];
@@ -65,5 +67,6 @@ void foo() {
int a20[__builtin_classify_type(atomic_d) == real_type_class ? 1 : -1];
int a21[__builtin_classify_type(complex_i) == complex_type_class ? 1 : -1];
int a22[__builtin_classify_type(complex_d) == complex_type_class ? 1 : -1];
+ int a23[__builtin_classify_type(bitint) == bitint_type_class ? 1 : -1];
}
More information about the cfe-commits
mailing list