public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/107348] New: documentation: __builtin_classify_type() undocumented
@ 2022-10-21 14:38 colomar.6.4.3 at gmail dot com
2022-10-21 14:47 ` [Bug c/107348] " jakub at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: colomar.6.4.3 at gmail dot com @ 2022-10-21 14:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107348
Bug ID: 107348
Summary: documentation: __builtin_classify_type() undocumented
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: colomar.6.4.3 at gmail dot com
Target Milestone: ---
I can't find any documentation about `__builtin_classify_type()`.
Moreover, it behaves weird with arrays.
$ grepc type_class
./gcc/typeclass.h:30:
enum type_class
{
no_type_class = -1,
void_type_class, integer_type_class, char_type_class,
enumeral_type_class, boolean_type_class,
pointer_type_class, reference_type_class, offset_type_class,
real_type_class, complex_type_class,
function_type_class, method_type_class,
record_type_class, union_type_class,
array_type_class, string_type_class,
lang_type_class, opaque_type_class
};
One would expect that for arrays, it would return `array_type_class`, i.e.,
`14`, but it returns `5`, i.e., `pointer_type_class`.
alx@debian:~/tmp$ cat ptr.c
#include <stdio.h>
int
main(void)
{
int a[5];
printf("%d\n", __builtin_classify_type(a));
}
alx@debian:~/tmp$ cc -Wall -Wextra ptr.c
alx@debian:~/tmp$ ./a.out
5
Please document the builtin (and also fix the handling of arrays).
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c/107348] documentation: __builtin_classify_type() undocumented
2022-10-21 14:38 [Bug c/107348] New: documentation: __builtin_classify_type() undocumented colomar.6.4.3 at gmail dot com
@ 2022-10-21 14:47 ` jakub at gcc dot gnu.org
2022-10-21 14:49 ` colomar.6.4.3 at gmail dot com
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-10-21 14:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107348
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
There is a array to pointer decay in the argument, so pointer_type_class is the
right answer.
As for documentation, seems __builtin_classify_type is documented in gccint
manual rather than gcc:
https://gcc.gnu.org/onlinedocs/gccint/Varargs.html#Varargs
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c/107348] documentation: __builtin_classify_type() undocumented
2022-10-21 14:38 [Bug c/107348] New: documentation: __builtin_classify_type() undocumented colomar.6.4.3 at gmail dot com
2022-10-21 14:47 ` [Bug c/107348] " jakub at gcc dot gnu.org
@ 2022-10-21 14:49 ` colomar.6.4.3 at gmail dot com
2022-10-21 14:56 ` jakub at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: colomar.6.4.3 at gmail dot com @ 2022-10-21 14:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107348
--- Comment #2 from Alejandro Colomar <colomar.6.4.3 at gmail dot com> ---
Being a builtin, I expected that you could just do "compiler magic" to avoid
the decay.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c/107348] documentation: __builtin_classify_type() undocumented
2022-10-21 14:38 [Bug c/107348] New: documentation: __builtin_classify_type() undocumented colomar.6.4.3 at gmail dot com
2022-10-21 14:47 ` [Bug c/107348] " jakub at gcc dot gnu.org
2022-10-21 14:49 ` colomar.6.4.3 at gmail dot com
@ 2022-10-21 14:56 ` jakub at gcc dot gnu.org
2022-10-21 14:59 ` colomar.6.4.3 at gmail dot com
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-10-21 14:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107348
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Most of the builtins don't do such special magic.
It is true that some, mostly newer added, builtins do have such magic, but I
think __builtin_classify_type is one of the first builtins added to GCC
(certainly GCC 1.36 in 1989 had it).
It would be very bad idea to change its behavior all of sudden after 33 years.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c/107348] documentation: __builtin_classify_type() undocumented
2022-10-21 14:38 [Bug c/107348] New: documentation: __builtin_classify_type() undocumented colomar.6.4.3 at gmail dot com
` (2 preceding siblings ...)
2022-10-21 14:56 ` jakub at gcc dot gnu.org
@ 2022-10-21 14:59 ` colomar.6.4.3 at gmail dot com
2022-10-21 15:12 ` jakub at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: colomar.6.4.3 at gmail dot com @ 2022-10-21 14:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107348
--- Comment #4 from Alejandro Colomar <colomar.6.4.3 at gmail dot com> ---
Hmm. Then I wonder if array_type_class is being used at all, or if it's unused
code.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c/107348] documentation: __builtin_classify_type() undocumented
2022-10-21 14:38 [Bug c/107348] New: documentation: __builtin_classify_type() undocumented colomar.6.4.3 at gmail dot com
` (3 preceding siblings ...)
2022-10-21 14:59 ` colomar.6.4.3 at gmail dot com
@ 2022-10-21 15:12 ` jakub at gcc dot gnu.org
2022-10-21 15:17 ` colomar.6.4.3 at gmail dot com
2023-12-05 17:48 ` alx at kernel dot org
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-10-21 15:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107348
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Most likely. I think char_type_class, function_type_class, method_type_class,
string_type_class most likely too (function and methods also decay to pointers
to pointer to members), string has the same issue as array, char isn't even
handled in type_to_class). Not really sure about reference_type_class, maybe
even that.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c/107348] documentation: __builtin_classify_type() undocumented
2022-10-21 14:38 [Bug c/107348] New: documentation: __builtin_classify_type() undocumented colomar.6.4.3 at gmail dot com
` (4 preceding siblings ...)
2022-10-21 15:12 ` jakub at gcc dot gnu.org
@ 2022-10-21 15:17 ` colomar.6.4.3 at gmail dot com
2023-12-05 17:48 ` alx at kernel dot org
6 siblings, 0 replies; 8+ messages in thread
From: colomar.6.4.3 at gmail dot com @ 2022-10-21 15:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107348
--- Comment #6 from Alejandro Colomar <colomar.6.4.3 at gmail dot com> ---
Thanks!
Maybe a working __builtin_classify_type2() would be useful... Maybe not...
BTW, maybe it's worth checking all the code in gcc that is comparing the result
against 14, and see if it should be removed, or fixed, or if it actually works
somehow.
Cheers,
Alex
P.S.: Maybe having a search function, or a single-HTML-page manual (as glibc
does) would be good for finding this stuff. I don't know. I tried searching
in the PDF, and I didn't find it.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c/107348] documentation: __builtin_classify_type() undocumented
2022-10-21 14:38 [Bug c/107348] New: documentation: __builtin_classify_type() undocumented colomar.6.4.3 at gmail dot com
` (5 preceding siblings ...)
2022-10-21 15:17 ` colomar.6.4.3 at gmail dot com
@ 2023-12-05 17:48 ` alx at kernel dot org
6 siblings, 0 replies; 8+ messages in thread
From: alx at kernel dot org @ 2023-12-05 17:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107348
Alejandro Colomar <alx at kernel dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|UNCONFIRMED |RESOLVED
--- Comment #7 from Alejandro Colomar <alx at kernel dot org> ---
I just realized it was fixed recently. Thanks!
commit 53d834a7fae3afffebb45a2d66908f705773a7fc
Author: Jakub Jelinek <jakub@redhat.com>
Date: Wed Sep 20 18:37:29 2023 +0200
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.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-12-05 17:48 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-21 14:38 [Bug c/107348] New: documentation: __builtin_classify_type() undocumented colomar.6.4.3 at gmail dot com
2022-10-21 14:47 ` [Bug c/107348] " jakub at gcc dot gnu.org
2022-10-21 14:49 ` colomar.6.4.3 at gmail dot com
2022-10-21 14:56 ` jakub at gcc dot gnu.org
2022-10-21 14:59 ` colomar.6.4.3 at gmail dot com
2022-10-21 15:12 ` jakub at gcc dot gnu.org
2022-10-21 15:17 ` colomar.6.4.3 at gmail dot com
2023-12-05 17:48 ` alx at kernel dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).