<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>Is there any chance of this making it into 3.4? If so, I can work (and think) on it tomorrow, otherwise it can wait, obviously.<br></div>
<div> </div>
<div>(Sorry for the short answer, had a long day.)<br></div>
<div> </div>
<div id="sig19426269"><div class="signature">-- <br></div>
<div class="signature"> Gábor 'ShdNx' Kozár<br></div>
<div class="signature"> kozargabor@gmail.com<br></div>
<div class="signature"> </div>
</div>
<div> </div>
<div> </div>
<div>On Mon, Dec 16, 2013, at 18:50, Jordan Rose wrote:<br></div>
<blockquote type="cite"><div>This does look fairly straightforward, and fairly good! But I'm concerned<br></div>
<div>about the FunctionDecl parameter: the analyzer also allows<br></div>
<div>ObjCMethodDecls and BlockDecls to be analyzed as top-level entry points.<br></div>
<div>Perhaps a PointerUnion3 would be the best thing to do here, at least for<br></div>
<div>now? Or alternately, we allow people to specify which initial state<br></div>
<div>they're checking, either by having several callbacks or using a template<br></div>
<div>parameter. What do you think?<br></div>
<div> </div>
<div>Also, one nice thing about checkInitialState is that it can be non-const,<br></div>
<div>since it is guaranteed to run 0 or 1 times before the checker is used<br></div>
<div>elsewhere. :-)<br></div>
<div> </div>
<div> </div>
<blockquote><div>- Handling NULL ProgramStateRef-s. I do not think it is reasonable to have NULL as the initial state. Probably assert when a checkInitialState call returns NULL?<br></div>
</blockquote><div> </div>
<div> </div>
<div>I think a NULL initial state means a checker has decided not to analyze<br></div>
<div>this function. Weird and unlikely, but possible. (For example, it allows<br></div>
<div>us to move the -analyze-function option into a checker.)<br></div>
<div> </div>
<blockquote><div>- Whether to call the checkInitialState callback in ExprEngine::getInitialState, or where getInitialState is used. I found one such method: CoreEngine::ExecuteWorkList. Logically - knowing nothing of the codebase -, I think it makes sense to do this in getInitialState. It does not appear to belong to CoreEngine, especially since I cannot find any references to getCheckerManager() in CoreEngine.<br></div>
</blockquote><div> </div>
<div> </div>
<div>I agree. Can you explain why you needed to move the getInitialState call<br></div>
<div>earlier? It seems dangerous to run checkers before we have a block<br></div>
<div>counter in place, since conjured symbols use the block count.<br></div>
<div> </div>
<div>Do we have any checkers that can use this? Perhaps as proof-of-concept<br></div>
<div>you can move the check for main's argc and argv into a checker.<br></div>
<div> </div>
<div> </div>
<blockquote><div>Once checkInitialState is working, I also plan to do a void checkBeginFunction(const FunctionDecl*, CheckerContext&) const, i.e. a callback that is called whenever a function is entered, either through a function call (this would be triggered right after checkPreCall) or when it is the entry point of the analysis.<br></div>
</blockquote><div> </div>
<div> </div>
<div>I'm not sold on this one yet. I mean, I get the idea, but it again seems<br></div>
<div>like something where we want a nicer interface than just "FunctionDecl"<br></div>
<div>(and at the very least need to handle ObjCMethodDecl as well). But we can<br></div>
<div>discuss this later.<br></div>
<div> </div>
<div>I think you'd implement this by calling checkBeginFunction right after<br></div>
<div>checkInitialState and also from ExprEngine::inlineCall (right after<br></div>
<div>"State->enterStackFrame(...)")<br></div>
<div> </div>
<div> </div>
<div>Finally, style notes (guessing this comes from bouncing between<br></div>
<div>projects):<br></div>
<div> </div>
<blockquote><div>+ if(!State) return NULL; // exit early in case of unfeasible state<br></div>
</blockquote><div> </div>
<div> </div>
<div>Space after if, consequent statement on a separate line, comments also on<br></div>
<div>a separate line (and in the form of a complete sentence, with<br></div>
<div>capitalization and a period).<br></div>
<div> </div>
<div>Thank you for putting this together!<br></div>
<div>Jordan<br></div>
<div> </div>
<div> </div>
<div>On Dec 13, 2013, at 17:03 , Gabor Kozar <<a href="mailto:kozargabor@gmail.com">kozargabor@gmail.com</a>> wrote:<br></div>
<div> </div>
<blockquote><div>Hi Jordan,<br></div>
<div> </div>
<div>I had an issue recently with the Static Analyzer that I wouldn't be able to detect when a function was entered - either through a call or serving as the entry point of the analysis. (I ended up using checkPreStmt and figuring out if we've been magically transported inside a function body and check the program state whether the necessary info was already recorded by checkPreCall. Not something I'd call nice by any means.)<br></div>
<div> </div>
<div>So I wrote to cfg-dev and you mentioned that you had no such callbacks currently implemented, although they have been needed before, and that patches were welcome. Since this is a fairly trivial project, I was comfortable with doing it in my very limited free time (especially because I still intend to work on the Static Analyzer open projects at some point when I'm able).<br></div>
<div> </div>
<div>Find the diff file attached. Since you've pointed me to ExprEngine::getInitialState, I just modified it to call any checkers registered for check::InitialState at the end. So the signature for the callback is:<br></div>
<div>ProgramStateRef checkInitialState(const FunctionDecl*, ProgramStateRef) const<br></div>
<div> </div>
<div>There are a few things I'm not sure about:<br></div>
<div>- Handling NULL ProgramStateRef-s. I do not think it is reasonable to have NULL as the initial state. Probably assert when a checkInitialState call returns NULL?<br></div>
<div>- Whether to call the checkInitialState callback in ExprEngine::getInitialState, or where getInitialState is used. I found one such method: CoreEngine::ExecuteWorkList. Logically - knowing nothing of the codebase -, I think it makes sense to do this in getInitialState. It does not appear to belong to CoreEngine, especially since I cannot find any references to getCheckerManager() in CoreEngine.<br></div>
<div> </div>
<div>Please let me know what you think!<br></div>
<div> </div>
<div>Once checkInitialState is working, I also plan to do a void checkBeginFunction(const FunctionDecl*, CheckerContext&) const, i.e. a callback that is called whenever a function is entered, either through a function call (this would be triggered right after checkPreCall) or when it is the entry point of the analysis.<br></div>
<div> </div>
<div>I'm not sure about where can I notify the checkers of this though. When is the point when we can say "okay so let's start analyzing this function"? If you could point me to the method, that would help a lot. (Ironically, we also have a code comprehension project running where I work [at Ericsson], but I do not have access to server where we have the Clang trunk parsed, since I'm doing this from home in my free time.)<br></div>
<div> </div>
<div>Thanks!<br></div>
<div> </div>
<div>-- <br></div>
<div>Gábor 'ShdNx' Kozár<br></div>
<div><a href="mailto:kozargabor@gmail.com">kozargabor@gmail.com</a><br></div>
<div> </div>
</blockquote><div> </div>
<p>Email had 1 attachment:<br></p><ul><li><code>patch-checkInitialState.diff</code><br></li><li> 6k (text/x-patch)<br></li></ul></blockquote></body>
</html>