MLIR 24.0.0git
mlir::Diagnostic Class Reference

This class contains all of the information necessary to report a diagnostic to the DiagnosticEngine. More...

#include "mlir/IR/Diagnostics.h"

Public Types

using note_iterator = llvm::pointee_iterator<NoteVector::iterator>
using const_note_iterator

Public Member Functions

 Diagnostic (Location loc, DiagnosticSeverity severity)
 Diagnostic (Diagnostic &&)=default
Diagnostic & operator= (Diagnostic &&)=default
DiagnosticSeverity getSeverity () const
 Returns the severity of this diagnostic.
Location getLocation () const
 Returns the source location for this diagnostic.
MutableArrayRef< DiagnosticArgument > getArguments ()
 Returns the current list of diagnostic arguments.
ArrayRef< DiagnosticArgument > getArguments () const
template<typename Arg>
std::enable_if_t<!std::is_convertible< Arg, StringRef >::value &&std::is_constructible< DiagnosticArgument, Arg >::value, Diagnostic & > operator<< (Arg &&val)
 Stream operator for inserting new diagnostic arguments.
Diagnostic & operator<< (StringAttr val)
template<size_t n>
Diagnostic & operator<< (const char(&val)[n])
 Stream in a string literal.
Diagnostic & operator<< (char val)
 Stream in a Twine argument.
Diagnostic & operator<< (const Twine &val)
Diagnostic & operator<< (Twine &&val)
Diagnostic & operator<< (OperationName val)
 Stream in an OperationName.
Diagnostic & operator<< (Operation &op)
 Stream in an Operation.
Diagnostic & operator<< (OpWithFlags op)
Diagnostic & operator<< (Operation *op)
Diagnostic & appendOp (Operation &op, const OpPrintingFlags &flags)
 Append an operation with the given printing flags.
Diagnostic & operator<< (Value val)
 Stream in a Value.
template<typename EnumT>
std::enable_if_t< std::is_enum_v< EnumT > &&std::is_convertible_v< decltype(stringifyEnum(std::declval< EnumT >())), StringRef >, Diagnostic & > operator<< (EnumT val)
 Stream in an enum that has a stringifyEnum function.
template<typename T, typename ValueT = llvm::detail::ValueOfRange<T>>
std::enable_if_t<!std::is_constructible< DiagnosticArgument, T >::value, Diagnostic & > operator<< (T &&range)
 Stream in a range.
template<typename T>
Diagnostic & appendRange (const T &c, const char *delim=", ")
 Append a range to the diagnostic.
template<typename Arg1, typename Arg2, typename... Args>
Diagnostic & append (Arg1 &&arg1, Arg2 &&arg2, Args &&...args)
 Append arguments to the diagnostic.
template<typename Arg>
Diagnostic & append (Arg &&arg)
 Append one argument to the diagnostic.
void print (raw_ostream &os, std::optional< int64_t > messagePartIndex=std::nullopt) const
 Outputs this diagnostic to a stream.
std::string str () const
 Converts the diagnostic to a string, concatenating all the parts if there are multiples.
SmallVector< std::string > strs () const
 Converts each message part to a separate string.
Diagnostic & attachNote (std::optional< Location > noteLoc=std::nullopt)
 Attaches a note to this diagnostic.
iterator_range< note_iterator > getNotes ()
 Returns the notes held by this diagnostic.
iterator_range< const_note_iterator > getNotes () const
 operator LogicalResult () const
 Allow a diagnostic to be converted to 'failure'.
 operator ParseResult () const
 Allow a diagnostic to be converted to 'failure'.
template<typename T>
 operator FailureOr< T > () const
 Allow a diagnostic to be converted to FailureOr<T>.
SmallVectorImpl< DiagnosticArgument > & getMetadata ()
 Returns the current list of diagnostic metadata.
void startNewMessagePart ()
 Starts a new message part.

Detailed Description

This class contains all of the information necessary to report a diagnostic to the DiagnosticEngine.

It should generally not be constructed directly, and instead used transitively via InFlightDiagnostic.

A diagnostic may contain multiple message parts that share its location, severity, metadata, and attached notes. Empty message parts are ignored.

Definition at line 159 of file Diagnostics.h.

Member Typedef Documentation

◆ const_note_iterator

Initial value:
llvm::pointee_iterator<NoteVector::const_iterator>

Definition at line 275 of file Diagnostics.h.

◆ note_iterator

using mlir::Diagnostic::note_iterator = llvm::pointee_iterator<NoteVector::iterator>

