Fix a crasher where when we're attempting to replace a type
[oota-llvm.git] / lib / IR / DiagnosticInfo.cpp
1 //===- llvm/Support/DiagnosticInfo.cpp - Diagnostic Definitions -*- C++ -*-===//
2 //
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 // This file defines the different classes involved in low level diagnostics.
11 //
12 // Diagnostics reporting is still done as part of the LLVMContext.
13 //===----------------------------------------------------------------------===//
14
15 #include "llvm/ADT/Twine.h"
16 #include "llvm/IR/Constants.h"
17 #include "llvm/IR/DiagnosticInfo.h"
18 #include "llvm/IR/DiagnosticPrinter.h"
19 #include "llvm/IR/Function.h"
20 #include "llvm/IR/Instruction.h"
21 #include "llvm/IR/Metadata.h"
22 #include "llvm/Support/Atomic.h"
23 #include <string>
24
25 using namespace llvm;
26
27 int llvm::getNextAvailablePluginDiagnosticKind() {
28   static sys::cas_flag PluginKindID = DK_FirstPluginKind;
29   return (int)sys::AtomicIncrement(&PluginKindID);
30 }
31
32 DiagnosticInfoInlineAsm::DiagnosticInfoInlineAsm(const Instruction &I,
33                                                  const Twine &MsgStr,
34                                                  DiagnosticSeverity Severity)
35     : DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(0), MsgStr(MsgStr),
36       Instr(&I) {
37   if (const MDNode *SrcLoc = I.getMetadata("srcloc")) {
38     if (SrcLoc->getNumOperands() != 0)
39       if (const ConstantInt *CI = dyn_cast<ConstantInt>(SrcLoc->getOperand(0)))
40         LocCookie = CI->getZExtValue();
41   }
42 }
43
44 void DiagnosticInfoInlineAsm::print(DiagnosticPrinter &DP) const {
45   DP << getMsgStr();
46   if (getLocCookie())
47     DP << " at line " << getLocCookie();
48 }
49
50 void DiagnosticInfoStackSize::print(DiagnosticPrinter &DP) const {
51   DP << "stack size limit exceeded (" << getStackSize() << ") in "
52      << getFunction();
53 }
54
55 void DiagnosticInfoDebugMetadataVersion::print(DiagnosticPrinter &DP) const {
56   DP << "ignoring debug info with an invalid version (" << getMetadataVersion()
57      << ") in " << getModule();
58 }