|
@@ -210,50 +210,71 @@ std::unique_ptr<llvm::Module> LoadModuleFromBitcode(llvm::StringRef BC,
|
|
return LoadModuleFromBitcode(pBitcodeBuf.get(), Ctx, DiagStr);
|
|
return LoadModuleFromBitcode(pBitcodeBuf.get(), Ctx, DiagStr);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+std::string FormatMessageAtLocation(const DebugLoc &DL, const Twine& Msg) {
|
|
|
|
+ std::string locString;
|
|
|
|
+ raw_string_ostream os(locString);
|
|
|
|
+ DL.print(os);
|
|
|
|
+ os << ": " << Msg;
|
|
|
|
+ return os.str();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+Twine FormatMessageWithoutLocation(const Twine& Msg) {
|
|
|
|
+ return Msg + " Use /Zi for source location.";
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void EmitWarningOrErrorOnInstruction(Instruction *I, StringRef Msg,
|
|
|
|
+ bool bWarning);
|
|
|
|
+
|
|
// If we don't have debug location and this is select/phi,
|
|
// If we don't have debug location and this is select/phi,
|
|
// try recursing users to find instruction with debug info.
|
|
// try recursing users to find instruction with debug info.
|
|
// Only recurse phi/select and limit depth to prevent doing
|
|
// Only recurse phi/select and limit depth to prevent doing
|
|
// too much work if no debug location found.
|
|
// too much work if no debug location found.
|
|
-static bool EmitErrorOnInstructionFollowPhiSelect(
|
|
|
|
- Instruction *I, StringRef Msg, unsigned depth=0) {
|
|
|
|
|
|
+static bool EmitWarningOrErrorOnInstructionFollowPhiSelect(Instruction *I,
|
|
|
|
+ StringRef Msg,
|
|
|
|
+ bool bWarning,
|
|
|
|
+ unsigned depth = 0) {
|
|
if (depth > 4)
|
|
if (depth > 4)
|
|
return false;
|
|
return false;
|
|
if (I->getDebugLoc().get()) {
|
|
if (I->getDebugLoc().get()) {
|
|
- EmitErrorOnInstruction(I, Msg);
|
|
|
|
|
|
+ EmitWarningOrErrorOnInstruction(I, Msg, bWarning);
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
if (isa<PHINode>(I) || isa<SelectInst>(I)) {
|
|
if (isa<PHINode>(I) || isa<SelectInst>(I)) {
|
|
for (auto U : I->users())
|
|
for (auto U : I->users())
|
|
if (Instruction *UI = dyn_cast<Instruction>(U))
|
|
if (Instruction *UI = dyn_cast<Instruction>(U))
|
|
- if (EmitErrorOnInstructionFollowPhiSelect(UI, Msg, depth+1))
|
|
|
|
|
|
+ if (EmitWarningOrErrorOnInstructionFollowPhiSelect(UI, Msg, bWarning,
|
|
|
|
+ depth + 1))
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
-std::string FormatMessageAtLocation(const DebugLoc &DL, const Twine& Msg) {
|
|
|
|
- std::string locString;
|
|
|
|
- raw_string_ostream os(locString);
|
|
|
|
- DL.print(os);
|
|
|
|
- os << ": " << Msg;
|
|
|
|
- return os.str();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-Twine FormatMessageWithoutLocation(const Twine& Msg) {
|
|
|
|
- return Msg + " Use /Zi for source location.";
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void EmitErrorOnInstruction(Instruction *I, StringRef Msg) {
|
|
|
|
|
|
+static void EmitWarningOrErrorOnInstruction(Instruction *I, StringRef Msg,
|
|
|
|
+ bool bWarning) {
|
|
const DebugLoc &DL = I->getDebugLoc();
|
|
const DebugLoc &DL = I->getDebugLoc();
|
|
if (DL.get()) {
|
|
if (DL.get()) {
|
|
- I->getContext().emitError(FormatMessageAtLocation(DL, Msg));
|
|
|
|
|
|
+ if (bWarning)
|
|
|
|
+ I->getContext().emitWarning(FormatMessageAtLocation(DL, Msg));
|
|
|
|
+ else
|
|
|
|
+ I->getContext().emitError(FormatMessageAtLocation(DL, Msg));
|
|
return;
|
|
return;
|
|
} else if (isa<PHINode>(I) || isa<SelectInst>(I)) {
|
|
} else if (isa<PHINode>(I) || isa<SelectInst>(I)) {
|
|
- if (EmitErrorOnInstructionFollowPhiSelect(I, Msg))
|
|
|
|
|
|
+ if (EmitWarningOrErrorOnInstructionFollowPhiSelect(I, Msg, bWarning))
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- I->getContext().emitError(FormatMessageWithoutLocation(Msg));
|
|
|
|
|
|
+ if (bWarning)
|
|
|
|
+ I->getContext().emitWarning(FormatMessageWithoutLocation(Msg));
|
|
|
|
+ else
|
|
|
|
+ I->getContext().emitError(FormatMessageWithoutLocation(Msg));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void EmitErrorOnInstruction(Instruction *I, StringRef Msg) {
|
|
|
|
+ EmitWarningOrErrorOnInstruction(I, Msg, /*bWarning*/false);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void EmitWarningOnInstruction(Instruction *I, StringRef Msg) {
|
|
|
|
+ EmitWarningOrErrorOnInstruction(I, Msg, /*bWarning*/true);
|
|
}
|
|
}
|
|
|
|
|
|
const StringRef kResourceMapErrorMsg =
|
|
const StringRef kResourceMapErrorMsg =
|