void PathDiagnosticClient::HandleDiagnostic(Diagnostic::Level DiagLevel,
                                            const DiagnosticInfo &Info) {

  // Create a PathDiagnostic with a single piece.

  PathDiagnostic* D = new PathDiagnostic();

  const char *LevelStr;
  switch (DiagLevel) {
  default:
  case Diagnostic::Ignored: assert(0 && "Invalid diagnostic type");
  case Diagnostic::Note:    LevelStr = "note: "; break;
  case Diagnostic::Warning: LevelStr = "warning: "; break;
  case Diagnostic::Error:   LevelStr = "error: "; break;
  case Diagnostic::Fatal:   LevelStr = "fatal error: "; break;
  }

  llvm::SmallString<100> StrC;
  StrC += LevelStr;
  Info.FormatDiagnostic(StrC);

  PathDiagnosticPiece *P =
    new PathDiagnosticEventPiece(Info.getLocation(), StrC.str());

  for (unsigned i = 0, e = Info.getNumRanges(); i != e; ++i)
    P->addRange(Info.getRange(i));
  for (unsigned i = 0, e = Info.getNumCodeModificationHints(); i != e; ++i)
    P->addCodeModificationHint(Info.getCodeModificationHint(i));
  D->push_front(P);

  HandlePathDiagnostic(D);
}
Exemplo n.º 2
0
PathDiagnosticPiece*
BugReporterVisitor::getDefaultEndPath(BugReporterContext &BRC,
                                      const ExplodedNode *EndPathNode,
                                      BugReport &BR) {
  PathDiagnosticLocation L =
    PathDiagnosticLocation::createEndOfPath(EndPathNode,BRC.getSourceManager());

  BugReport::ranges_iterator Beg, End;
  llvm::tie(Beg, End) = BR.getRanges();

  // Only add the statement itself as a range if we didn't specify any
  // special ranges for this report.
  PathDiagnosticPiece *P = new PathDiagnosticEventPiece(L,
      BR.getDescription(),
      Beg == End);
  for (; Beg != End; ++Beg)
    P->addRange(*Beg);

  return P;
}
Exemplo n.º 3
0
PathDiagnosticPiece*
BugReporterVisitor::getDefaultEndPath(BugReporterContext &BRC,
                                      const ExplodedNode *EndPathNode,
                                      BugReport &BR) {
    const ProgramPoint &PP = EndPathNode->getLocation();
    PathDiagnosticLocation L;

    if (const BlockEntrance *BE = dyn_cast<BlockEntrance>(&PP)) {
        const CFGBlock *block = BE->getBlock();
        if (block->getBlockID() == 0) {
            L = PathDiagnosticLocation::createDeclEnd(PP.getLocationContext(),
                    BRC.getSourceManager());
        }
    }

    if (!L.isValid()) {
        const Stmt *S = BR.getStmt();

        if (!S)
            return NULL;

        L = PathDiagnosticLocation(S, BRC.getSourceManager(),
                                   PP.getLocationContext());
    }

    BugReport::ranges_iterator Beg, End;
    llvm::tie(Beg, End) = BR.getRanges();

    // Only add the statement itself as a range if we didn't specify any
    // special ranges for this report.
    PathDiagnosticPiece *P = new PathDiagnosticEventPiece(L,
            BR.getDescription(),
            Beg == End);
    for (; Beg != End; ++Beg)
        P->addRange(*Beg);

    return P;
}