[cfe-dev] Prevent RetainCountChecker from Analyzing Function Bodies when They Have Certain Annotate Attribute
Malhar Thakkar via cfe-dev
cfe-dev at lists.llvm.org
Fri Jul 7 00:23:23 PDT 2017
Dear all,
I wish to prevent the RetainCountChecker from analyzing function bodies if
these functions have certain annotate attributes. Consider the following
example to get a better idea of why I wish to do that.
Below is a small snippet from the Integer Set Library (ISL).
typedef struct {
int ref;
} isl_basic_map;
__attribute__((cf_returns_retained))
isl_basic_map *isl_basic_map_copy(isl_basic_map *bmap);
__attribute__((cf_returns_retained))
isl_basic_map *isl_basic_map_cow
(__attribute__((cf_consumed)) isl_basic_map *bmap);
void free(void *);
__attribute__((annotate("rc_ownership_trusted_implementation")))
isl_basic_map *isl_basic_map_free
(__attribute__((cf_consumed)) isl_basic_map *bmap) {
if (!bmap)
return NULL;
if (--bmap->ref > 0)
return NULL;
free(bmap);
return NULL;
}
__attribute__((cf_returns_retained))
isl_basic_map *foo
(__attribute__((cf_consumed)) isl_basic_map *bmap) {
// *After this call, 'temp' has a +1 reference count.*
isl_basic_map *temp = isl_basic_map_copy(bmap);
// *After this call, 'bmap' has a +1 reference count.*
bmap = isl_basic_map_cow(bmap);
// *After this call, assuming the predicate of the second if branch to be
true, 'bmap' has a +1 reference count.*
isl_basic_map_free(bmap);
return temp; *// Object leaked: 'bmap'*
}
While running the RetainCountChecker on the above example, it raises a leak
warning for 'bmap' in function 'foo'. This warning is a true positive from
the checker's perspective in the sense that the reference count of 'bmap'
obtained from 'isl_basic_map_cow' is not decremented(from the checker's
perspective) in 'isl_basic_map_free' even though it takes the argument
'bmap' as '__attribute__((cf_consumed))'.
Actually, '--bmap->ref' does decrement the reference count (from ISL's
perspective). Hence, to prevent such false positives (from ISL's
perspective) to be raised, I wish to prevent the RetainCountChecker to
analyze the bodies of the functions having
'rc_ownership_trusted_implementation' annotate attribute. I want the
checker to just look at the declaration of such functions (and not go
inside their bodies) to get the necessary information about reference
counting.
Could someone suggest me a way to achieve my objective?
Thank you.
Regards,
Malhar Thakkar
ᐧ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170707/80357fcd/attachment.html>
More information about the cfe-dev
mailing list