1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

[llc] Add reportError helper and canonicalize error messages

This commit is contained in:
Fangrui Song 2021-01-26 15:33:37 -08:00
parent 795af9c7de
commit 9459868630
3 changed files with 36 additions and 33 deletions

View File

@ -1,14 +1,15 @@
; RUN: not llvm-as -data-layout=A5 < %s 2>&1 | FileCheck -check-prefixes=COMMON,AS %s
; RUN: not llc -mtriple amdgcn-amd-amdhsa < %s 2>&1 | FileCheck -check-prefixes=COMMON,LLC %s
; RUN: llvm-as < %s | not llc -mtriple amdgcn-amd-amdhsa 2>&1 | FileCheck -check-prefixes=MISMATCH %s
; RUN: not opt -data-layout=A5 -S < %s 2>&1 | FileCheck -check-prefixes=COMMON,LLC %s
; RUN: not opt -data-layout=A5 -S < %s 2>&1 | FileCheck -check-prefixes=COMMON,OPT %s
; RUN: llvm-as < %s | not opt -data-layout=A5 2>&1 | FileCheck -check-prefixes=MISMATCH %s
; AS: assembly parsed, but does not verify as correct!
; COMMON: Allocation instruction pointer not in the stack address space!
; COMMON: %tmp = alloca i32
; MISMATCH: Explicit load/store type does not match pointee type of pointer operand
; LLC: error: input module is broken!
; LLC: error: {{.*}}input module cannot be verified
; OPT: error: input module is broken!
define amdgpu_kernel void @test() {
%tmp = alloca i32

View File

@ -6,4 +6,4 @@
; RUN: not llc -mtriple=powerpc64-ibm-aix --relocation-model=ropi-rwpi < %s 2>&1 | FileCheck --check-prefix=CHECK-NON-PIC %s
; CHECK-NOT: {{.}}
; CHECK-NON-PIC: invalid relocation model, AIX only supports PIC.
; CHECK-NON-PIC: error: '<stdin>': invalid relocation model, AIX only supports PIC

View File

@ -200,6 +200,25 @@ static cl::opt<RunPassOption, true, cl::parser<std::string>> RunPass(
static int compileModule(char **, LLVMContext &);
LLVM_ATTRIBUTE_NORETURN static void reportError(Twine Msg,
StringRef Filename = "") {
SmallString<256> Prefix;
if (!Filename.empty()) {
if (Filename == "-")
Filename = "<stdin>";
("'" + Twine(Filename) + "': ").toStringRef(Prefix);
}
WithColor::error(errs(), "llc") << Prefix << Msg << "\n";
exit(1);
}
LLVM_ATTRIBUTE_NORETURN static void reportError(Error Err, StringRef Filename) {
assert(Err);
handleAllErrors(createFileError(Filename, std::move(Err)),
[&](const ErrorInfoBase &EI) { reportError(EI.message()); });
llvm_unreachable("reportError() should not return");
}
static std::unique_ptr<ToolOutputFile> GetOutputStream(const char *TargetName,
Triple::OSType OS,
const char *ProgName) {
@ -260,7 +279,7 @@ static std::unique_ptr<ToolOutputFile> GetOutputStream(const char *TargetName,
OpenFlags |= sys::fs::OF_Text;
auto FDOut = std::make_unique<ToolOutputFile>(OutputFilename, EC, OpenFlags);
if (EC) {
WithColor::error() << EC.message() << '\n';
reportError(EC.message());
return nullptr;
}
@ -353,18 +372,12 @@ int main(int argc, char **argv) {
setupLLVMOptimizationRemarks(Context, RemarksFilename, RemarksPasses,
RemarksFormat, RemarksWithHotness,
RemarksHotnessThreshold);
if (Error E = RemarksFileOrErr.takeError()) {
WithColor::error(errs(), argv[0]) << toString(std::move(E)) << '\n';
return 1;
}
if (Error E = RemarksFileOrErr.takeError())
reportError(std::move(E), RemarksFilename);
std::unique_ptr<ToolOutputFile> RemarksFile = std::move(*RemarksFileOrErr);
if (InputLanguage != "" && InputLanguage != "ir" &&
InputLanguage != "mir") {
WithColor::error(errs(), argv[0])
<< "input language must be '', 'IR' or 'MIR'\n";
return 1;
}
if (InputLanguage != "" && InputLanguage != "ir" && InputLanguage != "mir")
reportError("input language must be '', 'IR' or 'MIR'");
// Compile the module TimeCompilations times to give better compile time
// metrics.
@ -490,11 +503,9 @@ static int compileModule(char **argv, LLVMContext &Context) {
// On AIX, setting the relocation model to anything other than PIC is
// considered a user error.
if (TheTriple.isOSAIX() && RM.hasValue() && *RM != Reloc::PIC_) {
WithColor::error(errs(), argv[0])
<< "invalid relocation model, AIX only supports PIC.\n";
exit(1);
}
if (TheTriple.isOSAIX() && RM.hasValue() && *RM != Reloc::PIC_)
reportError("invalid relocation model, AIX only supports PIC",
InputFilename);
InitializeOptions(TheTriple);
Target = std::unique_ptr<TargetMachine>(TheTarget->createTargetMachine(
@ -567,10 +578,8 @@ static int compileModule(char **argv, LLVMContext &Context) {
std::error_code EC;
DwoOut = std::make_unique<ToolOutputFile>(SplitDwarfOutputFile, EC,
sys::fs::OF_None);
if (EC) {
WithColor::error(errs(), argv[0]) << EC.message() << '\n';
return 1;
}
if (EC)
reportError(EC.message(), SplitDwarfOutputFile);
}
// Build up all of the passes that we want to do to the module.
@ -586,12 +595,8 @@ static int compileModule(char **argv, LLVMContext &Context) {
// Verify module immediately to catch problems before doInitialization() is
// called on any passes.
if (!NoVerify && verifyModule(*M, &errs())) {
std::string Prefix =
(Twine(argv[0]) + Twine(": ") + Twine(InputFilename)).str();
WithColor::error(errs(), Prefix) << "input module is broken!\n";
return 1;
}
if (!NoVerify && verifyModule(*M, &errs()))
reportError("input module cannot be verified", InputFilename);
// Override function attributes based on CPUStr, FeaturesStr, and command line
// flags.
@ -650,10 +655,7 @@ static int compileModule(char **argv, LLVMContext &Context) {
} else if (Target->addPassesToEmitFile(
PM, *OS, DwoOut ? &DwoOut->os() : nullptr,
codegen::getFileType(), NoVerify, MMIWP)) {
WithColor::warning(errs(), argv[0])
<< "target does not support generation of this"
<< " file type!\n";
return 1;
reportError("target does not support generation of this file type");
}
const_cast<TargetLoweringObjectFile *>(LLVMTM.getObjFileLowering())