[lld] [ELF] Add context-aware diagnostic functions (PR #112319)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 21 23:07:50 PDT 2024


================
@@ -679,6 +681,25 @@ static inline void internalLinkerError(StringRef loc, const Twine &msg) {
               llvm::getBugReportMsg());
 }
 
+struct ELFSyncStream : SyncStream {
+  Ctx &ctx;
+  ELFSyncStream(Ctx &ctx, DiagLevel level)
+      : SyncStream(*ctx.e, level), ctx(ctx) {}
+};
+
+template <typename T>
+std::enable_if_t<!std::is_pointer_v<std::remove_reference_t<T>>,
+                 const ELFSyncStream &>
+operator<<(const ELFSyncStream &s, T &&v) {
+  s.os << std::forward<T>(v);
+  return s;
+}
+
+ELFSyncStream Log(Ctx &ctx);
+ELFSyncStream Warn(Ctx &ctx);
+ELFSyncStream Err(Ctx &ctx);
----------------
MaskRay wrote:

Adopted `ErrAlways`.

Sorry that I just realized that I did not update this yet.

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


More information about the llvm-commits mailing list