brintos

brintos / llvm-project-archived public Read only

0
0
Text · 902 B · 4b023a7 Raw
38 lines · cpp
1// RUN: %clang_analyze_cc1 \2// RUN:  -analyzer-checker=core,unix.Malloc \3// RUN:  -verify %s4 5// expected-no-diagnostics: We do not model Integer Set Library's retain-count6//                          based allocation. If any of the parameters has an7//                          '__isl_' prefixed macro definition we escape every8//                          of them when we are about to 'free()' something.9 10#define __isl_take11#define __isl_keep12 13struct Object { int Ref; };14void free(void *);15 16Object *copyObj(__isl_keep Object *O) {17  O->Ref++;18  return O;19}20 21void 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 28void 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}38