LLVM  8.0.1
SourceMgr.cpp
Go to the documentation of this file.
1 //===- SourceMgr.cpp - Manager for Simple Source Buffers & Diagnostics ----===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the SourceMgr class. This class is used as a simple
11 // substrate for diagnostics, #include handling, and other low level things for
12 // simple parsers.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #include "llvm/Support/SourceMgr.h"
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/ADT/Twine.h"
22 #include "llvm/Support/ErrorOr.h"
23 #include "llvm/Support/Locale.h"
25 #include "llvm/Support/Path.h"
26 #include "llvm/Support/SMLoc.h"
27 #include "llvm/Support/WithColor.h"
29 #include <algorithm>
30 #include <cassert>
31 #include <cstddef>
32 #include <limits>
33 #include <memory>
34 #include <string>
35 #include <utility>
36 
37 using namespace llvm;
38 
39 static const size_t TabStop = 8;
40 
41 unsigned SourceMgr::AddIncludeFile(const std::string &Filename,
42  SMLoc IncludeLoc,
43  std::string &IncludedFile) {
44  IncludedFile = Filename;
46  MemoryBuffer::getFile(IncludedFile);
47 
48  // If the file didn't exist directly, see if it's in an include path.
49  for (unsigned i = 0, e = IncludeDirectories.size(); i != e && !NewBufOrErr;
50  ++i) {
51  IncludedFile =
52  IncludeDirectories[i] + sys::path::get_separator().data() + Filename;
53  NewBufOrErr = MemoryBuffer::getFile(IncludedFile);
54  }
55 
56  if (!NewBufOrErr)
57  return 0;
58 
59  return AddNewSourceBuffer(std::move(*NewBufOrErr), IncludeLoc);
60 }
61 
63  for (unsigned i = 0, e = Buffers.size(); i != e; ++i)
64  if (Loc.getPointer() >= Buffers[i].Buffer->getBufferStart() &&
65  // Use <= here so that a pointer to the null at the end of the buffer
66  // is included as part of the buffer.
67  Loc.getPointer() <= Buffers[i].Buffer->getBufferEnd())
68  return i + 1;
69  return 0;
70 }
71 
72 template <typename T>
73 unsigned SourceMgr::SrcBuffer::getLineNumber(const char *Ptr) const {
74 
75  // Ensure OffsetCache is allocated and populated with offsets of all the
76  // '\n' bytes.
77  std::vector<T> *Offsets = nullptr;
78  if (OffsetCache.isNull()) {
79  Offsets = new std::vector<T>();
80  OffsetCache = Offsets;
81  size_t Sz = Buffer->getBufferSize();
83  StringRef S = Buffer->getBuffer();
84  for (size_t N = 0; N < Sz; ++N) {
85  if (S[N] == '\n') {
86  Offsets->push_back(static_cast<T>(N));
87  }
88  }
89  } else {
90  Offsets = OffsetCache.get<std::vector<T> *>();
91  }
92 
93  const char *BufStart = Buffer->getBufferStart();
94  assert(Ptr >= BufStart && Ptr <= Buffer->getBufferEnd());
95  ptrdiff_t PtrDiff = Ptr - BufStart;
96  assert(PtrDiff >= 0 && static_cast<size_t>(PtrDiff) <= std::numeric_limits<T>::max());
97  T PtrOffset = static_cast<T>(PtrDiff);
98 
99  // std::lower_bound returns the first EOL offset that's not-less-than
100  // PtrOffset, meaning the EOL that _ends the line_ that PtrOffset is on
101  // (including if PtrOffset refers to the EOL itself). If there's no such
102  // EOL, returns end().
103  auto EOL = std::lower_bound(Offsets->begin(), Offsets->end(), PtrOffset);
104 
105  // Lines count from 1, so add 1 to the distance from the 0th line.
106  return (1 + (EOL - Offsets->begin()));
107 }
108 
109 SourceMgr::SrcBuffer::SrcBuffer(SourceMgr::SrcBuffer &&Other)
110  : Buffer(std::move(Other.Buffer)),
111  OffsetCache(Other.OffsetCache),
112  IncludeLoc(Other.IncludeLoc) {
113  Other.OffsetCache = nullptr;
114 }
115 
116 SourceMgr::SrcBuffer::~SrcBuffer() {
117  if (!OffsetCache.isNull()) {
118  if (OffsetCache.is<std::vector<uint8_t>*>())
119  delete OffsetCache.get<std::vector<uint8_t>*>();
120  else if (OffsetCache.is<std::vector<uint16_t>*>())
121  delete OffsetCache.get<std::vector<uint16_t>*>();
122  else if (OffsetCache.is<std::vector<uint32_t>*>())
123  delete OffsetCache.get<std::vector<uint32_t>*>();
124  else
125  delete OffsetCache.get<std::vector<uint64_t>*>();
126  OffsetCache = nullptr;
127  }
128 }
129 
130 std::pair<unsigned, unsigned>
131 SourceMgr::getLineAndColumn(SMLoc Loc, unsigned BufferID) const {
132  if (!BufferID)
133  BufferID = FindBufferContainingLoc(Loc);
134  assert(BufferID && "Invalid Location!");
135 
136  auto &SB = getBufferInfo(BufferID);
137  const char *Ptr = Loc.getPointer();
138 
139  size_t Sz = SB.Buffer->getBufferSize();
140  unsigned LineNo;
142  LineNo = SB.getLineNumber<uint8_t>(Ptr);
143  else if (Sz <= std::numeric_limits<uint16_t>::max())
144  LineNo = SB.getLineNumber<uint16_t>(Ptr);
145  else if (Sz <= std::numeric_limits<uint32_t>::max())
146  LineNo = SB.getLineNumber<uint32_t>(Ptr);
147  else
148  LineNo = SB.getLineNumber<uint64_t>(Ptr);
149 
150  const char *BufStart = SB.Buffer->getBufferStart();
151  size_t NewlineOffs = StringRef(BufStart, Ptr-BufStart).find_last_of("\n\r");
152  if (NewlineOffs == StringRef::npos) NewlineOffs = ~(size_t)0;
153  return std::make_pair(LineNo, Ptr-BufStart-NewlineOffs);
154 }
155 
156 void SourceMgr::PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const {
157  if (IncludeLoc == SMLoc()) return; // Top of stack.
158 
159  unsigned CurBuf = FindBufferContainingLoc(IncludeLoc);
160  assert(CurBuf && "Invalid or unspecified location!");
161 
162  PrintIncludeStack(getBufferInfo(CurBuf).IncludeLoc, OS);
163 
164  OS << "Included from "
165  << getBufferInfo(CurBuf).Buffer->getBufferIdentifier()
166  << ":" << FindLineNumber(IncludeLoc, CurBuf) << ":\n";
167 }
168 
170  const Twine &Msg,
171  ArrayRef<SMRange> Ranges,
172  ArrayRef<SMFixIt> FixIts) const {
173  // First thing to do: find the current buffer containing the specified
174  // location to pull out the source line.
176  std::pair<unsigned, unsigned> LineAndCol;
177  StringRef BufferID = "<unknown>";
178  std::string LineStr;
179 
180  if (Loc.isValid()) {
181  unsigned CurBuf = FindBufferContainingLoc(Loc);
182  assert(CurBuf && "Invalid or unspecified location!");
183 
184  const MemoryBuffer *CurMB = getMemoryBuffer(CurBuf);
185  BufferID = CurMB->getBufferIdentifier();
186 
187  // Scan backward to find the start of the line.
188  const char *LineStart = Loc.getPointer();
189  const char *BufStart = CurMB->getBufferStart();
190  while (LineStart != BufStart && LineStart[-1] != '\n' &&
191  LineStart[-1] != '\r')
192  --LineStart;
193 
194  // Get the end of the line.
195  const char *LineEnd = Loc.getPointer();
196  const char *BufEnd = CurMB->getBufferEnd();
197  while (LineEnd != BufEnd && LineEnd[0] != '\n' && LineEnd[0] != '\r')
198  ++LineEnd;
199  LineStr = std::string(LineStart, LineEnd);
200 
201  // Convert any ranges to column ranges that only intersect the line of the
202  // location.
203  for (unsigned i = 0, e = Ranges.size(); i != e; ++i) {
204  SMRange R = Ranges[i];
205  if (!R.isValid()) continue;
206 
207  // If the line doesn't contain any part of the range, then ignore it.
208  if (R.Start.getPointer() > LineEnd || R.End.getPointer() < LineStart)
209  continue;
210 
211  // Ignore pieces of the range that go onto other lines.
212  if (R.Start.getPointer() < LineStart)
213  R.Start = SMLoc::getFromPointer(LineStart);
214  if (R.End.getPointer() > LineEnd)
215  R.End = SMLoc::getFromPointer(LineEnd);
216 
217  // Translate from SMLoc ranges to column ranges.
218  // FIXME: Handle multibyte characters.
219  ColRanges.push_back(std::make_pair(R.Start.getPointer()-LineStart,
220  R.End.getPointer()-LineStart));
221  }
222 
223  LineAndCol = getLineAndColumn(Loc, CurBuf);
224  }
225 
226  return SMDiagnostic(*this, Loc, BufferID, LineAndCol.first,
227  LineAndCol.second-1, Kind, Msg.str(),
228  LineStr, ColRanges, FixIts);
229 }
230 
232  bool ShowColors) const {
233  // Report the message with the diagnostic handler if present.
234  if (DiagHandler) {
235  DiagHandler(Diagnostic, DiagContext);
236  return;
237  }
238 
239  if (Diagnostic.getLoc().isValid()) {
240  unsigned CurBuf = FindBufferContainingLoc(Diagnostic.getLoc());
241  assert(CurBuf && "Invalid or unspecified location!");
242  PrintIncludeStack(getBufferInfo(CurBuf).IncludeLoc, OS);
243  }
244 
245  Diagnostic.print(nullptr, OS, ShowColors);
246 }
247 
250  const Twine &Msg, ArrayRef<SMRange> Ranges,
251  ArrayRef<SMFixIt> FixIts, bool ShowColors) const {
252  PrintMessage(OS, GetMessage(Loc, Kind, Msg, Ranges, FixIts), ShowColors);
253 }
254 
256  const Twine &Msg, ArrayRef<SMRange> Ranges,
257  ArrayRef<SMFixIt> FixIts, bool ShowColors) const {
258  PrintMessage(errs(), Loc, Kind, Msg, Ranges, FixIts, ShowColors);
259 }
260 
261 //===----------------------------------------------------------------------===//
262 // SMDiagnostic Implementation
263 //===----------------------------------------------------------------------===//
264 
266  int Line, int Col, SourceMgr::DiagKind Kind,
267  StringRef Msg, StringRef LineStr,
268  ArrayRef<std::pair<unsigned,unsigned>> Ranges,
269  ArrayRef<SMFixIt> Hints)
270  : SM(&sm), Loc(L), Filename(FN), LineNo(Line), ColumnNo(Col), Kind(Kind),
271  Message(Msg), LineContents(LineStr), Ranges(Ranges.vec()),
272  FixIts(Hints.begin(), Hints.end()) {
273  llvm::sort(FixIts);
274 }
275 
276 static void buildFixItLine(std::string &CaretLine, std::string &FixItLine,
277  ArrayRef<SMFixIt> FixIts, ArrayRef<char> SourceLine){
278  if (FixIts.empty())
279  return;
280 
281  const char *LineStart = SourceLine.begin();
282  const char *LineEnd = SourceLine.end();
283 
284  size_t PrevHintEndCol = 0;
285 
286  for (ArrayRef<SMFixIt>::iterator I = FixIts.begin(), E = FixIts.end();
287  I != E; ++I) {
288  // If the fixit contains a newline or tab, ignore it.
289  if (I->getText().find_first_of("\n\r\t") != StringRef::npos)
290  continue;
291 
292  SMRange R = I->getRange();
293 
294  // If the line doesn't contain any part of the range, then ignore it.
295  if (R.Start.getPointer() > LineEnd || R.End.getPointer() < LineStart)
296  continue;
297 
298  // Translate from SMLoc to column.
299  // Ignore pieces of the range that go onto other lines.
300  // FIXME: Handle multibyte characters in the source line.
301  unsigned FirstCol;
302  if (R.Start.getPointer() < LineStart)
303  FirstCol = 0;
304  else
305  FirstCol = R.Start.getPointer() - LineStart;
306 
307  // If we inserted a long previous hint, push this one forwards, and add
308  // an extra space to show that this is not part of the previous
309  // completion. This is sort of the best we can do when two hints appear
310  // to overlap.
311  //
312  // Note that if this hint is located immediately after the previous
313  // hint, no space will be added, since the location is more important.
314  unsigned HintCol = FirstCol;
315  if (HintCol < PrevHintEndCol)
316  HintCol = PrevHintEndCol + 1;
317 
318  // FIXME: This assertion is intended to catch unintended use of multibyte
319  // characters in fixits. If we decide to do this, we'll have to track
320  // separate byte widths for the source and fixit lines.
321  assert((size_t)sys::locale::columnWidth(I->getText()) ==
322  I->getText().size());
323 
324  // This relies on one byte per column in our fixit hints.
325  unsigned LastColumnModified = HintCol + I->getText().size();
326  if (LastColumnModified > FixItLine.size())
327  FixItLine.resize(LastColumnModified, ' ');
328 
329  std::copy(I->getText().begin(), I->getText().end(),
330  FixItLine.begin() + HintCol);
331 
332  PrevHintEndCol = LastColumnModified;
333 
334  // For replacements, mark the removal range with '~'.
335  // FIXME: Handle multibyte characters in the source line.
336  unsigned LastCol;
337  if (R.End.getPointer() >= LineEnd)
338  LastCol = LineEnd - LineStart;
339  else
340  LastCol = R.End.getPointer() - LineStart;
341 
342  std::fill(&CaretLine[FirstCol], &CaretLine[LastCol], '~');
343  }
344 }
345 
346 static void printSourceLine(raw_ostream &S, StringRef LineContents) {
347  // Print out the source line one character at a time, so we can expand tabs.
348  for (unsigned i = 0, e = LineContents.size(), OutCol = 0; i != e; ++i) {
349  size_t NextTab = LineContents.find('\t', i);
350  // If there were no tabs left, print the rest, we are done.
351  if (NextTab == StringRef::npos) {
352  S << LineContents.drop_front(i);
353  break;
354  }
355 
356  // Otherwise, print from i to NextTab.
357  S << LineContents.slice(i, NextTab);
358  OutCol += NextTab - i;
359  i = NextTab;
360 
361  // If we have a tab, emit at least one space, then round up to 8 columns.
362  do {
363  S << ' ';
364  ++OutCol;
365  } while ((OutCol % TabStop) != 0);
366  }
367  S << '\n';
368 }
369 
370 static bool isNonASCII(char c) {
371  return c & 0x80;
372 }
373 
374 void SMDiagnostic::print(const char *ProgName, raw_ostream &OS,
375  bool ShowColors, bool ShowKindLabel) const {
376  {
377  WithColor S(OS, raw_ostream::SAVEDCOLOR, true, false, !ShowColors);
378 
379  if (ProgName && ProgName[0])
380  S << ProgName << ": ";
381 
382  if (!Filename.empty()) {
383  if (Filename == "-")
384  S << "<stdin>";
385  else
386  S << Filename;
387 
388  if (LineNo != -1) {
389  S << ':' << LineNo;
390  if (ColumnNo != -1)
391  S << ':' << (ColumnNo + 1);
392  }
393  S << ": ";
394  }
395  }
396 
397  if (ShowKindLabel) {
398  switch (Kind) {
399  case SourceMgr::DK_Error:
400  WithColor::error(OS, "", !ShowColors);
401  break;
403  WithColor::warning(OS, "", !ShowColors);
404  break;
405  case SourceMgr::DK_Note:
406  WithColor::note(OS, "", !ShowColors);
407  break;
409  WithColor::remark(OS, "", !ShowColors);
410  break;
411  }
412  }
413 
414  WithColor(OS, raw_ostream::SAVEDCOLOR, true, false, !ShowColors)
415  << Message << '\n';
416 
417  if (LineNo == -1 || ColumnNo == -1)
418  return;
419 
420  // FIXME: If there are multibyte or multi-column characters in the source, all
421  // our ranges will be wrong. To do this properly, we'll need a byte-to-column
422  // map like Clang's TextDiagnostic. For now, we'll just handle tabs by
423  // expanding them later, and bail out rather than show incorrect ranges and
424  // misaligned fixits for any other odd characters.
425  if (find_if(LineContents, isNonASCII) != LineContents.end()) {
426  printSourceLine(OS, LineContents);
427  return;
428  }
429  size_t NumColumns = LineContents.size();
430 
431  // Build the line with the caret and ranges.
432  std::string CaretLine(NumColumns+1, ' ');
433 
434  // Expand any ranges.
435  for (unsigned r = 0, e = Ranges.size(); r != e; ++r) {
436  std::pair<unsigned, unsigned> R = Ranges[r];
437  std::fill(&CaretLine[R.first],
438  &CaretLine[std::min((size_t)R.second, CaretLine.size())],
439  '~');
440  }
441 
442  // Add any fix-its.
443  // FIXME: Find the beginning of the line properly for multibyte characters.
444  std::string FixItInsertionLine;
445  buildFixItLine(CaretLine, FixItInsertionLine, FixIts,
446  makeArrayRef(Loc.getPointer() - ColumnNo,
447  LineContents.size()));
448 
449  // Finally, plop on the caret.
450  if (unsigned(ColumnNo) <= NumColumns)
451  CaretLine[ColumnNo] = '^';
452  else
453  CaretLine[NumColumns] = '^';
454 
455  // ... and remove trailing whitespace so the output doesn't wrap for it. We
456  // know that the line isn't completely empty because it has the caret in it at
457  // least.
458  CaretLine.erase(CaretLine.find_last_not_of(' ')+1);
459 
460  printSourceLine(OS, LineContents);
461 
462  {
463  WithColor S(OS, raw_ostream::GREEN, true, false, !ShowColors);
464 
465  // Print out the caret line, matching tabs in the source line.
466  for (unsigned i = 0, e = CaretLine.size(), OutCol = 0; i != e; ++i) {
467  if (i >= LineContents.size() || LineContents[i] != '\t') {
468  S << CaretLine[i];
469  ++OutCol;
470  continue;
471  }
472 
473  // Okay, we have a tab. Insert the appropriate number of characters.
474  do {
475  S << CaretLine[i];
476  ++OutCol;
477  } while ((OutCol % TabStop) != 0);
478  }
479  S << '\n';
480  }
481 
482  // Print out the replacement line, matching tabs in the source line.
483  if (FixItInsertionLine.empty())
484  return;
485 
486  for (size_t i = 0, e = FixItInsertionLine.size(), OutCol = 0; i < e; ++i) {
487  if (i >= LineContents.size() || LineContents[i] != '\t') {
488  OS << FixItInsertionLine[i];
489  ++OutCol;
490  continue;
491  }
492 
493  // Okay, we have a tab. Insert the appropriate number of characters.
494  do {
495  OS << FixItInsertionLine[i];
496  // FIXME: This is trying not to break up replacements, but then to re-sync
497  // with the tabs between replacements. This will fail, though, if two
498  // fix-it replacements are exactly adjacent, or if a fix-it contains a
499  // space. Really we should be precomputing column widths, which we'll
500  // need anyway for multibyte chars.
501  if (FixItInsertionLine[i] != ' ')
502  ++i;
503  ++OutCol;
504  } while (((OutCol % TabStop) != 0) && i != e);
505  }
506  OS << '\n';
507 }
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
Definition: MemoryBuffer.h:70
Represents a range in source code.
Definition: SMLoc.h:49
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:259
Represents either an error or a value T.
Definition: ErrorOr.h:57
unsigned FindBufferContainingLoc(SMLoc Loc) const
Return the ID of the buffer containing the specified location.
Definition: SourceMgr.cpp:62
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:250
This class represents lattice values for constants.
Definition: AllocatorList.h:24
SMLoc getLoc() const
Definition: SourceMgr.h:286
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true) const
Definition: SourceMgr.cpp:374
An RAII object that temporarily switches an output stream to a specific color.
Definition: WithColor.h:38
iterator begin() const
Definition: ArrayRef.h:137
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
static raw_ostream & error()
Convenience method for printing "error: " to stderr.
Definition: WithColor.cpp:61
void PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const
Prints the names of included files and the line of the file they were included from.
Definition: SourceMgr.cpp:156
Offsets
Offsets in bytes from the start of the input buffer.
Definition: SIInstrInfo.h:1025
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.
Definition: StringRef.h:421
static raw_ostream & warning()
Convenience method for printing "warning: " to stderr.
Definition: WithColor.cpp:63
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. ...
Definition: SourceMgr.cpp:131
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).
Definition: StringRef.h:128
SMLoc Start
Definition: SMLoc.h:51
SMDiagnostic()=default
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.
Definition: SourceMgr.cpp:248
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:451
static raw_ostream & note()
Convenience method for printing "note: " to stderr.
Definition: WithColor.cpp:65
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:784
const MemoryBuffer * getMemoryBuffer(unsigned i) const
Definition: SourceMgr.h:131
static const size_t TabStop
Definition: SourceMgr.cpp:39
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
Definition: SourceMgr.h:152
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
auto lower_bound(R &&Range, ForwardIt I) -> decltype(adl_begin(Range))
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1282
int columnWidth(StringRef s)
Definition: Locale.cpp:9
const char * getPointer() const
Definition: SMLoc.h:35
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1214
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
Definition: SourceMgr.h:42
StringRef get_separator(Style style=Style::native)
Return the preferred separator for this platform.
Definition: Path.cpp:626
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.
Definition: SourceMgr.cpp:169
const SrcBuffer & getBufferInfo(unsigned i) const
Definition: SourceMgr.h:126
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1116
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_front(size_t N=1) const
Return a StringRef equal to &#39;this&#39; but with the first N elements dropped.
Definition: StringRef.h:645
bool isValid() const
Definition: SMLoc.h:60
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
iterator end() const
Definition: ArrayRef.h:138
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
Definition: StringRef.h:710
static void printSourceLine(raw_ostream &S, StringRef LineContents)
Definition: SourceMgr.cpp:346
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:42
static raw_ostream & remark()
Convenience method for printing "remark: " to stderr.
Definition: WithColor.cpp:67
bool isValid() const
Definition: SMLoc.h:30
SMLoc End
Definition: SMLoc.h:51
unsigned FindLineNumber(SMLoc Loc, unsigned BufferID=0) const
Find the line number for the specified location in the specified file.
Definition: SourceMgr.h:177
static bool isNonASCII(char c)
Definition: SourceMgr.cpp:370
static SMLoc getFromPointer(const char *Ptr)
Definition: SMLoc.h:37
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...
Definition: SourceMgr.cpp:41
const char * getBufferEnd() const
Definition: MemoryBuffer.h:61
static const size_t npos
Definition: StringRef.h:51
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
static void buildFixItLine(std::string &CaretLine, std::string &FixItLine, ArrayRef< SMFixIt > FixIts, ArrayRef< char > SourceLine)
Definition: SourceMgr.cpp:276
const char * getBufferStart() const
Definition: MemoryBuffer.h:60
std::string str() const
Return the twine contents as a std::string.
Definition: Twine.cpp:18
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.
const unsigned Kind
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Represents a location in source code.
Definition: SMLoc.h:24
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Definition: StringRef.h:298
OutputIt copy(R &&Range, OutputIt Out)
Definition: STLExtras.h:1238
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:144
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:260