[RISC-V] Avoid unnecessary extensions when value is already extended
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / snprintf-concat.c
blobc40440c490560d15afdab896a8f7e5032d246f22
1 typedef __SIZE_TYPE__ size_t;
2 #include "../../gcc.dg/analyzer/analyzer-decls.h"
4 extern size_t
5 strlen(const char* __s) __attribute__((__nothrow__, __leaf__))
6 __attribute__((__pure__)) __attribute__((__nonnull__(1)));
8 extern void*
9 malloc(size_t __size) __attribute__((__nothrow__, __leaf__))
10 __attribute__((__malloc__)) __attribute__((__alloc_size__(1)));
12 extern int
13 snprintf(char* __restrict __s, size_t size, const char* __restrict, ...)
14 __attribute__((__nothrow__));
16 char *
17 test_1 (const char *a, const char *b)
19 size_t sz = strlen (a) + strlen (b) + 2;
20 char *p = (char *) malloc (sz);
21 if (!p)
22 return NULL;
23 snprintf (p, sz, "%s/%s", a, b);
24 return p;
27 void
28 test_2 (const char *a, const char *b)
30 size_t sz = strlen (a) + strlen (b) + 2;
31 char *p = (char *) malloc (sz); /* { dg-message "allocated here" "PR 107017" { xfail *-*-* } } */
32 if (!p)
33 return;
34 snprintf (p, sz, "%s/%s", a, b); /* { dg-warning "leak of 'p'" "PR 107017" { xfail *-*-* } } */