Coverage Report

Created: 2019-07-24 05:18

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