<br><br><div class="gmail_quote">On Tue, May 1, 2012 at 8:16 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Tue, May 1, 2012 at 10:56 AM, Ted Kremenek <<a href="mailto:kremenek@apple.com">kremenek@apple.com</a>> wrote:<br>
> Author: kremenek<br>
> Date: Tue May  1 12:56:57 2012<br>
> New Revision: 155923<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=155923&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=155923&view=rev</a><br>
> Log:<br>
> Remove dead code found by static analyzer.<br>
><br>
> Modified:<br>
>    cfe/trunk/lib/Frontend/CompilerInstance.cpp<br>
><br>
> Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=155923&r1=155922&r2=155923&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=155923&r1=155922&r2=155923&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)<br>
> +++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Tue May  1 12:56:57 2012<br>
> @@ -861,11 +861,6 @@<br>
>   // Determine what file we're searching from.<br>
>   SourceManager &SourceMgr = getSourceManager();<br>
>   SourceLocation ExpandedImportLoc = SourceMgr.getExpansionLoc(ImportLoc);<br>
> -  const FileEntry *CurFile<br>
> -    = SourceMgr.getFileEntryForID(SourceMgr.getFileID(ExpandedImportLoc));<br>
> -  if (!CurFile)<br>
> -    CurFile = SourceMgr.getFileEntryForID(SourceMgr.getMainFileID());<br>
<br>
</div>Would it be practical for Clang to have a warning that caught this (at<br>
least incrementally) - the assignment inside the conditional is dead -<br>
nothing after it reads CurFile, so it would be nice if we warned. (&<br>
then the user would probably be able to see that the rest of this was<br>
silly too)<br>
<div class="HOEnZb"><div class="h5"><br>
> -<br>
>   StringRef ModuleName = Path[0].first->getName();<br>
>   SourceLocation ModuleNameLoc = Path[0].second;<br>
><br>
><br>
><br></div></div></blockquote></div><br>It would probably be possible to detect that CurFile is assigned without being ever read afterwards (using the CFG I guess).<br><br>However we would have to leave it up to the user to detect that the function invocation is now useless, since C++ has unfortunately no notion of purity.<br>
<br>-- Matthieu<br>