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)
| ^~~~~~~~~