<div dir="ltr"><div class="gmail_quote"><div dir="ltr">Clang Experts,<div><br></div><div>I'm interested in using the CSA to track various aspects and properties of values in C++ programs. For example, if I decide that a value or object should be colored blue, then it should remain blue throughout its life in the translation unit. So far, I've been using the following map with some degree of success:</div><div><br></div><div>REGISTER_MAP_WITH_PROGRAMSTATE(ColorMap, const MemRegion *, Color)<br></div><div><br></div><div>So rather than coloring the values, I'm coloring their associated memory. Furthermore, when blue memory is copied to another location, the target location is also colored blue (using checkBind). In the following typical case, my strategy works fine:</div><div><br></div><div>void foo (int *j) {</div><div>    *j += 3; // in this statement, color the memory pointed to by j "blue"</div><div>    return;</div><div>}</div><div><br></div><div>void bar () {</div><div>    int i = 42;</div><div>    foo(&i);</div><div>    i -= 3; // in this statement, i is still "blue"</div><div>}</div><div><br></div><div>But the following will NOT work:</div><div><br></div><div><div>int foo (int j) {</div><div>    j += 3; // in this statement, color j's memory "blue"</div><div>    return j;</div><div>}</div><div><br></div><div>void bar () {</div><div>    int i = 42;</div><div>    int k = foo(i);</div><div>    k -= 3; // in this statement, k is not "blue", though I want it to be</div><div>}</div></div><div><br></div><div>The reason why this doesn't work is that in the second example, j is returned by foo() by value, meaning it's copied, and so the k inside bar() no longer refers to the same (blue) memory region. This would be fine if checkBind() were to catch such copies, but apparently it does not. The same problem arises when variables are passed by value to a function. For example, if I had colored i blue in bar() before calling foo(i), then i would no longer be blue inside foo();</div><div><br></div><div>My second approach was to also allow for the coloring of SVal's:</div><div><br></div><div>REGISTER_MAP_WITH_PROGRAMSTATE(ColorSValMap, SVal *, Color)<br></div><div><br></div><div>But this led to other problems, because apparently SVal's are not unique, and are recycled. So a lot of values were being incorrectly labeled as blue.</div><div><br></div><div>Any help would be very much appreciated. BTW I'm using Clang 3.5.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>~Scott Constable</div></font></span></div>
</div><br></div>