[clang] [clang][DependencyScanning] Logging Dependency Scanning Events (PR #195896)
Qiongsi Wu via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 2 11:48:40 PDT 2026
================
@@ -0,0 +1,68 @@
+//===- AtomicLineLogger.h ---------------------------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+/// \file
+/// Defines a logger where each line is written atomically to the file. It is
+/// safe to share a logger instance across threads.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_BASIC_ATOMICLINELOGGER_H
+#define LLVM_CLANG_BASIC_ATOMICLINELOGGER_H
+
+#include "clang/Basic/LLVM.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/raw_ostream.h"
+#include <memory>
+
+namespace clang {
+
+class LogLine {
+ SmallString<128> Buffer;
+ std::optional<llvm::raw_svector_ostream> FormattingOS;
+ raw_ostream *Dest = nullptr;
+
+public:
+ explicit LogLine(raw_ostream &Dest);
+ LogLine() {}
+ LogLine(LogLine &&Other);
+ LogLine(const LogLine &) = delete;
+ LogLine &operator=(const LogLine &) = delete;
+ LogLine &operator=(LogLine &&) = delete;
+
+ ~LogLine() {
+ if (Dest) {
+ assert(FormattingOS && "Cannot have uninitialized FormattingOS");
+ *FormattingOS << '\n';
+ Dest->write(Buffer.data(), Buffer.size());
----------------
qiongsiwu wrote:
Good catch! TSan does get tripped at `pos += Size;` inside `write_impl`. The `OnDiskCASLogger` has exactly the same problem.
I've rewritten the code that performs the write (https://github.com/llvm/llvm-project/pull/205395, with this PR rebased on top of it), and the unit tests pass with TSan. I will check with the CAS folks to see if we need to do something there.
https://github.com/llvm/llvm-project/pull/195896
More information about the cfe-commits
mailing list