1 //===--- CodeGenAction.cpp - LLVM Code Generation Frontend Action ---------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "clang/CodeGen/CodeGenAction.h"
11 #include "clang/AST/ASTConsumer.h"
12 #include "clang/AST/ASTContext.h"
13 #include "clang/AST/DeclGroup.h"
14 #include "clang/AST/DeclCXX.h"
15 #include "clang/Basic/FileManager.h"
16 #include "clang/Basic/SourceManager.h"
17 #include "clang/Basic/TargetInfo.h"
18 #include "clang/CodeGen/BackendUtil.h"
19 #include "clang/CodeGen/ModuleBuilder.h"
20 #include "clang/Frontend/CompilerInstance.h"
21 #include "clang/Frontend/FrontendDiagnostic.h"
22 #include "llvm/ADT/SmallString.h"
23 #include "llvm/Bitcode/ReaderWriter.h"
24 #include "llvm/IR/DebugInfo.h"
25 #include "llvm/IR/DiagnosticInfo.h"
26 #include "llvm/IR/DiagnosticPrinter.h"
27 #include "llvm/IR/LLVMContext.h"
28 #include "llvm/IR/Module.h"
29 #include "llvm/IRReader/IRReader.h"
30 #include "llvm/Linker/Linker.h"
31 #include "llvm/Pass.h"
32 #include "llvm/Support/MemoryBuffer.h"
33 #include "llvm/Support/SourceMgr.h"
34 #include "llvm/Support/Timer.h"
36 using namespace clang;
40 class BackendConsumer : public ASTConsumer {
41 virtual void anchor();
42 DiagnosticsEngine &Diags;
44 const CodeGenOptions &CodeGenOpts;
45 const TargetOptions &TargetOpts;
46 const LangOptions &LangOpts;
47 raw_ostream *AsmOutStream;
50 Timer LLVMIRGeneration;
52 std::unique_ptr<CodeGenerator> Gen;
54 std::unique_ptr<llvm::Module> TheModule, LinkModule;
57 BackendConsumer(BackendAction action, DiagnosticsEngine &_Diags,
58 const CodeGenOptions &compopts,
59 const TargetOptions &targetopts,
60 const LangOptions &langopts, bool TimePasses,
61 const std::string &infile, llvm::Module *LinkModule,
62 raw_ostream *OS, LLVMContext &C)
63 : Diags(_Diags), Action(action), CodeGenOpts(compopts),
64 TargetOpts(targetopts), LangOpts(langopts), AsmOutStream(OS),
65 Context(), LLVMIRGeneration("LLVM IR Generation Time"),
66 Gen(CreateLLVMCodeGen(Diags, infile, compopts, targetopts, C)),
67 LinkModule(LinkModule) {
68 llvm::TimePassesIsEnabled = TimePasses;
71 llvm::Module *takeModule() { return TheModule.release(); }
72 llvm::Module *takeLinkModule() { return LinkModule.release(); }
74 void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override {
75 Gen->HandleCXXStaticMemberVarInstantiation(VD);
78 void Initialize(ASTContext &Ctx) override {
81 if (llvm::TimePassesIsEnabled)
82 LLVMIRGeneration.startTimer();
86 TheModule.reset(Gen->GetModule());
88 if (llvm::TimePassesIsEnabled)
89 LLVMIRGeneration.stopTimer();
92 bool HandleTopLevelDecl(DeclGroupRef D) override {
93 PrettyStackTraceDecl CrashInfo(*D.begin(), SourceLocation(),
94 Context->getSourceManager(),
95 "LLVM IR generation of declaration");
97 if (llvm::TimePassesIsEnabled)
98 LLVMIRGeneration.startTimer();
100 Gen->HandleTopLevelDecl(D);
102 if (llvm::TimePassesIsEnabled)
103 LLVMIRGeneration.stopTimer();
108 void HandleInlineMethodDefinition(CXXMethodDecl *D) override {
109 PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
110 Context->getSourceManager(),
111 "LLVM IR generation of inline method");
112 if (llvm::TimePassesIsEnabled)
113 LLVMIRGeneration.startTimer();
115 Gen->HandleInlineMethodDefinition(D);
117 if (llvm::TimePassesIsEnabled)
118 LLVMIRGeneration.stopTimer();
121 void HandleTranslationUnit(ASTContext &C) override {
123 PrettyStackTraceString CrashInfo("Per-file LLVM IR generation");
124 if (llvm::TimePassesIsEnabled)
125 LLVMIRGeneration.startTimer();
127 Gen->HandleTranslationUnit(C);
129 if (llvm::TimePassesIsEnabled)
130 LLVMIRGeneration.stopTimer();
133 // Silently ignore if we weren't initialized for some reason.
137 // Make sure IR generation is happy with the module. This is released by
138 // the module provider.
139 llvm::Module *M = Gen->ReleaseModule();
141 // The module has been released by IR gen on failures, do not double
147 assert(TheModule.get() == M &&
148 "Unexpected module change during IR generation");
150 // Link LinkModule into this module if present, preserving its validity.
152 std::string ErrorMsg;
153 if (Linker::LinkModules(M, LinkModule.get(), Linker::PreserveSource,
155 Diags.Report(diag::err_fe_cannot_link_module)
156 << LinkModule->getModuleIdentifier() << ErrorMsg;
161 // Install an inline asm handler so that diagnostics get printed through
162 // our diagnostics hooks.
163 LLVMContext &Ctx = TheModule->getContext();
164 LLVMContext::InlineAsmDiagHandlerTy OldHandler =
165 Ctx.getInlineAsmDiagnosticHandler();
166 void *OldContext = Ctx.getInlineAsmDiagnosticContext();
167 Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, this);
169 LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
170 Ctx.getDiagnosticHandler();
171 void *OldDiagnosticContext = Ctx.getDiagnosticContext();
172 Ctx.setDiagnosticHandler(DiagnosticHandler, this);
174 EmitBackendOutput(Diags, CodeGenOpts, TargetOpts, LangOpts,
175 C.getTargetInfo().getTargetDescription(),
176 TheModule.get(), Action, AsmOutStream);
178 Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext);
180 Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext);
183 void HandleTagDeclDefinition(TagDecl *D) override {
184 PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
185 Context->getSourceManager(),
186 "LLVM IR generation of declaration");
187 Gen->HandleTagDeclDefinition(D);
190 void HandleTagDeclRequiredDefinition(const TagDecl *D) override {
191 Gen->HandleTagDeclRequiredDefinition(D);
194 void CompleteTentativeDefinition(VarDecl *D) override {
195 Gen->CompleteTentativeDefinition(D);
198 void HandleVTable(CXXRecordDecl *RD, bool DefinitionRequired) override {
199 Gen->HandleVTable(RD, DefinitionRequired);
202 void HandleLinkerOptionPragma(llvm::StringRef Opts) override {
203 Gen->HandleLinkerOptionPragma(Opts);
206 void HandleDetectMismatch(llvm::StringRef Name,
207 llvm::StringRef Value) override {
208 Gen->HandleDetectMismatch(Name, Value);
211 void HandleDependentLibrary(llvm::StringRef Opts) override {
212 Gen->HandleDependentLibrary(Opts);
215 static void InlineAsmDiagHandler(const llvm::SMDiagnostic &SM,void *Context,
216 unsigned LocCookie) {
217 SourceLocation Loc = SourceLocation::getFromRawEncoding(LocCookie);
218 ((BackendConsumer*)Context)->InlineAsmDiagHandler2(SM, Loc);
221 static void DiagnosticHandler(const llvm::DiagnosticInfo &DI,
223 ((BackendConsumer *)Context)->DiagnosticHandlerImpl(DI);
226 void InlineAsmDiagHandler2(const llvm::SMDiagnostic &,
227 SourceLocation LocCookie);
229 void DiagnosticHandlerImpl(const llvm::DiagnosticInfo &DI);
230 /// \brief Specialized handler for InlineAsm diagnostic.
231 /// \return True if the diagnostic has been successfully reported, false
233 bool InlineAsmDiagHandler(const llvm::DiagnosticInfoInlineAsm &D);
234 /// \brief Specialized handler for StackSize diagnostic.
235 /// \return True if the diagnostic has been successfully reported, false
237 bool StackSizeDiagHandler(const llvm::DiagnosticInfoStackSize &D);
238 /// \brief Specialized handlers for optimization remarks.
239 /// Note that these handlers only accept remarks and they always handle
242 EmitOptimizationRemark(const llvm::DiagnosticInfoOptimizationBase &D,
245 OptimizationRemarkHandler(const llvm::DiagnosticInfoOptimizationRemark &D);
246 void OptimizationRemarkHandler(
247 const llvm::DiagnosticInfoOptimizationRemarkMissed &D);
248 void OptimizationRemarkHandler(
249 const llvm::DiagnosticInfoOptimizationRemarkAnalysis &D);
252 void BackendConsumer::anchor() {}
255 /// ConvertBackendLocation - Convert a location in a temporary llvm::SourceMgr
256 /// buffer to be a valid FullSourceLoc.
257 static FullSourceLoc ConvertBackendLocation(const llvm::SMDiagnostic &D,
258 SourceManager &CSM) {
259 // Get both the clang and llvm source managers. The location is relative to
260 // a memory buffer that the LLVM Source Manager is handling, we need to add
261 // a copy to the Clang source manager.
262 const llvm::SourceMgr &LSM = *D.getSourceMgr();
264 // We need to copy the underlying LLVM memory buffer because llvm::SourceMgr
265 // already owns its one and clang::SourceManager wants to own its one.
266 const MemoryBuffer *LBuf =
267 LSM.getMemoryBuffer(LSM.FindBufferContainingLoc(D.getLoc()));
269 // Create the copy and transfer ownership to clang::SourceManager.
270 // TODO: Avoid copying files into memory.
271 llvm::MemoryBuffer *CBuf =
272 llvm::MemoryBuffer::getMemBufferCopy(LBuf->getBuffer(),
273 LBuf->getBufferIdentifier());
274 // FIXME: Keep a file ID map instead of creating new IDs for each location.
275 FileID FID = CSM.createFileID(CBuf);
277 // Translate the offset into the file.
278 unsigned Offset = D.getLoc().getPointer() - LBuf->getBufferStart();
279 SourceLocation NewLoc =
280 CSM.getLocForStartOfFile(FID).getLocWithOffset(Offset);
281 return FullSourceLoc(NewLoc, CSM);
285 /// InlineAsmDiagHandler2 - This function is invoked when the backend hits an
286 /// error parsing inline asm. The SMDiagnostic indicates the error relative to
287 /// the temporary memory buffer that the inline asm parser has set up.
288 void BackendConsumer::InlineAsmDiagHandler2(const llvm::SMDiagnostic &D,
289 SourceLocation LocCookie) {
290 // There are a couple of different kinds of errors we could get here. First,
291 // we re-format the SMDiagnostic in terms of a clang diagnostic.
293 // Strip "error: " off the start of the message string.
294 StringRef Message = D.getMessage();
295 if (Message.startswith("error: "))
296 Message = Message.substr(7);
298 // If the SMDiagnostic has an inline asm source location, translate it.
300 if (D.getLoc() != SMLoc())
301 Loc = ConvertBackendLocation(D, Context->getSourceManager());
304 switch (D.getKind()) {
305 case llvm::SourceMgr::DK_Error:
306 DiagID = diag::err_fe_inline_asm;
308 case llvm::SourceMgr::DK_Warning:
309 DiagID = diag::warn_fe_inline_asm;
311 case llvm::SourceMgr::DK_Note:
312 DiagID = diag::note_fe_inline_asm;
315 // If this problem has clang-level source location information, report the
316 // issue in the source with a note showing the instantiated
318 if (LocCookie.isValid()) {
319 Diags.Report(LocCookie, DiagID).AddString(Message);
321 if (D.getLoc().isValid()) {
322 DiagnosticBuilder B = Diags.Report(Loc, diag::note_fe_inline_asm_here);
323 // Convert the SMDiagnostic ranges into SourceRange and attach them
324 // to the diagnostic.
325 for (unsigned i = 0, e = D.getRanges().size(); i != e; ++i) {
326 std::pair<unsigned, unsigned> Range = D.getRanges()[i];
327 unsigned Column = D.getColumnNo();
328 B << SourceRange(Loc.getLocWithOffset(Range.first - Column),
329 Loc.getLocWithOffset(Range.second - Column));
335 // Otherwise, report the backend issue as occurring in the generated .s file.
336 // If Loc is invalid, we still need to report the issue, it just gets no
338 Diags.Report(Loc, DiagID).AddString(Message);
341 #define ComputeDiagID(Severity, GroupName, DiagID) \
343 switch (Severity) { \
344 case llvm::DS_Error: \
345 DiagID = diag::err_fe_##GroupName; \
347 case llvm::DS_Warning: \
348 DiagID = diag::warn_fe_##GroupName; \
350 case llvm::DS_Remark: \
351 llvm_unreachable("'remark' severity not expected"); \
353 case llvm::DS_Note: \
354 DiagID = diag::note_fe_##GroupName; \
359 #define ComputeDiagRemarkID(Severity, GroupName, DiagID) \
361 switch (Severity) { \
362 case llvm::DS_Error: \
363 DiagID = diag::err_fe_##GroupName; \
365 case llvm::DS_Warning: \
366 DiagID = diag::warn_fe_##GroupName; \
368 case llvm::DS_Remark: \
369 DiagID = diag::remark_fe_##GroupName; \
371 case llvm::DS_Note: \
372 DiagID = diag::note_fe_##GroupName; \
378 BackendConsumer::InlineAsmDiagHandler(const llvm::DiagnosticInfoInlineAsm &D) {
380 ComputeDiagID(D.getSeverity(), inline_asm, DiagID);
381 std::string Message = D.getMsgStr().str();
383 // If this problem has clang-level source location information, report the
384 // issue as being a problem in the source with a note showing the instantiated
386 SourceLocation LocCookie =
387 SourceLocation::getFromRawEncoding(D.getLocCookie());
388 if (LocCookie.isValid())
389 Diags.Report(LocCookie, DiagID).AddString(Message);
391 // Otherwise, report the backend diagnostic as occurring in the generated
393 // If Loc is invalid, we still need to report the diagnostic, it just gets
396 Diags.Report(Loc, DiagID).AddString(Message);
398 // We handled all the possible severities.
403 BackendConsumer::StackSizeDiagHandler(const llvm::DiagnosticInfoStackSize &D) {
404 if (D.getSeverity() != llvm::DS_Warning)
405 // For now, the only support we have for StackSize diagnostic is warning.
406 // We do not know how to format other severities.
409 if (const Decl *ND = Gen->GetDeclForMangledName(D.getFunction().getName())) {
410 Diags.Report(ND->getASTContext().getFullLoc(ND->getLocation()),
411 diag::warn_fe_frame_larger_than)
412 << D.getStackSize() << Decl::castToDeclContext(ND);
419 void BackendConsumer::EmitOptimizationRemark(
420 const llvm::DiagnosticInfoOptimizationBase &D, unsigned DiagID) {
421 // We only support remarks.
422 assert(D.getSeverity() == llvm::DS_Remark);
424 SourceManager &SourceMgr = Context->getSourceManager();
425 FileManager &FileMgr = SourceMgr.getFileManager();
427 unsigned Line, Column;
428 D.getLocation(&Filename, &Line, &Column);
429 SourceLocation DILoc;
430 const FileEntry *FE = FileMgr.getFile(Filename);
431 if (FE && Line > 0) {
432 // If -gcolumn-info was not used, Column will be 0. This upsets the
433 // source manager, so pass 1 if Column is not set.
434 DILoc = SourceMgr.translateFileLineCol(FE, Line, Column ? Column : 1);
437 // If a location isn't available, try to approximate it using the associated
438 // function definition. We use the definition's right brace to differentiate
439 // from diagnostics that genuinely relate to the function itself.
440 FullSourceLoc Loc(DILoc, SourceMgr);
442 if (const Decl *FD = Gen->GetDeclForMangledName(D.getFunction().getName()))
443 Loc = FD->getASTContext().getFullLoc(FD->getBodyRBrace());
445 Diags.Report(Loc, DiagID) << AddFlagValue(D.getPassName())
448 if (DILoc.isInvalid())
449 // If we were not able to translate the file:line:col information
450 // back to a SourceLocation, at least emit a note stating that
451 // we could not translate this location. This can happen in the
452 // case of #line directives.
453 Diags.Report(Loc, diag::note_fe_backend_optimization_remark_invalid_loc)
454 << Filename << Line << Column;
457 void BackendConsumer::OptimizationRemarkHandler(
458 const llvm::DiagnosticInfoOptimizationRemark &D) {
459 // Optimization remarks are active only if the -Rpass flag has a regular
460 // expression that matches the name of the pass name in \p D.
461 if (CodeGenOpts.OptimizationRemarkPattern &&
462 CodeGenOpts.OptimizationRemarkPattern->match(D.getPassName()))
463 EmitOptimizationRemark(D, diag::remark_fe_backend_optimization_remark);
466 void BackendConsumer::OptimizationRemarkHandler(
467 const llvm::DiagnosticInfoOptimizationRemarkMissed &D) {
468 // Missed optimization remarks are active only if the -Rpass-missed
469 // flag has a regular expression that matches the name of the pass
471 if (CodeGenOpts.OptimizationRemarkMissedPattern &&
472 CodeGenOpts.OptimizationRemarkMissedPattern->match(D.getPassName()))
473 EmitOptimizationRemark(D,
474 diag::remark_fe_backend_optimization_remark_missed);
477 void BackendConsumer::OptimizationRemarkHandler(
478 const llvm::DiagnosticInfoOptimizationRemarkAnalysis &D) {
479 // Optimization analysis remarks are active only if the -Rpass-analysis
480 // flag has a regular expression that matches the name of the pass
482 if (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
483 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName()))
484 EmitOptimizationRemark(
485 D, diag::remark_fe_backend_optimization_remark_analysis);
488 /// \brief This function is invoked when the backend needs
489 /// to report something to the user.
490 void BackendConsumer::DiagnosticHandlerImpl(const DiagnosticInfo &DI) {
491 unsigned DiagID = diag::err_fe_inline_asm;
492 llvm::DiagnosticSeverity Severity = DI.getSeverity();
493 // Get the diagnostic ID based.
494 switch (DI.getKind()) {
495 case llvm::DK_InlineAsm:
496 if (InlineAsmDiagHandler(cast<DiagnosticInfoInlineAsm>(DI)))
498 ComputeDiagID(Severity, inline_asm, DiagID);
500 case llvm::DK_StackSize:
501 if (StackSizeDiagHandler(cast<DiagnosticInfoStackSize>(DI)))
503 ComputeDiagID(Severity, backend_frame_larger_than, DiagID);
505 case llvm::DK_OptimizationRemark:
506 // Optimization remarks are always handled completely by this
507 // handler. There is no generic way of emitting them.
508 OptimizationRemarkHandler(cast<DiagnosticInfoOptimizationRemark>(DI));
510 case llvm::DK_OptimizationRemarkMissed:
511 // Optimization remarks are always handled completely by this
512 // handler. There is no generic way of emitting them.
513 OptimizationRemarkHandler(cast<DiagnosticInfoOptimizationRemarkMissed>(DI));
515 case llvm::DK_OptimizationRemarkAnalysis:
516 // Optimization remarks are always handled completely by this
517 // handler. There is no generic way of emitting them.
518 OptimizationRemarkHandler(
519 cast<DiagnosticInfoOptimizationRemarkAnalysis>(DI));
522 // Plugin IDs are not bound to any value as they are set dynamically.
523 ComputeDiagRemarkID(Severity, backend_plugin, DiagID);
526 std::string MsgStorage;
528 raw_string_ostream Stream(MsgStorage);
529 DiagnosticPrinterRawOStream DP(Stream);
533 // Report the backend message using the usual diagnostic mechanism.
535 Diags.Report(Loc, DiagID).AddString(MsgStorage);
539 CodeGenAction::CodeGenAction(unsigned _Act, LLVMContext *_VMContext)
540 : Act(_Act), LinkModule(nullptr),
541 VMContext(_VMContext ? _VMContext : new LLVMContext),
542 OwnsVMContext(!_VMContext) {}
544 CodeGenAction::~CodeGenAction() {
550 bool CodeGenAction::hasIRSupport() const { return true; }
552 void CodeGenAction::EndSourceFileAction() {
553 // If the consumer creation failed, do nothing.
554 if (!getCompilerInstance().hasASTConsumer())
557 // If we were given a link module, release consumer's ownership of it.
559 BEConsumer->takeLinkModule();
561 // Steal the module from the consumer.
562 TheModule.reset(BEConsumer->takeModule());
565 llvm::Module *CodeGenAction::takeModule() { return TheModule.release(); }
567 llvm::LLVMContext *CodeGenAction::takeLLVMContext() {
568 OwnsVMContext = false;
572 static raw_ostream *GetOutputStream(CompilerInstance &CI,
574 BackendAction Action) {
576 case Backend_EmitAssembly:
577 return CI.createDefaultOutputFile(false, InFile, "s");
579 return CI.createDefaultOutputFile(false, InFile, "ll");
581 return CI.createDefaultOutputFile(true, InFile, "bc");
582 case Backend_EmitNothing:
584 case Backend_EmitMCNull:
585 return CI.createNullOutputFile();
586 case Backend_EmitObj:
587 return CI.createDefaultOutputFile(true, InFile, "o");
590 llvm_unreachable("Invalid action!");
593 ASTConsumer *CodeGenAction::CreateASTConsumer(CompilerInstance &CI,
595 BackendAction BA = static_cast<BackendAction>(Act);
596 std::unique_ptr<raw_ostream> OS(GetOutputStream(CI, InFile, BA));
597 if (BA != Backend_EmitNothing && !OS)
600 llvm::Module *LinkModuleToUse = LinkModule;
602 // If we were not given a link module, and the user requested that one be
603 // loaded from bitcode, do so now.
604 const std::string &LinkBCFile = CI.getCodeGenOpts().LinkBitcodeFile;
605 if (!LinkModuleToUse && !LinkBCFile.empty()) {
606 std::string ErrorStr;
608 llvm::MemoryBuffer *BCBuf =
609 CI.getFileManager().getBufferForFile(LinkBCFile, &ErrorStr);
611 CI.getDiagnostics().Report(diag::err_cannot_open_file)
612 << LinkBCFile << ErrorStr;
616 ErrorOr<llvm::Module *> ModuleOrErr =
617 getLazyBitcodeModule(BCBuf, *VMContext);
618 if (std::error_code EC = ModuleOrErr.getError()) {
619 CI.getDiagnostics().Report(diag::err_cannot_open_file)
620 << LinkBCFile << EC.message();
623 LinkModuleToUse = ModuleOrErr.get();
626 BEConsumer = new BackendConsumer(BA, CI.getDiagnostics(), CI.getCodeGenOpts(),
627 CI.getTargetOpts(), CI.getLangOpts(),
628 CI.getFrontendOpts().ShowTimers, InFile,
629 LinkModuleToUse, OS.release(), *VMContext);
633 void CodeGenAction::ExecuteAction() {
634 // If this is an IR file, we have to treat it specially.
635 if (getCurrentFileKind() == IK_LLVM_IR) {
636 BackendAction BA = static_cast<BackendAction>(Act);
637 CompilerInstance &CI = getCompilerInstance();
638 raw_ostream *OS = GetOutputStream(CI, getCurrentFile(), BA);
639 if (BA != Backend_EmitNothing && !OS)
643 SourceManager &SM = CI.getSourceManager();
644 FileID FID = SM.getMainFileID();
645 llvm::MemoryBuffer *MainFile = SM.getBuffer(FID, &Invalid);
649 llvm::SMDiagnostic Err;
650 TheModule.reset(ParseIR(MainFile, Err, *VMContext));
652 // Translate from the diagnostic info to the SourceManager location if
654 // TODO: Unify this with ConvertBackendLocation()
656 if (Err.getLineNo() > 0) {
657 assert(Err.getColumnNo() >= 0);
658 Loc = SM.translateFileLineCol(SM.getFileEntryForID(FID),
659 Err.getLineNo(), Err.getColumnNo() + 1);
662 // Strip off a leading diagnostic code if there is one.
663 StringRef Msg = Err.getMessage();
664 if (Msg.startswith("error: "))
668 CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0");
670 CI.getDiagnostics().Report(Loc, DiagID) << Msg;
673 const TargetOptions &TargetOpts = CI.getTargetOpts();
674 if (TheModule->getTargetTriple() != TargetOpts.Triple) {
675 unsigned DiagID = CI.getDiagnostics().getCustomDiagID(
676 DiagnosticsEngine::Warning,
677 "overriding the module target triple with %0");
679 CI.getDiagnostics().Report(SourceLocation(), DiagID) << TargetOpts.Triple;
680 TheModule->setTargetTriple(TargetOpts.Triple);
683 EmitBackendOutput(CI.getDiagnostics(), CI.getCodeGenOpts(), TargetOpts,
684 CI.getLangOpts(), CI.getTarget().getTargetDescription(),
685 TheModule.get(), BA, OS);
689 // Otherwise follow the normal AST path.
690 this->ASTFrontendAction::ExecuteAction();
695 void EmitAssemblyAction::anchor() { }
696 EmitAssemblyAction::EmitAssemblyAction(llvm::LLVMContext *_VMContext)
697 : CodeGenAction(Backend_EmitAssembly, _VMContext) {}
699 void EmitBCAction::anchor() { }
700 EmitBCAction::EmitBCAction(llvm::LLVMContext *_VMContext)
701 : CodeGenAction(Backend_EmitBC, _VMContext) {}
703 void EmitLLVMAction::anchor() { }
704 EmitLLVMAction::EmitLLVMAction(llvm::LLVMContext *_VMContext)
705 : CodeGenAction(Backend_EmitLL, _VMContext) {}
707 void EmitLLVMOnlyAction::anchor() { }
708 EmitLLVMOnlyAction::EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext)
709 : CodeGenAction(Backend_EmitNothing, _VMContext) {}
711 void EmitCodeGenOnlyAction::anchor() { }
712 EmitCodeGenOnlyAction::EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext)
713 : CodeGenAction(Backend_EmitMCNull, _VMContext) {}
715 void EmitObjAction::anchor() { }
716 EmitObjAction::EmitObjAction(llvm::LLVMContext *_VMContext)
717 : CodeGenAction(Backend_EmitObj, _VMContext) {}