blob: 29727ac8a6a4a8bfa238e12fd8fa73364dc920d3 [file] [log] [blame]
Daniel Dunbarba1da8a2009-06-23 23:39:15 +00001//===- lib/MC/MCContext.cpp - Machine Code Context ------------------------===//
Daniel Dunbarecc63f82009-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 Lattner7c5b0212009-10-19 22:49:00 +000011#include "llvm/ADT/SmallString.h"
12#include "llvm/ADT/Twine.h"
Chandler Carruthd04a8d42012-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 Espindolac85dca62011-01-23 04:28:49 +000022#include "llvm/Support/ELF.h"
Jim Grosbach82f4ce52012-01-26 23:20:11 +000023#include "llvm/Support/ErrorHandling.h"
Jim Grosbach82f4ce52012-01-26 23:20:11 +000024#include "llvm/Support/Signals.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000025#include "llvm/Support/SourceMgr.h"
Daniel Dunbarecc63f82009-06-23 22:01:43 +000026using namespace llvm;
27
Chris Lattnerf0559e42010-04-08 20:30:37 +000028typedef StringMap<const MCSectionMachO*> MachOUniqueMapTy;
Chris Lattner74aae472010-04-08 21:26:26 +000029typedef StringMap<const MCSectionELF*> ELFUniqueMapTy;
Chris Lattnereb40a0f2010-05-07 17:17:41 +000030typedef StringMap<const MCSectionCOFF*> COFFUniqueMapTy;
Chris Lattnerf0559e42010-04-08 20:30:37 +000031
32
Evan Cheng0e6a0522011-07-18 20:57:22 +000033MCContext::MCContext(const MCAsmInfo &mai, const MCRegisterInfo &mri,
Pedro Artigas873a1dd2012-12-06 22:12:44 +000034 const MCObjectFileInfo *mofi, const SourceMgr *mgr,
Pedro Artigas5399d252012-12-12 22:59:46 +000035 bool DoAutoReset ) :
Jim Grosbach3662e5c2012-01-26 23:20:05 +000036 SrcMgr(mgr), MAI(mai), MRI(mri), MOFI(mofi),
Eli Friedmanf4387d92011-04-18 05:02:31 +000037 Allocator(), Symbols(Allocator), UsedNames(Allocator),
Chandler Carruth6c31d312012-12-17 21:32:42 +000038 NextUniqueID(0),
39 CompilationDir(llvm::sys::Path::GetCurrentDirectory().str()),
Pedro Artigas5399d252012-12-12 22:59:46 +000040 CurrentDwarfLoc(0,0,0,DWARF2_FLAG_IS_STMT,0,0),
41 DwarfLocSeen(false), GenDwarfForAssembly(false), GenDwarfFileNumber(0),
42 AllowTemporaryLabels(true), AutoReset(DoAutoReset) {
43
Chris Lattnerf0559e42010-04-08 20:30:37 +000044 MachOUniquingMap = 0;
Chris Lattner74aae472010-04-08 21:26:26 +000045 ELFUniquingMap = 0;
Chris Lattnereb40a0f2010-05-07 17:17:41 +000046 COFFUniquingMap = 0;
Kevin Enderbyf187ac52010-06-28 21:45:58 +000047
48 SecureLogFile = getenv("AS_SECURE_LOG_FILE");
49 SecureLog = 0;
50 SecureLogUsed = false;
Pedro Artigas873a1dd2012-12-06 22:12:44 +000051}
52
53MCContext::~MCContext() {
54
Pedro Artigas5399d252012-12-12 22:59:46 +000055 if (AutoReset)
56 reset();
Pedro Artigas873a1dd2012-12-06 22:12:44 +000057
58 // NOTE: The symbols are all allocated out of a bump pointer allocator,
59 // we don't need to free them here.
60
61 // If the stream for the .secure_log_unique directive was created free it.
62 delete (raw_ostream*)SecureLog;
63}
64
65//===----------------------------------------------------------------------===//
66// Module Lifetime Management
67//===----------------------------------------------------------------------===//
68
Pedro Artigas5399d252012-12-12 22:59:46 +000069void MCContext::reset() {
Pedro Artigas873a1dd2012-12-06 22:12:44 +000070 UsedNames.clear();
71 Symbols.clear();
72 Allocator.Reset();
73 Instances.clear();
74 MCDwarfFiles.clear();
75 MCDwarfDirs.clear();
76 MCGenDwarfLabelEntries.clear();
77 DwarfDebugFlags = StringRef();
78 MCLineSections.clear();
79 MCLineSectionOrder.clear();
80 CurrentDwarfLoc = MCDwarfLoc(0,0,0,DWARF2_FLAG_IS_STMT,0,0);
Michael J. Spencer326990f2010-11-26 04:16:08 +000081
Chris Lattnerf0559e42010-04-08 20:30:37 +000082 // If we have the MachO uniquing map, free it.
83 delete (MachOUniqueMapTy*)MachOUniquingMap;
Chris Lattner74aae472010-04-08 21:26:26 +000084 delete (ELFUniqueMapTy*)ELFUniquingMap;
Chris Lattnereb40a0f2010-05-07 17:17:41 +000085 delete (COFFUniqueMapTy*)COFFUniquingMap;
Pedro Artigas873a1dd2012-12-06 22:12:44 +000086 MachOUniquingMap = 0;
87 ELFUniquingMap = 0;
88 COFFUniquingMap = 0;
Pedro Artigas5399d252012-12-12 22:59:46 +000089
90 NextUniqueID = 0;
91 AllowTemporaryLabels = true;
92 DwarfLocSeen = false;
93 GenDwarfForAssembly = false;
94 GenDwarfFileNumber = 0;
Daniel Dunbarecc63f82009-06-23 22:01:43 +000095}
96
Chris Lattnerf0559e42010-04-08 20:30:37 +000097//===----------------------------------------------------------------------===//
98// Symbol Manipulation
99//===----------------------------------------------------------------------===//
100
Chris Lattner9b97a732010-03-30 18:10:53 +0000101MCSymbol *MCContext::GetOrCreateSymbol(StringRef Name) {
Chris Lattner00685bb2010-03-10 01:29:27 +0000102 assert(!Name.empty() && "Normal symbols cannot be unnamed!");
Michael J. Spencer326990f2010-11-26 04:16:08 +0000103
Chris Lattnerc28cc092010-03-15 06:15:35 +0000104 // Do the lookup and get the entire StringMapEntry. We want access to the
105 // key if we are creating the entry.
106 StringMapEntry<MCSymbol*> &Entry = Symbols.GetOrCreateValue(Name);
Rafael Espindola9f447242010-12-01 20:46:11 +0000107 MCSymbol *Sym = Entry.getValue();
108
109 if (Sym)
110 return Sym;
111
112 Sym = CreateSymbol(Name);
113 Entry.setValue(Sym);
114 return Sym;
115}
116
117MCSymbol *MCContext::CreateSymbol(StringRef Name) {
Daniel Dunbarc6cf43d2011-03-28 22:49:15 +0000118 // Determine whether this is an assembler temporary or normal label, if used.
119 bool isTemporary = false;
120 if (AllowTemporaryLabels)
121 isTemporary = Name.startswith(MAI.getPrivateGlobalPrefix());
Rafael Espindola9f447242010-12-01 20:46:11 +0000122
123 StringMapEntry<bool> *NameEntry = &UsedNames.GetOrCreateValue(Name);
124 if (NameEntry->getValue()) {
125 assert(isTemporary && "Cannot rename non temporary symbols");
Benjamin Kramerc18214a2011-04-09 11:26:27 +0000126 SmallString<128> NewName = Name;
Rafael Espindola9f447242010-12-01 20:46:11 +0000127 do {
Benjamin Kramerc18214a2011-04-09 11:26:27 +0000128 NewName.resize(Name.size());
129 raw_svector_ostream(NewName) << NextUniqueID++;
130 NameEntry = &UsedNames.GetOrCreateValue(NewName);
Rafael Espindola9f447242010-12-01 20:46:11 +0000131 } while (NameEntry->getValue());
132 }
133 NameEntry->setValue(true);
Chris Lattnerc69485e2009-06-24 04:31:49 +0000134
Chris Lattnerc28cc092010-03-15 06:15:35 +0000135 // Ok, the entry doesn't already exist. Have the MCSymbol object itself refer
Rafael Espindola9f447242010-12-01 20:46:11 +0000136 // to the copy of the string that is embedded in the UsedNames entry.
137 MCSymbol *Result = new (*this) MCSymbol(NameEntry->getKey(), isTemporary);
138
139 return Result;
Chris Lattnerc69485e2009-06-24 04:31:49 +0000140}
141
Chris Lattner9b97a732010-03-30 18:10:53 +0000142MCSymbol *MCContext::GetOrCreateSymbol(const Twine &Name) {
Chris Lattner7c5b0212009-10-19 22:49:00 +0000143 SmallString<128> NameSV;
144 Name.toVector(NameSV);
Chris Lattner9b97a732010-03-30 18:10:53 +0000145 return GetOrCreateSymbol(NameSV.str());
Chris Lattner7c5b0212009-10-19 22:49:00 +0000146}
147
Chris Lattner1d72a762010-03-14 08:23:30 +0000148MCSymbol *MCContext::CreateTempSymbol() {
Rafael Espindola9f447242010-12-01 20:46:11 +0000149 SmallString<128> NameSV;
Benjamin Kramerc18214a2011-04-09 11:26:27 +0000150 raw_svector_ostream(NameSV)
151 << MAI.getPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
Rafael Espindola9f447242010-12-01 20:46:11 +0000152 return CreateSymbol(NameSV);
Chris Lattner1d72a762010-03-14 08:23:30 +0000153}
154
Kevin Enderbyebe7fcd2010-05-17 23:08:19 +0000155unsigned MCContext::NextInstance(int64_t LocalLabelVal) {
Benjamin Kramer47f9a492010-05-18 12:15:34 +0000156 MCLabel *&Label = Instances[LocalLabelVal];
157 if (!Label)
158 Label = new (*this) MCLabel(0);
159 return Label->incInstance();
Kevin Enderbyebe7fcd2010-05-17 23:08:19 +0000160}
161
162unsigned MCContext::GetInstance(int64_t LocalLabelVal) {
Benjamin Kramer47f9a492010-05-18 12:15:34 +0000163 MCLabel *&Label = Instances[LocalLabelVal];
164 if (!Label)
165 Label = new (*this) MCLabel(0);
166 return Label->getInstance();
Kevin Enderbyebe7fcd2010-05-17 23:08:19 +0000167}
168
169MCSymbol *MCContext::CreateDirectionalLocalSymbol(int64_t LocalLabelVal) {
170 return GetOrCreateSymbol(Twine(MAI.getPrivateGlobalPrefix()) +
171 Twine(LocalLabelVal) +
172 "\2" +
Duncan Sands34727662010-07-12 08:16:59 +0000173 Twine(NextInstance(LocalLabelVal)));
Kevin Enderbyebe7fcd2010-05-17 23:08:19 +0000174}
175MCSymbol *MCContext::GetDirectionalLocalSymbol(int64_t LocalLabelVal,
176 int bORf) {
177 return GetOrCreateSymbol(Twine(MAI.getPrivateGlobalPrefix()) +
178 Twine(LocalLabelVal) +
179 "\2" +
Duncan Sands34727662010-07-12 08:16:59 +0000180 Twine(GetInstance(LocalLabelVal) + bORf));
Kevin Enderbyebe7fcd2010-05-17 23:08:19 +0000181}
182
Daniel Dunbar2928c832009-11-06 10:58:06 +0000183MCSymbol *MCContext::LookupSymbol(StringRef Name) const {
Daniel Dunbarecc63f82009-06-23 22:01:43 +0000184 return Symbols.lookup(Name);
185}
Chris Lattnerf0559e42010-04-08 20:30:37 +0000186
Roman Divackyf145c132012-09-18 17:10:37 +0000187MCSymbol *MCContext::LookupSymbol(const Twine &Name) const {
188 SmallString<128> NameSV;
189 Name.toVector(NameSV);
190 return LookupSymbol(NameSV.str());
191}
192
Chris Lattnerf0559e42010-04-08 20:30:37 +0000193//===----------------------------------------------------------------------===//
194// Section Management
195//===----------------------------------------------------------------------===//
196
197const MCSectionMachO *MCContext::
198getMachOSection(StringRef Segment, StringRef Section,
199 unsigned TypeAndAttributes,
200 unsigned Reserved2, SectionKind Kind) {
Michael J. Spencer326990f2010-11-26 04:16:08 +0000201
Chris Lattnerf0559e42010-04-08 20:30:37 +0000202 // We unique sections by their segment/section pair. The returned section
203 // may not have the same flags as the requested section, if so this should be
204 // diagnosed by the client as an error.
Michael J. Spencer326990f2010-11-26 04:16:08 +0000205
Chris Lattnerf0559e42010-04-08 20:30:37 +0000206 // Create the map if it doesn't already exist.
207 if (MachOUniquingMap == 0)
208 MachOUniquingMap = new MachOUniqueMapTy();
209 MachOUniqueMapTy &Map = *(MachOUniqueMapTy*)MachOUniquingMap;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000210
Chris Lattnerf0559e42010-04-08 20:30:37 +0000211 // Form the name to look up.
212 SmallString<64> Name;
213 Name += Segment;
214 Name.push_back(',');
215 Name += Section;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000216
Chris Lattnerf0559e42010-04-08 20:30:37 +0000217 // Do the lookup, if we have a hit, return it.
218 const MCSectionMachO *&Entry = Map[Name.str()];
219 if (Entry) return Entry;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000220
Chris Lattnerf0559e42010-04-08 20:30:37 +0000221 // Otherwise, return a new section.
Chris Lattner74aae472010-04-08 21:26:26 +0000222 return Entry = new (*this) MCSectionMachO(Segment, Section, TypeAndAttributes,
223 Reserved2, Kind);
Chris Lattnerf0559e42010-04-08 20:30:37 +0000224}
Chris Lattner74aae472010-04-08 21:26:26 +0000225
Rafael Espindola4283f4b2010-11-10 19:05:07 +0000226const MCSectionELF *MCContext::
Chris Lattner74aae472010-04-08 21:26:26 +0000227getELFSection(StringRef Section, unsigned Type, unsigned Flags,
Rafael Espindola2ff9e832010-11-11 18:13:52 +0000228 SectionKind Kind) {
229 return getELFSection(Section, Type, Flags, Kind, 0, "");
230}
231
232const MCSectionELF *MCContext::
233getELFSection(StringRef Section, unsigned Type, unsigned Flags,
234 SectionKind Kind, unsigned EntrySize, StringRef Group) {
Chris Lattner74aae472010-04-08 21:26:26 +0000235 if (ELFUniquingMap == 0)
236 ELFUniquingMap = new ELFUniqueMapTy();
237 ELFUniqueMapTy &Map = *(ELFUniqueMapTy*)ELFUniquingMap;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000238
Chris Lattner74aae472010-04-08 21:26:26 +0000239 // Do the lookup, if we have a hit, return it.
240 StringMapEntry<const MCSectionELF*> &Entry = Map.GetOrCreateValue(Section);
241 if (Entry.getValue()) return Entry.getValue();
Michael J. Spencer326990f2010-11-26 04:16:08 +0000242
Jan Wen Voung186e7a02010-09-30 05:59:22 +0000243 // Possibly refine the entry size first.
244 if (!EntrySize) {
245 EntrySize = MCSectionELF::DetermineEntrySize(Kind);
246 }
Rafael Espindola2ff9e832010-11-11 18:13:52 +0000247
248 MCSymbol *GroupSym = NULL;
249 if (!Group.empty())
250 GroupSym = GetOrCreateSymbol(Group);
251
Chris Lattner74aae472010-04-08 21:26:26 +0000252 MCSectionELF *Result = new (*this) MCSectionELF(Entry.getKey(), Type, Flags,
Rafael Espindola2ff9e832010-11-11 18:13:52 +0000253 Kind, EntrySize, GroupSym);
Chris Lattner74aae472010-04-08 21:26:26 +0000254 Entry.setValue(Result);
255 return Result;
256}
257
Rafael Espindola2ff9e832010-11-11 18:13:52 +0000258const MCSectionELF *MCContext::CreateELFGroupSection() {
259 MCSectionELF *Result =
Rafael Espindolac85dca62011-01-23 04:28:49 +0000260 new (*this) MCSectionELF(".group", ELF::SHT_GROUP, 0,
Rafael Espindola2ff9e832010-11-11 18:13:52 +0000261 SectionKind::getReadOnly(), 4, NULL);
262 return Result;
263}
264
Chris Lattner6e5ce282010-05-07 21:49:09 +0000265const MCSection *MCContext::getCOFFSection(StringRef Section,
266 unsigned Characteristics,
267 int Selection,
268 SectionKind Kind) {
Chris Lattnereb40a0f2010-05-07 17:17:41 +0000269 if (COFFUniquingMap == 0)
270 COFFUniquingMap = new COFFUniqueMapTy();
271 COFFUniqueMapTy &Map = *(COFFUniqueMapTy*)COFFUniquingMap;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000272
Chris Lattnereb40a0f2010-05-07 17:17:41 +0000273 // Do the lookup, if we have a hit, return it.
274 StringMapEntry<const MCSectionCOFF*> &Entry = Map.GetOrCreateValue(Section);
275 if (Entry.getValue()) return Entry.getValue();
Michael J. Spencer326990f2010-11-26 04:16:08 +0000276
Chris Lattner6e5ce282010-05-07 21:49:09 +0000277 MCSectionCOFF *Result = new (*this) MCSectionCOFF(Entry.getKey(),
278 Characteristics,
279 Selection, Kind);
Michael J. Spencer326990f2010-11-26 04:16:08 +0000280
Chris Lattnereb40a0f2010-05-07 17:17:41 +0000281 Entry.setValue(Result);
282 return Result;
283}
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000284
285//===----------------------------------------------------------------------===//
286// Dwarf Management
287//===----------------------------------------------------------------------===//
288
289/// GetDwarfFile - takes a file name an number to place in the dwarf file and
290/// directory tables. If the file number has already been allocated it is an
291/// error and zero is returned and the client reports the error, else the
292/// allocated file number is returned. The file numbers may be in any order.
Nick Lewycky44d798d2011-10-17 23:05:28 +0000293unsigned MCContext::GetDwarfFile(StringRef Directory, StringRef FileName,
294 unsigned FileNumber) {
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000295 // TODO: a FileNumber of zero says to use the next available file number.
296 // Note: in GenericAsmParser::ParseDirectiveFile() FileNumber was checked
297 // to not be less than one. This needs to be change to be not less than zero.
298
299 // Make space for this FileNumber in the MCDwarfFiles vector if needed.
300 if (FileNumber >= MCDwarfFiles.size()) {
301 MCDwarfFiles.resize(FileNumber + 1);
302 } else {
303 MCDwarfFile *&ExistingFile = MCDwarfFiles[FileNumber];
304 if (ExistingFile)
305 // It is an error to use see the same number more than once.
306 return 0;
307 }
308
309 // Get the new MCDwarfFile slot for this FileNumber.
310 MCDwarfFile *&File = MCDwarfFiles[FileNumber];
311
Nick Lewycky44d798d2011-10-17 23:05:28 +0000312 if (Directory.empty()) {
313 // Separate the directory part from the basename of the FileName.
NAKAMURA Takumi4c215c02012-07-03 03:59:29 +0000314 StringRef tFileName = sys::path::filename(FileName);
315 if (!tFileName.empty()) {
316 Directory = sys::path::parent_path(FileName);
317 if (!Directory.empty())
NAKAMURA Takumia6f14532012-07-03 06:01:27 +0000318 FileName = tFileName;
Kevin Enderby064e48a2011-11-01 23:39:05 +0000319 }
Nick Lewycky44d798d2011-10-17 23:05:28 +0000320 }
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000321
322 // Find or make a entry in the MCDwarfDirs vector for this Directory.
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000323 // Capture directory name.
Nick Lewycky44d798d2011-10-17 23:05:28 +0000324 unsigned DirIndex;
325 if (Directory.empty()) {
326 // For FileNames with no directories a DirIndex of 0 is used.
327 DirIndex = 0;
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000328 } else {
Nick Lewycky18ad76b2011-10-12 20:20:48 +0000329 DirIndex = 0;
330 for (unsigned End = MCDwarfDirs.size(); DirIndex < End; DirIndex++) {
Benjamin Kramer3bce5ad2010-07-29 13:53:19 +0000331 if (Directory == MCDwarfDirs[DirIndex])
Kevin Enderby232ab942010-08-31 22:55:11 +0000332 break;
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000333 }
334 if (DirIndex >= MCDwarfDirs.size()) {
Benjamin Kramer3bce5ad2010-07-29 13:53:19 +0000335 char *Buf = static_cast<char *>(Allocate(Directory.size()));
336 memcpy(Buf, Directory.data(), Directory.size());
337 MCDwarfDirs.push_back(StringRef(Buf, Directory.size()));
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000338 }
Kevin Enderbyb07ce602010-08-09 22:52:14 +0000339 // The DirIndex is one based, as DirIndex of 0 is used for FileNames with
340 // no directories. MCDwarfDirs[] is unlike MCDwarfFiles[] in that the
Nick Lewycky44d798d2011-10-17 23:05:28 +0000341 // directory names are stored at MCDwarfDirs[DirIndex-1] where FileNames
342 // are stored at MCDwarfFiles[FileNumber].Name .
Kevin Enderbyb07ce602010-08-09 22:52:14 +0000343 DirIndex++;
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000344 }
Michael J. Spencer326990f2010-11-26 04:16:08 +0000345
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000346 // Now make the MCDwarfFile entry and place it in the slot in the MCDwarfFiles
347 // vector.
Nick Lewycky44d798d2011-10-17 23:05:28 +0000348 char *Buf = static_cast<char *>(Allocate(FileName.size()));
349 memcpy(Buf, FileName.data(), FileName.size());
350 File = new (*this) MCDwarfFile(StringRef(Buf, FileName.size()), DirIndex);
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000351
352 // return the allocated FileNumber.
353 return FileNumber;
354}
Kevin Enderbyc1840b32010-08-24 20:32:42 +0000355
Kevin Enderby3f55c242010-10-04 20:17:24 +0000356/// isValidDwarfFileNumber - takes a dwarf file number and returns true if it
Kevin Enderbyc1840b32010-08-24 20:32:42 +0000357/// currently is assigned and false otherwise.
Kevin Enderby3f55c242010-10-04 20:17:24 +0000358bool MCContext::isValidDwarfFileNumber(unsigned FileNumber) {
Kevin Enderbyc1840b32010-08-24 20:32:42 +0000359 if(FileNumber == 0 || FileNumber >= MCDwarfFiles.size())
360 return false;
361
Kevin Enderby3f55c242010-10-04 20:17:24 +0000362 return MCDwarfFiles[FileNumber] != 0;
Kevin Enderbyc1840b32010-08-24 20:32:42 +0000363}
Jim Grosbach82f4ce52012-01-26 23:20:11 +0000364
365void MCContext::FatalError(SMLoc Loc, const Twine &Msg) {
366 // If we have a source manager and a location, use it. Otherwise just
367 // use the generic report_fatal_error().
368 if (!SrcMgr || Loc == SMLoc())
369 report_fatal_error(Msg);
370
371 // Use the source manager to print the message.
372 SrcMgr->PrintMessage(Loc, SourceMgr::DK_Error, Msg);
373
374 // If we reached here, we are failing ungracefully. Run the interrupt handlers
375 // to make sure any special cleanups get done, in particular that we remove
376 // files registered with RemoveFileOnSignal.
377 sys::RunInterruptHandlers();
378 exit(1);
379}