https://github.com/ChenMiaoi created https://github.com/llvm/llvm-project/pull/236360
The global module index could be generated while a module was being rebuilt because the check for .pcm.lock files never matched: sys::path::extension() returns ".lock", not ".pcm.lock". >From ccdd4f31569b40a8463d8835a18a8e6e2e741409 Mon Sep 17 00:00:00 2001 From: Chen Miao <[email protected]> Date: Wed, 28 Oct 2026 17:50:22 +0800 Subject: [PATCH] [clang] Fix PCM lock detection when generating the global module index The global module index could be generated while a module was being rebuilt because the check for .pcm.lock files never matched: sys::path::extension() returns ".lock", not ".pcm.lock". --- clang/lib/Serialization/GlobalModuleIndex.cpp | 2 +- clang/test/Modules/global_index.m | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/clang/lib/Serialization/GlobalModuleIndex.cpp b/clang/lib/Serialization/GlobalModuleIndex.cpp index 7ab9a3d299f64..7a154898e4b25 100644 --- a/clang/lib/Serialization/GlobalModuleIndex.cpp +++ b/clang/lib/Serialization/GlobalModuleIndex.cpp @@ -887,7 +887,7 @@ GlobalModuleIndex::writeIndex(FileManager &FileMgr, // ... unless it's a .pcm.lock file, which indicates that someone is // in the process of rebuilding a module. They'll rebuild the index // at the end of that translation unit, so we don't have to. - if (llvm::sys::path::extension(D->path()) == ".pcm.lock") + if (StringRef(D->path()).ends_with(".pcm.lock")) return llvm::createStringError(std::errc::device_or_resource_busy, "someone else is building the index"); diff --git a/clang/test/Modules/global_index.m b/clang/test/Modules/global_index.m index 3857e10c2e922..c8e2b27912d65 100644 --- a/clang/test/Modules/global_index.m +++ b/clang/test/Modules/global_index.m @@ -8,6 +8,16 @@ // Run and use the global module index // RUN: %clang_cc1 -Rmodule-include-translation -Wno-private-module -fmodules-cache-path=%t/cache -fdisable-module-hash -fmodules -fimplicit-module-maps -F %S/Inputs %s -verify -print-stats 2>&1 | FileCheck %s +// Skip index generation while another module is being built. +// RUN: rm %t/cache/modules.idx +// RUN: touch %t/cache/building.pcm.lock +// RUN: %clang_cc1 -Rmodule-include-translation -Wno-private-module -fmodules-cache-path=%t/cache -fdisable-module-hash -fmodules -fimplicit-module-maps -F %S/Inputs %s -verify +// RUN: not test -e %t/cache/modules.idx +// Resume index generation once the module lock is removed. +// RUN: rm %t/cache/building.pcm.lock +// RUN: %clang_cc1 -Rmodule-include-translation -Wno-private-module -fmodules-cache-path=%t/cache -fdisable-module-hash -fmodules -fimplicit-module-maps -F %S/Inputs %s -verify +// RUN: test -f %t/cache/modules.idx + // expected-no-diagnostics @import DependsOnModule; @import Module; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
