[PATCH] D135284: [Driver] select alternative target containing . in executable name
Dan McGregor via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 26 13:40:17 PDT 2022
dankm updated this revision to Diff 470918.
dankm added a comment.
Added a simple testcase, and updated commit message.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D135284/new/
https://reviews.llvm.org/D135284
Files:
clang/lib/Driver/ToolChain.cpp
clang/test/Driver/target-override.c
Index: clang/test/Driver/target-override.c
===================================================================
--- clang/test/Driver/target-override.c
+++ clang/test/Driver/target-override.c
@@ -3,6 +3,7 @@
// RUN: rm -rf %t && mkdir %t
// RUN: ln -s %clang %t/i386-clang
+// RUN: ln -s %clang %t/x86_64-pc-freebsd13.1-clang
// Check if invocation of "foo-clang" adds option "-target foo".
//
@@ -13,3 +14,8 @@
//
// RUN: %t/i386-clang -c --target=x86_64 -### %s 2>&1 | FileCheck -check-prefix CHECK-TG2 %s
// CHECK-TG2: Target: x86_64
+
+// Check if invocation of "arch-vendor-osX.Y-clang" adds option "-target arch-vendor-osX.Y".
+//
+// RUN: %t/x86_64-pc-freebsd13.1-clang -c -### %s 2>&1 | FileCheck -check-prefix CHECK-TG3 %s
+// CHECK-TG3: Target: x86_64-pc-freebsd13.1
Index: clang/lib/Driver/ToolChain.cpp
===================================================================
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -198,7 +198,7 @@
/// Normalize the program name from argv[0] by stripping the file extension if
/// present and lower-casing the string on Windows.
static std::string normalizeProgramName(llvm::StringRef Argv0) {
- std::string ProgName = std::string(llvm::sys::path::stem(Argv0));
+ std::string ProgName = std::string(llvm::sys::path::filename(Argv0));
if (is_style_windows(llvm::sys::path::Style::native)) {
// Transform to lowercase for case insensitive file systems.
std::transform(ProgName.begin(), ProgName.end(), ProgName.begin(),
@@ -217,6 +217,13 @@
// added via -target as implicit first argument.
const DriverSuffix *DS = FindDriverSuffix(ProgName, Pos);
+ if (!DS && ProgName.endswith(".exe")) {
+ // Try again after stripping the executable suffix:
+ // clang++.exe -> clang++
+ ProgName = ProgName.drop_back(StringRef(".exe").size());
+ DS = FindDriverSuffix(ProgName, Pos);
+ }
+
if (!DS) {
// Try again after stripping any trailing version number:
// clang++3.5 -> clang++
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135284.470918.patch
Type: text/x-patch
Size: 2007 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221026/30d6b15d/attachment.bin>
More information about the cfe-commits
mailing list