Skip to content

[clang] Classify vector types in __builtin_classify_type #73299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,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.
* ``__builtin_classify_type()`` now classifies ``_BitInt`` values as the return value ``18``
and vector types as return value ``19``, to match GCC 14's behavior.

New Compiler Flags
------------------
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/AST/ExprConstShared.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ enum class GCCTypeClass {
// literals.
// Lang = 16,
// OpaqueType = 17,
BitInt = 18
BitInt = 18,
Vector = 19
};

GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
Expand Down
8 changes: 5 additions & 3 deletions clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11615,16 +11615,18 @@ GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
return EvaluateBuiltinClassifyType(
CanTy->castAs<AtomicType>()->getValueType(), LangOpts);

case Type::BlockPointer:
case Type::Vector:
case Type::ExtVector:
return GCCTypeClass::Vector;

case Type::BlockPointer:
case Type::ConstantMatrix:
case Type::ObjCObject:
case Type::ObjCInterface:
case Type::ObjCObjectPointer:
case Type::Pipe:
// 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.
// Classify all other types that don't fit into the regular
// classification the same way.
return GCCTypeClass::None;

case Type::BitInt:
Expand Down
6 changes: 3 additions & 3 deletions clang/test/Sema/builtin-classify-type.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ enum gcc_type_class {
record_type_class, union_type_class,
array_type_class, string_type_class,
lang_type_class, opaque_type_class,
bitint_type_class
bitint_type_class, vector_type_class
};

void foo(void) {
Expand Down Expand Up @@ -67,8 +67,8 @@ void foo(void) {
int a11[__builtin_classify_type(arr) == pointer_type_class ? 1 : -1];
int a12[__builtin_classify_type("abc") == pointer_type_class ? 1 : -1];
int a13[__builtin_classify_type(block) == no_type_class ? 1 : -1];
int a14[__builtin_classify_type(vec) == no_type_class ? 1 : -1];
int a15[__builtin_classify_type(evec) == no_type_class ? 1 : -1];
int a14[__builtin_classify_type(vec) == vector_type_class ? 1 : -1];
int a15[__builtin_classify_type(evec) == vector_type_class ? 1 : -1];
int a16[__builtin_classify_type(atomic_i) == integer_type_class ? 1 : -1];
int a17[__builtin_classify_type(atomic_d) == real_type_class ? 1 : -1];
int a18[__builtin_classify_type(complex_i) == complex_type_class ? 1 : -1];
Expand Down
6 changes: 3 additions & 3 deletions clang/test/SemaCXX/builtin-classify-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ enum gcc_type_class {
record_type_class, union_type_class,
array_type_class, string_type_class,
lang_type_class, opaque_type_class,
bitint_type_class
bitint_type_class, vector_type_class
};

class cl {
Expand Down Expand Up @@ -62,8 +62,8 @@ void foo() {
int a14[__builtin_classify_type(arr) == pointer_type_class ? 1 : -1];
int a15[__builtin_classify_type("abc") == pointer_type_class ? 1 : -1];
int a16[__builtin_classify_type(block) == no_type_class ? 1 : -1];
int a17[__builtin_classify_type(vec) == no_type_class ? 1 : -1];
int a18[__builtin_classify_type(evec) == no_type_class ? 1 : -1];
int a17[__builtin_classify_type(vec) == vector_type_class ? 1 : -1];
int a18[__builtin_classify_type(evec) == vector_type_class ? 1 : -1];
int a19[__builtin_classify_type(atomic_i) == integer_type_class ? 1 : -1];
int a20[__builtin_classify_type(atomic_d) == real_type_class ? 1 : -1];
int a21[__builtin_classify_type(complex_i) == complex_type_class ? 1 : -1];
Expand Down