[PATCH] D155123: [Driver] Warn about -mios-version-min instead of erroring out when targeting MachO embedded architectures
Akira Hatanaka via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 12 14:41:14 PDT 2023
ahatanak created this revision.
ahatanak added reviewers: arphaman, t.p.northover, MaskRay.
ahatanak added a project: clang.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
ahatanak requested review of this revision.
Sometimes users pass this option when targeting embedded architectures like armv7m on non-darwin platforms.
Emit a warning instead of erroring out, which restores the behavior prior to 34d7acd444b88342fc93fca202608c1e16fa5946 <https://reviews.llvm.org/rG34d7acd444b88342fc93fca202608c1e16fa5946>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D155123
Files:
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Darwin.cpp
clang/lib/Driver/ToolChains/Darwin.h
clang/test/Driver/macho-embedded.c
Index: clang/test/Driver/macho-embedded.c
===================================================================
--- clang/test/Driver/macho-embedded.c
+++ clang/test/Driver/macho-embedded.c
@@ -6,10 +6,13 @@
// RUN: %clang -arch armv7m -target thumbv7-apple-darwin -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED
// RUN: %clang -arch armv7em -target thumbv7-apple-darwin -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED
+// RUN: %clang -arch armv7m -target thumbv7-apple-ios -mios-version-min=5 -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG --check-prefix=CHECK-MACHO-EMBEDDED
+
// CHECK-IOS: "-triple" "thumbv7" "thumbv7-apple-ios
// CHECK-AAPCS: "-target-abi" "aapcs"
// CHECK-APCS: "-target-abi" "apcs-gnu"
+// CHECK-MACHO-EMBEDDED-DIAG: clang: 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"
Index: clang/lib/Driver/ToolChains/Darwin.h
===================================================================
--- clang/lib/Driver/ToolChains/Darwin.h
+++ clang/lib/Driver/ToolChains/Darwin.h
@@ -28,7 +28,8 @@
namespace darwin {
llvm::Triple::ArchType getArchTypeForMachOArchName(StringRef Str);
-void setTripleTypeForMachOArchName(llvm::Triple &T, StringRef Str);
+void setTripleTypeForMachOArchName(llvm::Triple &T, StringRef Str,
+ const llvm::opt::ArgList &Args);
class LLVM_LIBRARY_VISIBILITY MachOTool : public Tool {
virtual void anchor();
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -74,7 +74,8 @@
.Default(llvm::Triple::UnknownArch);
}
-void darwin::setTripleTypeForMachOArchName(llvm::Triple &T, StringRef Str) {
+void darwin::setTripleTypeForMachOArchName(llvm::Triple &T, StringRef Str,
+ const ArgList &Args) {
const llvm::Triple::ArchType Arch = getArchTypeForMachOArchName(Str);
llvm::ARM::ArchKind ArchKind = llvm::ARM::parseArch(Str);
T.setArch(Arch);
@@ -84,6 +85,11 @@
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())
+ if (Arg *A = Args.getLastArgNoClaim(options::OPT_mios_version_min_EQ))
+ A->ignoreTargetSpecific();
+
T.setOS(llvm::Triple::UnknownOS);
T.setObjectFormat(llvm::Triple::MachO);
}
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -546,14 +546,15 @@
if (Target.isOSBinFormatMachO()) {
// If an explicit Darwin arch name is given, that trumps all.
if (!DarwinArchName.empty()) {
- tools::darwin::setTripleTypeForMachOArchName(Target, DarwinArchName);
+ tools::darwin::setTripleTypeForMachOArchName(Target, DarwinArchName,
+ Args);
return Target;
}
// Handle the Darwin '-arch' flag.
if (Arg *A = Args.getLastArg(options::OPT_arch)) {
StringRef ArchName = A->getValue();
- tools::darwin::setTripleTypeForMachOArchName(Target, ArchName);
+ tools::darwin::setTripleTypeForMachOArchName(Target, ArchName, Args);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155123.539741.patch
Type: text/x-patch
Size: 3586 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230712/12048a1f/attachment-0001.bin>
More information about the cfe-commits
mailing list