public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/106850] New: restrict type qualifier ignored on function return type
@ 2022-09-06 13:50 colomar.6.4.3 at gmail dot com
  2022-09-06 13:51 ` [Bug c/106850] " colomar.6.4.3 at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: colomar.6.4.3 at gmail dot com @ 2022-09-06 13:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106850

            Bug ID: 106850
           Summary: restrict type qualifier ignored on function return
                    type
           Product: gcc
           Version: 12.2.0
            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: ---

Related: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87313>

The description of the restrict qualifier would lead one to think that it can
be used as a standard way of describing a function that returns a unique
pointer, as the [[gnu::malloc]] attribute does in GNU C.

GCC currently ignores the qualifier, so it can't use it for the optimizations
that [[gnu::malloc]] allows, but if GCC didn't ignore the qualifier, it could
be used for that.

```c
#include <err.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>

[[gnu::malloc(free)]]
void *restrict
my_malloc(size_t size)
{
        void *p;

        p = malloc(size);  
        if (!p)    
                err(EXIT_FAILURE, "malloc(2)");    

        return p;
}
```
```sh
$ cc -Wall -Wextra my_malloc.c -S
my_malloc.c:8:1: warning: type qualifiers ignored on function return type
[-Wignored-qualifiers]
    8 | my_malloc(size_t size)
      | ^~~~~~~~~
```

Could you please not ignore the qualifier, and treat it as synonym of
[[gnu::malloc]]?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/106850] restrict type qualifier ignored on function return type
  2022-09-06 13:50 [Bug c/106850] New: restrict type qualifier ignored on function return type colomar.6.4.3 at gmail dot com
@ 2022-09-06 13:51 ` colomar.6.4.3 at gmail dot com
  2022-09-06 13:56 ` pinskia at gcc dot gnu.org
  2022-09-06 14:00 ` colomar.6.4.3 at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: colomar.6.4.3 at gmail dot com @ 2022-09-06 13:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106850

--- Comment #1 from Alejandro Colomar <colomar.6.4.3 at gmail dot com> ---
The benefits are:

- It's standard.
- It's less bytes to type.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/106850] restrict type qualifier ignored on function return type
  2022-09-06 13:50 [Bug c/106850] New: restrict type qualifier ignored on function return type colomar.6.4.3 at gmail dot com
  2022-09-06 13:51 ` [Bug c/106850] " colomar.6.4.3 at gmail dot com
@ 2022-09-06 13:56 ` pinskia at gcc dot gnu.org
  2022-09-06 14:00 ` colomar.6.4.3 at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-09-06 13:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106850

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> It's standard.

Not really as the warning is correct qualifiers are really ignored on return
types as required by the standard.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/106850] restrict type qualifier ignored on function return type
  2022-09-06 13:50 [Bug c/106850] New: restrict type qualifier ignored on function return type colomar.6.4.3 at gmail dot com
  2022-09-06 13:51 ` [Bug c/106850] " colomar.6.4.3 at gmail dot com
  2022-09-06 13:56 ` pinskia at gcc dot gnu.org
@ 2022-09-06 14:00 ` colomar.6.4.3 at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: colomar.6.4.3 at gmail dot com @ 2022-09-06 14:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106850

--- Comment #3 from Alejandro Colomar <colomar.6.4.3 at gmail dot com> ---
Ahhh, yeah, something like rvalues don't have qualifiers.  I seem to remember
now.

Maybe the standard should fix this for restrict, because things like clang's
_Nonnull would benefit from being kept in such cases.

Of course, that might complicate the compiler...

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-09-06 14:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-06 13:50 [Bug c/106850] New: restrict type qualifier ignored on function return type colomar.6.4.3 at gmail dot com
2022-09-06 13:51 ` [Bug c/106850] " colomar.6.4.3 at gmail dot com
2022-09-06 13:56 ` pinskia at gcc dot gnu.org
2022-09-06 14:00 ` colomar.6.4.3 at gmail dot com

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).