r182681 - Add some safety checks in a couple of SourceManager functions.

Jordan Rose jordan_rose at apple.com
Fri May 24 16:36:36 PDT 2013


On May 24, 2013, at 16:35 , Argyrios Kyrtzidis <akyrtzi at gmail.com> wrote:

> On May 24, 2013, at 3:40 PM, Jordan Rose <jordan_rose at apple.com> wrote:
> 
>> I see that we're fixing crashes, but why isn't it just part of the precondition for this function that it is never called with an invalid FileID?
> 
> It's not checking the parameters, the source locations it received may be fine, but then getDecomposedLoc() may return an invalid FileID because, for example, the location was in a PCH and the file it referred to was removed from the file system *after* we fully loaded the PCH.
> 
>> 
>> Also, you can't change isBeforeInTranslationUnit that way; the sort's not consistent. Invalid locs should be always before or always after valid locs, or you should assert that this doesn't happen.
> 
> You are right that the return value becomes meaningless; maybe add an optional "bool *Invalid" parameter and allow callers to check that ?

This function is used as a comparator for std::sort and such. I think you can just make an ordering by fiat and it won't hurt anyone.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130524/da050dcf/attachment.html>


More information about the cfe-commits mailing list