Definition at line 274 of file Diagnostics.h.

Constructor & Destructor Documentation

◆ Diagnostic() [1/2]

◆ Diagnostic() [2/2]

mlir::Diagnostic::Diagnostic ( Diagnostic && )
default

References Diagnostic().

Member Function Documentation

◆ append() [1/2]

template<typename Arg>
Diagnostic & mlir::Diagnostic::append ( Arg && arg)
inline

Append one argument to the diagnostic.

Definition at line 250 of file Diagnostics.h.

References Diagnostic().

◆ append() [2/2]

template<typename Arg1, typename Arg2, typename... Args>
Diagnostic & mlir::Diagnostic::append ( Arg1 && arg1,
Arg2 && arg2,
Args &&... args )
inline

Append arguments to the diagnostic.

Definition at line 244 of file Diagnostics.h.

References append(), and Diagnostic().

Referenced by append(), and mlir::detail::verifySymbolTable().

◆ appendOp()

Diagnostic & Diagnostic::appendOp ( Operation & op,
const OpPrintingFlags & flags )

Append an operation with the given printing flags.

Definition at line 146 of file Diagnostics.cpp.

References adjustPrintingFlags(), Diagnostic(), mlir::Operation::print(), and str().

Referenced by operator<<(), and operator<<().

◆ appendRange()

template<typename T>
Diagnostic & mlir::Diagnostic::appendRange ( const T & c,
const char * delim = ", " )
inline

Append a range to the diagnostic.

The default delimiter between elements is ','.

Definition at line 236 of file Diagnostics.h.

References Diagnostic().

◆ attachNote()

Diagnostic & Diagnostic::attachNote ( std::optional< Location > noteLoc = std::nullopt)

Attaches a note to this diagnostic.

A new location may be optionally provided, if not, then the location defaults to the one specified for this diagnostic. Notes may not be attached to other notes.

Append and return a new note.

Definition at line 216 of file Diagnostics.cpp.

References Diagnostic(), and mlir::Note.

Referenced by mlir::DiagnosedDefiniteFailure::attachNote().

◆ getArguments() [1/2]

MutableArrayRef< DiagnosticArgument > mlir::Diagnostic::getArguments ( )
inline

Returns the current list of diagnostic arguments.

Definition at line 175 of file Diagnostics.h.

Referenced by print().

◆ getArguments() [2/2]

ArrayRef< DiagnosticArgument > mlir::Diagnostic::getArguments ( ) const
inline

Definition at line 176 of file Diagnostics.h.

◆ getLocation()

Location mlir::Diagnostic::getLocation ( ) const
inline

Returns the source location for this diagnostic.

Definition at line 172 of file Diagnostics.h.

◆ getMetadata()

SmallVectorImpl< DiagnosticArgument > & mlir::Diagnostic::getMetadata ( )
inline

Returns the current list of diagnostic metadata.

Definition at line 300 of file Diagnostics.h.

◆ getNotes() [1/2]

iterator_range< note_iterator > mlir::Diagnostic::getNotes ( )
inline

Returns the notes held by this diagnostic.

Definition at line 279 of file Diagnostics.h.

◆ getNotes() [2/2]

iterator_range< const_note_iterator > mlir::Diagnostic::getNotes ( ) const
inline

Definition at line 282 of file Diagnostics.h.

◆ getSeverity()

DiagnosticSeverity mlir::Diagnostic::getSeverity ( ) const
inline

Returns the severity of this diagnostic.

Definition at line 169 of file Diagnostics.h.

◆ operator FailureOr< T >()

template<typename T>
mlir::Diagnostic::operator FailureOr< T > ( ) const
inline

Allow a diagnostic to be converted to FailureOr<T>.

Always results in 'failure' because this cast cannot possibly return an object of 'T'.

Definition at line 295 of file Diagnostics.h.

◆ operator LogicalResult()

Diagnostic::operator LogicalResult ( ) const

Allow a diagnostic to be converted to 'failure'.

Definition at line 232 of file Diagnostics.cpp.

◆ operator ParseResult()

mlir::Diagnostic::operator ParseResult ( ) const
inline

Allow a diagnostic to be converted to 'failure'.

Definition at line 290 of file Diagnostics.h.

◆ operator<<() [1/13]

template<typename Arg>
std::enable_if_t<!std::is_convertible< Arg, StringRef >::value &&std::is_constructible< DiagnosticArgument, Arg >::value, Diagnostic & > mlir::Diagnostic::operator<< ( Arg && val)
inline

