<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div></div><div><br><div><div>On 15 Dec 2013, at 22:27, Richard <<a href="mailto:tarka.t.otter@gmail.com">tarka.t.otter@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Hey Ted,<br><br>Took a while to find the time, attached is the latest patch. Notes below.<br><br>On 04 Dec 2013, at 00:24, Ted Kremenek <<a href="mailto:kremenek@apple.com">kremenek@apple.com</a>> wrote:<br><blockquote type="cite"><br>To start off, this file is missing the standard LLVM boilerplate, which mentions the name of the file and what its purpose is. In this case, a brief description of the purpose of the checker seems warranted.<br><br></blockquote><br>Comments and boilerplate added, methods renamed.<br><br><blockquote type="cite"><blockquote type="cite"> VersionTuple deploymentTarget(ProgramStateRef State) const;<br></blockquote><br>I don’t think this method is even needed. More comments below.<br><br></blockquote><br>There are still a couple of places where this is needed. For example, checking if the introduced version of a function is later than the deployment target, or to output the deployment target in the bug report.<br><br><blockquote type="cite"><blockquote type="cite"> VersionTuple getCheckedForVersion(ProgramStateRef State) const;<br> ProgramStateRef setCheckedForVersion(ProgramStateRef State,<br> VersionTuple V) const;<br> };<br>}<br><br>REGISTER_TRAIT_WITH_PROGRAMSTATE(CheckedVersionMajor, unsigned)<br>REGISTER_TRAIT_WITH_PROGRAMSTATE(CheckedVersionMinor, unsigned)<br>REGISTER_TRAIT_WITH_PROGRAMSTATE(CheckedVersionSubminor, unsigned)<br></blockquote><br>Having three maps is far less efficient than having one map for VersionTuple. It’s not just the size of the individual pieces of data; its the metadata to represent the map itself. All of these seemed to be changed together in lockstep, it is is far more efficient to both retrieve and set data from one map instead of 3. To understand the efficiency, each map is represented by a functional AVL binary tree. Having three trees requires balancing and querying three trees, as well as the memory associated with three trees.<br><br></blockquote><br>Yes, this was supposed to be temporary while I worked out how to stuff a VersionTuple into the program state. After spending a bit of time on this, I am still none the wiser. What is the easiest way to achieve this? To use a single element list of VersionTuple as the type, or is there some other way to extend the PartialProgramState to handle a VersionTuple?<br><br><blockquote type="cite"><blockquote type="cite"><br> VersionTuple Introduced = versionIntroduced(D);<br><br> // If we have an ObjC method with no introduced version, check the class's or<br> // the protocol's introduced version.<br> const NamedDecl *VersionDecl = cast<NamedDecl>(D);<br> if (Introduced.empty()) {<br> if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {<br> const DeclContext *DC = MD->getDeclContext();<br> if (const ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(DC)) {<br> Introduced = versionIntroduced(PD);<br> VersionDecl = PD;<br> } else {<br> const ObjCInterfaceDecl *ID = MD->getClassInterface();<br> Introduced = versionIntroduced(ID);<br> VersionDecl = ID;<br> }<br> }<br> }<br></blockquote><br>This looks like this can be hoisted directly into “versionIntroduced” (or rather, “getVersionIntroduced”). That way getVersionIntroduced() computes the truth as a self-encapsulated information, regardless of whether it consults the map or has to compute some of the information lazily. Also, it doesn’t look like all of the callers to getVersionIntroduced() compute this information consistently; hoisting it into getVersionIntroduced() would solve that problem.<br><br></blockquote><br>Done, although it is a little bit messy as we need both the version tuple and the decl from which it came, so the getVersionIntroduced function now returns a pair.<br><br><blockquote type="cite"><blockquote type="cite"><br> if (TargetMinVersion >= Introduced)<br> return;<br><br> // We have a method being called that is available later than the minimum<br> // deployment target, so we need to check for any availability checks.<br> VersionTuple CheckedVersion = getCheckedForVersion(State);<br> if (CheckedVersion >= Introduced)<br> return;<br><br> if (ExplodedNode *N = Ctx.addTransition(State)) {<br> displayError(State, Introduced, VersionDecl, N, &Ctx.getBugReporter());<br> }<br></blockquote><br>This is good, but maybe we should only emit a warning once along a path. I’m concerned about a cascade of warnings. For example, say I had 10 function calls, one after the other, that were used unsafely, but would be safely guarded with a single check. We really don’t need 10 warnings; we only need one. If we stopped tracking version information along a path, we could perhaps only emit the warning once? One way to do that would be to pump up the checked version to something really high and store that in the state. A call to ‘addTransition()’ doesn’t stop the path; the analyzer will keep exploring a path.<br><br></blockquote><br>Is it not sufficient to just change this to a generateSink instead of addTransition?<br><br><blockquote type="cite"><blockquote type="cite">void ento::registerUnavailableMethodChecker(CheckerManager &mgr) {<br> mgr.registerChecker<UnavailableMethodChecker>();<br></blockquote><br>As mentioned earlier, you can put some checking for deployment information right here. If the context doesn’t support running the checker, just don’t run it at all.<br><br></blockquote><br>This is a nice idea, but how can we get hold of the context here?<span class="Apple-converted-space"> </span><br><br><blockquote type="cite"><blockquote type="cite">}<br></blockquote><br>For the test cases, they look like a good start. One thing I’d like to see is a test case that shows two unsafe calls one after the other. For example, you currently have:<br><br><blockquote type="cite">- (void)doVersion30InstanceStuff {<br> [super doVersion30InstanceStuff]; // no warning<br> [self doVersion40InstanceStuff]; // expected-warning {{Calling method introduced in OS X 40.0 (deployment target is 10.5.0)}}<br>}<br></blockquote><br><br>Try adding a third call here, maybe just repeating the second line:<br><br><blockquote type="cite">- (void)doVersion30InstanceStuff_B {<br> [super doVersion30InstanceStuff]; // no warning<br> [self doVersion40InstanceStuff]; // expected-warning {{Calling method introduced in OS X 40.0 (deployment target is 10.5.0)}}<br> [self doVersion40InstanceStuff]; // expected-warning {{Calling method introduced in OS X 40.0 (deployment target is 10.5.0)}}<br>}<br></blockquote><br><br>Right now I’d expect to see two warnings. It would be great to get them down to one (just the first one).<br><br></blockquote><br>Done.<br><br><blockquote type="cite">Overall this is looking really great. Thanks so much for working on this!<br><br>Cheers,<br>Ted<br></blockquote><br>Other than the state map and the checker registration, I think I have everything else covered. Let me know what you think.<br><br>Ta,<br>Richard.</div></blockquote></div><br></div></body></html>