Files
TheRock/compiler/amd-llvm/clang-tools-extra/clangd/unittests/CompilerTests.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

134 lines
4.2 KiB
C++

//===-- CompilerTests.cpp -------------------------------------------------===//
//
// 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 "Compiler.h"
#include "Config.h"
#include "Diagnostics.h"
#include "TestTU.h"
#include "clang/Frontend/DependencyOutputOptions.h"
#include "clang/Frontend/FrontendOptions.h"
#include "clang/Lex/PreprocessorOptions.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
namespace clang {
namespace clangd {
namespace {
using testing::IsEmpty;
TEST(BuildCompilerInvocation, DropsPCH) {
MockFS FS;
IgnoreDiagnostics Diags;
TestTU TU;
TU.AdditionalFiles["test.h.pch"] = "";
TU.ExtraArgs = {"-include-pch", "test.h.pch"};
EXPECT_THAT(buildCompilerInvocation(TU.inputs(FS), Diags)
->getPreprocessorOpts()
.ImplicitPCHInclude,
IsEmpty());
// Transparent include translation
TU.ExtraArgs = {"-include", "test.h"};
EXPECT_THAT(buildCompilerInvocation(TU.inputs(FS), Diags)
->getPreprocessorOpts()
.ImplicitPCHInclude,
IsEmpty());
// CL mode parsing.
TU.AdditionalFiles["test.pch"] = "";
TU.ExtraArgs = {"--driver-mode=cl"};
TU.ExtraArgs.push_back("/Yutest.h");
EXPECT_THAT(buildCompilerInvocation(TU.inputs(FS), Diags)
->getPreprocessorOpts()
.ImplicitPCHInclude,
IsEmpty());
EXPECT_THAT(buildCompilerInvocation(TU.inputs(FS), Diags)
->getPreprocessorOpts()
.PCHThroughHeader,
IsEmpty());
}
TEST(BuildCompilerInvocation, PragmaDebugCrash) {
TestTU TU = TestTU::withCode("#pragma clang __debug parser_crash");
TU.build(); // no-crash
}
TEST(BuildCompilerInvocation, DropsShowIncludes) {
MockFS FS;
IgnoreDiagnostics Diags;
TestTU TU;
TU.ExtraArgs = {"-Xclang", "--show-includes"};
EXPECT_THAT(buildCompilerInvocation(TU.inputs(FS), Diags)
->getDependencyOutputOpts()
.ShowIncludesDest,
ShowIncludesDestination::None);
TU.ExtraArgs = {"/showIncludes", "--driver-mode=cl"};
EXPECT_THAT(buildCompilerInvocation(TU.inputs(FS), Diags)
->getDependencyOutputOpts()
.ShowIncludesDest,
ShowIncludesDestination::None);
TU.ExtraArgs = {"/showIncludes:user", "--driver-mode=cl"};
EXPECT_THAT(buildCompilerInvocation(TU.inputs(FS), Diags)
->getDependencyOutputOpts()
.ShowIncludesDest,
ShowIncludesDestination::None);
}
TEST(BuildCompilerInvocation, DropsPlugins) {
MockFS FS;
IgnoreDiagnostics Diags;
TestTU TU;
TU.ExtraArgs = {"-Xclang", "-load",
"-Xclang", "plugins.so",
"-Xclang", "-plugin",
"-Xclang", "my_plugin",
"-Xclang", "-plugin-arg-my_plugin",
"-Xclang", "foo=bar",
"-Xclang", "-add-plugin",
"-Xclang", "my_plugin2"};
auto Opts = buildCompilerInvocation(TU.inputs(FS), Diags)->getFrontendOpts();
EXPECT_THAT(Opts.Plugins, IsEmpty());
EXPECT_THAT(Opts.PluginArgs, IsEmpty());
EXPECT_THAT(Opts.AddPluginActions, IsEmpty());
EXPECT_EQ(Opts.ProgramAction, frontend::ActionKind::ParseSyntaxOnly);
EXPECT_TRUE(Opts.ActionName.empty());
}
TEST(BuildCompilerInvocation, EmptyArgs) {
MockFS FS;
IgnoreDiagnostics Diags;
TestTU TU;
auto Inputs = TU.inputs(FS);
Inputs.CompileCommand.CommandLine.clear();
// No crash.
EXPECT_EQ(buildCompilerInvocation(Inputs, Diags), nullptr);
}
TEST(BuildCompilerInvocation, SuppressDiags) {
MockFS FS;
StoreDiags Diags;
TestTU TU;
TU.ExtraArgs = {"-funknown-arg"};
auto Inputs = TU.inputs(FS);
Config Cfg;
Cfg.Diagnostics.Suppress = {"drv_unknown_argument"};
WithContextValue SuppressFilterWithCfg(Config::Key, std::move(Cfg));
EXPECT_NE(buildCompilerInvocation(Inputs, Diags), nullptr);
EXPECT_THAT(Diags.take(), IsEmpty());
}
} // namespace
} // namespace clangd
} // namespace clang