llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.09k stars 12k forks source link

[clang] `clang -mpopcnt hello.c <link flag>` fails to generate warning when file precedes link flag #116278

Open paparodeo opened 4 hours ago

paparodeo commented 4 hours ago

on aarch64 darwin using the -mpopcnt flag will result in a warning on clang 16 and error on clang 19.1.3. however, if a linker flag trails the file name no warning / error is generated. eg:

$ clang -mpopcnt hello.c -lc
$ ./a.out
hello world

however, re-ordering the command line so the file name comes after -lc will generate the expected error

$ clang -mpopcnt -lc hello.c
clang: error: unsupported option '-mpopcnt' for target 'aarch64-apple-darwin'

this behavior is not seen with all link flags, eg -flat_namespace always will generate an error, but when used in conjunction with -Wl will generate an error (as do other flags, like -v)

$ clang -mpopcnt -flat_namespace hello.c
clang: error: unsupported option '-mpopcnt' for target 'aarch64-apple-darwin'
$ clang -mpopcnt hello.c -flat_namespace
clang: error: unsupported option '-mpopcnt' for target 'aarch64-apple-darwin'
$ clang -mpopcnt -Wl,-flat_namespace hello.c
clang: error: unsupported option '-mpopcnt' for target 'aarch64-apple-darwin'
$ clang -mpopcnt hello.c -Wl,-flat_namespace
$ ./a.out
hello world
$ clang -v
clang version 19.1.3
Target: aarch64-apple-darwin24.1.0
Thread model: posix
InstalledDir: /nix/store/6b4vxqc16xq1nq8jhdsylfml244vah22-clang-19.1.3/bin
llvmbot commented 4 hours ago

@llvm/issue-subscribers-clang-driver

Author: Reno Dakota (paparodeo)

on aarch64 darwin using the `-mpopcnt` flag will result in a warning on clang 16 and error on clang 19.1.3. however, if a linker flag trails the file name no warning / error is generated. eg: ```console $ clang -mpopcnt hello.c -lc $ ./a.out hello world ``` however, re-ordering the command line so the file name comes after `-lc` will generate the expected error ```console $ clang -mpopcnt -lc hello.c clang: error: unsupported option '-mpopcnt' for target 'aarch64-apple-darwin' ``` this behavior is not seen with all link flags, eg `-flat_namespace` always will generate an error, but when used in conjunction with `-Wl` will generate an error (as do other flags, like `-v`) ```console $ clang -mpopcnt -flat_namespace hello.c clang: error: unsupported option '-mpopcnt' for target 'aarch64-apple-darwin' $ clang -mpopcnt hello.c -flat_namespace clang: error: unsupported option '-mpopcnt' for target 'aarch64-apple-darwin' $ clang -mpopcnt -Wl,-flat_namespace hello.c clang: error: unsupported option '-mpopcnt' for target 'aarch64-apple-darwin' $ clang -mpopcnt hello.c -Wl,-flat_namespace $ ./a.out hello world ``` ```console $ clang -v clang version 19.1.3 Target: aarch64-apple-darwin24.1.0 Thread model: posix InstalledDir: /nix/store/6b4vxqc16xq1nq8jhdsylfml244vah22-clang-19.1.3/bin ```
paparodeo commented 2 hours ago

this can be reproduce on x64 linux by finding some other unsupported option: eg

$ clang -mno-mma -mhtm hello.c  
clang: error: unsupported option '-mno-mma' for target 'x86_64-unknown-linux-gnu'
clang: error: unsupported option '-mhtm' for target 'x86_64-unknown-linux-gnu'
$ clang -mno-mma -mhtm hello.c -lc
$ ./a.out
hello world