aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/analyzer/pr101983-not-main.c
blob: fbf3a393ebb6dadb42177987e528960b1b4d13c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* { dg-additional-options "-Wno-analyzer-too-complex -fno-analyzer-call-summaries" } */

#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>

struct list {
	struct list* next;
	void *a;
};

void func(struct list **res)
{
	struct list *cur = NULL;
	do {
		struct list *n = malloc(sizeof(struct list));
		void *a = malloc(1);
		if (n == NULL || a == NULL) {
			if (n != NULL) free(n);
			if (a != NULL) free(a);
			break;
		}

		if (cur == NULL) {
			*res = cur = n;
		} else {
			cur->next = n;
			cur = n;
		}
		n->a = a;
	} while (true);
}

int not_main()
{
	struct list *res;
	func(&res);
} /* { dg-warning "leak of 'res'" "leak of res" } */
/* { dg-warning "leak of '<unknown>'" "leak of res->a" { target *-*-* } .-1 } */
/* TODO: we should emit 'res->a' rather than '<unknown>' here.  */