[clang] ecad121 - [clang][Driver] Fix crash with unsupported architectures in MinGW and CrossWindows

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Mon May 1 18:34:14 PDT 2023


Author: KOMATA Manabu
Date: 2023-05-01T18:34:09-07:00
New Revision: ecad1210092764592ca9ee0670dd15831e54b770

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

LOG: [clang][Driver] Fix crash with unsupported architectures in MinGW and CrossWindows

MinGW and CrossWindows crash if the target is an unsupported target architecture.
Changed it to emit an error message.

Fixes https://github.com/llvm/llvm-project/issues/59545

Reviewed By: MaskRay, mstorsjo

Differential Revision: https://reviews.llvm.org/D148944

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/CrossWindows.cpp
    clang/lib/Driver/ToolChains/MinGW.cpp
    clang/test/Driver/unsupported-target-arch.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/CrossWindows.cpp b/clang/lib/Driver/ToolChains/CrossWindows.cpp
index bc91449326a5..3c5dfba329cf 100644
--- a/clang/lib/Driver/ToolChains/CrossWindows.cpp
+++ b/clang/lib/Driver/ToolChains/CrossWindows.cpp
@@ -94,7 +94,8 @@ void tools::CrossWindows::Linker::ConstructJob(
   CmdArgs.push_back("-m");
   switch (TC.getArch()) {
   default:
-    llvm_unreachable("unsupported architecture");
+    D.Diag(diag::err_target_unknown_triple) << TC.getEffectiveTriple().str();
+    break;
   case llvm::Triple::arm:
   case llvm::Triple::thumb:
     // FIXME: this is incorrect for WinCE

diff  --git a/clang/lib/Driver/ToolChains/MinGW.cpp b/clang/lib/Driver/ToolChains/MinGW.cpp
index bac486bab885..947abb9b02b5 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -135,7 +135,7 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA,
     CmdArgs.push_back("arm64pe");
     break;
   default:
-    llvm_unreachable("Unsupported target architecture.");
+    D.Diag(diag::err_target_unknown_triple) << TC.getEffectiveTriple().str();
   }
 
   Arg *SubsysArg =

diff  --git a/clang/test/Driver/unsupported-target-arch.c b/clang/test/Driver/unsupported-target-arch.c
index 11be696546db..b43a77e0486d 100644
--- a/clang/test/Driver/unsupported-target-arch.c
+++ b/clang/test/Driver/unsupported-target-arch.c
@@ -23,3 +23,11 @@
 // RUN: not %clang --target=noarch-unknown-nacl -o %t.o %s 2> %t.err
 // RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-NOARCH-NACL %s
 // CHECK-NOARCH-NACL:  error: the target architecture 'noarch' is not supported by the target 'Native Client'
+
+// RUN: not %clang --target=noarch-unknown-windows-gnu -o %t.o %s 2> %t.err
+// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-NOARCH-MINGW %s
+// CHECK-NOARCH-MINGW: error: unknown target triple 'noarch-unknown-windows-gnu'
+
+// RUN: not %clang --target=noarch-unknown-windows-itanium -o %t.o %s 2> %t.err
+// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-NOARCH-CROSSWINDOWS %s
+// CHECK-NOARCH-CROSSWINDOWS: error: unknown target triple 'noarch-unknown-windows-itanium'


        


More information about the cfe-commits mailing list