[lld] [ELF] Add context-aware diagnostic functions (PR #112319)
Peter Smith via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 15 06:28:32 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);
----------------
smithp35 wrote:
Is the intention that all errors are now errorOrWarn, it looks we currently have error and errorOrWarn.
I can see error being useful for conditions where the output file is always going to be broken, but we can complete the link with diagnostics. The errorOrWarn can be for when the output is likely broken, or some standard has been broken. FatalError can be used if we're going crash if we keep going.
This isn't a strong distinction so I can see it being worthwhile to merge so that more diagnostics can become warnings if needed.
https://github.com/llvm/llvm-project/pull/112319
More information about the llvm-commits
mailing list