[llvm] 752c912 - TargetRegistry: Don't add "error" to error messages

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 19 19:41:08 PDT 2022


Author: Matt Arsenault
Date: 2022-04-19T22:29:16-04:00
New Revision: 752c9122a6c01af57c481d7b12ff0bb7a8132759

URL: https://github.com/llvm/llvm-project/commit/752c9122a6c01af57c481d7b12ff0bb7a8132759
DIFF: https://github.com/llvm/llvm-project/commit/752c9122a6c01af57c481d7b12ff0bb7a8132759.diff

LOG: TargetRegistry: Don't add "error" to error messages

Many of the users of this add their own "error:" to the start,
resulting in error: error.

Added: 
    llvm/test/tools/llc/invalid-target.ll

Modified: 
    llvm/lib/MC/TargetRegistry.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/TargetRegistry.cpp b/llvm/lib/MC/TargetRegistry.cpp
index 09684b1e5ad2b..57444fd23784e 100644
--- a/llvm/lib/MC/TargetRegistry.cpp
+++ b/llvm/lib/MC/TargetRegistry.cpp
@@ -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
index 0000000000000..6eed627b0115d
--- /dev/null
+++ b/llvm/test/tools/llc/invalid-target.ll
@@ -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
+}


        


More information about the llvm-commits mailing list