Coverage Report

Created: 2022-05-17 06:19

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Frontend/TextDiagnosticBuffer.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- TextDiagnosticBuffer.cpp - Buffer Text Diagnostics -----------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This is a concrete diagnostic client, which buffers the diagnostic messages.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "clang/Frontend/TextDiagnosticBuffer.h"
14
#include "clang/Basic/Diagnostic.h"
15
#include "clang/Basic/LLVM.h"
16
#include "llvm/ADT/SmallString.h"
17
#include "llvm/Support/ErrorHandling.h"
18
19
using namespace clang;
20
21
/// HandleDiagnostic - Store the errors, warnings, and notes that are
22
/// reported.
23
void TextDiagnosticBuffer::HandleDiagnostic(DiagnosticsEngine::Level Level,
24
372k
                                            const Diagnostic &Info) {
25
  // Default implementation (Warnings/errors count).
26
372k
  DiagnosticConsumer::HandleDiagnostic(Level, Info);
27
28
372k
  SmallString<100> Buf;
29
372k
  Info.FormatDiagnostic(Buf);
30
372k
  switch (Level) {
31
0
  default: llvm_unreachable(
32
0
                         "Diagnostic not handled during diagnostic buffering!");
33
117k
  case DiagnosticsEngine::Note:
34
117k
    All.emplace_back(Level, Notes.size());
35
117k
    Notes.emplace_back(Info.getLocation(), std::string(Buf.str()));
36
117k
    break;
37
60.1k
  case DiagnosticsEngine::Warning:
38
60.1k
    All.emplace_back(Level, Warnings.size());
39
60.1k
    Warnings.emplace_back(Info.getLocation(), std::string(Buf.str()));
40
60.1k
    break;
41
105
  case DiagnosticsEngine::Remark:
42
105
    All.emplace_back(Level, Remarks.size());
43
105
    Remarks.emplace_back(Info.getLocation(), std::string(Buf.str()));
44
105
    break;
45
194k
  case DiagnosticsEngine::Error:
46
194k
  case DiagnosticsEngine::Fatal:
47
194k
    All.emplace_back(Level, Errors.size());
48
194k
    Errors.emplace_back(Info.getLocation(), std::string(Buf.str()));
49
194k
    break;
50
372k
  }
51
372k
}
52
53
40.3k
void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const {
54
40.3k
  for (const auto &I : All) {
55
234
    auto Diag = Diags.Report(Diags.getCustomDiagID(I.first, "%0"));
56
234
    switch (I.first) {
57
0
    default: llvm_unreachable(
58
0
                           "Diagnostic not handled during diagnostic flushing!");
59
94
    case DiagnosticsEngine::Note:
60
94
      Diag << Notes[I.second].second;
61
94
      break;
62
14
    case DiagnosticsEngine::Warning:
63
14
      Diag << Warnings[I.second].second;
64
14
      break;
65
2
    case DiagnosticsEngine::Remark:
66
2
      Diag << Remarks[I.second].second;
67
2
      break;
68
124
    case DiagnosticsEngine::Error:
69
124
    case DiagnosticsEngine::Fatal:
70
124
      Diag << Errors[I.second].second;
71
124
      break;
72
234
    }
73
234
  }
74
40.3k
}