[clang] Thread Safety Analysis: Don't treat function pointer parameters as scoped capabilities (PR #211885)

Marco Elver via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 28 06:52:00 PDT 2026


melver wrote:

> Applying the GPT-proposed fix for that bug would be unrelated to this PR:
> 
> ```diff
> --- a/clang/lib/DependencyScanning/InProcessModuleCache.cpp
> +++ b/clang/lib/DependencyScanning/InProcessModuleCache.cpp
> @@
>    void updateModuleTimestamp(StringRef Filename) override {
> -    // Note: This essentially replaces FS contention with mutex contention.
> -    auto &Timestamp = getOrCreateEntry(Filename).Timestamp;
> -
> -    Logger.log() << "timestamp_write: " << Filename;
> -    Timestamp.store(llvm::sys::toTimeT(std::chrono::system_clock::now()));
> +    // Note: This essentially replaces FS contention with mutex contention.
> +    // Only update/log the timestamp once to avoid duplicate timestamp_write
> +    // entries when multiple threads race to validate/build the same module.
> +    auto &Entry = getOrCreateEntry(Filename);
> +    // Protect access to the entry so that two threads won't both decide to
> +    // write/log. Using the Entry mutex is sufficient and cheap here.
> +    std::lock_guard<std::mutex> Lock(Entry.Mutex);
> +    // If Timestamp is non-zero, we already recorded a timestamp for this
> +    // module in this process; don't log again.
> +    time_t Current = Entry.Timestamp.load();
> +    if (Current != 0)
> +      return;
> +    time_t Now = llvm::sys::toTimeT(std::chrono::system_clock::now());
> +    Entry.Timestamp.store(Now);
> +    Logger.log() << "timestamp_write: " << Filename;
>    }
> ```

Yes, though could send a separate PR if it keeps blocking this one (if no fix PR pending yet). It looks like CI is still running and hasn't failed yet.

https://github.com/llvm/llvm-project/pull/211885


More information about the cfe-commits mailing list