llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

clang reports that -mcpu= option is unsupported when used together with --version

Open mgabka opened this issue 3 years ago • 4 comments

When running: clang -mcpu=native -v: on X86 we can see following error: clang: error: unsupported option '-mcpu=' for target 'x86_64-unknown-linux-gnu' or clang: error: unsupported option '-mcpu=' for target 'aarch64-unknown-linux-gnu' when executed on aarch64.

clang 16 was fine with it, the issue exists with clang 17 rc3 and on the main branch.

mgabka avatar Aug 24 '23 12:08 mgabka

@llvm/issue-subscribers-clang-driver

llvmbot avatar Aug 24 '23 14:08 llvmbot

-mcpu= is invalid for x86. GCC prints a warning while Clang prints an error. https://maskray.me/blog/2022-08-28-march-mcpu-mtune

% gcc -mcpu=native -c q.c
gcc: warning: ‘-mcpu=’ is deprecated; use ‘-mtune=’ or ‘-march=’ instead

-mcpu= can be used with AArch64.

I agree that the current diagnostic is not great[1], but do you have a specific reason to use other options along with -v without an input file? This is a corner case that Clang does not handle well.

% ~/llvm-prebuilt/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin/clang -march=native -v
...
clang-16: warning: argument unused during compilation: '-march=native' [-Wunused-command-line-argument]
% ~/llvm-prebuilt/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin/clang -march=native -Werror -v
...
clang-16: error: argument unused during compilation: '-march=native' [-Werror,-Wunused-command-line-argument]
clang-16: error: argument unused during compilation: '-Werror' [-Werror,-Wunused-command-line-argument]

[1]: Without an input file, clangDriver doesn't create jobs for actions. ConstructJob is not called. Most options are not claimed.

MaskRay avatar Aug 25 '23 02:08 MaskRay

I hit it when using spec2k17, from what I can see in the compiler detection stage it is applying all the optimization flags and append at the end "-v" to detect compiler version.

mgabka avatar Aug 29 '23 12:08 mgabka

Fixed by https://reviews.llvm.org/D159361

mgabka avatar Sep 11 '23 15:09 mgabka