blob: 23ec0bb12d6a75e7c086881eecc4a93e2c415b22 [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,
35 bool DoAutoInitializationFinalization ) :
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),
38 NextUniqueID(0),
Daniel Dunbarc6cf43d2011-03-28 22:49:15 +000039 CurrentDwarfLoc(0,0,0,DWARF2_FLAG_IS_STMT,0,0),
Pedro Artigas873a1dd2012-12-06 22:12:44 +000040 AllowTemporaryLabels(true),
41 AutoInitializationFinalization(DoAutoInitializationFinalization) {
Chris Lattnerf0559e42010-04-08 20:30:37 +000042 MachOUniquingMap = 0;
Chris Lattner74aae472010-04-08 21:26:26 +000043 ELFUniquingMap = 0;
Chris Lattnereb40a0f2010-05-07 17:17:41 +000044 COFFUniquingMap = 0;
Kevin Enderbyf187ac52010-06-28 21:45:58 +000045
46 SecureLogFile = getenv("AS_SECURE_LOG_FILE");
47 SecureLog = 0;
48 SecureLogUsed = false;
Daniel Dunbarecc63f82009-06-23 22:01:43 +000049
Pedro Artigas873a1dd2012-12-06 22:12:44 +000050 if (AutoInitializationFinalization)
51 doInitialization();
52}
53
54MCContext::~MCContext() {
55
56 if (AutoInitializationFinalization)
57 doFinalization();
58
59 // NOTE: The symbols are all allocated out of a bump pointer allocator,
60 // we don't need to free them here.
61
62 // If the stream for the .secure_log_unique directive was created free it.
63 delete (raw_ostream*)SecureLog;
64}
65
66//===----------------------------------------------------------------------===//
67// Module Lifetime Management
68//===----------------------------------------------------------------------===//
69
70void MCContext::doInitialization() {
71 NextUniqueID = 0;
72 AllowTemporaryLabels = true;
Pedro Artigas486a7ad2012-12-06 00:50:55 +000073 DwarfLocSeen = false;
74 GenDwarfForAssembly = false;
75 GenDwarfFileNumber = 0;
76}
77
Pedro Artigas873a1dd2012-12-06 22:12:44 +000078void MCContext::doFinalization() {
79 UsedNames.clear();
80 Symbols.clear();
81 Allocator.Reset();
82 Instances.clear();
83 MCDwarfFiles.clear();
84 MCDwarfDirs.clear();
85 MCGenDwarfLabelEntries.clear();
86 DwarfDebugFlags = StringRef();
87 MCLineSections.clear();
88 MCLineSectionOrder.clear();
89 CurrentDwarfLoc = MCDwarfLoc(0,0,0,DWARF2_FLAG_IS_STMT,0,0);
Michael J. Spencer326990f2010-11-26 04:16:08 +000090
Chris Lattnerf0559e42010-04-08 20:30:37 +000091 // If we have the MachO uniquing map, free it.
92 delete (MachOUniqueMapTy*)MachOUniquingMap;
Chris Lattner74aae472010-04-08 21:26:26 +000093 delete (ELFUniqueMapTy*)ELFUniquingMap;
Chris Lattnereb40a0f2010-05-07 17:17:41 +000094 delete (COFFUniqueMapTy*)COFFUniquingMap;
Pedro Artigas873a1dd2012-12-06 22:12:44 +000095 MachOUniquingMap = 0;
96 ELFUniquingMap = 0;
97 COFFUniquingMap = 0;
Daniel Dunbarecc63f82009-06-23 22:01:43 +000098}
99
Chris Lattnerf0559e42010-04-08 20:30:37 +0000100//===----------------------------------------------------------------------===//
101// Symbol Manipulation
102//===----------------------------------------------------------------------===//
103
Chris Lattner9b97a732010-03-30 18:10:53 +0000104MCSymbol *MCContext::GetOrCreateSymbol(StringRef Name) {
Chris Lattner00685bb2010-03-10 01:29:27 +0000105 assert(!Name.empty() && "Normal symbols cannot be unnamed!");
Michael J. Spencer326990f2010-11-26 04:16:08 +0000106
Chris Lattnerc28cc092010-03-15 06:15:35 +0000107 // Do the lookup and get the entire StringMapEntry. We want access to the
108 // key if we are creating the entry.
109 StringMapEntry<MCSymbol*> &Entry = Symbols.GetOrCreateValue(Name);
Rafael Espindola9f447242010-12-01 20:46:11 +0000110 MCSymbol *Sym = Entry.getValue();
111
112 if (Sym)
113 return Sym;
114
115 Sym = CreateSymbol(Name);
116 Entry.setValue(Sym);
117 return Sym;
118}
119
120MCSymbol *MCContext::CreateSymbol(StringRef Name) {
Daniel Dunbarc6cf43d2011-03-28 22:49:15 +0000121 // Determine whether this is an assembler temporary or normal label, if used.
122 bool isTemporary = false;
123 if (AllowTemporaryLabels)
124 isTemporary = Name.startswith(MAI.getPrivateGlobalPrefix());
Rafael Espindola9f447242010-12-01 20:46:11 +0000125
126 StringMapEntry<bool> *NameEntry = &UsedNames.GetOrCreateValue(Name);
127 if (NameEntry->getValue()) {
128 assert(isTemporary && "Cannot rename non temporary symbols");
Benjamin Kramerc18214a2011-04-09 11:26:27 +0000129 SmallString<128> NewName = Name;
Rafael Espindola9f447242010-12-01 20:46:11 +0000130 do {
Benjamin Kramerc18214a2011-04-09 11:26:27 +0000131 NewName.resize(Name.size());
132 raw_svector_ostream(NewName) << NextUniqueID++;
133 NameEntry = &UsedNames.GetOrCreateValue(NewName);
Rafael Espindola9f447242010-12-01 20:46:11 +0000134 } while (NameEntry->getValue());
135 }
136 NameEntry->setValue(true);
Chris Lattnerc69485e2009-06-24 04:31:49 +0000137
Chris Lattnerc28cc092010-03-15 06:15:35 +0000138 // Ok, the entry doesn't already exist. Have the MCSymbol object itself refer
Rafael Espindola9f447242010-12-01 20:46:11 +0000139 // to the copy of the string that is embedded in the UsedNames entry.
140 MCSymbol *Result = new (*this) MCSymbol(NameEntry->getKey(), isTemporary);
141
142 return Result;
Chris Lattnerc69485e2009-06-24 04:31:49 +0000143}
144
Chris Lattner9b97a732010-03-30 18:10:53 +0000145MCSymbol *MCContext::GetOrCreateSymbol(const Twine &Name) {
Chris Lattner7c5b0212009-10-19 22:49:00 +0000146 SmallString<128> NameSV;
147 Name.toVector(NameSV);
Chris Lattner9b97a732010-03-30 18:10:53 +0000148 return GetOrCreateSymbol(NameSV.str());
Chris Lattner7c5b0212009-10-19 22:49:00 +0000149}
150
Chris Lattner1d72a762010-03-14 08:23:30 +0000151MCSymbol *MCContext::CreateTempSymbol() {
Rafael Espindola9f447242010-12-01 20:46:11 +0000152 SmallString<128> NameSV;
Benjamin Kramerc18214a2011-04-09 11:26:27 +0000153 raw_svector_ostream(NameSV)
154 << MAI.getPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
Rafael Espindola9f447242010-12-01 20:46:11 +0000155 return CreateSymbol(NameSV);
Chris Lattner1d72a762010-03-14 08:23:30 +0000156}
157
Kevin Enderbyebe7fcd2010-05-17 23:08:19 +0000158unsigned MCContext::NextInstance(int64_t LocalLabelVal) {
Benjamin Kramer47f9a492010-05-18 12:15:34 +0000159 MCLabel *&Label = Instances[LocalLabelVal];
160 if (!Label)
161 Label = new (*this) MCLabel(0);
162 return Label->incInstance();
Kevin Enderbyebe7fcd2010-05-17 23:08:19 +0000163}
164
165unsigned MCContext::GetInstance(int64_t LocalLabelVal) {
Benjamin Kramer47f9a492010-05-18 12:15:34 +0000166 MCLabel *&Label = Instances[LocalLabelVal];
167 if (!Label)
168 Label = new (*this) MCLabel(0);
169 return Label->getInstance();
Kevin Enderbyebe7fcd2010-05-17 23:08:19 +0000170}
171
172MCSymbol *MCContext::CreateDirectionalLocalSymbol(int64_t LocalLabelVal) {
173 return GetOrCreateSymbol(Twine(MAI.getPrivateGlobalPrefix()) +
174 Twine(LocalLabelVal) +
175 "\2" +
Duncan Sands34727662010-07-12 08:16:59 +0000176 Twine(NextInstance(LocalLabelVal)));
Kevin Enderbyebe7fcd2010-05-17 23:08:19 +0000177}
178MCSymbol *MCContext::GetDirectionalLocalSymbol(int64_t LocalLabelVal,
179 int bORf) {
180 return GetOrCreateSymbol(Twine(MAI.getPrivateGlobalPrefix()) +
181 Twine(LocalLabelVal) +
182 "\2" +
Duncan Sands34727662010-07-12 08:16:59 +0000183 Twine(GetInstance(LocalLabelVal) + bORf));
Kevin Enderbyebe7fcd2010-05-17 23:08:19 +0000184}
185
Daniel Dunbar2928c832009-11-06 10:58:06 +0000186MCSymbol *MCContext::LookupSymbol(StringRef Name) const {
Daniel Dunbarecc63f82009-06-23 22:01:43 +0000187 return Symbols.lookup(Name);
188}
Chris Lattnerf0559e42010-04-08 20:30:37 +0000189
Roman Divackyf145c132012-09-18 17:10:37 +0000190MCSymbol *MCContext::LookupSymbol(const Twine &Name) const {
191 SmallString<128> NameSV;
192 Name.toVector(NameSV);
193 return LookupSymbol(NameSV.str());
194}
195
Chris Lattnerf0559e42010-04-08 20:30:37 +0000196//===----------------------------------------------------------------------===//
197// Section Management
198//===----------------------------------------------------------------------===//
199
200const MCSectionMachO *MCContext::
201getMachOSection(StringRef Segment, StringRef Section,
202 unsigned TypeAndAttributes,
203 unsigned Reserved2, SectionKind Kind) {
Michael J. Spencer326990f2010-11-26 04:16:08 +0000204
Chris Lattnerf0559e42010-04-08 20:30:37 +0000205 // We unique sections by their segment/section pair. The returned section
206 // may not have the same flags as the requested section, if so this should be
207 // diagnosed by the client as an error.
Michael J. Spencer326990f2010-11-26 04:16:08 +0000208
Chris Lattnerf0559e42010-04-08 20:30:37 +0000209 // Create the map if it doesn't already exist.
210 if (MachOUniquingMap == 0)
211 MachOUniquingMap = new MachOUniqueMapTy();
212 MachOUniqueMapTy &Map = *(MachOUniqueMapTy*)MachOUniquingMap;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000213
Chris Lattnerf0559e42010-04-08 20:30:37 +0000214 // Form the name to look up.
215 SmallString<64> Name;
216 Name += Segment;
217 Name.push_back(',');
218 Name += Section;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000219
Chris Lattnerf0559e42010-04-08 20:30:37 +0000220 // Do the lookup, if we have a hit, return it.
221 const MCSectionMachO *&Entry = Map[Name.str()];
222 if (Entry) return Entry;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000223
Chris Lattnerf0559e42010-04-08 20:30:37 +0000224 // Otherwise, return a new section.
Chris Lattner74aae472010-04-08 21:26:26 +0000225 return Entry = new (*this) MCSectionMachO(Segment, Section, TypeAndAttributes,
226 Reserved2, Kind);
Chris Lattnerf0559e42010-04-08 20:30:37 +0000227}
Chris Lattner74aae472010-04-08 21:26:26 +0000228
Rafael Espindola4283f4b2010-11-10 19:05:07 +0000229const MCSectionELF *MCContext::
Chris Lattner74aae472010-04-08 21:26:26 +0000230getELFSection(StringRef Section, unsigned Type, unsigned Flags,
Rafael Espindola2ff9e832010-11-11 18:13:52 +0000231 SectionKind Kind) {
232 return getELFSection(Section, Type, Flags, Kind, 0, "");
233}
234
235const MCSectionELF *MCContext::
236getELFSection(StringRef Section, unsigned Type, unsigned Flags,
237 SectionKind Kind, unsigned EntrySize, StringRef Group) {
Chris Lattner74aae472010-04-08 21:26:26 +0000238 if (ELFUniquingMap == 0)
239 ELFUniquingMap = new ELFUniqueMapTy();
240 ELFUniqueMapTy &Map = *(ELFUniqueMapTy*)ELFUniquingMap;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000241
Chris Lattner74aae472010-04-08 21:26:26 +0000242 // Do the lookup, if we have a hit, return it.
243 StringMapEntry<const MCSectionELF*> &Entry = Map.GetOrCreateValue(Section);
244 if (Entry.getValue()) return Entry.getValue();
Michael J. Spencer326990f2010-11-26 04:16:08 +0000245
Jan Wen Voung186e7a02010-09-30 05:59:22 +0000246 // Possibly refine the entry size first.
247 if (!EntrySize) {
248 EntrySize = MCSectionELF::DetermineEntrySize(Kind);
249 }
Rafael Espindola2ff9e832010-11-11 18:13:52 +0000250
251 MCSymbol *GroupSym = NULL;
252 if (!Group.empty())
253 GroupSym = GetOrCreateSymbol(Group);
254
Chris Lattner74aae472010-04-08 21:26:26 +0000255 MCSectionELF *Result = new (*this) MCSectionELF(Entry.getKey(), Type, Flags,
Rafael Espindola2ff9e832010-11-11 18:13:52 +0000256 Kind, EntrySize, GroupSym);
Chris Lattner74aae472010-04-08 21:26:26 +0000257 Entry.setValue(Result);
258 return Result;
259}
260
Rafael Espindola2ff9e832010-11-11 18:13:52 +0000261const MCSectionELF *MCContext::CreateELFGroupSection() {
262 MCSectionELF *Result =
Rafael Espindolac85dca62011-01-23 04:28:49 +0000263 new (*this) MCSectionELF(".group", ELF::SHT_GROUP, 0,
Rafael Espindola2ff9e832010-11-11 18:13:52 +0000264 SectionKind::getReadOnly(), 4, NULL);
265 return Result;
266}
267
Chris Lattner6e5ce282010-05-07 21:49:09 +0000268const MCSection *MCContext::getCOFFSection(StringRef Section,
269 unsigned Characteristics,
270 int Selection,
271 SectionKind Kind) {
Chris Lattnereb40a0f2010-05-07 17:17:41 +0000272 if (COFFUniquingMap == 0)
273 COFFUniquingMap = new COFFUniqueMapTy();
274 COFFUniqueMapTy &Map = *(COFFUniqueMapTy*)COFFUniquingMap;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000275
Chris Lattnereb40a0f2010-05-07 17:17:41 +0000276 // Do the lookup, if we have a hit, return it.
277 StringMapEntry<const MCSectionCOFF*> &Entry = Map.GetOrCreateValue(Section);
278 if (Entry.getValue()) return Entry.getValue();
Michael J. Spencer326990f2010-11-26 04:16:08 +0000279
Chris Lattner6e5ce282010-05-07 21:49:09 +0000280 MCSectionCOFF *Result = new (*this) MCSectionCOFF(Entry.getKey(),
281 Characteristics,
282 Selection, Kind);
Michael J. Spencer326990f2010-11-26 04:16:08 +0000283
Chris Lattnereb40a0f2010-05-07 17:17:41 +0000284 Entry.setValue(Result);
285 return Result;
286}
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000287
288//===----------------------------------------------------------------------===//
289// Dwarf Management
290//===----------------------------------------------------------------------===//
291
292/// GetDwarfFile - takes a file name an number to place in the dwarf file and
293/// directory tables. If the file number has already been allocated it is an
294/// error and zero is returned and the client reports the error, else the
295/// allocated file number is returned. The file numbers may be in any order.
Nick Lewycky44d798d2011-10-17 23:05:28 +0000296unsigned MCContext::GetDwarfFile(StringRef Directory, StringRef FileName,
297 unsigned FileNumber) {
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000298 // TODO: a FileNumber of zero says to use the next available file number.
299 // Note: in GenericAsmParser::ParseDirectiveFile() FileNumber was checked
300 // to not be less than one. This needs to be change to be not less than zero.
301
302 // Make space for this FileNumber in the MCDwarfFiles vector if needed.
303 if (FileNumber >= MCDwarfFiles.size()) {
304 MCDwarfFiles.resize(FileNumber + 1);
305 } else {
306 MCDwarfFile *&ExistingFile = MCDwarfFiles[FileNumber];
307 if (ExistingFile)
308 // It is an error to use see the same number more than once.
309 return 0;
310 }
311
312 // Get the new MCDwarfFile slot for this FileNumber.
313 MCDwarfFile *&File = MCDwarfFiles[FileNumber];
314
Nick Lewycky44d798d2011-10-17 23:05:28 +0000315 if (Directory.empty()) {
316 // Separate the directory part from the basename of the FileName.
NAKAMURA Takumi4c215c02012-07-03 03:59:29 +0000317 StringRef tFileName = sys::path::filename(FileName);
318 if (!tFileName.empty()) {
319 Directory = sys::path::parent_path(FileName);
320 if (!Directory.empty())
NAKAMURA Takumia6f14532012-07-03 06:01:27 +0000321 FileName = tFileName;
Kevin Enderby064e48a2011-11-01 23:39:05 +0000322 }
Nick Lewycky44d798d2011-10-17 23:05:28 +0000323 }
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000324
325 // Find or make a entry in the MCDwarfDirs vector for this Directory.
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000326 // Capture directory name.
Nick Lewycky44d798d2011-10-17 23:05:28 +0000327 unsigned DirIndex;
328 if (Directory.empty()) {
329 // For FileNames with no directories a DirIndex of 0 is used.
330 DirIndex = 0;
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000331 } else {
Nick Lewycky18ad76b2011-10-12 20:20:48 +0000332 DirIndex = 0;
333 for (unsigned End = MCDwarfDirs.size(); DirIndex < End; DirIndex++) {
Benjamin Kramer3bce5ad2010-07-29 13:53:19 +0000334 if (Directory == MCDwarfDirs[DirIndex])
Kevin Enderby232ab942010-08-31 22:55:11 +0000335 break;
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000336 }
337 if (DirIndex >= MCDwarfDirs.size()) {
Benjamin Kramer3bce5ad2010-07-29 13:53:19 +0000338 char *Buf = static_cast<char *>(Allocate(Directory.size()));
339 memcpy(Buf, Directory.data(), Directory.size());
340 MCDwarfDirs.push_back(StringRef(Buf, Directory.size()));
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000341 }
Kevin Enderbyb07ce602010-08-09 22:52:14 +0000342 // The DirIndex is one based, as DirIndex of 0 is used for FileNames with
343 // no directories. MCDwarfDirs[] is unlike MCDwarfFiles[] in that the
Nick Lewycky44d798d2011-10-17 23:05:28 +0000344 // directory names are stored at MCDwarfDirs[DirIndex-1] where FileNames
345 // are stored at MCDwarfFiles[FileNumber].Name .
Kevin Enderbyb07ce602010-08-09 22:52:14 +0000346 DirIndex++;
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000347 }
Michael J. Spencer326990f2010-11-26 04:16:08 +0000348
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000349 // Now make the MCDwarfFile entry and place it in the slot in the MCDwarfFiles
350 // vector.
Nick Lewycky44d798d2011-10-17 23:05:28 +0000351 char *Buf = static_cast<char *>(Allocate(FileName.size()));
352 memcpy(Buf, FileName.data(), FileName.size());
353 File = new (*this) MCDwarfFile(StringRef(Buf, FileName.size()), DirIndex);
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000354
355 // return the allocated FileNumber.
356 return FileNumber;
357}
Kevin Enderbyc1840b32010-08-24 20:32:42 +0000358
Kevin Enderby3f55c242010-10-04 20:17:24 +0000359/// isValidDwarfFileNumber - takes a dwarf file number and returns true if it
Kevin Enderbyc1840b32010-08-24 20:32:42 +0000360/// currently is assigned and false otherwise.
Kevin Enderby3f55c242010-10-04 20:17:24 +0000361bool MCContext::isValidDwarfFileNumber(unsigned FileNumber) {
Kevin Enderbyc1840b32010-08-24 20:32:42 +0000362 if(FileNumber == 0 || FileNumber >= MCDwarfFiles.size())
363 return false;
364
Kevin Enderby3f55c242010-10-04 20:17:24 +0000365 return MCDwarfFiles[FileNumber] != 0;
Kevin Enderbyc1840b32010-08-24 20:32:42 +0000366}
Jim Grosbach82f4ce52012-01-26 23:20:11 +0000367
368void MCContext::FatalError(SMLoc Loc, const Twine &Msg) {
369 // If we have a source manager and a location, use it. Otherwise just
370 // use the generic report_fatal_error().
371 if (!SrcMgr || Loc == SMLoc())
372 report_fatal_error(Msg);
373
374 // Use the source manager to print the message.
375 SrcMgr->PrintMessage(Loc, SourceMgr::DK_Error, Msg);
376
377 // If we reached here, we are failing ungracefully. Run the interrupt handlers
378 // to make sure any special cleanups get done, in particular that we remove
379 // files registered with RemoveFileOnSignal.
380 sys::RunInterruptHandlers();
381 exit(1);
382}