[RISC-V] Avoid unnecessary extensions when value is already extended
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / data-model-20.c
blobdd7996bd1605841e7901846753dd35138423f382
1 /* { dg-additional-options "-Wno-analyzer-too-complex" } */
2 /* { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } */
4 #include <stdlib.h>
6 struct foo { int dummy; };
8 struct foo **
9 test (int n) {
10 struct foo **arr;
11 int i;
13 if ((arr = (struct foo **)malloc(n * sizeof(struct foo *))) == NULL)
14 return NULL;
16 for (i = 0; i < n; i++) {
17 if ((arr[i] = (struct foo *)malloc(sizeof(struct foo))) == NULL) {
18 for (; i >= 0; i++) { /* { dg-warning "infinite loop" } */
19 /* This loop is in the wrong direction, so not technically an
20 infinite loop ("i" will eventually wrap around), but the
21 analyzer's condition handling treats the overflow as such.
22 In any case, the code is suspect and warrants a warning. */
23 free(arr[i]); /* { dg-bogus "double-'free'" } */
25 free(arr); /* { dg-warning "leak" } */
26 return NULL;
29 return arr;