blob: f5f3bddcb21e8e872b989e6a609ec1a4d4c614ab [file] [log] [blame]
Daniel Dunbarbadeace2009-06-23 23:39:15 +00001//===- lib/MC/MCContext.cpp - Machine Code Context ------------------------===//
Daniel Dunbarca29e4d2009-06-23 22:01:43 +00002//
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#include "llvm/MC/MCContext.h"
Chris Lattner86dfd732009-10-19 22:49:00 +000011#include "llvm/ADT/SmallString.h"
12#include "llvm/ADT/Twine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000013#include "llvm/MC/MCAsmInfo.h"
14#include "llvm/MC/MCDwarf.h"
15#include "llvm/MC/MCLabel.h"
16#include "llvm/MC/MCObjectFileInfo.h"
17#include "llvm/MC/MCRegisterInfo.h"
18#include "llvm/MC/MCSectionCOFF.h"
19#include "llvm/MC/MCSectionELF.h"
20#include "llvm/MC/MCSectionMachO.h"
21#include "llvm/MC/MCSymbol.h"
Rafael Espindolaaea49582011-01-23 04:28:49 +000022#include "llvm/Support/ELF.h"
Jim Grosbachb18b4092012-01-26 23:20:11 +000023#include "llvm/Support/ErrorHandling.h"
Rafael Espindolaef03b9f2013-06-14 20:26:58 +000024#include "llvm/Support/FileSystem.h"
Eric Christopher906da232012-12-18 00:31:01 +000025#include "llvm/Support/MemoryBuffer.h"
Jim Grosbachb18b4092012-01-26 23:20:11 +000026#include "llvm/Support/Signals.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000027#include "llvm/Support/SourceMgr.h"
David Blaikie15b25df2013-10-22 23:41:52 +000028#include <map>
29
Daniel Dunbarca29e4d2009-06-23 22:01:43 +000030using namespace llvm;
31
David Blaikie15b25df2013-10-22 23:41:52 +000032typedef std::pair<std::string, std::string> SectionGroupPair;
33
Chris Lattner20731122010-04-08 20:30:37 +000034typedef StringMap<const MCSectionMachO*> MachOUniqueMapTy;
David Blaikie15b25df2013-10-22 23:41:52 +000035typedef std::map<SectionGroupPair, const MCSectionELF *> ELFUniqueMapTy;
Rafael Espindola60ec3832013-11-19 19:52:52 +000036typedef std::map<SectionGroupPair, const MCSectionCOFF *> COFFUniqueMapTy;
Chris Lattner20731122010-04-08 20:30:37 +000037
Bill Wendlingbc07a892013-06-18 07:20:20 +000038MCContext::MCContext(const MCAsmInfo *mai, const MCRegisterInfo *mri,
Pedro Artigase84b13f2012-12-06 22:12:44 +000039 const MCObjectFileInfo *mofi, const SourceMgr *mgr,
Eric Christopher79f16562012-12-18 00:42:26 +000040 bool DoAutoReset) :
Jim Grosbachdfc5b552012-01-26 23:20:05 +000041 SrcMgr(mgr), MAI(mai), MRI(mri), MOFI(mofi),
Eli Friedman0e402082011-04-18 05:02:31 +000042 Allocator(), Symbols(Allocator), UsedNames(Allocator),
Chandler Carruth10700aad2012-12-17 21:32:42 +000043 NextUniqueID(0),
Andrew Trick1c6a4c32013-12-10 04:39:05 +000044 CurrentDwarfLoc(0,0,0,DWARF2_FLAG_IS_STMT,0,0),
Pedro Artigas7212ee42012-12-12 22:59:46 +000045 DwarfLocSeen(false), GenDwarfForAssembly(false), GenDwarfFileNumber(0),
Manman Ren4e042a62013-02-05 21:52:47 +000046 AllowTemporaryLabels(true), DwarfCompileUnitID(0), AutoReset(DoAutoReset) {
Pedro Artigas7212ee42012-12-12 22:59:46 +000047
Rafael Espindolaef03b9f2013-06-14 20:26:58 +000048 error_code EC = llvm::sys::fs::current_path(CompilationDir);
Andrew Trick32591d32013-12-10 04:39:09 +000049 if (EC)
50 CompilationDir.clear();
Rafael Espindolaef03b9f2013-06-14 20:26:58 +000051
Chris Lattner20731122010-04-08 20:30:37 +000052 MachOUniquingMap = 0;
Chris Lattner5418dd52010-04-08 21:26:26 +000053 ELFUniquingMap = 0;
Chris Lattner87cffa92010-05-07 17:17:41 +000054 COFFUniquingMap = 0;
Kevin Enderbye233dda2010-06-28 21:45:58 +000055
56 SecureLogFile = getenv("AS_SECURE_LOG_FILE");
57 SecureLog = 0;
58 SecureLogUsed = false;
Eric Christopher906da232012-12-18 00:31:01 +000059
60 if (SrcMgr && SrcMgr->getNumBuffers() > 0)
61 MainFileName = SrcMgr->getMemoryBuffer(0)->getBufferIdentifier();
62 else
63 MainFileName = "";
Pedro Artigase84b13f2012-12-06 22:12:44 +000064}
65
66MCContext::~MCContext() {
67
Pedro Artigas7212ee42012-12-12 22:59:46 +000068 if (AutoReset)
69 reset();
Pedro Artigase84b13f2012-12-06 22:12:44 +000070
71 // NOTE: The symbols are all allocated out of a bump pointer allocator,
72 // we don't need to free them here.
Andrew Trick1c6a4c32013-12-10 04:39:05 +000073
Pedro Artigase84b13f2012-12-06 22:12:44 +000074 // If the stream for the .secure_log_unique directive was created free it.
75 delete (raw_ostream*)SecureLog;
76}
77
78//===----------------------------------------------------------------------===//
79// Module Lifetime Management
80//===----------------------------------------------------------------------===//
81
Pedro Artigas7212ee42012-12-12 22:59:46 +000082void MCContext::reset() {
Pedro Artigase84b13f2012-12-06 22:12:44 +000083 UsedNames.clear();
84 Symbols.clear();
85 Allocator.Reset();
86 Instances.clear();
David Blaikied9012ba2014-03-13 21:59:51 +000087 MCDwarfLineTablesCUMap.clear();
Pedro Artigase84b13f2012-12-06 22:12:44 +000088 MCGenDwarfLabelEntries.clear();
89 DwarfDebugFlags = StringRef();
Pedro Artigas7ba2edc2013-02-20 00:10:29 +000090 DwarfCompileUnitID = 0;
Pedro Artigase84b13f2012-12-06 22:12:44 +000091 CurrentDwarfLoc = MCDwarfLoc(0,0,0,DWARF2_FLAG_IS_STMT,0,0);
Michael J. Spencerf13f4422010-11-26 04:16:08 +000092
Chris Lattner20731122010-04-08 20:30:37 +000093 // If we have the MachO uniquing map, free it.
94 delete (MachOUniqueMapTy*)MachOUniquingMap;
Chris Lattner5418dd52010-04-08 21:26:26 +000095 delete (ELFUniqueMapTy*)ELFUniquingMap;
Chris Lattner87cffa92010-05-07 17:17:41 +000096 delete (COFFUniqueMapTy*)COFFUniquingMap;
Pedro Artigase84b13f2012-12-06 22:12:44 +000097 MachOUniquingMap = 0;
98 ELFUniquingMap = 0;
99 COFFUniquingMap = 0;
Pedro Artigas7212ee42012-12-12 22:59:46 +0000100
101 NextUniqueID = 0;
102 AllowTemporaryLabels = true;
103 DwarfLocSeen = false;
104 GenDwarfForAssembly = false;
105 GenDwarfFileNumber = 0;
Daniel Dunbarca29e4d2009-06-23 22:01:43 +0000106}
107
Chris Lattner20731122010-04-08 20:30:37 +0000108//===----------------------------------------------------------------------===//
109// Symbol Manipulation
110//===----------------------------------------------------------------------===//
111
Chris Lattner98970432010-03-30 18:10:53 +0000112MCSymbol *MCContext::GetOrCreateSymbol(StringRef Name) {
Chris Lattnerb973ea82010-03-10 01:29:27 +0000113 assert(!Name.empty() && "Normal symbols cannot be unnamed!");
Michael J. Spencerf13f4422010-11-26 04:16:08 +0000114
Chris Lattner13348762010-03-15 06:15:35 +0000115 // Do the lookup and get the entire StringMapEntry. We want access to the
116 // key if we are creating the entry.
117 StringMapEntry<MCSymbol*> &Entry = Symbols.GetOrCreateValue(Name);
Rafael Espindola5fe5f452010-12-01 20:46:11 +0000118 MCSymbol *Sym = Entry.getValue();
119
120 if (Sym)
121 return Sym;
122
123 Sym = CreateSymbol(Name);
124 Entry.setValue(Sym);
125 return Sym;
126}
127
128MCSymbol *MCContext::CreateSymbol(StringRef Name) {
Daniel Dunbar4ee0d032011-03-28 22:49:15 +0000129 // Determine whether this is an assembler temporary or normal label, if used.
130 bool isTemporary = false;
131 if (AllowTemporaryLabels)
Bill Wendlingbc07a892013-06-18 07:20:20 +0000132 isTemporary = Name.startswith(MAI->getPrivateGlobalPrefix());
Rafael Espindola5fe5f452010-12-01 20:46:11 +0000133
134 StringMapEntry<bool> *NameEntry = &UsedNames.GetOrCreateValue(Name);
135 if (NameEntry->getValue()) {
Alp Tokerf907b892013-12-05 05:44:44 +0000136 assert(isTemporary && "Cannot rename non-temporary symbols");
Benjamin Kramer2b6c96b2011-04-09 11:26:27 +0000137 SmallString<128> NewName = Name;
Rafael Espindola5fe5f452010-12-01 20:46:11 +0000138 do {
Benjamin Kramer2b6c96b2011-04-09 11:26:27 +0000139 NewName.resize(Name.size());
140 raw_svector_ostream(NewName) << NextUniqueID++;
141 NameEntry = &UsedNames.GetOrCreateValue(NewName);
Rafael Espindola5fe5f452010-12-01 20:46:11 +0000142 } while (NameEntry->getValue());
143 }
144 NameEntry->setValue(true);
Chris Lattner3f5738d2009-06-24 04:31:49 +0000145
Chris Lattner13348762010-03-15 06:15:35 +0000146 // Ok, the entry doesn't already exist. Have the MCSymbol object itself refer
Rafael Espindola5fe5f452010-12-01 20:46:11 +0000147 // to the copy of the string that is embedded in the UsedNames entry.
148 MCSymbol *Result = new (*this) MCSymbol(NameEntry->getKey(), isTemporary);
149
150 return Result;
Chris Lattner3f5738d2009-06-24 04:31:49 +0000151}
152
Chris Lattner98970432010-03-30 18:10:53 +0000153MCSymbol *MCContext::GetOrCreateSymbol(const Twine &Name) {
Chris Lattner86dfd732009-10-19 22:49:00 +0000154 SmallString<128> NameSV;
David Blaikie8e5283a2013-12-03 18:18:28 +0000155 return GetOrCreateSymbol(Name.toStringRef(NameSV));
Chris Lattner86dfd732009-10-19 22:49:00 +0000156}
157
Chris Lattner073d8172010-03-14 08:23:30 +0000158MCSymbol *MCContext::CreateTempSymbol() {
Rafael Espindola5fe5f452010-12-01 20:46:11 +0000159 SmallString<128> NameSV;
Benjamin Kramer2b6c96b2011-04-09 11:26:27 +0000160 raw_svector_ostream(NameSV)
Bill Wendlingbc07a892013-06-18 07:20:20 +0000161 << MAI->getPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
Rafael Espindola5fe5f452010-12-01 20:46:11 +0000162 return CreateSymbol(NameSV);
Chris Lattner073d8172010-03-14 08:23:30 +0000163}
164
Rafael Espindola4269b9e2014-03-13 18:09:26 +0000165unsigned MCContext::NextInstance(unsigned LocalLabelVal) {
Benjamin Kramerab7be752010-05-18 12:15:34 +0000166 MCLabel *&Label = Instances[LocalLabelVal];
167 if (!Label)
168 Label = new (*this) MCLabel(0);
169 return Label->incInstance();
Kevin Enderby0510b482010-05-17 23:08:19 +0000170}
171
Rafael Espindola4269b9e2014-03-13 18:09:26 +0000172unsigned MCContext::GetInstance(unsigned LocalLabelVal) {
Benjamin Kramerab7be752010-05-18 12:15:34 +0000173 MCLabel *&Label = Instances[LocalLabelVal];
174 if (!Label)
175 Label = new (*this) MCLabel(0);
176 return Label->getInstance();
Kevin Enderby0510b482010-05-17 23:08:19 +0000177}
178
Rafael Espindola4269b9e2014-03-13 18:09:26 +0000179MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
180 unsigned Instance) {
181 MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)];
182 if (!Sym)
183 Sym = CreateTempSymbol();
184 return Sym;
Kevin Enderby0510b482010-05-17 23:08:19 +0000185}
Rafael Espindola4269b9e2014-03-13 18:09:26 +0000186
187MCSymbol *MCContext::CreateDirectionalLocalSymbol(unsigned LocalLabelVal) {
188 unsigned Instance = NextInstance(LocalLabelVal);
189 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
190}
191
192MCSymbol *MCContext::GetDirectionalLocalSymbol(unsigned LocalLabelVal,
193 bool Before) {
194 unsigned Instance = GetInstance(LocalLabelVal);
195 if (!Before)
196 ++Instance;
197 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
Kevin Enderby0510b482010-05-17 23:08:19 +0000198}
199
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000200MCSymbol *MCContext::LookupSymbol(StringRef Name) const {
Daniel Dunbarca29e4d2009-06-23 22:01:43 +0000201 return Symbols.lookup(Name);
202}
Chris Lattner20731122010-04-08 20:30:37 +0000203
Roman Divacky0be33592012-09-18 17:10:37 +0000204MCSymbol *MCContext::LookupSymbol(const Twine &Name) const {
205 SmallString<128> NameSV;
206 Name.toVector(NameSV);
207 return LookupSymbol(NameSV.str());
208}
209
Chris Lattner20731122010-04-08 20:30:37 +0000210//===----------------------------------------------------------------------===//
211// Section Management
212//===----------------------------------------------------------------------===//
213
214const MCSectionMachO *MCContext::
215getMachOSection(StringRef Segment, StringRef Section,
216 unsigned TypeAndAttributes,
217 unsigned Reserved2, SectionKind Kind) {
Michael J. Spencerf13f4422010-11-26 04:16:08 +0000218
Chris Lattner20731122010-04-08 20:30:37 +0000219 // We unique sections by their segment/section pair. The returned section
220 // may not have the same flags as the requested section, if so this should be
221 // diagnosed by the client as an error.
Michael J. Spencerf13f4422010-11-26 04:16:08 +0000222
Chris Lattner20731122010-04-08 20:30:37 +0000223 // Create the map if it doesn't already exist.
224 if (MachOUniquingMap == 0)
225 MachOUniquingMap = new MachOUniqueMapTy();
226 MachOUniqueMapTy &Map = *(MachOUniqueMapTy*)MachOUniquingMap;
Michael J. Spencerf13f4422010-11-26 04:16:08 +0000227
Chris Lattner20731122010-04-08 20:30:37 +0000228 // Form the name to look up.
229 SmallString<64> Name;
230 Name += Segment;
231 Name.push_back(',');
232 Name += Section;
Michael J. Spencerf13f4422010-11-26 04:16:08 +0000233
Chris Lattner20731122010-04-08 20:30:37 +0000234 // Do the lookup, if we have a hit, return it.
235 const MCSectionMachO *&Entry = Map[Name.str()];
236 if (Entry) return Entry;
Michael J. Spencerf13f4422010-11-26 04:16:08 +0000237
Chris Lattner20731122010-04-08 20:30:37 +0000238 // Otherwise, return a new section.
Chris Lattner5418dd52010-04-08 21:26:26 +0000239 return Entry = new (*this) MCSectionMachO(Segment, Section, TypeAndAttributes,
240 Reserved2, Kind);
Chris Lattner20731122010-04-08 20:30:37 +0000241}
Chris Lattner5418dd52010-04-08 21:26:26 +0000242
Rafael Espindola36ef57d2010-11-10 19:05:07 +0000243const MCSectionELF *MCContext::
Chris Lattner5418dd52010-04-08 21:26:26 +0000244getELFSection(StringRef Section, unsigned Type, unsigned Flags,
Rafael Espindolaa3e9a222010-11-11 18:13:52 +0000245 SectionKind Kind) {
246 return getELFSection(Section, Type, Flags, Kind, 0, "");
247}
248
249const MCSectionELF *MCContext::
250getELFSection(StringRef Section, unsigned Type, unsigned Flags,
251 SectionKind Kind, unsigned EntrySize, StringRef Group) {
Chris Lattner5418dd52010-04-08 21:26:26 +0000252 if (ELFUniquingMap == 0)
253 ELFUniquingMap = new ELFUniqueMapTy();
254 ELFUniqueMapTy &Map = *(ELFUniqueMapTy*)ELFUniquingMap;
Michael J. Spencerf13f4422010-11-26 04:16:08 +0000255
Chris Lattner5418dd52010-04-08 21:26:26 +0000256 // Do the lookup, if we have a hit, return it.
David Blaikie15b25df2013-10-22 23:41:52 +0000257 std::pair<ELFUniqueMapTy::iterator, bool> Entry = Map.insert(
258 std::make_pair(SectionGroupPair(Section, Group), (MCSectionELF *)0));
259 if (!Entry.second) return Entry.first->second;
Michael J. Spencerf13f4422010-11-26 04:16:08 +0000260
Jan Wen Voungefbdbe52010-09-30 05:59:22 +0000261 // Possibly refine the entry size first.
262 if (!EntrySize) {
263 EntrySize = MCSectionELF::DetermineEntrySize(Kind);
264 }
Rafael Espindolaa3e9a222010-11-11 18:13:52 +0000265
266 MCSymbol *GroupSym = NULL;
267 if (!Group.empty())
268 GroupSym = GetOrCreateSymbol(Group);
269
David Blaikie15b25df2013-10-22 23:41:52 +0000270 MCSectionELF *Result = new (*this) MCSectionELF(
271 Entry.first->first.first, Type, Flags, Kind, EntrySize, GroupSym);
272 Entry.first->second = Result;
Chris Lattner5418dd52010-04-08 21:26:26 +0000273 return Result;
274}
275
Rafael Espindolaa3e9a222010-11-11 18:13:52 +0000276const MCSectionELF *MCContext::CreateELFGroupSection() {
277 MCSectionELF *Result =
Rafael Espindolaaea49582011-01-23 04:28:49 +0000278 new (*this) MCSectionELF(".group", ELF::SHT_GROUP, 0,
Rafael Espindolaa3e9a222010-11-11 18:13:52 +0000279 SectionKind::getReadOnly(), 4, NULL);
280 return Result;
281}
282
Rafael Espindola60ec3832013-11-19 19:52:52 +0000283const MCSectionCOFF *
284MCContext::getCOFFSection(StringRef Section, unsigned Characteristics,
285 SectionKind Kind, StringRef COMDATSymName,
286 int Selection, const MCSectionCOFF *Assoc) {
Chris Lattner87cffa92010-05-07 17:17:41 +0000287 if (COFFUniquingMap == 0)
288 COFFUniquingMap = new COFFUniqueMapTy();
289 COFFUniqueMapTy &Map = *(COFFUniqueMapTy*)COFFUniquingMap;
Michael J. Spencerf13f4422010-11-26 04:16:08 +0000290
Chris Lattner87cffa92010-05-07 17:17:41 +0000291 // Do the lookup, if we have a hit, return it.
Michael J. Spencerf13f4422010-11-26 04:16:08 +0000292
Rafael Espindola60ec3832013-11-19 19:52:52 +0000293 SectionGroupPair P(Section, COMDATSymName);
294 std::pair<COFFUniqueMapTy::iterator, bool> Entry =
295 Map.insert(std::make_pair(P, (MCSectionCOFF *)0));
296 COFFUniqueMapTy::iterator Iter = Entry.first;
297 if (!Entry.second)
298 return Iter->second;
Michael J. Spencerf13f4422010-11-26 04:16:08 +0000299
Rafael Espindola60ec3832013-11-19 19:52:52 +0000300 const MCSymbol *COMDATSymbol = NULL;
301 if (!COMDATSymName.empty())
302 COMDATSymbol = GetOrCreateSymbol(COMDATSymName);
303
304 MCSectionCOFF *Result =
305 new (*this) MCSectionCOFF(Iter->first.first, Characteristics,
306 COMDATSymbol, Selection, Assoc, Kind);
307
308 Iter->second = Result;
Chris Lattner87cffa92010-05-07 17:17:41 +0000309 return Result;
310}
Kevin Enderbye5930f12010-07-28 20:55:35 +0000311
Rafael Espindola60ec3832013-11-19 19:52:52 +0000312const MCSectionCOFF *
313MCContext::getCOFFSection(StringRef Section, unsigned Characteristics,
314 SectionKind Kind) {
315 return getCOFFSection(Section, Characteristics, Kind, "", 0);
316}
317
Nico Riecka37acf72013-07-06 12:13:10 +0000318const MCSectionCOFF *MCContext::getCOFFSection(StringRef Section) {
319 if (COFFUniquingMap == 0)
320 COFFUniquingMap = new COFFUniqueMapTy();
321 COFFUniqueMapTy &Map = *(COFFUniqueMapTy*)COFFUniquingMap;
322
Rafael Espindola60ec3832013-11-19 19:52:52 +0000323 SectionGroupPair P(Section, "");
324 COFFUniqueMapTy::iterator Iter = Map.find(P);
325 if (Iter == Map.end())
326 return 0;
327 return Iter->second;
Nico Riecka37acf72013-07-06 12:13:10 +0000328}
329
Kevin Enderbye5930f12010-07-28 20:55:35 +0000330//===----------------------------------------------------------------------===//
331// Dwarf Management
332//===----------------------------------------------------------------------===//
333
334/// GetDwarfFile - takes a file name an number to place in the dwarf file and
335/// directory tables. If the file number has already been allocated it is an
336/// error and zero is returned and the client reports the error, else the
337/// allocated file number is returned. The file numbers may be in any order.
Nick Lewycky40f8f2f2011-10-17 23:05:28 +0000338unsigned MCContext::GetDwarfFile(StringRef Directory, StringRef FileName,
Manman Ren1e427202013-03-07 01:42:00 +0000339 unsigned FileNumber, unsigned CUID) {
David Blaikied9012ba2014-03-13 21:59:51 +0000340 MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID];
David Blaikie498589c2014-03-13 19:15:04 +0000341 return Table.getFile(Directory, FileName, FileNumber);
Kevin Enderbye5930f12010-07-28 20:55:35 +0000342}
Kevin Enderby1264b7c2010-08-24 20:32:42 +0000343
Kevin Enderbya68d0042010-10-04 20:17:24 +0000344/// isValidDwarfFileNumber - takes a dwarf file number and returns true if it
Kevin Enderby1264b7c2010-08-24 20:32:42 +0000345/// currently is assigned and false otherwise.
Manman Ren1e427202013-03-07 01:42:00 +0000346bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) {
David Blaikiea55ddad2014-03-13 18:55:04 +0000347 const SmallVectorImpl<MCDwarfFile>& MCDwarfFiles = getMCDwarfFiles(CUID);
Kevin Enderby1264b7c2010-08-24 20:32:42 +0000348 if(FileNumber == 0 || FileNumber >= MCDwarfFiles.size())
349 return false;
350
David Blaikiea55ddad2014-03-13 18:55:04 +0000351 return !MCDwarfFiles[FileNumber].Name.empty();
Kevin Enderby1264b7c2010-08-24 20:32:42 +0000352}
Jim Grosbachb18b4092012-01-26 23:20:11 +0000353
354void MCContext::FatalError(SMLoc Loc, const Twine &Msg) {
355 // If we have a source manager and a location, use it. Otherwise just
356 // use the generic report_fatal_error().
357 if (!SrcMgr || Loc == SMLoc())
358 report_fatal_error(Msg);
359
360 // Use the source manager to print the message.
361 SrcMgr->PrintMessage(Loc, SourceMgr::DK_Error, Msg);
362
363 // If we reached here, we are failing ungracefully. Run the interrupt handlers
364 // to make sure any special cleanups get done, in particular that we remove
365 // files registered with RemoveFileOnSignal.
366 sys::RunInterruptHandlers();
367 exit(1);
368}