Repository navigation
Description
I built llvm in MacOS (enabled "clang;lld;compiler-rt"), and saw the following error when opening compiler-rt/lib/profile/InstrProfilingFile.c. I only saw this kind of error in files under compiler-rt folder. For files under other folders like clang, llvm, lld, I don't see that and it works well.
Logs
Unable to handle compilation, expected exactly one compiler job in ' "/Users/zequanwu/chromium/src/third_party/llvm-build/Release+Asserts/bin/clang" "-cc1" "-triple" "i386-apple-ios9.0.0-simulator" "-Wundef-prefix=TARGET_OS_" "-Werror=undef-prefix" "-fsyntax-only" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "InstrProfilingFile.c" "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=all" "-fno-rounding-math" "-munwind-tables" "-faligned-alloc-unavailable" "-target-sdk-version=14.5" "-fcompatibility-qualified-id-block-type-checking" "-fvisibility-inlines-hidden-static-local-var" "-target-cpu" "yonah" "-tune-cpu" "generic" "-debugger-tuning=lldb" "-target-linker-version" "609.8" "-nostdinc++" "-resource-dir" "/Users/zequanwu/Library/Application Support/Code/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/12.0.0/clangd_12.0.0/lib/clang/12.0.0" "-isysroot" "/Users/zequanwu/llvm-project/sysroot/MacOSX.sdk" "-isysroot" "/Applications/Xcode_12.5.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk" "-D" "_DEBUG" "-D" "__STDC_CONSTANT_MACROS" "-D" "__STDC_FORMAT_MACROS" "-D" "__STDC_LIMIT_MACROS" "-I" "/Users/zequanwu/llvm-project/build/release/projects/compiler-rt/lib/profile" "-I" "/Users/zequanwu/llvm-project/compiler-rt/lib/profile" "-I" "/Users/zequanwu/llvm-project/build/release/include" "-I" "/Users/zequanwu/llvm-project/llvm/include" "-I" "/Users/zequanwu/llvm-project/compiler-rt/lib/profile/.." "-I" "/Users/zequanwu/llvm-project/compiler-rt/lib/profile/../../include" "-D" "NDEBUG" "-D" "COMPILER_RT_HAS_ATOMICS=1" "-D" "COMPILER_RT_HAS_FCNTL_LCK=1" "-D" "COMPILER_RT_HAS_UNAME=1" "-U" "NDEBUG" "-internal-isystem" "/Applications/Xcode_12.5.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk/usr/local/include" "-internal-isystem" "/Users/zequanwu/Library/Application Support/Code/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/12.0.0/clangd_12.0.0/lib/clang/12.0.0/include" "-internal-externc-isystem" "/Applications/Xcode_12.5.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk/usr/include" "-O3" "-Werror=date-time" "-Werror=unguarded-availability-new" "-Wall" "-Wextra" "-Wno-unused-parameter" "-Wwrite-strings" "-Wmissing-field-initializers" "-Wno-long-long" "-Wc++98-compat-extra-semi" "-Wimplicit-fallthrough" "-Wcovered-switch-default" "-Wdelete-non-virtual-dtor" "-Wstring-conversion" "-Wmisleading-indentation" "-Wall" "-Wno-unused-parameter" "-Wno-pedantic" "-pedantic" "-fconst-strings" "-fdebug-compilation-dir" "/Users/zequanwu/llvm-project/build/release" "-ferror-limit" "19" "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fmax-type-align=16" "-vectorize-loops" "-vectorize-slp" "-x" "c" "/Users/zequanwu/llvm-project/compiler-rt/lib/profile/InstrProfilingFile.c"; "/Users/zequanwu/chromium/src/third_party/llvm-build/Release+Asserts/bin/clang" "-cc1" "-triple" "x86_64-apple-ios9.0.0-simulator" "-Wundef-prefix=TARGET_OS_" "-Werror=undef-prefix" "-Wdeprecated-objc-isa-usage" "-Werror=deprecated-objc-isa-usage" "-Werror=implicit-function-declaration" "-fsyntax-only" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "InstrProfilingFile.c" "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=all" "-fno-rounding-math" "-munwind-tables" "-faligned-alloc-unavailable" "-target-sdk-version=14.5" "-fcompatibility-qualified-id-block-type-checking" "-fvisibility-inlines-hidden-static-local-var" "-target-cpu" "core2" "-tune-cpu" "generic" "-debugger-tuning=lldb" "-target-linker-version" "609.8" "-nostdinc++" "-resource-dir" "/Users/zequanwu/Library/Application Support/Code/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/12.0.0/clangd_12.0.0/lib/clang/12.0.0" "-isysroot" "/Users/zequanwu/llvm-project/sysroot/MacOSX.sdk" "-isysroot" "/Applications/Xcode_12.5.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk" "-D" "_DEBUG" "-D" "__STDC_CONSTANT_MACROS" "-D" "__STDC_FORMAT_MACROS" "-D" "__STDC_LIMIT_MACROS" "-I" "/Users/zequanwu/llvm-project/build/release/projects/compiler-rt/lib/profile" "-I" "/Users/zequanwu/llvm-project/compiler-rt/lib/profile" "-I" "/Users/zequanwu/llvm-project/build/release/include" "-I" "/Users/zequanwu/llvm-project/llvm/include" "-I" "/Users/zequanwu/llvm-project/compiler-rt/lib/profile/.." "-I" "/Users/zequanwu/llvm-project/compiler-rt/lib/profile/../../include" "-D" "NDEBUG" "-D" "COMPILER_RT_HAS_ATOMICS=1" "-D" "COMPILER_RT_HAS_FCNTL_LCK=1" "-D" "COMPILER_RT_HAS_UNAME=1" "-U" "NDEBUG" "-internal-isystem" "/Applications/Xcode_12.5.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk/usr/local/include" "-internal-isystem" "/Users/zequanwu/Library/Application Support/Code/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/12.0.0/clangd_12.0.0/lib/clang/12.0.0/include" "-internal-externc-isystem" "/Applications/Xcode_12.5.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk/usr/include" "-O3" "-Werror=date-time" "-Werror=unguarded-availability-new" "-Wall" "-Wextra" "-Wno-unused-parameter" "-Wwrite-strings" "-Wmissing-field-initializers" "-Wno-long-long" "-Wc++98-compat-extra-semi" "-Wimplicit-fallthrough" "-Wcovered-switch-default" "-Wdelete-non-virtual-dtor" "-Wstring-conversion" "-Wmisleading-indentation" "-Wall" "-Wno-unused-parameter" "-Wno-pedantic" "-pedantic" "-fconst-strings" "-fdebug-compilation-dir" "/Users/zequanwu/llvm-project/build/release" "-ferror-limit" "19" "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fmax-type-align=16" "-vectorize-loops" "-vectorize-slp" "-x" "c" "/Users/zequanwu/llvm-project/compiler-rt/lib/profile/InstrProfilingFile.c"; "/Users/zequanwu/chromium/src/third_party/llvm-build/Release+Asserts/bin/clang" "-cc1" "-triple" "arm64-apple-ios9.0.0" "-Wundef-prefix=TARGET_OS_" "-Werror=undef-prefix" "-Wdeprecated-objc-isa-usage" "-Werror=deprecated-objc-isa-usage" "-Werror=implicit-function-declaration" "-fsyntax-only" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "InstrProfilingFile.c" "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=non-leaf" "-fno-rounding-math" "-munwind-tables" "-faligned-alloc-unavailable" "-target-sdk-version=14.5" "-fcompatibility-qualified-id-block-type-checking" "-fvisibility-inlines-hidden-static-local-var" "-target-cpu" "apple-a7" "-target-feature" "+fp-armv8" "-target-feature" "+neon" "-target-feature" "+crypto" "-target-feature" "+zcm" "-target-feature" "+zcz" "-target-feature" "+sha2" "-target-feature" "+aes" "-target-abi" "darwinpcs" "-fallow-half-arguments-and-returns" "-debugger-tuning=lldb" "-target-linker-version" "609.8" "-nostdinc++" "-resource-dir" "/Users/zequanwu/Library/Application Support/Code/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/12.0.0/clangd_12.0.0/lib/clang/12.0.0" "-isysroot" "/Users/zequanwu/llvm-project/sysroot/MacOSX.sdk" "-isysroot" "/Applications/Xcode_12.5.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk" "-D" "_DEBUG" "-D" "__STDC_CONSTANT_MACROS" "-D" "__STDC_FORMAT_MACROS" "-D" "__STDC_LIMIT_MACROS" "-I" "/Users/zequanwu/llvm-project/build/release/projects/compiler-rt/lib/profile" "-I" "/Users/zequanwu/llvm-project/compiler-rt/lib/profile" "-I" "/Users/zequanwu/llvm-project/build/release/include" "-I" "/Users/zequanwu/llvm-project/llvm/include" "-I" "/Users/zequanwu/llvm-project/compiler-rt/lib/profile/.." "-I" "/Users/zequanwu/llvm-project/compiler-rt/lib/profile/../../include" "-D" "NDEBUG" "-D" "COMPILER_RT_HAS_ATOMICS=1" "-D" "COMPILER_RT_HAS_FCNTL_LCK=1" "-D" "COMPILER_RT_HAS_UNAME=1" "-U" "NDEBUG" "-internal-isystem" "/Applications/Xcode_12.5.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk/usr/local/include" "-internal-isystem" "/Users/zequanwu/Library/Application Support/Code/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/12.0.0/clangd_12.0.0/lib/clang/12.0.0/include" "-internal-externc-isystem" "/Applications/Xcode_12.5.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk/usr/include" "-O3" "-Werror=date-time" "-Werror=unguarded-availability-new" "-Wall" "-Wextra" "-Wno-unused-parameter" "-Wwrite-strings" "-Wmissing-field-initializers" "-Wno-long-long" "-Wc++98-compat-extra-semi" "-Wimplicit-fallthrough" "-Wcovered-switch-default" "-Wdelete-non-virtual-dtor" "-Wstring-conversion" "-Wmisleading-indentation" "-Wall" "-Wno-unused-parameter" "-Wno-pedantic" "-pedantic" "-fconst-strings" "-fdebug-compilation-dir" "/Users/zequanwu/llvm-project/build/release" "-ferror-limit" "19" "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fmax-type-align=16" "-vectorize-loops" "-vectorize-slp" "-x" "c" "/Users/zequanwu/llvm-project/compiler-rt/lib/profile/InstrProfilingFile.c"; 'clang(fe_expected_compiler_job)
More logs:
[Error - 5:31:11 PM] Request textDocument/documentLink failed.
[object Object]
[Error - 5:31:11 PM] Request textDocument/codeAction failed.
[object Object]
V[17:31:12.124] <<< {"id":81,"jsonrpc":"2.0","method":"textDocument/codeAction","params":{"context":{"diagnostics":[]},"range":{"end":{"character":19,"line":167},"start":{"character":19,"line":167}},"textDocument":{"uri":"file:///Users/zequanwu/llvm-project/compiler-rt/lib/profile/InstrProfilingFile.c"}}}
I[17:31:12.124] <-- textDocument/codeAction(81)
I[17:31:12.124] --> reply:textDocument/codeAction(81) 0 ms, error: invalid AST
V[17:31:12.124] >>> {"error":{"code":-32001,"message":"invalid AST"},"id":81,"jsonrpc":"2.0"}
I[17:31:12.124] --> textDocument/clangd.fileStatus
V[17:31:12.124] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///Users/zequanwu/llvm-project/compiler-rt/lib/profile/InstrProfilingFile.c"}}
[Error - 5:31:12 PM] Request textDocument/codeAction failed.
There are 13 entries in compilation_database.json with following file field:
"file": "/Users/zequanwu/llvm-project/compiler-rt/lib/profile/InstrProfiling.c"
System information
Clangd version: clangd version 12.0.0 (https://github.com/clangd/llvm-project 8a844a3a321ea56da21af4d48433ad493b1bcfae)
OS: MacOS 11.3.1.
Editor: VS Code 1.58.1
Plugin: clangd
Activity
kadircet commentedon Aug 2, 2021
can you provide full clangd logs ? they should contain the compile flags received from your database. it seems like you are compiling for multiple architectures within a single compilation, I don't know what clang flag triggers that though.
ZequanWu commentedon Aug 5, 2021
I added
--log=verboseas clangd argument in vscode.log:
kadircet commentedon Aug 5, 2021
As I've suspected, you've got
-arch i386 -arch x86_64 -arch arm64in your compile flags which results in 3 compilation actions.We should drop multiple arch options in clangd, but the question is which one to keep (or whether to keep any at all).
In the meantime you can workaround the issue by putting a .clangd file in your project root with contents:
This will drop all
-archflags and make clang default to your host's architecture. If you want to edit code while targeting a specific architecture you can change contents to (while changingfoowith your desired arch):ZequanWu commentedon Aug 5, 2021
Thanks, that works.
sam-mccall commentedon Aug 6, 2021
Yeah exactly which is best is fuzzy (the example shows "first" isn't ideal), but clearly anything is better than what we do now.
BTW the easiest way to repro this on non-mac is adding a mac target (exact target doesn't matter).
compile_flags.txt:kadircet commentedon Aug 6, 2021
[clangd] Avoid "expected one compiler job" by picking the first eligi…
[clangd] Strip mutliple arch options
[clangd] Strip mutliple arch options
[clangd] Strip mutliple arch options
[clangd] Avoid "expected one compiler job" by picking the first eligi…