Coverage Report

Created: 2020-09-22 08:39

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