41 struct LineNoCacheTy {
42 const char *LastQuery;
43 unsigned LastQueryBufferID;
44 unsigned LineNoOfQuery;
50 return (LineNoCacheTy*)
Ptr;
59 std::string &IncludedFile) {
60 IncludedFile = Filename;
65 for (
unsigned i = 0, e = IncludeDirectories.size(); i != e && !NewBufOrErr;
79 for (
unsigned i = 0, e = Buffers.size(); i != e; ++i)
80 if (Loc.
getPointer() >= Buffers[i].Buffer->getBufferStart() &&
83 Loc.
getPointer() <= Buffers[i].Buffer->getBufferEnd())
88 std::pair<unsigned, unsigned>
92 assert(BufferID &&
"Invalid Location!");
101 const char *
Ptr = BufStart;
106 if (LineNoCacheTy *Cache =
getCache(LineNoCache))
107 if (Cache->LastQueryBufferID == BufferID &&
109 Ptr = Cache->LastQuery;
110 LineNo = Cache->LineNoOfQuery;
116 if (*Ptr ==
'\n') ++LineNo;
120 LineNoCache =
new LineNoCacheTy();
123 LineNoCacheTy &Cache = *
getCache(LineNoCache);
124 Cache.LastQueryBufferID = BufferID;
125 Cache.LastQuery =
Ptr;
126 Cache.LineNoOfQuery = LineNo;
130 return std::make_pair(LineNo, Ptr-BufStart-NewlineOffs);
134 if (IncludeLoc ==
SMLoc())
return;
137 assert(CurBuf &&
"Invalid or unspecified location!");
141 OS <<
"Included from "
153 std::pair<unsigned, unsigned> LineAndCol;
159 assert(CurBuf &&
"Invalid or unspecified location!");
167 while (LineStart != BufStart && LineStart[-1] !=
'\n' &&
168 LineStart[-1] !=
'\r')
174 while (LineEnd != BufEnd && LineEnd[0] !=
'\n' && LineEnd[0] !=
'\r')
176 LineStr = std::string(LineStart, LineEnd);
180 for (
unsigned i = 0, e = Ranges.
size(); i != e; ++i) {
203 return SMDiagnostic(*
this, Loc, BufferID, LineAndCol.first,
204 LineAndCol.second-1, Kind, Msg.
str(),
205 LineStr, ColRanges, FixIts);
209 bool ShowColors)
const {
212 DiagHandler(Diagnostic, DiagContext);
218 assert(CurBuf &&
"Invalid or unspecified location!");
222 Diagnostic.
print(
nullptr, OS, ShowColors);
245 ArrayRef<std::pair<unsigned,unsigned>> Ranges,
247 : SM(&sm), Loc(L), Filename(FN), LineNo(Line), ColumnNo(Col), Kind(Kind),
248 Message(Msg), LineContents(LineStr), Ranges(Ranges.vec()),
249 FixIts(Hints.
begin(), Hints.
end()) {
258 const char *LineStart = SourceLine.
begin();
259 const char *LineEnd = SourceLine.
end();
261 size_t PrevHintEndCol = 0;
291 unsigned HintCol = FirstCol;
292 if (HintCol < PrevHintEndCol)
293 HintCol = PrevHintEndCol + 1;
299 I->getText().size());
302 unsigned LastColumnModified = HintCol +
I->getText().size();
303 if (LastColumnModified > FixItLine.size())
304 FixItLine.resize(LastColumnModified,
' ');
306 std::copy(
I->getText().begin(),
I->getText().end(),
307 FixItLine.begin() + HintCol);
309 PrevHintEndCol = LastColumnModified;
315 LastCol = LineEnd - LineStart;
319 std::fill(&CaretLine[FirstCol], &CaretLine[LastCol],
'~');
325 for (
unsigned i = 0, e = LineContents.
size(), OutCol = 0; i != e; ++i) {
326 if (LineContents[i] !=
'\t') {
327 S << LineContents[i];
336 }
while ((OutCol %
TabStop) != 0);
346 bool ShowKindLabel)
const {
353 if (ProgName && ProgName[0])
354 S << ProgName <<
": ";
356 if (!Filename.empty()) {
365 S <<
':' << (ColumnNo+1);
395 S << Message <<
'\n';
400 if (LineNo == -1 || ColumnNo == -1)
412 size_t NumColumns = LineContents.size();
415 std::string CaretLine(NumColumns+1,
' ');
418 for (
unsigned r = 0, e = Ranges.size(); r != e; ++r) {
419 std::pair<unsigned, unsigned> R = Ranges[r];
420 std::fill(&CaretLine[R.first],
421 &CaretLine[
std::min((
size_t)R.second, CaretLine.size())],
427 std::string FixItInsertionLine;
430 LineContents.size()));
433 if (
unsigned(ColumnNo) <= NumColumns)
434 CaretLine[ColumnNo] =
'^';
436 CaretLine[NumColumns] =
'^';
441 CaretLine.erase(CaretLine.find_last_not_of(
' ')+1);
449 for (
unsigned i = 0, e = CaretLine.size(), OutCol = 0; i != e; ++i) {
450 if (i >= LineContents.size() || LineContents[i] !=
'\t') {
460 }
while ((OutCol %
TabStop) != 0);
468 if (FixItInsertionLine.empty())
471 for (
size_t i = 0, e = FixItInsertionLine.size(), OutCol = 0; i < e; ++i) {
472 if (i >= LineContents.size() || LineContents[i] !=
'\t') {
473 S << FixItInsertionLine[i];
480 S << FixItInsertionLine[i];
486 if (FixItInsertionLine[i] !=
' ')
489 }
while (((OutCol %
TabStop) != 0) && i != e);
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true) const
Represents a range in source code.
void push_back(const T &Elt)
const_iterator end(StringRef path)
Get end iterator over path.
Represents either an error or a value T.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
void PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const
Prints the names of included files and the line of the file they were included from.
const char * getPointer() const
const char * getBufferStart() const
std::pair< unsigned, unsigned > getLineAndColumn(SMLoc Loc, unsigned BufferID=0) const
Find the line and column number for the specified location in the specified file. ...
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
virtual bool has_colors() const
This function determines if this stream is displayed and supports colors.
virtual raw_ostream & changeColor(enum Colors Color, bool Bold=false, bool BG=false)
Changes the foreground color of text that will be output from this point forward. ...
std::string str() const
Return the twine contents as a std::string.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
static const size_t TabStop
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
size_t size() const
size - Get the array size.
int columnWidth(StringRef s)
LLVM_NODISCARD size_t find_last_of(char C, size_t From=npos) const
Find the last character in the string that is C, or npos if not found.
bool empty() const
empty - Check if the array is empty.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
const SrcBuffer & getBufferInfo(unsigned i) const
static LineNoCacheTy * getCache(void *Ptr)
StringRef get_separator(Style style=Style::native)
Return the preferred separator for this platform.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static void printSourceLine(raw_ostream &S, StringRef LineContents)
This interface provides simple read-only access to a block of memory, and provides simple methods for...
unsigned FindLineNumber(SMLoc Loc, unsigned BufferID=0) const
Find the line number for the specified location in the specified file.
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
static bool isNonASCII(char c)
static SMLoc getFromPointer(const char *Ptr)
unsigned AddIncludeFile(const std::string &Filename, SMLoc IncludeLoc, std::string &IncludedFile)
Search for a file with the specified name in the current directory or in one of the IncludeDirs...
const MemoryBuffer * getMemoryBuffer(unsigned i) const
static void buildFixItLine(std::string &CaretLine, std::string &FixItLine, ArrayRef< SMFixIt > FixIts, ArrayRef< char > SourceLine)
const char * getBufferEnd() const
unsigned FindBufferContainingLoc(SMLoc Loc) const
Return the ID of the buffer containing the specified location.
Provides ErrorOr<T> smart pointer.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
virtual raw_ostream & resetColor()
Resets the colors to terminal defaults.
This class implements an extremely fast bulk output stream that can only output to a stream...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
StringRef - Represent a constant reference to a string, i.e.
SMDiagnostic GetMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None) const
Return an SMDiagnostic at the specified location with the specified string.
void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
Represents a location in source code.
auto find_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...