Author: Jan Svoboda Date: 2024-04-10T09:08:01-07:00 New Revision: fc3dff9b4637bb5960fe70add90cd27e6842d58b
URL: https://github.com/llvm/llvm-project/commit/fc3dff9b4637bb5960fe70add90cd27e6842d58b DIFF: https://github.com/llvm/llvm-project/commit/fc3dff9b4637bb5960fe70add90cd27e6842d58b.diff LOG: [clang][modules] Stop eagerly reading files with diagnostic pragmas (#87442) This makes it so that the importer doesn't need to stat all input files of a module that contain diagnostic pragmas, reducing file system traffic. Added: clang/test/Modules/home-is-cwd-search-paths.c Modified: clang/lib/Serialization/ASTReader.cpp Removed: ################################################################################ diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 679302e7a838f1..2e73a0a7140104 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -6626,8 +6626,6 @@ void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) { "Invalid data, missing pragma diagnostic states"); FileID FID = ReadFileID(F, Record, Idx); assert(FID.isValid() && "invalid FileID for transition"); - // FIXME: Remove this once we don't need the side-effects. - (void)SourceMgr.getSLocEntryOrNull(FID); unsigned Transitions = Record[Idx++]; // Note that we don't need to set up Parent/ParentOffset here, because diff --git a/clang/test/Modules/home-is-cwd-search-paths.c b/clang/test/Modules/home-is-cwd-search-paths.c new file mode 100644 index 00000000000000..0b8954e691bc04 --- /dev/null +++ b/clang/test/Modules/home-is-cwd-search-paths.c @@ -0,0 +1,34 @@ +// This test demonstrates how -fmodule-map-file-home-is-cwd with -fmodules-embed-all-files +// extend the importer search paths by relying on the side effects of pragma diagnostic +// mappings deserialization. + +// RUN: rm -rf %t +// RUN: split-file %s %t + +//--- dir1/a.modulemap +module a { header "a.h" } +//--- dir1/a.h +#include "search.h" +// The first compilation is configured such that -I search does contain the search.h header. +//--- dir1/search/search.h +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wparentheses" +#pragma clang diagnostic pop +// RUN: cd %t/dir1 && %clang_cc1 -fmodules -I search \ +// RUN: -emit-module -fmodule-name=a a.modulemap -o %t/a.pcm \ +// RUN: -fmodules-embed-all-files -fmodule-map-file-home-is-cwd + +//--- dir2/b.modulemap +module b { header "b.h" } +//--- dir2/b.h +#include "search.h" // expected-error{{'search.h' file not found}} +// The second compilation is configured such that -I search is an empty directory. +// However, since b.pcm simply embeds the headers as "search/search.h", this compilation +// ends up seeing it too. This relies solely on ASTReader::ReadPragmaDiagnosticMappings() +// eagerly reading the corresponding INPUT_FILE record before header search happens. +// Removing the eager deserialization makes this header invisible and so does removing +// the pragma directives. +// RUN: mkdir %t/dir2/search +// RUN: cd %t/dir2 && %clang_cc1 -fmodules -I search \ +// RUN: -emit-module -fmodule-name=b b.modulemap -o %t/b.pcm \ +// RUN: -fmodule-file=%t/a.pcm -verify _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits