Skip to content

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

@paparodeo

Description

@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 not 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:driver'clang' and 'clang++' user-facing binaries. Not 'clang-cl'

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions