public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/98109] New: Seemingly wrong warnings from -Wnonnull when combined with -O2 -fsanitize=undefined
@ 2020-12-02 22:54 gabravier at gmail dot com
  2020-12-03  1:08 ` [Bug middle-end/98109] " msebor at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gabravier at gmail dot com @ 2020-12-02 22:54 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98109
           Summary: Seemingly wrong warnings from -Wnonnull when combined
                    with -O2 -fsanitize=undefined
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

typedef __SIZE_TYPE__ size_t;

void *my_memcpy(void *destination, const void *source, size_t size)
    __attribute__((nonnull (1, 2)))
    __attribute__((access (write_only, 1, 3))) __attribute__((access
(read_only, 2, 3)));

void swap_1000(char *elem1, char *elem2, size_t element_size)
{
    char buffer[1000];

    my_memcpy(buffer, elem1, 1000);
    my_memcpy(elem1, elem2, 1000);
    my_memcpy(elem2, buffer, 1000);
}

When compiling this with -Wnonnull -O2 -fsanitize=undefined, these warnings are
observed :

test.c: In function ‘swap_1000’:
test.c:11:5: warning: argument 2 is null but the corresponding size argument 3
value is 1000 [-Wnonnull]
   11 |     my_memcpy(buffer, elem1, 1000);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.c:3:7: note: in a call to function ‘my_memcpy’ declared with attribute
‘read_only (2, 3)’
    3 | void *my_memcpy(void *destination, const void *source, size_t size)
      |       ^~~~~~~~~
test.c:12:5: warning: argument 2 is null but the corresponding size argument 3
value is 1000 [-Wnonnull]
   12 |     my_memcpy(elem1, elem2, 1000);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.c:3:7: note: in a call to function ‘my_memcpy’ declared with attribute
‘read_only (2, 3)’
    3 | void *my_memcpy(void *destination, const void *source, size_t size)
      |       ^~~~~~~~~

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

end of thread, other threads:[~2022-08-01 22:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-02 22:54 [Bug middle-end/98109] New: Seemingly wrong warnings from -Wnonnull when combined with -O2 -fsanitize=undefined gabravier at gmail dot com
2020-12-03  1:08 ` [Bug middle-end/98109] " msebor at gcc dot gnu.org
2021-05-19 10:44 ` jlegg at feralinteractive dot com
2021-05-19 16:02 ` msebor at gcc dot gnu.org
2022-07-31  9:02 ` b.buschinski at googlemail dot com
2022-08-01 22:01 ` msebor at gcc dot gnu.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).