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