<div dir="ltr"><div>Watching that presentation you mention was one of the 1st things I did some time ago. I think I'll watch it again to refresh.<br><br></div><div>I'll reread again the docs with your comments in mind.<br>
</div><div><br></div>Thanks for the clarifications, Jordan.</div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-05-08 6:02 GMT+02:00 Jordan Rose <span dir="ltr"><<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Hello, Aitor. I'm afraid you're still getting SVals, symbols, and MemRegions somewhat mixed up. They are not interchangeable. Have you watched our presentation on writing a checker yet? (Linked here: <a href="http://clang-analyzer.llvm.org/checker_dev_manual.html" target="_blank">http://clang-analyzer.llvm.org/checker_dev_manual.html</a>) I'm sorry it's not really incorporated into the rest of the Checker Development Manual, but the video is probably still the clearest introduction to analyzer core concepts that we have.</div>
<div><br></div><div><br></div><div><div class=""><blockquote type="cite"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr">1) To test if Loc is a MemRegionVal I use the following, but there's something wrong I can't figure out (it doesn't compile), and I'm stuck (as far as I know, MemRegionVal is a subclass of SVal):<br>
<br><span style="font-family:'courier new',monospace">if (clang::isa<loc::MemRegionVal></span><span style="font-family:'courier new',monospace">(Loc)) ...</span><span style="font-family:arial,helvetica,sans-serif"><br>
</span><span style="font-family:'courier new',monospace"></span></div></blockquote></div></div></blockquote><div><br></div></div><div><div>This is a bit mundane—you can only use isa<> on pointers and references, but SVals are passed around by value. As you discovered, you can use getAs.</div>
</div><div class=""><div><br></div><div><blockquote type="cite"><div dir="ltr"><div><div><span style="font-family:'courier new',monospace"><span style="font-family:arial,helvetica,sans-serif">SymbolRef sym = L->getAsLocSymbol();<br>
</span></span></div><span style="font-family:'courier new',monospace"><span style="font-family:arial,helvetica,sans-serif"></span></span><span style="font-family:'courier new',monospace"><span style="font-family:arial,helvetica,sans-serif">SymbolRef sym = VLoc.getAsLocSymbol();<br>
</span></span></div><span style="font-family:'courier new',monospace"><span style="font-family:arial,helvetica,sans-serif"></span></span><span style="font-family:'courier new',monospace"><span style="font-family:arial,helvetica,sans-serif">SymbolRef sym = VLoc.getAsSymbol()</span></span>;<br>
<div></div></div></blockquote></div><div><br></div></div><div>The second one will handle everything the first one handles, as well as locations cast to integer values (like "(intptr_t)&x"). The last one will also give you back symbols for non-location values. But not all memory regions are based on symbols (a local variable does not need a symbol), and of course not all symbolic values are memory regions (the result of random() is an integer).</div>
<div class=""><div><br></div><br><blockquote type="cite"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><span style="font-family:'courier new',monospace"><span style="font-family:arial,helvetica,sans-serif">2) ElementRegion doesn't belong to the SVal class hierarchy</span></span>. <span style="font-family:'courier new',monospace"><span style="font-family:arial,helvetica,sans-serif">How can I know if Loc is an ElementRegin?</span></span></div>
</blockquote></div></div></blockquote><br></div></div><div>That's not really a good question. What you really want to know is if a given location is within a constant string region. That's a much simpler question.</div>
<div><br></div><div>// Does this value represent the address of a region?</div><div>const MemRegion *MR = V.getAsRegion();</div><div>if (!MR)</div><div>  return;</div><div><br></div><div>bool isString = isa<StringRegion>(MR->getBaseRegion());</div>
<div><br></div><div>This isn't going to cover <i>all</i> use cases, but it does cover this one much more nicely than trying to pattern-match on ElementRegion.</div><div><br></div><div>(Finally, of course, -fconst-strings is a much safer way to handle this kind of issue, but that doesn't help if you have an existing codebase.)</div>
<span class="HOEnZb"><font color="#888888"><div><br></div><div>Jordan</div><div><br></div></font></span></div></blockquote></div><br></div>