<div dir="ltr">Hello everyone,<div><br></div><div><a href="https://docs.google.com/document/d/1oC3qxh_q-Ly8DVsijcb4U5H8pkcA-19OR8NCeYthBN8/edit?usp=sharing">This</a> is the final report of my GSoC project. The aim of my project was to add support to RetainCountChecker to perform reference counting of objects in frameworks written in C, primarily for the Integer Set Library (ISL).</div><div><br></div><div><div>My work in this GSoC project primarily involved the following two tasks:</div><div><ul><li>Analyze how the RetainCountChecker performs (in terms of true/false positives and true/false negatives) on the ISL codebase.<br></li><li>Fix most of the true positives (due to missing annotations) and false positives by adding certain functionalities to the RetainCountChecker.<br></li></ul><div><span id="gmail-docs-internal-guid-7bf810a9-126c-672b-41ac-f38ffd26ad4f"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;text-align:justify"><span style="font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">Patches submitted to clang and ISL:</span></p><ul style="margin-top:0pt;margin-bottom:0pt"><li style="list-style-type:disc;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline"><p style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;text-align:justify"><span style="background-color:transparent;vertical-align:baseline;white-space:pre-wrap">Missing annotations in various functions in ISL resulted in a lot of leak warnings for reference counted objects. To suppress these warnings, I submitted </span><a href="http://repo.or.cz/isl.git/search/HEAD?s=Malhar+Thakkar;st=author" style="text-decoration-line:none"><span style="background-color:transparent;text-decoration-line:underline;vertical-align:baseline;white-space:pre-wrap">patches</span></a><span style="background-color:transparent;vertical-align:baseline;white-space:pre-wrap"> to add missing annotations to such functions.</span></p></li><li style="list-style-type:disc;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline"><p style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;text-align:justify"><span style="background-color:transparent;vertical-align:baseline;white-space:pre-wrap">False positives were raised when the RetainCountChecker analyzed the bodies of functions (which perform reference counting) of the form </span><span style="font-family:"Source Code Pro";background-color:transparent;vertical-align:baseline;white-space:pre-wrap">obj_free()</span><span style="background-color:transparent;vertical-align:baseline;white-space:pre-wrap">, </span><span style="font-family:"Source Code Pro";background-color:transparent;vertical-align:baseline;white-space:pre-wrap">obj_copy()</span><span style="background-color:transparent;vertical-align:baseline;white-space:pre-wrap"> and </span><span style="font-family:"Source Code Pro";background-color:transparent;vertical-align:baseline;white-space:pre-wrap">obj_cow()</span><span style="background-color:transparent;vertical-align:baseline;white-space:pre-wrap">. To prevent such false positives, I submitted this </span><a href="https://reviews.llvm.org/D34937" style="text-decoration-line:none"><span style="background-color:transparent;text-decoration-line:underline;vertical-align:baseline;white-space:pre-wrap">patch</span></a><span style="background-color:transparent;vertical-align:baseline;white-space:pre-wrap">. This patch makes the checker trust the implementations of these functions and hence, prevents it to analyze the bodies of these functions.</span></p></li><li style="list-style-type:disc;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline"><p style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;text-align:justify"><span style="background-color:transparent;vertical-align:baseline;white-space:pre-wrap">Diagnostic notes emitted by the RetainCountChecker were specific to Core Foundation and Objective-C objects. To support more generalized reference counting annotations and emit more generalized diagnostic notes, I submitted this </span><a href="https://reviews.llvm.org/D35613" style="text-decoration-line:none"><span style="background-color:transparent;text-decoration-line:underline;vertical-align:baseline;white-space:pre-wrap">patch</span></a><span style="background-color:transparent;vertical-align:baseline;white-space:pre-wrap">.</span></p></li><li>Original RetainCountChecker did not have the functionality of performing reference counting of function parameters on the callee-side which can prove to be very useful for various kinds of debugging. This <a href="https://reviews.llvm.org/D36441" style="text-decoration-line:none"><span style="font-family:Arial;background-color:transparent;text-decoration-line:underline;vertical-align:baseline;white-space:pre-wrap">patch</span></a><span style="background-color:transparent;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap"> adds that functionality.</span><br></li></ul></span></div></div></div><div><br></div><div><span id="gmail-docs-internal-guid-7bf810a9-126d-0f7d-5592-c317f390b387"><span style="font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">Analysis of building the ISL codebase with Clang Static Analyzer during various stages can be found </span><a href="https://docs.google.com/spreadsheets/d/1G233lt251m-z1TwcHqAzaV6vrrGGVkt0-WKh4QAaW9U/edit?usp=sharing" style="text-decoration-line:none"><span style="font-family:Arial;background-color:transparent;text-decoration-line:underline;vertical-align:baseline;white-space:pre-wrap">here</span></a><span style="font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">. </span></span><span style="background-color:transparent;color:rgb(0,0,0);font-family:Arial;white-space:pre-wrap">Note that the “View Report” hyperlinks will not work on your systems since their paths are pertaining to my local system.</span><br></div><div><span style="background-color:transparent;color:rgb(0,0,0);font-family:Arial;white-space:pre-wrap"><br></span></div><div><span id="gmail-docs-internal-guid-7bf810a9-126f-34a8-382c-d1ac8850f04a"><h1 dir="ltr" style="line-height:1.38;margin-top:20pt;margin-bottom:6pt"><span style="font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap"><font size="4">Usage</font></span></h1><ul style="margin-top:0pt;margin-bottom:0pt"><li style="list-style-type:disc;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline"><p style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="background-color:transparent;vertical-align:baseline;white-space:pre-wrap">Download the latest clang source code by </span><span style="font-family:"Source Code Pro";background-color:transparent;font-weight:700;vertical-align:baseline;white-space:pre-wrap">git clone <a href="http://llvm.org/git/clang.git">http://llvm.org/git/clang.git</a></span><span style="background-color:transparent;font-weight:700;vertical-align:baseline;white-space:pre-wrap"> </span><span style="background-color:transparent;vertical-align:baseline;white-space:pre-wrap">and build it from source.</span></p></li><li style="list-style-type:disc;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline"><p style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="background-color:transparent;vertical-align:baseline;white-space:pre-wrap">Download the latest ISL source code by </span><span style="font-family:"Source Code Pro";background-color:transparent;font-weight:700;vertical-align:baseline;white-space:pre-wrap">git clone git://<a href="http://repo.or.cz/isl.git">repo.or.cz/isl.git</a></span></p></li><li style="list-style-type:disc;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline"><p style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="background-color:transparent;vertical-align:baseline;white-space:pre-wrap">Prepend obj_free(), obj_cow() and obj_free() functions in ISL with </span><span style="font-family:"Source Code Pro";background-color:transparent;vertical-align:baseline;white-space:pre-wrap">__attribute__((annotate("rc_ownership_trusted_implementation"))</span><span style="background-color:transparent;vertical-align:baseline;white-space:pre-wrap"> as mentioned above.</span></p></li><li style="list-style-type:disc;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline"><p style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="background-color:transparent;vertical-align:baseline;white-space:pre-wrap">Run the following scripts (in order) in the ISL home directory to build it using Clang Static Analyzer.</span></p></li><ul style="margin-top:0pt;margin-bottom:0pt"><li style="list-style-type:circle;font-family:"Source Code Pro";color:rgb(0,0,0);background-color:transparent;vertical-align:baseline"><p style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="background-color:transparent;vertical-align:baseline;white-space:pre-wrap">$LLVM_BUILD/bin/scan-build --use-analyzer $LLVM_BUILD/bin/clang --use-cc $LLVM_BUILD/bin/clang -o <output_folder_path> -enable-checker osx.cocoa.RetainCount ./configure CC="gcc" CFLAGS='-Wno-nullability-completeness -I/usr/local/include'</span></p></li><li style="list-style-type:circle;font-family:"Source Code Pro";color:rgb(0,0,0);background-color:transparent;vertical-align:baseline"><p style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="background-color:transparent;vertical-align:baseline;white-space:pre-wrap">$LLVM_BUILD/bin/scan-build --use-analyzer $LLVM_BUILD/bin/clang --use-cc $LLVM_BUILD/bin/clang -o <output_folder_path> -enable-checker osx.cocoa.RetainCount make CC="gcc" CFLAGS='-Wno-nullability-completeness -I/usr/local/include -I/$ISL_SRC -D__isl_give="__attribute__((annotate(\"rc_ownership_returns_retained\")))" -D__isl_take="__attribute__((annotate(\"rc_ownership_consumed\")))"'</span></p></li></ul><li>Run<span style="background-color:transparent;font-family:"Source Code Pro";color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap"> </span>$LLVM_BUILD/bin/scan-view<span style="background-color:transparent;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap"> on the output directory to view the results.</span><br></li></ul><div><font color="#000000" face="Arial"><span style="white-space:pre-wrap"><br></span></font></div><div><font color="#000000" face="Arial"><span style="white-space:pre-wrap"><br></span></font></div><div><font color="#000000" face="Arial"><span style="white-space:pre-wrap">Let me know your thoughts on my final report.</span></font></div><div><font color="#000000" face="Arial"><span style="white-space:pre-wrap"><br></span></font></div><div><font color="#000000" face="Arial"><span style="white-space:pre-wrap"><br></span></font></div><div><font color="#000000" face="Arial"><span style="white-space:pre-wrap">Thank you.</span></font></div><div><font color="#000000" face="Arial"><span style="white-space:pre-wrap"><br></span></font></div><div><font color="#000000" face="Arial"><span style="white-space:pre-wrap"><br></span></font></div><div><font color="#000000" face="Arial"><span style="white-space:pre-wrap"><br></span></font></div><div><font color="#000000" face="Arial"><span style="white-space:pre-wrap">Regards,</span></font></div><div><font color="#000000" face="Arial"><span style="white-space:pre-wrap">Malhar Thakkar</span></font></div></span></div></div><div hspace="streak-pt-mark" style="max-height:1px"><img alt="" style="width:0px;max-height:0px;overflow:hidden" src="https://mailfoogae.appspot.com/t?sender=aY3MxM2IxMDMxQGlpdGguYWMuaW4%3D&type=zerocontent&guid=57ddc826-ac79-4d10-bcef-774a87b6536f"><font color="#ffffff" size="1">ᐧ</font></div>