summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/clang/unittests/Frontend/CompilerInstanceTest.cpp
diff options
context:
space:
mode:
authorpatrick <patrick@openbsd.org>2020-08-03 14:31:31 +0000
committerpatrick <patrick@openbsd.org>2020-08-03 14:31:31 +0000
commite5dd70708596ae51455a0ffa086a00c5b29f8583 (patch)
tree5d676f27b570bacf71e786c3b5cff3e6f6679b59 /gnu/llvm/clang/unittests/Frontend/CompilerInstanceTest.cpp
parentImport LLVM 10.0.0 release including clang, lld and lldb. (diff)
downloadwireguard-openbsd-e5dd70708596ae51455a0ffa086a00c5b29f8583.tar.xz
wireguard-openbsd-e5dd70708596ae51455a0ffa086a00c5b29f8583.zip
Import LLVM 10.0.0 release including clang, lld and lldb.
ok hackroom tested by plenty
Diffstat (limited to 'gnu/llvm/clang/unittests/Frontend/CompilerInstanceTest.cpp')
-rw-r--r--gnu/llvm/clang/unittests/Frontend/CompilerInstanceTest.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/gnu/llvm/clang/unittests/Frontend/CompilerInstanceTest.cpp b/gnu/llvm/clang/unittests/Frontend/CompilerInstanceTest.cpp
new file mode 100644
index 00000000000..d2377d07406
--- /dev/null
+++ b/gnu/llvm/clang/unittests/Frontend/CompilerInstanceTest.cpp
@@ -0,0 +1,94 @@
+//===- unittests/Frontend/CompilerInstanceTest.cpp - CI tests -------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Format.h"
+#include "llvm/Support/ToolOutputFile.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace clang;
+
+namespace {
+
+TEST(CompilerInstance, DefaultVFSOverlayFromInvocation) {
+ // Create a temporary VFS overlay yaml file.
+ int FD;
+ SmallString<256> FileName;
+ ASSERT_FALSE(sys::fs::createTemporaryFile("vfs", "yaml", FD, FileName));
+ ToolOutputFile File(FileName, FD);
+
+ SmallString<256> CurrentPath;
+ sys::fs::current_path(CurrentPath);
+ sys::fs::make_absolute(CurrentPath, FileName);
+
+ // Mount the VFS file itself on the path 'virtual.file'. Makes this test
+ // a bit shorter than creating a new dummy file just for this purpose.
+ const std::string CurrentPathStr = CurrentPath.str();
+ const std::string FileNameStr = FileName.str();
+ const char *VFSYaml = "{ 'version': 0, 'roots': [\n"
+ " { 'name': '%s',\n"
+ " 'type': 'directory',\n"
+ " 'contents': [\n"
+ " { 'name': 'vfs-virtual.file', 'type': 'file',\n"
+ " 'external-contents': '%s'\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ "]}\n";
+ File.os() << format(VFSYaml, CurrentPathStr.c_str(), FileName.c_str());
+ File.os().flush();
+
+ // Create a CompilerInvocation that uses this overlay file.
+ const std::string VFSArg = "-ivfsoverlay" + FileNameStr;
+ const char *Args[] = {"clang", VFSArg.c_str(), "-xc++", "-"};
+
+ IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
+ CompilerInstance::createDiagnostics(new DiagnosticOptions());
+
+ std::shared_ptr<CompilerInvocation> CInvok =
+ createInvocationFromCommandLine(Args, Diags);
+
+ if (!CInvok)
+ FAIL() << "could not create compiler invocation";
+ // Create a minimal CompilerInstance which should use the VFS we specified
+ // in the CompilerInvocation (as we don't explicitly set our own).
+ CompilerInstance Instance;
+ Instance.setDiagnostics(Diags.get());
+ Instance.setInvocation(CInvok);
+ Instance.createFileManager();
+
+ // Check if the virtual file exists which means that our VFS is used by the
+ // CompilerInstance.
+ ASSERT_TRUE(Instance.getFileManager().getFile("vfs-virtual.file"));
+}
+
+TEST(CompilerInstance, AllowDiagnosticLogWithUnownedDiagnosticConsumer) {
+ auto DiagOpts = new DiagnosticOptions();
+ // Tell the diagnostics engine to emit the diagnostic log to STDERR. This
+ // ensures that a chained diagnostic consumer is created so that the test can
+ // exercise the unowned diagnostic consumer in a chained consumer.
+ DiagOpts->DiagnosticLogFile = "-";
+
+ // Create the diagnostic engine with unowned consumer.
+ std::string DiagnosticOutput;
+ llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput);
+ auto DiagPrinter = std::make_unique<TextDiagnosticPrinter>(
+ DiagnosticsOS, new DiagnosticOptions());
+ CompilerInstance Instance;
+ IntrusiveRefCntPtr<DiagnosticsEngine> Diags = Instance.createDiagnostics(
+ DiagOpts, DiagPrinter.get(), /*ShouldOwnClient=*/false);
+
+ Diags->Report(diag::err_expected) << "no crash";
+ ASSERT_EQ(DiagnosticsOS.str(), "error: expected no crash\n");
+}
+
+} // anonymous namespace