[cfe-commits] r155923 - /cfe/trunk/lib/Frontend/CompilerInstance.cpp

Matthieu Monrocq matthieu.monrocq at gmail.com
Wed May 2 11:55:36 PDT 2012


On Tue, May 1, 2012 at 8:16 PM, David Blaikie <dblaikie at gmail.com> wrote:

> On Tue, May 1, 2012 at 10:56 AM, Ted Kremenek <kremenek at apple.com> wrote:
> > Author: kremenek
> > Date: Tue May  1 12:56:57 2012
> > New Revision: 155923
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=155923&view=rev
> > Log:
> > Remove dead code found by static analyzer.
> >
> > Modified:
> >    cfe/trunk/lib/Frontend/CompilerInstance.cpp
> >
> > Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=155923&r1=155922&r2=155923&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
> > +++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Tue May  1 12:56:57 2012
> > @@ -861,11 +861,6 @@
> >   // Determine what file we're searching from.
> >   SourceManager &SourceMgr = getSourceManager();
> >   SourceLocation ExpandedImportLoc =
> SourceMgr.getExpansionLoc(ImportLoc);
> > -  const FileEntry *CurFile
> > -    =
> SourceMgr.getFileEntryForID(SourceMgr.getFileID(ExpandedImportLoc));
> > -  if (!CurFile)
> > -    CurFile = SourceMgr.getFileEntryForID(SourceMgr.getMainFileID());
>
> Would it be practical for Clang to have a warning that caught this (at
> least incrementally) - the assignment inside the conditional is dead -
> nothing after it reads CurFile, so it would be nice if we warned. (&
> then the user would probably be able to see that the rest of this was
> silly too)
>
> > -
> >   StringRef ModuleName = Path[0].first->getName();
> >   SourceLocation ModuleNameLoc = Path[0].second;
> >
> >
> >
>

It would probably be possible to detect that CurFile is assigned without
being ever read afterwards (using the CFG I guess).

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.

-- Matthieu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120502/9cb06622/attachment.html>


More information about the cfe-commits mailing list