<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">I'll implement this.<div><br><div><div>On Jun 18, 2010, at 1:26 PM, Douglas Gregor wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jun 17, 2010, at 7:47 PM, Tom Care wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">I think there might be other things broken in this function too.<div><br></div><div>I'm having problems trying to get highlighting/fixits working for parts of printf statements (rather than the whole thing).</div><div><br></div><div>Currently, if I give a SourceLocation within a printf formatting string, it will highlight it from the beginning until the end of the format string (rather than the end I specified). For example:</div><div><br></div><div><div><font class="Apple-style-span" face="'Courier New'"><div>/tmp/fixit.c:13:15: warning: precision used with 'n' conversion specifier,</div><div>      resulting in undefined behavior [-Wformat]</div><div>  printf("%100.100n", (int*) 0);</div><div>              ^~~~~</div><div><br></div></font></div><div>When what I expect is:</div><div><div><font class="Apple-style-span" face="'Courier New'"><div>/tmp/fixit.c:13:15: warning: precision used with 'n' conversion specifier,</div><div>      resulting in undefined behavior [-Wformat]</div><div>  printf("%100.100n", (int*) 0);</div><div>              ^~~~</div><div><br></div></font></div></div><div>This ends up breaking the fixits, which delete the rest of the format string rather than the invalid part.</div><div><br></div><div>The offending line is lib/Frontend/TextDiagnosticPrinter.cpp:116</div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(82, 145, 114); "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(82, 145, 114); "><span style="color: #000000">      </span>// Add in the length of the token, so that we cover <span style="text-decoration: underline">multi</span>-char tokens.</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(82, 145, 114); "><span style="color: #000000">      </span><font class="Apple-style-span">EndColNo += </font><span style="text-decoration: underline"><font class="Apple-style-span">Lexer</font></span><font class="Apple-style-span">::MeasureTokenLength(End, SM, *LangOpts);</font></div></div></div><div><br></div><div>I'm sure this line has importance, but I don't think it is correct.</div><div><br></div><div>I'm a bit lost in this section! Does anyone have any ideas?</div></div></div></blockquote><br></div><div>The mental model for a source range is that it is a pair of source locations [B, E), where both B and E are expected to point at the beginning of the token. That line above is relexing the token at the location E to find the end of the token. Since you've adjusted the ranges to point at specific characters, when you're getting is E adjusted to the end of the "token" where you're pointing... which is in the middle of a string literal, hence the somewhat odd highlighting behavior.</div><div><br></div><div>We would need to introduce a new notion (e.g., a new "CharacterSourceRange") that forgoes this adjustment and treats the ending source location in the range as character-level positions in the source rather than token-level positions. CharacterSourceRange would only be used in limited places when needed, such as FixItHint and perhaps Diagnostic, and all affected clients would need to be updated.</div><div><br></div><div>  - Doug</div><br></div>_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev<br></blockquote></div><br></div></body></html>