TargetRegistry: Don't add "error" to error messages
authorMatt Arsenault <Matthew.Arsenault@amd.com>
Tue, 19 Apr 2022 00:18:05 +0000 (20:18 -0400)
committerMatt Arsenault <Matthew.Arsenault@amd.com>
Wed, 20 Apr 2022 02:29:16 +0000 (22:29 -0400)
Many of the users of this add their own "error:" to the start,
resulting in error: error.

llvm/lib/MC/TargetRegistry.cpp
llvm/test/tools/llc/invalid-target.ll [new file with mode: 0644]

index 09684b1..57444fd 100644 (file)
@@ -33,7 +33,7 @@ const Target *TargetRegistry::lookupTarget(const std::string &ArchName,
                      [&](const Target &T) { return ArchName == T.getName(); });
 
     if (I == targets().end()) {
-      Error = "error: invalid target '" + ArchName + "'.\n";
+      Error = "invalid target '" + ArchName + "'.\n";
       return nullptr;
     }
 
@@ -49,7 +49,7 @@ const Target *TargetRegistry::lookupTarget(const std::string &ArchName,
     std::string TempError;
     TheTarget = TargetRegistry::lookupTarget(TheTriple.getTriple(), TempError);
     if (!TheTarget) {
-      Error = ": error: unable to get target for '"
+      Error = "unable to get target for '"
             + TheTriple.getTriple()
             + "', see --version and --triple.\n";
       return nullptr;
diff --git a/llvm/test/tools/llc/invalid-target.ll b/llvm/test/tools/llc/invalid-target.ll
new file mode 100644 (file)
index 0000000..6eed627
--- /dev/null
@@ -0,0 +1,11 @@
+; RUN: not llc -march=arst -o /dev/null %s 2>&1 | FileCheck -check-prefix=MARCH %s
+; RUN: not llc -mtriple=arst-- -o /dev/null %s 2>&1 | FileCheck -check-prefix=MTRIPLE %s
+
+; Check the error message doesn't say error twice.
+
+; MARCH: {{.*}}llc{{.*}}: error: invalid target 'arst'.{{$}}
+; MTRIPLE: {{.*}}llc{{.*}}: error: unable to get target for 'arst-unknown-unknown', see --version and --triple.{{$}}
+
+define void @func() {
+  ret void
+}