aboutsummaryrefslogtreecommitdiff
path: root/gcc/builtins.cc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2023-09-20 18:37:29 +0200
committerJakub Jelinek <jakub@redhat.com>2023-09-20 18:37:29 +0200
commit53d834a7fae3afffebb45a2d66908f705773a7fc (patch)
tree4af979256b3f85649ada1d5cabc08c21cf6947db /gcc/builtins.cc
parent27282dc0931484c31fa391772499d878afcc746a (diff)
downloadgcc-53d834a7fae3afffebb45a2d66908f705773a7fc.zip
gcc-53d834a7fae3afffebb45a2d66908f705773a7fc.tar.gz
gcc-53d834a7fae3afffebb45a2d66908f705773a7fc.tar.bz2
c, c++: Accept __builtin_classify_type (typename)
As mentioned in my stdckdint.h mail, __builtin_classify_type has a problem that argument promotion (the argument is passed to ... prototyped builtin function) means that certain type classes will simply never appear. I think it is too late to change how it behaves, lots of code in the wild might rely on the current behavior. So, the following patch adds option to use a typename rather than expression as the operand to the builtin, making it behave similarly to sizeof, typeof or say the clang _Generic extension where the first argument can be there not just expression, but also typename. I think we have other prior art here, e.g. __builtin_va_arg also expects typename. I've added this to both C and C++, because it would be weird if it supported it only in C and not in C++. 2023-09-20 Jakub Jelinek <jakub@redhat.com> gcc/ * builtins.h (type_to_class): Declare. * builtins.cc (type_to_class): No longer static. Return int rather than enum. * doc/extend.texi (__builtin_classify_type): Document. gcc/c/ * c-parser.cc (c_parser_postfix_expression_after_primary): Parse __builtin_classify_type call with typename as argument. gcc/cp/ * parser.cc (cp_parser_postfix_expression): Parse __builtin_classify_type call with typename as argument. * pt.cc (tsubst_copy_and_build): Handle __builtin_classify_type with dependent typename as argument. gcc/testsuite/ * c-c++-common/builtin-classify-type-1.c: New test. * g++.dg/ext/builtin-classify-type-1.C: New test. * g++.dg/ext/builtin-classify-type-2.C: New test. * gcc.dg/builtin-classify-type-1.c: New test.
Diffstat (limited to 'gcc/builtins.cc')
-rw-r--r--gcc/builtins.cc3
1 files changed, 1 insertions, 2 deletions
diff --git a/gcc/builtins.cc b/gcc/builtins.cc
index 3b453b3..6e4274b 100644
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -113,7 +113,6 @@ static rtx expand_builtin_apply_args (void);
static rtx expand_builtin_apply_args_1 (void);
static rtx expand_builtin_apply (rtx, rtx, rtx);
static void expand_builtin_return (rtx);
-static enum type_class type_to_class (tree);
static rtx expand_builtin_classify_type (tree);
static rtx expand_builtin_mathfn_3 (tree, rtx, rtx);
static rtx expand_builtin_mathfn_ternary (tree, rtx, rtx);
@@ -1853,7 +1852,7 @@ expand_builtin_return (rtx result)
/* Used by expand_builtin_classify_type and fold_builtin_classify_type. */
-static enum type_class
+int
type_to_class (tree type)
{
switch (TREE_CODE (type))