Coverage Report

Created: 2021-09-21 08:58

/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
366k
                                            const Diagnostic &Info) {
25
  // Default implementation (Warnings/errors count).
26
366k
  DiagnosticConsumer::HandleDiagnostic(Level, Info);
27
28
366k
  SmallString<100> Buf;
29
366k
  Info.FormatDiagnostic(Buf);
30
366k
  switch (Level) {
31
0
  default: llvm_unreachable(
32
0
                         "Diagnostic not handled during diagnostic buffering!");
33
116k
  case DiagnosticsEngine::Note:
34
116k
    All.emplace_back(Level, Notes.size());
35
116k
    Notes.emplace_back(Info.getLocation(), std::string(Buf.str()));
36
116k
    break;
37
59.0k
  case DiagnosticsEngine::Warning:
38
59.0k
    All.emplace_back(Level, Warnings.size());
39
59.0k
    Warnings.emplace_back(Info.getLocation(), std::string(Buf.str()));
40
59.0k
    break;
41
112
  case DiagnosticsEngine::Remark:
42
112
    All.emplace_back(Level, Remarks.size());
43
112
    Remarks.emplace_back(Info.getLocation(), std::string(Buf.str()));
44
112
    break;
45
190k
  case DiagnosticsEngine::Error:
46
190k
  case DiagnosticsEngine::Fatal:
47
190k
    All.emplace_back(Level, Errors.size());
48
190k
    Errors.emplace_back(Info.getLocation(), std::string(Buf.str()));
49
190k
    break;
50
366k
  }
51
366k
}
52
53
40.5k
void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const {
54
40.5k
  for (const auto &I : All) {
55
225
    auto Diag = Diags.Report(Diags.getCustomDiagID(I.first, "%0"));
56
225
    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
15
    case DiagnosticsEngine::Warning:
63
15
      Diag << Warnings[I.second].second;
64
15
      break;
65
2
    case DiagnosticsEngine::Remark:
66
2
      Diag << Remarks[I.second].second;
67
2
      break;
68
114
    case DiagnosticsEngine::Error:
69
114
    case DiagnosticsEngine::Fatal:
70
114
      Diag << Errors[I.second].second;
71
114
      break;
72
225
    }
73
225
  }
74
40.5k
}