@@ -58,6 +58,8 @@ enum DiagnosticSeverity : char {
5858// / Defines the different supported kind of a diagnostic.
5959// / This enum should be extended with a new ID for each added concrete subclass.
6060enum DiagnosticKind {
61+ DK_Generic,
62+ DK_GenericWithLoc,
6163 DK_InlineAsm,
6264 DK_ResourceLimit,
6365 DK_StackSize,
@@ -134,6 +136,33 @@ class DiagnosticInfo {
134136
135137using DiagnosticHandlerFunction = std::function<void (const DiagnosticInfo &)>;
136138
139+ class DiagnosticInfoGeneric : public DiagnosticInfo {
140+ const Twine &MsgStr;
141+ const Instruction *Inst = nullptr ;
142+
143+ public:
144+ // / \p MsgStr is the message to be reported to the frontend.
145+ // / This class does not copy \p MsgStr, therefore the reference must be valid
146+ // / for the whole life time of the Diagnostic.
147+ DiagnosticInfoGeneric (const Twine &MsgStr,
148+ DiagnosticSeverity Severity = DS_Error)
149+ : DiagnosticInfo(DK_Generic, Severity), MsgStr(MsgStr) {}
150+
151+ DiagnosticInfoGeneric (const Instruction *I, const Twine &ErrMsg,
152+ DiagnosticSeverity Severity = DS_Warning)
153+ : DiagnosticInfo(DK_Generic, Severity), MsgStr(ErrMsg), Inst(I) {}
154+
155+ const Twine &getMsgStr () const { return MsgStr; }
156+ const Instruction *getInstruction () const { return Inst; }
157+
158+ // / \see DiagnosticInfo::print.
159+ void print (DiagnosticPrinter &DP) const override ;
160+
161+ static bool classof (const DiagnosticInfo *DI) {
162+ return DI->getKind () == DK_Generic;
163+ }
164+ };
165+
137166// / Diagnostic information for inline asm reporting.
138167// / This is basically a message and an optional location.
139168class DiagnosticInfoInlineAsm : public DiagnosticInfo {
@@ -146,21 +175,12 @@ class DiagnosticInfoInlineAsm : public DiagnosticInfo {
146175 const Instruction *Instr = nullptr ;
147176
148177public:
149- // / \p MsgStr is the message to be reported to the frontend.
150- // / This class does not copy \p MsgStr, therefore the reference must be valid
151- // / for the whole life time of the Diagnostic.
152- DiagnosticInfoInlineAsm (const Twine &MsgStr,
153- DiagnosticSeverity Severity = DS_Error)
154- : DiagnosticInfo(DK_InlineAsm, Severity), MsgStr(MsgStr) {}
155-
156178 // / \p LocCookie if non-zero gives the line number for this report.
157179 // / \p MsgStr gives the message.
158180 // / This class does not copy \p MsgStr, therefore the reference must be valid
159181 // / for the whole life time of the Diagnostic.
160182 DiagnosticInfoInlineAsm (uint64_t LocCookie, const Twine &MsgStr,
161- DiagnosticSeverity Severity = DS_Error)
162- : DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(LocCookie),
163- MsgStr (MsgStr) {}
183+ DiagnosticSeverity Severity = DS_Error);
164184
165185 // / \p Instr gives the original instruction that triggered the diagnostic.
166186 // / \p MsgStr gives the message.
@@ -354,6 +374,31 @@ class DiagnosticInfoWithLocationBase : public DiagnosticInfo {
354374 DiagnosticLocation Loc;
355375};
356376
377+ class DiagnosticInfoGenericWithLoc : public DiagnosticInfoWithLocationBase {
378+ private:
379+ // / Message to be reported.
380+ const Twine &MsgStr;
381+
382+ public:
383+ // / \p MsgStr is the message to be reported to the frontend.
384+ // / This class does not copy \p MsgStr, therefore the reference must be valid
385+ // / for the whole life time of the Diagnostic.
386+ DiagnosticInfoGenericWithLoc (const Twine &MsgStr, const Function &Fn,
387+ const DiagnosticLocation &Loc,
388+ DiagnosticSeverity Severity = DS_Error)
389+ : DiagnosticInfoWithLocationBase(DK_GenericWithLoc, Severity, Fn, Loc),
390+ MsgStr (MsgStr) {}
391+
392+ const Twine &getMsgStr () const { return MsgStr; }
393+
394+ // / \see DiagnosticInfo::print.
395+ void print (DiagnosticPrinter &DP) const override ;
396+
397+ static bool classof (const DiagnosticInfo *DI) {
398+ return DI->getKind () == DK_GenericWithLoc;
399+ }
400+ };
401+
357402// / Diagnostic information for stack size etc. reporting.
358403// / This is basically a function and a size.
359404class DiagnosticInfoResourceLimit : public DiagnosticInfoWithLocationBase {
0 commit comments