<div dir="ltr">Hi Jordan,<div><br></div><div>Thanks! Running it with the clang driver made it work. Regarding the clang frontend, I couldn't make it work by using "-analyzer-checker=core,alpha.mychecker", but "-analyzer-checker=core,osx,alpha.mychecker" did work!</div>
<div><br></div><div>Best regards,</div><div>Rafael</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, May 28, 2014 at 12:25 AM, Jordan Rose <span dir="ltr"><<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>></span> wrote:<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>It's worth noting that running without the core checkers enabled isn't really a sane state for the analyzer. You should either pass "core,alpha.mychecker.MyChecker" to -analyzer-checker, or use "clang --analyze" instead of "clang -cc1 -analyze" and use "-Xanalyzer" to pass down the -analyzer-checker option.</div>
<span class="HOEnZb"><font color="#888888"><div><br></div><div>Jordan</div></font></span><div><div class="h5"><br><div><div>On May 26, 2014, at 18:36 , Rafael Auler <<a href="mailto:rafaelauler@gmail.com" target="_blank">rafaelauler@gmail.com</a>> wrote:</div>
<br><blockquote type="cite"><div dir="ltr">Hi Jordan,<div><br></div><div>I'm using the tagged version 3.4, do you think it is an issue that got fixed in trunk? I am quite sure that I have it enabled, since I put some debugging printfs and saw the results:</div>
<div><br></div><div>-1 = doNotCallTwice() has not been called before<br></div><div>0 = doNotCallTwice() has been called before</div><div><br></div><div><div>rafael$ clang -cc1 -analyze -analyzer-checker=alpha.mychecker.MyChecker mytest.c</div>
<div>doNotCallTwice! -1</div><div>doNotCallTwice! -1</div><div>doNotCallTwice! -1</div><div>rafael$ vim mytest.c # change to avoid folding</div><div>rafael$ clang -cc1 -analyze -analyzer-checker=alpha.mychecker.MyChecker mytest.c</div>
<div>doNotCallTwice! -1</div><div>doNotCallTwice! -1</div><div>doNotCallTwice! -1</div><div>doNotCallTwice! 0</div><div>mytest.c:8:5: warning: Called twice</div><div> doNotCallTwice();</div><div> ^~~~~~~~~~~~~~~~</div>
<div>1 warning generated.</div></div><div><br></div><div><br></div><div>In the first case, I use only function calls in the test case. In the second, I put the extra statement that forces the engine to avoid folding, and the detection finally works.</div>
<div><br></div><div>Thanks,</div><div>Rafael</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, May 26, 2014 at 5:52 PM, Jordan Rose <span dir="ltr"><<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>></span> wrote:<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>Hm, if I drop this into my clang sources (and update it to match changes in trunk), I don't see any issues with what you've written—building and running it on your sample input works fine. Are you sure you have it enabled? (I forgot to pass -analyzer-checker on my first test, so I have to ask.)</div>
<div><br></div><div>Jordan</div><br><div><div><div><div>On May 25, 2014, at 7:28 , Rafael Auler <<a href="mailto:rafaelauler@gmail.com" target="_blank">rafaelauler@gmail.com</a>> wrote:</div><br></div></div>
<blockquote type="cite"><div><div><div dir="ltr">Hi Jordan,<div><br></div><div>Sure, it is attached. Thanks for taking a look at this. </div><div><br></div><div>Cheers,</div><div>Rafael</div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Sun, May 25, 2014 at 4:13 AM, Jordan Rose <span dir="ltr"><<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, Rafael. From your description, this sounds like a bug in the analyzer—two program states with differing user data should not be folded. Can you attach your checker so I can take a look and see if there are any obvious mistakes? (on your part or ours).<br>
<br>
Thanks,<br>
Jordan<br>
<div><br>
On May 24, 2014, at 22:01 , Rafael Auler <<a href="mailto:rafaelauler@gmail.com" target="_blank">rafaelauler@gmail.com</a>> wrote:<br>
<br>
> Hello,<br>
><br>
> I am trying to write a very simple checker for the clang static analyzer for the sake of writing a first exercise on this topic. Its goal is to simply alert whether a specific function has been called twice in a given path. Let's assume the name of this specific function that I am tracking is "doNotCallTwice()".<br>
><br>
> In order to record state information, I use the REGISTER_TRAIT_WITH_PROGRAMSTATE macro to register an unsigned together with the program state. This integer indicates whether the function "doNotCallTwice()" has been called in a path and, if it is equal to 1 in a node where I detect yet another call, I prepare to report a "double call" bug. I use "checkPostCall" for changing the state.<br>
><br>
> However, something strange happens. My extra integer registered in the program state is not sufficient to differentiate two ProgramStates with the same ProgramPoint: the engine fold the two nodes anyway, ignoring my new state information. On the other hand, the information *is* propagated. If I use other ways to avoid the nodes being folded, the checker works fine.<br>
><br>
> An example where it does not work:<br>
><br>
> void myfunc (int x, int y) {<br>
> if (x)<br>
> doNotCallTwice();<br>
> if (y)<br>
> doNotCallTwice();<br>
> doNotCallTwice();<br>
> }<br>
><br>
> Since programstates get folded in the ExplodedGraph, I never detect any path where two calls to doNotCallTwice() happen. However, change the code in the following way avoids the folding and make my checker work:<br>
><br>
> void myfunc (int x, int y) {<br>
> if (x)<br>
> doNotCallTwice();<br>
> if (y)<br>
> doNotCallTwice();<br>
> y = x; // Now x and y are not dead anymore and this won't be folded<br>
> doNotCallTwice();<br>
> }<br>
><br>
> I based my checker on SimpleStreamChecker.cpp. Am I doing something conceptually wrong?<br>
><br>
> Best regards,<br>
> Rafael<br>
</div>> _______________________________________________<br>
> cfe-dev mailing list<br>
> <a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br>
</blockquote></div><br></div>
</div></div><span><MyChecker.cpp></span><span><mytest.c></span></blockquote></div><br></div></blockquote></div><br></div>
</blockquote></div><br></div></div></div></blockquote></div><br></div>