[cfe-commits] r151774 - in /cfe/trunk/lib/StaticAnalyzer/Core: PathDiagnostic.cpp PlistDiagnostics.cpp

David Blaikie dblaikie at gmail.com
Wed Feb 29 16:19:26 PST 2012


On Wed, Feb 29, 2012 at 3:59 PM, Ted Kremenek <kremenek at apple.com> wrote:
> Author: kremenek
> Date: Wed Feb 29 17:59:20 2012
> New Revision: 151774
>
> URL: http://llvm.org/viewvc/llvm-project?rev=151774&view=rev
> Log:
> [analyzer] when scanning FIDs in a PathDiagnostic, correctly recurse calls and macros.

Is there a test case for this? I haven't managed to (nor tried to
hard) wrap my head around the change & thought a test case would make
it clearer what's being enabled/fixed here.

- David

>
> Modified:
>    cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
>    cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
>
> Modified: cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp?rev=151774&r1=151773&r2=151774&view=diff
> ==============================================================================
> --- cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp (original)
> +++ cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp Wed Feb 29 17:59:20 2012
> @@ -93,26 +93,43 @@
>     // Verify that the entire path is from the same FileID.
>     FileID FID;
>     const SourceManager &SMgr = (*D->path.begin())->getLocation().getManager();
> +    llvm::SmallVector<const PathPieces *, 5> WorkList;
> +    WorkList.push_back(&D->path);
>
> -    for (PathPieces::const_iterator I = D->path.begin(), E = D->path.end();
> -         I != E; ++I) {
> -      FullSourceLoc L = (*I)->getLocation().asLocation().getExpansionLoc();
> +    while (!WorkList.empty()) {
> +      const PathPieces &path = *WorkList.back();
> +      WorkList.pop_back();
> +
> +      for (PathPieces::const_iterator I = path.begin(), E = path.end();
> +           I != E; ++I) {
> +        const PathDiagnosticPiece *piece = I->getPtr();
> +        FullSourceLoc L = piece->getLocation().asLocation().getExpansionLoc();
>
> -      if (FID.isInvalid()) {
> -        FID = SMgr.getFileID(L);
> -      } else if (SMgr.getFileID(L) != FID)
> -        return; // FIXME: Emit a warning?
> -
> -      // Check the source ranges.
> -      for (PathDiagnosticPiece::range_iterator RI = (*I)->ranges_begin(),
> -           RE = (*I)->ranges_end();
> -           RI != RE; ++RI) {
> -        SourceLocation L = SMgr.getExpansionLoc(RI->getBegin());
> -        if (!L.isFileID() || SMgr.getFileID(L) != FID)
> -          return; // FIXME: Emit a warning?
> -        L = SMgr.getExpansionLoc(RI->getEnd());
> -        if (!L.isFileID() || SMgr.getFileID(L) != FID)
> +        if (FID.isInvalid()) {
> +          FID = SMgr.getFileID(L);
> +        } else if (SMgr.getFileID(L) != FID)
>           return; // FIXME: Emit a warning?
> +
> +        // Check the source ranges.
> +        for (PathDiagnosticPiece::range_iterator RI = piece->ranges_begin(),
> +             RE = piece->ranges_end();
> +             RI != RE; ++RI) {
> +          SourceLocation L = SMgr.getExpansionLoc(RI->getBegin());
> +          if (!L.isFileID() || SMgr.getFileID(L) != FID)
> +            return; // FIXME: Emit a warning?
> +          L = SMgr.getExpansionLoc(RI->getEnd());
> +          if (!L.isFileID() || SMgr.getFileID(L) != FID)
> +            return; // FIXME: Emit a warning?
> +        }
> +
> +        if (const PathDiagnosticCallPiece *call =
> +            dyn_cast<PathDiagnosticCallPiece>(piece)) {
> +          WorkList.push_back(&call->path);
> +        }
> +        else if (const PathDiagnosticMacroPiece *macro =
> +                 dyn_cast<PathDiagnosticMacroPiece>(piece)) {
> +          WorkList.push_back(&macro->subPieces);
> +        }
>       }
>     }
>
>
> Modified: cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp?rev=151774&r1=151773&r2=151774&view=diff
> ==============================================================================
> --- cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp (original)
> +++ cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp Wed Feb 29 17:59:20 2012
> @@ -324,19 +324,38 @@
>   if (!Diags.empty())
>     SM = &(*(*Diags.begin())->path.begin())->getLocation().getManager();
>
> +
>   for (std::vector<const PathDiagnostic*>::iterator DI = Diags.begin(),
>        DE = Diags.end(); DI != DE; ++DI) {
>
>     const PathDiagnostic *D = *DI;
>
> -    for (PathPieces::const_iterator I = D->path.begin(), E = D->path.end();
> -         I!=E; ++I) {
> -      AddFID(FM, Fids, SM, (*I)->getLocation().asLocation());
> -
> -      for (PathDiagnosticPiece::range_iterator RI = (*I)->ranges_begin(),
> -           RE= (*I)->ranges_end(); RI != RE; ++RI) {
> -        AddFID(FM, Fids, SM, RI->getBegin());
> -        AddFID(FM, Fids, SM, RI->getEnd());
> +    llvm::SmallVector<const PathPieces *, 5> WorkList;
> +    WorkList.push_back(&D->path);
> +
> +    while (!WorkList.empty()) {
> +      const PathPieces &path = *WorkList.back();
> +      WorkList.pop_back();
> +
> +      for (PathPieces::const_iterator I = path.begin(), E = path.end();
> +           I!=E; ++I) {
> +        const PathDiagnosticPiece *piece = I->getPtr();
> +        AddFID(FM, Fids, SM, piece->getLocation().asLocation());
> +
> +        for (PathDiagnosticPiece::range_iterator RI = piece->ranges_begin(),
> +             RE= piece->ranges_end(); RI != RE; ++RI) {
> +          AddFID(FM, Fids, SM, RI->getBegin());
> +          AddFID(FM, Fids, SM, RI->getEnd());
> +        }
> +
> +        if (const PathDiagnosticCallPiece *call =
> +            dyn_cast<PathDiagnosticCallPiece>(piece)) {
> +          WorkList.push_back(&call->path);
> +        }
> +        else if (const PathDiagnosticMacroPiece *macro =
> +                 dyn_cast<PathDiagnosticMacroPiece>(piece)) {
> +          WorkList.push_back(&macro->subPieces);
> +        }
>       }
>     }
>   }
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list