Stream operator for inserting new diagnostic arguments.

Definition at line 176 of file Diagnostics.h.

◆ operator<<() [2/13]

Diagnostic & Diagnostic::operator<< ( char val)

Stream in a Twine argument.

Definition at line 103 of file Diagnostics.cpp.

References Diagnostic().

◆ operator<<() [3/13]

template<size_t n>
Diagnostic & mlir::Diagnostic::operator<< ( const char(&) val[n])
inline

Stream in a string literal.

Definition at line 191 of file Diagnostics.h.

References Diagnostic().

◆ operator<<() [4/13]

Diagnostic & Diagnostic::operator<< ( const Twine & val)

Definition at line 104 of file Diagnostics.cpp.

References Diagnostic(), and twineToStrRef().

◆ operator<<() [5/13]

template<typename EnumT>
std::enable_if_t< std::is_enum_v< EnumT > &&std::is_convertible_v< decltype(stringifyEnum(std::declval< EnumT >())), StringRef >, Diagnostic & > mlir::Diagnostic::operator<< ( EnumT val)
inline

Stream in an enum that has a stringifyEnum function.

Definition at line 212 of file Diagnostics.h.

References Diagnostic().

◆ operator<<() [6/13]

Diagnostic & Diagnostic::operator<< ( Operation & op)

Stream in an Operation.

Definition at line 138 of file Diagnostics.cpp.

References appendOp(), and Diagnostic().

◆ operator<<() [7/13]

Diagnostic & mlir::Diagnostic::operator<< ( Operation * op)
inline

Definition at line 207 of file Diagnostics.h.

References Diagnostic().

◆ operator<<() [8/13]

Diagnostic & Diagnostic::operator<< ( OperationName val)

Stream in an OperationName.

Definition at line 119 of file Diagnostics.cpp.

References Diagnostic(), and mlir::OperationName::getStringRef().

◆ operator<<() [9/13]

Diagnostic & Diagnostic::operator<< ( OpWithFlags op)

◆ operator<<() [10/13]

Diagnostic & Diagnostic::operator<< ( StringAttr val)

Definition at line 113 of file Diagnostics.cpp.

References Diagnostic().

◆ operator<<() [11/13]

template<typename T, typename ValueT = llvm::detail::ValueOfRange<T>>
std::enable_if_t<!std::is_constructible< DiagnosticArgument, T >::value, Diagnostic & > mlir::Diagnostic::operator<< ( T && range)
inline

Stream in a range.

Definition at line 212 of file Diagnostics.h.

◆ operator<<() [12/13]

Diagnostic & Diagnostic::operator<< ( Twine && val)

Definition at line 108 of file Diagnostics.cpp.

References Diagnostic(), and twineToStrRef().

◆ operator<<() [13/13]

Diagnostic & Diagnostic::operator<< ( Value val)

Stream in a Value.

Definition at line 158 of file Diagnostics.cpp.

References adjustPrintingFlags(), Diagnostic(), mlir::Value::print(), and str().

◆ operator=()

Diagnostic & mlir::Diagnostic::operator= ( Diagnostic && )
default

References Diagnostic().

◆ print()

void Diagnostic::print ( raw_ostream & os,
std::optional< int64_t > messagePartIndex = std::nullopt ) const

Outputs this diagnostic to a stream.

If messagePartIndex is provided, only that message part is printed; otherwise, all arguments are printed without separators between message parts.

Definition at line 166 of file Diagnostics.cpp.

References getArguments().

Referenced by mlirAffineExprPrint(), mlirAffineMapPrint(), mlirDiagnosticPrint(), mlirIntegerSetPrint(), str(), and strs().

◆ startNewMessagePart()

void Diagnostic::startNewMessagePart ( )

Starts a new message part.

This has no effect if the current message part is empty.

Definition at line 235 of file Diagnostics.cpp.

◆ str()

std::string Diagnostic::str ( ) const

Converts the diagnostic to a string, concatenating all the parts if there are multiples.

Convert the diagnostic to a string.

Definition at line 188 of file Diagnostics.cpp.

References print(), and str().

Referenced by appendOp(), operator<<(), str(), and strs().

◆ strs()

SmallVector< std::string > Diagnostic::strs ( ) const

Converts each message part to a separate string.

Returns a single string if the diagnostic has not been divided into multiple parts.

Definition at line 196 of file Diagnostics.cpp.

References print(), str(), and strs().

Referenced by strs().


The documentation for this class was generated from the following files: