annotate clang/test/Analysis/retain-count-alloc.cpp @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_analyze_cc1 \
anatofuz
parents:
diff changeset
2 // RUN: -analyzer-checker=core,unix.Malloc \
anatofuz
parents:
diff changeset
3 // RUN: -verify %s
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 // expected-no-diagnostics: We do not model Integer Set Library's retain-count
anatofuz
parents:
diff changeset
6 // based allocation. If any of the parameters has an
anatofuz
parents:
diff changeset
7 // '__isl_' prefixed macro definition we escape every
anatofuz
parents:
diff changeset
8 // of them when we are about to 'free()' something.
anatofuz
parents:
diff changeset
9
anatofuz
parents:
diff changeset
10 #define __isl_take
anatofuz
parents:
diff changeset
11 #define __isl_keep
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
13 struct Object { int Ref; };
anatofuz
parents:
diff changeset
14 void free(void *);
anatofuz
parents:
diff changeset
15
anatofuz
parents:
diff changeset
16 Object *copyObj(__isl_keep Object *O) {
anatofuz
parents:
diff changeset
17 O->Ref++;
anatofuz
parents:
diff changeset
18 return O;
anatofuz
parents:
diff changeset
19 }
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21 void freeObj(__isl_take Object *O) {
anatofuz
parents:
diff changeset
22 if (--O->Ref > 0)
anatofuz
parents:
diff changeset
23 return;
anatofuz
parents:
diff changeset
24
anatofuz
parents:
diff changeset
25 free(O); // Here we notice that the parameter contains '__isl_', escape it.
anatofuz
parents:
diff changeset
26 }
anatofuz
parents:
diff changeset
27
anatofuz
parents:
diff changeset
28 void useAfterFree(__isl_take Object *A) {
anatofuz
parents:
diff changeset
29 if (!A)
anatofuz
parents:
diff changeset
30 return;
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 Object *B = copyObj(A);
anatofuz
parents:
diff changeset
33 freeObj(B);
anatofuz
parents:
diff changeset
34
anatofuz
parents:
diff changeset
35 A->Ref = 13;
anatofuz
parents:
diff changeset
36 // no-warning: 'Use of memory after it is freed' was here.
anatofuz
parents:
diff changeset
37 }