LLVM  15.0.0git
SourceMgr.cpp
Go to the documentation of this file.
1 //===- SourceMgr.cpp - Manager for Simple Source Buffers & Diagnostics ----===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the SourceMgr class. This class is used as a simple
10 // substrate for diagnostics, #include handling, and other low level things for
11 // simple parsers.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "llvm/Support/SourceMgr.h"
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/ADT/Twine.h"
21 #include "llvm/Support/ErrorOr.h"
22 #include "llvm/Support/Locale.h"
24 #include "llvm/Support/Path.h"
25 #include "llvm/Support/SMLoc.h"
26 #include "llvm/Support/WithColor.h"
28 #include <algorithm>
29 #include <cassert>
30 #include <cstddef>
31 #include <limits>
32 #include <memory>
33 #include <string>
34 #include <utility>
35 
36 using namespace llvm;
37 
38 static const size_t TabStop = 8;
39 
40 unsigned SourceMgr::AddIncludeFile(const std::string &Filename,
41  SMLoc IncludeLoc,
42  std::string &IncludedFile) {
44  OpenIncludeFile(Filename, IncludedFile);
45  if (!NewBufOrErr)
46  return 0;
47 
48  return AddNewSourceBuffer(std::move(*NewBufOrErr), IncludeLoc);
49 }
50 
52 SourceMgr::OpenIncludeFile(const std::string &Filename,
53  std::string &IncludedFile) {
54  IncludedFile = Filename;
56  MemoryBuffer::getFile(IncludedFile);
57 
58  // If the file didn't exist directly, see if it's in an include path.
59  for (unsigned i = 0, e = IncludeDirectories.size(); i != e && !NewBufOrErr;
60  ++i) {
61  IncludedFile =
62  IncludeDirectories[i] + sys::path::get_separator().data() + Filename;
63  NewBufOrErr = MemoryBuffer::getFile(IncludedFile);
64  }
65 
66  return NewBufOrErr;
67 }
68 
70  for (unsigned i = 0, e = Buffers.size(); i != e; ++i)
71  if (Loc.getPointer() >= Buffers[i].Buffer->getBufferStart() &&
72  // Use <= here so that a pointer to the null at the end of the buffer
73  // is included as part of the buffer.
74  Loc.getPointer() <= Buffers[i].Buffer->getBufferEnd())
75  return i + 1;
76  return 0;
77 }
78 
79 template <typename T>
80 static std::vector<T> &GetOrCreateOffsetCache(void *&OffsetCache,
81  MemoryBuffer *Buffer) {
82  if (OffsetCache)
83  return *static_cast<std::vector<T> *>(OffsetCache);
84 
85  // Lazily fill in the offset cache.
86  auto *Offsets = new std::vector<T>();
87  size_t Sz = Buffer->getBufferSize();
89  StringRef S = Buffer->getBuffer();
90  for (size_t N = 0; N < Sz; ++N) {
91  if (S[N] == '\n')
92  Offsets->push_back(static_cast<T>(N));
93  }
94 
95  OffsetCache = Offsets;
96  return *Offsets;
97 }
98 
99 template <typename T>
100 unsigned SourceMgr::SrcBuffer::getLineNumberSpecialized(const char *Ptr) const {
101  std::vector<T> &Offsets =
102  GetOrCreateOffsetCache<T>(OffsetCache, Buffer.get());
103 
104  const char *BufStart = Buffer->getBufferStart();
105  assert(Ptr >= BufStart && Ptr <= Buffer->getBufferEnd());
106  ptrdiff_t PtrDiff = Ptr - BufStart;
107  assert(PtrDiff >= 0 &&
108  static_cast<size_t>(PtrDiff) <= std::numeric_limits<T>::max());
109  T PtrOffset = static_cast<T>(PtrDiff);
110 
111  // llvm::lower_bound gives the number of EOL before PtrOffset. Add 1 to get
112  // the line number.
113  return llvm::lower_bound(Offsets, PtrOffset) - Offsets.begin() + 1;
114 }
115 
116 /// Look up a given \p Ptr in in the buffer, determining which line it came
117 /// from.
118 unsigned SourceMgr::SrcBuffer::getLineNumber(const char *Ptr) const {
119  size_t Sz = Buffer->getBufferSize();
121  return getLineNumberSpecialized<uint8_t>(Ptr);
122  else if (Sz <= std::numeric_limits<uint16_t>::max())
123  return getLineNumberSpecialized<uint16_t>(Ptr);
124  else if (Sz <= std::numeric_limits<uint32_t>::max())
125  return getLineNumberSpecialized<uint32_t>(Ptr);
126  else
127  return getLineNumberSpecialized<uint64_t>(Ptr);
128 }
129 
130 template <typename T>
131 const char *SourceMgr::SrcBuffer::getPointerForLineNumberSpecialized(
132  unsigned LineNo) const {
133  std::vector<T> &Offsets =
134  GetOrCreateOffsetCache<T>(OffsetCache, Buffer.get());
135 
136  // We start counting line and column numbers from 1.
137  if (LineNo != 0)
138  --LineNo;
139 
140  const char *BufStart = Buffer->getBufferStart();
141 
142  // The offset cache contains the location of the \n for the specified line,
143  // we want the start of the line. As such, we look for the previous entry.
144  if (LineNo == 0)
145  return BufStart;
146  if (LineNo > Offsets.size())
147  return nullptr;
148  return BufStart + Offsets[LineNo - 1] + 1;
149 }
150 
151 /// Return a pointer to the first character of the specified line number or
152 /// null if the line number is invalid.
153 const char *
154 SourceMgr::SrcBuffer::getPointerForLineNumber(unsigned LineNo) const {
155  size_t Sz = Buffer->getBufferSize();
157  return getPointerForLineNumberSpecialized<uint8_t>(LineNo);
158  else if (Sz <= std::numeric_limits<uint16_t>::max())
159  return getPointerForLineNumberSpecialized<uint16_t>(LineNo);
160  else if (Sz <= std::numeric_limits<uint32_t>::max())
161  return getPointerForLineNumberSpecialized<uint32_t>(LineNo);
162  else
163  return getPointerForLineNumberSpecialized<uint64_t>(LineNo);
164 }
165 
166 SourceMgr::SrcBuffer::SrcBuffer(SourceMgr::SrcBuffer &&Other)
167  : Buffer(std::move(Other.Buffer)), OffsetCache(Other.OffsetCache),
168  IncludeLoc(Other.IncludeLoc) {
169  Other.OffsetCache = nullptr;
170 }
171 
172 SourceMgr::SrcBuffer::~SrcBuffer() {
173  if (OffsetCache) {
174  size_t Sz = Buffer->getBufferSize();
176  delete static_cast<std::vector<uint8_t> *>(OffsetCache);
177  else if (Sz <= std::numeric_limits<uint16_t>::max())
178  delete static_cast<std::vector<uint16_t> *>(OffsetCache);
179  else if (Sz <= std::numeric_limits<uint32_t>::max())
180  delete static_cast<std::vector<uint32_t> *>(OffsetCache);
181  else
182  delete static_cast<std::vector<uint64_t> *>(OffsetCache);
183  OffsetCache = nullptr;
184  }
185 }
186 
187 std::pair<unsigned, unsigned>
188 SourceMgr::getLineAndColumn(SMLoc Loc, unsigned BufferID) const {
189  if (!BufferID)
190  BufferID = FindBufferContainingLoc(Loc);
191  assert(BufferID && "Invalid location!");
192 
193  auto &SB = getBufferInfo(BufferID);
194  const char *Ptr = Loc.getPointer();
195 
196  unsigned LineNo = SB.getLineNumber(Ptr);
197  const char *BufStart = SB.Buffer->getBufferStart();
198  size_t NewlineOffs = StringRef(BufStart, Ptr - BufStart).find_last_of("\n\r");
199  if (NewlineOffs == StringRef::npos)
200  NewlineOffs = ~(size_t)0;
201  return std::make_pair(LineNo, Ptr - BufStart - NewlineOffs);
202 }
203 
204 // FIXME: Note that the formatting of source locations is spread between
205 // multiple functions, some in SourceMgr and some in SMDiagnostic. A better
206 // solution would be a general-purpose source location formatter
207 // in one of those two classes, or possibly in SMLoc.
208 
209 /// Get a string with the source location formatted in the standard
210 /// style, but without the line offset. If \p IncludePath is true, the path
211 /// is included. If false, only the file name and extension are included.
213  bool IncludePath) const {
214  auto BufferID = FindBufferContainingLoc(Loc);
215  assert(BufferID && "Invalid location!");
216  auto FileSpec = getBufferInfo(BufferID).Buffer->getBufferIdentifier();
217 
218  if (IncludePath) {
219  return FileSpec.str() + ":" + std::to_string(FindLineNumber(Loc, BufferID));
220  } else {
221  auto I = FileSpec.find_last_of("/\\");
222  I = (I == FileSpec.size()) ? 0 : (I + 1);
223  return FileSpec.substr(I).str() + ":" +
224  std::to_string(FindLineNumber(Loc, BufferID));
225  }
226 }
227 
228 /// Given a line and column number in a mapped buffer, turn it into an SMLoc.
229 /// This will return a null SMLoc if the line/column location is invalid.
230 SMLoc SourceMgr::FindLocForLineAndColumn(unsigned BufferID, unsigned LineNo,
231  unsigned ColNo) {
232  auto &SB = getBufferInfo(BufferID);
233  const char *Ptr = SB.getPointerForLineNumber(LineNo);
234  if (!Ptr)
235  return SMLoc();
236 
237  // We start counting line and column numbers from 1.
238  if (ColNo != 0)
239  --ColNo;
240 
241  // If we have a column number, validate it.
242  if (ColNo) {
243  // Make sure the location is within the current line.
244  if (Ptr + ColNo > SB.Buffer->getBufferEnd())
245  return SMLoc();
246 
247  // Make sure there is no newline in the way.
248  if (StringRef(Ptr, ColNo).find_first_of("\n\r") != StringRef::npos)
249  return SMLoc();
250 
251  Ptr += ColNo;
252  }
253 
254  return SMLoc::getFromPointer(Ptr);
255 }
256 
257 void SourceMgr::PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const {
258  if (IncludeLoc == SMLoc())
259  return; // Top of stack.
260 
261  unsigned CurBuf = FindBufferContainingLoc(IncludeLoc);
262  assert(CurBuf && "Invalid or unspecified location!");
263 
264  PrintIncludeStack(getBufferInfo(CurBuf).IncludeLoc, OS);
265 
266  OS << "Included from " << getBufferInfo(CurBuf).Buffer->getBufferIdentifier()
267  << ":" << FindLineNumber(IncludeLoc, CurBuf) << ":\n";
268 }
269 
271  const Twine &Msg, ArrayRef<SMRange> Ranges,
272  ArrayRef<SMFixIt> FixIts) const {
273  // First thing to do: find the current buffer containing the specified
274  // location to pull out the source line.
276  std::pair<unsigned, unsigned> LineAndCol;
277  StringRef BufferID = "<unknown>";
278  StringRef LineStr;
279 
280  if (Loc.isValid()) {
281  unsigned CurBuf = FindBufferContainingLoc(Loc);
282  assert(CurBuf && "Invalid or unspecified location!");
283 
284  const MemoryBuffer *CurMB = getMemoryBuffer(CurBuf);
285  BufferID = CurMB->getBufferIdentifier();
286 
287  // Scan backward to find the start of the line.
288  const char *LineStart = Loc.getPointer();
289  const char *BufStart = CurMB->getBufferStart();
290  while (LineStart != BufStart && LineStart[-1] != '\n' &&
291  LineStart[-1] != '\r')
292  --LineStart;
293 
294  // Get the end of the line.
295  const char *LineEnd = Loc.getPointer();
296  const char *BufEnd = CurMB->getBufferEnd();
297  while (LineEnd != BufEnd && LineEnd[0] != '\n' && LineEnd[0] != '\r')
298  ++LineEnd;
299  LineStr = StringRef(LineStart, LineEnd - LineStart);
300 
301  // Convert any ranges to column ranges that only intersect the line of the
302  // location.
303  for (SMRange R : Ranges) {
304  if (!R.isValid())
305  continue;
306 
307  // If the line doesn't contain any part of the range, then ignore it.
308  if (R.Start.getPointer() > LineEnd || R.End.getPointer() < LineStart)
309  continue;
310 
311  // Ignore pieces of the range that go onto other lines.
312  if (R.Start.getPointer() < LineStart)
313  R.Start = SMLoc::getFromPointer(LineStart);
314  if (R.End.getPointer() > LineEnd)
315  R.End = SMLoc::getFromPointer(LineEnd);
316 
317  // Translate from SMLoc ranges to column ranges.
318  // FIXME: Handle multibyte characters.
319  ColRanges.push_back(std::make_pair(R.Start.getPointer() - LineStart,
320  R.End.getPointer() - LineStart));
321  }
322 
323  LineAndCol = getLineAndColumn(Loc, CurBuf);
324  }
325 
326  return SMDiagnostic(*this, Loc, BufferID, LineAndCol.first,
327  LineAndCol.second - 1, Kind, Msg.str(), LineStr,
328  ColRanges, FixIts);
329 }
330 
332  bool ShowColors) const {
333  // Report the message with the diagnostic handler if present.
334  if (DiagHandler) {
335  DiagHandler(Diagnostic, DiagContext);
336  return;
337  }
338 
339  if (Diagnostic.getLoc().isValid()) {
340  unsigned CurBuf = FindBufferContainingLoc(Diagnostic.getLoc());
341  assert(CurBuf && "Invalid or unspecified location!");
342  PrintIncludeStack(getBufferInfo(CurBuf).IncludeLoc, OS);
343  }
344 
345  Diagnostic.print(nullptr, OS, ShowColors);
346 }
347 
350  ArrayRef<SMRange> Ranges, ArrayRef<SMFixIt> FixIts,
351  bool ShowColors) const {
352  PrintMessage(OS, GetMessage(Loc, Kind, Msg, Ranges, FixIts), ShowColors);
353 }
354 
356  const Twine &Msg, ArrayRef<SMRange> Ranges,
357  ArrayRef<SMFixIt> FixIts, bool ShowColors) const {
358  PrintMessage(errs(), Loc, Kind, Msg, Ranges, FixIts, ShowColors);
359 }
360 
361 //===----------------------------------------------------------------------===//
362 // SMFixIt Implementation
363 //===----------------------------------------------------------------------===//
364 
365 SMFixIt::SMFixIt(SMRange R, const Twine &Replacement)
366  : Range(R), Text(Replacement.str()) {
367  assert(R.isValid());
368 }
369 
370 //===----------------------------------------------------------------------===//
371 // SMDiagnostic Implementation
372 //===----------------------------------------------------------------------===//
373 
376  StringRef LineStr,
377  ArrayRef<std::pair<unsigned, unsigned>> Ranges,
378  ArrayRef<SMFixIt> Hints)
379  : SM(&sm), Loc(L), Filename(std::string(FN)), LineNo(Line), ColumnNo(Col),
380  Kind(Kind), Message(Msg), LineContents(LineStr), Ranges(Ranges.vec()),
381  FixIts(Hints.begin(), Hints.end()) {
382  llvm::sort(FixIts);
383 }
384 
385 static void buildFixItLine(std::string &CaretLine, std::string &FixItLine,
386  ArrayRef<SMFixIt> FixIts,
387  ArrayRef<char> SourceLine) {
388  if (FixIts.empty())
389  return;
390 
391  const char *LineStart = SourceLine.begin();
392  const char *LineEnd = SourceLine.end();
393 
394  size_t PrevHintEndCol = 0;
395 
396  for (const llvm::SMFixIt &Fixit : FixIts) {
397  // If the fixit contains a newline or tab, ignore it.
398  if (Fixit.getText().find_first_of("\n\r\t") != StringRef::npos)
399  continue;
400 
401  SMRange R = Fixit.getRange();
402 
403  // If the line doesn't contain any part of the range, then ignore it.
404  if (R.Start.getPointer() > LineEnd || R.End.getPointer() < LineStart)
405  continue;
406 
407  // Translate from SMLoc to column.
408  // Ignore pieces of the range that go onto other lines.
409  // FIXME: Handle multibyte characters in the source line.
410  unsigned FirstCol;
411  if (R.Start.getPointer() < LineStart)
412  FirstCol = 0;
413  else
414  FirstCol = R.Start.getPointer() - LineStart;
415 
416  // If we inserted a long previous hint, push this one forwards, and add
417  // an extra space to show that this is not part of the previous
418  // completion. This is sort of the best we can do when two hints appear
419  // to overlap.
420  //
421  // Note that if this hint is located immediately after the previous
422  // hint, no space will be added, since the location is more important.
423  unsigned HintCol = FirstCol;
424  if (HintCol < PrevHintEndCol)
425  HintCol = PrevHintEndCol + 1;
426 
427  // FIXME: This assertion is intended to catch unintended use of multibyte
428  // characters in fixits. If we decide to do this, we'll have to track
429  // separate byte widths for the source and fixit lines.
430  assert((size_t)sys::locale::columnWidth(Fixit.getText()) ==
431  Fixit.getText().size());
432 
433  // This relies on one byte per column in our fixit hints.
434  unsigned LastColumnModified = HintCol + Fixit.getText().size();
435  if (LastColumnModified > FixItLine.size())
436  FixItLine.resize(LastColumnModified, ' ');
437 
438  llvm::copy(Fixit.getText(), FixItLine.begin() + HintCol);
439 
440  PrevHintEndCol = LastColumnModified;
441 
442  // For replacements, mark the removal range with '~'.
443  // FIXME: Handle multibyte characters in the source line.
444  unsigned LastCol;
445  if (R.End.getPointer() >= LineEnd)
446  LastCol = LineEnd - LineStart;
447  else
448  LastCol = R.End.getPointer() - LineStart;
449 
450  std::fill(&CaretLine[FirstCol], &CaretLine[LastCol], '~');
451  }
452 }
453 
454 static void printSourceLine(raw_ostream &S, StringRef LineContents) {
455  // Print out the source line one character at a time, so we can expand tabs.
456  for (unsigned i = 0, e = LineContents.size(), OutCol = 0; i != e; ++i) {
457  size_t NextTab = LineContents.find('\t', i);
458  // If there were no tabs left, print the rest, we are done.
459  if (NextTab == StringRef::npos) {
460  S << LineContents.drop_front(i);
461  break;
462  }
463 
464  // Otherwise, print from i to NextTab.
465  S << LineContents.slice(i, NextTab);
466  OutCol += NextTab - i;
467  i = NextTab;
468 
469  // If we have a tab, emit at least one space, then round up to 8 columns.
470  do {
471  S << ' ';
472  ++OutCol;
473  } while ((OutCol % TabStop) != 0);
474  }
475  S << '\n';
476 }
477 
478 static bool isNonASCII(char c) { return c & 0x80; }
479 
480 void SMDiagnostic::print(const char *ProgName, raw_ostream &OS, bool ShowColors,
481  bool ShowKindLabel) const {
483 
484  {
485  WithColor S(OS, raw_ostream::SAVEDCOLOR, true, false, Mode);
486 
487  if (ProgName && ProgName[0])
488  S << ProgName << ": ";
489 
490  if (!Filename.empty()) {
491  if (Filename == "-")
492  S << "<stdin>";
493  else
494  S << Filename;
495 
496  if (LineNo != -1) {
497  S << ':' << LineNo;
498  if (ColumnNo != -1)
499  S << ':' << (ColumnNo + 1);
500  }
501  S << ": ";
502  }
503  }
504 
505  if (ShowKindLabel) {
506  switch (Kind) {
507  case SourceMgr::DK_Error:
508  WithColor::error(OS, "", !ShowColors);
509  break;
511  WithColor::warning(OS, "", !ShowColors);
512  break;
513  case SourceMgr::DK_Note:
514  WithColor::note(OS, "", !ShowColors);
515  break;
517  WithColor::remark(OS, "", !ShowColors);
518  break;
519  }
520  }
521 
522  WithColor(OS, raw_ostream::SAVEDCOLOR, true, false, Mode) << Message << '\n';
523 
524  if (LineNo == -1 || ColumnNo == -1)
525  return;
526 
527  // FIXME: If there are multibyte or multi-column characters in the source, all
528  // our ranges will be wrong. To do this properly, we'll need a byte-to-column
529  // map like Clang's TextDiagnostic. For now, we'll just handle tabs by
530  // expanding them later, and bail out rather than show incorrect ranges and
531  // misaligned fixits for any other odd characters.
532  if (any_of(LineContents, isNonASCII)) {
533  printSourceLine(OS, LineContents);
534  return;
535  }
536  size_t NumColumns = LineContents.size();
537 
538  // Build the line with the caret and ranges.
539  std::string CaretLine(NumColumns + 1, ' ');
540 
541  // Expand any ranges.
542  for (const std::pair<unsigned, unsigned> &R : Ranges)
543  std::fill(&CaretLine[R.first],
544  &CaretLine[std::min((size_t)R.second, CaretLine.size())], '~');
545 
546  // Add any fix-its.
547  // FIXME: Find the beginning of the line properly for multibyte characters.
548  std::string FixItInsertionLine;
550  CaretLine, FixItInsertionLine, FixIts,
551  makeArrayRef(Loc.getPointer() - ColumnNo, LineContents.size()));
552 
553  // Finally, plop on the caret.
554  if (unsigned(ColumnNo) <= NumColumns)
555  CaretLine[ColumnNo] = '^';
556  else
557  CaretLine[NumColumns] = '^';
558 
559  // ... and remove trailing whitespace so the output doesn't wrap for it. We
560  // know that the line isn't completely empty because it has the caret in it at
561  // least.
562  CaretLine.erase(CaretLine.find_last_not_of(' ') + 1);
563 
564  printSourceLine(OS, LineContents);
565 
566  {
568  WithColor S(OS, raw_ostream::GREEN, true, false, Mode);
569 
570  // Print out the caret line, matching tabs in the source line.
571  for (unsigned i = 0, e = CaretLine.size(), OutCol = 0; i != e; ++i) {
572  if (i >= LineContents.size() || LineContents[i] != '\t') {
573  S << CaretLine[i];
574  ++OutCol;
575  continue;
576  }
577 
578  // Okay, we have a tab. Insert the appropriate number of characters.
579  do {
580  S << CaretLine[i];
581  ++OutCol;
582  } while ((OutCol % TabStop) != 0);
583  }
584  S << '\n';
585  }
586 
587  // Print out the replacement line, matching tabs in the source line.
588  if (FixItInsertionLine.empty())
589  return;
590 
591  for (size_t i = 0, e = FixItInsertionLine.size(), OutCol = 0; i < e; ++i) {
592  if (i >= LineContents.size() || LineContents[i] != '\t') {
593  OS << FixItInsertionLine[i];
594  ++OutCol;
595  continue;
596  }
597 
598  // Okay, we have a tab. Insert the appropriate number of characters.
599  do {
600  OS << FixItInsertionLine[i];
601  // FIXME: This is trying not to break up replacements, but then to re-sync
602  // with the tabs between replacements. This will fail, though, if two
603  // fix-it replacements are exactly adjacent, or if a fix-it contains a
604  // space. Really we should be precomputing column widths, which we'll
605  // need anyway for multibyte chars.
606  if (FixItInsertionLine[i] != ' ')
607  ++i;
608  ++OutCol;
609  } while (((OutCol % TabStop) != 0) && i != e);
610  }
611  OS << '\n';
612 }
i
i
Definition: README.txt:29
llvm::SMFixIt::SMFixIt
SMFixIt(SMRange R, const Twine &Replacement)
Definition: SourceMgr.cpp:365
MemoryBuffer.h
llvm::SMDiagnostic::SMDiagnostic
SMDiagnostic()=default
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::lower_bound
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1724
StringRef.h
llvm::StringRef::npos
static constexpr size_t npos
Definition: StringRef.h:60
llvm::StringRef::find
LLVM_NODISCARD size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Definition: StringRef.h:315
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1185
Path.h
llvm::raw_ostream::GREEN
static constexpr Colors GREEN
Definition: raw_ostream.h:113
llvm::sys::path::end
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:235
llvm::sys::path::begin
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:226
llvm::copy
OutputIt copy(R &&Range, OutputIt Out)
Definition: STLExtras.h:1656
llvm::WithColor
An RAII object that temporarily switches an output stream to a specific color.
Definition: WithColor.h:53
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::sys::locale::columnWidth
int columnWidth(StringRef s)
Definition: Locale.cpp:9
llvm::SourceMgr::DK_Note
@ DK_Note
Definition: SourceMgr.h:37
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:893
STLExtras.h
llvm::StringRef::slice
LLVM_NODISCARD StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
Definition: StringRef.h:732
llvm::MemoryBuffer
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:50
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:159
llvm::SourceMgr::PrintIncludeStack
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:257
llvm::SourceMgr::DK_Remark
@ DK_Remark
Definition: SourceMgr.h:36
llvm::WithColor::remark
static raw_ostream & remark()
Convenience method for printing "remark: " to stderr.
Definition: WithColor.cpp:89
llvm::WithColor::error
static raw_ostream & error()
Convenience method for printing "error: " to stderr.
Definition: WithColor.cpp:83
llvm::MemoryBuffer::getFile
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
Definition: MemoryBuffer.cpp:239
llvm::SMFixIt
Represents a single fixit, a replacement of one range of text with another.
Definition: SourceMgr.h:256
llvm::StringRef::find_last_of
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:436
llvm::SMLoc
Represents a location in source code.
Definition: SMLoc.h:23
ptrdiff_t
llvm::MemoryBuffer::getBufferEnd
const char * getBufferEnd() const
Definition: MemoryBuffer.h:66
llvm::MemoryBuffer::getBufferSize
size_t getBufferSize() const
Definition: MemoryBuffer.h:67
Twine.h
llvm::SMDiagnostic
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:281
SMLoc.h
llvm::ColorMode::Auto
@ Auto
Determine whether to use color based on the command line argument and the raw_ostream.
llvm::ColorMode::Disable
@ Disable
Disable colors.
printSourceLine
static void printSourceLine(raw_ostream &S, StringRef LineContents)
Definition: SourceMgr.cpp:454
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::MemoryBuffer::getBuffer
StringRef getBuffer() const
Definition: MemoryBuffer.h:69
c
the resulting code requires compare and branches when and if the revised code is with conditional branches instead of More there is a byte word extend before each where there should be only and the condition codes are not remembered when the same two values are compared twice More LSR enhancements i8 and i32 load store addressing modes are identical int int c
Definition: README.txt:418
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
SourceMgr.h
llvm::SourceMgr::getMemoryBuffer
const MemoryBuffer * getMemoryBuffer(unsigned i) const
Definition: SourceMgr.h:125
llvm::MemoryBuffer::getBufferIdentifier
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
Definition: MemoryBuffer.h:75
isNonASCII
static bool isNonASCII(char c)
Definition: SourceMgr.cpp:478
llvm::SourceMgr::OpenIncludeFile
ErrorOr< std::unique_ptr< MemoryBuffer > > OpenIncludeFile(const std::string &Filename, std::string &IncludedFile)
Search for a file with the specified name in the current directory or in one of the IncludeDirs,...
Definition: SourceMgr.cpp:52
llvm::WithColor::warning
static raw_ostream & warning()
Convenience method for printing "warning: " to stderr.
Definition: WithColor.cpp:85
llvm::SMDiagnostic::print
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true) const
Definition: SourceMgr.cpp:480
llvm::SMLoc::isValid
bool isValid() const
Definition: SMLoc.h:29
llvm::sys::path::get_separator
StringRef get_separator(Style style=Style::native)
Return the preferred separator for this platform.
Definition: Path.cpp:609
llvm::SourceMgr::PrintMessage
void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
Definition: SourceMgr.cpp:348
llvm::SourceMgr::DK_Warning
@ DK_Warning
Definition: SourceMgr.h:35
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
ErrorOr.h
buildFixItLine
static void buildFixItLine(std::string &CaretLine, std::string &FixItLine, ArrayRef< SMFixIt > FixIts, ArrayRef< char > SourceLine)
Definition: SourceMgr.cpp:385
I
#define I(x, y, z)
Definition: MD5.cpp:58
ArrayRef.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1663
Mode
SI Whole Quad Mode
Definition: SIWholeQuadMode.cpp:262
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::min
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:357
llvm::SourceMgr::FindBufferContainingLoc
unsigned FindBufferContainingLoc(SMLoc Loc) const
Return the ID of the buffer containing the specified location.
Definition: SourceMgr.cpp:69
llvm::any_of
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1612
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::SourceMgr
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Definition: SourceMgr.h:31
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
TabStop
static const size_t TabStop
Definition: SourceMgr.cpp:38
llvm::ColorMode
ColorMode
Definition: WithColor.h:39
llvm::AMDGPU::SendMsg::Msg
const CustomOperand< const MCSubtargetInfo & > Msg[]
Definition: AMDGPUAsmUtils.cpp:39
llvm::StringRef::size
constexpr LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:157
llvm::SourceMgr::DiagKind
DiagKind
Definition: SourceMgr.h:33
WithColor.h
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::MemoryBuffer::getBufferStart
const char * getBufferStart() const
Definition: MemoryBuffer.h:65
std
Definition: BitVector.h:851
llvm::StringRef::drop_front
LLVM_NODISCARD StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition: StringRef.h:653
llvm::SMLoc::getPointer
const char * getPointer() const
Definition: SMLoc.h:34
llvm::ArrayRef::begin
iterator begin() const
Definition: ArrayRef.h:152
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1550
llvm::SourceMgr::DK_Error
@ DK_Error
Definition: SourceMgr.h:34
Locale.h
llvm::raw_ostream::SAVEDCOLOR
static constexpr Colors SAVEDCOLOR
Definition: raw_ostream.h:119
llvm::SourceMgr::AddNewSourceBuffer
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
Definition: SourceMgr.h:144
llvm::SourceMgr::GetMessage
SMDiagnostic GetMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}) const
Return an SMDiagnostic at the specified location with the specified string.
Definition: SourceMgr.cpp:270
llvm::SourceMgr::AddIncludeFile
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:40
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:475
SmallVector.h
llvm::SMRange
Represents a range in source code.
Definition: SMLoc.h:48
N
#define N
llvm::ErrorOr
Represents either an error or a value T.
Definition: ErrorOr.h:56
llvm::to_string
std::string to_string(const T &Value)
Definition: ScopedPrinter.h:86
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
llvm::StringRef::data
const LLVM_NODISCARD char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:149
llvm::SMLoc::getFromPointer
static SMLoc getFromPointer(const char *Ptr)
Definition: SMLoc.h:36
llvm::SourceMgr::getLineAndColumn
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:188
llvm::SourceMgr::FindLocForLineAndColumn
SMLoc FindLocForLineAndColumn(unsigned BufferID, unsigned LineNo, unsigned ColNo)
Given a line and column number in a mapped buffer, turn it into an SMLoc.
Definition: SourceMgr.cpp:230
llvm::WithColor::note
static raw_ostream & note()
Convenience method for printing "note: " to stderr.
Definition: WithColor.cpp:87
llvm::SMDiagnostic::getLoc
SMLoc getLoc() const
Definition: SourceMgr.h:306
raw_ostream.h
llvm::SI::KernelInputOffsets::Offsets
Offsets
Offsets in bytes from the start of the input buffer.
Definition: SIInstrInfo.h:1283
GetOrCreateOffsetCache
static std::vector< T > & GetOrCreateOffsetCache(void *&OffsetCache, MemoryBuffer *Buffer)
Definition: SourceMgr.cpp:80
llvm::ArrayRef::end
iterator end() const
Definition: ArrayRef.h:153
llvm::SourceMgr::getBufferInfo
const SrcBuffer & getBufferInfo(unsigned i) const
Definition: SourceMgr.h:120
SpecialSubKind::string
@ string
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1225
llvm::SourceMgr::getFormattedLocationNoOffset
std::string getFormattedLocationNoOffset(SMLoc Loc, bool IncludePath=false) const
Get a string with the SMLoc filename and line number formatted in the standard style.
Definition: SourceMgr.cpp:212
llvm::SourceMgr::FindLineNumber
unsigned FindLineNumber(SMLoc Loc, unsigned BufferID=0) const
Find the line number for the specified location in the specified file.
Definition: SourceMgr.h:196