<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">On May 24, 2013, at 3:40 PM, Jordan Rose <<a href="mailto:jordan_rose@apple.com">jordan_rose@apple.com</a>> wrote:<br><div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="letter-spacing: 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; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>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?</div></div></blockquote><div><br></div><div>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.</div><br><blockquote type="cite"><div style="letter-spacing: 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; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div><br></div><div>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.</div></div></blockquote><div><br></div><div>You are right that the return value becomes meaningless; maybe add an optional "bool *Invalid" parameter and allow callers to check that ?</div><br><blockquote type="cite"><div style="letter-spacing: 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; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div><br></div><div>Jordan</div><div><br></div><br><div><div>On May 24, 2013, at 15:24 , Argyrios Kyrtzidis <<a href="mailto:akyrtzi@gmail.com">akyrtzi@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="letter-spacing: 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;">Author: akirtzidis<br>Date: Fri May 24 17:24:04 2013<br>New Revision: 182681<br><br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=182681&view=rev">http://llvm.org/viewvc/llvm-project?rev=182681&view=rev</a><br>Log:<br>Add some safety checks in a couple of SourceManager functions.<br><br>This is to address crash in<span class="Apple-converted-space"> </span><a href="rdar://13932308">rdar://13932308</a><br><br>Modified:<br>   cfe/trunk/lib/Basic/SourceManager.cpp<br><br>Modified: cfe/trunk/lib/Basic/SourceManager.cpp<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=182681&r1=182680&r2=182681&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=182681&r1=182680&r2=182681&view=diff</a><br>==============================================================================<br>--- cfe/trunk/lib/Basic/SourceManager.cpp (original)<br>+++ cfe/trunk/lib/Basic/SourceManager.cpp Fri May 24 17:24:04 2013<br>@@ -1958,6 +1958,9 @@ SourceManager::getMacroArgExpandedLocati<br><br>std::pair<FileID, unsigned><br>SourceManager::getDecomposedIncludedLoc(FileID FID) const {<br>+  if (FID.isInvalid())<br>+    return std::make_pair(FileID(), 0);<br>+<br>  // Uses IncludedLocMap to retrieve/cache the decomposed loc.<br><br>  typedef std::pair<FileID, unsigned> DecompTy;<br>@@ -1969,11 +1972,14 @@ SourceManager::getDecomposedIncludedLoc(<br>    return DecompLoc; // already in map.<br><br>  SourceLocation UpperLoc;<br>-  const SrcMgr::SLocEntry &Entry = getSLocEntry(FID);<br>-  if (Entry.isExpansion())<br>-    UpperLoc = Entry.getExpansion().getExpansionLocStart();<br>-  else<br>-    UpperLoc = Entry.getFile().getIncludeLoc();<br>+  bool Invalid = false;<br>+  const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid);<br>+  if (!Invalid) {<br>+    if (Entry.isExpansion())<br>+      UpperLoc = Entry.getExpansion().getExpansionLocStart();<br>+    else<br>+      UpperLoc = Entry.getFile().getIncludeLoc();<br>+  }<br><br>  if (UpperLoc.isValid())<br>    DecompLoc = getDecomposedLoc(UpperLoc);<br>@@ -2033,6 +2039,9 @@ bool SourceManager::isBeforeInTranslatio<br>  std::pair<FileID, unsigned> LOffs = getDecomposedLoc(LHS);<br>  std::pair<FileID, unsigned> ROffs = getDecomposedLoc(RHS);<br><br>+  if (LOffs.first.isInvalid() || ROffs.first.isInvalid())<br>+    return false;<br>+<br>  // If the source locations are in the same file, just compare offsets.<br>  if (LOffs.first == ROffs.first)<br>    return LOffs.second < ROffs.second;<br><br><br>_______________________________________________<br>cfe-commits mailing list<br><a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a></div></blockquote></div></div></blockquote></div><br></body></html>