DmitryPolukhin added a comment.
Herald added a subscriber: MaskRay.
Herald added a project: All.

@ldionne and @dexonsmith, it seems that this diff breaks clang-tools like 
clang-tidy and clangd if `-isysroot` is specified in the compilation database. 
Moreover, clang from Xcode 14 and 15 uses paths specified in `-sysroot` and 
ignores headers alongside the clang binary. I don’t know if it is new behavior 
or it was this way when this diff was committed. Minimal reproducer is 
following:

  $ cat compile_commands.json
  [
      {
          "directory": "/Users/test/test",
          "file": "test.cpp",
          "arguments": [
              
"/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++",
              "-isysroot",
              
"/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk",
              "-c",
              "test.cpp",
              "-v"
          ]
      }
  ]
  
  $ <upstream>/build/bin/clang-tidy -p compile_commands.json test.cpp
  ...
  #include <...> search starts here:
   
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
   <upstream>/build/lib/clang/18/include
   
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
   
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks
 (framework directory)
  End of search list.
  1 error generated.
  Error while processing test.cpp.
  test.cpp:1:10: error: 'cxxabi.h' file not found [clang-diagnostic-error]
      1 | #include <cxxabi.h>
        |          ^~~~~~~~~~
  Found compiler error(s).
  
  $ 
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
 -isysroot 
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
 -c test.cpp -v
  ...
  #include <...> search starts here:
   
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1
   
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/14.0.3/include
   
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
   
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
   
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks
 (framework directory)
  End of search list.

So upstream clang-tools uses a path to the compiler binary specified in CDB as 
an installation dir and searches in 
".../XcodeDefault.xctoolchain/usr/bin/../include/c++/v1" but the Apple compiler 
from CDB searches in the path specified in sysroot 
".../MacOSX.sdk/usr/include/c++/v1". I also checked clangd from Apple 
toolchain, it also uses path species in `-sysroot`. I have a local patch that 
honors `-isysroot` if it is explicitly specified in the command line but 
prefers headers alongside the binary in other cases and it seems that it 
matches the behavior of Apple compiler.  But it breaks all tests that 
specifically test that `-isysroot` is ignored. Should I change the test and 
send the patch for review?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89001/new/

https://reviews.llvm.org/D89001

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D89001: [c... Dmitry Polukhin via Phabricator via cfe-commits

Reply via email to