Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
paparodeo opened this issue Nov 14, 2024 · 3 comments
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl'

Comments

@paparodeo
Copy link

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
@github-actions github-actions bot added the clang Clang issues not falling into any other category label Nov 14, 2024
@EugeneZelenko EugeneZelenko added clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' and removed clang Clang issues not falling into any other category labels Nov 14, 2024
@llvmbot
Copy link

llvmbot commented Nov 14, 2024

@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:
$ 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

@paparodeo
Copy link
Author

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

@paparodeo
Copy link
Author

paparodeo commented Nov 15, 2024

seems to be this block which is swallowing the errors:

// If we are linking, claim any options which are obviously only used for
// compilation.
// FIXME: Understand why the last Phase List length is used here.
if (FinalPhase == phases::Link && LastPLSize == 1) {
Args.ClaimAllArgs(options::OPT_CompileOnly_Group);
Args.ClaimAllArgs(options::OPT_cl_compile_Group);
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl'
Projects
None yet
Development

No branches or pull requests

3 participants