adamcz created this revision. Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, mgorny. Herald added a project: clang. adamcz requested review of this revision. Herald added a subscriber: ilya-biryukov.
This fixes a crash bug in clangd when used with modules. ASTWriter would end up writing references to submodules into the PCH file, but upon reading the submodules would not exists and HeaderFileInfoTrait::ReadData would crash. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D85532 Files: clang-tools-extra/clangd/unittests/CMakeLists.txt clang-tools-extra/clangd/unittests/ModulesTests.cpp 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-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