clang 24.0.0git
VerifyDiagnosticConsumer.cpp File Reference
#include "clang/Frontend/VerifyDiagnosticConsumer.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticFrontend.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TokenKinds.h"
#include "clang/Frontend/TextDiagnosticBuffer.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/Lexer.h"
#include "clang/Lex/PPCallbacks.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/Token.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstring>
#include <iterator>
#include <memory>
#include <string>
#include <utility>
#include <vector>

Go to the source code of this file.

Classes

class  clang::VerifyDiagnosticConsumer::MarkerTracker

Typedefs

using Directive = VerifyDiagnosticConsumer::Directive
using DirectiveList = VerifyDiagnosticConsumer::DirectiveList
using ExpectedData = VerifyDiagnosticConsumer::ExpectedData
using DiagList = TextDiagnosticBuffer::DiagList
using const_diag_iterator = TextDiagnosticBuffer::const_iterator

Functions

static std::string DetailedErrorString (const DiagnosticsEngine &Diags)
static bool ParseDirective (StringRef S, ExpectedData *ED, SourceManager &SM, Preprocessor *PP, SourceLocation Pos, VerifyDiagnosticConsumer::ParsingState &State, VerifyDiagnosticConsumer::MarkerTracker &Markers, bool OneDiagPerDirective, bool DisableWildcardInDiagLoc)
 ParseDirective - Go through the comment and see if it indicates expected diagnostics.
static bool findDirectives (SourceManager &SM, FileID FID, const LangOptions &LangOpts)
 Lex the specified source file to determine whether it contains any expected-* directives.
static unsigned PrintUnexpected (DiagnosticsEngine &Diags, SourceManager *SourceMgr, const_diag_iterator diag_begin, const_diag_iterator diag_end, const char *Kind)
 Takes a list of diagnostics that have been generated but not matched by an expected-* directive and produces a diagnostic to the user from this.
static unsigned PrintExpected (DiagnosticsEngine &Diags, SourceManager &SourceMgr, std::vector< Directive * > &DL, const char *Kind)
 Takes a list of diagnostics that were expected to have been generated but were not and produces a diagnostic to the user from this.
static bool IsFromSameFile (SourceManager &SM, SourceLocation DirectiveLoc, SourceLocation DiagnosticLoc)
 Determine whether two source locations come from the same file.
static unsigned PrintPartial (DiagnosticsEngine &Diags, SourceManager &SourceMgr, llvm::SmallVector< std::pair< Directive *, std::string > > &DL, const char *Kind)
 Takes a list of diagnostics that were partially matched and prints them.
static unsigned CheckLists (DiagnosticsEngine &Diags, SourceManager &SourceMgr, const char *Label, DirectiveList &Left, const_diag_iterator d2_begin, const_diag_iterator d2_end, bool IgnoreUnexpected)
 CheckLists - Compare expected to seen diagnostic lists and return the the difference between them.
static unsigned CheckResults (DiagnosticsEngine &Diags, SourceManager &SourceMgr, const TextDiagnosticBuffer &Buffer, ExpectedData &ED)
 CheckResults - This compares the expected results to those that were actually reported.
static unsigned CheckResultsAreInOrder (DiagnosticsEngine &Diags, SourceManager &SourceMgr, const TextDiagnosticBuffer &Buffer, const ExpectedData &ED)

Typedef Documentation

◆ const_diag_iterator

◆ DiagList

◆ Directive

◆ DirectiveList

◆ ExpectedData

Function Documentation

◆ CheckLists()

◆ CheckResults()

◆ CheckResultsAreInOrder()

◆ DetailedErrorString()

std::string DetailedErrorString ( const DiagnosticsEngine & Diags)
static

◆ findDirectives()

bool findDirectives ( SourceManager & SM,
FileID FID,
const LangOptions & LangOpts )
static

Lex the specified source file to determine whether it contains any expected-* directives.

As a Lexer is used rather than a full-blown Preprocessor, directives inside skipped if blocks will still be found.

Returns
true if any directives were found.

Definition at line 918 of file VerifyDiagnosticConsumer.cpp.

References clang::SourceManager::getBufferOrFake(), clang::SourceManager::getDiagnostics(), clang::Lexer::getSpelling(), clang::VerifyDiagnosticConsumer::HasNoDirectives, clang::FileID::isInvalid(), clang::Lexer::LexFromRawLexer(), ParseDirective(), clang::Lexer::SetCommentRetentionState(), and Tok.

Referenced by clang::VerifyDiagnosticConsumer::UpdateParsedFileStatus().

◆ IsFromSameFile()

◆ ParseDirective()

bool ParseDirective ( StringRef S,
ExpectedData * ED,
SourceManager & SM,
Preprocessor * PP,
SourceLocation Pos,
VerifyDiagnosticConsumer::ParsingState & State,
VerifyDiagnosticConsumer::MarkerTracker & Markers,
bool OneDiagPerDirective,
bool DisableWildcardInDiagLoc )
static

ParseDirective - Go through the comment and see if it indicates expected diagnostics.

If so, then put them in the appropriate directive list.

Returns true if any valid directives were found.

Definition at line 434 of file VerifyDiagnosticConsumer.cpp.

References clang::VerifyDiagnosticConsumer::MarkerTracker::addDirective(), clang::VerifyDiagnosticConsumer::MarkerTracker::addMarker(), clang::SrcMgr::C_User, clang::SourceManager::createFileID(), clang::DType, clang::VerifyDiagnosticConsumer::ExpectedData::Errors, clang::File, clang::SourceManager::getBufferOrFake(), clang::DiagnosticsEngine::getDiagnosticOptions(), clang::Preprocessor::getDiagnostics(), clang::SourceManager::getDiagnostics(), clang::SourceManager::getFileID(), clang::SourceManager::getFileManager(), clang::SourceLocation::getLocWithOffset(), clang::FileManager::getOptionalFileRef(), clang::SourceManager::getSpellingLineNumber(), clang::VerifyDiagnosticConsumer::HasExpectedNoDiagnostics, clang::VerifyDiagnosticConsumer::HasOtherExpectedDirectives, clang::Invalid, clang::Preprocessor::isIncrementalProcessingEnabled(), clang::FileID::isInvalid(), clang::SourceLocation::isInvalid(), clang::Line, clang::Preprocessor::LookupFile(), clang::VerifyDiagnosticConsumer::Directive::MaxCount, NoDiag(), clang::VerifyDiagnosticConsumer::ExpectedData::Notes, clang::VerifyDiagnosticConsumer::ExpectedData::Remarks, clang::DiagnosticsEngine::Report(), clang::SourceManager::translateFile(), clang::SourceManager::translateLineCol(), clang::DiagnosticOptions::VerifyPrefixes, and clang::VerifyDiagnosticConsumer::ExpectedData::Warnings.

Referenced by findDirectives(), and clang::VerifyDiagnosticConsumer::HandleComment().

◆ PrintExpected()

unsigned PrintExpected ( DiagnosticsEngine & Diags,
SourceManager & SourceMgr,
std::vector< Directive * > & DL,
const char * Kind )
static

Takes a list of diagnostics that were expected to have been generated but were not and produces a diagnostic to the user from this.

Definition at line 988 of file VerifyDiagnosticConsumer.cpp.

References clang::DiagnosticsEngine::getDiagnosticOptions(), clang::DiagnosticsEngine::Report(), clang::DiagnosticBuilder::setForceEmit(), and clang::DiagnosticOptions::VerifyPrefixes.

Referenced by CheckLists().

◆ PrintPartial()

unsigned PrintPartial ( DiagnosticsEngine & Diags,
SourceManager & SourceMgr,
llvm::SmallVector< std::pair< Directive *, std::string > > & DL,
const char * Kind )
static

Takes a list of diagnostics that were partially matched and prints them.

Definition at line 1041 of file VerifyDiagnosticConsumer.cpp.

References IsFromSameFile(), clang::DiagnosticsEngine::Report(), and clang::DiagnosticBuilder::setForceEmit().

Referenced by CheckLists().

◆ PrintUnexpected()

unsigned PrintUnexpected ( DiagnosticsEngine & Diags,
SourceManager * SourceMgr,
const_diag_iterator diag_begin,
const_diag_iterator diag_end,
const char * Kind )
static

Takes a list of diagnostics that have been generated but not matched by an expected-* directive and produces a diagnostic to the user from this.

Definition at line 957 of file VerifyDiagnosticConsumer.cpp.

References clang::File, clang::DiagnosticsEngine::getDiagnosticOptions(), clang::DiagnosticsEngine::Report(), clang::DiagnosticBuilder::setForceEmit(), and clang::DiagnosticOptions::VerifyPrefixes.

Referenced by CheckLists().