[flang][cuda] Adapt ExternalNameConversion to work in gpu module (#117039)
[llvm-project.git] / clang / unittests / Driver / SimpleDiagnosticConsumer.h
blob6515bdedb3d5df53a96457c27cd2d01253034b4a
1 //===- unittests/Driver/SimpleDiagnosticConsumer.h ------------------------===//
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 // Simple diagnostic consumer to grab up diagnostics for testing.
11 //===----------------------------------------------------------------------===//
13 #ifndef CLANG_UNITTESTS_SIMPLEDIAGNOSTICCONSUMER_H
14 #define CLANG_UNITTESTS_SIMPLEDIAGNOSTICCONSUMER_H
16 #include "clang/Driver/Driver.h"
17 #include "clang/Basic/Diagnostic.h"
18 #include "llvm/ADT/SmallString.h"
19 #include "llvm/Support/VirtualFileSystem.h"
21 struct SimpleDiagnosticConsumer : public clang::DiagnosticConsumer {
22 void HandleDiagnostic(clang::DiagnosticsEngine::Level DiagLevel,
23 const clang::Diagnostic &Info) override {
24 if (DiagLevel == clang::DiagnosticsEngine::Level::Error) {
25 Errors.emplace_back();
26 Info.FormatDiagnostic(Errors.back());
27 } else {
28 Msgs.emplace_back();
29 Info.FormatDiagnostic(Msgs.back());
32 void clear() override {
33 Msgs.clear();
34 Errors.clear();
35 DiagnosticConsumer::clear();
37 std::vector<llvm::SmallString<32>> Msgs;
38 std::vector<llvm::SmallString<32>> Errors;
41 // Using SimpleDiagnosticConsumer, this function makes a clang Driver, suitable
42 // for testing situations where it will only ever be used for emitting
43 // diagnostics, such as being passed to `MultilibSet::select`.
44 inline clang::driver::Driver diagnostic_test_driver() {
45 llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> DiagID(
46 new clang::DiagnosticIDs());
47 llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
48 new llvm::vfs::InMemoryFileSystem);
49 auto *DiagConsumer = new SimpleDiagnosticConsumer;
50 llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> DiagOpts =
51 new clang::DiagnosticOptions();
52 clang::DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagConsumer);
53 return clang::driver::Driver("/bin/clang", "", Diags, "", InMemoryFileSystem);
56 #endif // CLANG_UNITTESTS_SIMPLEDIAGNOSTICCONSUMER_H