[clang] 45ff63b - [Driver] Also warn about -mwatchos-version-min and -mtvos-version-min

Cassie Jones via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 17 13:26:59 PDT 2023


Author: Cassie Jones
Date: 2023-07-17T13:26:52-07:00
New Revision: 45ff63ba6112c199897b4117d54f19d28161b632

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

LOG: [Driver] Also warn about -mwatchos-version-min and -mtvos-version-min

Sometimes users pass this option when targeting embedded architectures like armv7m on non-darwin platforms.
This applies to watchOS and tvOS as well as iOS.

Depends on D155407

Reviewed By: MaskRay, ahatanak

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

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Darwin.cpp
    clang/test/Driver/macho-embedded.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index a73f46bb320294..65bd6c6a7eb35a 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -26,6 +26,7 @@
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/TargetParser/TargetParser.h"
+#include "llvm/TargetParser/Triple.h"
 #include <cstdlib> // ::getenv
 
 using namespace clang::driver;
@@ -85,10 +86,16 @@ void darwin::setTripleTypeForMachOArchName(llvm::Triple &T, StringRef Str,
   if (ArchKind == llvm::ARM::ArchKind::ARMV6M ||
       ArchKind == llvm::ARM::ArchKind::ARMV7M ||
       ArchKind == llvm::ARM::ArchKind::ARMV7EM) {
-    // Don't reject -mios-version-min= if we have an iOS triple.
-    if (T.isiOS())
+    // Don't reject these -version-min= if we have the appropriate triple.
+    if (T.getOS() == llvm::Triple::IOS)
       for (Arg *A : Args.filtered(options::OPT_mios_version_min_EQ))
         A->ignoreTargetSpecific();
+    if (T.getOS() == llvm::Triple::WatchOS)
+      for (Arg *A : Args.filtered(options::OPT_mwatchos_version_min_EQ))
+        A->ignoreTargetSpecific();
+    if (T.getOS() == llvm::Triple::TvOS)
+      for (Arg *A : Args.filtered(options::OPT_mtvos_version_min_EQ))
+        A->ignoreTargetSpecific();
 
     T.setOS(llvm::Triple::UnknownOS);
     T.setObjectFormat(llvm::Triple::MachO);

diff  --git a/clang/test/Driver/macho-embedded.c b/clang/test/Driver/macho-embedded.c
index 14b933ba256de0..bb4971203518b3 100644
--- a/clang/test/Driver/macho-embedded.c
+++ b/clang/test/Driver/macho-embedded.c
@@ -8,12 +8,17 @@
 
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 -mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-watchos -mwatchos-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-tvos -mtvos-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+
+// RUN: %clang -arch armv7m --target=thumbv7-apple-tvos -mios-version-min=5 -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-MIXED
 
 // CHECK-IOS: "-triple" "thumbv7" "thumbv7-apple-ios
 
 // CHECK-AAPCS: "-target-abi" "aapcs"
 // CHECK-APCS: "-target-abi" "apcs-gnu"
 
-// CHECK-MACHO-EMBEDDED-DIAG: warning: argument unused during compilation: '-mios-version-min=5'
 // CHECK-MACHO-EMBEDDED: "-triple" "{{thumbv[67]e?m}}-apple-unknown-macho"
 // CHECK-MACHO-EMBEDDED: "-mrelocation-model" "pic"
+// CHECK-MACHO-EMBEDDED-DIAG: warning: argument unused during compilation: '-m{{ios|watchos|tvos}}-version-min=5'
+// CHECK-MACHO-EMBEDDED-MIXED: error: unsupported option '-mios-version-min=' for target 'thumbv7-apple-tvos'


        


More information about the cfe-commits mailing list