adamcz updated this revision to Diff 283922. adamcz added a comment. This time the fix is included ;-)
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D85532/new/ https://reviews.llvm.org/D85532 Files: clang-tools-extra/clangd/unittests/CMakeLists.txt clang-tools-extra/clangd/unittests/ModulesTests.cpp clang/lib/Frontend/PrecompiledPreamble.cpp Index: clang/lib/Frontend/PrecompiledPreamble.cpp =================================================================== --- clang/lib/Frontend/PrecompiledPreamble.cpp +++ clang/lib/Frontend/PrecompiledPreamble.cpp @@ -208,6 +208,11 @@ Callbacks.AfterPCHEmitted(Writer); } + bool BeginSourceFileAction(CompilerInstance &CI) override { + CI.getLangOpts().CompilingPCH = true; + return ASTFrontendAction::BeginSourceFileAction(CI); + } + bool shouldEraseOutputFiles() override { return !hasEmittedPreamblePCH(); } bool hasCodeCompletionSupport() const override { return false; } bool hasASTFileSupport() const override { return false; } Index: clang-tools-extra/clangd/unittests/ModulesTests.cpp =================================================================== --- /dev/null +++ clang-tools-extra/clangd/unittests/ModulesTests.cpp @@ -0,0 +1,45 @@ +//===-- ModulesTests.cpp ---------------------------------------*- C++ -*-===// +// +// 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 "Annotations.h" +#include "TestFS.h" +#include "TestTU.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include <memory> +#include <string> + +namespace clang { +namespace clangd { +namespace { + +TEST(Modules, TextualIncludeInPreamble) { + TestTU TU = TestTU::withCode(R"cpp( +#include "Textual.h" + +void foo() {} +)cpp"); + TU.ExtraArgs.push_back("-fmodules"); + TU.ExtraArgs.push_back("-fmodule-name=M"); + TU.ExtraArgs.push_back("-fmodule-map-file=m.modulemap"); + TU.AdditionalFiles["Textual.h"] = "void foo();"; + TU.AdditionalFiles["m.modulemap"] = R"modulemap( +module M { + module Textual { + textual header "Textual.h" + } +} +)modulemap"; + // Test that we do not crash. + TU.index(); +} + +} // namespace +} // namespace clangd +} // namespace clang Index: clang-tools-extra/clangd/unittests/CMakeLists.txt =================================================================== --- clang-tools-extra/clangd/unittests/CMakeLists.txt +++ clang-tools-extra/clangd/unittests/CMakeLists.txt @@ -63,6 +63,7 @@ IndexTests.cpp JSONTransportTests.cpp LSPClient.cpp + ModulesTests.cpp ParsedASTTests.cpp PathMappingTests.cpp PreambleTests.cpp
Index: clang/lib/Frontend/PrecompiledPreamble.cpp =================================================================== --- clang/lib/Frontend/PrecompiledPreamble.cpp +++ clang/lib/Frontend/PrecompiledPreamble.cpp @@ -208,6 +208,11 @@ Callbacks.AfterPCHEmitted(Writer); } + bool BeginSourceFileAction(CompilerInstance &CI) override { + CI.getLangOpts().CompilingPCH = true; + return ASTFrontendAction::BeginSourceFileAction(CI); + } + bool shouldEraseOutputFiles() override { return !hasEmittedPreamblePCH(); } bool hasCodeCompletionSupport() const override { return false; } bool hasASTFileSupport() const override { return false; } Index: clang-tools-extra/clangd/unittests/ModulesTests.cpp =================================================================== --- /dev/null +++ clang-tools-extra/clangd/unittests/ModulesTests.cpp @@ -0,0 +1,45 @@ +//===-- ModulesTests.cpp ---------------------------------------*- C++ -*-===// +// +// 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 "Annotations.h" +#include "TestFS.h" +#include "TestTU.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include <memory> +#include <string> + +namespace clang { +namespace clangd { +namespace { + +TEST(Modules, TextualIncludeInPreamble) { + TestTU TU = TestTU::withCode(R"cpp( +#include "Textual.h" + +void foo() {} +)cpp"); + TU.ExtraArgs.push_back("-fmodules"); + TU.ExtraArgs.push_back("-fmodule-name=M"); + TU.ExtraArgs.push_back("-fmodule-map-file=m.modulemap"); + TU.AdditionalFiles["Textual.h"] = "void foo();"; + TU.AdditionalFiles["m.modulemap"] = R"modulemap( +module M { + module Textual { + textual header "Textual.h" + } +} +)modulemap"; + // Test that we do not crash. + TU.index(); +} + +} // namespace +} // namespace clangd +} // namespace clang Index: clang-tools-extra/clangd/unittests/CMakeLists.txt =================================================================== --- clang-tools-extra/clangd/unittests/CMakeLists.txt +++ clang-tools-extra/clangd/unittests/CMakeLists.txt @@ -63,6 +63,7 @@ IndexTests.cpp JSONTransportTests.cpp LSPClient.cpp + ModulesTests.cpp ParsedASTTests.cpp PathMappingTests.cpp PreambleTests.cpp
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits