[clang] [Driver] Mark -arch as TargetSpecific (PR #74365)

2023-12-05 Thread Daniil Kovalev via cfe-commits

kovdan01 wrote:

OK, thanks for such a detailed explanation! Closing 
https://github.com/llvm/llvm-project/pull/72821 as not needed.

https://github.com/llvm/llvm-project/pull/74365
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Mark -arch as TargetSpecific (PR #74365)

2023-12-05 Thread Fangrui Song via cfe-commits

MaskRay wrote:

When the target triple is aarch64 and `-arch ` is specified, e.g. 
`--target=aarch64 -arch arm64e`, there is currently no warning/error, because 
`clang/lib/Driver/ToolChains/Arch/AArch64.cpp` claims `OPT_arch` in quite a few 
places.
We can safely remove these references now that https://reviews.llvm.org/D55731 
has checked `isOSDarwin` (which covers macOS/iOS/watchOS/DriverKit).

> Are we supposed to pass -target to clang in addition to -arch if we want to 
> be sure to compile with Apple's triple?

If the default target triple is not Apple's triple, `--target=` is required. 
`clang -arch arm64` without `--target=` does not work.
This is the desired behavior.

> It might be reasonable, but in such case many tests which use -arch without 
> -target actually might run with undesired non-Apple triple - I find such 
> behavior a bit misleading. Is this "by design"?

These tests need to be fixed to specify `--target=` if it may run on a 
non-Apple target.
It's possible that `-arch ` is redundant with `--target=`.


https://github.com/llvm/llvm-project/pull/74365
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Mark -arch as TargetSpecific (PR #74365)

2023-12-05 Thread Daniil Kovalev via cfe-commits

kovdan01 wrote:

@MaskRay Unfortunately, the case I was initially trying to fix still has a 
problem after applying this patch. Consider 
`LLVM_DEFAULT_TARGET_TRIPLE=aarch64-linux-musl`. In such a case, running `clang 
-arch arm64e -c test.c -###` will show us `"-triple" 
"aarch64-unknown-linux-musl"`. As far as I understood from the comment 
https://github.com/llvm/llvm-project/pull/72821#issuecomment-1839435929, a 
warning `-Wunused-command-line-argument` should be emitted - but it is not 
(this does not change even if we really compile to the object file instead of 
just printing cli args with `-###`).

Are we supposed to pass `-target` to clang in addition to `-arch` if we want to 
be sure to compile with Apple's triple? It might be reasonable, but in such 
case many tests which use `-arch` without `-target` actually might run with 
undesired non-Apple triple - I find such behavior a bit misleading. Is this "by 
design"?

https://github.com/llvm/llvm-project/pull/74365
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Mark -arch as TargetSpecific (PR #74365)

2023-12-05 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay closed 
https://github.com/llvm/llvm-project/pull/74365
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Mark -arch as TargetSpecific (PR #74365)

2023-12-04 Thread Brad Smith via cfe-commits

https://github.com/brad0 approved this pull request.


https://github.com/llvm/llvm-project/pull/74365
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Mark -arch as TargetSpecific (PR #74365)

2023-12-04 Thread James Y Knight via cfe-commits

https://github.com/jyknight approved this pull request.


https://github.com/llvm/llvm-project/pull/74365
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Mark -arch as TargetSpecific (PR #74365)

2023-12-04 Thread Jon Roelofs via cfe-commits

https://github.com/jroelofs approved this pull request.


https://github.com/llvm/llvm-project/pull/74365
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Mark -arch as TargetSpecific (PR #74365)

2023-12-04 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Fangrui Song (MaskRay)


Changes

`-arch` is a Darwin-specific option that is ignored for other targets
and not known by GCC.
```
% clang -arch arm64 -c a.c
clang: warning: argument unused during compilation: '-arch arm64' 
[-Wunused-command-line-argument]
```

We are utilizing TargetSpecific (from https://reviews.llvm.org/D151590)
to make more options lead to errors for unsupported targets.


---
Full diff: https://github.com/llvm/llvm-project/pull/74365.diff


4 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+1-1) 
- (modified) clang/test/Driver/arc-exceptions.m (+2-2) 
- (modified) clang/test/Driver/arm-arch-darwin.c (+3-2) 
- (modified) clang/test/Frontend/darwin-eabi.c (+3-3) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1d04e4f6e7e6d..8c6d1f61ebcf2 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -994,7 +994,7 @@ def all__load : Flag<["-"], "all_load">;
 def allowable__client : Separate<["-"], "allowable_client">;
 def ansi : Flag<["-", "--"], "ansi">, Group;
 def arch__errors__fatal : Flag<["-"], "arch_errors_fatal">;
-def arch : Separate<["-"], "arch">, Flags<[NoXarchOption]>;
+def arch : Separate<["-"], "arch">, Flags<[NoXarchOption,TargetSpecific]>;
 def arch__only : Separate<["-"], "arch_only">;
 def autocomplete : Joined<["--"], "autocomplete=">;
 def bind__at__load : Flag<["-"], "bind_at_load">;
diff --git a/clang/test/Driver/arc-exceptions.m 
b/clang/test/Driver/arc-exceptions.m
index 4501ccd073823..c1dd02d59988c 100644
--- a/clang/test/Driver/arc-exceptions.m
+++ b/clang/test/Driver/arc-exceptions.m
@@ -1,5 +1,5 @@
-// RUN: %clang -### -x objective-c -arch x86_64 -fobjc-arc -fsyntax-only %s 2> 
%t.log
+// RUN: %clang -### -x objective-c --target=x86_64-apple-macos10.6 -fobjc-arc 
-fsyntax-only %s 2> %t.log
 // RUN: grep objective-c %t.log
 // RUN: not grep "fobjc-arc-exceptions" %t.log
-// RUN: %clang -### -x objective-c++ -arch x86_64 -fobjc-arc -fsyntax-only %s 
2> %t.log
+// RUN: %clang -### -x objective-c++ --target=x86_64-apple-macos10.6 
-fobjc-arc -fsyntax-only %s 2> %t.log
 // RUN: grep "fobjc-arc-exceptions" %t.log
diff --git a/clang/test/Driver/arm-arch-darwin.c 
b/clang/test/Driver/arm-arch-darwin.c
index 55089619d1e71..c523622964738 100644
--- a/clang/test/Driver/arm-arch-darwin.c
+++ b/clang/test/Driver/arm-arch-darwin.c
@@ -1,6 +1,7 @@
 // On Darwin, arch should override CPU for triple purposes
 // RUN: %clang -target armv7m-apple-darwin -arch armv7m -mcpu=cortex-m4 -### 
-c %s 2>&1 | FileCheck -check-prefix=CHECK-V7M-DARWIN %s
 // CHECK-V7M-DARWIN: "-cc1"{{.*}} "-triple" "thumbv7m-{{.*}} "-target-cpu" 
"cortex-m4"
-// RUN: %clang -target armv7m -arch armv7m -mcpu=cortex-m4 -### -c %s 2>&1 | 
FileCheck -check-prefix=CHECK-V7M-OVERRIDDEN %s
-// CHECK-V7M-OVERRIDDEN: "-cc1"{{.*}} "-triple" "thumbv7em-{{.*}} 
"-target-cpu" "cortex-m4"
 
+/// -arch is unsupported for non-Darwin targets.
+// RUN: not %clang --target=armv7m -arch armv7m -mcpu=cortex-m4 -### -c %s 
2>&1 | FileCheck -check-prefix=ERR %s
+// ERR: unsupported option '-arch' for target 'armv7m'
diff --git a/clang/test/Frontend/darwin-eabi.c 
b/clang/test/Frontend/darwin-eabi.c
index 27471e6cfb0e6..9d62632891cbe 100644
--- a/clang/test/Frontend/darwin-eabi.c
+++ b/clang/test/Frontend/darwin-eabi.c
@@ -1,6 +1,6 @@
-// RUN: %clang -arch armv6m -dM -E %s | FileCheck %s
-// RUN: %clang -arch armv7m -dM -E %s | FileCheck %s
-// RUN: %clang -arch armv7em -dM -E %s | FileCheck %s
+// RUN: %clang --target=armv6m-apple-darwin -dM -E %s | FileCheck %s
+// RUN: %clang --target=armv7m-apple-darwin -dM -E %s | FileCheck %s
+// RUN: %clang --target=armv7em-apple-darwin -dM -E %s | FileCheck %s
 // RUN: %clang_cc1 -triple thumbv7m-apple-unknown-macho -dM -E %s | FileCheck 
%s
 
 // CHECK-NOT: __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__

``




https://github.com/llvm/llvm-project/pull/74365
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Mark -arch as TargetSpecific (PR #74365)

2023-12-04 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay created 
https://github.com/llvm/llvm-project/pull/74365

`-arch` is a Darwin-specific option that is ignored for other targets
and not known by GCC.
```
% clang -arch arm64 -c a.c
clang: warning: argument unused during compilation: '-arch arm64' 
[-Wunused-command-line-argument]
```

We are utilizing TargetSpecific (from https://reviews.llvm.org/D151590)
to make more options lead to errors for unsupported targets.


>From 8de8d31f941eda119456a0656856b0d22282acba Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Mon, 4 Dec 2023 12:16:36 -0800
Subject: [PATCH] [Driver] Mark -arch as TargetSpecific

`-arch` is a Darwin-specific option that is ignored for other targets
and not known by GCC.
```
% clang -arch arm64 -c a.c
clang: warning: argument unused during compilation: '-arch arm64' 
[-Wunused-command-line-argument]
```

We are utilizing TargetSpecific (from https://reviews.llvm.org/D151590)
to make more options lead to errors for unsupported targets.
---
 clang/include/clang/Driver/Options.td | 2 +-
 clang/test/Driver/arc-exceptions.m| 4 ++--
 clang/test/Driver/arm-arch-darwin.c   | 5 +++--
 clang/test/Frontend/darwin-eabi.c | 6 +++---
 4 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1d04e4f6e7e6d..8c6d1f61ebcf2 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -994,7 +994,7 @@ def all__load : Flag<["-"], "all_load">;
 def allowable__client : Separate<["-"], "allowable_client">;
 def ansi : Flag<["-", "--"], "ansi">, Group;
 def arch__errors__fatal : Flag<["-"], "arch_errors_fatal">;
-def arch : Separate<["-"], "arch">, Flags<[NoXarchOption]>;
+def arch : Separate<["-"], "arch">, Flags<[NoXarchOption,TargetSpecific]>;
 def arch__only : Separate<["-"], "arch_only">;
 def autocomplete : Joined<["--"], "autocomplete=">;
 def bind__at__load : Flag<["-"], "bind_at_load">;
diff --git a/clang/test/Driver/arc-exceptions.m 
b/clang/test/Driver/arc-exceptions.m
index 4501ccd073823..c1dd02d59988c 100644
--- a/clang/test/Driver/arc-exceptions.m
+++ b/clang/test/Driver/arc-exceptions.m
@@ -1,5 +1,5 @@
-// RUN: %clang -### -x objective-c -arch x86_64 -fobjc-arc -fsyntax-only %s 2> 
%t.log
+// RUN: %clang -### -x objective-c --target=x86_64-apple-macos10.6 -fobjc-arc 
-fsyntax-only %s 2> %t.log
 // RUN: grep objective-c %t.log
 // RUN: not grep "fobjc-arc-exceptions" %t.log
-// RUN: %clang -### -x objective-c++ -arch x86_64 -fobjc-arc -fsyntax-only %s 
2> %t.log
+// RUN: %clang -### -x objective-c++ --target=x86_64-apple-macos10.6 
-fobjc-arc -fsyntax-only %s 2> %t.log
 // RUN: grep "fobjc-arc-exceptions" %t.log
diff --git a/clang/test/Driver/arm-arch-darwin.c 
b/clang/test/Driver/arm-arch-darwin.c
index 55089619d1e71..c523622964738 100644
--- a/clang/test/Driver/arm-arch-darwin.c
+++ b/clang/test/Driver/arm-arch-darwin.c
@@ -1,6 +1,7 @@
 // On Darwin, arch should override CPU for triple purposes
 // RUN: %clang -target armv7m-apple-darwin -arch armv7m -mcpu=cortex-m4 -### 
-c %s 2>&1 | FileCheck -check-prefix=CHECK-V7M-DARWIN %s
 // CHECK-V7M-DARWIN: "-cc1"{{.*}} "-triple" "thumbv7m-{{.*}} "-target-cpu" 
"cortex-m4"
-// RUN: %clang -target armv7m -arch armv7m -mcpu=cortex-m4 -### -c %s 2>&1 | 
FileCheck -check-prefix=CHECK-V7M-OVERRIDDEN %s
-// CHECK-V7M-OVERRIDDEN: "-cc1"{{.*}} "-triple" "thumbv7em-{{.*}} 
"-target-cpu" "cortex-m4"
 
+/// -arch is unsupported for non-Darwin targets.
+// RUN: not %clang --target=armv7m -arch armv7m -mcpu=cortex-m4 -### -c %s 
2>&1 | FileCheck -check-prefix=ERR %s
+// ERR: unsupported option '-arch' for target 'armv7m'
diff --git a/clang/test/Frontend/darwin-eabi.c 
b/clang/test/Frontend/darwin-eabi.c
index 27471e6cfb0e6..9d62632891cbe 100644
--- a/clang/test/Frontend/darwin-eabi.c
+++ b/clang/test/Frontend/darwin-eabi.c
@@ -1,6 +1,6 @@
-// RUN: %clang -arch armv6m -dM -E %s | FileCheck %s
-// RUN: %clang -arch armv7m -dM -E %s | FileCheck %s
-// RUN: %clang -arch armv7em -dM -E %s | FileCheck %s
+// RUN: %clang --target=armv6m-apple-darwin -dM -E %s | FileCheck %s
+// RUN: %clang --target=armv7m-apple-darwin -dM -E %s | FileCheck %s
+// RUN: %clang --target=armv7em-apple-darwin -dM -E %s | FileCheck %s
 // RUN: %clang_cc1 -triple thumbv7m-apple-unknown-macho -dM -E %s | FileCheck 
%s
 
 // CHECK-NOT: __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits