Coverage Report

Created: 2020-02-15 09:57

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