From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 7B1293858D35; Mon, 20 Nov 2023 09:46:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7B1293858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700473594; bh=SpkpOn8IbKPe7vBiYmiR10HOMoZWf+K4/+1Mx6geOt4=; h=From:To:Subject:Date:From; b=dmsLlFoiJ1T2ULUyT9NLjnyJ53b2VFMZlxAhluhmz2z73b/aycz6BFhpZLK/gHxEx Uko5OCmXqKl3FjDKrZnVJNOHqnz/GNrm/aLVY/420V2RBNqujh+yYNDn5Fc/CWGfvH YOdEzKpGMsUtr9nviy/xAiO4JvIJ0TFjzDGu+k5o= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-5615] c, c++: Add new value for vector types for __builtin_classify_type X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: f25a5b199a0ebd4695466e665e49041339f0c6a7 X-Git-Newrev: 509b470dcee9795887a60ddb32ab454f22e74411 Message-Id: <20231120094634.7B1293858D35@sourceware.org> Date: Mon, 20 Nov 2023 09:46:34 +0000 (GMT) List-Id: https://gcc.gnu.org/g:509b470dcee9795887a60ddb32ab454f22e74411 commit r14-5615-g509b470dcee9795887a60ddb32ab454f22e74411 Author: Jakub Jelinek Date: Mon Nov 20 10:37:59 2023 +0100 c, c++: Add new value for vector types for __builtin_classify_type While filing a clang request to return 18 on _BitInts for __builtin_classify_type instead of -1 they return currently, I've noticed that we return -1 for vector types. Initially I wanted to change behavior just for __builtin_classify_type (type) form, as that is new in GCC 14 and we've returned for 20+ years -1 for __builtin_classify_type on vector expressions, but I was convinved otherwise, so this changes the behavior even for that and now returns 19. 2023-11-20 Jakub Jelinek gcc/ * typeclass.h (enum type_class): Add vector_type_class. * builtins.cc (type_to_class): Return vector_type_class for VECTOR_TYPE. * doc/extend.texi (__builtin_classify_type): Mention bit-precise integer types and vector types. gcc/testsuite/ * c-c++-common/builtin-classify-type-1.c (main): Add tests for vector types. Diff: --- gcc/builtins.cc | 1 + gcc/doc/extend.texi | 10 +++++----- gcc/testsuite/c-c++-common/builtin-classify-type-1.c | 12 ++++++++++++ gcc/typeclass.h | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/gcc/builtins.cc b/gcc/builtins.cc index 5ece0d23eb9..a489ef1c564 100644 --- a/gcc/builtins.cc +++ b/gcc/builtins.cc @@ -1859,6 +1859,7 @@ type_to_class (tree type) case LANG_TYPE: return lang_type_class; case OPAQUE_TYPE: return opaque_type_class; case BITINT_TYPE: return bitint_type_class; + case VECTOR_TYPE: return vector_type_class; default: return no_type_class; } } diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 3169acd8550..9474e9398bb 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -14746,11 +14746,11 @@ The @code{__builtin_classify_type} returns a small integer with a category of @var{arg} argument's type, like void type, integer type, enumeral type, boolean type, pointer type, reference type, offset type, real type, complex type, function type, method type, record type, union type, array type, -string type, etc. When the argument is an expression, for -backwards compatibility reason the argument is promoted like arguments -passed to @code{...} in varargs function, so some classes are never returned -in certain languages. Alternatively, the argument of the built-in -function can be a typename, such as the @code{typeof} specifier. +string type, bit-precise integer type, vector type, etc. When the argument +is an expression, for backwards compatibility reason the argument is promoted +like arguments passed to @code{...} in varargs function, so some classes are +never returned in certain languages. Alternatively, the argument of the +built-in function can be a typename, such as the @code{typeof} specifier. @smallexample int a[2]; diff --git a/gcc/testsuite/c-c++-common/builtin-classify-type-1.c b/gcc/testsuite/c-c++-common/builtin-classify-type-1.c index a41dbe16301..f90f2d93607 100644 --- a/gcc/testsuite/c-c++-common/builtin-classify-type-1.c +++ b/gcc/testsuite/c-c++-common/builtin-classify-type-1.c @@ -22,6 +22,10 @@ main () const char *p = (const char *) 0; float f = 0.0; _Complex double c = 0.0; + typedef int VI __attribute__((vector_size (4 * sizeof (int)))); + typedef float VF __attribute__((vector_size (4 * sizeof (int)))); + VI vi = { 0, 0, 0, 0 }; + VF vf = { 0.0f, 0.0f, 0.0f, 0.0f }; #ifdef __cplusplus struct T { void foo (); }; int &r = a[0]; @@ -43,6 +47,8 @@ main () static_assert (__builtin_classify_type (struct S) == 12, ""); static_assert (__builtin_classify_type (union U) == 13, ""); static_assert (__builtin_classify_type (int [2]) == 14, ""); + static_assert (__builtin_classify_type (VI) == 19, ""); + static_assert (__builtin_classify_type (VF) == 19, ""); static_assert (__builtin_classify_type (__typeof__ (a[0])) == 1, ""); static_assert (__builtin_classify_type (__typeof__ (e)) == 3, ""); static_assert (__builtin_classify_type (__typeof__ (b)) == 4, ""); @@ -57,6 +63,8 @@ main () static_assert (__builtin_classify_type (__typeof__ (s)) == 12, ""); static_assert (__builtin_classify_type (__typeof__ (u)) == 13, ""); static_assert (__builtin_classify_type (__typeof__ (a)) == 14, ""); + static_assert (__builtin_classify_type (__typeof__ (vi)) == 19, ""); + static_assert (__builtin_classify_type (__typeof__ (vf)) == 19, ""); #ifndef __cplusplus static_assert (__builtin_classify_type (a[0]) == 1, ""); static_assert (__builtin_classify_type (e) == 1, ""); @@ -102,4 +110,8 @@ main () abort (); if (__builtin_classify_type (a) != 5) abort (); + if (__builtin_classify_type (vi) != 19) + abort (); + if (__builtin_classify_type (vf) != 19) + abort (); } diff --git a/gcc/typeclass.h b/gcc/typeclass.h index 4b162e1d2c5..2723c653e48 100644 --- a/gcc/typeclass.h +++ b/gcc/typeclass.h @@ -38,7 +38,7 @@ enum 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 }; #endif /* GCC_TYPECLASS_H */