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-tidy broken with llvm v19.1.3 #196344

Open
4 tasks done
lukeshingles opened this issue Nov 1, 2024 · 15 comments
Open
4 tasks done

clang-tidy broken with llvm v19.1.3 #196344

lukeshingles opened this issue Nov 1, 2024 · 15 comments
Labels
bug Reproducible Homebrew/homebrew-core bug

Comments

@lukeshingles
Copy link
Contributor

lukeshingles commented Nov 1, 2024

brew gist-logs <formula> link OR brew config AND brew doctor output

https://gist.github.com/lukeshingles/b1477f4b5eaf327af99940ec848213b4

Verification

What were you trying to do (and why)?

clang-tidy is no longer finding system headers since the llvm 19.1.3 update (#196094)

What happened (include all command output)?

$ clang-tidy helloworld.cpp
4 warnings and 1 error generated.
Error while processing /Users/luke/test/helloworld.cpp.
warning: -lunwind: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: argument unused during compilation: '-L/opt/homebrew/opt/llvm/lib' [clang-diagnostic-unused-command-line-argument]
warning: argument unused during compilation: '-L/opt/homebrew/opt/llvm/lib/c++' [clang-diagnostic-unused-command-line-argument]
warning: argument unused during compilation: '-L/opt/homebrew/opt/llvm/lib/unwind' [clang-diagnostic-unused-command-line-argument]
helloworld.cpp:1:10: error: 'iostream' file not found [clang-diagnostic-error]
    1 | #include <iostream>
      |          ^~~~~~~~~~
Found compiler error(s).

What did you expect to happen?

Using llvm 19.1.2 formula, the output is:

$ clang-tidy helloworld.cpp
4 warnings generated.
warning: -lunwind: 'linker' input unused [clang-diagnostic-unused-command-line-argument]
warning: argument unused during compilation: '-L/opt/homebrew/opt/llvm/lib' [clang-diagnostic-unused-command-line-argument]
warning: argument unused during compilation: '-L/opt/homebrew/opt/llvm/lib/c++' [clang-diagnostic-unused-command-line-argument]
warning: argument unused during compilation: '-L/opt/homebrew/opt/llvm/lib/unwind' [clang-diagnostic-unused-command-line-argument]

(Some warnings but no error finding <iostream>).

Step-by-step reproduction instructions (by running brew commands)

// helloworld.cpp
#include <iostream>

int main() {
  std::cout << "Hello World!";
  return 0;
}
pip install compiledb
compiledb make helloworld
clang-tidy helloworld.cpp
@lukeshingles lukeshingles added the bug Reproducible Homebrew/homebrew-core bug label Nov 1, 2024
@lukeshingles lukeshingles changed the title clang-tidy v19.1.3 broken clang-tidy broken with llvm v19.1.3 Nov 1, 2024
@lukeshingles
Copy link
Contributor Author

I get the same errors when I run clang-tidy from pip (latest version is 19.1.0) when brew llvm 19.1.3 is installed.

@carlocab
Copy link
Member

carlocab commented Nov 1, 2024

Oh, that's annoying. Looks like clang-tidy does not use Clang config files.

As a workaround, try

xcrun clang-tidy helloworld.cpp

@Congyuwang
Copy link

Congyuwang commented Nov 2, 2024

Similar problem, but with clang. With 19.1.3, clang can't find stuff like #include<string>.

Now I'll have to manually add --sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk for things to work.

I wonder if this is as expected. Or what is the right way to fix this system-header-missing problem?

@lukeshingles
Copy link
Contributor Author

lukeshingles commented Nov 2, 2024

For me, I didn’t have any problem compiling with clang++. Does my simple example compile?

@carlocab
Copy link
Member

carlocab commented Nov 2, 2024

@Congyuwang, I can't reproduce your issue so I'll need to know:

  • the output of your brew config
  • the output of your brew doctor
  • the output of ls -la /Library/Developer/CommandLineTools
  • the exact steps needed to reproduce the failure you're seeing

@Bo98
Copy link
Member

Bo98 commented Nov 3, 2024

Looks like clang-tidy does not use Clang config files.

For the clang-tidy issue: looks like it's not resolving the config directory correctly:

$ /opt/homebrew/opt/llvm/bin/clang++ -v test.cpp
Homebrew clang version 19.1.3
Target: arm64-apple-darwin23.6.0
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/llvm/19.1.3/bin
Configuration file: /opt/homebrew/etc/clang/arm64-apple-darwin23.cfg
System configuration file directory: /opt/homebrew/etc/clang
User configuration file directory: /Users/bo/.config/clang
 "/opt/homebrew/Cellar/llvm/19.1.3/bin/clang-19" -cc1 ...

$ /opt/homebrew/opt/llvm/bin/clang-tidy test.cpp
Homebrew clang version 19.1.3
Target: arm64-apple-darwin23.6.0
Thread model: posix
InstalledDir: 
System configuration file directory: ../../../../etc/clang
User configuration file directory: /Users/bo/.config/clang
ignoring nonexistent directory "../include/c++/v1"
ignoring nonexistent directory "/usr/include/c++/v1"
clang Invocation:
 "c++" "-cc1" ...

@carlocab
Copy link
Member

carlocab commented Nov 3, 2024

For the clang-tidy issue: looks like it's not resolving the config directory correctly:

This seems to be why:

InstalledDir:

It doesn't know where the driver is, so it can't resolve the path to the config file.

@xakep8
Copy link
Contributor

xakep8 commented Nov 6, 2024

For the clang-tidy issue: looks like it's not resolving the config directory correctly:

This seems to be why:

InstalledDir:

It doesn't know where the driver is, so it can't resolve the path to the config file.

would it work to use a custom prefix flag with path while building to fix issue?

@carlocab
Copy link
Member

carlocab commented Nov 6, 2024

would it work to use a custom prefix flag with path while building to fix issue?

Not quite, since InstalledDir is not populated by the build-time install prefix. For clang, this is populated here (and then printed here). clang-tidy needs to do something similar.

In any case, we also do set CMAKE_INSTALL_PREFIX when building, so not sure there is much more to do in that regard.

@Bo98
Copy link
Member

Bo98 commented Nov 6, 2024

LLVM is designed to be relocatable so it does not bake in install prefixes.

@carlocab
Copy link
Member

@Congyuwang, I think your issue should have been fixed by #197410. You'll need to brew update && brew reinstall llvm to pick up the fix. (Or do brew update && brew postinstall llvm if you're only doing native builds.)

@Congyuwang
Copy link

@carlocab Not working. Running the following

main.c

int main() {
    return 0;
}

build.sh

eval "$(brew shellenv)"
export LLD=${HOMEBREW_PREFIX}/opt/lld/bin/ld64.lld
export CC=${HOMEBREW_PREFIX}/opt/llvm/bin/clang
${CC} -O3 --target=arm64-apple-macosx10.14 -fuse-ld=${LLD} -o main main.c -v

Run ./build.sh

We get

Homebrew clang version 19.1.3
Target: arm64-apple-macosx10.14
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/llvm/19.1.3/bin
Configuration file: /opt/homebrew/etc/clang/arm64-apple-macosx10.14.cfg
System configuration file directory: /opt/homebrew/etc/clang
User configuration file directory: /Users/congyuwang/.config/clang
 "/opt/homebrew/Cellar/llvm/19.1.3/bin/clang-19" -cc1 -triple arm64-apple-macosx10.14.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -dumpdir main- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.c -mrelocation-model pic -pic-level 2 -mframe-pointer=non-leaf -ffp-contract=on -fno-rounding-math -funwind-tables=1 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -fbuiltin-headers-in-system-modules -fdefine-target-os-macros -target-cpu apple-m1 -target-feature +zcm -target-feature +zcz -target-feature +v8.4a -target-feature +aes -target-feature +altnzcv -target-feature +ccdp -target-feature +complxnum -target-feature +crc -target-feature +dotprod -target-feature +fp-armv8 -target-feature +fp16fml -target-feature +fptoint -target-feature +fullfp16 -target-feature +jsconv -target-feature +lse -target-feature +neon -target-feature +pauth -target-feature +perfmon -target-feature +predres -target-feature +ras -target-feature +rcpc -target-feature +rdm -target-feature +sb -target-feature +sha2 -target-feature +sha3 -target-feature +specrestrict -target-feature +ssbs -target-abi darwinpcs -debugger-tuning=lldb -fdebug-compilation-dir=/Users/congyuwang/Projects/CppProjects/brew-clang-debug -target-linker-version 1115.7.3 -v -fcoverage-compilation-dir=/Users/congyuwang/Projects/CppProjects/brew-clang-debug -resource-dir /opt/homebrew/Cellar/llvm/19.1.3/lib/clang/19 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/local/include -internal-isystem /opt/homebrew/Cellar/llvm/19.1.3/lib/clang/19/include -internal-externc-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include -O3 -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fmax-type-align=16 -fcolor-diagnostics -vectorize-loops -vectorize-slp -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/fc/bckw5h_s4c9fz9dlgltf7b840000gn/T/main-b0ef43.o -x c main.c
clang -cc1 version 19.1.3 based upon LLVM 19.1.3 default target arm64-apple-darwin24.1.0
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /opt/homebrew/Cellar/llvm/19.1.3/lib/clang/19/include
End of search list.
 "/opt/homebrew/opt/lld/bin/ld64.lld" -demangle -lto_library /opt/homebrew/Cellar/llvm/19.1.3/lib/libLTO.dylib -dynamic -arch arm64 -platform_version macos 11.0.0 11.0.0 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk -mllvm -enable-linkonceodr-outlining -o main /var/folders/fc/bckw5h_s4c9fz9dlgltf7b840000gn/T/main-b0ef43.o -lSystem /opt/homebrew/Cellar/llvm/19.1.3/lib/clang/19/lib/darwin/libclang_rt.osx.a
ld64.lld: error: library not found for -lSystem
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Seems like MacOSX10.14.sdk is not found.

However, specifying --sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk compiles successfully.

@Congyuwang
Copy link

Congyuwang commented Nov 13, 2024

❯ ls /Library/Developer/CommandLineTools/SDKs/
MacOSX.sdk     MacOSX12.1.sdk MacOSX12.3.sdk MacOSX14.5.sdk MacOSX14.sdk   MacOSX15.1.sdk MacOSX15.sdk

I only have the above. MacOS 15.1, Xcode 16.1. There is no MacOSX10.14.sdk.

Whereas we have

❯ cat /opt/homebrew/etc/clang/arm64-apple-macosx10.14.cfg
--sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk

@carlocab
Copy link
Member

@Congyuwang, don't use --target. Use -mmacos-version-min. See discussion at #197532.

@Congyuwang
Copy link

@Congyuwang, don't use --target. Use -mmacos-version-min. See discussion at #197532.

I must say that this maybe the correct way to go. But I didn’t add the target flag myself, but it is added by some (I need further investigation to see) upstream dependencies. So this incorrect use of target for the purpose can be quite common.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Reproducible Homebrew/homebrew-core bug
Projects
None yet
Development

No branches or pull requests

5 participants